[comp.sys.mac.programmer] File manager's "Newline" mode

borcelf@jacobs.cs.orst.edu (Fernando Borcel) (09/25/89)

	IM vII and vIV mention a "newline" mode when reading from a (text) file.
But it doesn't seem to mention how this mode is set.  So the question is:
How do you set it?

Thanks,

	Fernando Borcel
	borcelf@jacobs.cs.orst.edu
'

oster@dewey.soe.berkeley.edu (David Phillip Oster) (09/25/89)

In article <12604@orstcs.CS.ORST.EDU> borcelf@jacobs.cs.orst.edu (Fernando Borcel) writes:
>	IM vII and vIV mention a "newline" mode when reading from a (text) file.
>But it doesn't seem to mention how this mode is set.  So the question is:
>How do you set it?

You use PBRead(), and you stuff the newline character into the high byte
of ioPosMode. Caution, this is _only_ supported by the file manager, in
particular, it is not supported by the Serial Driver, so yo can't read
from the serial port up to the next newline using this method.

--- David Phillip Oster      7 line signature follows
Keith Sproul, head of microcomputer support at Union Carbide, NJ, complained
about the poorly digitized fellatio on an IBM porno program. "Mac is better
on everything, and this is no execption."  -- "Computer Porn at the Office"
by Reese Erlich, _This_World_, S.F. Chronicle, p.8, Aug 13, 1989

Arpa: oster@dewey.soe.berkeley.edu
Uucp: {uwvax,decvax}!ucbvax!oster%dewey.soe.berkeley.edu

borcelf@jacobs.CS.ORST.EDU (Fernando Borcel) (09/26/89)

I posted an article a couple of days ago, referred to the File Manager's
New Line mode.  I got a couple of answers, telling me to set the high byte in
ioPosMode to the NewLine character.  I did, but it seem to make no difference
at all!  Here's a chunk of the little prototype code I wrote to see if it
worked or not...  Here it goes...

 
 var
  MiscFile: integer;
  error: OSErr;
  paramBlock: ParamBlockRec;
  stream: streamType;
  filename: str255;

begin
 filename := ':MiscFile';
 with ParamBlock do
  begin
   ioNameptr := @filename;
   ioPermssn := fsRdPerm;
   ioVRefNum := 0;
   ioMisc := nil;
   ioBuffer := @stream;
   ioReqCount := 255;
   ioPosMode := $0d00;		{High byte = <CR>}
   ioPosOffset := 0;
  end;

 error := PBOpen(@ParamBlock, false);

 repeat
  error := PBRead(@paramBlock, false);
  writeln(Text2Str(stream, paramBlock.ioActCount));
 until error <> noErr;
 error := PBClose(@paramBlock, false);
end.

================
Thanks,
		Fernando Borcel
		borcelf@jacobs.cs.orst.edu

		

zben@umd5.umd.edu (Ben Cranston) (09/26/89)

In article <12615@orstcs.CS.ORST.EDU> borcelf@jacobs.CS.ORST.EDU.UUCP (Fernando Borcel) writes:

> New Line mode ... set the high byte in ioPosMode to the NewLine character.  

OK, you got half of it right, but you also gotta set one bit to tell it
that there is something meaningful in that byte.  You wouldn't want it to
stop on every NULL, would you   :-)

>   ioMisc := nil;
>   ioBuffer := @stream;
>   ioReqCount := 255;
>   ioPosMode := $0d00;		{High byte = <CR>}
    ioPosMode := $0d80;         {Hi byte CR and bit 7 to say it is valid}
                    ^
>   ioPosOffset := 0;

My apologies for the relative verbousity of this note when I could have just
added one line to the original message pointing out the problem.  When I did
so the news software complained that I had not added enough new text to the
message (thanks, guys).  Lets hope this is enough to satisfy it.
-- 
Sig     DS.L    ('ZBen')       ; Ben Cranston <zben@Trantor.UMD.EDU>
* Computer Science Center Network Infrastructures Group
* University of Maryland at College Park

lsr@Apple.COM (Larry Rosenstein) (09/26/89)

Inside Mac volume 4 p 121 says that you also have to set bit 7 of 
ioPosMode as well as putting the character in the upper byte.

Larry Rosenstein, Apple Computer, Inc.
Object Specialist

Internet: lsr@Apple.com   UUCP: {nsc, sun}!apple!lsr
AppleLink: Rosenstein1