1 /*-
2 * This code contains changes by
3 * Gunnar Ritter, Freiburg i. Br., Germany, 2002. All rights reserved.
4 *
5 * Conditions 1, 2, and 4 and the no-warranty notice below apply
6 * to these changes.
7 *
8 *
9 * Copyright (c) 1991
10 * The Regents of the University of California. All rights reserved.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * 3. All advertising materials mentioning features or use of this software
21 * must display the following acknowledgement:
22 * This product includes software developed by the University of
23 * California, Berkeley and its contributors.
24 * 4. Neither the name of the University nor the names of its contributors
25 * may be used to endorse or promote products derived from this software
26 * without specific prior written permission.
27 *
28 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
29 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
32 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 * SUCH DAMAGE.
39 *
40 *
41 * Copyright(C) Caldera International Inc. 2001-2002. All rights reserved.
42 *
43 * Redistribution and use in source and binary forms, with or without
44 * modification, are permitted provided that the following conditions
45 * are met:
46 * Redistributions of source code and documentation must retain the
47 * above copyright notice, this list of conditions and the following
48 * disclaimer.
49 * Redistributions in binary form must reproduce the above copyright
50 * notice, this list of conditions and the following disclaimer in the
51 * documentation and/or other materials provided with the distribution.
52 * All advertising materials mentioning features or use of this software
53 * must display the following acknowledgement:
54 * This product includes software developed or owned by Caldera
55 * International, Inc.
56 * Neither the name of Caldera International, Inc. nor the names of
57 * other contributors may be used to endorse or promote products
58 * derived from this software without specific prior written permission.
59 *
60 * USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA
61 * INTERNATIONAL, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR
62 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
63 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
64 * ARE DISCLAIMED. IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE
65 * LIABLE FOR ANY DIRECT, INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR
66 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
67 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
68 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
69 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
70 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
71 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
72 */
73
74 #ifdef notdef
75 char copyright[] =
76 "Copyright (c) 1991 The Regents of the University of California.\n\
77 All rights reserved.\n";
78 #endif
79
80 /* from 4.4BSD /usr/src/old/awk/proc.c 4.4 (Berkeley) 4/17/91 */
81 /* Sccsid @(#)proc.c 1.8 (gritter) 12/25/06> */
82
83 #include "awk.h"
84 #include <stdio.h>
85 #include <string.h>
86 #include <stdlib.h>
87 struct xx
88 { int token;
89 const char *name;
90 const char *pname;
91 } proc[] = {
92 { PROGRAM, "program", NULL},
93 { BOR, "boolop", " || "},
94 { AND, "boolop", " && "},
95 { NOT, "boolop", " !"},
96 { NE, "relop", " != "},
97 { EQ, "relop", " == "},
98 { LE, "relop", " <= "},
99 { LT, "relop", " < "},
100 { GE, "relop", " >= "},
101 { GT, "relop", " > "},
102 { ARRAY, "array", NULL},
103 { INDIRECT, "indirect", "$("},
104 { SUBSTR, "substr", "substr"},
105 { INDEX, "sindex", "sindex"},
106 { SPRINTF, "awsprintf", "sprintf "},
107 { ADD, "arith", " + "},
108 { MINUS, "arith", " - "},
109 { MULT, "arith", " * "},
110 { DIVIDE, "arith", " / "},
111 { MOD, "arith", " % "},
112 { UMINUS, "arith", " -"},
113 { PREINCR, "incrdecr", "++"},
114 { POSTINCR, "incrdecr", "++"},
115 { PREDECR, "incrdecr", "--"},
116 { POSTDECR, "incrdecr", "--"},
117 { CAT, "cat", " "},
118 { PASTAT, "pastat", NULL},
119 { PASTAT2, "dopa2", NULL},
120 { MATCH, "matchop", " ~ "},
121 { NOTMATCH, "matchop", " !~ "},
122 { PRINTF, "aprintf", "printf"},
123 { PRINT, "print", "print"},
124 { SPLIT, "split", "split"},
125 { ASSIGN, "assign", " = "},
126 { ADDEQ, "assign", " += "},
127 { SUBEQ, "assign", " -= "},
128 { MULTEQ, "assign", " *= "},
129 { DIVEQ, "assign", " /= "},
130 { MODEQ, "assign", " %= "},
131 { IF, "ifstat", "if("},
132 { WHILE, "whilestat", "while("},
133 { FOR, "forstat", "for("},
134 { IN, "instat", "instat"},
135 { NEXT, "jump", "next"},
136 { EXIT, "jump", "exit"},
137 { BREAK, "jump", "break"},
138 { CONTINUE, "jump", "continue"},
139 { FNCN, "fncn", "fncn"},
140 { GETLINE, "getline", "getline"},
141 { 0, ""},
142 };
143 #define SIZE LASTTOKEN - FIRSTTOKEN
144 const char *table[SIZE];
145 const char *names[SIZE];
146
147 extern char *tokname(int);
148
149 int
main(void)150 main(void)
151 { struct xx *p;
152 int i;
153 printf("#include \"awk.def\"\n");
154 printf("obj nullproc(node **, int);\n");
155 for(p=proc;p->token!=0;p++)
156 if(p==proc || strcmp(p->name, (p-1)->name))
157 printf("extern obj %s(node **, int);\n",p->name);
158 for(p=proc;p->token!=0;p++)
159 table[p->token-FIRSTTOKEN]=p->name;
160 printf("obj (*proctab[%d])(node **, int) = {\n", SIZE);
161 for(i=0;i<SIZE;i++)
162 if(table[i]==0) printf("/*%s*/\tnullproc,\n",tokname(i+FIRSTTOKEN));
163 else printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
164 printf("};\n");
165 printf("char *printname[%d] = {\n", SIZE);
166 for(p=proc; p->token!=0; p++)
167 names[p->token-FIRSTTOKEN] = p->pname;
168 for(i=0; i<SIZE; i++)
169 printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),
170 names[i]?names[i]:"");
171 printf("};\n");
172 exit(0);
173 }
174
175 #include "token.c"
176