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

  1.  
  2.  
  3.  
  4.  
  5. # include "strings.h"
  6.  
  7. procedure readS{(var f: Text; var s: String)};
  8. {
  9. * Reads a string from text file f; eoln terminating.  The input is
  10. * left pointing to the beginning of the next line, if any.
  11. *
  12. * precondition:
  13. *    f open for reading & not eof(f)
  14. }
  15.     const BufferLength = 120;     
  16.     var t : String;
  17.         i : Nat0; 
  18.      line : packed array [1..BufferLength] of Char;
  19.         
  20. begin
  21.     i := 0;
  22.     while not eoln(f) and (i <> BufferLength) 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 eoln(f) then begin
  29.         { --  Get the rest }
  30.         t := nil;
  31.         readS(f, t);
  32.         assignS(s, concatS(s, t))
  33.     end;
  34.     if eoln(f) then get(f)
  35. end{ -- readS};
  36.