BSD 4_4 release
[unix-history] / usr / src / old / awk / proc.c
CommitLineData
2791ff57
KB
1/*-
2 * Copyright (c) 1991 The Regents of the University of California.
3 * All rights reserved.
4 *
ad787160
C
5 * This module is believed to contain source code proprietary to AT&T.
6 * Use and redistribution is subject to the Berkeley Software License
7 * Agreement and your Software Agreement with AT&T (Western Electric).
2791ff57
KB
8 */
9
10#ifndef lint
11char copyright[] =
12"@(#) Copyright (c) 1991 The Regents of the University of California.\n\
13 All rights reserved.\n";
14#endif /* not lint */
15
b803c326 16#ifndef lint
ad787160 17static char sccsid[] = "@(#)proc.c 4.4 (Berkeley) 4/17/91";
2791ff57 18#endif /* not lint */
088c0627
KM
19
20#include "awk.h"
21#define NULL 0
22struct xx
23{ int token;
24 char *name;
25 char *pname;
26} proc[] = {
27 { PROGRAM, "program", NULL},
28 { BOR, "boolop", " || "},
29 { AND, "boolop", " && "},
30 { NOT, "boolop", " !"},
31 { NE, "relop", " != "},
32 { EQ, "relop", " == "},
33 { LE, "relop", " <= "},
34 { LT, "relop", " < "},
35 { GE, "relop", " >= "},
36 { GT, "relop", " > "},
37 { ARRAY, "array", NULL},
38 { INDIRECT, "indirect", "$("},
39 { SUBSTR, "substr", "substr"},
40 { INDEX, "sindex", "sindex"},
41 { SPRINTF, "asprintf", "sprintf "},
42 { ADD, "arith", " + "},
43 { MINUS, "arith", " - "},
44 { MULT, "arith", " * "},
45 { DIVIDE, "arith", " / "},
46 { MOD, "arith", " % "},
47 { UMINUS, "arith", " -"},
48 { PREINCR, "incrdecr", "++"},
49 { POSTINCR, "incrdecr", "++"},
50 { PREDECR, "incrdecr", "--"},
51 { POSTDECR, "incrdecr", "--"},
52 { CAT, "cat", " "},
53 { PASTAT, "pastat", NULL},
54 { PASTAT2, "dopa2", NULL},
55 { MATCH, "matchop", " ~ "},
56 { NOTMATCH, "matchop", " !~ "},
57 { PRINTF, "aprintf", "printf"},
58 { PRINT, "print", "print"},
59 { SPLIT, "split", "split"},
60 { ASSIGN, "assign", " = "},
61 { ADDEQ, "assign", " += "},
62 { SUBEQ, "assign", " -= "},
63 { MULTEQ, "assign", " *= "},
64 { DIVEQ, "assign", " /= "},
65 { MODEQ, "assign", " %= "},
66 { IF, "ifstat", "if("},
67 { WHILE, "whilestat", "while("},
68 { FOR, "forstat", "for("},
69 { IN, "instat", "instat"},
70 { NEXT, "jump", "next"},
71 { EXIT, "jump", "exit"},
72 { BREAK, "jump", "break"},
73 { CONTINUE, "jump", "continue"},
74 { FNCN, "fncn", "fncn"},
75 { GETLINE, "getline", "getline"},
76 { 0, ""},
77};
78#define SIZE LASTTOKEN - FIRSTTOKEN
79char *table[SIZE];
80char *names[SIZE];
81main()
82{ struct xx *p;
83 int i;
84 printf("#include \"awk.def\"\n");
85 printf("obj nullproc();\n");
86 for(p=proc;p->token!=0;p++)
87 if(p==proc || strcmp(p->name, (p-1)->name))
88 printf("extern obj %s();\n",p->name);
89 for(p=proc;p->token!=0;p++)
90 table[p->token-FIRSTTOKEN]=p->name;
91 printf("obj (*proctab[%d])() = {\n", SIZE);
92 for(i=0;i<SIZE;i++)
93 if(table[i]==0) printf("/*%s*/\tnullproc,\n",tokname(i+FIRSTTOKEN));
94 else printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
95 printf("};\n");
96 printf("char *printname[%d] = {\n", SIZE);
97 for(p=proc; p->token!=0; p++)
98 names[p->token-FIRSTTOKEN] = p->pname;
99 for(i=0; i<SIZE; i++)
c48090b0
SL
100 printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),
101 names[i]?names[i]:"");
088c0627
KM
102 printf("};\n");
103 exit(0);
104}