lib_initscr.c revision 178866
1247835Skib/**************************************************************************** 2247835Skib * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. * 3247835Skib * * 4247835Skib * Permission is hereby granted, free of charge, to any person obtaining a * 5247835Skib * copy of this software and associated documentation files (the * 6247835Skib * "Software"), to deal in the Software without restriction, including * 7247835Skib * without limitation the rights to use, copy, modify, merge, publish, * 8247835Skib * distribute, distribute with modifications, sublicense, and/or sell * 9247835Skib * copies of the Software, and to permit persons to whom the Software is * 10247835Skib * furnished to do so, subject to the following conditions: * 11247835Skib * * 12247835Skib * The above copyright notice and this permission notice shall be included * 13247835Skib * in all copies or substantial portions of the Software. * 14247835Skib * * 15247835Skib * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * 16247835Skib * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * 17247835Skib * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * 18247835Skib * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * 19247835Skib * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * 20247835Skib * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * 21247835Skib * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * 22247835Skib * * 23247835Skib * Except as contained in this notice, the name(s) of the above copyright * 24247835Skib * holders shall not be used in advertising or otherwise to promote the * 25247835Skib * sale, use or other dealings in this Software without prior written * 26247835Skib * authorization. * 27247835Skib ****************************************************************************/ 28247835Skib 29247835Skib/**************************************************************************** 30247835Skib * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * 31247835Skib * and: Eric S. Raymond <esr@snark.thyrsus.com> * 32247835Skib * and: Thomas E. Dickey 1996-2003 * 33247835Skib ****************************************************************************/ 34247835Skib 35247835Skib/* 36247835Skib** lib_initscr.c 37247835Skib** 38247835Skib** The routines initscr(), and termname(). 39247835Skib** 40247835Skib*/ 41247835Skib 42247835Skib#include <curses.priv.h> 43247835Skib 44247835Skib#if HAVE_SYS_TERMIO_H 45247835Skib#include <sys/termio.h> /* needed for ISC */ 46247835Skib#endif 47247835Skib 48247835SkibMODULE_ID("$Id: lib_initscr.c,v 1.36 2008/04/12 18:11:36 tom Exp $") 49247835Skib 50247835SkibNCURSES_EXPORT(WINDOW *) 51247835Skibinitscr(void) 52247835Skib{ 53247835Skib WINDOW *result; 54247835Skib 55247835Skib NCURSES_CONST char *name; 56247835Skib 57247835Skib START_TRACE(); 58247835Skib T((T_CALLED("initscr()"))); 59247835Skib 60247835Skib _nc_lock_global(set_SP); 61247835Skib /* Portable applications must not call initscr() more than once */ 62247835Skib if (!_nc_globals.init_screen) { 63247835Skib _nc_globals.init_screen = TRUE; 64247835Skib 65247835Skib if ((name = getenv("TERM")) == 0 66247835Skib || *name == '\0') 67247835Skib name = "unknown"; 68247835Skib#ifdef __CYGWIN__ 69247835Skib /* 70247835Skib * 2002/9/21 71247835Skib * Work around a bug in Cygwin. Full-screen subprocesses run from 72247835Skib * bash, in turn spawned from another full-screen process, will dump 73247835Skib * core when attempting to write to stdout. Opening /dev/tty 74247835Skib * explicitly seems to fix the problem. 75247835Skib */ 76247835Skib if (isatty(fileno(stdout))) { 77247835Skib FILE *fp = fopen("/dev/tty", "w"); 78247835Skib if (fp != 0 && isatty(fileno(fp))) { 79247835Skib fclose(stdout); 80247835Skib dup2(fileno(fp), STDOUT_FILENO); 81247835Skib stdout = fdopen(STDOUT_FILENO, "w"); 82247835Skib } 83247835Skib } 84247835Skib#endif 85247835Skib if (newterm(name, stdout, stdin) == 0) { 86247835Skib fprintf(stderr, "Error opening terminal: %s.\n", name); 87247835Skib exit(EXIT_FAILURE); 88247835Skib } 89247835Skib 90247835Skib /* def_shell_mode - done in newterm/_nc_setupscreen */ 91247835Skib def_prog_mode(); 92247835Skib } 93247835Skib result = stdscr; 94247835Skib _nc_unlock_global(set_SP); 95247835Skib 96247835Skib returnWin(result); 97247835Skib} 98247835Skib