home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / turbopas / raw_lpt.pas < prev    next >
Pascal/Delphi Source File  |  1994-03-05  |  2KB  |  84 lines

  1.  
  2. Date: Monday, 27 November 1989  09:11-MST
  3. From: Leonard Campbell <UCIC309%UNLVM.BITNET@ricevm1.rice.edu>
  4. To:   Info-IBMPC@WSMRSIMTEL20.ARMY.MIL
  5. Re:   ^Z problem in turbo pascal
  6.  
  7. By Default Turbo pascal uses a file handle that filters out ^Z's and
  8. posibly massages other characters (such as tabs).  I have a small program
  9. stub that changes the file handle to process characters in 'RAW' mode.
  10. Program follows:
  11.  
  12. PROGRAM printout; { This stub allow you to write the EOF char to }
  13.                   { device LPT1}
  14. USES dos;
  15.  
  16. VAR
  17.   ExitSave: pointer;
  18.   dosregs:dos.registers;
  19.   Lst: FILE;
  20.  
  21. PROCEDURE init;
  22.  
  23.   VAR
  24.     i, j: Integer;
  25.  
  26.   BEGIN
  27.     IF ParamCount = 0 THEN BEGIN
  28.       Writeln('NO argument given');
  29.       Writeln('SYNTAX: cmd <outputloc>');
  30.       Writeln('  outputloc is the destination (default PRN)');
  31.       Writeln('  ... more desc');
  32.       Halt; END;
  33.     IF ParamCount > 0 THEN outn := ParamSTR(1)
  34.     ELSE outn := 'LPT1';
  35.     Assign(Lst, outn); {$i-}
  36.     Rewrite(Lst, 1); {$i+}
  37.     IF IOresult <> 0 THEN BEGIN
  38.       Writeln('Error opening output file:', outn);
  39.       Halt; END;
  40.     Writeln(' Output routed to ', outn);
  41.     with dosregs do begin   { here is where we change mode}
  42.        ah := $44;  { get device info}
  43.        al := $00;
  44.        bx := filerec(lst).handle;
  45.        msdos(dosregs);
  46.        devinfo := dx;
  47.        isptr := 0 <> (dx and $0080);   {if device is block char device then}
  48.        if isptr then begin
  49.           ah := $44;
  50.           al := $01;
  51.           bx := filerec(lst).handle;
  52.           dx := devinfo or $0020;      {set device to RAW mode}
  53.           dh := 0;
  54.           msdos(dosregs); end; end;
  55.      isopen := true;
  56.   END {init};
  57.  
  58. {$F+}
  59. procedure ExitHandler;
  60.   { Return the ptr to chr device }
  61.   begin
  62.    if isopen then begin
  63.        if isptr then with dosregs do begin
  64.           ah := $44; { set device info}
  65.           al := $01;
  66.           bx := filerec(lst).handle;
  67.           dx := devinfo;
  68.           dh := 0;
  69.           msdos(dosregs); end;
  70.        close(lst);  end;
  71.   ExitProc := ExitSave
  72.   end;
  73. {$F-}
  74.  
  75. BEGIN {listfont}
  76.   isopen := false;
  77.    ExitSave := ExitProc;
  78.    ExitProc := @ExitHandler;
  79.   init;
  80.   {do your stuf here}
  81.   {I.E.  for i := 0 to 255 do write(lst,chr(i)); }
  82.  
  83. END.{printout}.
  84.