Print this page
3731 Update nawk to version 20121220

*** 21,44 **** /* * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved. */ ! /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ ! /* All Rights Reserved */ ! ! #include <stdio.h> ! #include <string.h> ! #include <stdlib.h> ! #include <libintl.h> #include "awk.h" #include "y.tab.h" struct xx { int token; ! char *name; ! char *pname; } proc[] = { { PROGRAM, "program", NULL }, { BOR, "boolop", " || " }, { AND, "boolop", " && " }, { NOT, "boolop", " !" }, --- 21,60 ---- /* * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved. */ ! /* ! * Copyright (C) Lucent Technologies 1997 ! * All Rights Reserved ! * ! * Permission to use, copy, modify, and distribute this software and ! * its documentation for any purpose and without fee is hereby ! * granted, provided that the above copyright notice appear in all ! * copies and that both that the copyright notice and this ! * permission notice and warranty disclaimer appear in supporting ! * documentation, and that the name Lucent Technologies or any of ! * its entities not be used in advertising or publicity pertaining ! * to distribution of the software without specific, written prior ! * permission. ! * ! * LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, ! * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. ! * IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY ! * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES ! * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER ! * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ! * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF ! * THIS SOFTWARE. ! */ #include "awk.h" #include "y.tab.h" struct xx { int token; ! const char *name; ! const char *pname; } proc[] = { { PROGRAM, "program", NULL }, { BOR, "boolop", " || " }, { AND, "boolop", " && " }, { NOT, "boolop", " !" },
*** 52,62 **** { INDIRECT, "indirect", "$(" }, { SUBSTR, "substr", "substr" }, { SUB, "sub", "sub" }, { GSUB, "gsub", "gsub" }, { INDEX, "sindex", "sindex" }, ! { SPRINTF, "a_sprintf", "sprintf " }, { ADD, "arith", " + " }, { MINUS, "arith", " - " }, { MULT, "arith", " * " }, { DIVIDE, "arith", " / " }, { MOD, "arith", " % " }, --- 68,78 ---- { INDIRECT, "indirect", "$(" }, { SUBSTR, "substr", "substr" }, { SUB, "sub", "sub" }, { GSUB, "gsub", "gsub" }, { INDEX, "sindex", "sindex" }, ! { SPRINTF, "awksprintf", "sprintf " }, { ADD, "arith", " + " }, { MINUS, "arith", " - " }, { MULT, "arith", " * " }, { DIVIDE, "arith", " / " }, { MOD, "arith", " % " },
*** 71,84 **** { PASTAT2, "dopa2", NULL }, { MATCH, "matchop", " ~ " }, { NOTMATCH, "matchop", " !~ " }, { MATCHFCN, "matchop", "matchop" }, { INTEST, "intest", "intest" }, ! { PRINTF, "aprintf", "printf" }, ! { PRINT, "print", "print" }, { CLOSE, "closefile", "closefile" }, ! { DELETE, "delete", "delete" }, { SPLIT, "split", "split" }, { ASSIGN, "assign", " = " }, { ADDEQ, "assign", " += " }, { SUBEQ, "assign", " -= " }, { MULTEQ, "assign", " *= " }, --- 87,100 ---- { PASTAT2, "dopa2", NULL }, { MATCH, "matchop", " ~ " }, { NOTMATCH, "matchop", " !~ " }, { MATCHFCN, "matchop", "matchop" }, { INTEST, "intest", "intest" }, ! { PRINTF, "awkprintf", "printf" }, ! { PRINT, "printstat", "print" }, { CLOSE, "closefile", "closefile" }, ! { DELETE, "awkdelete", "awkdelete" }, { SPLIT, "split", "split" }, { ASSIGN, "assign", " = " }, { ADDEQ, "assign", " += " }, { SUBEQ, "assign", " -= " }, { MULTEQ, "assign", " *= " },
*** 90,166 **** { WHILE, "whilestat", "while(" }, { FOR, "forstat", "for(" }, { DO, "dostat", "do" }, { IN, "instat", "instat" }, { NEXT, "jump", "next" }, { EXIT, "jump", "exit" }, { BREAK, "jump", "break" }, { CONTINUE, "jump", "continue" }, { RETURN, "jump", "ret" }, { BLTIN, "bltin", "bltin" }, { CALL, "call", "call" }, { ARG, "arg", "arg" }, { VARNF, "getnf", "NF" }, ! { GETLINE, "getaline", "getline" }, { 0, "", "" }, }; ! #define SIZE LASTTOKEN - FIRSTTOKEN + 1 ! char *table[SIZE]; char *names[SIZE]; int ! main() { ! struct xx *p; int i, n, tok; char c; FILE *fp; ! char buf[100], name[100], def[100]; ! printf("#include \"awk.h\"\n"); ! printf("#include \"y.tab.h\"\n\n"); if ((fp = fopen("y.tab.h", "r")) == NULL) { ! fprintf(stderr, gettext("maketab can't open y.tab.h!\n")); exit(1); } ! printf("static uchar *printname[%d] = {\n", SIZE); i = 0; while (fgets(buf, sizeof (buf), fp) != NULL) { n = sscanf(buf, "%1c %s %s %d", &c, def, name, &tok); /* not a valid #define? */ ! if (c != '#' || n != 4 && strcmp(def, "define") != 0) continue; ! if (tok < FIRSTTOKEN || tok > LASTTOKEN) { ! fprintf(stderr, gettext("maketab funny token %d %s\n"), ! tok, buf); ! exit(1); ! } ! names[tok-FIRSTTOKEN] = malloc(strlen(name)+1); ! strcpy(names[tok-FIRSTTOKEN], name); ! printf("\t(uchar *) \"%s\",\t/* %d */\n", name, tok); i++; } ! printf("};\n\n"); for (p = proc; p->token != 0; p++) table[p->token-FIRSTTOKEN] = p->name; ! printf("\nCell *(*proctab[%d])() = {\n", SIZE); for (i = 0; i < SIZE; i++) if (table[i] == 0) ! printf("\tnullproc,\t/* %s */\n", names[i]); else ! printf("\t%s,\t/* %s */\n", table[i], names[i]); ! printf("};\n\n"); ! printf("uchar *\ntokname(int n)\n"); /* print a tokname() function */ ! printf("{\n"); ! printf(" static char buf[100];\n\n"); ! printf(" if (n < FIRSTTOKEN || n > LASTTOKEN) {\n"); ! printf(" (void) sprintf(buf, \"token %%d\", n);\n"); ! printf(" return ((uchar *)buf);\n"); ! printf(" }\n"); ! printf(" return printname[n-257];\n"); ! printf("}\n"); ! exit(0); } --- 106,187 ---- { WHILE, "whilestat", "while(" }, { FOR, "forstat", "for(" }, { DO, "dostat", "do" }, { IN, "instat", "instat" }, { NEXT, "jump", "next" }, + { NEXTFILE, "jump", "nextfile" }, { EXIT, "jump", "exit" }, { BREAK, "jump", "break" }, { CONTINUE, "jump", "continue" }, { RETURN, "jump", "ret" }, { BLTIN, "bltin", "bltin" }, { CALL, "call", "call" }, { ARG, "arg", "arg" }, { VARNF, "getnf", "NF" }, ! { GETLINE, "awkgetline", "getline" }, { 0, "", "" }, }; ! #define SIZE (LASTTOKEN - FIRSTTOKEN + 1) ! const char *table[SIZE]; char *names[SIZE]; + /* ARGSUSED */ int ! main(int argc, char *argv[]) { ! const struct xx *p; int i, n, tok; char c; FILE *fp; ! char buf[200], name[200], def[200]; ! (void) printf("#include <stdio.h>\n"); ! (void) printf("#include \"awk.h\"\n"); ! (void) printf("#include \"y.tab.h\"\n\n"); ! for (i = SIZE; --i >= 0; ) ! names[i] = ""; if ((fp = fopen("y.tab.h", "r")) == NULL) { ! (void) fprintf(stderr, ! gettext("maketab can't open y.tab.h!\n")); exit(1); } ! (void) printf("static uchar *printname[%d] = {\n", SIZE); i = 0; while (fgets(buf, sizeof (buf), fp) != NULL) { + /* LINTED E_SEC_SCANF_UNBOUNDED_COPY */ n = sscanf(buf, "%1c %s %s %d", &c, def, name, &tok); /* not a valid #define? */ ! if (c != '#' || (n != 4 && strcmp(def, "define") != 0)) continue; ! if (tok < FIRSTTOKEN || tok > LASTTOKEN) ! continue; ! names[tok-FIRSTTOKEN] = (char *)malloc(strlen(name)+1); ! (void) strcpy(names[tok-FIRSTTOKEN], name); ! (void) printf("\t(uchar *) \"%s\",\t/* %d */\n", name, tok); i++; } ! (void) printf("};\n\n"); for (p = proc; p->token != 0; p++) table[p->token-FIRSTTOKEN] = p->name; ! (void) printf("\nCell *(*proctab[%d])(Node **, int) = {\n", SIZE); for (i = 0; i < SIZE; i++) if (table[i] == 0) ! (void) printf("\tnullproc,\t/* %s */\n", names[i]); else ! (void) printf("\t%s,\t/* %s */\n", table[i], names[i]); ! (void) printf("};\n\n"); ! /* print a tokname() function */ ! (void) printf("uchar *\ntokname(int n)\n"); ! (void) printf("{\n"); ! (void) printf(" static char buf[100];\n\n"); ! (void) printf(" if (n < FIRSTTOKEN || n > LASTTOKEN) {\n"); ! (void) printf(" (void) sprintf(buf, \"token %%d\", n);\n"); ! (void) printf(" return ((uchar *)buf);\n"); ! (void) printf(" }\n"); ! (void) printf(" return printname[n-FIRSTTOKEN];\n"); ! (void) printf("}\n"); ! return (0); }