|
|
1.1 ! root 1: /* ! 2: Copyright (c) 1989 AT&T ! 3: All Rights Reserved ! 4: ! 5: THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T. ! 6: ! 7: The copyright notice above does not evidence any ! 8: actual or intended publication of such source code. ! 9: */ ! 10: ! 11: #include <stdio.h> ! 12: #include <string.h> ! 13: #include <stdlib.h> ! 14: #include "awk.h" ! 15: #include "y.tab.h" ! 16: ! 17: struct xx ! 18: { int token; ! 19: char *name; ! 20: char *pname; ! 21: } proc[] = { ! 22: { PROGRAM, "program", NULL }, ! 23: { BOR, "boolop", " || " }, ! 24: { AND, "boolop", " && " }, ! 25: { NOT, "boolop", " !" }, ! 26: { NE, "relop", " != " }, ! 27: { EQ, "relop", " == " }, ! 28: { LE, "relop", " <= " }, ! 29: { LT, "relop", " < " }, ! 30: { GE, "relop", " >= " }, ! 31: { GT, "relop", " > " }, ! 32: { ARRAY, "array", NULL }, ! 33: { INDIRECT, "indirect", "$(" }, ! 34: { SUBSTR, "substr", "substr" }, ! 35: { SUB, "sub", "sub" }, ! 36: { GSUB, "gsub", "gsub" }, ! 37: { INDEX, "sindex", "sindex" }, ! 38: { SPRINTF, "asprintf", "sprintf " }, ! 39: { ADD, "arith", " + " }, ! 40: { MINUS, "arith", " - " }, ! 41: { MULT, "arith", " * " }, ! 42: { DIVIDE, "arith", " / " }, ! 43: { MOD, "arith", " % " }, ! 44: { UMINUS, "arith", " -" }, ! 45: { POWER, "arith", " **" }, ! 46: { PREINCR, "incrdecr", "++" }, ! 47: { POSTINCR, "incrdecr", "++" }, ! 48: { PREDECR, "incrdecr", "--" }, ! 49: { POSTDECR, "incrdecr", "--" }, ! 50: { CAT, "cat", " " }, ! 51: { PASTAT, "pastat", NULL }, ! 52: { PASTAT2, "dopa2", NULL }, ! 53: { MATCH, "matchop", " ~ " }, ! 54: { NOTMATCH, "matchop", " !~ " }, ! 55: { MATCHFCN, "matchop", "matchop" }, ! 56: { INTEST, "intest", "intest" }, ! 57: { PRINTF, "aprintf", "printf" }, ! 58: { PRINT, "printstat", "print" }, ! 59: { CLOSE, "closefile", "closefile" }, ! 60: { DELETE, "adelete", "adelete" }, ! 61: { SPLIT, "split", "split" }, ! 62: { ASSIGN, "assign", " = " }, ! 63: { ADDEQ, "assign", " += " }, ! 64: { SUBEQ, "assign", " -= " }, ! 65: { MULTEQ, "assign", " *= " }, ! 66: { DIVEQ, "assign", " /= " }, ! 67: { MODEQ, "assign", " %= " }, ! 68: { POWEQ, "assign", " ^= " }, ! 69: { CONDEXPR, "condexpr", " ?: " }, ! 70: { IF, "ifstat", "if(" }, ! 71: { WHILE, "whilestat", "while(" }, ! 72: { FOR, "forstat", "for(" }, ! 73: { DO, "dostat", "do" }, ! 74: { IN, "instat", "instat" }, ! 75: { NEXT, "jump", "next" }, ! 76: { EXIT, "jump", "exit" }, ! 77: { BREAK, "jump", "break" }, ! 78: { CONTINUE, "jump", "continue" }, ! 79: { RETURN, "jump", "ret" }, ! 80: { BLTIN, "bltin", "bltin" }, ! 81: { CALL, "call", "call" }, ! 82: { ARG, "arg", "arg" }, ! 83: { VARNF, "getnf", "NF" }, ! 84: { GETLINE, "getline", "getline" }, ! 85: { 0, "", "" }, ! 86: }; ! 87: ! 88: #define SIZE LASTTOKEN - FIRSTTOKEN + 1 ! 89: char *table[SIZE]; ! 90: char *names[SIZE]; ! 91: ! 92: main(int argc, char *argv[]) ! 93: { ! 94: struct xx *p; ! 95: int i, n, tok; ! 96: char c; ! 97: FILE *fp; ! 98: char buf[100], name[100], def[100]; ! 99: ! 100: printf("#include <stdio.h>\n"); ! 101: printf("#include \"awk.h\"\n"); ! 102: printf("#include \"y.tab.h\"\n\n"); ! 103: for (i = SIZE; --i >= 0; ) ! 104: names[i] = ""; ! 105: ! 106: if ((fp = fopen("y.tab.h", "r")) == NULL) { ! 107: fprintf(stderr, "maketab can't open y.tab.h!\n"); ! 108: exit(1); ! 109: } ! 110: printf("static uchar *printname[%d] = {\n", SIZE); ! 111: i = 0; ! 112: while (fgets(buf, sizeof buf, fp) != NULL) { ! 113: n = sscanf(buf, "%1c %s %s %d", &c, def, name, &tok); ! 114: if (c != '#' || n != 4 && strcmp(def,"define") != 0) /* not a valid #define */ ! 115: continue; ! 116: if (tok < FIRSTTOKEN || tok > LASTTOKEN) { ! 117: fprintf(stderr, "maketab funny token %d %s\n", tok, buf); ! 118: exit(1); ! 119: } ! 120: names[tok-FIRSTTOKEN] = (char *) malloc(strlen(name)+1); ! 121: strcpy(names[tok-FIRSTTOKEN], name); ! 122: printf("\t(uchar *) \"%s\",\t/* %d */\n", name, tok); ! 123: i++; ! 124: } ! 125: printf("};\n\n"); ! 126: ! 127: for (p=proc; p->token!=0; p++) ! 128: table[p->token-FIRSTTOKEN] = p->name; ! 129: printf("\nCell *(*proctab[%d])(Node **, int) = {\n", SIZE); ! 130: for (i=0; i<SIZE; i++) ! 131: if (table[i]==0) ! 132: printf("\tnullproc,\t/* %s */\n", names[i]); ! 133: else ! 134: printf("\t%s,\t/* %s */\n", table[i], names[i]); ! 135: printf("};\n\n"); ! 136: ! 137: printf("uchar *tokname(int n)\n"); /* print a tokname() function */ ! 138: printf("{\n"); ! 139: printf(" static uchar buf[100];\n\n"); ! 140: printf(" if (n < FIRSTTOKEN || n > LASTTOKEN) {\n"); ! 141: printf(" sprintf(buf, \"token %%d\", n);\n"); ! 142: printf(" return buf;\n"); ! 143: printf(" }\n"); ! 144: printf(" return printname[n-FIRSTTOKEN];\n"); ! 145: printf("}\n"); ! 146: return 0; ! 147: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.