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

Defined functions

end_quote defined in line 164; used 5 times
puts defined in line 377; used 2 times
w_con defined in line 26; used 9 times
w_file defined in line 216; used 4 times
w_flush defined in line 204; used 2 times
w_key defined in line 128; used 67 times
w_new defined in line 141; used 10 times
w_op defined in line 41; used 66 times
w_raw defined in line 318; used 18 times
w_string defined in line 238; used 4 times
w_sync defined in line 193; used 4 times
w_var defined in line 56; used 7 times

Defined variables

Fillcnt defined in line 18; used 2 times
Last modified: 1986-04-17
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1295
Valid CSS Valid XHTML 1.0 Strict