home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C!T ROM 2
/
ctrom_ii_b.zip
/
ctrom_ii_b
/
PROGRAM
/
PASCAL
/
LOG_01
/
IOLOG.PAS
next >
Wrap
Pascal/Delphi Source File
|
1988-10-05
|
4KB
|
158 lines
Unit IoLog ;
{
Logs all output to a log file
Edition history
28-08-88 22:00 2 2 LSD/HL Started this file
can log simple outputs and gotoxy and ClrScr
10-05-88 10:00 1 3 LSD/HL Placed in ShareWare
WARNING ! This unit is still under work and is released on as-is basis.
If there's anything wrong with it, that's your problem. You don't have
to use it.
This unit declares, opens and closes a file IOLOG.LOG. It copies all output
from the program to this file, and some of the other screen routines like
clrscr and gotoxy
This unit is designed for debug and documentation phase only. It is not
intended to be left in a finished product. Buy why not, if you find some
use for that.
This unit is [ should be ] totally transparent to the program using it.
Known problems and limitations
==============================
- If the program does not use Crt, its output can be redirected in dos where
ever wanted. This feature gets disabled because this unit uses Crt. But if
you want to redirect your output, you can still assign output to '', but
then this unit won't catch the output. [ This might be repaired in a later
version ]
- All output functions ( like gotoxy ) are logged only if every unit of the
target program uses IOLOG. All text is logged anyway, but not the specials.
- Not all Crt's function logged (yet)
(c) Copyright 1988 LSD - Levanto Software Development, Aarhus, Denmark
You may use this unit in your own programs free of charge. If you use it
programs you sell or otherwise make business with it, you are kindly asked to
send some money, or at least a post card to
LSD - Levanto Software Development
Rydevaenget 35,2,th
DK 8210 Aarhus V
Denmark
+ 45 6 156270 2:505/22.28
}
INTERFACE
Uses
Crt,
Dos ;
Procedure GotoXy ( x,y : integer );
Procedure ClrScr ;
IMPLEMENTATION
var
LogFile : text ;
ExitSave : pointer ;
OldFlushPtr : pointer ;
{ ---------------- Logging other output-related functions --------------- }
Procedure GotoXy ( x,y : integer );
begin
writeln ( logfile, 'Gotoxy ( ',x,', ',y,' );' );
Crt.gotoxy ( x,y );
end ; { GotoXy }
Procedure ClrScr ;
begin
writeln ( logfile, 'ClrScr ;' );
crt. ClrScr ;
end ; { ClrScr }
{ ----------------- Handling the actual output ----------------------- }
Function CallOldPtr ( var F : TextRec ) : integer ;
inline ( $FF/$1E/OldFlushPtr );
{$F+} Function Flushproc ( var F : TextRec ) : integer ; {$F-}
var p : integer ;
begin
with TextRec(F) do begin
if ( BufPos > 2 ) and
( BufPtr^ [BufPos-1] = #10 ) and
( BufPtr^ [BufPos-2] = #13 )
then begin
write ( logfile, 'writeln ( ''' );
for p := 0 to BufPos-3 do
write ( logfile, BufPtr^[p] );
writeln ( logfile, ''' );' );
end
else begin
if ( BufPtr^ [0] = #13 ) and
( BufPtr^ [1] = #10 )
then writeln ( logfile, 'writeln ;' )
else begin
write ( logfile, 'write ( ''' );
for p := 0 to BufPos-1 do
write ( logfile, BufPtr^[p] );
writeln ( logfile, ''' );' );
end ; { really write }
end ; { simple write }
end ; { with }
FlushProc := CallOldPtr ( F );
end ; { FlushProc }
{ ------------------------- Entry and exit codes ----------------------- }
{$F+} Procedure ExitRoutine ; {$F-}
begin
TextRec ( Output ) .FlushFunc := OldFlushPtr ;
close ( logfile );
ExitProc := ExitSave ;
writeln ( 'IOLOG: All output is captured in IOLOG.LOG ');
end ; { ExitRoutine }
begin { entry section of IOLOG }
assign ( logfile, 'IOLOG.LOG' );
rewrite ( logfile );
with TextRec ( Output ) do begin
OldFlushPtr := FlushFunc ;
FlushFunc := @ FlushProc ;
end ; { with }
ExitSave := ExitProc ;
ExitProc := @ ExitRoutine ;
end .