dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / lib / krb5 / ss / mk_cmds.c
blobbd4fb0d3c6aca35a239881517caa22d364a122e2
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"
7 /*
8 * make_commands.c
10 * util/ss/mk_cmds.c
12 * Copyright 1987, 1988 by MIT Student Information Processing Board
14 * For copyright information, see copyright.h.
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"
25 static const char copyright[] =
26 "Copyright 1987 by MIT Student Information Processing Board";
28 extern pointer malloc (unsigned);
29 extern char *last_token;
30 extern FILE *output_file;
32 extern FILE *yyin, *yyout;
33 #ifndef NO_YYLINENO
34 extern int yylineno;
35 #endif
37 int main(argc, argv)
38 int argc;
39 char **argv;
41 char c_file[MAXPATHLEN];
42 int result;
43 char *path, *p, *q;
45 if (argc != 2) {
46 fputs("Usage: ", stderr);
47 fputs(argv[0], stderr);
48 fputs("cmdtbl.ct\n", stderr);
49 exit(1);
52 path = malloc(strlen(argv[1])+4); /* extra space to add ".ct" */
53 strcpy(path, argv[1]);
54 p = strrchr(path, '/');
55 if (p == NULL)
56 p = path;
57 else
58 p++;
59 p = strrchr(p, '.');
60 if (p == NULL || strcmp(p, ".ct"))
61 strcat(path, ".ct");
62 yyin = fopen(path, "rF");
63 if (!yyin) {
64 perror(path);
65 exit(1);
68 p = strrchr(path, '.');
69 *p = '\0';
70 q = rindex(path, '/');
71 strncpy(c_file, (q) ? q + 1 : path, sizeof(c_file) - 1);
72 c_file[sizeof(c_file) - 1] = '\0';
73 strncat(c_file, ".c", sizeof(c_file) - 1 - strlen(c_file));
74 *p = '.';
76 output_file = fopen(c_file, "w+F");
77 if (!output_file) {
78 perror(c_file);
79 exit(1);
82 fputs("/* ", output_file);
83 fputs(c_file, output_file);
84 fputs(" - automatically generated from ", output_file);
85 fputs(path, output_file);
86 fputs(" */\n", output_file);
87 fputs("#include <ss/ss.h>\n\n", output_file);
88 fputs("#ifndef __STDC__\n#define const\n#endif\n\n", output_file);
89 /* parse it */
90 result = yyparse();
91 /* put file descriptors back where they belong */
92 fclose(yyin); /* bye bye input file */
93 fclose(output_file); /* bye bye output file */
95 return result;
98 yyerror(s)
99 char *s;
101 fputs(s, stderr);
102 #ifdef NO_YYLINENO
103 fprintf(stderr, "\nLast token was '%s'\n", last_token);
104 #else
105 fprintf(stderr, "\nLine %d; last token was '%s'\n",
106 yylineno, last_token);
107 #endif