home *** CD-ROM | disk | FTP | other *** search
- /*****************************************************************************
-
- mac_StrInit.c: Copyright (c) Kevin Hammond 1993. All rights reserved.
-
- This module reads strings from the Gofer resource fork.
-
- *****************************************************************************/
-
-
- #include "mac.h"
-
- #pragma segment StrInit
-
- extern char *safemalloc();
-
- /* GoferVersionString is allocated in getresstring() */
-
- char *GoferVersionString;
-
- extern char *PreludeName, *PrefsName;
- extern unsigned ExtraStack;
-
-
- char *getresstring();
-
- /*
- InitResData reads all initialisation strings from the resource fork.
- These are currently:
-
- Res_MinSize_String Minimum Startup Size
- Res_StackSize_String How much extra C stack to allow (0=>default)
- Res_PreludeName_String What the Prelude's called
- Res_PrefName_String What the Preference File's called
- Res_Version_String Gofer Version
- */
-
-
- InitResData()
- {
- char *GoferSizeString, *GoferStackString;
-
- /* Version */
- GoferVersionString = getresstring(Res_Version_String);
- if(GoferVersionString == NIL)
- GoferVersionString = "??.??";
-
- /* Minimum Macintosh heap to run in, even without MultiFinder */
- GoferSizeString = getresstring(Res_MinSize_String);
- if(GoferSizeString == NIL || (MinMemSize = atoi(GoferSizeString))==0)
- MinMemSize = DEFAULT_MIN_MEM_SIZE;
-
- /* Extra Stack to allocate, 0 means use the default algorithm */
- GoferStackString = getresstring(Res_StackSize_String);
- if(GoferStackString != NIL)
- ExtraStack = atoi(GoferStackString);
-
- /* The name of the Prelude file */
- PreludeName = getresstring(Res_PreludeName_String);
- if(PreludeName==NIL)
- PreludeName = "";
-
- /* The name of the Prelude file */
- PrefsName = getresstring(Res_PrefsName_String);
- if(PrefsName==NIL)
- PrefsName = DEFAULT_PREFS_NAME;
-
- /* Free the local strings if malloc() is known to have been used */
- if(GoferSizeString!=NIL)
- free(GoferSizeString);
-
- if(GoferStackString!=NIL)
- free(GoferStackString);
- }
-
-
- /*
- Get resource 'STR ' id into the string pointer s.
- s is set to NIL if no such resource exists.
- Otherwise a new C string is allocated, and the resource copied.
- This lets us free the string later if required.
- */
-
- char *getresstring(id)
- int id;
- {
- Handle h = GetResource('STR ',id);
-
- if(h == NIL)
- return(NIL);
- else
- {
- char *s = safemalloc((int)(**(char **)h)+1);
-
- /* Lock and copy h: locked in case pstrcopy's in a different segment */
- HLock(h);
- pstrcopy((char *)*h,s);
- HUnlock(h);
-
- p2cstr(s);
- return(s);
- }
- }
-