home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CP/M
/
CPM_CDROM.iso
/
mbug
/
mbug120.arc
/
PASCAL.LBR
/
APPEND.PZS
/
APPEND.PAS
Wrap
Pascal/Delphi Source File
|
1979-12-31
|
3KB
|
74 lines
{----------------------------------------------------------------------------}
{APPEND.PAS Append to textfiles in TURBO PASCAL 1985 October 25}
{Utility routines for inclusion in applications programs, see APPEND.DOC}
type
fcbtyp=record {CPM-80 v2.2 see pp 188,194 Zaks CPM Handbook}
drivecode:byte;
nameroot:array[1..8] of char;
nameext:array[1..3] of char;
extent:byte;
spare:integer;
reccount:byte;
diskmap:set of 0..127;
nextrec:byte;
randomrec:integer;
end;
fibtyp=record {Z-80 TURBO see p 159 Turbo v2.0 manual}
flags,filekind,chbuf,bufpointer:byte;
numrecords,reclength,currentrec,spare:integer;
fcb:fcbtyp;
crap:byte; {mystery!...required for alignment of buffer}
buffer:array[0..127] of byte; {could call this a string instead}
end;
var
infile:text;
fib:fibtyp absolute infile;
line:string[80];
j:byte;
fcbaddr,filesize:integer;
const
close=16; {BDOS call arguments}
open=15;
{Flag bit values for TURBO File Interface Block see eg. v2.0 Manual p160 }
rena=1; {read enable}
wena=2; {write enable}
wflg=4; {write semaphore..data available for writing buffer to disk}
rflg=8; {read semaphore..buffer space available for reading from disk}
{----------------------------------------------------------------------------}
procedure appendtext(var textfile:text); {sets up textfile for write access}
var
fib:fibtyp absolute textfile;{textfile originally opened by RESET for read}
ch:char;
begin
with fib do
begin
fcb.nextrec:=fcb.reccount-1; {go direct to last record of file}
bufpointer:=0; {commence eof search at bottom of buffer}
repeat readln(textfile,ch); until eof(textfile); {search buffer for eof}
bufpointer:=bufpointer-1; {step back over eof mark}
flags:=(flags or wena+wflg) and not(rena+rflg); {set flags for write}
fcb.nextrec:=fcb.reccount-1; {set to reuse last record}
end; {with fib}
end; {appendtext}
procedure flushtext(var textfile:text);
{Fixes written text onto disk..TURBO's flush( ) doesnt work on text files}
var
j,fcbaddr:integer;
fib:fibtyp absolute textfile;
begin
with fib do
begin
(* for j:=bufpointer to 127 do write(textfile,' ');
writeln(textfile); {new line for next entry}
*)
fcbaddr:=addr(fcb);{bdos() doesnt seem to like addr() function as argument}
bdos(close,fcbaddr); {transfers buffer and fcb to disk}
flags:=(flags or wena+wflg) and not(rena+rflg); {reset flags for write}
end; {with fib}
end; {flushtext}
{----------------------------------------------------------------------------}