Path: utzoo!utgpu!jarvis.csri.toronto.edu!clyde.concordia.ca!uunet!mcsun!sunic!tut!santra!kampi.hut.fi!jmunkki From: jmunkki@kampi.hut.fi (Juri Munkki) Newsgroups: comp.sys.mac.programmer Subject: Re: How read by line from file? Message-ID: <1990Feb6.201847.446@santra.uucp> Date: 6 Feb 90 20:18:47 GMT References: <3129@dogie.macc.wisc.edu> Sender: news@santra.uucp (Cnews - USENET news system) Reply-To: jmunkki@kampi.hut.fi (Juri Munkki) Organization: Helsinki University of Technology, FINLAND Lines: 61 In article <3129@dogie.macc.wisc.edu> yahnke@vms.macc.wisc.edu (Ross Yahnke, MACC) writes: >In article , rf1m+@andrew.cmu.edu (Richard Vernon Ford) writes... >-How do you use FSRead in newline mode? It seems as if it should be >-simple to read from a file, one line at a time. Could someone please >-send me an example, (I'm using Think C 4.0). > >You ask how you use FSRead in newline mode? Hah! FSRead has no newline >mode, bunky. You bite the bullet and buffer your i/o. Allocate a >chunk 'o mem, FSRead into that, and move a ptr thru the chunk >searching for carriage returns. When your ptr gets near the end >of the chunk 'o mem, do another FSRead. Now this certainly was an interesting answer. In fact the answer was far more interesting than the question. How about telling this person that he can use PBRead instead of FSRead? Of course you need the parameter block: ParamBlockRec MyBlock; And you need a routine to read a line into a buffer: void ReadLine() { MyBlock.ioParam.ioBuffer=(Ptr)&BigStr; MyBlock.ioParam.ioReqCount=255; /* Max 255 chars. */ theerr=PBRead(&MyBlock,FALSE); /* Error checking gone. */ BigStr[MyBlock.ioParam.ioActCount]=0; /* Reading a C string! */ } To open the file you do this: SFGetFile(blaablaa...you fill in the blanks...); if(MyReply.good) { MyBlock.ioParam.ioNamePtr=(StringPtr)&MyReply.fName; MyBlock.ioParam.ioVRefNum= MyReply.vRefNum; MyBlock.ioParam.ioPermssn=fsRdPerm; MyBlock.ioParam.ioCompletion=0; MyBlock.ioParam.ioVersNum=0; MyBlock.ioParam.ioMisc=0; PBOpen(&MyBlock,FALSE); Then we set the newline mode. 13 is for . I admit this part could be somewhat cleaner. MyBlock.ioParam.ioPosOffset=0; MyBlock.ioParam.ioPosMode=fsAtMark+128+(13<<8); ProcessFile(); PBClose(&MyBlock,FALSE); Using a parameter block for reading a file isn't actually any harder than using FSRead. You just have to fill in the block and after that the calls are almost identical to the high level calls. The only real difference is that data is passed through the parameter block and that you pass the block pointer instead of a reference number. _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._ | Juri Munkki jmunkki@hut.fi jmunkki@fingate.bitnet I Want Ne | | Helsinki University of Technology Computing Centre My Own XT | ^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^