10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 50Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 60Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 70Sstevel@tonic-gate * with the License. 80Sstevel@tonic-gate * 90Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 100Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 110Sstevel@tonic-gate * See the License for the specific language governing permissions 120Sstevel@tonic-gate * and limitations under the License. 130Sstevel@tonic-gate * 140Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 150Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 160Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 170Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 180Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 190Sstevel@tonic-gate * 200Sstevel@tonic-gate * CDDL HEADER END 210Sstevel@tonic-gate */ 220Sstevel@tonic-gate /* 23*350Sdp * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24*350Sdp * Use is subject to license terms. 250Sstevel@tonic-gate */ 260Sstevel@tonic-gate /* Copyright (c) 1988 AT&T */ 270Sstevel@tonic-gate /* All Rights Reserved */ 280Sstevel@tonic-gate 290Sstevel@tonic-gate 300Sstevel@tonic-gate /* 310Sstevel@tonic-gate * University Copyright- Copyright (c) 1982, 1986, 1988 320Sstevel@tonic-gate * The Regents of the University of California 330Sstevel@tonic-gate * All Rights Reserved 340Sstevel@tonic-gate * 350Sstevel@tonic-gate * University Acknowledgment- Portions of this document are derived from 360Sstevel@tonic-gate * software developed by the University of California, Berkeley, and its 370Sstevel@tonic-gate * contributors. 380Sstevel@tonic-gate */ 390Sstevel@tonic-gate 400Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 410Sstevel@tonic-gate 420Sstevel@tonic-gate /* 430Sstevel@tonic-gate ************************************************************************* 440Sstevel@tonic-gate * COPYRIGHT NOTICE * 450Sstevel@tonic-gate ************************************************************************* 460Sstevel@tonic-gate * This software is copyright(C) 1982 by Pavel Curtis * 470Sstevel@tonic-gate * * 480Sstevel@tonic-gate * Permission is granted to reproduce and distribute * 490Sstevel@tonic-gate * this file by any means so long as no fee is charged * 500Sstevel@tonic-gate * above a nominal handling fee and so long as this * 510Sstevel@tonic-gate * notice is always included in the copies. * 520Sstevel@tonic-gate * * 530Sstevel@tonic-gate * Other rights are reserved except as explicitly granted * 540Sstevel@tonic-gate * by written permission of the author. * 550Sstevel@tonic-gate * Pavel Curtis * 560Sstevel@tonic-gate * Computer Science Dept. * 570Sstevel@tonic-gate * 405 Upson Halli * 580Sstevel@tonic-gate * Cornell Universityi * 590Sstevel@tonic-gate * Ithaca, NY 14853 * 600Sstevel@tonic-gate * * 610Sstevel@tonic-gate * Ph- (607) 256-4934 * 620Sstevel@tonic-gate * * 630Sstevel@tonic-gate * Pavel.Cornell@Udel-Relay(ARPAnet) * 640Sstevel@tonic-gate * decvax!cornell!pavel(UUCPnet) * 650Sstevel@tonic-gate *********************************************************************** */ 660Sstevel@tonic-gate 670Sstevel@tonic-gate /* 680Sstevel@tonic-gate * comp_main.c --- Main program for terminfo compiler 690Sstevel@tonic-gate * 700Sstevel@tonic-gate * $Log: RCS/comp_main.v $ 710Sstevel@tonic-gate * Revision 2.1 82/10/25 14:45:37 pavel 720Sstevel@tonic-gate * Added Copyright Notice 730Sstevel@tonic-gate * 740Sstevel@tonic-gate * Revision 2.0 82/10/24 15:16:37 pavel 750Sstevel@tonic-gate * Beta-one Test Release 760Sstevel@tonic-gate * 770Sstevel@tonic-gate * Revision 1.3 82/08/23 22:29:36 pavel 780Sstevel@tonic-gate * The REAL Alpha-one Release Version 790Sstevel@tonic-gate * 800Sstevel@tonic-gate * Revision 1.2 82/08/19 19:09:49 pavel 810Sstevel@tonic-gate * Alpha Test Release One 820Sstevel@tonic-gate * 830Sstevel@tonic-gate * Revision 1.1 82/08/12 18:36:55 pavel 840Sstevel@tonic-gate * Initial revision 850Sstevel@tonic-gate * 860Sstevel@tonic-gate * 870Sstevel@tonic-gate */ 880Sstevel@tonic-gate 890Sstevel@tonic-gate 900Sstevel@tonic-gate #define EXTERN /* EXTERN=extern in other .c files */ 910Sstevel@tonic-gate #include <sys/types.h> 920Sstevel@tonic-gate #include <sys/stat.h> 930Sstevel@tonic-gate #include <stdlib.h> 940Sstevel@tonic-gate #include <unistd.h> 950Sstevel@tonic-gate #include "compiler.h" 960Sstevel@tonic-gate 970Sstevel@tonic-gate char *source_file = "./terminfo.src"; 980Sstevel@tonic-gate char *destination = SRCDIR; 990Sstevel@tonic-gate char *usage_string = "[-v[n]] [-c] source-file\n"; 1000Sstevel@tonic-gate char check_only = 0; 1010Sstevel@tonic-gate char *progname; 1020Sstevel@tonic-gate 1030Sstevel@tonic-gate extern void make_hash_table(); /* should be in a header file :-( */ 1040Sstevel@tonic-gate extern void compile(); /* should be in a header file :-( */ 1050Sstevel@tonic-gate extern void syserr_abort(); /* should be in a header file :-( */ 1060Sstevel@tonic-gate static void init(); 1070Sstevel@tonic-gate 108*350Sdp int 1090Sstevel@tonic-gate main(int argc, char *argv[]) 1100Sstevel@tonic-gate { 1110Sstevel@tonic-gate int i; 1120Sstevel@tonic-gate int argflag = FALSE; 1130Sstevel@tonic-gate 1140Sstevel@tonic-gate debug_level = 0; 1150Sstevel@tonic-gate progname = argv[0]; 1160Sstevel@tonic-gate 1170Sstevel@tonic-gate umask(022); 1180Sstevel@tonic-gate 1190Sstevel@tonic-gate for (i = 1; i < argc; i++) { 1200Sstevel@tonic-gate if (argv[i][0] == '-') { 1210Sstevel@tonic-gate switch (argv[i][1]) { 1220Sstevel@tonic-gate case 'c': 1230Sstevel@tonic-gate check_only = 1; 1240Sstevel@tonic-gate break; 1250Sstevel@tonic-gate 1260Sstevel@tonic-gate case 'v': 1270Sstevel@tonic-gate debug_level = argv[i][2] ? atoi(&argv[i][2]) : 1; 1280Sstevel@tonic-gate break; 1290Sstevel@tonic-gate 1300Sstevel@tonic-gate default: 1310Sstevel@tonic-gate fprintf(stderr, 1320Sstevel@tonic-gate "%s: Unknown option. Usage is:\n\t%s: %s\n", 1330Sstevel@tonic-gate argv[0], progname, usage_string); 1340Sstevel@tonic-gate exit(1); 1350Sstevel@tonic-gate } 1360Sstevel@tonic-gate } else if (argflag) { 1370Sstevel@tonic-gate fprintf(stderr, "%s: Too many file names. Usage is:\n\t%s\n", 1380Sstevel@tonic-gate argv[0], usage_string); 1390Sstevel@tonic-gate exit(1); 1400Sstevel@tonic-gate } else { 1410Sstevel@tonic-gate argflag = TRUE; 1420Sstevel@tonic-gate source_file = argv[i]; 1430Sstevel@tonic-gate } 1440Sstevel@tonic-gate } 1450Sstevel@tonic-gate 1460Sstevel@tonic-gate init(); 1470Sstevel@tonic-gate make_hash_table(); 1480Sstevel@tonic-gate compile(); 1490Sstevel@tonic-gate 1500Sstevel@tonic-gate exit(0); 1510Sstevel@tonic-gate 1520Sstevel@tonic-gate return(0); 1530Sstevel@tonic-gate } 1540Sstevel@tonic-gate 1550Sstevel@tonic-gate /* 1560Sstevel@tonic-gate * init() 1570Sstevel@tonic-gate * 1580Sstevel@tonic-gate * Miscellaneous initializations 1590Sstevel@tonic-gate * 1600Sstevel@tonic-gate * Open source file as standard input 1610Sstevel@tonic-gate * Change directory to working terminfo directory. 1620Sstevel@tonic-gate * 1630Sstevel@tonic-gate */ 1640Sstevel@tonic-gate 1650Sstevel@tonic-gate static void 1660Sstevel@tonic-gate init() 1670Sstevel@tonic-gate { 1680Sstevel@tonic-gate char *env = getenv("TERMINFO"); 1690Sstevel@tonic-gate 1700Sstevel@tonic-gate start_time = time((time_t *) 0); 1710Sstevel@tonic-gate 1720Sstevel@tonic-gate curr_line = 0; 1730Sstevel@tonic-gate 1740Sstevel@tonic-gate if (freopen(source_file, "r", stdin) == NULL) { 1750Sstevel@tonic-gate fprintf(stderr, "%s: Can't open %s\n", progname, source_file); 1760Sstevel@tonic-gate exit(1); 1770Sstevel@tonic-gate } 1780Sstevel@tonic-gate 1790Sstevel@tonic-gate if (env && *env) 1800Sstevel@tonic-gate destination = env; 1810Sstevel@tonic-gate 1820Sstevel@tonic-gate if (check_only) { 1830Sstevel@tonic-gate DEBUG(1, "Would be working in %s\n", destination); 1840Sstevel@tonic-gate } else { 1850Sstevel@tonic-gate DEBUG(1, "Working in %s\n", destination); 1860Sstevel@tonic-gate } 1870Sstevel@tonic-gate 1880Sstevel@tonic-gate if (access(destination, 7) < 0) { 1890Sstevel@tonic-gate fprintf(stderr, "%s: %s nonexistent or permission denied\n", 1900Sstevel@tonic-gate progname, destination); 1910Sstevel@tonic-gate exit(1); 1920Sstevel@tonic-gate } 1930Sstevel@tonic-gate 1940Sstevel@tonic-gate if (chdir(destination) < 0) { 1950Sstevel@tonic-gate fprintf(stderr, "%s: %s is not a directory\n", 1960Sstevel@tonic-gate progname, destination); 1970Sstevel@tonic-gate exit(1); 1980Sstevel@tonic-gate } 1990Sstevel@tonic-gate 2000Sstevel@tonic-gate } 2010Sstevel@tonic-gate 2020Sstevel@tonic-gate /* 2030Sstevel@tonic-gate * 2040Sstevel@tonic-gate * check_dir(dirletter) 2050Sstevel@tonic-gate * 2060Sstevel@tonic-gate * Check for access rights to the destination directory. 2070Sstevel@tonic-gate * Create any directories which don't exist. 2080Sstevel@tonic-gate * 2090Sstevel@tonic-gate */ 2100Sstevel@tonic-gate 2110Sstevel@tonic-gate void 2120Sstevel@tonic-gate check_dir(char dirletter) 2130Sstevel@tonic-gate { 2140Sstevel@tonic-gate struct stat64 statbuf; 2150Sstevel@tonic-gate static char dirnames[128]; 2160Sstevel@tonic-gate static char dir[2] = " "; 2170Sstevel@tonic-gate 2180Sstevel@tonic-gate if (dirnames[dirletter] == 0) { 2190Sstevel@tonic-gate dir[0] = dirletter; 2200Sstevel@tonic-gate if (stat64(dir, &statbuf) < 0) { 2210Sstevel@tonic-gate if (mkdir(dir, 0755) < 0) 2220Sstevel@tonic-gate syserr_abort("mkdir %s returned bad status", dir); 2230Sstevel@tonic-gate dirnames[dirletter] = 1; 2240Sstevel@tonic-gate } else if (access(dir, 7) < 0) { 2250Sstevel@tonic-gate fprintf(stderr, "%s: %s/%s: Permission denied\n", 2260Sstevel@tonic-gate progname, destination, dir); 2270Sstevel@tonic-gate perror(dir); 2280Sstevel@tonic-gate exit(1); 2290Sstevel@tonic-gate } else if ((statbuf.st_mode & S_IFMT) != S_IFDIR) { 2300Sstevel@tonic-gate fprintf(stderr, "%s: %s/%s: Not a directory\n", 2310Sstevel@tonic-gate progname, destination, dir); 2320Sstevel@tonic-gate perror(dir); 2330Sstevel@tonic-gate exit(1); 2340Sstevel@tonic-gate } 2350Sstevel@tonic-gate } 2360Sstevel@tonic-gate return; 2370Sstevel@tonic-gate } 2380Sstevel@tonic-gate 2390Sstevel@tonic-gate #include <curses.h> 2400Sstevel@tonic-gate #if (defined(SYSV) || defined(USG)) && !defined(SIGPOLL) 2410Sstevel@tonic-gate /* 2420Sstevel@tonic-gate * mkdir(dirname, mode) 2430Sstevel@tonic-gate * 2440Sstevel@tonic-gate * forks and execs the mkdir program to create the given directory 2450Sstevel@tonic-gate * 2460Sstevel@tonic-gate */ 2470Sstevel@tonic-gate 2480Sstevel@tonic-gate mkdir(dirname, mode) 2490Sstevel@tonic-gate #ifdef __STDC__ 2500Sstevel@tonic-gate const 2510Sstevel@tonic-gate #endif 2520Sstevel@tonic-gate char *dirname; 2530Sstevel@tonic-gate int mode; 2540Sstevel@tonic-gate { 2550Sstevel@tonic-gate int fork_rtn; 2560Sstevel@tonic-gate int status; 2570Sstevel@tonic-gate 2580Sstevel@tonic-gate fork_rtn = fork(); 2590Sstevel@tonic-gate 2600Sstevel@tonic-gate switch (fork_rtn) { 2610Sstevel@tonic-gate case 0: /* Child */ 2620Sstevel@tonic-gate (void) execl("/bin/mkdir", "mkdir", dirname, (char *)0); 2630Sstevel@tonic-gate _exit(1); 2640Sstevel@tonic-gate 2650Sstevel@tonic-gate case -1: /* Error */ 2660Sstevel@tonic-gate fprintf(stderr, "%s: SYSTEM ERROR!! Fork failed!!!\n", 2670Sstevel@tonic-gate progname); 2680Sstevel@tonic-gate exit(1); 2690Sstevel@tonic-gate 2700Sstevel@tonic-gate default: 2710Sstevel@tonic-gate (void) wait(&status); 2720Sstevel@tonic-gate if ((status != 0) || (chmod(dirname, mode) == -1)) 2730Sstevel@tonic-gate return (-1); 2740Sstevel@tonic-gate return (0); 2750Sstevel@tonic-gate } 2760Sstevel@tonic-gate } 2770Sstevel@tonic-gate #endif 278