home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / sys / mac / programm / 15533 < prev    next >
Encoding:
Text File  |  1992-09-15  |  1.7 KB  |  55 lines

  1. Newsgroups: comp.sys.mac.programmer
  2. Path: sparky!uunet!munnari.oz.au!uniwa!cujo!NewsWatcher!user
  3. From: peter@cujo.curtin.edu.au (Peter N Lewis)
  4. Subject: Re: How to <<Readln>> from a text referenced by a handle??
  5. Message-ID: <peter-160992091557@134.7.50.3>
  6. Followup-To: comp.sys.mac.programmer
  7. Sender: news@cujo.curtin.edu.au (News Manager)
  8. Organization: NCRPDA, Curtin University
  9. References: <1992Sep15.074458.6297@bernina.ethz.ch>
  10. Date: Wed, 16 Sep 1992 01:32:12 GMT
  11. Lines: 42
  12.  
  13. In article <1992Sep15.074458.6297@bernina.ethz.ch>, czychi@bernina.ethz.ch
  14. (Gary Czychi) wrote:
  15.  
  16. > nd in my application, I have already read in the text of a file in one big
  17. > chunk and pass the handle to the place where I process the data.
  18.  
  19. {$R-}
  20. procedure ReadALine(h:handle; var s:str255);
  21. var
  22.   p:ptr;
  23.   size,len:longInt;
  24. begin
  25.   p:=h^;
  26.   size:=GetHandleSize(h);
  27.   len:=0;
  28.   while (size>0) & (p^ <> 13) do begin
  29.     p:=ptr(ord(p)+1);
  30.     size:=size-1;
  31.     len:=len+1;
  32.   end;
  33.   if len>255 then len:=255;
  34.   s[0]:=chr(len);
  35.   BlockMove(h^,@s[1],len);
  36.   if size>0 then begin
  37.     p:=ptr(ord(p)+1); { Skip over the <cr> }
  38.     size:=size-1;
  39.     BlockMove(p,h^,size);
  40.   end;
  41.   SetHandleSize(h,size);
  42. end;
  43.  
  44. I tested this code, it seems to work ok.  Note, if you were going to read
  45. lots of lines, you'd be better keeping an offset, and avoiding the block
  46. move all the time, but the above will work ok, and isn't *that* inefficent,
  47. it depends how many times you want to call ReadALine, if its 10 or 20, no
  48. problem, if its 10 or 20 thousand, then some rethinking would be
  49. necessary...
  50.    Peter.
  51.  
  52. _______________________________________________________________________
  53. Peter N Lewis, NCRPDA, Curtin University       peter@cujo.curtin.edu.au
  54. GPO Box U1987, Perth WA 6001, AUSTRALIA             FAX: +61 9 367 8141
  55.