home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume2 / pstrings / part01 / readtS.p < prev    next >
Encoding:
Text File  |  1991-08-07  |  845 b   |  35 lines

  1.  
  2.  
  3.  
  4.  
  5. # include "strings.h"
  6.  
  7. procedure readtS{(var f: Text; var s: String; function stop(c:Char):Boolean)};
  8. {
  9. * Reads a string from text file f; eoln or stop(c) returning true
  10. * (whichever occurs first) terminating.  In either case,
  11. * input is left positioned at the terminator.
  12. *
  13. * precondition:
  14. *    f open for reading & not eof(f)
  15. }
  16.     const BufferLength = 120;
  17.     var t : String;
  18.         i : Nat0; 
  19.      line : packed array [1..BufferLength] of Char;
  20. begin
  21.     i := 0;
  22.     while not eoln(f) and (i <> BufferLength) and not stop(f^) do begin
  23.         i := i+1;
  24.         read(f, line[i])
  25.     end;
  26.     if i = 0 then assignS(s, nil) else assignS(s, mk(line, i));
  27.     { --  Check for more characters on the input line }
  28.     if (i = BufferLength) and not stop(f^) and not eoln(f) then begin
  29.         { --  Get the rest }
  30.         t := nil;
  31.         readS(f, t);
  32.         assignS(s, concatS(s, t))
  33.     end
  34. end{ -- readtS};
  35.