From 9c16db9589f395decf9eff74bc48cc2e9a427a5a Mon Sep 17 00:00:00 2001 From: Pavel Stehule Date: Wed, 4 Oct 2023 16:05:05 +0200 Subject: [PATCH] supersedes #276, #278 where the discussion is (#303) --- pdcurses/initscr.c | 6 ++++-- vt/pdckbd.c | 19 ++++--------------- vt/pdcscrn.c | 9 ++++----- 3 files changed, 12 insertions(+), 22 deletions(-) diff --git a/pdcurses/initscr.c b/pdcurses/initscr.c index 5097f165..fe2c1622 100644 --- a/pdcurses/initscr.c +++ b/pdcurses/initscr.c @@ -162,6 +162,10 @@ SCREEN *newterm(const char *type, FILE *outfd, FILE *infd) if (!SP) return NULL; + /* output_fd, input_fd should be initialized before PDC_src_open */ + SP->output_fd = outfd ? outfd : stdout; + SP->input_fd = infd ? infd : stdin; + if (PDC_scr_open() == ERR) { fprintf(stderr, "initscr(): Unable to create SP\n"); @@ -286,8 +290,6 @@ SCREEN *newterm(const char *type, FILE *outfd, FILE *infd) return NULL; SP->c_ungind = 0; SP->c_ungmax = NUNGETCH; - SP->output_fd = outfd; - SP->input_fd = infd; return SP; } diff --git a/vt/pdckbd.c b/vt/pdckbd.c index 729712d4..be75709e 100644 --- a/vt/pdckbd.c +++ b/vt/pdckbd.c @@ -38,24 +38,13 @@ 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; if( PDC_resize_occurred) return( TRUE); - if( SP->input_fd && SP->input_fd != stdin) - { - rval = !feof( SP->input_fd); - if( rval && c) - { - *c = fgetc( SP->input_fd); - if( *c == EOF) - rval = FALSE; - } - return( rval); - } + #ifdef LINUX_FRAMEBUFFER_PORT PDC_check_for_blinking( ); #endif @@ -69,14 +58,14 @@ static bool check_key( int *c) return( TRUE); } FD_ZERO( &rdset); - FD_SET( STDIN, &rdset); + FD_SET( fileno( SP->input_fd), &rdset); timeout.tv_sec = 0; timeout.tv_usec = 0; - if( select( STDIN + 1, &rdset, NULL, NULL, &timeout) > 0) + if( select( fileno( SP->input_fd) + 1, &rdset, NULL, NULL, &timeout) > 0) { rval = TRUE; if( c) - *c = getchar( ); + *c = fgetc( SP->input_fd); } else rval = FALSE; diff --git a/vt/pdcscrn.c b/vt/pdcscrn.c index f77f4060..422c59e5 100644 --- a/vt/pdcscrn.c +++ b/vt/pdcscrn.c @@ -115,7 +115,6 @@ static int set_win10_for_vt_codes( const bool setting_mode) #endif bool PDC_resize_occurred = FALSE; -const int STDIN = 0; static mmask_t _stored_trap_mbe; /* COLOR_PAIR to attribute encoding table. */ @@ -125,14 +124,14 @@ void PDC_reset_prog_mode( void) #ifdef USE_TERMIOS struct termios term; - tcgetattr( STDIN, &orig_term); + tcgetattr( fileno( SP->input_fd), &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( SP->input_fd), TCSANOW, &term); #endif #ifndef _WIN32 if( !PDC_is_ansi) @@ -204,7 +203,7 @@ void PDC_scr_close( void) set_win10_for_vt_codes( FALSE); #else #if !defined( DOS) - tcsetattr( STDIN, TCSANOW, &orig_term); + tcsetattr( fileno( SP->input_fd), TCSANOW, &orig_term); #endif #endif PDC_doupdate( ); @@ -302,7 +301,7 @@ int PDC_scr_open(void) if (!SP || PDC_init_palette( )) return ERR; - setbuf( stdin, NULL); + setbuf( SP->input_fd, NULL); #ifdef USE_TERMIOS sigemptyset(&sa.sa_mask); sa.sa_flags = 0;