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

Defined functions

getescape defined in line 191; used 2 times
getname defined in line 219; used 2 times
putch defined in line 247; used 3 times

Defined variables

Controlwords defined in line 47; used 1 times

Defined struct's

cntrlwd defined in line 41; used 4 times
Last modified: 1995-02-18
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 3240
Valid CSS Valid XHTML 1.0 Strict