summaryrefslogtreecommitdiffstats
path: root/Mac/Python
diff options
context:
space:
mode:
authorJack Jansen <jack.jansen@cwi.nl>1996-04-04 15:39:18 (GMT)
committerJack Jansen <jack.jansen@cwi.nl>1996-04-04 15:39:18 (GMT)
commita486a55f59a0b45d8a0bc3ae38beae3a6e3b7bb5 (patch)
tree7e6836f50933e37553eb6e818c4fcd7414bed7fc /Mac/Python
parentdb0baced2309b358d706f5f027a2ecd2e581e609 (diff)
downloadcpython-a486a55f59a0b45d8a0bc3ae38beae3a6e3b7bb5.zip
cpython-a486a55f59a0b45d8a0bc3ae38beae3a6e3b7bb5.tar.gz
cpython-a486a55f59a0b45d8a0bc3ae38beae3a6e3b7bb5.tar.bz2
Added support for override preferences
Diffstat (limited to 'Mac/Python')
-rw-r--r--Mac/Python/macgetpath.c67
1 files changed, 54 insertions, 13 deletions
diff --git a/Mac/Python/macgetpath.c b/Mac/Python/macgetpath.c
index 38feb3e..4bdab5c 100644
--- a/Mac/Python/macgetpath.c
+++ b/Mac/Python/macgetpath.c
@@ -151,17 +151,25 @@ PyMac_GetPythonDir()
Boolean modified = 0;
short oldrh, prefrh;
+ oldrh = CurResFile();
/*
- ** Remember old resource file and try to open preferences file
- ** in the preferences folder.
+ ** First look for an override of the preferences file
*/
- oldrh = CurResFile();
- prefrh = PyMac_OpenPrefFile();
- /* So, we've opened our preferences file, we hope. Look for the alias */
- handle = (AliasHandle)Get1Resource('alis', PYTHONHOME_ID);
- if ( handle == NULL ) {
- (void)StopAlert(BADPREFFILE_ID, NULL);
- exit(1);
+ handle = (AliasHandle)GetResource('alis', PYTHONHOMEOVERRIDE_ID);
+ if ( handle != NULL ) {
+ prefrh = oldrh;
+ } else {
+ /*
+ ** Remember old resource file and try to open preferences file
+ ** in the preferences folder.
+ */
+ prefrh = PyMac_OpenPrefFile();
+ /* So, we've opened our preferences file, we hope. Look for the alias */
+ handle = (AliasHandle)Get1Resource('alis', PYTHONHOME_ID);
+ if ( handle == NULL ) {
+ (void)StopAlert(BADPREFFILE_ID, NULL);
+ exit(1);
+ }
}
/* It exists. Resolve it (possibly updating it) */
if ( ResolveAlias(NULL, handle, &dirspec, &modified) != noErr ) {
@@ -172,8 +180,10 @@ PyMac_GetPythonDir()
ChangedResource((Handle)handle);
UpdateResFile(prefrh);
}
- CloseResFile(prefrh);
- UseResFile(oldrh);
+ if ( prefrh != oldrh ) {
+ CloseResFile(prefrh);
+ UseResFile(oldrh);
+ }
if ( nfullpath(&dirspec, name) == 0 ) {
strcat(name, ":");
@@ -198,6 +208,8 @@ char *dir;
char *rv;
int i, newlen;
Str255 pathitem;
+ int resource_id;
+ OSErr err;
/*
** Remember old resource file and try to open preferences file
@@ -217,8 +229,16 @@ char *dir;
if( (rv = malloc(2)) == NULL )
goto out;
strcpy(rv, "\n");
+ /*
+ ** See whether there's an override.
+ */
+ GetIndString(pathitem, PYTHONPATHOVERRIDE_ID, 1);
+ if ( pathitem[0] )
+ resource_id = PYTHONPATHOVERRIDE_ID;
+ else
+ resource_id = PYTHONPATH_ID;
for(i=1; ; i++) {
- GetIndString(pathitem, PYTHONPATH_ID, i);
+ GetIndString(pathitem, resource_id, i);
if( pathitem[0] == 0 )
break;
if ( pathitem[0] >= 9 && strncmp((char *)pathitem+1, "$(PYTHON)", 9) == 0 ) {
@@ -236,6 +256,25 @@ char *dir;
}
rv[newlen-2] = '\n';
rv[newlen-1] = 0;
+ } else if ( pathitem[0] >= 14 && strncmp((char *)pathitem+1, "$(APPLICATION)", 14) == 0 ) {
+ /* This is the application itself */
+ char fullname[256];
+
+ if ( (err=PyMac_process_location(&dirspec)) != 0 ) {
+ printf("Cannot get FSSpec for application, error %d\n", err);
+ exit(1);
+ }
+ if ( nfullpath(&dirspec, fullname) != 0 ) {
+ printf("Cannot convert application fsspec to path\n");
+ exit(1);
+ }
+ newlen = strlen(rv) + strlen(fullname) + 2;
+ if( (rv=realloc(rv, newlen)) == NULL)
+ goto out;
+ strcpy(rv+strlen(rv), fullname);
+ rv[newlen-2] = '\n';
+ rv[newlen-1] = 0;
+
} else {
/* Use as-is */
newlen = strlen(rv) + (pathitem[0]) + 2;
@@ -276,7 +315,9 @@ PyMac_PreferenceOptions(int *inspect, int *verbose, int *suppress_print,
oldrh = CurResFile();
prefrh = PyMac_OpenPrefFile();
- handle = GetResource('Popt', PYTHONOPTIONS_ID);
+ handle = GetResource('Popt', PYTHONOPTIONSOVERRIDE_ID);
+ if ( handle == NULL )
+ handle = GetResource('Popt', PYTHONOPTIONS_ID);
if ( handle == NULL ) {
return;
}