rf1m+@andrew.cmu.edu (Richard Vernon Ford) (02/06/90)
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). Thanks. -------------------------------------------------------------------------- Richard Ford INTERNET:rf1m+@andrew.cmu.edu Senior, Civil Engineering BITNET: rf1m@DRYCAS Carnegie Mellon University "Doing the job search thing"
yahnke@vms.macc.wisc.edu (Ross Yahnke, MACC) (02/06/90)
In article <AZnWC8e00WB5IMBW8u@andrew.cmu.edu>, 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. I glossed over a few details, but you get the picture. >>> Internet: yahnke@macc.wisc.edu <<< >>> Mille voix chuchottent <<c'est vrai>> <<<
time@oxtrap.aa.ox.com (Tim Endres) (02/07/90)
In article <3129@dogie.macc.wisc.edu> yahnke@vms.macc.wisc.edu (Ross Yahnke, MACC) writes: In article <AZnWC8e00WB5IMBW8u@andrew.cmu.edu>, 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. I glossed over a few details, but you get the picture. I believe this is wrong. When I wrote the MacNFS client, we had serious problems debugging BinHex which used the NewLine mode of the Mac File System. I believe you specify in the high byte of a parameter to the open call or the read call the character to end reading on. In your case this character is newline. Please EMail me if you can not find the documentation, which should be in VolII. BUT, I am almost certain this can be done!
jmunkki@kampi.hut.fi (Juri Munkki) (02/07/90)
In article <3129@dogie.macc.wisc.edu> yahnke@vms.macc.wisc.edu (Ross Yahnke, MACC) writes: >In article <AZnWC8e00WB5IMBW8u@andrew.cmu.edu>, 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 <cr>. 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 | ^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^
yahnke@vms.macc.wisc.edu (Ross Yahnke, MACC) (02/07/90)
->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 Whoops, sorry bunky... I was wrong! Several people have pointed out to me that FSRead *does* have a newline mode. Tom Dowdy writes: >FSRead does have a newline mode. It isn't the fastest thing in the world, >but it does certainly work, and I have used it in the past. Probably a >bit of an obscure reference, [in] IM IV - page 121.... Oh fractious day... many pardons for my ignorance, mea culpa, etc. >>> Internet: yahnke@macc.wisc.edu <<< >>> Mille voix chuchottent <<c'est vrai>> <<<
gerhard@cs.arizona.edu (Gerhard Mehldau) (02/07/90)
In article <TIME.90Feb6161219@oxtrap.aa.ox.com>, time@oxtrap.aa.ox.com (Tim Endres) writes: > In article <3129@dogie.macc.wisc.edu> yahnke@vms.macc.wisc.edu (Ross Yahnke, MACC) writes: > > In article <AZnWC8e00WB5IMBW8u@andrew.cmu.edu>, rf1m+@andrew.cmu.edu (Richard Vernon Ford) writes... > -How do you use FSRead in newline mode? ..... > > You ask how you use FSRead in newline mode? Hah! ..... > > I believe this is wrong. ..... I remember trying this, too. IM II and IM IV both say that it can be done. However, I couldn't find a description of how to do it. If anyone knows, please post the solution! -- -> Gerhard Mehldau Dept. of Computer Science internet: gerhard@cs.arizona.edu University of Arizona uucp: {cmcl2,noao,uunet}!arizona!gerhard Tucson, AZ 85721, U.S.A. at&t: +1 (602) 621-4632
amanda@mermaid.intercon.com (Amanda Walker) (02/07/90)
In article <1990Feb6.201847.446@santra.uucp>, jmunkki@kampi.hut.fi (Juri Munkki) writes: > Using a parameter block for reading a file isn't actually any harder than > using FSRead. It also seems to be much faster. Since FSRead is a RAM-based routine (not an actual toolbox routine), one wonders why it isn't just a call to PBRead, using a parameter block sitting on the stack... -- Amanda Walker InterCon Systems Corporation "Many of the truths we cling to depend greatly upon our own point of view." --Obi-Wan Kenobi in "Return of the Jedi"