aboutsummaryrefslogtreecommitdiff
path: root/usr.bin/mk_cmds/mk_cmds.c
diff options
context:
space:
mode:
authorGarrett Wollman <wollman@FreeBSD.org>1995-01-19 21:30:25 +0000
committerGarrett Wollman <wollman@FreeBSD.org>1995-01-19 21:30:25 +0000
commitba20ecf423ac8aaf6e241878eafd0c5110f47a46 (patch)
treef70616a0424ea1fd91d7bc668991f279a491d9aa /usr.bin/mk_cmds/mk_cmds.c
parent282244c5b6328a489f08d00612722fbfd46a52c6 (diff)
downloadsrc-ba20ecf423ac8aaf6e241878eafd0c5110f47a46.tar.gz
src-ba20ecf423ac8aaf6e241878eafd0c5110f47a46.zip
Other part of SIPB subsystem library, the program to make command tables.
Notes
Notes: svn path=/cvs2svn/branches/sipb/; revision=5719
Diffstat (limited to 'usr.bin/mk_cmds/mk_cmds.c')
-rw-r--r--usr.bin/mk_cmds/mk_cmds.c94
1 files changed, 94 insertions, 0 deletions
diff --git a/usr.bin/mk_cmds/mk_cmds.c b/usr.bin/mk_cmds/mk_cmds.c
new file mode 100644
index 000000000000..ef7ac5e90576
--- /dev/null
+++ b/usr.bin/mk_cmds/mk_cmds.c
@@ -0,0 +1,94 @@
+/*
+ * make_commands.c
+ *
+ * Header: mk_cmds.c,v 1.6 89/01/25 07:47:26 raeburn Exp
+ * $Locker: $
+ *
+ * Copyright 1987, 1988 by MIT Student Information Processing Board
+ *
+ * For copyright information, see copyright.h.
+ */
+
+#include "copyright.h"
+#include <stdio.h>
+#include <sys/param.h>
+#include <sys/file.h>
+#include <strings.h>
+#include "ss_internal.h"
+
+static const char copyright[] =
+ "Copyright 1987 by MIT Student Information Processing Board";
+
+extern pointer malloc PROTOTYPE((unsigned));
+extern char *last_token;
+extern FILE *output_file;
+
+extern FILE *yyin, *yyout;
+extern int yylineno;
+
+main(argc, argv)
+ int argc;
+ char **argv;
+{
+ char c_file[MAXPATHLEN];
+ int result;
+ char *path, *p;
+
+ if (argc != 2) {
+ fputs("Usage: ", stderr);
+ fputs(argv[0], stderr);
+ fputs("cmdtbl.ct\n", stderr);
+ exit(1);
+ }
+
+ path = malloc(strlen(argv[1])+4); /* extra space to add ".ct" */
+ strcpy(path, argv[1]);
+ p = rindex(path, '/');
+ if (p == (char *)NULL)
+ p = path;
+ else
+ p++;
+ p = rindex(p, '.');
+ if (p == (char *)NULL || strcmp(p, ".ct"))
+ strcat(path, ".ct");
+ yyin = fopen(path, "r");
+ if (!yyin) {
+ perror(path);
+ exit(1);
+ }
+
+ p = rindex(path, '.');
+ *p = '\0';
+ strcpy(c_file, path);
+ strcat(c_file, ".c");
+ *p = '.';
+
+ output_file = fopen(c_file, "w+");
+ if (!output_file) {
+ perror(c_file);
+ exit(1);
+ }
+
+ fputs("/* ", output_file);
+ fputs(c_file, output_file);
+ fputs(" - automatically generated from ", output_file);
+ fputs(path, output_file);
+ fputs(" */\n", output_file);
+ fputs("#include <ss/ss.h>\n\n", output_file);
+ fputs("#ifndef __STDC__\n#define const\n#endif\n\n", output_file);
+ /* parse it */
+ result = yyparse();
+ /* put file descriptors back where they belong */
+ fclose(yyin); /* bye bye input file */
+ fclose(output_file); /* bye bye output file */
+
+ return result;
+}
+
+yyerror(s)
+ char *s;
+{
+ fputs(s, stderr);
+ fprintf(stderr, "\nLine %d; last token was '%s'\n",
+ yylineno, last_token);
+}