From 312bcbb69391db1eb8d9eaa7618802c352ba1a59 Mon Sep 17 00:00:00 2001 From: John van Groningen Date: Tue, 14 Oct 2003 14:24:52 +0000 Subject: use unix console I/O if started using Terminal (if -psn argument is missing), set global_argv and global_argc variables for MachO --- mcon.c | 197 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 192 insertions(+), 5 deletions(-) diff --git a/mcon.c b/mcon.c index 17bfbb4..c0d8213 100644 --- a/mcon.c +++ b/mcon.c @@ -9,7 +9,7 @@ #ifdef MACHO # define MACOSX #endif -#ifdef MACHO +#ifdef MACOSX # define FLUSH_PORT_BUFFER #endif #if defined (MACOSX) || defined (MACHO) @@ -22,6 +22,10 @@ # define NEWLINE_CHAR '\n' #endif +#ifdef MACHO +# define MAYBE_USE_STDIO +#endif + #ifdef MACOSX # define TARGET_API_MAC_CARBON 1 #endif @@ -44,14 +48,15 @@ extern void sprintf (char *,...); #include #include #ifndef NEW_HEADERS -# include +//# include +#include #endif #include #include #include #include #ifndef NEW_HEADERS -# include +//# include #endif #ifdef STACK_OVERFLOW_EXCEPTION_HANDLER # ifdef MACHO @@ -442,10 +447,24 @@ QDGlobals qd; #endif +#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))) +inline void oputs(const char *s) {while (*s) {oputc(*s);s++;}} +inline void eputs(const char *s) {while (*s) {eputc(*s);s++;}} +#endif + void w_print_char (char c) { GrafPtr port; +#ifdef MAYBE_USE_STDIO + if (use_stdio){ + oputc (c); + return; + } +#endif #ifdef MACOSX GetPort (&port); SetPort (GetWindowPort (c_window)); @@ -494,6 +513,19 @@ void w_print_text (char *s,unsigned long length) char *end_s,c; GrafPtr port; +#ifdef MAYBE_USE_STDIO + if (use_stdio){ + int l; + + l=length; + if (l) + do { + oputc (*s); + ++s; + } while (--l); + return; + } +#endif #ifdef MACOSX GetPort (&port); SetPort (GetWindowPort (c_window)); @@ -570,6 +602,12 @@ void ew_print_char (char c) { GrafPtr port; +#ifdef MAYBE_USE_STDIO + if (use_stdio){ + eputc (c); + return; + } +#endif #ifdef MACOSX GetPort (&port); SetPort (GetWindowPort (e_window)); @@ -636,6 +674,20 @@ void ew_print_text (char *s,unsigned long length) { GrafPtr port; +#ifdef MAYBE_USE_STDIO + if (use_stdio){ + int l; + + l=length; + if (l){ + do { + eputc (*s); + ++s; + } while (--l); + } + return; + } +#endif #ifdef MACOSX GetPort (&port); SetPort (GetWindowPort (e_window)); @@ -841,6 +893,12 @@ int w_get_char() { int c; +#ifdef MAYBE_USE_STDIO + if (use_stdio){ + return getchar(); + } +#endif + if (input_buffer_length==0){ GrafPtr port; @@ -881,7 +939,11 @@ int w_get_int (int *i_p) unsigned int i; c=w_get_char(); +#ifdef MAYBE_USE_STDIO + while (c==' ' || c=='\t' || c=='\n' || c=='\r') +#else while (c==' ' || c=='\t' || c==NEWLINE_CHAR) +#endif c=w_get_char(); negative=0; @@ -894,9 +956,17 @@ int w_get_int (int *i_p) } if (!is_digit (c)){ +#ifdef MAYBE_USE_STDIO + if (use_stdio){ + if (c!=EOF) + ungetc (c,stdin); + } else { +#endif --input_buffer_pos; ++input_buffer_length; - +#ifdef MAYBE_USE_STDIO + } +#endif *i_p=0; return 0; } @@ -911,8 +981,17 @@ int w_get_int (int *i_p) if (negative) i=-i; +#ifdef MAYBE_USE_STDIO + if (use_stdio){ + if (c!=EOF) + ungetc (c,stdin); + } else { +#endif --input_buffer_pos; ++input_buffer_length; +#ifdef MAYBE_USE_STDIO + } +#endif *i_p=i; return -1; @@ -926,7 +1005,11 @@ int w_get_real (double *r_p) n=0; c=w_get_char(); +#ifdef MAYBE_USE_STDIO + while (c==' ' || c=='\t' || c=='\n' || c=='\r') +#else while (c==' ' || c=='\t' || c==NEWLINE_CHAR) +#endif c=w_get_char(); if (c=='+') @@ -986,8 +1069,17 @@ int w_get_real (double *r_p) if (n>=256) result=0; +#ifdef MAYBE_USE_STDIO + if (use_stdio){ + if (c!=EOF) + ungetc (c,stdin); + } else { +#endif --input_buffer_pos; ++input_buffer_length; +#ifdef MAYBE_USE_STDIO + } +#endif *r_p=0.0; @@ -1011,6 +1103,19 @@ unsigned long w_get_text (char *string,unsigned long max_length) char *sp,*dp; GrafPtr port; +#ifdef MAYBE_USE_STDIO + if (use_stdio){ + int length; + + fgets (string,(int)max_length,stdin); + + for (length=0; length