17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 77c478bd9Sstevel@tonic-gate * with the License. 87c478bd9Sstevel@tonic-gate * 97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 127c478bd9Sstevel@tonic-gate * and limitations under the License. 137c478bd9Sstevel@tonic-gate * 147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 197c478bd9Sstevel@tonic-gate * 207c478bd9Sstevel@tonic-gate * CDDL HEADER END 217c478bd9Sstevel@tonic-gate */ 227c478bd9Sstevel@tonic-gate /* 23*d2117003Sdp * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24*d2117003Sdp * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate /* Copyright (c) 1988 AT&T */ 277c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate 307c478bd9Sstevel@tonic-gate /* 317c478bd9Sstevel@tonic-gate * University Copyright- Copyright (c) 1982, 1986, 1988 327c478bd9Sstevel@tonic-gate * The Regents of the University of California 337c478bd9Sstevel@tonic-gate * All Rights Reserved 347c478bd9Sstevel@tonic-gate * 357c478bd9Sstevel@tonic-gate * University Acknowledgment- Portions of this document are derived from 367c478bd9Sstevel@tonic-gate * software developed by the University of California, Berkeley, and its 377c478bd9Sstevel@tonic-gate * contributors. 387c478bd9Sstevel@tonic-gate */ 397c478bd9Sstevel@tonic-gate 407c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 417c478bd9Sstevel@tonic-gate 427c478bd9Sstevel@tonic-gate /* 437c478bd9Sstevel@tonic-gate ************************************************************************* 447c478bd9Sstevel@tonic-gate * COPYRIGHT NOTICE * 457c478bd9Sstevel@tonic-gate ************************************************************************* 467c478bd9Sstevel@tonic-gate * This software is copyright(C) 1982 by Pavel Curtis * 477c478bd9Sstevel@tonic-gate * * 487c478bd9Sstevel@tonic-gate * Permission is granted to reproduce and distribute * 497c478bd9Sstevel@tonic-gate * this file by any means so long as no fee is charged * 507c478bd9Sstevel@tonic-gate * above a nominal handling fee and so long as this * 517c478bd9Sstevel@tonic-gate * notice is always included in the copies. * 527c478bd9Sstevel@tonic-gate * * 537c478bd9Sstevel@tonic-gate * Other rights are reserved except as explicitly granted * 547c478bd9Sstevel@tonic-gate * by written permission of the author. * 557c478bd9Sstevel@tonic-gate * Pavel Curtis * 567c478bd9Sstevel@tonic-gate * Computer Science Dept. * 577c478bd9Sstevel@tonic-gate * 405 Upson Halli * 587c478bd9Sstevel@tonic-gate * Cornell Universityi * 597c478bd9Sstevel@tonic-gate * Ithaca, NY 14853 * 607c478bd9Sstevel@tonic-gate * * 617c478bd9Sstevel@tonic-gate * Ph- (607) 256-4934 * 627c478bd9Sstevel@tonic-gate * * 637c478bd9Sstevel@tonic-gate * Pavel.Cornell@Udel-Relay(ARPAnet) * 647c478bd9Sstevel@tonic-gate * decvax!cornell!pavel(UUCPnet) * 657c478bd9Sstevel@tonic-gate *********************************************************************** */ 667c478bd9Sstevel@tonic-gate 677c478bd9Sstevel@tonic-gate /* 687c478bd9Sstevel@tonic-gate * comp_main.c --- Main program for terminfo compiler 697c478bd9Sstevel@tonic-gate * 707c478bd9Sstevel@tonic-gate * $Log: RCS/comp_main.v $ 717c478bd9Sstevel@tonic-gate * Revision 2.1 82/10/25 14:45:37 pavel 727c478bd9Sstevel@tonic-gate * Added Copyright Notice 737c478bd9Sstevel@tonic-gate * 747c478bd9Sstevel@tonic-gate * Revision 2.0 82/10/24 15:16:37 pavel 757c478bd9Sstevel@tonic-gate * Beta-one Test Release 767c478bd9Sstevel@tonic-gate * 777c478bd9Sstevel@tonic-gate * Revision 1.3 82/08/23 22:29:36 pavel 787c478bd9Sstevel@tonic-gate * The REAL Alpha-one Release Version 797c478bd9Sstevel@tonic-gate * 807c478bd9Sstevel@tonic-gate * Revision 1.2 82/08/19 19:09:49 pavel 817c478bd9Sstevel@tonic-gate * Alpha Test Release One 827c478bd9Sstevel@tonic-gate * 837c478bd9Sstevel@tonic-gate * Revision 1.1 82/08/12 18:36:55 pavel 847c478bd9Sstevel@tonic-gate * Initial revision 857c478bd9Sstevel@tonic-gate * 867c478bd9Sstevel@tonic-gate * 877c478bd9Sstevel@tonic-gate */ 887c478bd9Sstevel@tonic-gate 897c478bd9Sstevel@tonic-gate 907c478bd9Sstevel@tonic-gate #define EXTERN /* EXTERN=extern in other .c files */ 917c478bd9Sstevel@tonic-gate #include <sys/types.h> 927c478bd9Sstevel@tonic-gate #include <sys/stat.h> 937c478bd9Sstevel@tonic-gate #include <stdlib.h> 947c478bd9Sstevel@tonic-gate #include <unistd.h> 957c478bd9Sstevel@tonic-gate #include "compiler.h" 967c478bd9Sstevel@tonic-gate 977c478bd9Sstevel@tonic-gate char *source_file = "./terminfo.src"; 987c478bd9Sstevel@tonic-gate char *destination = SRCDIR; 997c478bd9Sstevel@tonic-gate char *usage_string = "[-v[n]] [-c] source-file\n"; 1007c478bd9Sstevel@tonic-gate char check_only = 0; 1017c478bd9Sstevel@tonic-gate char *progname; 1027c478bd9Sstevel@tonic-gate 1037c478bd9Sstevel@tonic-gate extern void make_hash_table(); /* should be in a header file :-( */ 1047c478bd9Sstevel@tonic-gate extern void compile(); /* should be in a header file :-( */ 1057c478bd9Sstevel@tonic-gate extern void syserr_abort(); /* should be in a header file :-( */ 1067c478bd9Sstevel@tonic-gate static void init(); 1077c478bd9Sstevel@tonic-gate 108*d2117003Sdp int 1097c478bd9Sstevel@tonic-gate main(int argc, char *argv[]) 1107c478bd9Sstevel@tonic-gate { 1117c478bd9Sstevel@tonic-gate int i; 1127c478bd9Sstevel@tonic-gate int argflag = FALSE; 1137c478bd9Sstevel@tonic-gate 1147c478bd9Sstevel@tonic-gate debug_level = 0; 1157c478bd9Sstevel@tonic-gate progname = argv[0]; 1167c478bd9Sstevel@tonic-gate 1177c478bd9Sstevel@tonic-gate umask(022); 1187c478bd9Sstevel@tonic-gate 1197c478bd9Sstevel@tonic-gate for (i = 1; i < argc; i++) { 1207c478bd9Sstevel@tonic-gate if (argv[i][0] == '-') { 1217c478bd9Sstevel@tonic-gate switch (argv[i][1]) { 1227c478bd9Sstevel@tonic-gate case 'c': 1237c478bd9Sstevel@tonic-gate check_only = 1; 1247c478bd9Sstevel@tonic-gate break; 1257c478bd9Sstevel@tonic-gate 1267c478bd9Sstevel@tonic-gate case 'v': 1277c478bd9Sstevel@tonic-gate debug_level = argv[i][2] ? atoi(&argv[i][2]) : 1; 1287c478bd9Sstevel@tonic-gate break; 1297c478bd9Sstevel@tonic-gate 1307c478bd9Sstevel@tonic-gate default: 1317c478bd9Sstevel@tonic-gate fprintf(stderr, 1327c478bd9Sstevel@tonic-gate "%s: Unknown option. Usage is:\n\t%s: %s\n", 1337c478bd9Sstevel@tonic-gate argv[0], progname, usage_string); 1347c478bd9Sstevel@tonic-gate exit(1); 1357c478bd9Sstevel@tonic-gate } 1367c478bd9Sstevel@tonic-gate } else if (argflag) { 1377c478bd9Sstevel@tonic-gate fprintf(stderr, "%s: Too many file names. Usage is:\n\t%s\n", 1387c478bd9Sstevel@tonic-gate argv[0], usage_string); 1397c478bd9Sstevel@tonic-gate exit(1); 1407c478bd9Sstevel@tonic-gate } else { 1417c478bd9Sstevel@tonic-gate argflag = TRUE; 1427c478bd9Sstevel@tonic-gate source_file = argv[i]; 1437c478bd9Sstevel@tonic-gate } 1447c478bd9Sstevel@tonic-gate } 1457c478bd9Sstevel@tonic-gate 1467c478bd9Sstevel@tonic-gate init(); 1477c478bd9Sstevel@tonic-gate make_hash_table(); 1487c478bd9Sstevel@tonic-gate compile(); 1497c478bd9Sstevel@tonic-gate 1507c478bd9Sstevel@tonic-gate exit(0); 1517c478bd9Sstevel@tonic-gate 1527c478bd9Sstevel@tonic-gate return(0); 1537c478bd9Sstevel@tonic-gate } 1547c478bd9Sstevel@tonic-gate 1557c478bd9Sstevel@tonic-gate /* 1567c478bd9Sstevel@tonic-gate * init() 1577c478bd9Sstevel@tonic-gate * 1587c478bd9Sstevel@tonic-gate * Miscellaneous initializations 1597c478bd9Sstevel@tonic-gate * 1607c478bd9Sstevel@tonic-gate * Open source file as standard input 1617c478bd9Sstevel@tonic-gate * Change directory to working terminfo directory. 1627c478bd9Sstevel@tonic-gate * 1637c478bd9Sstevel@tonic-gate */ 1647c478bd9Sstevel@tonic-gate 1657c478bd9Sstevel@tonic-gate static void 1667c478bd9Sstevel@tonic-gate init() 1677c478bd9Sstevel@tonic-gate { 1687c478bd9Sstevel@tonic-gate char *env = getenv("TERMINFO"); 1697c478bd9Sstevel@tonic-gate 1707c478bd9Sstevel@tonic-gate start_time = time((time_t *) 0); 1717c478bd9Sstevel@tonic-gate 1727c478bd9Sstevel@tonic-gate curr_line = 0; 1737c478bd9Sstevel@tonic-gate 1747c478bd9Sstevel@tonic-gate if (freopen(source_file, "r", stdin) == NULL) { 1757c478bd9Sstevel@tonic-gate fprintf(stderr, "%s: Can't open %s\n", progname, source_file); 1767c478bd9Sstevel@tonic-gate exit(1); 1777c478bd9Sstevel@tonic-gate } 1787c478bd9Sstevel@tonic-gate 1797c478bd9Sstevel@tonic-gate if (env && *env) 1807c478bd9Sstevel@tonic-gate destination = env; 1817c478bd9Sstevel@tonic-gate 1827c478bd9Sstevel@tonic-gate if (check_only) { 1837c478bd9Sstevel@tonic-gate DEBUG(1, "Would be working in %s\n", destination); 1847c478bd9Sstevel@tonic-gate } else { 1857c478bd9Sstevel@tonic-gate DEBUG(1, "Working in %s\n", destination); 1867c478bd9Sstevel@tonic-gate } 1877c478bd9Sstevel@tonic-gate 1887c478bd9Sstevel@tonic-gate if (access(destination, 7) < 0) { 1897c478bd9Sstevel@tonic-gate fprintf(stderr, "%s: %s nonexistent or permission denied\n", 1907c478bd9Sstevel@tonic-gate progname, destination); 1917c478bd9Sstevel@tonic-gate exit(1); 1927c478bd9Sstevel@tonic-gate } 1937c478bd9Sstevel@tonic-gate 1947c478bd9Sstevel@tonic-gate if (chdir(destination) < 0) { 1957c478bd9Sstevel@tonic-gate fprintf(stderr, "%s: %s is not a directory\n", 1967c478bd9Sstevel@tonic-gate progname, destination); 1977c478bd9Sstevel@tonic-gate exit(1); 1987c478bd9Sstevel@tonic-gate } 1997c478bd9Sstevel@tonic-gate 2007c478bd9Sstevel@tonic-gate } 2017c478bd9Sstevel@tonic-gate 2027c478bd9Sstevel@tonic-gate /* 2037c478bd9Sstevel@tonic-gate * 2047c478bd9Sstevel@tonic-gate * check_dir(dirletter) 2057c478bd9Sstevel@tonic-gate * 2067c478bd9Sstevel@tonic-gate * Check for access rights to the destination directory. 2077c478bd9Sstevel@tonic-gate * Create any directories which don't exist. 2087c478bd9Sstevel@tonic-gate * 2097c478bd9Sstevel@tonic-gate */ 2107c478bd9Sstevel@tonic-gate 2117c478bd9Sstevel@tonic-gate void 2127c478bd9Sstevel@tonic-gate check_dir(char dirletter) 2137c478bd9Sstevel@tonic-gate { 2147c478bd9Sstevel@tonic-gate struct stat64 statbuf; 2157c478bd9Sstevel@tonic-gate static char dirnames[128]; 2167c478bd9Sstevel@tonic-gate static char dir[2] = " "; 2177c478bd9Sstevel@tonic-gate 2187c478bd9Sstevel@tonic-gate if (dirnames[dirletter] == 0) { 2197c478bd9Sstevel@tonic-gate dir[0] = dirletter; 2207c478bd9Sstevel@tonic-gate if (stat64(dir, &statbuf) < 0) { 2217c478bd9Sstevel@tonic-gate if (mkdir(dir, 0755) < 0) 2227c478bd9Sstevel@tonic-gate syserr_abort("mkdir %s returned bad status", dir); 2237c478bd9Sstevel@tonic-gate dirnames[dirletter] = 1; 2247c478bd9Sstevel@tonic-gate } else if (access(dir, 7) < 0) { 2257c478bd9Sstevel@tonic-gate fprintf(stderr, "%s: %s/%s: Permission denied\n", 2267c478bd9Sstevel@tonic-gate progname, destination, dir); 2277c478bd9Sstevel@tonic-gate perror(dir); 2287c478bd9Sstevel@tonic-gate exit(1); 2297c478bd9Sstevel@tonic-gate } else if ((statbuf.st_mode & S_IFMT) != S_IFDIR) { 2307c478bd9Sstevel@tonic-gate fprintf(stderr, "%s: %s/%s: Not a directory\n", 2317c478bd9Sstevel@tonic-gate progname, destination, dir); 2327c478bd9Sstevel@tonic-gate perror(dir); 2337c478bd9Sstevel@tonic-gate exit(1); 2347c478bd9Sstevel@tonic-gate } 2357c478bd9Sstevel@tonic-gate } 2367c478bd9Sstevel@tonic-gate return; 2377c478bd9Sstevel@tonic-gate } 2387c478bd9Sstevel@tonic-gate 2397c478bd9Sstevel@tonic-gate #include <curses.h> 2407c478bd9Sstevel@tonic-gate #if (defined(SYSV) || defined(USG)) && !defined(SIGPOLL) 2417c478bd9Sstevel@tonic-gate /* 2427c478bd9Sstevel@tonic-gate * mkdir(dirname, mode) 2437c478bd9Sstevel@tonic-gate * 2447c478bd9Sstevel@tonic-gate * forks and execs the mkdir program to create the given directory 2457c478bd9Sstevel@tonic-gate * 2467c478bd9Sstevel@tonic-gate */ 2477c478bd9Sstevel@tonic-gate 2487c478bd9Sstevel@tonic-gate mkdir(dirname, mode) 2497c478bd9Sstevel@tonic-gate #ifdef __STDC__ 2507c478bd9Sstevel@tonic-gate const 2517c478bd9Sstevel@tonic-gate #endif 2527c478bd9Sstevel@tonic-gate char *dirname; 2537c478bd9Sstevel@tonic-gate int mode; 2547c478bd9Sstevel@tonic-gate { 2557c478bd9Sstevel@tonic-gate int fork_rtn; 2567c478bd9Sstevel@tonic-gate int status; 2577c478bd9Sstevel@tonic-gate 2587c478bd9Sstevel@tonic-gate fork_rtn = fork(); 2597c478bd9Sstevel@tonic-gate 2607c478bd9Sstevel@tonic-gate switch (fork_rtn) { 2617c478bd9Sstevel@tonic-gate case 0: /* Child */ 2627c478bd9Sstevel@tonic-gate (void) execl("/bin/mkdir", "mkdir", dirname, (char *)0); 2637c478bd9Sstevel@tonic-gate _exit(1); 2647c478bd9Sstevel@tonic-gate 2657c478bd9Sstevel@tonic-gate case -1: /* Error */ 2667c478bd9Sstevel@tonic-gate fprintf(stderr, "%s: SYSTEM ERROR!! Fork failed!!!\n", 2677c478bd9Sstevel@tonic-gate progname); 2687c478bd9Sstevel@tonic-gate exit(1); 2697c478bd9Sstevel@tonic-gate 2707c478bd9Sstevel@tonic-gate default: 2717c478bd9Sstevel@tonic-gate (void) wait(&status); 2727c478bd9Sstevel@tonic-gate if ((status != 0) || (chmod(dirname, mode) == -1)) 2737c478bd9Sstevel@tonic-gate return (-1); 2747c478bd9Sstevel@tonic-gate return (0); 2757c478bd9Sstevel@tonic-gate } 2767c478bd9Sstevel@tonic-gate } 2777c478bd9Sstevel@tonic-gate #endif 278