strasser@psych.psy.uq.oz.au (Michael Strasser) (07/11/90)
I am having a problem using Munger in a macApp program I'm writing. I am trying to use it as part of a simple text-parsing routine. Here is an example of what I have now: Given: VAR aChar : Char; text : Handle; offset : LONGINT; where : LONGINT; I have text set correctly (I've checked this), and offset set to 0. I then try to find the first tab character in a string which I know contains at least one tab using: aChar := chTab; where := Munger(text, offset, @aChar, 1, NIL, 0); but Munger returns -1, signifying that the string was not found. Am I doing anything wrong? According to my reading of IM, it should be OK. ------ Mike Strasser Psychology Dept, Univ. Of Queensland
keith@Apple.COM (Keith Rollin) (07/13/90)
In article <477@psych.psy.uq.oz.au> strasser@psych.psy.uq.oz.au (Michael Strasser) writes: >I am having a problem using Munger in a macApp program I'm writing. I >am trying to use it as part of a simple text-parsing routine. Here is >an example of what I have now: > >Given: > > VAR > aChar : Char; > text : Handle; > offset : LONGINT; > where : LONGINT; > >I have text set correctly (I've checked this), and offset set to 0. >I then try to find the first tab character in a string which I know >contains at least one tab using: > > aChar := chTab; > where := Munger(text, offset, @aChar, 1, NIL, 0); > >but Munger returns -1, signifying that the string was not found. > >Am I doing anything wrong? According to my reading of IM, it should be >OK. You're passing a pointer to the length byte of "aChar", rather than the first character of aChar. Try: where := Munger(text, offset @aChar[1], Length(aChar), NIL, 0); -- ------------------------------------------------------------------------------ Keith Rollin --- Apple Computer, Inc. --- Developer Technical Support INTERNET: keith@apple.com UUCP: {decwrl, hoptoad, nsc, sun, amdahl}!apple!keith "Argue for your Apple, and sure enough, it's yours" - Keith Rollin, Contusions
drc@claris.com (Dennis Cohen) (07/13/90)
keith@Apple.COM (Keith Rollin) writes: >In article <477@psych.psy.uq.oz.au> strasser@psych.psy.uq.oz.au (Michael Strasser) writes: >>I am having a problem using Munger in a macApp program I'm writing. I >>am trying to use it as part of a simple text-parsing routine. Here is >>an example of what I have now: >> >>Given: >> >> VAR >> aChar : Char; >> text : Handle; >> offset : LONGINT; >> where : LONGINT; >> >>I have text set correctly (I've checked this), and offset set to 0. >>I then try to find the first tab character in a string which I know >>contains at least one tab using: >> >> aChar := chTab; >> where := Munger(text, offset, @aChar, 1, NIL, 0); >> >>but Munger returns -1, signifying that the string was not found. >> >>Am I doing anything wrong? According to my reading of IM, it should be >>OK. >You're passing a pointer to the length byte of "aChar", rather than the >first character of aChar. Try: > where := Munger(text, offset @aChar[1], Length(aChar), NIL, 0); Keith, since when does a Char have a length byte? This cannot be the problem as stated. I don't know what he has as a value for chTab, but I'd be curious since the code he has works for me when I try it. -- Dennis Cohen Claris Corp. **************************************************** Disclaimer: Any opinions expressed above are _MINE_!
keith@Apple.COM (Keith Rollin) (07/14/90)
In article <11122@claris.com> drc@claris.com (Dennis Cohen) writes: >keith@Apple.COM (Keith Rollin) writes: > >>In article <477@psych.psy.uq.oz.au> strasser@psych.psy.uq.oz.au (Michael Strasser) writes: >>>Given: >>> >>> VAR >>> aChar : Char; >>> text : Handle; >>> offset : LONGINT; >>> where : LONGINT; >>> >>>I have text set correctly (I've checked this), and offset set to 0. >>>I then try to find the first tab character in a string which I know >>>contains at least one tab using: >>> >>> aChar := chTab; >>> where := Munger(text, offset, @aChar, 1, NIL, 0); >>> >>>but Munger returns -1, signifying that the string was not found. > >>You're passing a pointer to the length byte of "aChar", rather than the >>first character of aChar. Try: > >> where := Munger(text, offset @aChar[1], Length(aChar), NIL, 0); > >Keith, since when does a Char have a length byte? This cannot be the >problem as stated. I don't know what he has as a value for chTab, but >I'd be curious since the code he has works for me when I try it. Merde. I don't know why I assumed that aChar was a string, especially since the variable declaration was given. You are, of course, correct. -- ------------------------------------------------------------------------------ Keith Rollin --- Apple Computer, Inc. --- Developer Technical Support INTERNET: keith@apple.com UUCP: {decwrl, hoptoad, nsc, sun, amdahl}!apple!keith "Argue for your Apple, and sure enough, it's yours" - Keith Rollin, Contusions
dowdy@apple.com (Tom Dowdy) (07/14/90)
Okay fine. Nobody else has gotten the right answer, so I'll try :-) In article <42936@apple.Apple.COM> keith@Apple.COM (Keith Rollin) writes: > In article <11122@claris.com> drc@claris.com (Dennis Cohen) writes: > >keith@Apple.COM (Keith Rollin) writes: > >>In article <477@psych.psy.uq.oz.au> strasser@psych.psy.uq.oz.au (Michael Strasser) writes: > >>> [ asks why Munger fails on the following call ] > >>> aChar : Char; > >>> where := Munger(text, offset, @aChar, 1, NIL, 0); > >>[ Keith suggests that there is a length byte screwing him up ] > >[ Dennis points out that Chars don't have length bytes ] > [ Keith is embarassed ] This is actually caused by the fact that Pascal will store a char as a short. @Char is giving you a pointer to the high order byte, which is NOT where the data is, it's in the low order byte. So, Ptr(ORD(@Char)+1) is the right way to pass a pointer to a char in Pascal. Keith had the right idea, but the wrong reason. The real reason why this doesn't work is that Pascal sucks. :-) Tom Dowdy Internet: dowdy@apple.COM Apple Computer MS:81EQ UUCP: {sun,voder,amdahl,decwrl}!apple!dowdy 20525 Mariani Ave AppleLink: DOWDY1 Cupertino, CA 95014 "The 'Ooh-Ah' Bird is so called because it lays square eggs."
DN5@psuvm.psu.edu (07/16/90)
In article <9135@goofy.Apple.COM>, dowdy@apple.com (Tom Dowdy) says: >This is actually caused by the fact that Pascal will store a char as a >short. @Char is giving you a pointer to the high order byte, which is NOT >where the data is, it's in the low order byte. > >So, Ptr(ORD(@Char)+1) is the right way to pass a pointer to a char in Pascal. > >Keith had the right idea, but the wrong reason. The real reason why this >doesn't work is that Pascal sucks. :-) > > Tom Dowdy Internet: dowdy@apple.COM > Apple Computer MS:81EQ UUCP: {sun,voder,amdahl,decwrl}!apple!dowdy Actually, I don't believe that the definition of Pascal says that you have to put a CHAR into the low order byte. Even if it did, I would think that the correct thing for the compiler to do would be to get the correct address with the @ operator. Not doing so seems a bug, because now getting the address of an element of a PACKED ARRAY OF CHAR is somehow different from getting the address of a normal CHAR. Perhaps Apple's Pascal should have put the CHAR into the high-order byte, in order to make this come out better? On the other hand, this might generate slightly more code. Which is better, generating more efficient code, or having the compiler work the way that it looks like it should...? (no smiley) In any case, it should be documented somewhere. If not, that is truely a BUG (in the documentation). ()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()() D. Jay Newman ! All syllogisms have three parts, dn5@psuvm.psu.edu ! therefore this is not a syllogism. CBEL--Teaching and Learning Technologies Group