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

1.1       root        1: # include      <ingres.h>
                      2: # include      <aux.h>
                      3: # include      <tree.h>
                      4: # include      "parser.h"
                      5: # include      <catalog.h>
                      6: # include      <pv.h>
                      7: # include      <symbol.h>
                      8: # include      <sccs.h>
                      9: 
                     10: SCCSID(@(#)par_util.c  7.2     5/31/83)
                     11: 
                     12: /*
                     13: **  PAR_UTIL -- parser utility functions
                     14: **
                     15: **     These functions are generally unrelated except that they are
                     16: **     needed to operate the parser and are too small to be considered
                     17: **     seperate modules.
                     18: **
                     19: **     Defined Constants:
                     20: **
                     21: **     Defines:
                     22: **             timeofday       -- convert arguments to minutes since midnight
                     23: **             tlprepend       -- attach two target list components
                     24: **             header          -- prints the header for a retrieve to terminal
                     25: **             patmat          -- converts pattern matching characters in a string
                     26: **             permcom         -- adds a command to the permit command vector
                     27: **
                     28: **     Requires:
                     29: **             nothing
                     30: **
                     31: **     Required By:
                     32: **             y.tab.c         -- the grammar
                     33: **
                     34: **     Files:
                     35: **             none
                     36: **
                     37: **     Compilation Flags:
                     38: **             none
                     39: **
                     40: **     Trace Flags:
                     41: **             PAR_UTIL.C ~~ 62, 63
                     42: **
                     43: **     History:
                     44: **             20 Dec 1978     -- written (rick)
                     45: */
                     46: 
                     47: 
                     48: 
                     49: 
                     50: 
                     51: 
                     52: 
                     53: 
                     54: /*
                     55: **  TIMEOFDAY -- convert 2 integers to minutes since midnight
                     56: **
                     57: **     Converts the hours and minutes parameters to minutes since midnight
                     58: **     performing some error (bounds) checking on the time.
                     59: **
                     60: **     To answer the question about what is midnight, both 0:00 and 24:00
                     61: **     are handled, but not the same way.  The former is zero minutes from
                     62: **     midnight and the latter is 1440 minutes from midnight.  (1440 is
                     63: **     24 hrs times 60 minutes, or 1 minute past the end of the day.)
                     64: **
                     65: **     Parameters:
                     66: **             hrs             -- an integer pointer to the hour
                     67: **             mins            -- an integer pointer to the minutes
                     68: **
                     69: **     Returns:
                     70: **             integer time since midnight
                     71: **
                     72: **     Side Effects:
                     73: **             may detect an error and call par_error which never returns.
                     74: **
                     75: **     Requires:
                     76: **             that the pointers be on integer boundaries
                     77: **
                     78: **     Called By:
                     79: **             y.tab.c         -- the grammar
                     80: **
                     81: **     Trace Flags:
                     82: **             none
                     83: **
                     84: **     Diagnostics:
                     85: **             BADHOURS        -- No such hour
                     86: **             BADMINS         -- No such minute
                     87: **             BAD24TIME       -- only 24:00 allowed
                     88: **
                     89: **     Syserrs:
                     90: **             none
                     91: **
                     92: **     History:
                     93: **             20 Dec 1978     -- written (rick)
                     94: */
                     95: timeofday(hrs, mins)
                     96: int    *hrs;
                     97: int    *mins;
                     98: {
                     99:        register int    h;
                    100:        register int    m;
                    101:        register int    rtval;
                    102: 
                    103:        h = *hrs;
                    104:        m = *mins;
                    105:        if (h > 24 || h < 0)
                    106:                /* no such hour */
                    107:                par_error(BADHOURS, WARN, iocv(h), 0);
                    108:        if (m > 59 || h < 0)
                    109:                /* no such minute */
                    110:                par_error(BADMINS, WARN, iocv(m), 0);
                    111:        if (h == 24)
                    112:        {
                    113:                h = 1440;
                    114:                if (m != 0)
                    115:                        /* can only use 24:00 */
                    116:                        par_error(BAD24TIME, WARN, iocv(m), 0);
                    117:        }
                    118:        rtval = (h * 60) + m;
                    119:        return (rtval);
                    120: }
                    121: 
                    122: 
                    123: /*
                    124: **  TLPREPEND -- combine two target list components
                    125: **
                    126: **     Attach two target list components to each other.
                    127: **     Neither component need be a single element.  The
                    128: **     'a' component will be attached at the extreme left
                    129: **     of the 'b' component.
                    130: **
                    131: **     Parameters:
                    132: **             a               -- tl component to attach
                    133: **             b               -- tl base for attaching
                    134: **
                    135: **     Returns:
                    136: **             nothing
                    137: **
                    138: **     Side Effects:
                    139: **             this routine is a side effect.  It attaches a to b
                    140: **             and when it returns a is attached to b but the pointer
                    141: **             to b never changes (neither does the pointer to a)
                    142: **
                    143: **     Requires:
                    144: **             nothing
                    145: **
                    146: **     Called By:
                    147: **             y.tab.c         -- the grammar
                    148: **
                    149: **     Trace Flags:
                    150: **             tlprepend ~~ 62.4
                    151: **
                    152: **     Diagnostics:
                    153: **             none
                    154: **
                    155: **     Syserrs:
                    156: **             none
                    157: **
                    158: **     History:
                    159: **             20 Dec 1978     -- written (rick)
                    160: */
                    161: 
                    162: QTREE *
                    163: tlprepend(a, b)
                    164: QTREE  *a;
                    165: QTREE  *b;
                    166: {
                    167:        register QTREE  *q;
                    168: 
                    169: # ifdef        xPTR1
                    170:        tTfp(62, 4, "tlprepend\n");
                    171: # endif
                    172: 
                    173:        /* scan to the left end of b */
                    174:        for (q = b; q->left != NULL; q = q->left)
                    175:                ;       /* no action */
                    176:        
                    177:        /* attach a to the end of b */
                    178:        q->left = a;
                    179:        return (b);
                    180: }
                    181: 
                    182: 
                    183: 
                    184: 
                    185: /*
                    186: **  HEADER.C -- print header for retrieve to terminal
                    187: **
                    188: **     "setp" to reconstruct the field names and types and passing
                    189: **     them to the normal printhdr etc.
                    190: **
                    191: **     Defines:
                    192: **             header()
                    193: **
                    194: **     Requires:
                    195: **             printhdr        - utility lib
                    196: **             beginhdr        - utility lib
                    197: **             printeol        - utility lib
                    198: **             printeh         - utility lib
                    199: **             atoi            - utility lib
                    200: **             Dc              - vble, number of params in list
                    201: **             Dv              - vble, list of parameters
                    202: **
                    203: **     Trace Flags:
                    204: **             none
                    205: **
                    206: **     History:
                    207: **             written (ancient history) (rick)
                    208: */
                    209: header(pv)
                    210: PARM   *pv;
                    211: {
                    212:        int     len;
                    213: 
                    214:        beginhdr();
                    215: 
                    216:        for (; pv->pv_type != PV_EOF; pv += 2)
                    217:        {
                    218:                len = atoi(&pv[1].pv_val.pv_str[1]);
                    219: 
                    220:                printhdr(pv[1].pv_val.pv_str[0] & I1MASK, len, pv->pv_val.pv_str);
                    221:        }
                    222:        printeol();
                    223:        printeh();
                    224: }
                    225: 
                    226: 
                    227: 
                    228: 
                    229: 
                    230: 
                    231: /*
                    232: **  PATMAT -- converts pattern matching characters in a string
                    233: **
                    234: **     Searches a string up to a null byte for one of the pattern
                    235: **     matching characters '*', '?', '[', and ']'. It then converts
                    236: **     these characters to their internal control character equivalents.
                    237: **
                    238: **     Parameters:
                    239: **             str             -- the string to search
                    240: **
                    241: **     Returns:
                    242: **             0               -- no pattern matching in string
                    243: **             1               -- at least one pattern matching character
                    244: **
                    245: **     Side Effects:
                    246: **             none
                    247: **
                    248: **     Requires:
                    249: **             symbol.h
                    250: **
                    251: **     Called By:
                    252: **             y.tab.c         -- grammar
                    253: **
                    254: **     Trace Flags:
                    255: **             none
                    256: **
                    257: **     Diagnostics:
                    258: **             none
                    259: **
                    260: **     Syserrs:
                    261: **             none
                    262: **
                    263: **     History:
                    264: **             written (ancient history) (rick)
                    265: */
                    266: 
                    267: 
                    268: /*
                    269: ** PATMAT
                    270: **     hunts through a string and converts the pattern matching
                    271: **     characters and replaces with the corresponding cntrl chars
                    272: */
                    273: patmat(str)
                    274: char   *str;
                    275: {
                    276:        register char   *p, *q;
                    277:        register int    flag;
                    278: 
                    279:        flag = 0;
                    280:        q = str;
                    281:        for (p = str; *p; p++)
                    282:        {
                    283:                if (*p == '\\')
                    284:                {
                    285:                        *q++ = *++p;
                    286:                        continue;
                    287:                }
                    288:                switch (*p)
                    289:                {
                    290:                  case '*':
                    291:                        *q++ = PAT_ANY;
                    292:                        flag = 1;
                    293:                        continue;
                    294: 
                    295:                  case '?':
                    296:                        *q++ = PAT_ONE;
                    297:                        flag = 1;
                    298:                        continue;
                    299: 
                    300:                  case '[':
                    301:                        *q++ = PAT_LBRAC;
                    302:                        flag = 1;
                    303:                        continue;
                    304: 
                    305:                  case ']':
                    306:                        *q++ = PAT_RBRAC;
                    307:                        flag = 1;
                    308:                        continue;
                    309:                }
                    310:                *q++ = *p;
                    311:        }
                    312:        *q = '\0';
                    313:        return (flag);
                    314: }
                    315: /*
                    316: **  PERMCOM -- map command allowed into protection catalog bits
                    317: **
                    318: **     translates the QMODE type symbols into the appropriate counterparts
                    319: **     for the permit statement allowed command vector.  The manifest
                    320: **     constants are designed to be inclusive or'd together to form a
                    321: **     composite bit map of OK actions.
                    322: **
                    323: **     Parameters:
                    324: **             a               -- the QMODE type symbol for the command to add
                    325: **
                    326: **     Returns:
                    327: **             none
                    328: **
                    329: **     Side Effects:
                    330: **             changes the variable Permcomd to reflect the additional permission
                    331: **
                    332: **     Requires:
                    333: **             Permcomd must be define globally
                    334: **             catalog.h for the proper constants
                    335: **
                    336: **     Called By:
                    337: **             y.tab.c         -- the grammar
                    338: **
                    339: **     Trace Flags:
                    340: **             none
                    341: **
                    342: **     Diagnostics:
                    343: **             none
                    344: **
                    345: **     Syserrs:
                    346: **             bad QMODE(%d)   -- a bad symbol has been passed for mapping
                    347: **
                    348: **     History:
                    349: **             28 Dec 1978     -- written (rick)
                    350: */
                    351: 
                    352: permcom(a)
                    353: int    a;
                    354: {
                    355:        extern int              Permcomd;
                    356:        switch (a)
                    357:        {
                    358:          case mdRETR:
                    359:                Permcomd |= PRO_RETR;
                    360:                break;
                    361: 
                    362:          case mdAPP:
                    363:                Permcomd |= PRO_APP;
                    364:                break;
                    365:        
                    366:          case mdREPL:
                    367:                Permcomd |= PRO_REPL;
                    368:                break;
                    369: 
                    370:          case mdDEL:
                    371:                Permcomd |= PRO_DEL;
                    372:                break;
                    373: 
                    374:          case -1:
                    375:                Permcomd |= 0177777;            /* all bits set */
                    376:                break;
                    377:        
                    378:          default:
                    379:                syserr("permcom: bad QMODE(%d)", a);
                    380:        }
                    381: }
                    382: 
                    383: char   *
                    384: makestr(str)
                    385: register char  *str;
                    386: {
                    387:        register char   *result;
                    388:        register int    len;
                    389: 
                    390:        len = length(str) + 1;
                    391: 
                    392:        result = (char *) need(Qbuf, len);
                    393: 
                    394:        bmove(str, result, len);
                    395: 
                    396:        return (result);
                    397: }

unix.superglobalmegacorp.com

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