xref: /onnv-gate/usr/src/cmd/oawk/makeprctab.c (revision 13093:48f2dbca79a2)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
58546SRoger.Faulkner@Sun.COM  * Common Development and Distribution License (the "License").
68546SRoger.Faulkner@Sun.COM  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
218546SRoger.Faulkner@Sun.COM 
22731Srobbin /*
23*13093SRoger.Faulkner@Oracle.COM  * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
24731Srobbin  */
25731Srobbin 
260Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
270Sstevel@tonic-gate /*	  All Rights Reserved  	*/
280Sstevel@tonic-gate 
290Sstevel@tonic-gate #include "awk.h"
300Sstevel@tonic-gate /* tmaino #define NULL 0 */
310Sstevel@tonic-gate #define	XNULL	"(null)"
320Sstevel@tonic-gate 
330Sstevel@tonic-gate 
340Sstevel@tonic-gate struct xx
350Sstevel@tonic-gate {	int token;
360Sstevel@tonic-gate 	char *name;
370Sstevel@tonic-gate 	char *pname;
380Sstevel@tonic-gate } proc[] = {
390Sstevel@tonic-gate 	{ PROGRAM, "program", XNULL},
400Sstevel@tonic-gate 	{ BOR, "boolop", " || "},
410Sstevel@tonic-gate 	{ AND, "boolop", " && "},
420Sstevel@tonic-gate 	{ NOT, "boolop", " !"},
430Sstevel@tonic-gate 	{ NE, "relop", " != "},
440Sstevel@tonic-gate 	{ EQ, "relop", " == "},
450Sstevel@tonic-gate 	{ LE, "relop", " <= "},
460Sstevel@tonic-gate 	{ LT, "relop", " < "},
470Sstevel@tonic-gate 	{ GE, "relop", " >= "},
480Sstevel@tonic-gate 	{ GT, "relop", " > "},
490Sstevel@tonic-gate 	{ ARRAY, "array", XNULL},
500Sstevel@tonic-gate 	{ INDIRECT, "indirect", "$("},
510Sstevel@tonic-gate 	{ SUBSTR, "substr", "substr"},
520Sstevel@tonic-gate 	{ INDEX, "sindex", "sindex"},
538546SRoger.Faulkner@Sun.COM 	{ SPRINTF, "a_sprintf", "sprintf "},
540Sstevel@tonic-gate 	{ ADD, "arith", " + "},
550Sstevel@tonic-gate 	{ MINUS, "arith", " - "},
560Sstevel@tonic-gate 	{ MULT, "arith", " * "},
570Sstevel@tonic-gate 	{ DIVIDE, "arith", " / "},
580Sstevel@tonic-gate 	{ MOD, "arith", " % "},
590Sstevel@tonic-gate 	{ UMINUS, "arith", " -"},
600Sstevel@tonic-gate 	{ PREINCR, "incrdecr", "++"},
610Sstevel@tonic-gate 	{ POSTINCR, "incrdecr", "++"},
620Sstevel@tonic-gate 	{ PREDECR, "incrdecr", "--"},
630Sstevel@tonic-gate 	{ POSTDECR, "incrdecr", "--"},
640Sstevel@tonic-gate 	{ CAT, "cat", " "},
650Sstevel@tonic-gate 	{ PASTAT, "pastat", XNULL},
660Sstevel@tonic-gate 	{ PASTAT2, "dopa2", XNULL},
670Sstevel@tonic-gate 	{ MATCH, "matchop", " ~ "},
680Sstevel@tonic-gate 	{ NOTMATCH, "matchop", " !~ "},
690Sstevel@tonic-gate 	{ PRINTF, "aprintf", "printf"},
700Sstevel@tonic-gate 	{ PRINT, "print", "print"},
710Sstevel@tonic-gate 	{ SPLIT, "split", "split"},
720Sstevel@tonic-gate 	{ ASSIGN, "assign", " = "},
730Sstevel@tonic-gate 	{ ADDEQ, "assign", " += "},
740Sstevel@tonic-gate 	{ SUBEQ, "assign", " -= "},
750Sstevel@tonic-gate 	{ MULTEQ, "assign", " *= "},
760Sstevel@tonic-gate 	{ DIVEQ, "assign", " /= "},
770Sstevel@tonic-gate 	{ MODEQ, "assign", " %= "},
780Sstevel@tonic-gate 	{ IF, "ifstat", "if("},
790Sstevel@tonic-gate 	{ WHILE, "whilestat", "while("},
800Sstevel@tonic-gate 	{ FOR, "forstat", "for("},
810Sstevel@tonic-gate 	{ IN, "instat", "instat"},
820Sstevel@tonic-gate 	{ NEXT, "jump", "next"},
830Sstevel@tonic-gate 	{ EXIT, "jump", "exit"},
840Sstevel@tonic-gate 	{ BREAK, "jump", "break"},
850Sstevel@tonic-gate 	{ CONTINUE, "jump", "continue"},
860Sstevel@tonic-gate 	{ FNCN, "fncn", "fncn"},
87*13093SRoger.Faulkner@Oracle.COM 	{ GETLINE, "getaline", "getline"},
880Sstevel@tonic-gate 	{ 0, ""},
890Sstevel@tonic-gate };
900Sstevel@tonic-gate #define	SIZE	LASTTOKEN - FIRSTTOKEN
910Sstevel@tonic-gate char *table[SIZE];
920Sstevel@tonic-gate char *names[SIZE];
930Sstevel@tonic-gate 
94731Srobbin int
main(void)95731Srobbin main(void)
960Sstevel@tonic-gate {
970Sstevel@tonic-gate 	struct xx *p;
980Sstevel@tonic-gate 	int i;
990Sstevel@tonic-gate 
1000Sstevel@tonic-gate 
1010Sstevel@tonic-gate 	printf("#include \"awk.def\"\n");
1020Sstevel@tonic-gate 	printf("CELL *nullproc();\n");
1030Sstevel@tonic-gate 	for (i = SIZE; --i >= 0; /* dummy */)
1040Sstevel@tonic-gate 		names[i] = "";
105731Srobbin 	for (p = proc; p->token != 0; p++)
106731Srobbin 		if (p == proc || strcmp(p->name, (p-1)->name))
1070Sstevel@tonic-gate 			printf("extern CELL *%s();\n", p->name);
108731Srobbin 	for (p = proc; p->token != 0; p++)
1090Sstevel@tonic-gate 		table[p->token-FIRSTTOKEN] = p->name;
1100Sstevel@tonic-gate 	printf("CELL *(*proctab[%d])() = {\n", SIZE);
111731Srobbin 	for (i = 0; i < SIZE; i++)
112731Srobbin 		if (table[i] == 0)
1130Sstevel@tonic-gate 			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
1140Sstevel@tonic-gate 		else
1150Sstevel@tonic-gate 		printf("/*%s*/\t%s,\n", tokname(i+FIRSTTOKEN), table[i]);
1160Sstevel@tonic-gate 	printf("};\n");
1170Sstevel@tonic-gate 	printf("char *printname[%d] = {\n", SIZE);
118731Srobbin 	for (p = proc; p->token != 0; p++)
1190Sstevel@tonic-gate 		names[p->token-FIRSTTOKEN] = p->pname;
120731Srobbin 	for (i = 0; i < SIZE; i++)
1210Sstevel@tonic-gate 		printf("/*%s*/\t\"%s\",\n", tokname(i+FIRSTTOKEN), names[i]);
1220Sstevel@tonic-gate 	printf("};\n");
123731Srobbin 	return (0);
1240Sstevel@tonic-gate }
125