11#include "Python.h"
22#include "osdefs.h"
3-
3+ #include "macglue.h"
44#include "pythonresources.h"
55
66
2323#include <TextUtils.h>
2424#include <Dialogs.h>
2525
26+ #ifdef USE_GUSI
27+ #include <GUSI.h>
28+ #endif
29+
2630#define PYTHONPATH "\
2731:\n\
2832:Lib\n\
@@ -149,27 +153,24 @@ PyMac_GetPythonDir()
149153 AliasHandle handle ;
150154 FSSpec dirspec ;
151155 Boolean modified = 0 ;
152- short oldrh , prefrh ;
156+ short oldrh , prefrh = -1 , homerh ;
153157
154158 oldrh = CurResFile ();
155- /*
156- ** First look for an override of the preferences file
157- */
158- handle = (AliasHandle )GetResource ('alis' , PYTHONHOMEOVERRIDE_ID );
159+
160+ /* First look for an override in the application file */
161+ UseResFile ( PyMac_AppRefNum );
162+ handle = (AliasHandle )Get1Resource ('alis' , PYTHONHOMEOVERRIDE_ID );
159163 if ( handle != NULL ) {
160- prefrh = oldrh ;
161- } else {
162- /*
163- ** Remember old resource file and try to open preferences file
164- ** in the preferences folder.
165- */
164+ homerh = PyMac_AppRefNum ;
165+ } else {
166+ /* Try to open preferences file in the preferences folder. */
166167 prefrh = PyMac_OpenPrefFile ();
167- /* So, we've opened our preferences file, we hope. Look for the alias */
168168 handle = (AliasHandle )Get1Resource ('alis' , PYTHONHOME_ID );
169169 if ( handle == NULL ) {
170170 (void )StopAlert (BADPREFFILE_ID , NULL );
171171 exit (1 );
172172 }
173+ homerh = prefrh ;
173174 }
174175 /* It exists. Resolve it (possibly updating it) */
175176 if ( ResolveAlias (NULL , handle , & dirspec , & modified ) != noErr ) {
@@ -178,12 +179,10 @@ PyMac_GetPythonDir()
178179 }
179180 if ( modified ) {
180181 ChangedResource ((Handle )handle );
181- UpdateResFile (prefrh );
182- }
183- if ( prefrh != oldrh ) {
184- CloseResFile (prefrh );
185- UseResFile (oldrh );
182+ UpdateResFile (homerh );
186183 }
184+ if ( prefrh != -1 ) CloseResFile (prefrh );
185+ UseResFile (oldrh );
187186
188187 if ( nfullpath (& dirspec , name ) == 0 ) {
189188 strcat (name , ":" );
@@ -212,11 +211,13 @@ char *dir;
212211 OSErr err ;
213212 Handle h ;
214213
214+ oldrh = CurResFile ();
215215 /*
216- ** This is a bit tricky. We check here whether the current resource file
216+ ** This is a bit tricky. We check here whether the application file
217217 ** contains an override. This is to forestall us finding another STR# resource
218218 ** with "our" id and using that for path initialization
219219 */
220+ UseResFile (PyMac_AppRefNum );
220221 SetResLoad (0 );
221222 if ( (h = Get1Resource ('STR#' , PYTHONPATHOVERRIDE_ID )) ) {
222223 ReleaseResource (h );
@@ -225,12 +226,12 @@ char *dir;
225226 resource_id = PYTHONPATH_ID ;
226227 }
227228 SetResLoad (1 );
229+ UseResFile (oldrh );
228230
229231 /*
230232 ** Remember old resource file and try to open preferences file
231233 ** in the preferences folder.
232234 */
233- oldrh = CurResFile ();
234235 if ( FindFolder (kOnSystemDisk , 'pref' , kDontCreateFolder , & prefdirRefNum ,
235236 & prefdirDirID ) == noErr ) {
236237 (void )FSMakeFSSpec (prefdirRefNum , prefdirDirID , "\pPython Preferences" , & dirspec );
@@ -302,10 +303,8 @@ char *dir;
302303 rv ++ ;
303304 }
304305out :
305- if ( prefrh ) {
306- CloseResFile (prefrh );
307- UseResFile (oldrh );
308- }
306+ if ( prefrh != -1 ) CloseResFile (prefrh );
307+ UseResFile (oldrh );
309308 return rv ;
310309}
311310#endif /* !USE_BUILTIN_PATH */
@@ -315,17 +314,24 @@ PyMac_PreferenceOptions(int *inspect, int *verbose, int *suppress_print,
315314 int * unbuffered , int * debugging , int * keep_normal ,
316315 int * keep_error )
317316{
318- short oldrh , prefrh ;
317+ short oldrh , prefrh = -1 ;
319318 Handle handle ;
320319 int size ;
321320 char * p ;
322321
323322
324323 oldrh = CurResFile ();
325- prefrh = PyMac_OpenPrefFile ();
326- handle = GetResource ('Popt' , PYTHONOPTIONSOVERRIDE_ID );
327- if ( handle == NULL )
324+
325+ /* Attempt to load overrides from application */
326+ UseResFile (PyMac_AppRefNum );
327+ handle = Get1Resource ('Popt' , PYTHONOPTIONSOVERRIDE_ID );
328+ UseResFile (oldrh );
329+
330+ /* Otherwise get options from prefs file or any other open resource file */
331+ if ( handle == NULL ) {
332+ prefrh = PyMac_OpenPrefFile ();
328333 handle = GetResource ('Popt' , PYTHONOPTIONS_ID );
334+ }
329335 if ( handle == NULL ) {
330336 return ;
331337 }
@@ -340,9 +346,35 @@ PyMac_PreferenceOptions(int *inspect, int *verbose, int *suppress_print,
340346 if ( size > POPT_DEBUGGING ) * debugging = p [POPT_DEBUGGING ];
341347 if ( size > POPT_KEEPNORM ) * keep_normal = p [POPT_KEEPNORM ];
342348 if ( size > POPT_KEEPERR ) * keep_error = p [POPT_KEEPERR ];
349+ /* The rest are not implemented yet */
343350
344351 HUnlock (handle );
345352
346- CloseResFile (prefrh );
353+ if ( prefrh != -1 ) CloseResFile (prefrh );
354+ UseResFile (oldrh );
355+ }
356+
357+ #ifdef USE_GUSI
358+ void
359+ PyMac_SetGUSIOptions ()
360+ {
361+ Handle h ;
362+ short oldrh , prefrh = -1 ;
363+
364+ oldrh = CurResFile ();
365+
366+ /* Try override from the application resource fork */
367+ UseResFile (PyMac_AppRefNum );
368+ h = Get1Resource ('GU\267I' , GUSIOPTIONSOVERRIDE_ID );
369+ UseResFile (oldrh );
370+
371+ /* If that didn't work try nonoverride from anywhere */
372+ if ( h == NULL ) {
373+ prefrh = PyMac_OpenPrefFile ();
374+ h = GetResource ('GU\267I' , GUSIOPTIONS_ID );
375+ }
376+ if ( h ) GUSILoadConfiguration (h );
377+ if ( prefrh != -1 ) CloseResFile (prefrh );
347378 UseResFile (oldrh );
348379}
380+ #endif /* USE_GUSI */
0 commit comments