home *** CD-ROM | disk | FTP | other *** search
/ kermit.columbia.edu / kermit.columbia.edu.tar / kermit.columbia.edu / ucsdmagiscan2 / binutils.text next >
Text File  |  2011-08-11  |  3KB  |  113 lines

  1.  
  2.  This contains the routines for eight bit quoting 
  3.  
  4. (* ---------------------------------------------------- *)
  5.  
  6. procedure Bbufemp(* var buffer : pakettype;
  7.                       Len    : integer  *);
  8.  procedure to empty the buffe into a file 
  9.  
  10. var
  11.   r      : char;
  12.   i      : integer;
  13.  
  14. begin
  15. i := 0;
  16.  
  17. while i < Len do { while not at the end of packet do }
  18.   begin
  19.   r := buffer[i];
  20.   if (r = myquote) then { if myquote the a control char ? }
  21.     begin{get quoted character}
  22.     i := i + 1;
  23.     r := buffer[i];
  24.     if (aand(ord(r),127) <> ord(myquote)) and
  25.        (aand(ord(r),127) <> ord(mybquote)) then
  26.       r := ctl(r) { controlify the character }
  27.     end
  28.    else
  29.      if (r = myBquote) then { if mybquote then eight bit should be set }
  30.        begin{get the binary character}
  31.        i := i + 1;
  32.        r := buffer[i];
  33.        if (aand(ord(r),127) = ord(myquote)) then { is a control char }
  34.          begin
  35.          i := i + 1;
  36.          r := buffer[i];
  37.          if (aand(ord(r),127) <> ord(myquote)) and
  38.             (aand(ord(r),127) <> ord(mybquote)) then
  39.            r := ctl(chr(aand(ord(r),127)));
  40.          end;
  41.        r := chr(aand(ord(r),127) + 128) { add in eight bit }
  42.        end
  43.       else
  44.         begin{get the normal character}
  45.         r := chr(aand(ord(r),127))
  46.         end;
  47.   i := i + 1;
  48.   FileBuf[BuffPosn] := r; { put in the file buffer }
  49.   BuffPosn := BuffPosn + 1;
  50.   if BuffPosn > BufEnd then { if file buffer full then save it }
  51.     SaveBuff(FileBuf,BuffPosn,False)
  52.   end{while}
  53.  
  54. end{Bbufemp};
  55.  
  56. (* ---------------------------------------------------- *)
  57.  
  58. function Bbufill(*var buffer: packettype): integer*);
  59.  This fills a packet from the file 
  60.  
  61. var i,j,k : integer;
  62.     r     : char;
  63.     OK    : boolean;
  64.  
  65. begin
  66. OK := ((not eof(f)) and (TranState <> ImgFile)) or
  67.       ((not EOI) and (TranState = ImgFile));
  68.  
  69. i := 0;
  70. (* while file has some data & packet has some room we'll keep going *)
  71. while ((buffposn <= bufend) or OK) and (i < spsiz-8) do
  72.   begin
  73.   ReadBuff(FileBuf,BuffPosn);(* while *)
  74.   if (buffposn <= bufend) then     (* if we're within buffer bounds *)
  75.     begin
  76.     r := filebuf[buffposn];      (* get a character *)
  77.     buffposn := buffposn + 1;         (* increase buffer pointer *)
  78.     if ord(r) > 127 then
  79.       begin{we have the eight bit set }
  80.       buffer[i] := bquote;
  81.       i := i + 1;
  82.       r := chr(aand(ord(r),127));{ convert to 7 bit }
  83.       if (r in ctlset) then
  84.         begin
  85.         buffer[i] := quote;
  86.         i := i + 1;
  87.         if (r <> quote) and (r <> bquote) then
  88.           r := ctl(r);
  89.         end
  90.       end
  91.      else
  92.        if (r in ctlset) then     (* if a control char *)
  93.          begin
  94.          buffer[i] := quote;      (* put the quote in buffer *)
  95.          i := i + 1;
  96.          if (r <> quote) and (r <> bquote) then
  97.              r := ctl(r);   (* and un-controllify char *)
  98.          end;
  99.     buffer[i] := r; { update the buffer }
  100.     i := i + 1;
  101.     end;
  102.   OK := ((not eof(f)) and (TranState <> ImgFile)) or
  103.         ((not EOI) and (TranState = ImgFile));
  104.   end{while};
  105. if (i = 0) then                         (* if we're at end of file, *)
  106.   Bbufill := (at_eof)                    (* indicate it *)
  107.  else                                    (* else *)
  108.    Bbufill := i                           (* return # of chars in packet *)
  109. end; (* Bbufill *)
  110.  
  111. (* ---------------------------------------------------- *)
  112.  
  113.