home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / PROG / PASCAL / MISCTI10.ZIP / TI118.ASC < prev    next >
Encoding:
Text File  |  1988-05-12  |  2.4 KB  |  91 lines

  1. PRODUCT : TURBO PASCAL     NUMBER : 118
  2. VERSION : 2.00x
  3.      OS : PC-DOS, MS-DOS
  4.    DATE : March 13, 1986
  5.  
  6.   TITLE : REDIRECTION OF INPUT/OUTPUT
  7.  
  8.  
  9.  
  10.  
  11. This  program  demonstrates user defined INPUT and OUTPUT  device 
  12. drivers.   Use the indicated portion of the sample program as  an 
  13. INCLUDE  file  to  be  inserted in declaration  section  of  your 
  14. program files.
  15.  
  16. The MS-DOS facilities of redirection,  piping,  and  simultaneous 
  17. printing  through the use of ^P or ^PrtSc will be re-enabled.  At 
  18. the  beginning  of  your  main  program,  place  the  statements 
  19. (ConInPtr:=Ofs(GetC);)  and (ConOutPtr:=Ofs(PutC);).   The  INPUT
  20. and OUTPUT from your programs will be redirected through the GetC
  21. function and the PutC Procedure.  Type <Ctrl> <P> at the start of
  22. your program run and you will get output at both the CRT and  the 
  23. printer.}
  24. _________________________________________________________________
  25.  
  26.                       START OF INCLUDE FILE
  27. _________________________________________________________________
  28.  
  29. program Redirect:
  30. Type RegRecord = Record Case Integer Of
  31.                    1: (AX,BX,CX,DX,BP,SI,DI,DS,ES,Flags:
  32. Integer);
  33.                    2: (AL,AH,BL,BH,CL,CH,DL,DH: Byte);
  34.                  End;
  35.  
  36. Var    Regs    : RegRecord;
  37.  
  38. Function GetC: Byte;
  39.  
  40. Begin
  41.   Regs.AH:=8;
  42.   MsDos(Regs);
  43.   GetC:=Regs.AL;
  44. End;
  45.  
  46. Procedure PutC(C: Byte);
  47.  
  48. Begin
  49.   Regs.AH:=2;
  50.   Regs.DL:=C;
  51.   MsDos(Regs);
  52. End;
  53.  
  54. ________________________________________________________________
  55.  
  56.                        END OF INCLUDE FILE
  57. _________________________________________________________________
  58.  
  59. Var  Str    : String [255];
  60.      I      : integer;
  61.      Answer : char;
  62.  
  63.  
  64. begin
  65.   ConInPtr:=Ofs(GetC);           { Include these lines at the   }
  66.   ConOutPtr:=Ofs(PutC);          { start of your program        }
  67.   repeat
  68.     ClrScr;
  69.     writeln ('This is a test of INPUT/OUTPUT redirection:  ');
  70.     writeln;
  71.     for I := 1 to 128 do         { demonstrates formated output }
  72.       write (1:5);
  73.     writeln; writeln;
  74.     writeln ('Enter a String of characters from the keyboard.');
  75.     writeln;
  76.     readln (Str);
  77.     writeln;
  78.     writeln (Str);
  79.     writeln; writeln;
  80.     writeln ('Run again? (Y/N)'); writeln;
  81.     writeln ('Type <Ctrl> <P> first to test output to
  82. PRINTER/CRT');
  83.     repeat
  84.       read (kbd,Answer);
  85.     until upcase (Answer) in ['Y','N'];
  86.     writeln;
  87.     writeln;
  88.   until upcase (Answer) = 'N';
  89. end.
  90.  
  91.