[comp.sys.mac] Broken DrawString in LSC?

kwallich@hpsmtc1.HP.COM (Ken Wallich) (10/23/87)

I'm using LSC and am having problems getting DrawString to work when
I pass anything to it.  It appears that LSC is failing to null terminate
the string I pass.  This happens both when I pass literals, or sprintf'ed
parms.  I'm running V2.11.  Has anyone else run across this?  The code
worked fine under Megamax and DesMet (remember that one?).  Any help
would be most appreciated.

Thanks in advance...


--------------------
Ken Wallich                     ...hplabs!hpsmtc1!kwallich
-------------------- 

raylau@dasys1.UUCP (Raymond Lau) (10/25/87)

In article <11540031@hpsmtc1.HP.COM>, kwallich@hpsmtc1.HP.COM (Ken Wallich) writes:
> 
> I'm using LSC and am having problems getting DrawString to work when
> I pass anything to it.  It appears that LSC is failing to null terminate
> the string I pass.  This happens both when I pass literals, or sprintf'ed
> parms.  I'm running V2.11.  Has anyone else run across this?  The code
> worked fine under Megamax and DesMet (remember that one?).  Any help
> would be most appreciated.
> 

DrawString expects a pascal string (length byte preceeded)  DrawString("\pTest"); works fine.  If you're passing null terminated C strings, you must convert them first.  Megamax deals only in C strings and converts them before passing them to DrawString...(adding conversion overhead for when you know the string in advance.)

singer@endor.harvard.edu (Richard Siegel) (10/26/87)

In article <11540031@hpsmtc1.HP.COM> kwallich@hpsmtc1.HP.COM (Ken Wallich) writes:
>
>
>
>I'm using LSC and am having problems getting DrawString to work when
>I pass anything to it.  It appears that LSC is failing to null terminate
>the string I pass.  This happens both when I pass literals, or sprintf'ed

	DrawString doesn't take null-terminated strings, it takes Pascal
strings. Try the following:

	DrawString("\pThis is a string.");

	or

	sprintf(s, "\pThis is a string.");
	DrawString(s);

It worked right in Desmet and Megamax because (as has already been described)
both of those compilers do the string conversion from C to Pascal auto-
matically.

		--Rich

**The opinions stated herein are my own opinions and do not necessarily
represent the policies or opinions of my employer (THINK Technologies, Inc).

* Richard M. Siegel | {decvax, ucbvax, sun}!harvard!endor!singer    *
* Customer Support  | singer@endor.harvard.edu			    *
* Symantec, THINK Technologies Division.  (No snappy quote)         *

lipsett@inmet.UUCP (10/26/87)

DrawString (and the other Toolbox routines) accept Pascal strings,
which are counted ASCII strings.  LSC uses C strings by default.  LSC
WILL NOT AUTOMATICALLY CONVERT FOR YOU (this is a feature).  You can
specify a Pascal-style string literal by the syntax "\pyour string".
The runtime routines PtoCstr and CtoPstr will convert from one style
to the other in-place (and also return the converted string as a
function value).  When you use them, remember to include <pascal.h> or
to declare the function types (I only say this because it took me two
days to find this stupid error on my part).

Roger Lipsett