Annotation of 42BSD/ingres/source/equel/prtout.c, revision 1.1.1.1

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.