Print this page
3731 Update nawk to version 20121220
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/awk/maketab.c
+++ new/usr/src/cmd/awk/maketab.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
↓ open down ↓ |
15 lines elided |
↑ open up ↑ |
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21
22 22 /*
23 23 * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
24 24 */
25 25
26 -/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
27 -/* All Rights Reserved */
28 -
29 -#include <stdio.h>
30 -#include <string.h>
31 -#include <stdlib.h>
32 -#include <libintl.h>
26 +/*
27 + * Copyright (C) Lucent Technologies 1997
28 + * All Rights Reserved
29 + *
30 + * Permission to use, copy, modify, and distribute this software and
31 + * its documentation for any purpose and without fee is hereby
32 + * granted, provided that the above copyright notice appear in all
33 + * copies and that both that the copyright notice and this
34 + * permission notice and warranty disclaimer appear in supporting
35 + * documentation, and that the name Lucent Technologies or any of
36 + * its entities not be used in advertising or publicity pertaining
37 + * to distribution of the software without specific, written prior
38 + * permission.
39 + *
40 + * LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
41 + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
42 + * IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
43 + * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
44 + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
45 + * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
46 + * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
47 + * THIS SOFTWARE.
48 + */
33 49 #include "awk.h"
34 50 #include "y.tab.h"
35 51
36 52 struct xx {
37 53 int token;
38 - char *name;
39 - char *pname;
54 + const char *name;
55 + const char *pname;
40 56 } proc[] = {
41 57 { PROGRAM, "program", NULL },
42 58 { BOR, "boolop", " || " },
43 59 { AND, "boolop", " && " },
44 60 { NOT, "boolop", " !" },
45 61 { NE, "relop", " != " },
46 62 { EQ, "relop", " == " },
47 63 { LE, "relop", " <= " },
48 64 { LT, "relop", " < " },
49 65 { GE, "relop", " >= " },
50 66 { GT, "relop", " > " },
51 67 { ARRAY, "array", NULL },
52 68 { INDIRECT, "indirect", "$(" },
53 69 { SUBSTR, "substr", "substr" },
54 70 { SUB, "sub", "sub" },
55 71 { GSUB, "gsub", "gsub" },
56 72 { INDEX, "sindex", "sindex" },
57 - { SPRINTF, "a_sprintf", "sprintf " },
73 + { SPRINTF, "awksprintf", "sprintf " },
58 74 { ADD, "arith", " + " },
59 75 { MINUS, "arith", " - " },
60 76 { MULT, "arith", " * " },
61 77 { DIVIDE, "arith", " / " },
62 78 { MOD, "arith", " % " },
63 79 { UMINUS, "arith", " -" },
64 80 { POWER, "arith", " **" },
65 81 { PREINCR, "incrdecr", "++" },
66 82 { POSTINCR, "incrdecr", "++" },
67 83 { PREDECR, "incrdecr", "--" },
68 84 { POSTDECR, "incrdecr", "--" },
69 85 { CAT, "cat", " " },
70 86 { PASTAT, "pastat", NULL },
71 87 { PASTAT2, "dopa2", NULL },
72 88 { MATCH, "matchop", " ~ " },
73 89 { NOTMATCH, "matchop", " !~ " },
74 90 { MATCHFCN, "matchop", "matchop" },
75 91 { INTEST, "intest", "intest" },
76 - { PRINTF, "aprintf", "printf" },
77 - { PRINT, "print", "print" },
92 + { PRINTF, "awkprintf", "printf" },
93 + { PRINT, "printstat", "print" },
78 94 { CLOSE, "closefile", "closefile" },
79 - { DELETE, "delete", "delete" },
95 + { DELETE, "awkdelete", "awkdelete" },
80 96 { SPLIT, "split", "split" },
81 97 { ASSIGN, "assign", " = " },
82 98 { ADDEQ, "assign", " += " },
83 99 { SUBEQ, "assign", " -= " },
84 100 { MULTEQ, "assign", " *= " },
85 101 { DIVEQ, "assign", " /= " },
86 102 { MODEQ, "assign", " %= " },
87 103 { POWEQ, "assign", " ^= " },
88 104 { CONDEXPR, "condexpr", " ?: " },
89 105 { IF, "ifstat", "if(" },
90 106 { WHILE, "whilestat", "while(" },
91 107 { FOR, "forstat", "for(" },
92 108 { DO, "dostat", "do" },
93 109 { IN, "instat", "instat" },
94 110 { NEXT, "jump", "next" },
111 + { NEXTFILE, "jump", "nextfile" },
95 112 { EXIT, "jump", "exit" },
96 113 { BREAK, "jump", "break" },
97 114 { CONTINUE, "jump", "continue" },
98 115 { RETURN, "jump", "ret" },
99 116 { BLTIN, "bltin", "bltin" },
100 117 { CALL, "call", "call" },
101 118 { ARG, "arg", "arg" },
102 119 { VARNF, "getnf", "NF" },
103 - { GETLINE, "getaline", "getline" },
120 + { GETLINE, "awkgetline", "getline" },
104 121 { 0, "", "" },
105 122 };
106 123
107 -#define SIZE LASTTOKEN - FIRSTTOKEN + 1
108 -char *table[SIZE];
124 +#define SIZE (LASTTOKEN - FIRSTTOKEN + 1)
125 +const char *table[SIZE];
109 126 char *names[SIZE];
110 127
128 +/* ARGSUSED */
111 129 int
112 -main()
130 +main(int argc, char *argv[])
113 131 {
114 - struct xx *p;
132 + const struct xx *p;
115 133 int i, n, tok;
116 134 char c;
117 135 FILE *fp;
118 - char buf[100], name[100], def[100];
136 + char buf[200], name[200], def[200];
119 137
120 - printf("#include \"awk.h\"\n");
121 - printf("#include \"y.tab.h\"\n\n");
138 + (void) printf("#include <stdio.h>\n");
139 + (void) printf("#include \"awk.h\"\n");
140 + (void) printf("#include \"y.tab.h\"\n\n");
141 + for (i = SIZE; --i >= 0; )
142 + names[i] = "";
122 143
123 144 if ((fp = fopen("y.tab.h", "r")) == NULL) {
124 - fprintf(stderr, gettext("maketab can't open y.tab.h!\n"));
145 + (void) fprintf(stderr,
146 + gettext("maketab can't open y.tab.h!\n"));
125 147 exit(1);
126 148 }
127 - printf("static uchar *printname[%d] = {\n", SIZE);
149 + (void) printf("static uchar *printname[%d] = {\n", SIZE);
128 150 i = 0;
129 151 while (fgets(buf, sizeof (buf), fp) != NULL) {
152 + /* LINTED E_SEC_SCANF_UNBOUNDED_COPY */
130 153 n = sscanf(buf, "%1c %s %s %d", &c, def, name, &tok);
131 154 /* not a valid #define? */
132 - if (c != '#' || n != 4 && strcmp(def, "define") != 0)
155 + if (c != '#' || (n != 4 && strcmp(def, "define") != 0))
156 + continue;
157 + if (tok < FIRSTTOKEN || tok > LASTTOKEN)
133 158 continue;
134 - if (tok < FIRSTTOKEN || tok > LASTTOKEN) {
135 - fprintf(stderr, gettext("maketab funny token %d %s\n"),
136 - tok, buf);
137 - exit(1);
138 - }
139 - names[tok-FIRSTTOKEN] = malloc(strlen(name)+1);
140 - strcpy(names[tok-FIRSTTOKEN], name);
141 - printf("\t(uchar *) \"%s\",\t/* %d */\n", name, tok);
159 + names[tok-FIRSTTOKEN] = (char *)malloc(strlen(name)+1);
160 + (void) strcpy(names[tok-FIRSTTOKEN], name);
161 + (void) printf("\t(uchar *) \"%s\",\t/* %d */\n", name, tok);
142 162 i++;
143 163 }
144 - printf("};\n\n");
164 + (void) printf("};\n\n");
145 165
146 166 for (p = proc; p->token != 0; p++)
147 167 table[p->token-FIRSTTOKEN] = p->name;
148 - printf("\nCell *(*proctab[%d])() = {\n", SIZE);
168 + (void) printf("\nCell *(*proctab[%d])(Node **, int) = {\n", SIZE);
149 169 for (i = 0; i < SIZE; i++)
150 170 if (table[i] == 0)
151 - printf("\tnullproc,\t/* %s */\n", names[i]);
171 + (void) printf("\tnullproc,\t/* %s */\n", names[i]);
152 172 else
153 - printf("\t%s,\t/* %s */\n", table[i], names[i]);
154 - printf("};\n\n");
173 + (void) printf("\t%s,\t/* %s */\n", table[i], names[i]);
174 + (void) printf("};\n\n");
155 175
156 - printf("uchar *\ntokname(int n)\n"); /* print a tokname() function */
157 - printf("{\n");
158 - printf(" static char buf[100];\n\n");
159 - printf(" if (n < FIRSTTOKEN || n > LASTTOKEN) {\n");
160 - printf(" (void) sprintf(buf, \"token %%d\", n);\n");
161 - printf(" return ((uchar *)buf);\n");
162 - printf(" }\n");
163 - printf(" return printname[n-257];\n");
164 - printf("}\n");
165 - exit(0);
176 + /* print a tokname() function */
177 + (void) printf("uchar *\ntokname(int n)\n");
178 + (void) printf("{\n");
179 + (void) printf(" static char buf[100];\n\n");
180 + (void) printf(" if (n < FIRSTTOKEN || n > LASTTOKEN) {\n");
181 + (void) printf(" (void) sprintf(buf, \"token %%d\", n);\n");
182 + (void) printf(" return ((uchar *)buf);\n");
183 + (void) printf(" }\n");
184 + (void) printf(" return printname[n-FIRSTTOKEN];\n");
185 + (void) printf("}\n");
186 + return (0);
166 187 }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX