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

1.1       root        1: # include      "monitor.h"
                      2: # include      <ingres.h>
                      3: # include      <aux.h>
                      4: # include      <signal.h>
                      5: # include      <ctlmod.h>
                      6: # include      <sccs.h>
                      7: 
                      8: SCCSID(@(#)monitor.c   7.1     2/5/81)
                      9: 
                     10: 
                     11: 
                     12: /*
                     13: **  MONITOR
                     14: **
                     15: **     This routine maintains the logical query buffer in
                     16: **     /tmp/INGQxxxx.  It in general just does a copy from input
                     17: **     to query buffer, unless it gets a backslash escape character
                     18: **     or dollarsign escape character.
                     19: **     It recognizes the following escapes:
                     20: **
                     21: **     \a -- force append mode (no autoclear)
                     22: **     \b -- branch (within an include file only)
                     23: **     \c -- reserved for screen clear in geoquel
                     24: **     \d -- change working directory
                     25: **     \e -- enter editor
                     26: **     \g -- "GO": submit query to INGRES
                     27: **     \i -- include (switch input to external file)
                     28: **     \k -- mark (for \b)
                     29: **     \l -- list: print query buffer after macro evaluation
                     30: **     \p -- print query buffer (before macro evaluation)
                     31: **     \q -- quit ingres
                     32: **     \r -- force reset (clear) of query buffer
                     33: **     \s -- call shell
                     34: **     \t -- print current time
                     35: **     \v -- evaluate macros, but throw away result (for side effects)
                     36: **     \w -- write query buffer to external file
                     37: **     \$t -- change setting of trace flags
                     38: **     \$r -- reset system
                     39: **     \\ -- produce a single backslash in query buffer
                     40: **
                     41: **     Uses trace flag 2
                     42: */
                     43: 
                     44: /*
                     45: **  COMMAND TABLE
                     46: **     To add synonyms for commands, add entries to this table
                     47: */
                     48: 
                     49: struct cntrlwd
                     50: {
                     51:        char    *name;
                     52:        int     code;
                     53: };
                     54: 
                     55: struct cntrlwd Controlwords[] =
                     56: {
                     57:        "a",            C_APPEND,
                     58:        "append",       C_APPEND,
                     59:        "b",            C_BRANCH,
                     60:        "branch",       C_BRANCH,
                     61:        "cd",           C_CHDIR,
                     62:        "chdir",        C_CHDIR,
                     63:        "e",            C_EDIT,
                     64:        "ed",           C_EDIT,
                     65:        "edit",         C_EDIT,
                     66:        "editor",       C_EDIT,
                     67:        "g",            C_GO,
                     68:        "go",           C_GO,
                     69:        "i",            C_INCLUDE,
                     70:        "include",      C_INCLUDE,
                     71:        "read",         C_INCLUDE,
                     72:        "k",            C_MARK,
                     73:        "mark",         C_MARK,
                     74:        "l",            C_LIST,
                     75:        "list",         C_LIST,
                     76:        "p",            C_PRINT,
                     77:        "print",        C_PRINT,
                     78:        "q",            C_QUIT,
                     79:        "quit",         C_QUIT,
                     80:        "r",            C_RESET,
                     81:        "reset",        C_RESET,
                     82:        "s",            C_SHELL,
                     83:        "sh",           C_SHELL,
                     84:        "shell",        C_SHELL,
                     85:        "t",            C_TIME,
                     86:        "time",         C_TIME,
                     87:        "date",         C_TIME,
                     88:        "v",            C_EVAL,
                     89:        "eval",         C_EVAL,
                     90:        "w",            C_WRITE,
                     91:        "write",        C_WRITE,
                     92:        "$t",           C_SYSTRACE,
                     93:        "$trace",       C_SYSTRACE,
                     94:        "$r",           C_SYSRESET,
                     95:        "$reset",       C_SYSRESET,
                     96:        0
                     97: };
                     98: 
                     99: 
                    100: monitor()
                    101: {
                    102:        register char   chr;
                    103:        int             timevec[2];
                    104:        register int    controlno;
                    105:        extern jmp_buf  CmReset;
                    106:        extern          error();
                    107:        extern char     *Proc_name;
                    108:        extern int      RubLevel;
                    109:        extern          rubcatch();
                    110: 
                    111:        setjmp(CmReset);
                    112:        initbuf(Qbuf, QbufSize, ERR_QBUF, error);
                    113:        clrmem(&Ctx, sizeof Ctx);
                    114:        Ctx.ctx_cmark = Ctx.ctx_pmark = markbuf(Qbuf);
                    115:        Ctx.ctx_name = Proc_name = Cm.cm_myname;
                    116:        Ctx.ctx_tvect = tT = FuncVect[0]->fn_tvect;
                    117:        xwait();
                    118:        if (RubLevel >= 0)
                    119:                signal(SIGINT, rubcatch);
                    120: 
                    121:        while (chr = getch())
                    122:        {
                    123:                if (chr == '\\')
                    124:                {
                    125:                        /* process control sequence */
                    126:                        if ((controlno = getescape(1)) == 0)
                    127:                                continue;
                    128: 
                    129:                        switch (controlno)
                    130:                        {
                    131: 
                    132:                          case C_EDIT:
                    133:                                edit();
                    134:                                continue;
                    135: 
                    136:                          case C_PRINT:
                    137:                                print();
                    138:                                continue;
                    139: 
                    140:                          case C_LIST:
                    141:                                eval(1);
                    142:                                continue;
                    143: 
                    144:                          case C_EVAL:
                    145:                                eval(0);
                    146:                                Autoclear = TRUE;
                    147:                                continue;
                    148: 
                    149:                          case C_INCLUDE:
                    150:                                include(0);
                    151:                                cgprompt();
                    152:                                continue;
                    153: 
                    154:                          case C_WRITE:
                    155:                                writeout();
                    156:                                cgprompt();
                    157:                                continue;
                    158: 
                    159:                          case C_CHDIR:
                    160:                                newdirec();
                    161:                                cgprompt();
                    162:                                continue;
                    163: 
                    164:                          case C_RESET:
                    165:                                clear(1);
                    166:                                continue;
                    167: 
                    168:                          case C_GO:
                    169:                                go();
                    170:                                continue;
                    171: 
                    172:                          case C_QUIT:
                    173:                                clrline(1);
                    174:                                quit();
                    175: 
                    176:                          case C_SHELL:
                    177:                                shell();
                    178:                                continue;
                    179: 
                    180:                          case C_TIME:
                    181:                                time(timevec);
                    182:                                printf("%s", ctime(timevec));
                    183:                                clrline(0);
                    184:                                continue;
                    185: 
                    186:                          case C_APPEND:
                    187:                                Autoclear = 0;
                    188:                                clrline(0);
                    189:                                continue;
                    190: 
                    191:                          case C_MARK:
                    192:                                getfilenm();
                    193:                                prompt(0);
                    194:                                continue;
                    195: 
                    196:                          case C_BRANCH:
                    197:                                branch();
                    198:                                prompt(0);
                    199:                                continue;
                    200: 
                    201:                          case C_SYSTRACE:
                    202:                                trace();
                    203:                                prompt(0);
                    204:                                continue;
                    205: 
                    206:                          case C_SYSRESET:
                    207:                                reset();
                    208:                                clrline(0);
                    209:                                continue;
                    210: 
                    211:                          default:
                    212:                                syserr("monitor: bad code %d", controlno);
                    213:                        }
                    214:                }
                    215:                putch(chr);
                    216:        }
                    217: 
                    218:        if (Input == stdin)
                    219:        {
                    220:                if (Nodayfile >= 0)
                    221:                        printf("\n");
                    222:        }
                    223:        else
                    224:                fclose(Input);
                    225: }
                    226: 
                    227: getescape(copy)
                    228: int    copy;
                    229: {
                    230:        register struct cntrlwd *cw;
                    231:        register char           *word;
                    232:        char                    *getname();
                    233: 
                    234:        word = getname();
                    235:        for (cw = Controlwords; cw->name; cw++)
                    236:        {
                    237:                if (sequal(cw->name, word))
                    238:                        return (cw->code);
                    239:        }
                    240: 
                    241:        /* not found -- pass symbol through and return failure */
                    242:        if (copy == 0)
                    243:                return (0);
                    244:        putch('\\');
                    245:        while (*word != 0)
                    246:        {
                    247:                putch(*word++);
                    248:        }
                    249:        return (0);
                    250: }
                    251: 
                    252: char *
                    253: getname()
                    254: {
                    255:        register char   *p;
                    256:        static char     buf[41];
                    257:        register int    len;
                    258:        register char   c;
                    259: 
                    260:        p = buf;
                    261:        for (len = 0; len < 40; len++)
                    262:        {
                    263:                c = getch();
                    264:                if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
                    265:                {
                    266:                        *p++ = c;
                    267:                }
                    268:                else if ((len == 0) && (c == '$'))      /* system control command */
                    269:                {
                    270:                        *p++ = c;
                    271:                }
                    272:                else
                    273:                {
                    274:                        ungetc(c, Input);
                    275:                        break;
                    276:                }
                    277:        }
                    278: 
                    279:        *p = 0;
                    280:        return (buf);
                    281: }
                    282: 
                    283: 
                    284: 
                    285: putch(ch)
                    286: char   ch;
                    287: {
                    288:        register char   c;
                    289: 
                    290:        c = ch;
                    291: 
                    292:        Prompt = Newline = (c == '\n');
                    293:        if (c < 040 && c != '\n' && c != '\t')
                    294:        {
                    295:                printf("Funny character 0%o converted to blank\n", c);
                    296:                c = ' ';
                    297:        }
                    298:        prompt(0);
                    299:        if (Autoclear)
                    300:                clear(0);
                    301:        putc(c, Qryiop);
                    302:        Notnull++;
                    303: }

unix.superglobalmegacorp.com

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