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