summaryrefslogtreecommitdiffstats
path: root/bin/sh/mknodes.c
diff options
context:
space:
mode:
authorpeter <peter@FreeBSD.org>1996-09-01 10:22:36 +0000
committerpeter <peter@FreeBSD.org>1996-09-01 10:22:36 +0000
commit5195be912eb257c05a0c97e561e72f01af2583ff (patch)
treee47ab3981b495c675a987dd1e943d1f4c823f314 /bin/sh/mknodes.c
parent2fc7d7d1fa299368ccdddede67b31695266698bd (diff)
downloadFreeBSD-src-5195be912eb257c05a0c97e561e72f01af2583ff.zip
FreeBSD-src-5195be912eb257c05a0c97e561e72f01af2583ff.tar.gz
Merge of 4.4-Lite2 sh source, plus some gcc -Wall cleaning. This is a
merge of parallel duplicate work by Steve Price and myself. :-] There are some changes to the build that are my fault... mkinit.c was trying (poorly) to duplicate some of the work that make(1) is designed to do. The Makefile hackery is my fault too, the depend list was incomplete because of some explicit OBJS+= entries, so mkdep wasn't picking up their source file #includes. This closes a pile of /bin/sh PR's, but not all of them.. Submitted by: Steve Price <steve@bonsai.hiwaay.net>, peter
Diffstat (limited to 'bin/sh/mknodes.c')
-rw-r--r--bin/sh/mknodes.c144
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;
}
OpenPOWER on IntegriCloud