# 2.11BSD#431 - /usr/ingres/source/equel/prtout.c

##### Functions

    begin_quote       X
    end_quote         X
    equate_lines      X
    puts              X
    w_con             X
    w_file            X
    w_flush           X
    w_key             X
    w_new             X
    w_op              X
    w_raw             X
    w_string          X
    w_sync            X
    w_var             X

       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

begin_quote defined in line 193; used 25 times

- in line 149, 301
- in /usr/ingres/source/equel/grammar.y line 821, 961, 969, 976, 983, 1001, 1008, 1015, 1022, 1029, 1036, 1043, 1073, 1087, 1094, 1102, 1108, 1116, 1123, 1130, 1143
- in /usr/ingres/source/equel/include.c line 146, 204

end_quote defined in line 207; used 5 times

- in line 183
- in /usr/ingres/source/equel/grammar.y line 142, 814, 838
- in /usr/ingres/source/equel/include.c line 136

equate_lines defined in line 226; used 6 times

- in /usr/ingres/source/equel/grammar.y line 127, 477, 490
- in /usr/ingres/source/equel/include.c line 137, 186
- in /usr/ingres/source/equel/yylex.c line 134

puts defined in line 432; used 2 times

- in line 409-414(2)

w_con defined in line 55; used 9 times

- in /usr/ingres/source/equel/grammar.y line 286, 693, 709, 788, 865, 895-901(4)

w_file defined in line 267; used 4 times

- in line 243, 257
- in /usr/ingres/source/equel/grammar.y line 472, 488

w_flush defined in line 254; used 2 times

- in /usr/ingres/source/equel/grammar.y line 436-438(2)

w_key defined in line 165; used 63 times

- in line 62, 102, 153, 276-279(2)
- in /usr/ingres/source/equel/display.c line 277
- in /usr/ingres/source/equel/grammar.y line 292, 319-325(4), 449, 537, 549, 558, 687, 776, 816-818(2), 835, 919-922(2), 938-941(2), 949-952(2), 962, 970, 977, 984-994(3), 1002, 1009, 1016, 1023, 1030, 1037, 1044-1045(2), 1058, 1068, 1074, 1081, 1088, 1095-1096(2), 1103, 1110, 1117, 1124, 1131, 1138, 1144, 1152, 1161, 1170, 1184, 1204-1207(2), 1221, 1228-1231(2)

w_new defined in line 180; used 10 times

- in line 105-110(2), 242, 256
- in /usr/ingres/source/equel/grammar.y line 409, 442, 471, 487, 496, 1051

w_op defined in line 72; used 65 times

- in line 107, 116-140(7), 184, 198, 211, 244, 258, 275
- in /usr/ingres/source/equel/display.c line 273, 400
- in /usr/ingres/source/equel/grammar.y line 138-143(2), 150, 177-180(2), 414-425(4), 465-467(2), 473-483(4), 489, 510-515(2), 562, 571, 736, 813, 820-822(2), 839-841(2), 925-935(5), 944-946(2), 1065, 1173-1176(2), 1192, 1198-1201(2), 1210, 1218
- in /usr/ingres/source/equel/include.c line 188-189(2)
- in /usr/ingres/source/equel/retrieve.c line 156-163(6)

w_raw defined in line 371; used 18 times

- in line 75, 169-170(2), 230, 302-306(2), 315-322(3), 329-336(3), 342-347(3)
- in /usr/ingres/source/equel/yylex.c line 138-139(2), 145

w_string defined in line 291; used 4 times

- in line 60, 273
- in /usr/ingres/source/equel/grammar.y line 424, 771

w_sync defined in line 240; used 3 times

- in /usr/ingres/source/equel/grammar.y line 133, 443, 497

w_var defined in line 89; used 7 times

- in /usr/ingres/source/equel/grammar.y line 295-298(2), 394, 699, 764-768(2), 796

Last modified: 1995-02-05 Generated: 2016-12-26 | Generated by src2html V0.67 page hit count: 1539 |