leonardr@uxe.cso.uiuc.edu (04/13/88)
shinberd@unioncs.UUCP(Dave Shinberg) writes in comp.sys.mac.programmer >I have been struggling with a seemingly simple problem for over two >weeks now. > >How to put characters into a plain text file. Open (and possibly create) the file you wish to write to and then use FSWrite with the number of bytes you wish to write to that file. > After some time I've >narrowed the problem down to the fact that a character occupies TWO BYTE >in MPW Pascal 2.0. Since the program is only intended to be used in English >I have no need for this. It also appears that some aplications such MPW itself >does not recognize two byte characters in a text file. > >My two questions are: > >1) I think my problem is with the SysEnvirons, but I am not totaly sure. > Not SysEnvirions, but the Environs information having to do with the Script Manager. They are two different things and Apple was nice enough to give them similiar names to confuse people. >2) How does TextEdit deal with these tow byte characters and why do some > applications seem to deal only with one byte characters? TextEdit (like all good programs) uses the routines in the Script Manager (See IM V for more info) to handle drawing and processing its Text. The Script Manager (and its Interface files) allow QuickDraw to handle multibyte chars as well as such linguistical features are Right-to-Left typing. If an application does not use the Script Manager and instead relies on its own editing routines (9 of 10 word processors surveyed) which assume that all chars are only one byte, then problems occur if you try to do two-byte character editing (Chinese and Japanese chars on the Mac are handled as Two-byte chars).
dan@Apple.COM (Dan Allen) (04/15/88)
If the problem at hand is to simply write characters to a textfile with MPW Pascal, and these characters are English (that is NOT Arabic, Hebrew, Japanese, or Chinese), THEN your problem has absolutely nothing to do with SysEnvirons, the Script Manager, or anything else that has to do with Two Byte Characters, as that is all for international non-Roman scripts. What your problem DOES concern, is the fact that in MPW Pascal, a CHAR occupies a word, which is TWO BYTES. However, when writing CHARs to textfiles, only a normal bytes worth is written, so your problem is still a mystery. Please send me more info and I'll see what I can do to help... Dan Allen MPW Engineer Apple Computer
darin@Apple.COM (Darin Adler) (04/15/88)
In article <226000007@uxe.cso.uiuc.edu> leonardr@uxe.cso.uiuc.edu writes: > > shinberd@unioncs.UUCP(Dave Shinberg) writes in comp.sys.mac.programmer > >How to put characters into a plain text file. > > > After some time I've > >narrowed the problem down to the fact that a character occupies TWO BYTE > >in MPW Pascal 2.0. Since the program is only intended to be used in English > >I have no need for this. It also appears that some aplications such MPW itself > >does not recognize two byte characters in a text file. You are confusing tyo-byte international characters with the fact that MPW Pascal allocates 2 bytes for a CHAR variable on the stack. CHARs occupy two bytes because of Pascal stack conventions. This is discussed in the "Using Assembly Language" chapter of Inside Mac Vol. I. If you want to write characters to a text file you should only write a single byte for each character. A call to write a single character to a file would look like this: VAR fileRefNum: INTEGER; character: CHAR; buffer: Ptr; count: LONGINT; error: OSErr; {assumes that a file is already open, and its refNum is fileRefNum} character := 'Z'; {write a Z to the file} buffer := Ptr(ORD(@character)+1); {point to the low-order byte} count := 1; {write one byte} error := FSWrite(fileRefNum, buffer, count); -- Darin Adler, Apple Computer AppleLink:Adler4 UUCP: {sun,voder,nsc,mtxinu,dual}!apple!darin CSNET: darin@Apple.com