home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Columbia Kermit
/
kermit.zip
/
archives
/
ucsdmagiscan2.tar.gz
/
ucsdmagiscan2.tar
/
binutils.text
next >
Wrap
Text File
|
2011-08-11
|
3KB
|
113 lines
This contains the routines for eight bit quoting
(* ---------------------------------------------------- *)
procedure Bbufemp(* var buffer : pakettype;
Len : integer *);
procedure to empty the buffe into a file
var
r : char;
i : integer;
begin
i := 0;
while i < Len do { while not at the end of packet do }
begin
r := buffer[i];
if (r = myquote) then { if myquote the a control char ? }
begin{get quoted character}
i := i + 1;
r := buffer[i];
if (aand(ord(r),127) <> ord(myquote)) and
(aand(ord(r),127) <> ord(mybquote)) then
r := ctl(r) { controlify the character }
end
else
if (r = myBquote) then { if mybquote then eight bit should be set }
begin{get the binary character}
i := i + 1;
r := buffer[i];
if (aand(ord(r),127) = ord(myquote)) then { is a control char }
begin
i := i + 1;
r := buffer[i];
if (aand(ord(r),127) <> ord(myquote)) and
(aand(ord(r),127) <> ord(mybquote)) then
r := ctl(chr(aand(ord(r),127)));
end;
r := chr(aand(ord(r),127) + 128) { add in eight bit }
end
else
begin{get the normal character}
r := chr(aand(ord(r),127))
end;
i := i + 1;
FileBuf[BuffPosn] := r; { put in the file buffer }
BuffPosn := BuffPosn + 1;
if BuffPosn > BufEnd then { if file buffer full then save it }
SaveBuff(FileBuf,BuffPosn,False)
end{while}
end{Bbufemp};
(* ---------------------------------------------------- *)
function Bbufill(*var buffer: packettype): integer*);
This fills a packet from the file
var i,j,k : integer;
r : char;
OK : boolean;
begin
OK := ((not eof(f)) and (TranState <> ImgFile)) or
((not EOI) and (TranState = ImgFile));
i := 0;
(* while file has some data & packet has some room we'll keep going *)
while ((buffposn <= bufend) or OK) and (i < spsiz-8) do
begin
ReadBuff(FileBuf,BuffPosn);(* while *)
if (buffposn <= bufend) then (* if we're within buffer bounds *)
begin
r := filebuf[buffposn]; (* get a character *)
buffposn := buffposn + 1; (* increase buffer pointer *)
if ord(r) > 127 then
begin{we have the eight bit set }
buffer[i] := bquote;
i := i + 1;
r := chr(aand(ord(r),127));{ convert to 7 bit }
if (r in ctlset) then
begin
buffer[i] := quote;
i := i + 1;
if (r <> quote) and (r <> bquote) then
r := ctl(r);
end
end
else
if (r in ctlset) then (* if a control char *)
begin
buffer[i] := quote; (* put the quote in buffer *)
i := i + 1;
if (r <> quote) and (r <> bquote) then
r := ctl(r); (* and un-controllify char *)
end;
buffer[i] := r; { update the buffer }
i := i + 1;
end;
OK := ((not eof(f)) and (TranState <> ImgFile)) or
((not EOI) and (TranState = ImgFile));
end{while};
if (i = 0) then (* if we're at end of file, *)
Bbufill := (at_eof) (* indicate it *)
else (* else *)
Bbufill := i (* return # of chars in packet *)
end; (* Bbufill *)
(* ---------------------------------------------------- *)