blob: b79e90b001ec76ce797692c1ac5c5a140e7ea132 [file] [log] [blame]
Jack Jansen42218ce1997-01-31 16:15:11 +00001/***********************************************************
2Copyright 1991-1997 by Stichting Mathematisch Centrum, Amsterdam,
3The Netherlands.
4
5 All Rights Reserved
6
7Permission to use, copy, modify, and distribute this software and its
8documentation for any purpose and without fee is hereby granted,
9provided that the above copyright notice appear in all copies and that
10both that copyright notice and this permission notice appear in
11supporting documentation, and that the names of Stichting Mathematisch
12Centrum or CWI or Corporation for National Research Initiatives or
13CNRI not be used in advertising or publicity pertaining to
14distribution of the software without specific, written prior
15permission.
16
17While CWI is the initial source for this software, a modified version
18is made available by the Corporation for National Research Initiatives
19(CNRI) at the Internet address ftp://ftp.python.org.
20
21STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH
22REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
23MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH
24CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
25DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
26PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
27TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
28PERFORMANCE OF THIS SOFTWARE.
29
30******************************************************************/
31
Jack Jansen12fce3e1995-08-14 12:31:44 +000032#include "Python.h"
33#include "osdefs.h"
Jack Jansen3f7d2b41996-09-06 22:21:07 +000034#include "macglue.h"
Jack Jansen41e25cc2000-07-14 22:16:01 +000035#include "macdefs.h"
Jack Jansen12fce3e1995-08-14 12:31:44 +000036#include "pythonresources.h"
Jack Jansen9ae898b2000-07-11 21:16:03 +000037#ifdef HAVE_UNISTD_H
38#include <unistd.h>
39#endif
Jack Jansen12fce3e1995-08-14 12:31:44 +000040
Jack Jansen697842f2001-09-10 22:00:39 +000041#ifdef TARGET_API_MAC_OSX
42#define PATHNAMELEN 1024
43#else
44#define PATHNAMELEN 256
45#endif
Jack Jansen12fce3e1995-08-14 12:31:44 +000046
47/* Return the initial python search path. This is called once from
48** initsys() to initialize sys.path.
49**
50** If USE_BUILTIN_PATH is defined the path defined here is used
51** (after prepending the python home dir to each item).
52** If it is not defined the path is gotten from a resource in the
53** Preferences file.
54**
55** XXXX This code needs cleaning up. The routines here have moved
56** around quite a bit, and they're pretty messy for that reason.
57*/
58
59#include <Files.h>
60#include <Aliases.h>
61#include <Folders.h>
62#include <Resources.h>
63#include <TextUtils.h>
Jack Jansenb39be211995-09-01 11:48:10 +000064#include <Dialogs.h>
Jack Jansen12fce3e1995-08-14 12:31:44 +000065
Jack Jansen2d1306b2000-04-07 09:10:49 +000066#ifdef USE_GUSI1
Jack Jansen3f7d2b41996-09-06 22:21:07 +000067#include <GUSI.h>
68#endif
69
Jack Jansen9ae898b2000-07-11 21:16:03 +000070#ifndef USE_BUILTIN_PATH
71staticforward char *PyMac_GetPythonPath();
72#endif
73
Jack Jansen12fce3e1995-08-14 12:31:44 +000074#define PYTHONPATH "\
75:\n\
76:Lib\n\
77:Lib:stdwin\n\
78:Lib:test\n\
79:Lib:mac"
80
Jack Jansenac82b6a1998-07-13 13:38:29 +000081static int
Jack Jansen83c74df1996-10-22 15:25:42 +000082getpreffilefss(FSSpec *fssp)
83{
84 static int diditbefore=0;
Jack Jansenac82b6a1998-07-13 13:38:29 +000085 static int rv = 1;
Jack Jansen83c74df1996-10-22 15:25:42 +000086 static FSSpec fss;
Jack Jansenabdf93c1998-07-31 09:33:28 +000087 short prefdirRefNum;
88 long prefdirDirID;
Just van Rossum26a69db1999-02-02 15:49:03 +000089 long pyprefdirDirID;
Jack Jansenabdf93c1998-07-31 09:33:28 +000090 Handle namehandle;
Just van Rossum26a69db1999-02-02 15:49:03 +000091 OSErr err;
Jack Jansenabdf93c1998-07-31 09:33:28 +000092
93 if ( !diditbefore ) {
Jack Jansenabdf93c1998-07-31 09:33:28 +000094 if ( (namehandle=GetNamedResource('STR ', PREFFILENAME_NAME)) == NULL ) {
95 (void)StopAlert(NOPREFNAME_ID, NULL);
96 exit(1);
97 }
98
Jack Jansenabdf93c1998-07-31 09:33:28 +000099 if ( **namehandle == '\0' ) {
100 /* Empty string means don't use preferences file */
101 rv = 0;
102 } else {
103 /* There is a filename, construct the fsspec */
Just van Rossum26a69db1999-02-02 15:49:03 +0000104 if ( FindFolder(kOnSystemDisk, 'pref', kDontCreateFolder, &prefdirRefNum,
105 &prefdirDirID) != noErr ) {
106 /* Something wrong with preferences folder */
107 (void)StopAlert(NOPREFDIR_ID, NULL);
108 exit(1);
109 }
110 /* make fsspec for the "Python" folder inside the prefs folder */
111 err = FSMakeFSSpec(prefdirRefNum, prefdirDirID, "\pPython", &fss);
112 if (err == fnfErr) {
113 /* it doesn't exist: create it */
114 err = FSpDirCreate(&fss, smSystemScript, &pyprefdirDirID);
115 } else {
116 /* it does exist, now find out the dirID of the Python prefs folder, brrr. */
117 CInfoPBRec info;
118 info.dirInfo.ioVRefNum = fss.vRefNum;
119 info.dirInfo.ioDrDirID = fss.parID;
120 info.dirInfo.ioNamePtr = fss.name;
121 info.dirInfo.ioFDirIndex = 0;
122 info.dirInfo.ioACUser = 0;
123 err = PBGetCatInfo(&info, 0);
124 if (err == noErr) {
125 pyprefdirDirID = info.dirInfo.ioDrDirID;
126 }
127 }
128 if (err != noErr) {
129 (void)StopAlert(NOPREFDIR_ID, NULL);
130 exit(1);
131 }
132 HLock(namehandle);
133 err = FSMakeFSSpec(fss.vRefNum, pyprefdirDirID, (unsigned char *)*namehandle, &fss);
134 HUnlock(namehandle);
135 if (err != noErr && err != fnfErr) {
136 (void)StopAlert(NOPREFDIR_ID, NULL);
137 exit(1);
138 }
Jack Jansenac82b6a1998-07-13 13:38:29 +0000139 }
Jack Jansen83c74df1996-10-22 15:25:42 +0000140 ReleaseResource(namehandle);
141 diditbefore = 1;
142 }
143 *fssp = fss;
Jack Jansenac82b6a1998-07-13 13:38:29 +0000144 return rv;
Jack Jansen83c74df1996-10-22 15:25:42 +0000145}
Jack Jansen12fce3e1995-08-14 12:31:44 +0000146
147char *
Jack Jansena547dca1996-07-10 15:48:25 +0000148Py_GetPath()
Jack Jansen12fce3e1995-08-14 12:31:44 +0000149{
150 /* Modified by Jack to do something a bit more sensible:
151 ** - Prepend the python home-directory (which is obtained from a Preferences
152 ** resource)
153 ** - Add :
154 */
155 static char *pythonpath;
Jack Jansen12fce3e1995-08-14 12:31:44 +0000156 char *p, *endp;
157 int newlen;
Jack Jansen83c74df1996-10-22 15:25:42 +0000158 char *curwd;
Jack Jansen12fce3e1995-08-14 12:31:44 +0000159
160 if ( pythonpath ) return pythonpath;
Jack Jansen12fce3e1995-08-14 12:31:44 +0000161#ifndef USE_BUILTIN_PATH
Jack Jansen83c74df1996-10-22 15:25:42 +0000162 if ( pythonpath = PyMac_GetPythonPath() )
Jack Jansen12fce3e1995-08-14 12:31:44 +0000163 return pythonpath;
164 printf("Warning: No pythonpath resource found, using builtin default\n");
165#endif
Jack Jansen83c74df1996-10-22 15:25:42 +0000166 curwd = PyMac_GetPythonDir();
Jack Jansen12fce3e1995-08-14 12:31:44 +0000167 p = PYTHONPATH;
168 endp = p;
169 pythonpath = malloc(2);
170 if ( pythonpath == NULL ) return PYTHONPATH;
171 strcpy(pythonpath, ":");
172 while (*endp) {
173 endp = strchr(p, '\n');
174 if ( endp == NULL )
175 endp = p + strlen(p);
176 newlen = strlen(pythonpath) + 1 + strlen(curwd) + (endp-p);
177 pythonpath = realloc(pythonpath, newlen+1);
178 if ( pythonpath == NULL ) return PYTHONPATH;
179 strcat(pythonpath, "\n");
180 if ( *p == ':' ) {
181 p++;
182 strcat(pythonpath, curwd);
183 strncat(pythonpath, p, (endp-p));
184 newlen--; /* Ok, ok, we've allocated one byte too much */
185 } else {
186 /* We've allocated too much in this case */
187 newlen -= strlen(curwd);
188 pythonpath = realloc(pythonpath, newlen+1);
189 if ( pythonpath == NULL ) return PYTHONPATH;
190 strncat(pythonpath, p, (endp-p));
191 }
192 pythonpath[newlen] = '\0';
193 p = endp + 1;
194 }
195 return pythonpath;
196}
197
Jack Jansen83c74df1996-10-22 15:25:42 +0000198
Jack Jansen41fa7ea1995-08-31 13:59:36 +0000199/*
200** Open/create the Python Preferences file, return the handle
201*/
Jack Jansenee081042000-04-21 23:53:37 +0000202short
Jack Jansen41fa7ea1995-08-31 13:59:36 +0000203PyMac_OpenPrefFile()
204{
Jack Jansenabdf93c1998-07-31 09:33:28 +0000205 AliasHandle handle;
206 FSSpec dirspec;
207 short prefrh;
208 OSErr err;
Jack Jansen41fa7ea1995-08-31 13:59:36 +0000209
Jack Jansenac82b6a1998-07-13 13:38:29 +0000210 if ( !getpreffilefss(&dirspec))
211 return -1;
Jack Jansen41fa7ea1995-08-31 13:59:36 +0000212 prefrh = FSpOpenResFile(&dirspec, fsRdWrShPerm);
213 if ( prefrh < 0 ) {
Jack Jansen83c74df1996-10-22 15:25:42 +0000214#if 0
Jack Jansen41fa7ea1995-08-31 13:59:36 +0000215 action = CautionAlert(NOPREFFILE_ID, NULL);
216 if ( action == NOPREFFILE_NO )
217 exit(1);
Jack Jansen83c74df1996-10-22 15:25:42 +0000218#endif
Jack Jansen532e3c21996-02-21 15:36:26 +0000219 FSpCreateResFile(&dirspec, 'Pyth', 'pref', 0);
Jack Jansen41fa7ea1995-08-31 13:59:36 +0000220 prefrh = FSpOpenResFile(&dirspec, fsRdWrShPerm);
221 if ( prefrh == -1 ) {
222 /* This "cannot happen":-) */
Jack Jansenb39be211995-09-01 11:48:10 +0000223 printf("Cannot create preferences file, error %d\n", ResError());
Jack Jansen41fa7ea1995-08-31 13:59:36 +0000224 exit(1);
225 }
Jack Jansen26ee1261996-11-09 18:45:18 +0000226 if ( (err=PyMac_init_process_location()) != 0 ) {
227 printf("Cannot get application location, error %d\n", err);
Jack Jansen41fa7ea1995-08-31 13:59:36 +0000228 exit(1);
229 }
Jack Jansen26ee1261996-11-09 18:45:18 +0000230 dirspec = PyMac_ApplicationFSSpec;
Jack Jansen41fa7ea1995-08-31 13:59:36 +0000231 dirspec.name[0] = 0;
Jack Jansenb39be211995-09-01 11:48:10 +0000232 if ((err=NewAlias(NULL, &dirspec, &handle)) != 0 ) {
233 printf("Cannot make alias to application directory, error %d\n", err);
Jack Jansen41fa7ea1995-08-31 13:59:36 +0000234 exit(1);
235 }
Jack Jansenabdf93c1998-07-31 09:33:28 +0000236 AddResource((Handle)handle, 'alis', PYTHONHOME_ID, "\p");
237 UpdateResFile(prefrh);
Jack Jansen41fa7ea1995-08-31 13:59:36 +0000238
239 } else {
240 UseResFile(prefrh);
241 }
242 return prefrh;
243}
Jack Jansen12fce3e1995-08-14 12:31:44 +0000244
245/*
246** Return the name of the Python directory
247*/
Jack Jansen5b3c9711997-09-08 13:22:49 +0000248char *
Jack Jansen12fce3e1995-08-14 12:31:44 +0000249PyMac_GetPythonDir()
250{
Jack Jansen83c74df1996-10-22 15:25:42 +0000251 static int diditbefore = 0;
Jack Jansen697842f2001-09-10 22:00:39 +0000252 static char name[PATHNAMELEN] = {':', '\0'};
Jack Jansenabdf93c1998-07-31 09:33:28 +0000253 AliasHandle handle;
254 FSSpec dirspec;
255 Boolean modified = 0;
256 short oldrh, prefrh = -1, homerh;
257
258 if ( diditbefore )
259 return name;
260
261 oldrh = CurResFile();
Jack Jansen3f7d2b41996-09-06 22:21:07 +0000262
Jack Jansenabdf93c1998-07-31 09:33:28 +0000263 /* First look for an override in the application file */
264 UseResFile(PyMac_AppRefNum);
265 handle = (AliasHandle)Get1Resource('alis', PYTHONHOMEOVERRIDE_ID);
266 UseResFile(oldrh);
267 if ( handle != NULL ) {
268 homerh = PyMac_AppRefNum;
269 } else {
270 /* Try to open preferences file in the preferences folder. */
271 prefrh = PyMac_OpenPrefFile();
272 handle = (AliasHandle)Get1Resource('alis', PYTHONHOME_ID);
273 if ( handle == NULL ) {
274 /* (void)StopAlert(BADPREFFILE_ID, NULL); */
275 diditbefore=1;
276 return ":";
277 }
278 homerh = prefrh;
279 }
280 /* It exists. Resolve it (possibly updating it) */
281 if ( ResolveAlias(NULL, handle, &dirspec, &modified) != noErr ) {
282 (void)StopAlert(BADPREFFILE_ID, NULL);
283 diditbefore=1;
284 return ":";
285 }
286 if ( modified ) {
Jack Jansen41fa7ea1995-08-31 13:59:36 +0000287 ChangedResource((Handle)handle);
Jack Jansenabdf93c1998-07-31 09:33:28 +0000288 UpdateResFile(homerh);
289 }
290 if ( prefrh != -1 ) CloseResFile(prefrh);
291 UseResFile(oldrh);
Jack Jansen41fa7ea1995-08-31 13:59:36 +0000292
Jack Jansen697842f2001-09-10 22:00:39 +0000293 if ( PyMac_GetFullPathname(&dirspec, name, PATHNAMELEN) == 0 ) {
Jack Jansen41fa7ea1995-08-31 13:59:36 +0000294 strcat(name, ":");
Jack Jansenabdf93c1998-07-31 09:33:28 +0000295 } else {
Jack Jansen41fa7ea1995-08-31 13:59:36 +0000296 /* If all fails, we return the current directory */
297 printf("Python home dir exists but I cannot find the pathname!!\n");
Jack Jansen12fce3e1995-08-14 12:31:44 +0000298 name[0] = 0;
Jack Jansen031b7792001-12-14 22:57:34 +0000299 (void)getcwd(name, sizeof(name));
Jack Jansen12fce3e1995-08-14 12:31:44 +0000300 }
Jack Jansen83c74df1996-10-22 15:25:42 +0000301 diditbefore = 1;
Jack Jansen12fce3e1995-08-14 12:31:44 +0000302 return name;
303}
304
305#ifndef USE_BUILTIN_PATH
Jack Jansen5b3c9711997-09-08 13:22:49 +0000306char *
Jack Jansen9ae898b2000-07-11 21:16:03 +0000307PyMac_GetPythonPath(void)
Jack Jansen12fce3e1995-08-14 12:31:44 +0000308{
Jack Jansenabdf93c1998-07-31 09:33:28 +0000309 short oldrh, prefrh = -1;
310 char *rv;
311 int i, newlen;
312 Str255 pathitem;
313 int resource_id;
314 OSErr err;
315 Handle h;
316
317 oldrh = CurResFile();
318 /*
319 ** This is a bit tricky. We check here whether the application file
320 ** contains an override. This is to forestall us finding another STR# resource
321 ** with "our" id and using that for path initialization
322 */
323 UseResFile(PyMac_AppRefNum);
324 SetResLoad(0);
325 if ( (h=Get1Resource('STR#', PYTHONPATHOVERRIDE_ID)) ) {
326 ReleaseResource(h);
327 resource_id = PYTHONPATHOVERRIDE_ID;
328 } else {
329 resource_id = PYTHONPATH_ID;
330 }
331 SetResLoad(1);
332 UseResFile(oldrh);
333
334 /* Open the preferences file only if there is no override */
335 if ( resource_id != PYTHONPATHOVERRIDE_ID )
336 prefrh = PyMac_OpenPrefFile();
337 /* At this point, we may or may not have the preferences file open, and it
338 ** may or may not contain a sys.path STR# resource. We don't care, if it doesn't
339 ** exist we use the one from the application (the default).
340 ** We put an initial '\n' in front of the path that we don't return to the caller
341 */
342 if( (rv = malloc(2)) == NULL )
343 goto out;
344 strcpy(rv, "\n");
Jack Jansenf12e7091996-09-05 15:19:24 +0000345
Jack Jansenabdf93c1998-07-31 09:33:28 +0000346 for(i=1; ; i++) {
347 GetIndString(pathitem, resource_id, i);
348 if( pathitem[0] == 0 )
349 break;
350 if ( pathitem[0] >= 9 && strncmp((char *)pathitem+1, "$(PYTHON)", 9) == 0 ) {
351 /* We have to put the directory in place */
352 char *dir = PyMac_GetPythonDir();
353
354 newlen = strlen(rv) + strlen(dir) + (pathitem[0]-9) + 2;
355 if( (rv=realloc(rv, newlen)) == NULL)
356 goto out;
357 strcat(rv, dir);
358 /* Skip a colon at the beginning of the item */
359 if ( pathitem[0] > 9 && pathitem[1+9] == ':' ) {
Jack Jansen12fce3e1995-08-14 12:31:44 +0000360 memcpy(rv+strlen(rv), pathitem+1+10, pathitem[0]-10);
361 newlen--;
362 } else {
363 memcpy(rv+strlen(rv), pathitem+1+9, pathitem[0]-9);
364 }
Jack Jansenabdf93c1998-07-31 09:33:28 +0000365 rv[newlen-2] = '\n';
366 rv[newlen-1] = 0;
367 } else if ( pathitem[0] >= 14 && strncmp((char *)pathitem+1, "$(APPLICATION)", 14) == 0 ) {
368 /* This is the application itself */
Jack Jansena486a551996-04-04 15:39:18 +0000369
Jack Jansenabdf93c1998-07-31 09:33:28 +0000370 if ( (err=PyMac_init_process_location()) != 0 ) {
Jack Jansen26ee1261996-11-09 18:45:18 +0000371 printf("Cannot get application location, error %d\n", err);
Jack Jansena486a551996-04-04 15:39:18 +0000372 exit(1);
373 }
Jack Jansen26ee1261996-11-09 18:45:18 +0000374
375 newlen = strlen(rv) + strlen(PyMac_ApplicationPath) + 2;
Jack Jansenabdf93c1998-07-31 09:33:28 +0000376 if( (rv=realloc(rv, newlen)) == NULL)
377 goto out;
378 strcpy(rv+strlen(rv), PyMac_ApplicationPath);
379 rv[newlen-2] = '\n';
380 rv[newlen-1] = 0;
Jack Jansena486a551996-04-04 15:39:18 +0000381
Jack Jansenabdf93c1998-07-31 09:33:28 +0000382 } else {
383 /* Use as-is */
384 newlen = strlen(rv) + (pathitem[0]) + 2;
385 if( (rv=realloc(rv, newlen)) == NULL)
386 goto out;
387 memcpy(rv+strlen(rv), pathitem+1, pathitem[0]);
388 rv[newlen-2] = '\n';
389 rv[newlen-1] = 0;
390 }
Jack Jansen12fce3e1995-08-14 12:31:44 +0000391 }
392 if( strlen(rv) == 1) {
393 free(rv);
394 rv = NULL;
395 }
396 if ( rv ) {
397 rv[strlen(rv)-1] = 0;
398 rv++;
399 }
400out:
Jack Jansen3f7d2b41996-09-06 22:21:07 +0000401 if ( prefrh != -1) CloseResFile(prefrh);
402 UseResFile(oldrh);
Jack Jansen12fce3e1995-08-14 12:31:44 +0000403 return rv;
404}
405#endif /* !USE_BUILTIN_PATH */
406
Jack Jansena4b7e141996-02-21 16:46:57 +0000407void
Jack Jansen7d5f9e81996-09-07 17:09:31 +0000408PyMac_PreferenceOptions(PyMac_PrefRecord *pr)
Jack Jansena4b7e141996-02-21 16:46:57 +0000409{
Jack Jansen3f7d2b41996-09-06 22:21:07 +0000410 short oldrh, prefrh = -1;
Jack Jansena4b7e141996-02-21 16:46:57 +0000411 Handle handle;
412 int size;
Jack Jansen5b3c9711997-09-08 13:22:49 +0000413 PyMac_PrefRecord *p;
414 int action;
Jack Jansena4b7e141996-02-21 16:46:57 +0000415
416
Jack Jansenabdf93c1998-07-31 09:33:28 +0000417 oldrh = CurResFile();
418
419 /* Attempt to load overrides from application */
420 UseResFile(PyMac_AppRefNum);
421 handle = Get1Resource('Popt', PYTHONOPTIONSOVERRIDE_ID);
422 UseResFile(oldrh);
423
424 /* Otherwise get options from prefs file or any other open resource file */
425 if ( handle == NULL ) {
426 prefrh = PyMac_OpenPrefFile();
427 handle = GetResource('Popt', PYTHONOPTIONS_ID);
Jack Jansen3f7d2b41996-09-06 22:21:07 +0000428 }
Jack Jansenabdf93c1998-07-31 09:33:28 +0000429 if ( handle == NULL ) {
430 return;
431 }
432 HLock(handle);
433 size = GetHandleSize(handle);
434 p = (PyMac_PrefRecord *)*handle;
435 if ( p->version == POPT_VERSION_CURRENT && size == sizeof(PyMac_PrefRecord) ) {
436 *pr = *p;
437 } else {
438 action = CautionAlert(BADPREFERENCES_ID, NULL);
439 if ( action == BADPREF_DELETE ) {
440 OSErr err;
441
442 RemoveResource(handle);
443 if ( (err=ResError()) ) printf("RemoveResource: %d\n", err);
444 if ( prefrh != -1 ) {
445 UpdateResFile(prefrh);
446 if ( (err=ResError()) ) printf("UpdateResFile: %d\n", err);
447 }
448 } else if ( action == BADPREF_QUIT )
449 exit(1);
450 }
451 HUnlock(handle);
Jack Jansena4b7e141996-02-21 16:46:57 +0000452
Jack Jansen3f7d2b41996-09-06 22:21:07 +0000453 if ( prefrh != -1) CloseResFile(prefrh);
Jack Jansenabdf93c1998-07-31 09:33:28 +0000454 UseResFile(oldrh);
Jack Jansena4b7e141996-02-21 16:46:57 +0000455}
Jack Jansen3f7d2b41996-09-06 22:21:07 +0000456
Jack Jansen2d1306b2000-04-07 09:10:49 +0000457#ifdef USE_GUSI1
Jack Jansen3f7d2b41996-09-06 22:21:07 +0000458void
459PyMac_SetGUSIOptions()
460{
461 Handle h;
462 short oldrh, prefrh = -1;
463
464 oldrh = CurResFile();
465
466 /* Try override from the application resource fork */
467 UseResFile(PyMac_AppRefNum);
468 h = Get1Resource('GU\267I', GUSIOPTIONSOVERRIDE_ID);
469 UseResFile(oldrh);
470
471 /* If that didn't work try nonoverride from anywhere */
472 if ( h == NULL ) {
473 prefrh = PyMac_OpenPrefFile();
474 h = GetResource('GU\267I', GUSIOPTIONS_ID);
475 }
476 if ( h ) GUSILoadConfiguration(h);
477 if ( prefrh != -1) CloseResFile(prefrh);
Jack Jansenabdf93c1998-07-31 09:33:28 +0000478 UseResFile(oldrh);
Jack Jansen3f7d2b41996-09-06 22:21:07 +0000479}
Jack Jansenee081042000-04-21 23:53:37 +0000480#endif /* USE_GUSI1 */