1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* 23*7c478bd9Sstevel@tonic-gate * Copyright (c) 1996, by Sun Microsystems, Inc. 24*7c478bd9Sstevel@tonic-gate * All Rights reserved. 25*7c478bd9Sstevel@tonic-gate */ 26*7c478bd9Sstevel@tonic-gate /* Copyright (c) 1988 AT&T */ 27*7c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 28*7c478bd9Sstevel@tonic-gate 29*7c478bd9Sstevel@tonic-gate 30*7c478bd9Sstevel@tonic-gate /* 31*7c478bd9Sstevel@tonic-gate * University Copyright- Copyright (c) 1982, 1986, 1988 32*7c478bd9Sstevel@tonic-gate * The Regents of the University of California 33*7c478bd9Sstevel@tonic-gate * All Rights Reserved 34*7c478bd9Sstevel@tonic-gate * 35*7c478bd9Sstevel@tonic-gate * University Acknowledgment- Portions of this document are derived from 36*7c478bd9Sstevel@tonic-gate * software developed by the University of California, Berkeley, and its 37*7c478bd9Sstevel@tonic-gate * contributors. 38*7c478bd9Sstevel@tonic-gate */ 39*7c478bd9Sstevel@tonic-gate 40*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 41*7c478bd9Sstevel@tonic-gate 42*7c478bd9Sstevel@tonic-gate /* 43*7c478bd9Sstevel@tonic-gate ************************************************************************* 44*7c478bd9Sstevel@tonic-gate * COPYRIGHT NOTICE * 45*7c478bd9Sstevel@tonic-gate ************************************************************************* 46*7c478bd9Sstevel@tonic-gate * This software is copyright(C) 1982 by Pavel Curtis * 47*7c478bd9Sstevel@tonic-gate * * 48*7c478bd9Sstevel@tonic-gate * Permission is granted to reproduce and distribute * 49*7c478bd9Sstevel@tonic-gate * this file by any means so long as no fee is charged * 50*7c478bd9Sstevel@tonic-gate * above a nominal handling fee and so long as this * 51*7c478bd9Sstevel@tonic-gate * notice is always included in the copies. * 52*7c478bd9Sstevel@tonic-gate * * 53*7c478bd9Sstevel@tonic-gate * Other rights are reserved except as explicitly granted * 54*7c478bd9Sstevel@tonic-gate * by written permission of the author. * 55*7c478bd9Sstevel@tonic-gate * Pavel Curtis * 56*7c478bd9Sstevel@tonic-gate * Computer Science Dept. * 57*7c478bd9Sstevel@tonic-gate * 405 Upson Halli * 58*7c478bd9Sstevel@tonic-gate * Cornell Universityi * 59*7c478bd9Sstevel@tonic-gate * Ithaca, NY 14853 * 60*7c478bd9Sstevel@tonic-gate * * 61*7c478bd9Sstevel@tonic-gate * Ph- (607) 256-4934 * 62*7c478bd9Sstevel@tonic-gate * * 63*7c478bd9Sstevel@tonic-gate * Pavel.Cornell@Udel-Relay(ARPAnet) * 64*7c478bd9Sstevel@tonic-gate * decvax!cornell!pavel(UUCPnet) * 65*7c478bd9Sstevel@tonic-gate *********************************************************************** */ 66*7c478bd9Sstevel@tonic-gate 67*7c478bd9Sstevel@tonic-gate /* 68*7c478bd9Sstevel@tonic-gate * comp_main.c --- Main program for terminfo compiler 69*7c478bd9Sstevel@tonic-gate * 70*7c478bd9Sstevel@tonic-gate * $Log: RCS/comp_main.v $ 71*7c478bd9Sstevel@tonic-gate * Revision 2.1 82/10/25 14:45:37 pavel 72*7c478bd9Sstevel@tonic-gate * Added Copyright Notice 73*7c478bd9Sstevel@tonic-gate * 74*7c478bd9Sstevel@tonic-gate * Revision 2.0 82/10/24 15:16:37 pavel 75*7c478bd9Sstevel@tonic-gate * Beta-one Test Release 76*7c478bd9Sstevel@tonic-gate * 77*7c478bd9Sstevel@tonic-gate * Revision 1.3 82/08/23 22:29:36 pavel 78*7c478bd9Sstevel@tonic-gate * The REAL Alpha-one Release Version 79*7c478bd9Sstevel@tonic-gate * 80*7c478bd9Sstevel@tonic-gate * Revision 1.2 82/08/19 19:09:49 pavel 81*7c478bd9Sstevel@tonic-gate * Alpha Test Release One 82*7c478bd9Sstevel@tonic-gate * 83*7c478bd9Sstevel@tonic-gate * Revision 1.1 82/08/12 18:36:55 pavel 84*7c478bd9Sstevel@tonic-gate * Initial revision 85*7c478bd9Sstevel@tonic-gate * 86*7c478bd9Sstevel@tonic-gate * 87*7c478bd9Sstevel@tonic-gate */ 88*7c478bd9Sstevel@tonic-gate 89*7c478bd9Sstevel@tonic-gate 90*7c478bd9Sstevel@tonic-gate #define EXTERN /* EXTERN=extern in other .c files */ 91*7c478bd9Sstevel@tonic-gate #include <sys/types.h> 92*7c478bd9Sstevel@tonic-gate #include <sys/stat.h> 93*7c478bd9Sstevel@tonic-gate #include <stdlib.h> 94*7c478bd9Sstevel@tonic-gate #include <unistd.h> 95*7c478bd9Sstevel@tonic-gate #include "compiler.h" 96*7c478bd9Sstevel@tonic-gate 97*7c478bd9Sstevel@tonic-gate char *source_file = "./terminfo.src"; 98*7c478bd9Sstevel@tonic-gate char *destination = SRCDIR; 99*7c478bd9Sstevel@tonic-gate char *usage_string = "[-v[n]] [-c] source-file\n"; 100*7c478bd9Sstevel@tonic-gate char check_only = 0; 101*7c478bd9Sstevel@tonic-gate char *progname; 102*7c478bd9Sstevel@tonic-gate 103*7c478bd9Sstevel@tonic-gate extern void make_hash_table(); /* should be in a header file :-( */ 104*7c478bd9Sstevel@tonic-gate extern void compile(); /* should be in a header file :-( */ 105*7c478bd9Sstevel@tonic-gate extern void syserr_abort(); /* should be in a header file :-( */ 106*7c478bd9Sstevel@tonic-gate static void init(); 107*7c478bd9Sstevel@tonic-gate 108*7c478bd9Sstevel@tonic-gate main(int argc, char *argv[]) 109*7c478bd9Sstevel@tonic-gate { 110*7c478bd9Sstevel@tonic-gate int i; 111*7c478bd9Sstevel@tonic-gate int argflag = FALSE; 112*7c478bd9Sstevel@tonic-gate 113*7c478bd9Sstevel@tonic-gate debug_level = 0; 114*7c478bd9Sstevel@tonic-gate progname = argv[0]; 115*7c478bd9Sstevel@tonic-gate 116*7c478bd9Sstevel@tonic-gate umask(022); 117*7c478bd9Sstevel@tonic-gate 118*7c478bd9Sstevel@tonic-gate for (i = 1; i < argc; i++) { 119*7c478bd9Sstevel@tonic-gate if (argv[i][0] == '-') { 120*7c478bd9Sstevel@tonic-gate switch (argv[i][1]) { 121*7c478bd9Sstevel@tonic-gate case 'c': 122*7c478bd9Sstevel@tonic-gate check_only = 1; 123*7c478bd9Sstevel@tonic-gate break; 124*7c478bd9Sstevel@tonic-gate 125*7c478bd9Sstevel@tonic-gate case 'v': 126*7c478bd9Sstevel@tonic-gate debug_level = argv[i][2] ? atoi(&argv[i][2]) : 1; 127*7c478bd9Sstevel@tonic-gate break; 128*7c478bd9Sstevel@tonic-gate 129*7c478bd9Sstevel@tonic-gate default: 130*7c478bd9Sstevel@tonic-gate fprintf(stderr, 131*7c478bd9Sstevel@tonic-gate "%s: Unknown option. Usage is:\n\t%s: %s\n", 132*7c478bd9Sstevel@tonic-gate argv[0], progname, usage_string); 133*7c478bd9Sstevel@tonic-gate exit(1); 134*7c478bd9Sstevel@tonic-gate } 135*7c478bd9Sstevel@tonic-gate } else if (argflag) { 136*7c478bd9Sstevel@tonic-gate fprintf(stderr, "%s: Too many file names. Usage is:\n\t%s\n", 137*7c478bd9Sstevel@tonic-gate argv[0], usage_string); 138*7c478bd9Sstevel@tonic-gate exit(1); 139*7c478bd9Sstevel@tonic-gate } else { 140*7c478bd9Sstevel@tonic-gate argflag = TRUE; 141*7c478bd9Sstevel@tonic-gate source_file = argv[i]; 142*7c478bd9Sstevel@tonic-gate } 143*7c478bd9Sstevel@tonic-gate } 144*7c478bd9Sstevel@tonic-gate 145*7c478bd9Sstevel@tonic-gate init(); 146*7c478bd9Sstevel@tonic-gate make_hash_table(); 147*7c478bd9Sstevel@tonic-gate compile(); 148*7c478bd9Sstevel@tonic-gate 149*7c478bd9Sstevel@tonic-gate exit(0); 150*7c478bd9Sstevel@tonic-gate 151*7c478bd9Sstevel@tonic-gate return(0); 152*7c478bd9Sstevel@tonic-gate } 153*7c478bd9Sstevel@tonic-gate 154*7c478bd9Sstevel@tonic-gate /* 155*7c478bd9Sstevel@tonic-gate * init() 156*7c478bd9Sstevel@tonic-gate * 157*7c478bd9Sstevel@tonic-gate * Miscellaneous initializations 158*7c478bd9Sstevel@tonic-gate * 159*7c478bd9Sstevel@tonic-gate * Open source file as standard input 160*7c478bd9Sstevel@tonic-gate * Change directory to working terminfo directory. 161*7c478bd9Sstevel@tonic-gate * 162*7c478bd9Sstevel@tonic-gate */ 163*7c478bd9Sstevel@tonic-gate 164*7c478bd9Sstevel@tonic-gate static void 165*7c478bd9Sstevel@tonic-gate init() 166*7c478bd9Sstevel@tonic-gate { 167*7c478bd9Sstevel@tonic-gate char *env = getenv("TERMINFO"); 168*7c478bd9Sstevel@tonic-gate 169*7c478bd9Sstevel@tonic-gate start_time = time((time_t *) 0); 170*7c478bd9Sstevel@tonic-gate 171*7c478bd9Sstevel@tonic-gate curr_line = 0; 172*7c478bd9Sstevel@tonic-gate 173*7c478bd9Sstevel@tonic-gate if (freopen(source_file, "r", stdin) == NULL) { 174*7c478bd9Sstevel@tonic-gate fprintf(stderr, "%s: Can't open %s\n", progname, source_file); 175*7c478bd9Sstevel@tonic-gate exit(1); 176*7c478bd9Sstevel@tonic-gate } 177*7c478bd9Sstevel@tonic-gate 178*7c478bd9Sstevel@tonic-gate if (env && *env) 179*7c478bd9Sstevel@tonic-gate destination = env; 180*7c478bd9Sstevel@tonic-gate 181*7c478bd9Sstevel@tonic-gate if (check_only) { 182*7c478bd9Sstevel@tonic-gate DEBUG(1, "Would be working in %s\n", destination); 183*7c478bd9Sstevel@tonic-gate } else { 184*7c478bd9Sstevel@tonic-gate DEBUG(1, "Working in %s\n", destination); 185*7c478bd9Sstevel@tonic-gate } 186*7c478bd9Sstevel@tonic-gate 187*7c478bd9Sstevel@tonic-gate if (access(destination, 7) < 0) { 188*7c478bd9Sstevel@tonic-gate fprintf(stderr, "%s: %s nonexistent or permission denied\n", 189*7c478bd9Sstevel@tonic-gate progname, destination); 190*7c478bd9Sstevel@tonic-gate exit(1); 191*7c478bd9Sstevel@tonic-gate } 192*7c478bd9Sstevel@tonic-gate 193*7c478bd9Sstevel@tonic-gate if (chdir(destination) < 0) { 194*7c478bd9Sstevel@tonic-gate fprintf(stderr, "%s: %s is not a directory\n", 195*7c478bd9Sstevel@tonic-gate progname, destination); 196*7c478bd9Sstevel@tonic-gate exit(1); 197*7c478bd9Sstevel@tonic-gate } 198*7c478bd9Sstevel@tonic-gate 199*7c478bd9Sstevel@tonic-gate } 200*7c478bd9Sstevel@tonic-gate 201*7c478bd9Sstevel@tonic-gate /* 202*7c478bd9Sstevel@tonic-gate * 203*7c478bd9Sstevel@tonic-gate * check_dir(dirletter) 204*7c478bd9Sstevel@tonic-gate * 205*7c478bd9Sstevel@tonic-gate * Check for access rights to the destination directory. 206*7c478bd9Sstevel@tonic-gate * Create any directories which don't exist. 207*7c478bd9Sstevel@tonic-gate * 208*7c478bd9Sstevel@tonic-gate */ 209*7c478bd9Sstevel@tonic-gate 210*7c478bd9Sstevel@tonic-gate void 211*7c478bd9Sstevel@tonic-gate check_dir(char dirletter) 212*7c478bd9Sstevel@tonic-gate { 213*7c478bd9Sstevel@tonic-gate struct stat64 statbuf; 214*7c478bd9Sstevel@tonic-gate static char dirnames[128]; 215*7c478bd9Sstevel@tonic-gate static char dir[2] = " "; 216*7c478bd9Sstevel@tonic-gate 217*7c478bd9Sstevel@tonic-gate if (dirnames[dirletter] == 0) { 218*7c478bd9Sstevel@tonic-gate dir[0] = dirletter; 219*7c478bd9Sstevel@tonic-gate if (stat64(dir, &statbuf) < 0) { 220*7c478bd9Sstevel@tonic-gate if (mkdir(dir, 0755) < 0) 221*7c478bd9Sstevel@tonic-gate syserr_abort("mkdir %s returned bad status", dir); 222*7c478bd9Sstevel@tonic-gate dirnames[dirletter] = 1; 223*7c478bd9Sstevel@tonic-gate } else if (access(dir, 7) < 0) { 224*7c478bd9Sstevel@tonic-gate fprintf(stderr, "%s: %s/%s: Permission denied\n", 225*7c478bd9Sstevel@tonic-gate progname, destination, dir); 226*7c478bd9Sstevel@tonic-gate perror(dir); 227*7c478bd9Sstevel@tonic-gate exit(1); 228*7c478bd9Sstevel@tonic-gate } else if ((statbuf.st_mode & S_IFMT) != S_IFDIR) { 229*7c478bd9Sstevel@tonic-gate fprintf(stderr, "%s: %s/%s: Not a directory\n", 230*7c478bd9Sstevel@tonic-gate progname, destination, dir); 231*7c478bd9Sstevel@tonic-gate perror(dir); 232*7c478bd9Sstevel@tonic-gate exit(1); 233*7c478bd9Sstevel@tonic-gate } 234*7c478bd9Sstevel@tonic-gate } 235*7c478bd9Sstevel@tonic-gate return; 236*7c478bd9Sstevel@tonic-gate } 237*7c478bd9Sstevel@tonic-gate 238*7c478bd9Sstevel@tonic-gate #include <curses.h> 239*7c478bd9Sstevel@tonic-gate #if (defined(SYSV) || defined(USG)) && !defined(SIGPOLL) 240*7c478bd9Sstevel@tonic-gate /* 241*7c478bd9Sstevel@tonic-gate * mkdir(dirname, mode) 242*7c478bd9Sstevel@tonic-gate * 243*7c478bd9Sstevel@tonic-gate * forks and execs the mkdir program to create the given directory 244*7c478bd9Sstevel@tonic-gate * 245*7c478bd9Sstevel@tonic-gate */ 246*7c478bd9Sstevel@tonic-gate 247*7c478bd9Sstevel@tonic-gate mkdir(dirname, mode) 248*7c478bd9Sstevel@tonic-gate #ifdef __STDC__ 249*7c478bd9Sstevel@tonic-gate const 250*7c478bd9Sstevel@tonic-gate #endif 251*7c478bd9Sstevel@tonic-gate char *dirname; 252*7c478bd9Sstevel@tonic-gate int mode; 253*7c478bd9Sstevel@tonic-gate { 254*7c478bd9Sstevel@tonic-gate int fork_rtn; 255*7c478bd9Sstevel@tonic-gate int status; 256*7c478bd9Sstevel@tonic-gate 257*7c478bd9Sstevel@tonic-gate fork_rtn = fork(); 258*7c478bd9Sstevel@tonic-gate 259*7c478bd9Sstevel@tonic-gate switch (fork_rtn) { 260*7c478bd9Sstevel@tonic-gate case 0: /* Child */ 261*7c478bd9Sstevel@tonic-gate (void) execl("/bin/mkdir", "mkdir", dirname, (char *)0); 262*7c478bd9Sstevel@tonic-gate _exit(1); 263*7c478bd9Sstevel@tonic-gate 264*7c478bd9Sstevel@tonic-gate case -1: /* Error */ 265*7c478bd9Sstevel@tonic-gate fprintf(stderr, "%s: SYSTEM ERROR!! Fork failed!!!\n", 266*7c478bd9Sstevel@tonic-gate progname); 267*7c478bd9Sstevel@tonic-gate exit(1); 268*7c478bd9Sstevel@tonic-gate 269*7c478bd9Sstevel@tonic-gate default: 270*7c478bd9Sstevel@tonic-gate (void) wait(&status); 271*7c478bd9Sstevel@tonic-gate if ((status != 0) || (chmod(dirname, mode) == -1)) 272*7c478bd9Sstevel@tonic-gate return (-1); 273*7c478bd9Sstevel@tonic-gate return (0); 274*7c478bd9Sstevel@tonic-gate } 275*7c478bd9Sstevel@tonic-gate } 276*7c478bd9Sstevel@tonic-gate #endif 277