1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 23 /* All Rights Reserved */ 24 25 26 #ident "%Z%%M% %I% %E% SMI" 27 28 #include "awk.h" 29 /* tmaino #define NULL 0 */ 30 #define XNULL "(null)" 31 32 33 struct xx 34 { int token; 35 char *name; 36 char *pname; 37 } proc[] = { 38 { PROGRAM, "program", XNULL}, 39 { BOR, "boolop", " || "}, 40 { AND, "boolop", " && "}, 41 { NOT, "boolop", " !"}, 42 { NE, "relop", " != "}, 43 { EQ, "relop", " == "}, 44 { LE, "relop", " <= "}, 45 { LT, "relop", " < "}, 46 { GE, "relop", " >= "}, 47 { GT, "relop", " > "}, 48 { ARRAY, "array", XNULL}, 49 { INDIRECT, "indirect", "$("}, 50 { SUBSTR, "substr", "substr"}, 51 { INDEX, "sindex", "sindex"}, 52 { SPRINTF, "asprintf", "sprintf "}, 53 { ADD, "arith", " + "}, 54 { MINUS, "arith", " - "}, 55 { MULT, "arith", " * "}, 56 { DIVIDE, "arith", " / "}, 57 { MOD, "arith", " % "}, 58 { UMINUS, "arith", " -"}, 59 { PREINCR, "incrdecr", "++"}, 60 { POSTINCR, "incrdecr", "++"}, 61 { PREDECR, "incrdecr", "--"}, 62 { POSTDECR, "incrdecr", "--"}, 63 { CAT, "cat", " "}, 64 { PASTAT, "pastat", XNULL}, 65 { PASTAT2, "dopa2", XNULL}, 66 { MATCH, "matchop", " ~ "}, 67 { NOTMATCH, "matchop", " !~ "}, 68 { PRINTF, "aprintf", "printf"}, 69 { PRINT, "print", "print"}, 70 { SPLIT, "split", "split"}, 71 { ASSIGN, "assign", " = "}, 72 { ADDEQ, "assign", " += "}, 73 { SUBEQ, "assign", " -= "}, 74 { MULTEQ, "assign", " *= "}, 75 { DIVEQ, "assign", " /= "}, 76 { MODEQ, "assign", " %= "}, 77 { IF, "ifstat", "if("}, 78 { WHILE, "whilestat", "while("}, 79 { FOR, "forstat", "for("}, 80 { IN, "instat", "instat"}, 81 { NEXT, "jump", "next"}, 82 { EXIT, "jump", "exit"}, 83 { BREAK, "jump", "break"}, 84 { CONTINUE, "jump", "continue"}, 85 { FNCN, "fncn", "fncn"}, 86 { GETLINE, "getline", "getline"}, 87 { 0, ""}, 88 }; 89 #define SIZE LASTTOKEN - FIRSTTOKEN 90 char *table[SIZE]; 91 char *names[SIZE]; 92 93 94 main() 95 { 96 struct xx *p; 97 int i; 98 99 100 printf("#include \"awk.def\"\n"); 101 printf("CELL *nullproc();\n"); 102 for (i = SIZE; --i >= 0; /* dummy */) 103 names[i] = ""; 104 for (p=proc; p->token!=0; p++) 105 if (p==proc || strcmp(p->name, (p-1)->name)) 106 printf("extern CELL *%s();\n", p->name); 107 for (p=proc; p->token!=0; p++) 108 table[p->token-FIRSTTOKEN] = p->name; 109 printf("CELL *(*proctab[%d])() = {\n", SIZE); 110 for (i=0; i<SIZE; i++) 111 if (table[i]==0) 112 printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN)); 113 else 114 printf("/*%s*/\t%s,\n", tokname(i+FIRSTTOKEN), table[i]); 115 printf("};\n"); 116 printf("char *printname[%d] = {\n", SIZE); 117 for (p=proc; p->token!=0; p++) 118 names[p->token-FIRSTTOKEN] = p->pname; 119 for (i=0; i<SIZE; i++) 120 printf("/*%s*/\t\"%s\",\n", tokname(i+FIRSTTOKEN), names[i]); 121 printf("};\n"); 122 exit(0); 123 } 124