|
|
1.1 ! root 1: #include "r.h" ! 2: #define BUFSIZE 5120 ! 3: char ibuf[BUFSIZE]; ! 4: char *ip = ibuf; ! 5: ! 6: ! 7: gtok(s) char *s; { /* get token into s */ ! 8: register c; ! 9: register char *p; ! 10: struct nlist *q; ! 11: ! 12: for(;;) { ! 13: p = s; ! 14: *p++ = c = getchr(); ! 15: if (isalpha(c) || isdigit(c)) { ! 16: while (isalpha(*p = getchr()) || isdigit(*p)) ! 17: p++; ! 18: putbak(*p); ! 19: *p = '\0'; ! 20: if ((q = lookup(s))->name != NULL && q->ydef == 0) { /* found but not keyword */ ! 21: if (q->def != fcnloc && q->def != FCN1loc) { /* not "function" */ ! 22: pbstr(q->def); ! 23: continue; ! 24: } ! 25: getfname(); /* recursive gtok */ ! 26: } ! 27: for (p=s; *p; p++) ! 28: if (isupper(*p)) ! 29: *p = tolower(*p); ! 30: for (p=s; *p; p++) ! 31: if (!isdigit(*p)) ! 32: return(LET); ! 33: return(DIG); ! 34: } ! 35: switch(c) { ! 36: case 0: ! 37: if (infptr > 0) { ! 38: fclose(infile[infptr]); ! 39: infptr--; ! 40: continue; ! 41: } ! 42: if (svargc > 1) { ! 43: svargc--; ! 44: svargv++; ! 45: if (infile[0] != stdin) ! 46: fclose(infile[0]); ! 47: if (!strcmp(*svargv, "-")) ! 48: infile[0] = stdin; ! 49: else if( (infile[0] = fopen(*svargv,"r")) == NULL ) ! 50: cant(*svargv); ! 51: linect[0] = 0; ! 52: curfile[0] = *svargv; ! 53: continue; ! 54: } ! 55: return(EOF); /* real eof */ ! 56: case ' ': ! 57: case '\t': ! 58: while ((c = getchr()) == ' ' || c == '\t') ! 59: ; /* skip others */ ! 60: if (c == COMMENT || c == '_') { ! 61: putbak(c); ! 62: continue; ! 63: } ! 64: if (c != '\n') { ! 65: putbak(c); ! 66: *p = '\0'; ! 67: return(' '); ! 68: } else { ! 69: *s = '\n'; ! 70: *(s+1) = '\0'; ! 71: return(*s); ! 72: } ! 73: case '_': ! 74: while ((c = getchr()) == ' ' || c == '\t') ! 75: ; ! 76: if (c == COMMENT) { ! 77: putbak(c); ! 78: gtok(s); /* recursive */ ! 79: } ! 80: else if (c != '\n') ! 81: putbak(c); ! 82: continue; ! 83: case '[': ! 84: *p = '\0'; ! 85: return('{'); ! 86: case ']': ! 87: *p = '\0'; ! 88: return('}'); ! 89: case '$': ! 90: case '\\': ! 91: if ((*p = getchr()) == '(' || *p == ')') { ! 92: putbak(*p=='(' ? '{' : '}'); ! 93: continue; ! 94: } ! 95: if (*p == '"' || *p == '\'') ! 96: p++; ! 97: else ! 98: putbak(*p); ! 99: *p = '\0'; ! 100: return('$'); ! 101: case COMMENT: ! 102: comment[comptr++] = 'c'; ! 103: while ((comment[comptr++] = getchr()) != '\n') ! 104: ; ! 105: flushcom(); ! 106: *s = '\n'; ! 107: *(s+1) = '\0'; ! 108: return(*s); ! 109: case '"': ! 110: case '\'': ! 111: for (; (*p = getchr()) != c; p++) { ! 112: if (*p == '\\') ! 113: *++p = getchr(); ! 114: if (*p == '\n') { ! 115: error("missing quote"); ! 116: putbak('\n'); ! 117: break; ! 118: } ! 119: } ! 120: *p++ = c; ! 121: *p = '\0'; ! 122: return(QUOTE); ! 123: case '%': ! 124: while ((*p = getchr()) != '\n') ! 125: p++; ! 126: putbak(*p); ! 127: *p = '\0'; ! 128: return('%'); ! 129: case '>': case '<': case '=': case '!': case '^': ! 130: return(peek(p, '=')); ! 131: case '&': ! 132: return(peek(p, '&')); ! 133: case '|': ! 134: return(peek(p, '|')); ! 135: default: ! 136: if (!isprint(c)) ! 137: continue; ! 138: case '\n': ! 139: *p = '\0'; ! 140: return(*s); ! 141: } ! 142: } ! 143: } ! 144: ! 145: gnbtok(s) char *s; { ! 146: register c; ! 147: while ((c = gtok(s)) == ' ' || c == '\t') ! 148: ; ! 149: return(c); ! 150: } ! 151: ! 152: getfname() { ! 153: while (gtok(fcname) == ' ') ! 154: ; ! 155: pbstr(fcname); ! 156: putbak(' '); ! 157: } ! 158: ! 159: peek(p, c1) char *p, c1; { ! 160: register c; ! 161: c = *(p-1); ! 162: if ((*p = getchr()) == c1) ! 163: p++; ! 164: else ! 165: putbak(*p); ! 166: *p = '\0'; ! 167: return(c); ! 168: } ! 169: ! 170: pbstr(str) ! 171: register char *str; ! 172: { ! 173: register char *p; ! 174: ! 175: p = str; ! 176: while (*p++); ! 177: --p; ! 178: if (ip >= &ibuf[BUFSIZE]) { ! 179: error("pushback overflow"); ! 180: exit(1); ! 181: } ! 182: while (p > str) ! 183: putbak(*--p); ! 184: } ! 185: ! 186: getchr() { ! 187: register c; ! 188: ! 189: if (ip > ibuf) ! 190: return(*--ip); ! 191: c = getc(infile[infptr]); ! 192: if (c == '\n') ! 193: linect[infptr]++; ! 194: if (c == EOF) ! 195: return(0); ! 196: return(c); ! 197: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.