|
|
1.1 ! root 1: /* ! 2: * request.c ! 3: * Nroff/Troff. ! 4: * Request handler. ! 5: */ ! 6: ! 7: #include <ctype.h> ! 8: #include "roff.h" ! 9: ! 10: /* ! 11: * This is called when the user gives a request. ! 12: * It collects the arguments and dispatches the request. ! 13: * Store the request line into miscbuf[], ! 14: * and also set up an arg list to pass to the request. ! 15: */ ! 16: request() ! 17: { ! 18: REG *rp; ! 19: int inqflag, argc, i; ! 20: register int c; ! 21: char *argp[ARGSIZE], *abuf, *abufend, name[2], *mpend; ! 22: register char *ap, *mp; ! 23: ! 24: if (isascii(c = getf(0)) && isspace(c)) { ! 25: while (c != '\n') ! 26: c = getf(0); ! 27: return; ! 28: } ! 29: oldbracelevel = bracelevel; ! 30: argc = 0; ! 31: for (i = 0; i < ARGSIZE; i++) ! 32: argp[i] = ""; ! 33: ap = abuf = nalloc(ABFSIZE); ! 34: abufend = &abuf[ABFSIZE-1]; ! 35: mp = miscbuf; ! 36: mpend = &mp[MSCSIZE-1]; ! 37: while (c != '\n') { ! 38: if (argc < ARGSIZE) ! 39: argp[argc++] = ap; ! 40: inqflag = 0; ! 41: while ((c != '\n') && (inqflag || !isascii(c) || !isspace(c))) { ! 42: if (c == '"' && escflag == 0) ! 43: inqflag ^= 1; ! 44: else { ! 45: if (ap >= abufend) ! 46: break; ! 47: if (c != EEND) ! 48: *ap++ = c; ! 49: } ! 50: if (mp >= mpend) ! 51: break; ! 52: *mp++ = c; ! 53: c = getf(0); ! 54: } ! 55: while (c != '\n' && isascii(c) && isspace(c)) { ! 56: if (ap >= abufend || mp >= mpend) { ! 57: printe("arguments too long"); ! 58: nfree(abuf); ! 59: while (c != '\n') ! 60: c = getf(0); ! 61: return; ! 62: } ! 63: *mp++ = c; ! 64: c = getf(0); ! 65: } ! 66: *ap++ = '\0'; ! 67: } ! 68: *mp++ = '\0'; ! 69: #if (DDEBUG != 0) ! 70: { ! 71: char **dap; ! 72: dap = &argp[1]; ! 73: printd(DBGREQX, "request %s", *dap++); ! 74: while (*dap != NULL) ! 75: printd(DBGREQX, " %s", *dap++); ! 76: printd(DBGREQX, "\n"); ! 77: } ! 78: #endif ! 79: argname(argp[0], name); ! 80: if (dflag) ! 81: fprintf(stderr, "%s\n", miscbuf); ! 82: if ((rp = findreg(name, RTEXT)) == NULL) ! 83: printe("request '%s' not found", argp[0]); ! 84: else { ! 85: if (rp->t_reg.r_macd.r_div.m_type == MREQS) ! 86: (*rp->t_reg.r_macd.r_div.m_func)(argc, argp); ! 87: else { ! 88: if (adstreg(rp) != 0) { ! 89: strp->x1.s_argc = argc; ! 90: for (i = 0; i < ARGSIZE; i++) ! 91: strp->x1.s_argp[i] = argp[i]; ! 92: strp->x1.s_abuf = abuf; ! 93: } ! 94: return; ! 95: } ! 96: } ! 97: nfree(abuf); ! 98: } ! 99: ! 100: /* ! 101: * Store the next argument from line 'lp' in argument buffer 'ap'. ! 102: * 'n' is the length of the buffer. ! 103: * Skip trailing spaces and return the new line pointer. ! 104: */ ! 105: char * ! 106: nextarg(lp, ap, n) register char *lp, *ap; int n; ! 107: { ! 108: register char *apend; ! 109: ! 110: apend = (ap == NULL) ? ap : &ap[n-1]; ! 111: while (!isascii(*lp) || !isspace(*lp)) { ! 112: if (*lp == '\0') ! 113: break; ! 114: if (ap < apend) ! 115: *ap++ = *lp; ! 116: lp++; ! 117: } ! 118: if (ap != NULL) ! 119: *ap = '\0'; ! 120: while (isascii(*lp) && isspace(*lp)) ! 121: lp++; ! 122: return lp; ! 123: } ! 124: ! 125: /* end of request.c */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.