Commit 5aaec724 authored by Jack Jansen's avatar Jack Jansen

- Rationalized override preferences support, by remembering

  application resource fork RefNum and looking there only
- Added support for loading gusi prefs from Preferences file (needs
  modified GUSI, but Matthias promised he'd incorporate the fixes in
  the next release)
parent 3d425653
#include "Python.h" #include "Python.h"
#include "osdefs.h" #include "osdefs.h"
#include "macglue.h"
#include "pythonresources.h" #include "pythonresources.h"
...@@ -23,6 +23,10 @@ ...@@ -23,6 +23,10 @@
#include <TextUtils.h> #include <TextUtils.h>
#include <Dialogs.h> #include <Dialogs.h>
#ifdef USE_GUSI
#include <GUSI.h>
#endif
#define PYTHONPATH "\ #define PYTHONPATH "\
:\n\ :\n\
:Lib\n\ :Lib\n\
...@@ -149,27 +153,24 @@ PyMac_GetPythonDir() ...@@ -149,27 +153,24 @@ PyMac_GetPythonDir()
AliasHandle handle; AliasHandle handle;
FSSpec dirspec; FSSpec dirspec;
Boolean modified = 0; Boolean modified = 0;
short oldrh, prefrh; short oldrh, prefrh = -1, homerh;
oldrh = CurResFile(); oldrh = CurResFile();
/*
** First look for an override of the preferences file /* First look for an override in the application file */
*/ UseResFile(PyMac_AppRefNum);
handle = (AliasHandle)GetResource('alis', PYTHONHOMEOVERRIDE_ID); handle = (AliasHandle)Get1Resource('alis', PYTHONHOMEOVERRIDE_ID);
if ( handle != NULL ) { if ( handle != NULL ) {
prefrh = oldrh; homerh = PyMac_AppRefNum;
} else { } else {
/* /* Try to open preferences file in the preferences folder. */
** Remember old resource file and try to open preferences file
** in the preferences folder.
*/
prefrh = PyMac_OpenPrefFile(); prefrh = PyMac_OpenPrefFile();
/* So, we've opened our preferences file, we hope. Look for the alias */
handle = (AliasHandle)Get1Resource('alis', PYTHONHOME_ID); handle = (AliasHandle)Get1Resource('alis', PYTHONHOME_ID);
if ( handle == NULL ) { if ( handle == NULL ) {
(void)StopAlert(BADPREFFILE_ID, NULL); (void)StopAlert(BADPREFFILE_ID, NULL);
exit(1); exit(1);
} }
homerh = prefrh;
} }
/* It exists. Resolve it (possibly updating it) */ /* It exists. Resolve it (possibly updating it) */
if ( ResolveAlias(NULL, handle, &dirspec, &modified) != noErr ) { if ( ResolveAlias(NULL, handle, &dirspec, &modified) != noErr ) {
...@@ -178,12 +179,10 @@ PyMac_GetPythonDir() ...@@ -178,12 +179,10 @@ PyMac_GetPythonDir()
} }
if ( modified ) { if ( modified ) {
ChangedResource((Handle)handle); ChangedResource((Handle)handle);
UpdateResFile(prefrh); UpdateResFile(homerh);
}
if ( prefrh != oldrh ) {
CloseResFile(prefrh);
UseResFile(oldrh);
} }
if ( prefrh != -1 ) CloseResFile(prefrh);
UseResFile(oldrh);
if ( nfullpath(&dirspec, name) == 0 ) { if ( nfullpath(&dirspec, name) == 0 ) {
strcat(name, ":"); strcat(name, ":");
...@@ -212,11 +211,13 @@ char *dir; ...@@ -212,11 +211,13 @@ char *dir;
OSErr err; OSErr err;
Handle h; Handle h;
oldrh = CurResFile();
/* /*
** This is a bit tricky. We check here whether the current resource file ** This is a bit tricky. We check here whether the application file
** contains an override. This is to forestall us finding another STR# resource ** contains an override. This is to forestall us finding another STR# resource
** with "our" id and using that for path initialization ** with "our" id and using that for path initialization
*/ */
UseResFile(PyMac_AppRefNum);
SetResLoad(0); SetResLoad(0);
if ( (h=Get1Resource('STR#', PYTHONPATHOVERRIDE_ID)) ) { if ( (h=Get1Resource('STR#', PYTHONPATHOVERRIDE_ID)) ) {
ReleaseResource(h); ReleaseResource(h);
...@@ -225,12 +226,12 @@ char *dir; ...@@ -225,12 +226,12 @@ char *dir;
resource_id = PYTHONPATH_ID; resource_id = PYTHONPATH_ID;
} }
SetResLoad(1); SetResLoad(1);
UseResFile(oldrh);
/* /*
** Remember old resource file and try to open preferences file ** Remember old resource file and try to open preferences file
** in the preferences folder. ** in the preferences folder.
*/ */
oldrh = CurResFile();
if ( FindFolder(kOnSystemDisk, 'pref', kDontCreateFolder, &prefdirRefNum, if ( FindFolder(kOnSystemDisk, 'pref', kDontCreateFolder, &prefdirRefNum,
&prefdirDirID) == noErr ) { &prefdirDirID) == noErr ) {
(void)FSMakeFSSpec(prefdirRefNum, prefdirDirID, "\pPython Preferences", &dirspec); (void)FSMakeFSSpec(prefdirRefNum, prefdirDirID, "\pPython Preferences", &dirspec);
...@@ -302,10 +303,8 @@ char *dir; ...@@ -302,10 +303,8 @@ char *dir;
rv++; rv++;
} }
out: out:
if ( prefrh ) { if ( prefrh != -1) CloseResFile(prefrh);
CloseResFile(prefrh); UseResFile(oldrh);
UseResFile(oldrh);
}
return rv; return rv;
} }
#endif /* !USE_BUILTIN_PATH */ #endif /* !USE_BUILTIN_PATH */
...@@ -315,17 +314,24 @@ PyMac_PreferenceOptions(int *inspect, int *verbose, int *suppress_print, ...@@ -315,17 +314,24 @@ PyMac_PreferenceOptions(int *inspect, int *verbose, int *suppress_print,
int *unbuffered, int *debugging, int *keep_normal, int *unbuffered, int *debugging, int *keep_normal,
int *keep_error) int *keep_error)
{ {
short oldrh, prefrh; short oldrh, prefrh = -1;
Handle handle; Handle handle;
int size; int size;
char *p; char *p;
oldrh = CurResFile(); oldrh = CurResFile();
prefrh = PyMac_OpenPrefFile();
handle = GetResource('Popt', PYTHONOPTIONSOVERRIDE_ID); /* Attempt to load overrides from application */
if ( handle == NULL ) UseResFile(PyMac_AppRefNum);
handle = Get1Resource('Popt', PYTHONOPTIONSOVERRIDE_ID);
UseResFile(oldrh);
/* Otherwise get options from prefs file or any other open resource file */
if ( handle == NULL ) {
prefrh = PyMac_OpenPrefFile();
handle = GetResource('Popt', PYTHONOPTIONS_ID); handle = GetResource('Popt', PYTHONOPTIONS_ID);
}
if ( handle == NULL ) { if ( handle == NULL ) {
return; return;
} }
...@@ -340,9 +346,35 @@ PyMac_PreferenceOptions(int *inspect, int *verbose, int *suppress_print, ...@@ -340,9 +346,35 @@ PyMac_PreferenceOptions(int *inspect, int *verbose, int *suppress_print,
if ( size > POPT_DEBUGGING ) *debugging = p[POPT_DEBUGGING]; if ( size > POPT_DEBUGGING ) *debugging = p[POPT_DEBUGGING];
if ( size > POPT_KEEPNORM ) *keep_normal = p[POPT_KEEPNORM]; if ( size > POPT_KEEPNORM ) *keep_normal = p[POPT_KEEPNORM];
if ( size > POPT_KEEPERR ) *keep_error = p[POPT_KEEPERR]; if ( size > POPT_KEEPERR ) *keep_error = p[POPT_KEEPERR];
/* The rest are not implemented yet */
HUnlock(handle); HUnlock(handle);
CloseResFile(prefrh); if ( prefrh != -1) CloseResFile(prefrh);
UseResFile(oldrh);
}
#ifdef USE_GUSI
void
PyMac_SetGUSIOptions()
{
Handle h;
short oldrh, prefrh = -1;
oldrh = CurResFile();
/* Try override from the application resource fork */
UseResFile(PyMac_AppRefNum);
h = Get1Resource('GU\267I', GUSIOPTIONSOVERRIDE_ID);
UseResFile(oldrh);
/* If that didn't work try nonoverride from anywhere */
if ( h == NULL ) {
prefrh = PyMac_OpenPrefFile();
h = GetResource('GU\267I', GUSIOPTIONS_ID);
}
if ( h ) GUSILoadConfiguration(h);
if ( prefrh != -1) CloseResFile(prefrh);
UseResFile(oldrh); UseResFile(oldrh);
} }
#endif /* USE_GUSI */
...@@ -52,6 +52,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ...@@ -52,6 +52,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
extern int Py_DebugFlag; /* For parser.c, declared in pythonrun.c */ extern int Py_DebugFlag; /* For parser.c, declared in pythonrun.c */
extern int Py_VerboseFlag; /* For import.c, declared in pythonrun.c */ extern int Py_VerboseFlag; /* For import.c, declared in pythonrun.c */
extern int Py_SuppressPrintingFlag; /* For ceval.c, declared in pythonrun.c */ extern int Py_SuppressPrintingFlag; /* For ceval.c, declared in pythonrun.c */
short PyMac_AppRefNum; /* RefNum of application resource fork */
/* Subroutines that live in their own file */ /* Subroutines that live in their own file */
...@@ -97,7 +98,9 @@ init_mac_world() ...@@ -97,7 +98,9 @@ init_mac_world()
static void static void
init_common() init_common()
{ {
/* Remember resource fork refnum, for later */
PyMac_AppRefNum = CurResFile();
/* Initialize toolboxes */ /* Initialize toolboxes */
init_mac_world(); init_mac_world();
...@@ -110,6 +113,7 @@ init_common() ...@@ -110,6 +113,7 @@ init_common()
/* Setup GUSI */ /* Setup GUSI */
GUSIDefaultSetup(); GUSIDefaultSetup();
PyMac_SetGUSISpin(); PyMac_SetGUSISpin();
PyMac_SetGUSIOptions();
#endif #endif
#ifdef USE_SIOUX #ifdef USE_SIOUX
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment