1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 /* 23 * Copyright 1997 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 /* Copyright (c) 1988 AT&T */ 28 /* All Rights Reserved */ 29 30 /* 31 * University Copyright- Copyright (c) 1982, 1986, 1988 32 * The Regents of the University of California 33 * All Rights Reserved 34 * 35 * University Acknowledgment- Portions of this document are derived from 36 * software developed by the University of California, Berkeley, and its 37 * contributors. 38 */ 39 40 /*LINTLIBRARY*/ 41 42 #include <stdlib.h> 43 #include <signal.h> 44 #include <sys/types.h> 45 #include "curses_inc.h" 46 47 /* 48 * This routine initializes the current and standard screen, 49 * and sets up the terminal. In case of error, initscr aborts. 50 * If you want an error status returned, call 51 * scp = newscreen(getenv("TERM"), 0, 0, 0, stdout, stdin); 52 */ 53 54 WINDOW * 55 initscr(void) 56 { 57 #ifdef SIGPOLL 58 void (*savsignal)(int); 59 extern void _ccleanup(int); 60 #else /* SIGPOLL */ 61 int (*savsignal)(); 62 extern int _ccleanup(int); 63 #endif /* SIGPOLL */ 64 65 #ifdef SIGTSTP 66 extern void _tstp(int); 67 #endif /* SIGTSTP */ 68 69 static char i_called_before = FALSE; 70 71 /* Free structures we are about to throw away so we can reuse the memory. */ 72 73 if (i_called_before && SP) { 74 delscreen(SP); 75 SP = NULL; 76 } 77 if (newscreen(NULL, 0, 0, 0, stdout, stdin) == NULL) { 78 (void) reset_shell_mode(); 79 if (term_errno != -1) 80 termerr(); 81 else 82 curserr(); 83 exit(1); 84 } 85 86 #ifdef DEBUG 87 if (outf) 88 fprintf(outf, "initscr: term = %s\n", SP); 89 #endif /* DEBUG */ 90 i_called_before = TRUE; 91 92 #ifdef SIGTSTP 93 /*LINTED*/ 94 if ((savsignal = signal(SIGTSTP, SIG_IGN)) == SIG_DFL) 95 (void) signal(SIGTSTP, _tstp); 96 else 97 (void) signal(SIGTSTP, savsignal); 98 #endif /* SIGTSTP */ 99 /*LINTED*/ 100 if ((savsignal = signal(SIGINT, SIG_IGN)) == SIG_DFL) 101 (void) signal(SIGINT, _ccleanup); 102 else 103 (void) signal(SIGINT, savsignal); 104 105 /*LINTED*/ 106 if ((savsignal = signal(SIGQUIT, SIG_IGN)) == SIG_DFL) 107 (void) signal(SIGQUIT, _ccleanup); 108 else 109 (void) signal(SIGQUIT, savsignal); 110 111 return (stdscr); 112 } 113