diff --git a/pdcurses/initscr.c b/pdcurses/initscr.c index 02c69c4f..df834a5a 100644 --- a/pdcurses/initscr.c +++ b/pdcurses/initscr.c @@ -148,6 +148,8 @@ MOUSE_STATUS Mouse_status; extern RIPPEDOFFLINE linesripped[5]; extern char linesrippedoff; +extern FILE *__infd; + WINDOW *initscr(void) { int i; @@ -161,6 +163,9 @@ WINDOW *initscr(void) if (!SP) return NULL; + if (!__infd) + __infd = stdin; + if (PDC_scr_open() == ERR) { fprintf(stderr, "initscr(): Unable to create SP\n"); @@ -330,7 +335,7 @@ SCREEN *newterm(const char *type, FILE *outfd, FILE *infd) INTENTIONALLY_UNUSED_PARAMETER( type); INTENTIONALLY_UNUSED_PARAMETER( outfd); - INTENTIONALLY_UNUSED_PARAMETER( infd); + __infd = infd; return initscr() ? SP : NULL; } diff --git a/vt/pdckbd.c b/vt/pdckbd.c index c9befcd9..5154274a 100644 --- a/vt/pdckbd.c +++ b/vt/pdckbd.c @@ -33,12 +33,12 @@ https://www.gnu.org/software/screen/manual/html_node/Control-Sequences.html */ extern bool PDC_resize_occurred; +FILE *__infd = NULL; static bool check_key( int *c) { bool rval; #ifndef USE_CONIO - const int STDIN = 0; struct timeval timeout; fd_set rdset; extern int PDC_n_ctrl_c; @@ -58,14 +58,14 @@ static bool check_key( int *c) return( TRUE); } FD_ZERO( &rdset); - FD_SET( STDIN, &rdset); + FD_SET( fileno(__infd), &rdset); timeout.tv_sec = 0; timeout.tv_usec = 0; - if( select( STDIN + 1, &rdset, NULL, NULL, &timeout) > 0) + if( select( fileno(__infd) + 1, &rdset, NULL, NULL, &timeout) > 0) { rval = TRUE; if( c) - *c = getchar( ); + *c = fgetc(__infd); } else rval = FALSE; diff --git a/vt/pdcscrn.c b/vt/pdcscrn.c index b6104f58..d7ecbae7 100644 --- a/vt/pdcscrn.c +++ b/vt/pdcscrn.c @@ -8,6 +8,7 @@ #include #include +extern FILE *__infd; static struct termios orig_term; #endif @@ -100,7 +101,6 @@ static int set_win10_for_vt_codes( const bool setting_mode) int PDC_rows = -1, PDC_cols = -1; bool PDC_resize_occurred = FALSE; -const int STDIN = 0; chtype PDC_capabilities = 0; static mmask_t _stored_trap_mbe; @@ -111,14 +111,14 @@ void PDC_reset_prog_mode( void) #ifdef USE_TERMIOS struct termios term; - tcgetattr( STDIN, &orig_term); + tcgetattr( fileno(__infd), &orig_term); memcpy( &term, &orig_term, sizeof( term)); term.c_lflag &= ~(ICANON | ECHO); term.c_iflag &= ~ICRNL; term.c_cc[VSUSP] = _POSIX_VDISABLE; /* disable Ctrl-Z */ term.c_cc[VSTOP] = _POSIX_VDISABLE; /* disable Ctrl-S */ term.c_cc[VSTART] = _POSIX_VDISABLE; /* disable Ctrl-Q */ - tcsetattr( STDIN, TCSANOW, &term); + tcsetattr( fileno(__infd), TCSANOW, &term); #endif #ifndef _WIN32 if( !PDC_is_ansi) @@ -190,7 +190,7 @@ void PDC_scr_close( void) set_win10_for_vt_codes( FALSE); #else #if !defined( DOS) - tcsetattr( STDIN, TCSANOW, &orig_term); + tcsetattr( fileno(__infd), TCSANOW, &orig_term); #endif #endif PDC_doupdate( ); @@ -212,7 +212,7 @@ static void sigwinchHandler( int sig) struct winsize ws; INTENTIONALLY_UNUSED_PARAMETER( sig); - if (ioctl(STDIN_FILENO, TIOCGWINSZ, &ws) != -1) + if (ioctl( fileno(__infd), TIOCGWINSZ, &ws) != -1) if( PDC_rows != ws.ws_row || PDC_cols != ws.ws_col) { PDC_rows = ws.ws_row; @@ -283,7 +283,7 @@ int PDC_scr_open(void) if (!SP || PDC_init_palette( )) return ERR; - setbuf( stdin, NULL); + setbuf(__infd, NULL); #ifdef USE_TERMIOS sigemptyset(&sa.sa_mask); sa.sa_flags = 0;