home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sys.mac.programmer
- Path: sparky!uunet!munnari.oz.au!uniwa!cujo!NewsWatcher!user
- From: peter@cujo.curtin.edu.au (Peter N Lewis)
- Subject: Re: How to <<Readln>> from a text referenced by a handle??
- Message-ID: <peter-160992091557@134.7.50.3>
- Followup-To: comp.sys.mac.programmer
- Sender: news@cujo.curtin.edu.au (News Manager)
- Organization: NCRPDA, Curtin University
- References: <1992Sep15.074458.6297@bernina.ethz.ch>
- Date: Wed, 16 Sep 1992 01:32:12 GMT
- Lines: 42
-
- In article <1992Sep15.074458.6297@bernina.ethz.ch>, czychi@bernina.ethz.ch
- (Gary Czychi) wrote:
-
- > nd in my application, I have already read in the text of a file in one big
- > chunk and pass the handle to the place where I process the data.
-
- {$R-}
- procedure ReadALine(h:handle; var s:str255);
- var
- p:ptr;
- size,len:longInt;
- begin
- p:=h^;
- size:=GetHandleSize(h);
- len:=0;
- while (size>0) & (p^ <> 13) do begin
- p:=ptr(ord(p)+1);
- size:=size-1;
- len:=len+1;
- end;
- if len>255 then len:=255;
- s[0]:=chr(len);
- BlockMove(h^,@s[1],len);
- if size>0 then begin
- p:=ptr(ord(p)+1); { Skip over the <cr> }
- size:=size-1;
- BlockMove(p,h^,size);
- end;
- SetHandleSize(h,size);
- end;
-
- I tested this code, it seems to work ok. Note, if you were going to read
- lots of lines, you'd be better keeping an offset, and avoiding the block
- move all the time, but the above will work ok, and isn't *that* inefficent,
- it depends how many times you want to call ReadALine, if its 10 or 20, no
- problem, if its 10 or 20 thousand, then some rethinking would be
- necessary...
- Peter.
-
- _______________________________________________________________________
- Peter N Lewis, NCRPDA, Curtin University peter@cujo.curtin.edu.au
- GPO Box U1987, Perth WA 6001, AUSTRALIA FAX: +61 9 367 8141
-