Annotation of coherent/e/bin/tic/comp_main.c, revision 1.1

1.1     ! root        1: /*********************************************************************
        !             2: *                         COPYRIGHT NOTICE                           *
        !             3: **********************************************************************
        !             4: *        This software is copyright (C) 1982 by Pavel Curtis         *
        !             5: *                                                                    *
        !             6: *        Permission is granted to reproduce and distribute           *
        !             7: *        this file by any means so long as no fee is charged         *
        !             8: *        above a nominal handling fee and so long as this            *
        !             9: *        notice is always included in the copies.                    *
        !            10: *                                                                    *
        !            11: *        Other rights are reserved except as explicitly granted      *
        !            12: *        by written permission of the author.                        *
        !            13: *                Pavel Curtis                                        *
        !            14: *                Computer Science Dept.                              *
        !            15: *                405 Upson Hall                                      *
        !            16: *                Cornell University                                  *
        !            17: *                Ithaca, NY 14853                                    *
        !            18: *                                                                    *
        !            19: *                Ph- (607) 256-4934                                  *
        !            20: *                                                                    *
        !            21: *                Pavel.Cornell@Udel-Relay   (ARPAnet)                *
        !            22: *                decvax!cornell!pavel       (UUCPnet)                *
        !            23: *********************************************************************/
        !            24: 
        !            25: /*
        !            26:  *     comp_main.c --- Main program for terminfo compiler
        !            27:  *
        !            28:  *  $Log:      comp_main.c,v $
        !            29:  * Revision 1.1  92/03/13  10:45:42  bin
        !            30:  * Initial revision
        !            31:  * 
        !            32:  * Revision 2.1  82/10/25  14:45:37  pavel
        !            33:  * Added Copyright Notice
        !            34:  * 
        !            35:  * Revision 2.0  82/10/24  15:16:37  pavel
        !            36:  * Beta-one Test Release
        !            37:  * 
        !            38:  * Revision 1.3  82/08/23  22:29:36  pavel
        !            39:  * The REAL Alpha-one Release Version
        !            40:  * 
        !            41:  * Revision 1.2  82/08/19  19:09:49  pavel
        !            42:  * Alpha Test Release One
        !            43:  * 
        !            44:  * Revision 1.1  82/08/12  18:36:55  pavel
        !            45:  * Initial revision
        !            46:  * 
        !            47:  *
        !            48:  */
        !            49: 
        !            50: #ifndef COHERENT
        !            51: static char RCSid[] =
        !            52:        "$Header: /src386/usr/bin/tic/RCS/comp_main.c,v 1.1 92/03/13 10:45:42 bin Exp $";
        !            53: #endif
        !            54: 
        !            55: #include <sys/types.h>
        !            56: #include <sys/stat.h>
        !            57: #include "compiler.h"
        !            58: 
        !            59: char   *source_file = "/etc/terminfo";
        !            60: char   *destination = SRCDIR;
        !            61: char   *usage_string = "\ttic [-v[n]] source-file\n";
        !            62: char   check_only = 0;
        !            63: 
        !            64: 
        !            65: main (argc, argv)
        !            66: int    argc;
        !            67: char   *argv[];
        !            68: {
        !            69:        int     i;
        !            70:        int     argflag = FALSE;
        !            71: 
        !            72:        debug_level = 0;
        !            73: 
        !            74:        for (i=1; i < argc; i++)
        !            75:        {
        !            76:            if (argv[i][0] == '-')
        !            77:            {
        !            78:                switch (argv[i][1])
        !            79:                {
        !            80:                    case 'c':
        !            81:                        check_only = 1;
        !            82:                        break;
        !            83: 
        !            84:                    case 'v':
        !            85:                        debug_level = argv[i][2]  ?  atoi(&argv[i][2])  :  1;
        !            86:                        break;
        !            87: 
        !            88:                    default:
        !            89:                        fprintf(stderr, "%s: Unknown option. Usage is:\n\t%s\n",
        !            90:                                                       argv[0], usage_string);
        !            91:                        exit(1);
        !            92:                }
        !            93:            }
        !            94:            else if (argflag)
        !            95:            {
        !            96:                fprintf(stderr, "%s: Too many file names.  Usage is:\n\t%s\n",
        !            97:                                                        argv[0], usage_string);
        !            98:                exit(1);
        !            99:            }
        !           100:            else
        !           101:            {
        !           102:                argflag = TRUE;
        !           103:                source_file = argv[i];
        !           104:            }
        !           105:        }
        !           106: 
        !           107:        init(argv[0]);
        !           108:        make_hash_table();
        !           109:        compile();
        !           110: 
        !           111:        exit(0);
        !           112: }
        !           113: 
        !           114: 
        !           115: 
        !           116: 
        !           117: /*
        !           118:  *     init(progname)
        !           119:  *
        !           120:  *     Miscelaneous initialisations
        !           121:  *
        !           122:  *     Open source file as standard input
        !           123:  *     Check for access rights to destination directories
        !           124:  *     Create any directories which don't exist.
        !           125:  *
        !           126:  */
        !           127: 
        !           128: init(progname)
        !           129: char   *progname;
        !           130: {
        !           131:        struct stat     statbuf;
        !           132:        char            *dirnames = "abcdefghijklmnopqrstuvwxyz" 
        !           133:                                "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
        !           134:        char            *getenv();
        !           135:        char            dir[2];
        !           136: 
        !           137:        start_time = time(0);
        !           138: 
        !           139:        curr_line = 0;
        !           140: 
        !           141:        if (freopen(source_file, "r", stdin) == NULL)
        !           142:        {
        !           143:            fprintf(stderr, "%s: Can't open %s\n", progname, source_file);
        !           144:            exit(1);
        !           145:        }
        !           146: 
        !           147:        if (getenv("TERMINFO") != NULL)
        !           148:            destination = getenv("TERMINFO");
        !           149: 
        !           150:        if (access(destination, 7) < 0)
        !           151:        {
        !           152:            fprintf(stderr, "%s: %s non-existant or permission denied\n",
        !           153:                                                        progname, destination);
        !           154:            exit(1);
        !           155:        }
        !           156: 
        !           157:        if (chdir(destination) < 0)
        !           158:        {
        !           159:            fprintf(stderr, "%s: %s is not a directory\n",
        !           160:                                                        progname, destination);
        !           161:            exit(1);
        !           162:        }
        !           163:        
        !           164:        dir[1] = '\0';
        !           165:        for (dir[0] = *dirnames; *dirnames != '\0'; dir[0] = *(++dirnames))
        !           166:        {
        !           167:            if (stat(dir, &statbuf) < 0)
        !           168:            {
        !           169:                mkdir(dir);
        !           170:                chmod(dir, 0755);
        !           171:            }
        !           172:            else if (access(dir, 7) < 0)
        !           173:            {
        !           174:                fprintf(stderr, "%s: %s/%s: Permission denied\n",
        !           175:                                                    progname, destination, dir);
        !           176:                exit(1);
        !           177:            }
        !           178:            else if ((statbuf.st_mode & S_IFMT) != S_IFDIR)
        !           179:            {
        !           180:                fprintf(stderr, "%s: %s/%s: Not a directory\n",
        !           181:                                                    progname, destination, dir);
        !           182:                exit(1);
        !           183:            }
        !           184:        }
        !           185: }
        !           186: 
        !           187: 
        !           188: 
        !           189: /*
        !           190:  *     mkdir(dirname)
        !           191:  *
        !           192:  *     forks and execs the mkdir program to create the given directory
        !           193:  *
        !           194:  */
        !           195: 
        !           196: mkdir(dirname)
        !           197: char   *dirname;
        !           198: {
        !           199:        int     fork_rtn;
        !           200:        int     status;
        !           201: 
        !           202:        fork_rtn = fork();
        !           203: 
        !           204:        switch (fork_rtn)
        !           205:        {
        !           206:            case 0:             /* Child */
        !           207:                execl("/bin/mkdir", "mkdir", dirname, 0);
        !           208:                exit(1);
        !           209: 
        !           210:            case -1:            /* Error */
        !           211:                fprintf(stderr, "tic: SYSTEM ERROR!! Fork failed!!!\n");
        !           212:                abort();
        !           213: 
        !           214:            default:
        !           215:                wait(&status);
        !           216:                if (status != 0)
        !           217:                    syserr_abort("mkdir returned bad status");
        !           218:                break;
        !           219:        }
        !           220: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.