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

  1.  
  2.  
  3.  
  4. # include "strings.h"
  5.  
  6. procedure writeS{var f: Text; s: String)};
  7. {
  8. * Write the dynamic string s to file f
  9. *
  10. * precondition:
  11. *    f open for writing    
  12. }
  13.    var temp: stringtail;
  14.        i, Currentlength: Nat1; ExtraChunks: Nat0;
  15. begin
  16.     if s = nil then { -- Do nothing if string = '' }
  17.     else begin
  18.      with s^ do begin
  19.         ExtraChunks := (LEN-1) div slength;
  20.         if LEN > slength then
  21.             CurrentLength := slength
  22.         else
  23.             CurrentLength := LEN;
  24.         write(f, HEAD:CurrentLength);
  25.         temp := TAIL;
  26.         { -- Output any tail chunks }
  27.         for i := 1 to ExtraChunks do with temp^ do
  28.             if i <> ExtraChunks then begin
  29.                 write(f, MORE);
  30.                 temp := REST
  31.             end else 
  32.                 if LEN mod slength <> 0 then
  33.                 write(f, MORE:(LEN mod slength))
  34.                 else
  35.                 write(f, MORE)
  36.      end;
  37.      { -- may have been asked to output a constant string }
  38.      if s^.REFS = 0 then disposeS(s)
  39.     end
  40. end{ -- writeS};
  41.  
  42.  
  43.