From 068b61626b2727f4aaf4aa79a4025a9e5522c014 Mon Sep 17 00:00:00 2001 From: deuce <> Date: Wed, 26 May 2004 07:29:21 +0000 Subject: [PATCH] Use STDIN as the isatty() test Don't use silly "static enum" More ODTimer fixes --- src/odoors/ODCom.c | 9 +++++---- src/odoors/ODGetIn.c | 2 +- src/odoors/ODInEx1.c | 6 +++--- src/odoors/ODInQue.c | 4 ---- src/odoors/ODKrnl.c | 2 +- src/odoors/ODPlat.c | 33 +++++---------------------------- 6 files changed, 15 insertions(+), 41 deletions(-) diff --git a/src/odoors/ODCom.c b/src/odoors/ODCom.c index ef370cdb01..f838c8dc76 100644 --- a/src/odoors/ODCom.c +++ b/src/odoors/ODCom.c @@ -1784,11 +1784,11 @@ no_fossil: if(pPortInfo->Method == kComMethodStdIO || pPortInfo->Method == kComMethodUnspecified) { - if (isatty(STDOUT_FILENO)) { - tcgetattr(STDOUT_FILENO,&tio_default); + if (isatty(STDIN_FILENO)) { + tcgetattr(STDIN_FILENO,&tio_default); tio_raw = tio_default; cfmakeraw(&tio_raw); - tcsetattr(STDOUT_FILENO,TCSANOW,&tio_raw); + tcsetattr(STDIN_FILENO,TCSANOW,&tio_raw); setvbuf(stdout, NULL, _IONBF, 0); } @@ -1980,7 +1980,8 @@ tODResult ODComClose(tPortHandle hPort) #ifdef INCLUDE_STDIO_COM case kComMethodStdIO: - tcsetattr(STDOUT_FILENO,TCSANOW,&tio_default); + if(isatty(STDIN_FILENO)) + tcsetattr(STDIN_FILENO,TCSANOW,&tio_default); break; #endif diff --git a/src/odoors/ODGetIn.c b/src/odoors/ODGetIn.c index 2af72f808f..bc905510f2 100644 --- a/src/odoors/ODGetIn.c +++ b/src/odoors/ODGetIn.c @@ -210,6 +210,7 @@ ODAPIDEF BOOL ODCALL od_get_input(tODInputEvent *pInputEvent, /* Loop until we have a valid input event, or until we should exit for */ /* some other reason. */ bGotEvent = FALSE; + while(!bGotEvent) { /* If we aren't supposed to wait for input, then fail if there is */ @@ -371,7 +372,6 @@ ODAPIDEF BOOL ODCALL od_get_input(tODInputEvent *pInputEvent, ODTimerStart(&SequenceFailTimer, MAX_CHARACTER_LATENCY); } bTimerActive = TRUE; - /* We only get here if we don't fully match a control sequence. */ /* If this was the first character of a control sequence, we only */ diff --git a/src/odoors/ODInEx1.c b/src/odoors/ODInEx1.c index 3f22624cc3..e6a556f84a 100644 --- a/src/odoors/ODInEx1.c +++ b/src/odoors/ODInEx1.c @@ -264,7 +264,7 @@ static char *apszDropFileNames[] = /* Array of door information (drop) file numbers * (corresponding to apszDropFileNames) */ -static enum { +enum { FOUND_EXITINFO_BBS, FOUND_DORINFO1_DEF, FOUND_CHAIN_TXT, @@ -2252,8 +2252,8 @@ malloc_error: od_control.baud=19200; gethostname(od_control.system_name,sizeof(od_control.system_name)); od_control.system_name[sizeof(od_control.system_name)-1]=0; - if (isatty(STDOUT_FILENO)) { - tcgetattr(STDOUT_FILENO,&term); + if (isatty(STDIN_FILENO)) { + tcgetattr(STDIN_FILENO,&term); od_control.baud=cfgetispeed(&term); if(!od_control.baud) od_control.baud=cfgetispeed(&term); diff --git a/src/odoors/ODInQue.c b/src/odoors/ODInQue.c index 46c49484bc..a2c0a7d40c 100644 --- a/src/odoors/ODInQue.c +++ b/src/odoors/ODInQue.c @@ -304,10 +304,6 @@ tODResult ODInQueueGetNextEvent(tODInQueueHandle hInQueue, tODInputEvent *pEvent, tODMilliSec Timeout) { tInputQueueInfo *pInputQueueInfo = ODHANDLE2PTR(hInQueue, tInputQueueInfo); -#ifdef ODPLAT_NIX - struct timeval tv; - fd_set in; -#endif ASSERT(pInputQueueInfo != NULL); ASSERT(pEvent != NULL); diff --git a/src/odoors/ODKrnl.c b/src/odoors/ODKrnl.c index 8d12d8999f..5c4c5cf8c6 100644 --- a/src/odoors/ODKrnl.c +++ b/src/odoors/ODKrnl.c @@ -193,7 +193,7 @@ tODResult ODKrnlInitialize(void) sigemptyset(&(act.sa_mask)); sigaction(SIGHUP,&act,NULL); - /* Run kernel on SIGALRM (Every 1 second) */ + /* Run kernel on SIGALRM (Every .01 seconds) */ act.sa_handler=sig_run_kernel; act.sa_flags=SA_RESTART; sigemptyset(&(act.sa_mask)); diff --git a/src/odoors/ODPlat.c b/src/odoors/ODPlat.c index 0279e8dd23..c0ed58e446 100644 --- a/src/odoors/ODPlat.c +++ b/src/odoors/ODPlat.c @@ -632,9 +632,6 @@ BOOL ODTimerElapsed(tODTimer *pTimer) */ void ODTimerWaitForElapse(tODTimer *pTimer) { -#ifdef ODPLAT_NIX - struct timeval tv; -#endif ASSERT(pTimer != NULL); #ifdef ODPLAT_DOS @@ -651,32 +648,12 @@ void ODTimerWaitForElapse(tODTimer *pTimer) od_sleep(0); } -#elif defined(ODPLAT_NIX) - /* This is timing sensitive and *MUST* wait regardless of 100% CPU or signals */ - od_sleep(ODTimerLeft(pTimer)); #else /* !ODPLAT_DOS */ - { - /* Under other platforms, timer resolution is high enough that we can */ - /* ask the OS to block this thread for the amount of time required */ - /* for the timer to elapse. */ - - tODMilliSec CurrentTime; - tODMilliSec TimerElapseTime = pTimer->Start + pTimer->Duration; + /* Under other platforms, timer resolution is high enough that we can */ + /* ask the OS to block this thread for the amount of time required */ + /* for the timer to elapse. */ - /* Determine the current time. */ -#ifdef ODPLAT_WIN32 - CurrentTime = GetCurrentTime(); -#endif /* ODPLAT_WIN32 */ - - if(TimerElapseTime <= CurrentTime) - { - /* Timer has already elapsed. */ - return; - } - - /* Sleep for the amount of time left until the timer should elapse. */ - od_sleep(TimerElapseTime - CurrentTime); - } + od_sleep(ODTimerLeft(pTimer)); #endif /* !ODPLAT_DOS */ } @@ -718,7 +695,7 @@ tODMilliSec ODTimerLeft(tODTimer *pTimer) } #elif defined(ODPLAT_NIX) gettimeofday(&tv,NULL); - left=(long long)tv.tv_sec*1000+tv.tv_usec/1000-pTimer->Start; + left=pTimer->Start+pTimer->Duration-(long long)tv.tv_sec*1000-tv.tv_usec/1000; if(left<0) left=0; return(left); -- GitLab