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