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