home *** CD-ROM | disk | FTP | other *** search
- /*
- Lattice C functions to remove and restore redirection of stdin and
- stdout. Both are void, and neither takes a parameter.
-
- un_rdir() saves the current handles for stdin and stdout, then sets
- both to CON, which means the keyboard and the screen.
-
- re_rdir() resets stdin and stdout to their saved handles. If you
- didn't already run un_rdir() to save their handles, it does nothing.
-
- Comments. All Lattice C calls seem to be through DOS. As a result,
- even the keyboard functions will be redirected. These functions could
- have two uses. un_rdir() by itself could guarantee that your program
- will be strictly keyboard to screen. More often, you may have some
- administrative type input and output as well as the actual work to be
- done. You could precede the instructions with un_rdir(), then use
- re_rdir() before the actual work, then use un_rdir() again for the
- wrap up.
- As an example of how these routines would be handy, try running DOS
- COMP with redirected output. The system will stop, waiting for you
- to say whether you want to compare more files, but the question will
- be in the output file. With these functions, you would precede the
- question with un_rdir(), and then use re_rdir() if the answer were yes.
-
- Acknowledgement. The key to these functions is the table in the
- program segment prefix which starts at byte 0x18. Stan Mitchell's
- Tech Notebook 55, "Command Line Redirection", page 44 in the PC Tech
- Journal for January, 1986 explained this structure to me.
-
- Lew Paper
- 1/30/86
- */
-
- static unsigned psp_seg; /* segment for psp */
- static unsigned char std_save[] = {0xff, 0xff}; /* Unassigned handle value,
- so impossible for stdin */
-
- extern unsigned _PSP[]; /* Double word with offset,
- segment of PSP in C.ASM */
-
- void un_rdir()
-
- {
- psp_seg = _PSP[1];
- peek(psp_seg, 0x18, &std_save, 2); /* Bytes 18 and 19 have the
- handles for stdin and stdout */
-
- poke(psp_seg, 0x18, "\x01\x01", 2); /* \x01 is the CON device */
- }
-
- void re_rdir()
-
- {
- if (std_save[0] != 0xff) /* un_rdir must have been called */
- {
- poke(psp_seg, 0x18, &std_save, 2);
- }
- }
-