Annotation of 42BSD/ingres/source/parser/control.c, revision 1.1.1.1

1.1       root        1: # include      <ingres.h>
                      2: # include      <aux.h>
                      3: # include      <symbol.h>
                      4: # include      <tree.h>
                      5: # include      "parser.h"
                      6: # include      <pv.h>
                      7: # include      "scanner.h"
                      8: # include      <sccs.h>
                      9: 
                     10: SCCSID(@(#)control.c   7.1     2/5/81)
                     11: 
                     12: /*
                     13: **  CONTROL.C -- -- collection of control functions for the parser
                     14: **
                     15: **     These routines administrate the operation of the parser for internal
                     16: **     sequencing.  There are 2 pairs of routines, one pair for each
                     17: **     quel statement, and one for each go-block, and there is one
                     18: **     routine to finish retrieve statements.
                     19: **
                     20: **     Defines:
                     21: **             startgo         -- initialize for a go-block
                     22: **             init_quelst     -- initialize for a quel statement
                     23: **             endquelst       -- clean up after a quel statement
                     24: **             endretrieve     -- clean up after a retrieve
                     25: **             endgo           -- clean up after a go-block
                     26: **
                     27: **     Trace Flags:
                     28: **             control.c ~~ 48, 49
                     29: **
                     30: **     History:
                     31: **             6 Jun 80 (jiw)          modified and redocumented for 6.3
                     32: **             15 Jan 79 (rick)        collected and documented more
                     33: **             ancient history
                     34: */
                     35: 
                     36: /*
                     37: ** INIT_QUELST -- set vbles for default mode before each quel statement
                     38: **
                     39: **     Parameters:
                     40: **             none
                     41: **
                     42: **     Returns:
                     43: **             nothing
                     44: **
                     45: **     Trace Flags:
                     46: **             init_quelst ~~ 48.0
                     47: */
                     48: 
                     49: int
                     50: init_quelst()
                     51: {
                     52:        extern int      neederr();
                     53:        extern          ack_err();
                     54:        extern int      Err_current;
                     55:        extern int      Patflag;
                     56:        extern int      Pars;
                     57:        extern int      Lcase;
                     58:        extern int      Dcase;
                     59:        extern int      Agflag;
                     60:        extern int      Opflag;
                     61:        extern int      Resrng;
                     62:        extern int      Qlflag;
                     63: 
                     64: #      ifdef   xPTR3
                     65:        tTfp(48, 0, "Init_quelst\n");
                     66: #      endif
                     67: 
                     68:        Err_current = 0;                        /* no error yet */
                     69:        Patflag = 0;                            /* reset pattern matching flag */
                     70:        Pars = 1;                               /* set scanner into "parser" mode */
                     71:        Lcase = Dcase;                          /* set case mapping to default */
                     72:        Agflag = 0;                             /* reset aggregate flag */
                     73:        Opflag = 0;                             /* reset qmode flag */
                     74:        Resrng = -1;                            /* reset result relation slot */
                     75:        Qlflag = 0;                             /* reset qualification flag */
                     76: 
                     77:        initp();                                /* initialize parameter vector */
                     78:        init_qt();                              /* assume we have qrytree */
                     79: 
                     80:        freesym();                              /* free symbol table space */
                     81:        rngreset();                             /* reset used bits in range tbl */
                     82: 
                     83:        return (1);
                     84: }
                     85: 
                     86: /*
                     87: ** ENDQUELST -- finish command checking and processing for each quel statement
                     88: **
                     89: **     Parameters:
                     90: **             op -- the type of query to finish up
                     91: **
                     92: **     Returns:
                     93: **             nothing
                     94: **
                     95: **     Trace Flags:
                     96: **             endquelst ~~ 48.4, 48.5
                     97: */
                     98: 
                     99: int
                    100: endquelst(op)
                    101: register int   op;
                    102: {
                    103:        register int                    i;
                    104:        char                            ibuf[2];        /* two char buffer for index keys */
                    105: 
                    106:        extern char                     *Indexspec;
                    107:        extern char                     *Indexname;
                    108:        extern int                      Equel;
                    109:        extern int                      Agflag;
                    110: 
                    111:        extern struct lasttok           *Lasttok;
                    112: 
                    113:        extern int                      yyerrflag;
                    114:        extern int                      Err_current;
                    115:        extern int                      Ingerr;
                    116:        extern int                      Err_fnd;
                    117: 
                    118:        extern DESC                     Attdes;
                    119:        extern DESC                     Reldesc;
                    120:        extern int                      Rsdmno;
                    121:        extern PARRNG                   Parrng[];
                    122:        extern int                      Resrng;
                    123: 
                    124:        extern int                      printtrail();
                    125: 
                    126: #      ifdef   xPTR3
                    127:        if (tTf(48, 4))
                    128:                prvect(0, getp());
                    129: #      endif
                    130: 
                    131:        /* check next token for GOVAL if the next token has been read */
                    132:        if (!Err_current && !yyerrflag)
                    133:                switch (op)
                    134:                {
                    135:                   case mdSAVE:
                    136:                   case mdCOPY:
                    137:                   case mdCREATE:
                    138: 
                    139: #                ifdef DISTRIB
                    140:                  case mdDCREATE:
                    141: #                endif
                    142: 
                    143:                  case mdINDEX:
                    144:                  case mdRANGE:
                    145:                        break;
                    146: 
                    147:                  default:
                    148:                        /* has vble ending and therefore must detect valid end of command */
                    149: #                      ifdef   xPTR3
                    150:                        tTfp(48, 5, "before NXTCMDERR\n");
                    151: #                      endif
                    152:                        if (Lastok.tokop != GOVAL)
                    153:                                /* next token not start of command */
                    154:                                par_error(NXTCMDERR, WARN, 0);
                    155:                        break;
                    156:                }
                    157: 
                    158:        if (Agflag >= MAXAGG)
                    159:                /* too many aggregates */
                    160:                par_error(AGGXTRA, WARN, 0);
                    161: 
                    162:        /* command ok so far, finish up */
                    163:        if (!Err_fnd)
                    164:        {
                    165:                switch (op)
                    166:                {
                    167:                  case mdINDEX:
                    168:                        if (tTf(48, 5))
                    169:                                printf("mdINDEX\n");
                    170:                        if (call(op, NULL) < 0)
                    171:                                ack_err();
                    172:                        if (tTf(48, 5))
                    173:                                printf("after call to call\n");
                    174: 
                    175:                        if (Ingerr)
                    176:                        {
                    177:                                if (tTf(48, 5))
                    178:                                        printf("Ingerr = %d\n", Ingerr);
                    179: 
                    180:                                endgo();
                    181: 
                    182:                                return (-1);
                    183:                        }
                    184: 
                    185:                        if (Indexspec)
                    186:                        {
                    187:                                initp();
                    188:                                setp(PV_STR, Indexname);        /* type */
                    189:                                setp(PV_STR, Indexspec);        /* specs */
                    190:                                setp(PV_STR, "num");
                    191:                                for (i = 1; i <= Rsdmno; i++)
                    192:                                {
                    193:                                        ibuf[0] = i & I1MASK;
                    194:                                        ibuf[1] = '\0';
                    195:                                        setp(PV_STR, ibuf);
                    196:                                }
                    197:                                if (call(mdMODIFY, NULL) < 0)
                    198:                                        ack_err();
                    199:                        }
                    200:                        break;
                    201: 
                    202:                  case mdRETR:
                    203:                  case mdRET_UNI:
                    204:                  case mdVIEW:
                    205:                        if (Resrng >= 0)                /* implies result reln */
                    206:                        {
                    207:                                if (calln(mdCREATE, NULL) < 0)
                    208:                                        ack_err();
                    209: 
                    210:                                cleanrel(&Attdes);
                    211: 
                    212:                                if ((i = openr(&Reldesc, -1, trim_relname(Parrng[Resrng].vardesc.reldum.relid))) < 0)
                    213:                                        syserr("result reln: error in openr '%d'", i);
                    214:                                
                    215:                                rngent(R_INTERNAL, "", &Reldesc);
                    216:                        }
                    217:                        else if (!Equel)
                    218:                                /* need to print header */
                    219:                                header(getp());
                    220: 
                    221:                        if (Ingerr)
                    222:                        {
                    223:                                /*
                    224:                                ** might be nice to back out the create already done
                    225:                                ** by this point so that the user doesn't need to
                    226:                                */
                    227:                                resetp();
                    228: 
                    229:                                endgo();        /* abort rest of go-block */
                    230: 
                    231:                                return (-1);
                    232:                        }
                    233:                        initp();
                    234:                        /* fall through */
                    235: 
                    236:                  case mdAPP:
                    237:                  case mdDEL:
                    238:                  case mdREPL:
                    239:                        if (op != mdVIEW)
                    240:                        {
                    241:                                call_tree(op, mdQRY, ack_err);
                    242: 
                    243:                                if (op == mdRETR || op == mdRET_UNI)
                    244:                                        endretrieve(ack_err);
                    245: 
                    246:                                break;
                    247:                        }
                    248: 
                    249: #                ifdef DISTRIB
                    250:                  case mdDISTRIB:
                    251:                        op = mdVIEW;
                    252: #                endif
                    253:                        /* else, do VIEW */
                    254:                        setp(PV_STR, trim_relname(Parrng[Resrng].vardesc.reldum.relid));
                    255: 
                    256:                  case mdINTEG:
                    257:                  case mdPROT:
                    258:                        call_tree(op, op, ack_err);
                    259:                        break;
                    260: 
                    261:                  case mdCREATE:
                    262: 
                    263: #                ifdef DISTRIB
                    264:                  case mdDCREATE:
                    265: #                endif
                    266: 
                    267:                  case mdDESTROY:
                    268:                  case mdMODIFY:
                    269: # ifdef        V6POINT3COMPAT
                    270:                        /* in this case, if an error in the dbu's will not */
                    271:                        /* cause other processing to halt */
                    272:                        call(op, NULL);
                    273: # else
                    274:                        if (call(op, NULL) < 0)
                    275:                                ack_err();
                    276: # endif
                    277:                        cleanrel(&Attdes);
                    278:                        break;
                    279: 
                    280:                  case mdCOPY:
                    281:                  case mdHELP:
                    282:                  case mdPRINT:
                    283:                  case mdSAVE:
                    284:                  case mdDISPLAY:
                    285:                  case mdREMQM:
                    286: # ifdef        V6POINT3COMPAT
                    287:                        call(op, NULL);
                    288: # else
                    289:                        if (call(op, NULL) < 0)
                    290:                                ack_err();
                    291: # endif
                    292:                        break;
                    293: 
                    294:                  case mdRANGE:
                    295:                        break;
                    296: 
                    297:                  default:
                    298:                        syserr("Endquelst: bad op %d", op);
                    299:                }
                    300:        }
                    301:     
                    302:        /* refresh relstat bits if necessary */
                    303:        rngfresh(op);
                    304:        if (init_quelst() < 0)
                    305:                return (-1);
                    306: 
                    307:        return (1);
                    308: }
                    309: 
                    310: /*
                    311: ** STARTGO -- do whatever needs doing to set up a go-block
                    312: **
                    313: **     Parameters:
                    314: **             none
                    315: **
                    316: **     Returns:
                    317: **             nothing
                    318: **
                    319: **     Trace Flags:
                    320: **             startgo ~~ 48.8
                    321: */
                    322: 
                    323: startgo()
                    324: {
                    325:        extern int      Err_fnd;
                    326:        extern int      Ing_err;
                    327:        extern int      yyline;
                    328: 
                    329: #      ifdef   xPTR3
                    330:        tTfp(48, 8, "startgo\n");
                    331: #      endif
                    332: 
                    333:        /* initialize for go-block */
                    334:        get_scan(PRIME);                /* prime the scanner input */
                    335:        Err_fnd = 0;            /* no errors have been found yet */
                    336:        Ingerr = 0;
                    337: 
                    338:        if (init_quelst() < 0)  /* most other init's are done for each statement */
                    339:                return (-1);
                    340: 
                    341:        yyline = 1;             /* reset line counter */
                    342: 
                    343:        return (1);
                    344: }
                    345: 
                    346: /*
                    347: **  ENDGO -- do whatever needs doing to clean up after a go block
                    348: **
                    349: **     Parameters:
                    350: **             none
                    351: **
                    352: **     Returns:
                    353: **             nothing
                    354: **
                    355: **     Trace Flags:
                    356: **             endgo ~~ 48.12
                    357: */
                    358: 
                    359: endgo()
                    360: {
                    361: #      ifdef   xPTR3
                    362:        tTfp(48, 12, "endgo\n");
                    363: #      endif
                    364: 
                    365:        if (!Equel && Err_fnd > 1)
                    366:                error(SUMMARY, iocv(Err_fnd), 0);
                    367: 
                    368:        get_scan(SYNC);
                    369: 
                    370:        resetp();
                    371: }
                    372: 
                    373: /*
                    374: **  ENDRETRIEVE -- finishes any sort of retrieve
                    375: **
                    376: **     Endretrieve either creates a result relation or prints a trailer
                    377: **
                    378: **     Parameters:
                    379: **             err_fcn -- function to pass to call
                    380: **
                    381: **     Returns:
                    382: **             nothing
                    383: **
                    384: **     Trace Flags:
                    385: **             endretrieve ~~ 48.14    
                    386: **
                    387: **     History:
                    388: **             June '80 -- (jiw) broken off from call_tree
                    389: */     
                    390: 
                    391: endretrieve(err_fcn)
                    392: int    (*err_fcn)();
                    393: {
                    394:        extern int              Resrng;
                    395:        extern char             *Relspec;
                    396:        extern PARRNG           Parrng[];
                    397:        extern int              Equel;
                    398: 
                    399:        if (Resrng >= 0)
                    400:        {
                    401:                if (Relspec)
                    402:                {
                    403:                        initp();
                    404: 
                    405:                        setp(PV_STR, trim_relname(Parrng[Resrng].vardesc.reldum.relid));
                    406:                        setp(PV_STR, Relspec);
                    407:                        if (call(mdMODIFY, err_fcn) < 0)
                    408:                                (*err_fcn)();
                    409:                }
                    410:        }
                    411:        else if (!Equel)
                    412:                printeh();
                    413: }
                    414: 
                    415: printtrail()
                    416: {
                    417:        extern int      Equel;
                    418: 
                    419:        if (!Equel)
                    420:                printeh();
                    421: 
                    422:        return (-1);
                    423: }

unix.superglobalmegacorp.com

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