home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / diverses / inout / un_rdir.c
Encoding:
C/C++ Source or Header  |  1987-01-31  |  2.3 KB  |  60 lines

  1. /*
  2.       Lattice C functions to remove and restore redirection of stdin and 
  3.    stdout.  Both are void, and neither takes a parameter.
  4.  
  5.       un_rdir() saves the current handles for stdin and stdout, then sets
  6.    both to CON, which means the keyboard and the screen.
  7.  
  8.       re_rdir() resets stdin and stdout to their saved handles.  If you
  9.    didn't already run un_rdir() to save their handles, it does nothing.
  10.  
  11.       Comments.  All Lattice C calls seem to be through DOS.  As a result,
  12.    even the keyboard functions will be redirected.  These functions could
  13.    have two uses.  un_rdir() by itself could guarantee that your program
  14.    will be strictly keyboard to screen.  More often, you may have some
  15.    administrative type input and output as well as the actual work to be
  16.    done.  You could precede the instructions with un_rdir(), then use
  17.    re_rdir() before the actual work, then use un_rdir() again for the
  18.    wrap up.  
  19.       As an example of how these routines would be handy, try running DOS
  20.    COMP with redirected output.  The system will stop, waiting for you
  21.    to say whether you want to compare more files, but the question will
  22.    be in the output file.  With these functions, you would precede the
  23.    question with un_rdir(), and then use re_rdir() if the answer were yes.
  24.  
  25.       Acknowledgement.  The key to these functions is the table in the
  26.    program segment prefix which starts at byte 0x18.  Stan Mitchell's
  27.    Tech Notebook 55, "Command Line Redirection", page 44 in the PC Tech 
  28.    Journal for January, 1986 explained this structure to me.
  29.  
  30.    Lew Paper
  31.    1/30/86
  32. */
  33.    
  34. static unsigned psp_seg;                   /* segment for psp */
  35. static unsigned char std_save[] = {0xff, 0xff}; /* Unassigned handle value, 
  36.                                                    so impossible for stdin */
  37.  
  38. extern unsigned _PSP[]; /* Double word with offset, 
  39.                            segment of PSP in C.ASM */
  40.  
  41. void un_rdir()
  42.  
  43.    {
  44.    psp_seg = _PSP[1];
  45.    peek(psp_seg, 0x18, &std_save, 2); /* Bytes 18 and 19 have the 
  46.                                          handles for stdin and stdout */
  47.  
  48.    poke(psp_seg, 0x18, "\x01\x01", 2); /* \x01 is the CON device */
  49.    }
  50.  
  51. void re_rdir()
  52.  
  53.    {
  54.    if (std_save[0] != 0xff) /* un_rdir must have been called */
  55.       {
  56.       poke(psp_seg, 0x18, &std_save, 2); 
  57.       }
  58.    }
  59.  
  60.