From be1ae7b7ee0da97bc79ffb25561bfcfc9b1e9728 Mon Sep 17 00:00:00 2001 From: John van Groningen Date: Fri, 24 Oct 2003 10:45:11 +0000 Subject: swap newline and carriage return characters in w_get_char and ungetc calls, to fix reading from the console, move use_stdio test to wait_for_key_press function, to prevent non termination after abort --- macho/_library.o | Bin 37528 -> 35900 bytes mcon.c | 29 ++++++++++++++--------------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/macho/_library.o b/macho/_library.o index 4d19dde..fa34b9b 100644 Binary files a/macho/_library.o and b/macho/_library.o differ diff --git a/mcon.c b/mcon.c index 8c51e3f..002001f 100644 --- a/mcon.c +++ b/mcon.c @@ -450,8 +450,9 @@ QDGlobals qd; #ifdef MAYBE_USE_STDIO static int use_stdio; -#define oputc(c) ((c=='\n') ? putchar('\r') : ((c=='\r') ? putchar('\n') : putchar(c))) -#define eputc(c) ((c=='\n') ? putc('\r',stderr) : ((c=='\r') ? putc('\n',stderr) : putc(c,stderr))) +#define swap_nl_cr(c) (((c)=='\n' || (c)=='\r') ? ((c) ^ ((char)('\n' ^ '\r'))) : (c)) +#define oputc(c) putchar(swap_nl_cr(c)) +#define eputc(c) putc(swap_nl_cr (c),stderr) inline void oputs(const char *s) {while (*s) {oputc(*s);s++;}} inline void eputs(const char *s) {while (*s) {eputc(*s);s++;}} #endif @@ -890,13 +891,14 @@ static void w_read_line() } } -int w_get_char() +int w_get_char (void) { int c; #ifdef MAYBE_USE_STDIO if (use_stdio){ - return getchar(); + c=getchar(); + return swap_nl_cr(c); } #endif @@ -960,7 +962,7 @@ int w_get_int (int *i_p) #ifdef MAYBE_USE_STDIO if (use_stdio){ if (c!=EOF) - ungetc (c,stdin); + ungetc (swap_nl_cr (c),stdin); } else { #endif --input_buffer_pos; @@ -985,7 +987,7 @@ int w_get_int (int *i_p) #ifdef MAYBE_USE_STDIO if (use_stdio){ if (c!=EOF) - ungetc (c,stdin); + ungetc (swap_nl_cr (c),stdin); } else { #endif --input_buffer_pos; @@ -1073,7 +1075,7 @@ int w_get_real (double *r_p) #ifdef MAYBE_USE_STDIO if (use_stdio){ if (c!=EOF) - ungetc (c,stdin); + ungetc (swap_nl_cr (c),stdin); } else { #endif --input_buffer_pos; @@ -1657,9 +1659,11 @@ static void wait_key() void wait_for_key_press (VOID) { -#if 1 - SetWTitle (flags & 16 ? e_window : c_window,"\ppress any key to exit"); +#ifdef MAYBE_USE_STDIO + if (use_stdio) + return; #endif + SetWTitle (flags & 16 ? e_window : c_window,"\ppress any key to exit"); wait_key(); } @@ -2138,12 +2142,7 @@ int main (void) my_pointer_glue (exit_tcpip_function); #endif - if ( -#ifdef MAYBE_USE_STDIO - (!use_stdio) && -#endif - !(flags & 16) || (flags & 8) || execution_aborted!=0) - { + if (!(flags & 16) || (flags & 8) || execution_aborted!=0){ #ifdef COMMUNICATION if (my_processor_id==0) #endif -- cgit v1.2.3