-- stdinout.eu -- by Matt Lewis -- -- This file overrides standard input/output routines and avoids -- using ncurses under Linux. There is no effect under DOS or Windows. -- Whenver you use printf or puts, the output will go to STDOUT when -- either file 1 or 2 is used. Also, if you try to read (using a get*) -- function, the result will be a read from STDIN. -- -- Reads and writes to files are treated normally. If you use '?' or -- wait_key(), you will need to call free_console() before you can use -- STDIN or STDOUT, because these commands create an ncurses terminal. -- Instead of wait_key(), you could just use getc(0). -- -- Also, if you have warnings enabled, an ncurses terminal might be created -- when your program finishes execution. Likewise, if your program crashes, -- you will get an ncurses terminal displaying the error. You can put a -- call to free_console() in your crash_routine, but the ncurses terminal -- will likely erase the visible contents on the terminal in which your -- program is running. without warning include misc.e include machine.e include dll.e atom so, xprintf, xgetc if platform() = LINUX then so = open_dll("") xprintf = define_c_proc( so, "printf", {C_POINTER} ) xgetc = define_c_func( so, "getchar", {}, C_INT ) end if global procedure old_printf( integer fn, sequence format, object o ) printf( fn, format, o ) end procedure global procedure printf( integer fn, sequence format, object o ) sequence text atom text_ptr if platform() != LINUX or fn > 2 then old_printf( fn, format, o ) else text = sprintf( format, o ) text_ptr = allocate_string( text ) c_proc( xprintf, {text_ptr} ) free( text_ptr ) end if end procedure procedure old_puts( integer fn, sequence text ) puts( fn, text ) end procedure global procedure puts( integer fn, object text ) if platform() != LINUX or fn > 2 then old_puts( fn, text ) else printf( fn, "%s", {text}) end if end procedure function old_getc( integer fn ) return getc( fn ) end function global function getc( integer fn ) if platform() != LINUX or fn > 0 then return old_getc( fn ) else return c_func( xgetc, {}) end if end function function old_gets( integer fn ) return gets( fn ) end function global function gets( integer fn ) sequence line if platform() != LINUX or fn > 0 then return old_gets( fn ) else line = "" line &= c_func( xgetc, {}) while line[$] != '\n' do line &= c_func( xgetc, {}) end while return line end if end function