2N/A/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2N/A/*
2N/A * make_commands.c
2N/A *
2N/A * util/ss/mk_cmds.c
2N/A *
2N/A * Copyright 1987, 1988 by MIT Student Information Processing Board
2N/A *
2N/A * For copyright information, see copyright.h.
2N/A */
2N/A
2N/A/*
2N/A * Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved.
2N/A */
2N/A
2N/A#include "copyright.h"
2N/A#include <stdio.h>
2N/A#include <sys/param.h>
2N/A#include <sys/types.h>
2N/A#include <sys/file.h>
2N/A#include <string.h>
2N/A#include "ss_internal.h"
2N/A
2N/Astatic const char copyright[] =
2N/A "Copyright 1987 by MIT Student Information Processing Board";
2N/A
2N/Aextern pointer malloc (unsigned);
2N/Aextern char *last_token;
2N/Aextern FILE *output_file;
2N/A
2N/Aextern FILE *yyin, *yyout;
2N/A#ifndef NO_YYLINENO
2N/Aextern int yylineno;
2N/A#endif
2N/A
2N/Aint main(argc, argv)
2N/A int argc;
2N/A char **argv;
2N/A{
2N/A char c_file[MAXPATHLEN];
2N/A int result;
2N/A char *path, *p, *q;
2N/A
2N/A if (argc != 2) {
2N/A fputs("Usage: ", stderr);
2N/A fputs(argv[0], stderr);
2N/A fputs("cmdtbl.ct\n", stderr);
2N/A exit(1);
2N/A }
2N/A
2N/A path = malloc(strlen(argv[1])+4); /* extra space to add ".ct" */
2N/A strcpy(path, argv[1]);
2N/A p = strrchr(path, '/');
2N/A if (p == (char *)NULL)
2N/A p = path;
2N/A else
2N/A p++;
2N/A p = strrchr(p, '.');
2N/A if (p == (char *)NULL || strcmp(p, ".ct"))
2N/A strcat(path, ".ct");
2N/A /* Solaris Kerberos */
2N/A yyin = fopen(path, "rF");
2N/A if (!yyin) {
2N/A perror(path);
2N/A exit(1);
2N/A }
2N/A
2N/A p = strrchr(path, '.');
2N/A *p = '\0';
2N/A q = rindex(path, '/');
2N/A strncpy(c_file, (q) ? q + 1 : path, sizeof(c_file) - 1);
2N/A c_file[sizeof(c_file) - 1] = '\0';
2N/A strncat(c_file, ".c", sizeof(c_file) - 1 - strlen(c_file));
2N/A *p = '.';
2N/A
2N/A /* Solaris Kerberos */
2N/A output_file = fopen(c_file, "w+F");
2N/A if (!output_file) {
2N/A perror(c_file);
2N/A exit(1);
2N/A }
2N/A
2N/A fputs("/* ", output_file);
2N/A fputs(c_file, output_file);
2N/A fputs(" - automatically generated from ", output_file);
2N/A fputs(path, output_file);
2N/A fputs(" */\n", output_file);
2N/A fputs("#include <ss/ss.h>\n\n", output_file);
2N/A fputs("#ifndef __STDC__\n#define const\n#endif\n\n", output_file);
2N/A /* parse it */
2N/A result = yyparse();
2N/A /* put file descriptors back where they belong */
2N/A fclose(yyin); /* bye bye input file */
2N/A fclose(output_file); /* bye bye output file */
2N/A
2N/A return result;
2N/A}
2N/A
2N/Ayyerror(s)
2N/Achar *s;
2N/A{
2N/A fputs(s, stderr);
2N/A#ifdef NO_YYLINENO
2N/A fprintf(stderr, "\nLast token was '%s'\n", last_token);
2N/A#else
2N/A fprintf(stderr, "\nLine %d; last token was '%s'\n",
2N/A yylineno, last_token);
2N/A#endif
2N/A}