Annotation of coherent/g/usr/lib/ncurses/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.8  93/04/12  14:13:01  bin
        !            30:  * Udo: third color update
        !            31:  * 
        !            32:  * Revision 1.2  92/04/13  14:36:18  bin
        !            33:  * update by vlad
        !            34:  * 
        !            35:  * Revision 2.1  82/10/25  14:45:37  pavel
        !            36:  * Added Copyright Notice
        !            37:  * 
        !            38:  * Revision 2.0  82/10/24  15:16:37  pavel
        !            39:  * Beta-one Test Release
        !            40:  * 
        !            41:  * Revision 1.3  82/08/23  22:29:36  pavel
        !            42:  * The REAL Alpha-one Release Version
        !            43:  * 
        !            44:  * Revision 1.2  82/08/19  19:09:49  pavel
        !            45:  * Alpha Test Release One
        !            46:  * 
        !            47:  * Revision 1.1  82/08/12  18:36:55  pavel
        !            48:  * Initial revision
        !            49:  * 
        !            50:  *
        !            51:  */
        !            52: 
        !            53: #ifdef RCSHDR
        !            54: static char RCSid[] =
        !            55:        "$Header: /src386/usr/lib/ncurses/RCS/comp_main.c,v 1.8 93/04/12 14:13:01 bin Exp Locker: bin $";
        !            56: #endif
        !            57: 
        !            58: #include <sys/types.h>
        !            59: #include <sys/stat.h>
        !            60: #include "compiler.h"
        !            61: 
        !            62: char   *source_file = "/etc/terminfo";
        !            63: char   *destination = SRCDIR;
        !            64: char   *usage_string = "\ttic [-v[n]] source-file\n";
        !            65: char   check_only = 0;
        !            66: 
        !            67: 
        !            68: main (argc, argv)
        !            69: int    argc;
        !            70: char   *argv[];
        !            71: {
        !            72:        int     i;
        !            73:        int     argflag = FALSE;
        !            74: 
        !            75:        debug_level = 0;
        !            76: 
        !            77:        for (i=1; i < argc; i++)
        !            78:        {
        !            79:            if (argv[i][0] == '-')
        !            80:            {
        !            81:                switch (argv[i][1])
        !            82:                {
        !            83:                    case 'c':
        !            84:                        check_only = 1;
        !            85:                        break;
        !            86: 
        !            87:                    case 'v':
        !            88:                        debug_level = argv[i][2]  ?  atoi(&argv[i][2])  :  1;
        !            89:                        break;
        !            90: 
        !            91:                    default:
        !            92:                        fprintf(stderr, "%s: Unknown option. Usage is:\n\t%s\n",
        !            93:                                                       argv[0], usage_string);
        !            94:                        exit(1);
        !            95:                }
        !            96:            }
        !            97:            else if (argflag)
        !            98:            {
        !            99:                fprintf(stderr, "%s: Too many file names.  Usage is:\n\t%s\n",
        !           100:                                                        argv[0], usage_string);
        !           101:                exit(1);
        !           102:            }
        !           103:            else
        !           104:            {
        !           105:                argflag = TRUE;
        !           106:                source_file = argv[i];
        !           107:            }
        !           108:        }
        !           109: 
        !           110:        init(argv[0]);
        !           111:        make_hash_table();
        !           112:        compile();
        !           113: 
        !           114:        exit(0);
        !           115: }
        !           116: 
        !           117: 
        !           118: /*
        !           119:  *     init(progname)
        !           120:  *
        !           121:  *     Miscelaneous initialisations
        !           122:  *
        !           123:  *     Open source file as standard input
        !           124:  *     Check for access rights to destination directories
        !           125:  *     Create any directories which don't exist.
        !           126:  *
        !           127:  */
        !           128: 
        !           129: init(progname)
        !           130: char   *progname;
        !           131: {
        !           132:        struct stat     statbuf;
        !           133:        char            *dirnames = "abcdefghijklmnopqrstuvwxyz" 
        !           134:                                "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
        !           135:        char            *getenv();
        !           136:        char            dir[2];
        !           137: 
        !           138:        start_time = time(0);
        !           139: 
        !           140:        curr_line = 0;
        !           141: 
        !           142:        if (freopen(source_file, "r", stdin) == NULL)
        !           143:        {
        !           144:            fprintf(stderr, "%s: Can't open %s\n", progname, source_file);
        !           145:            exit(1);
        !           146:        }
        !           147: 
        !           148:        if (getenv("TERMINFO") != NULL)
        !           149:            destination = getenv("TERMINFO");
        !           150: 
        !           151:        if (access(destination, 7) < 0)
        !           152:        {
        !           153:            fprintf(stderr, "%s: %s non-existant or permission denied\n",
        !           154:                                                        progname, destination);
        !           155:            exit(1);
        !           156:        }
        !           157: 
        !           158:        if (chdir(destination) < 0)
        !           159:        {
        !           160:            fprintf(stderr, "%s: %s is not a directory\n",
        !           161:                                                        progname, destination);
        !           162:            exit(1);
        !           163:        }
        !           164:        
        !           165:        dir[1] = '\0';
        !           166:        for (dir[0] = *dirnames; *dirnames != '\0'; dir[0] = *(++dirnames))
        !           167:        {
        !           168:            if (stat(dir, &statbuf) < 0)
        !           169:            {
        !           170:                mkdir(dir);
        !           171:                chmod(dir, 0755);
        !           172:            }
        !           173:            else if (access(dir, 7) < 0)
        !           174:            {
        !           175:                fprintf(stderr, "%s: %s/%s: Permission denied\n",
        !           176:                                                    progname, destination, dir);
        !           177:                exit(1);
        !           178:            }
        !           179:            else if ((statbuf.st_mode & S_IFMT) != S_IFDIR)
        !           180:            {
        !           181:                fprintf(stderr, "%s: %s/%s: Not a directory\n",
        !           182:                                                    progname, destination, dir);
        !           183:                exit(1);
        !           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.