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