1: #
   2: # include   <stdio.h>
   3: 
   4: # include   "constants.h"
   5: # include   "globals.h"
   6: 
   7: /*
   8: **  PRTOUT.C -- output routines
   9: **
  10: **	Output routines for non-specific data structures
  11: **	(i.e. w_display is in [display.c])
  12: **
  13: **	Defines:
  14: **		w_con()
  15: **		w_op()
  16: **		w_var()
  17: **		w_key()
  18: **		w_new()
  19: **		begin_quote()
  20: **		end_quote()
  21: **		equate_lines()
  22: **		w_sync()
  23: **		w_flush()
  24: **		w_file()
  25: **		w_string()
  26: **		w_raw()
  27: **		Charcnt - number of characters already output
  28: **			on current line (used in [yylex.c])
  29: **
  30: **
  31: **	Required By:
  32: **		semantic routines
  33: **
  34: **	Files:
  35: **		globals.h
  36: **		constants.h
  37: **
  38: **	History:
  39: **		6/1/78 -- (marc) written
  40: */
  41: 
  42: 
  43: 
  44: extern int  Fillcnt     = FILLCNT;
  45: 
  46: 
  47: /*
  48: **  W_CON -- write out a constant
  49: **	Writes out a constant of type 'type'
  50: **	pointed to by 'string'.
  51: **
  52: */
  53: 
  54: 
  55: w_con(type, string)
  56: int type;
  57: char    *string;
  58: {
  59:     if (type == Tokens.sp_sconst)
  60:         w_string(string, 1);
  61:     else
  62:         w_key(string);
  63: }
  64: 
  65: /*
  66: **  W_OP -- Writes out a string which doesn't need a blank
  67: **	    to separate it from a keyword.
  68: **
  69: */
  70: 
  71: 
  72: w_op(string)
  73: char        *string;
  74: {
  75:     w_raw(string);
  76:     Lastc = OPCHAR;
  77: }
  78: 
  79: /*
  80: **  W_VAR -- writes out code to send the
  81: **	     value of a C variable down to
  82: **	     the Quel scanner.
  83: **
  84: **	Conserves the state of In_quote.
  85: **
  86: */
  87: 
  88: 
  89: w_var(disp, type)
  90: int     type;
  91: struct display  *disp;
  92: {
  93:     register struct disp_node   *d;
  94:     register            savestat;
  95: 
  96:     savestat = In_quote;
  97: 
  98:     /* if was In_quote, then will want a space before the
  99: 	 * string written down
 100: 	 */
 101:     if (savestat)
 102:         w_key("");
 103:     if (type != opIDSTRING)
 104:     {
 105:         w_new("IIcvar(");
 106:         if (type != opSTRING)
 107:             w_op("&");
 108:     }
 109:     else
 110:         w_new("IIwrite(");
 111:     w_display(disp);
 112:     switch (type)
 113:     {
 114: 
 115:       case opINT :
 116:         w_op(",1,2);");
 117:         break;
 118: 
 119:       case opFLOAT :
 120:         w_op(",2,4);");
 121:         break;
 122: 
 123:       case opSTRING :
 124:         w_op(",3,0);");
 125:         break;
 126: 
 127:       case opDOUBLE :
 128:         w_op(",4,8);");
 129:         break;
 130: 
 131:       case opCHAR :
 132:         w_op(",5,1);");
 133:         break;
 134: 
 135:       case opLONG :
 136:         w_op(",6,4);");
 137:         break;
 138: 
 139:       case opIDSTRING :
 140:         w_op(");");
 141:         break;
 142: 
 143:       default :
 144:         syserr("invalid type %d in w_var",
 145:         type);
 146:     }
 147:     if (savestat)
 148:     {
 149:         begin_quote();
 150:         /* if was In_quote, then will want a space
 151: 		 * before next keyword
 152: 		 */
 153:         w_key("");
 154:     }
 155: }
 156: 
 157: /*
 158: **  W_KEY -- write out a string needing a blank to
 159: **	     separate it from other keywords.
 160: **
 161: */
 162: 
 163: 
 164: 
 165: w_key(string)
 166: char    *string;
 167: {
 168:     if (Lastc == KEYCHAR)
 169:         w_raw(" ");
 170:     w_raw(string);
 171:     Lastc = KEYCHAR;
 172: }
 173: 
 174: /*
 175: **  W_NEW -- write out a string after getting out of
 176: **	     any pending IIwrite's.
 177: **
 178: */
 179: 
 180: w_new(string)
 181: char    *string;
 182: {
 183:     end_quote();
 184:     w_op(string);
 185: }
 186: 
 187: /*
 188: **  BEGIN_QUOTE -- Issue an IIwrite("
 189: **
 190: */
 191: 
 192: 
 193: begin_quote()
 194: {
 195:     In_string = 1;
 196:     In_quote = 1;
 197:     Fillmode = 1;
 198:     w_op("IIwrite(\"");
 199: }
 200: 
 201: /*
 202: **  END_QUOTE -- End any pending IIwrite("
 203: **
 204: */
 205: 
 206: 
 207: end_quote()
 208: {
 209:     In_string = 0;
 210:     if (In_quote)
 211:         w_op("\");");
 212:     In_quote = 0;
 213: }
 214: 
 215: /*
 216: **  EQUATE_LINES -- Make subsequent lines be output on the
 217: **		    same line they were read (lines of C_CODE only).
 218: **
 219: **	Note: Because of the algorithm used, it is possible that
 220: **		the correct line in the output has already been passed,
 221: **		in which case equate_lines does nothing.
 222: **
 223: */
 224: 
 225: 
 226: equate_lines()
 227: {
 228:     Fillmode = 0;
 229:     while (Lineout < yyline)
 230:         w_raw("\n");
 231:     Lastc = OPCHAR;
 232: }
 233: 
 234: /*
 235: **  W_SYNC -- Put out an IIsync() call
 236: **
 237: */
 238: 
 239: 
 240: w_sync()
 241: {
 242:     w_new("IIsync(");
 243:     w_file();
 244:     w_op(");");
 245: }
 246: 
 247: 
 248: /*
 249: **  W_FLUSH -- Put out an IIflush_tup() call
 250: **
 251: */
 252: 
 253: 
 254: w_flush()
 255: {
 256:     w_new("IIflushtup(");
 257:     w_file();
 258:     w_op(");");
 259: }
 260: 
 261: /*
 262: **  W_FILE -- Writes out the name and line number of the
 263: **	      input file if Rtdb is specified, else a 0.
 264: */
 265: 
 266: 
 267: w_file()
 268: {
 269:     char        itemp [6];
 270: 
 271:     if (Rtdb)
 272:     {
 273:         w_string(Input_file_name, 0);
 274:         itoa(yyline, itemp);
 275:         w_op(",");
 276:         w_key(itemp);
 277:     }
 278:     else
 279:         w_key("0");
 280: }
 281: 
 282: /*
 283: **  W_STRING -- Writes out a string
 284: **
 285: **	String is output as a string constant if type == 0
 286: **	otherwise writes out string inside an IIwrite(
 287: **
 288: */
 289: 
 290: 
 291: w_string(string, type)
 292: char    *string;
 293: int type;
 294: {
 295:     register char   *t;
 296:     register char   *s;
 297: 
 298:     if (type)
 299:     {
 300:         if (!In_quote)
 301:             begin_quote();
 302:         w_raw("\\");
 303:     }
 304:     s = t = string;
 305:     In_string += 1;
 306:     w_raw("\"");
 307:     for ( ;*t ; )
 308:     {
 309:         if (*t == '\\')
 310:         {
 311: 
 312:             if (t [1] == '\n')
 313:             {
 314:                 *t = '\0';
 315:                 w_raw(s);
 316:                 s = t = &t [2];
 317:                 w_raw("\\\n");
 318:             }
 319:             else
 320:             {
 321:                 *t++ = '\0';
 322:                 w_raw(s);
 323:                 s = t;
 324:                 /* note that this call must be atomic,
 325: 				 * as w_raw would feel free to put newlines
 326: 				 * in if not.
 327: 				 */
 328:                 if (type)
 329:                     w_raw("\\\\");
 330:                 else
 331:                     w_raw("\\");
 332:             }
 333:         }
 334:         else if (*t == '"')
 335:         {
 336:             w_raw("\\\"");
 337:             s = ++t;
 338:         }
 339:         else
 340:             t++;
 341:     }
 342:     w_raw(s);
 343:     In_string -= 1;
 344:     if (type)
 345:         w_raw("\\\"");
 346:     else
 347:         w_raw("\"");
 348: }
 349: 
 350: /*
 351: **  W_RAW -- Lowest level output character routine
 352: **
 353: **	Outputs string depending on Fillcnt and In_quote
 354: **	and In_string and Fillmode.
 355: **	When not in Fillmode does straight output.
 356: **	When on Fillmode, fills lines to Fillmode.
 357: **
 358: **	NOTE : w_raw will feel free to output a newline after
 359: **		'string' if the string causes more than Fillcnt
 360: **		characters to be output.
 361: **		Inside strings (In_string != 0) w_raw will put
 362: **		a '\\' before the newline issued.
 363: **		When In_quote != 0 when the fillcnt is exceeded,
 364: **		the IIwrite( is ended an continued on the next line
 365: **		so that the query string won't overflow the C
 366: **		pre-processor's line buffer.
 367: **
 368: */
 369: 
 370: 
 371: w_raw(string)
 372: char    *string;
 373: {
 374:     register char   *s;
 375:     register    charcnt;
 376: 
 377:     charcnt = 0;
 378:     for (s = string; *s; s++)
 379:     {
 380:         if (*s != '\n')
 381:         {
 382:             putc(*s, Out_file);
 383:             charcnt++;
 384:         }
 385:         else
 386:         {
 387:             if (Fillmode == 0 ||
 388:                Charcnt + charcnt > Fillcnt ||
 389:                In_string)
 390:             {
 391:                 putc(*s, Out_file);
 392:                 Lineout++;
 393:                 charcnt = 0;
 394:                 Charcnt = 0;
 395:             }
 396:             else
 397:             {
 398:                 putc(' ', Out_file);
 399:                 charcnt++;
 400:             }
 401:         }
 402:     }
 403:     if ((Charcnt += charcnt) > Fillcnt && Fillmode == 1)
 404:     {
 405:         if (In_string)
 406:         {
 407:             if (In_quote)
 408:             {
 409:                 puts("\");\nIIwrite(\"", Out_file);
 410:                 Charcnt = 9;
 411:             }
 412:             else
 413:             {
 414:                 puts("\\\n", Out_file);
 415:                 Charcnt = 0;
 416:             }
 417:         }
 418:         else
 419:         {
 420:             putc('\n', Out_file);
 421:             Charcnt = 0;
 422:         }
 423:         Lineout++;
 424:     }
 425: }
 426: 
 427: /*
 428: **  PUTS -- put a string on an output file using putc()
 429: **
 430: */
 431: 
 432: puts(s, file)
 433: char    *s;
 434: FILE    *file;
 435: {
 436:     register char   *sp;
 437:     register FILE   *f;
 438: 
 439:     f = file;
 440:     for (sp = s; *sp; )
 441:         putc(*sp++, f);
 442: }

Defined functions

end_quote defined in line 207; used 5 times
puts defined in line 432; used 2 times
w_con defined in line 55; used 9 times
w_file defined in line 267; used 4 times
w_flush defined in line 254; used 2 times
w_key defined in line 165; used 63 times
w_new defined in line 180; used 10 times
w_op defined in line 72; used 65 times
w_raw defined in line 371; used 18 times
w_string defined in line 291; used 4 times
w_sync defined in line 240; used 3 times
w_var defined in line 89; used 7 times
Last modified: 1995-02-05
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 3448
Valid CSS Valid XHTML 1.0 Strict