home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
RBBS in a Box Volume 1 #3.1
/
RBBSIABOX31.cdr
/
finc
/
filter.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
1984-09-28
|
3KB
|
69 lines
Program FilterSample (input, output); {r filter.pas xa4 prosig}
{ This sample program allows the use of I/O Redirection from the MS-DOS
command line. It replaces the standard Turbo Input and Output routines
with ones using MS-DOS function calls 3F and 40 - which support the I/O
redirection capabilities of MS-DOS 2.0 and above. Note that due to the
use of the eof function, this function will only work on text files which
end in a CTRL-Z.
Note that this routine is relatively slow due to single byte calls of
the MS-DOS functions.
Sample usage:
Display a file on the standard output device: filter <filein
Copy a file: filter <filein >fileout
}
type RegPack = record
AX,BX,CX,DX,BP,SI,DI,DS,ES,FLAGS : integer;
end;
var Registers : RegPack;
Ch : char;
Function ReadDirect : char;
var ss, oo : integer;
begin
ss := seg(input); { Use Character Buffer in Input file FIB }
oo := ofs(input)+2;
Registers.AX := $3F00; { DOS Read Device Function }
Registers.BX := $0000; { Standard Input Device Handle }
Registers.CX := $0001; { Number of Bytes to Read }
Registers.DS := ss; { Buffer Location - Segment }
Registers.DX := oo; { Buffer Location - Offset }
Intr ($21, Registers);
ReadDirect := chr(mem[ss:oo]); { Get the Character Just Read }
end;
Procedure WriteDirect (OutputCh : char);
begin
Registers.AX := $4000; { DOS Write Device Function }
Registers.BX := $0001; { Standard Output Device Handle }
Registers.CX := $0001; { Number of Bytes to Write }
Registers.DS := seg(OutputCh); { Buffer Location - Segment }
Registers.DX := ofs(outputch); { Buffer Location - Offset }
Intr ($21, Registers);
end;
Procedure Initialize;
var oo, ss : integer;
begin
ss := seg(ConOutPtr); { Segment Pointer ... }
oo := ofs(ConOutPtr); { ... and Offset }
memw[ss:oo] := ofs(WriteDirect); { Replace it with ours }
ss := seg(ConInPtr);
oo := ofs(ConInPtr);
memw[ss:oo] := ofs(ReadDirect); { Replace this one too }
end;
begin
Initialize; { Go set up pointers to our routines }
repeat
Read(kbd,ch); { Read Kbd to avoid echo on Read Input }
Write(ch);
until eof(input); { Turbo blows up on plain old eof; }
end.