]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - usr.bin/mk_cmds/mk_cmds.c
This commit was generated by cvs2svn to compensate for changes in r80016,
[FreeBSD/FreeBSD.git] / usr.bin / mk_cmds / mk_cmds.c
1 /*
2  * make_commands.c
3  *
4  * Header: mk_cmds.c,v 1.6 89/01/25 07:47:26 raeburn Exp
5  *
6  * Copyright 1987, 1988 by MIT Student Information Processing Board
7  *
8  * For copyright information, see copyright.h.
9  */
10
11 #include "copyright.h"
12 #include <stdio.h>
13 #include <sys/param.h>
14 #include <sys/file.h>
15 #include <strings.h>
16 #include "ss_internal.h"
17
18 static const char copyright[] =
19     "Copyright 1987 by MIT Student Information Processing Board";
20
21 extern pointer malloc PROTOTYPE((unsigned));
22 extern char *last_token;
23 extern FILE *output_file;
24
25 extern FILE *yyin, *yyout;
26 extern int yylineno;
27
28 static void
29 usage(void)
30 {
31         fprintf(stderr, "usage: mk_cmds cmdtbl.ct\n");
32         exit(1);
33 }
34
35 int
36 main(argc, argv)
37     int argc;
38     char **argv;
39 {
40     char c_file[MAXPATHLEN];
41     int result;
42     char *path, *p;
43
44     if (argc != 2)
45                 usage();
46
47     path = malloc(strlen(argv[1])+4); /* extra space to add ".ct" */
48     strcpy(path, argv[1]);
49     p = rindex(path, '/');
50     if (p == (char *)NULL)
51         p = path;
52     else
53         p++;
54     p = rindex(p, '.');
55     if (p == (char *)NULL || strcmp(p, ".ct"))
56         strcat(path, ".ct");
57     yyin = fopen(path, "r");
58     if (!yyin) {
59         perror(path);
60         exit(1);
61     }
62
63     p = rindex(path, '.');
64     *p = '\0';
65     strcpy(c_file, path);
66     strcat(c_file, ".c");
67     *p = '.';
68
69     output_file = fopen(c_file, "w+");
70     if (!output_file) {
71         perror(c_file);
72         exit(1);
73     }
74
75     fputs("/* ", output_file);
76     fputs(c_file, output_file);
77     fputs(" - automatically generated from ", output_file);
78     fputs(path, output_file);
79     fputs(" */\n", output_file);
80     fputs("#include <ss/ss.h>\n\n", output_file);
81     fputs("#ifndef __STDC__\n#define const\n#endif\n\n", output_file);
82     /* parse it */
83     result = yyparse();
84     /* put file descriptors back where they belong */
85     fclose(yyin);               /* bye bye input file */
86     fclose(output_file);        /* bye bye output file */
87
88     return result;
89 }
90
91 int
92 yyerror(s)
93     char *s;
94 {
95     fputs(s, stderr);
96     fprintf(stderr, "\nLine %d; last token was '%s'\n",
97             yylineno, last_token);
98     return 0;
99 }