[BACK]Return to mk_cmds.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / mk_cmds

Annotation of src/usr.bin/mk_cmds/mk_cmds.c, Revision 1.1

1.1     ! downsj      1: /*     $OpenBSD: mk_cmds.c,v 1.1.1.1 1995/12/14 06:52:48 tholo Exp $   */
        !             2:
        !             3: /*-
        !             4:  * Copyright 1987, 1988 by the Student Information Processing Board
        !             5:  *     of the Massachusetts Institute of Technology
        !             6:  *
        !             7:  * Permission to use, copy, modify, and distribute this software
        !             8:  * and its documentation for any purpose and without fee is
        !             9:  * hereby granted, provided that the above copyright notice
        !            10:  * appear in all copies and that both that copyright notice and
        !            11:  * this permission notice appear in supporting documentation,
        !            12:  * and that the names of M.I.T. and the M.I.T. S.I.P.B. not be
        !            13:  * used in advertising or publicity pertaining to distribution
        !            14:  * of the software without specific, written prior permission.
        !            15:  * M.I.T. and the M.I.T. S.I.P.B. make no representations about
        !            16:  * the suitability of this software for any purpose.  It is
        !            17:  * provided "as is" without express or implied warranty.
        !            18:  */
        !            19:
        !            20: #include <stdio.h>
        !            21: #include <sys/types.h>
        !            22: #include <sys/param.h>
        !            23: #include <sys/file.h>
        !            24: #ifndef NPOSIX
        !            25: #include <string.h>
        !            26: #else
        !            27: #include <strings.h>
        !            28: #endif
        !            29: #include "mk_cmds_defs.h"
        !            30:
        !            31: static const char copyright[] =
        !            32:     "Copyright 1987 by MIT Student Information Processing Board";
        !            33:
        !            34: extern pointer malloc PROTOTYPE((unsigned));
        !            35: extern char *last_token;
        !            36: extern FILE *output_file;
        !            37:
        !            38: extern FILE *yyin, *yyout;
        !            39: extern unsigned lineno;
        !            40:
        !            41: main(argc, argv)
        !            42:     int argc;
        !            43:     char **argv;
        !            44: {
        !            45:     char c_file[MAXPATHLEN];
        !            46:     int result;
        !            47:     char *path, *p;
        !            48:
        !            49:     if (argc != 2) {
        !            50:        fputs("Usage: ", stderr);
        !            51:        fputs(argv[0], stderr);
        !            52:        fputs("cmdtbl.ct\n", stderr);
        !            53:        exit(1);
        !            54:     }
        !            55:
        !            56:     path = malloc(strlen(argv[1])+4); /* extra space to add ".ct" */
        !            57:     strcpy(path, argv[1]);
        !            58:     p = strrchr(path, '/');
        !            59:     if (p == (char *)NULL)
        !            60:        p = path;
        !            61:     else
        !            62:        p++;
        !            63:     p = strrchr(p, '.');
        !            64:     if (p == (char *)NULL || strcmp(p, ".ct"))
        !            65:        strcat(path, ".ct");
        !            66:     yyin = fopen(path, "r");
        !            67:     if (!yyin) {
        !            68:        perror(path);
        !            69:        exit(1);
        !            70:     }
        !            71:
        !            72:     p = strrchr(path, '.');
        !            73:     *p = '\0';
        !            74:     strcpy(c_file, path);
        !            75:     strcat(c_file, ".c");
        !            76:     *p = '.';
        !            77:
        !            78:     output_file = fopen(c_file, "w+");
        !            79:     if (!output_file) {
        !            80:        perror(c_file);
        !            81:        exit(1);
        !            82:     }
        !            83:
        !            84:     fputs("/* ", output_file); /* emacs fix -> */
        !            85:     fputs(c_file, output_file);
        !            86:     fputs(" - automatically generated from ", output_file);
        !            87:     fputs(path, output_file);
        !            88:     fputs(" */\n", output_file);
        !            89:     fputs("#include <ss/ss.h>\n\n", output_file);
        !            90:     fputs("#ifndef __STDC__\n#define const\n#endif\n\n", output_file);
        !            91:     /* parse it */
        !            92:     result = yyparse();
        !            93:     /* put file descriptors back where they belong */
        !            94:     fclose(yyin);              /* bye bye input file */
        !            95:     fclose(output_file);       /* bye bye output file */
        !            96:
        !            97:     return result;
        !            98: }
        !            99:
        !           100: yyerror(s)
        !           101:     char *s;
        !           102: {
        !           103:     fputs(s, stderr);
        !           104:     fprintf(stderr, "\nLine %d; last token was '%s'\n",
        !           105:            lineno, last_token);
        !           106: }