diff options
Diffstat (limited to 'bin/sh/mknodes.c')
-rw-r--r-- | bin/sh/mknodes.c | 144 |
1 files changed, 94 insertions, 50 deletions
diff --git a/bin/sh/mknodes.c b/bin/sh/mknodes.c index 5ede3af..4ed88d0 100644 --- a/bin/sh/mknodes.c +++ b/bin/sh/mknodes.c @@ -33,7 +33,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id$ + * $Id: mknodes.c,v 1.2 1994/09/24 02:57:55 davidg Exp $ */ #ifndef lint @@ -43,7 +43,7 @@ static char copyright[] = #endif /* not lint */ #ifndef lint -static char sccsid[] = "@(#)mknodes.c 8.1 (Berkeley) 5/31/93"; +static char sccsid[] = "@(#)mknodes.c 8.2 (Berkeley) 5/4/95"; #endif /* not lint */ /* @@ -52,6 +52,13 @@ static char sccsid[] = "@(#)mknodes.c 8.1 (Berkeley) 5/31/93"; */ #include <stdio.h> +#include <stdlib.h> +#include <string.h> +#if __STDC__ +#include <stdarg.h> +#else +#include <varargs.h> +#endif #define MAXTYPES 50 /* max number of node types */ @@ -82,27 +89,35 @@ struct str { /* struct representing a node structure */ }; -int ntypes; /* number of node types */ -char *nodename[MAXTYPES]; /* names of the nodes */ -struct str *nodestr[MAXTYPES]; /* type of structure used by the node */ -int nstr; /* number of structures */ -struct str str[MAXTYPES]; /* the structures */ -struct str *curstr; /* current structure */ - - -FILE *infp = stdin; -char line[1024]; -int linno; -char *linep; - - -char *savestr(); -#define equal(s1, s2) (strcmp(s1, s2) == 0) +static int ntypes; /* number of node types */ +static char *nodename[MAXTYPES]; /* names of the nodes */ +static struct str *nodestr[MAXTYPES]; /* type of structure used by the node */ +static int nstr; /* number of structures */ +static struct str str[MAXTYPES]; /* the structures */ +static struct str *curstr; /* current structure */ +static FILE *infp = stdin; +static char line[1024]; +static int linno; +static char *linep; + +static void parsenode __P((void)); +static void parsefield __P((void)); +static void output __P((char *)); +static void outsizes __P((FILE *)); +static void outfunc __P((FILE *, int)); +static void indent __P((int, FILE *)); +static int nextfield __P((char *)); +static void skipbl __P((void)); +static int readline __P((void)); +static void error __P((const char *, ...)); +static char *savestr __P((const char *)); +int main(argc, argv) + int argc; char **argv; - { +{ if (argc != 3) error("usage: mknodes file\n"); if ((infp = fopen(argv[1], "r")) == NULL) @@ -119,7 +134,9 @@ main(argc, argv) -parsenode() { +static void +parsenode() +{ char name[BUFLEN]; char tag[BUFLEN]; struct str *sp; @@ -133,7 +150,7 @@ parsenode() { error("Garbage at end of line"); nodename[ntypes] = savestr(name); for (sp = str ; sp < str + nstr ; sp++) { - if (equal(sp->tag, tag)) + if (strcmp(sp->tag, tag) == 0) break; } if (sp >= str + nstr) { @@ -147,7 +164,9 @@ parsenode() { } -parsefield() { +static void +parsefield() +{ char name[BUFLEN]; char type[BUFLEN]; char decl[2 * BUFLEN]; @@ -161,21 +180,21 @@ parsefield() { error("No field type"); fp = &curstr->field[curstr->nfields]; fp->name = savestr(name); - if (equal(type, "nodeptr")) { + if (strcmp(type, "nodeptr") == 0) { fp->type = T_NODE; sprintf(decl, "union node *%s", name); - } else if (equal(type, "nodelist")) { + } else if (strcmp(type, "nodelist") == 0) { fp->type = T_NODELIST; sprintf(decl, "struct nodelist *%s", name); - } else if (equal(type, "string")) { + } else if (strcmp(type, "string") == 0) { fp->type = T_STRING; sprintf(decl, "char *%s", name); - } else if (equal(type, "int")) { + } else if (strcmp(type, "int") == 0) { fp->type = T_INT; sprintf(decl, "int %s", name); - } else if (equal(type, "other")) { + } else if (strcmp(type, "other") == 0) { fp->type = T_OTHER; - } else if (equal(type, "temp")) { + } else if (strcmp(type, "temp") == 0) { fp->type = T_TEMP; } else { error("Unknown type %s", type); @@ -198,9 +217,10 @@ char writer[] = "\ */\n\ \n"; +static void output(file) char *file; - { +{ FILE *hfile; FILE *cfile; FILE *patfile; @@ -247,11 +267,11 @@ output(file) fputs(writer, cfile); while (fgets(line, sizeof line, patfile) != NULL) { for (p = line ; *p == ' ' || *p == '\t' ; p++); - if (equal(p, "%SIZES\n")) + if (strcmp(p, "%SIZES\n") == 0) outsizes(cfile); - else if (equal(p, "%CALCSIZE\n")) + else if (strcmp(p, "%CALCSIZE\n") == 0) outfunc(cfile, 1); - else if (equal(p, "%COPY\n")) + else if (strcmp(p, "%COPY\n") == 0) outfunc(cfile, 0); else fputs(line, cfile); @@ -260,9 +280,10 @@ output(file) +static void outsizes(cfile) FILE *cfile; - { +{ int i; fprintf(cfile, "static const short nodesize[%d] = {\n", ntypes); @@ -273,9 +294,11 @@ outsizes(cfile) } +static void outfunc(cfile, calcsize) FILE *cfile; - { + int calcsize; +{ struct str *sp; struct field *fp; int i; @@ -352,9 +375,11 @@ outfunc(cfile, calcsize) } +static void indent(amount, fp) + int amount; FILE *fp; - { +{ while (amount >= 8) { putc('\t', fp); amount -= 8; @@ -365,10 +390,10 @@ indent(amount, fp) } -int +static int nextfield(buf) char *buf; - { +{ register char *p, *q; p = linep; @@ -383,14 +408,17 @@ nextfield(buf) } -skipbl() { +static void +skipbl() +{ while (*linep == ' ' || *linep == '\t') linep++; } -int -readline() { +static int +readline() +{ register char *p; if (fgets(line, 1024, infp) == NULL) @@ -408,26 +436,42 @@ readline() { -error(msg, a1, a2, a3, a4, a5, a6) +static void +#if __STDC__ +error(const char *msg, ...) +#else +error(va_alist) + va_dcl +#endif +{ + va_list va; +#if __STDC__ + va_start(va, msg); +#else char *msg; - { - fprintf(stderr, "line %d: ", linno); - fprintf(stderr, msg, a1, a2, a3, a4, a5, a6); - putc('\n', stderr); + va_start(va); + msg = va_arg(va, char *); +#endif + + (void) fprintf(stderr, "line %d: ", linno); + (void) vfprintf(stderr, msg, va); + (void) fputc('\n', stderr); + + va_end(va); + exit(2); } -char * +static char * savestr(s) - char *s; - { + const char *s; +{ register char *p; - char *malloc(); if ((p = malloc(strlen(s) + 1)) == NULL) error("Out of space"); - strcpy(p, s); + (void) strcpy(p, s); return p; } |