🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: net.micro.mac
Article #867

C-style string resources

#867
From: Joel West
Date: Wed, 20 Mar 1985 16:47
48 lines
3121 bytes
I am using Megamax C release 2.0 and trying to get the skeleton application 
posted recently to work.  Unfortunately, I am getting one too many conflicts 
between C strings (which end in a 0) and Pascal "str255" (which are preceeded
by a length byte).

As distributed, the skeleton app uses GetString() to fetch a Pascal string
and then stuffs it in a dialog box with ParamString().  However, Megamax
converts all strings from C-style to Pascal style as you pass them to toolbox 
routines.  (One could debate this approach, but it does appear to be a 
reasonably justifiable solution to the problem.)  ParamString might not have 
done this conversion before 2.0, but it sure does now.

Being a reasonably clever fellow, I have tried a variety of approaches, being
careful not to stray beyond the bounds of good taste.  I have tried:
 (1) Using the distributed version.
     RESULT: Garbage leading character, random (varying) garbage
	     trailing character(s).
 (2) Using the distributed .c files, adding trailing "\0" to the declaration
	of the Pascal string resources.
     RESULT: No trailing garbage, still leading garbage (the length byte).
 (3) Using "Type GNRL = CSTR" and the ".S" data type in my resource file.
     RESULT: Undistinguishable from (2).  A friend said he'd found using
	     ResEdit that the ".S" strings don't seem to do what you'd
	     expect, i.e., a naked string without a length byte.
 (4) Revert to std. resource declarations; produce a modified getCstring()
	which converts C strings in place after calling GetString().
     RESULT: Works beautifully the first time.  However, the second time the
	     same string is used, a Pascal string is expected by getCstring()
	     (but it's actually in C form already) and all hell breaks loose.
 (5) Go back to (2).  Write a getCstring() that takes the GetString() and
	then bumps the pointer referenced by the handle.
     RESULT: Beautiful.  The strings show up perfect every time.  However,
	     Quit crashes the system.

Any ideas?  Declaring null-terminated C strings in the resource file would be 
nice, but I can't figure out how to do it.  Or, SuMacC allows you to fool
the interface string converter with "isapstr(..)", which indicates the string
is already Pascal-like and thus suppresses conversion.

Mail responses to me and I'll post the revised Skeleton with the winning entry 
to net.sources.mac.
-- 
	Joel West				     (619) 457-9681
	CACI, Inc. - Federal 3344 N. Torrey Pines Ct La Jolla 92037
	jww@bonnie.UUCP (ihnp4!bonnie!jww)
	westjw@nosc.ARPA

   "The best is the enemy of the good" - A. Mullarney
Technical Details
Message-ID: <450@bonnie.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!watmath!clyde!bonnie!jww

Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.2 9/18/84; site bonnie.UUCP
Path: arc1-ca.pugleaf.net!utzoo!watmath!clyde!bonnie!jww
From: jww@bonnie.UUCP (Joel West)
Newsgroups: net.micro.mac
Subject: C-style string resources
Message-ID: <450@bonnie.UUCP>
Date: Wed, 20-Mar-85 11:47:51 EST
Article-I.D.: bonnie.450
Posted: Wed Mar 20 11:47:51 1985
Date-Received: Thu, 21-Mar-85 02:27:51 EST
Organization: CACI -- La Jolla, Calif.
Lines: 48