home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / pascal / das_buch / tvision / redout / redirout.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1993-05-01  |  2.0 KB  |  85 lines

  1. (* ------------------------------------------------------ *)
  2. (*                      REDIROUT.PAS                      *)
  3. (*            Umleitung der Standard-Ausgabe              *)
  4. (*            (c) 1993 te-wi Verlag, München              *)
  5. (* ------------------------------------------------------ *)
  6. UNIT RedirOut;
  7.  
  8. INTERFACE
  9.  
  10. CONST
  11.   stdin   : WORD = 0;
  12.   stdout  : WORD = 1;
  13.   stderr  : WORD = 2;
  14.  
  15.   RedFile : STRING = 'STDOUT.RED' + #0;
  16.  
  17. VAR
  18.   oldin  : WORD;
  19.   oldout : WORD;
  20.   olderr : WORD;
  21.   Err    : WORD;
  22.  
  23.   FUNCTION RedOut  : WORD;
  24.   FUNCTION RedBack : WORD;
  25.  
  26. IMPLEMENTATION
  27.  
  28.   FUNCTION RedOut : WORD;
  29.   BEGIN
  30.     ASM
  31.       MOV  BX, stdout
  32.       MOV  AH, 45h
  33.       INT  21h                 (* duplicate stdout        *)
  34.       JC   @Error              (* failed                  *)
  35.  
  36.       MOV  oldout, AX          (* save stdout             *)
  37.  
  38.       MOV  CX, 0               (* normal attribute        *)
  39.       MOV  DX, OFFSET redfile + 1
  40.       MOV  AH, 3Ch
  41.       INT  21h
  42.       JC   @Error              (* failed                  *)
  43.  
  44.       MOV  BX, AX              (* redirect stdout hdle to *)
  45.       MOV  CX, stdout          (* track the new file hdle *)
  46.       MOV  AH, 46h
  47.       INT  21h
  48.       JC   @Error              (* failed                  *)
  49.  
  50.       MOV  Err, 0
  51.       JMP  @ok
  52.     @Error:
  53.       MOV  Err, AX             (* Error code              *)
  54.     @Ok:
  55.     END;
  56.   END;
  57.  
  58.   FUNCTION RedBack : WORD;
  59.   BEGIN
  60.     ASM
  61.       MOV  BX, oldout          (* restore original handle *)
  62.       MOV  CX, stdout
  63.       MOV  AH, 46h
  64.       INT  21h
  65.       JC   @Error2             (* failed                  *)
  66.  
  67.       MOV  BX, oldout          (* close dup'd handle      *)
  68.       MOV  AH, 3Eh
  69.       INT  21h
  70.       JC   @Error2             (* failed                  *)
  71.  
  72.       MOV  Err, 0
  73.       JMP  @ok2
  74.     @Error2:
  75.       MOV  Err, AX
  76.     @Ok2:
  77.     END;
  78.   END;
  79.  
  80. BEGIN
  81. END.
  82. (* ------------------------------------------------------ *)
  83. (*                  Ende von REDIROUT.PAS                 *)
  84.  
  85.