Re-indented properly (Just).

This commit is contained in:
Jack Jansen 1998-07-31 09:33:28 +00:00
parent 5fdd119aba
commit abdf93c6dc

View file

@ -71,29 +71,29 @@ getpreffilefss(FSSpec *fssp)
static int diditbefore=0; static int diditbefore=0;
static int rv = 1; static int rv = 1;
static FSSpec fss; static FSSpec fss;
short prefdirRefNum; short prefdirRefNum;
long prefdirDirID; long prefdirDirID;
Handle namehandle; Handle namehandle;
if ( !diditbefore ) { if ( !diditbefore ) {
if ( FindFolder(kOnSystemDisk, 'pref', kDontCreateFolder, &prefdirRefNum, if ( FindFolder(kOnSystemDisk, 'pref', kDontCreateFolder, &prefdirRefNum,
&prefdirDirID) != noErr ) { &prefdirDirID) != noErr ) {
/* Something wrong with preferences folder */ /* Something wrong with preferences folder */
(void)StopAlert(NOPREFDIR_ID, NULL); (void)StopAlert(NOPREFDIR_ID, NULL);
exit(1); exit(1);
} }
if ( (namehandle=GetNamedResource('STR ', PREFFILENAME_NAME)) == NULL ) { if ( (namehandle=GetNamedResource('STR ', PREFFILENAME_NAME)) == NULL ) {
(void)StopAlert(NOPREFNAME_ID, NULL); (void)StopAlert(NOPREFNAME_ID, NULL);
exit(1); exit(1);
} }
HLock(namehandle); HLock(namehandle);
if ( **namehandle == '\0' ) { if ( **namehandle == '\0' ) {
/* Empty string means don't use preferences file */ /* Empty string means don't use preferences file */
rv = 0; rv = 0;
} else { } else {
/* There is a filename, construct the fsspec */ /* There is a filename, construct the fsspec */
(void)FSMakeFSSpec(prefdirRefNum, prefdirDirID, (unsigned char *)*namehandle, &fss); (void)FSMakeFSSpec(prefdirRefNum, prefdirDirID, (unsigned char *)*namehandle, &fss);
} }
HUnlock(namehandle); HUnlock(namehandle);
@ -165,10 +165,10 @@ Py_GetPath()
static short static short
PyMac_OpenPrefFile() PyMac_OpenPrefFile()
{ {
AliasHandle handle; AliasHandle handle;
FSSpec dirspec; FSSpec dirspec;
short prefrh; short prefrh;
OSErr err; OSErr err;
if ( !getpreffilefss(&dirspec)) if ( !getpreffilefss(&dirspec))
return -1; return -1;
@ -196,8 +196,8 @@ PyMac_OpenPrefFile()
printf("Cannot make alias to application directory, error %d\n", err); printf("Cannot make alias to application directory, error %d\n", err);
exit(1); exit(1);
} }
AddResource((Handle)handle, 'alis', PYTHONHOME_ID, "\p"); AddResource((Handle)handle, 'alis', PYTHONHOME_ID, "\p");
UpdateResFile(prefrh); UpdateResFile(prefrh);
} else { } else {
UseResFile(prefrh); UseResFile(prefrh);
@ -212,50 +212,50 @@ char *
PyMac_GetPythonDir() PyMac_GetPythonDir()
{ {
static int diditbefore = 0; static int diditbefore = 0;
static char name[256] = {':', '\0'}; static char name[256] = {':', '\0'};
AliasHandle handle; AliasHandle handle;
FSSpec dirspec; FSSpec dirspec;
Boolean modified = 0; Boolean modified = 0;
short oldrh, prefrh = -1, homerh; short oldrh, prefrh = -1, homerh;
if ( diditbefore ) if ( diditbefore )
return name; return name;
oldrh = CurResFile(); oldrh = CurResFile();
/* First look for an override in the application file */ /* First look for an override in the application file */
UseResFile(PyMac_AppRefNum); UseResFile(PyMac_AppRefNum);
handle = (AliasHandle)Get1Resource('alis', PYTHONHOMEOVERRIDE_ID); handle = (AliasHandle)Get1Resource('alis', PYTHONHOMEOVERRIDE_ID);
UseResFile(oldrh); UseResFile(oldrh);
if ( handle != NULL ) { if ( handle != NULL ) {
homerh = PyMac_AppRefNum; homerh = PyMac_AppRefNum;
} else { } else {
/* Try to open preferences file in the preferences folder. */ /* Try to open preferences file in the preferences folder. */
prefrh = PyMac_OpenPrefFile(); prefrh = PyMac_OpenPrefFile();
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); */
diditbefore=1; diditbefore=1;
return ":"; return ":";
} }
homerh = prefrh; 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 ) {
(void)StopAlert(BADPREFFILE_ID, NULL); (void)StopAlert(BADPREFFILE_ID, NULL);
diditbefore=1; diditbefore=1;
return ":"; return ":";
} }
if ( modified ) { if ( modified ) {
ChangedResource((Handle)handle); ChangedResource((Handle)handle);
UpdateResFile(homerh); UpdateResFile(homerh);
} }
if ( prefrh != -1 ) CloseResFile(prefrh); if ( prefrh != -1 ) CloseResFile(prefrh);
UseResFile(oldrh); UseResFile(oldrh);
if ( PyMac_GetFullPath(&dirspec, name) == 0 ) { if ( PyMac_GetFullPath(&dirspec, name) == 0 ) {
strcat(name, ":"); strcat(name, ":");
} else { } else {
/* If all fails, we return the current directory */ /* If all fails, we return the current directory */
printf("Python home dir exists but I cannot find the pathname!!\n"); printf("Python home dir exists but I cannot find the pathname!!\n");
name[0] = 0; name[0] = 0;
@ -269,88 +269,88 @@ PyMac_GetPythonDir()
char * char *
PyMac_GetPythonPath() PyMac_GetPythonPath()
{ {
short oldrh, prefrh = -1; short oldrh, prefrh = -1;
char *rv; char *rv;
int i, newlen; int i, newlen;
Str255 pathitem; Str255 pathitem;
int resource_id; int resource_id;
OSErr err; OSErr err;
Handle h; Handle h;
oldrh = CurResFile(); oldrh = CurResFile();
/* /*
** This is a bit tricky. We check here whether the application 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); UseResFile(PyMac_AppRefNum);
SetResLoad(0); SetResLoad(0);
if ( (h=Get1Resource('STR#', PYTHONPATHOVERRIDE_ID)) ) { if ( (h=Get1Resource('STR#', PYTHONPATHOVERRIDE_ID)) ) {
ReleaseResource(h); ReleaseResource(h);
resource_id = PYTHONPATHOVERRIDE_ID; resource_id = PYTHONPATHOVERRIDE_ID;
} else { } else {
resource_id = PYTHONPATH_ID; resource_id = PYTHONPATH_ID;
} }
SetResLoad(1); SetResLoad(1);
UseResFile(oldrh); UseResFile(oldrh);
/* Open the preferences file only if there is no override */ /* Open the preferences file only if there is no override */
if ( resource_id != PYTHONPATHOVERRIDE_ID ) if ( resource_id != PYTHONPATHOVERRIDE_ID )
prefrh = PyMac_OpenPrefFile(); prefrh = PyMac_OpenPrefFile();
/* At this point, we may or may not have the preferences file open, and it /* At this point, we may or may not have the preferences file open, and it
** may or may not contain a sys.path STR# resource. We don't care, if it doesn't ** may or may not contain a sys.path STR# resource. We don't care, if it doesn't
** exist we use the one from the application (the default). ** exist we use the one from the application (the default).
** We put an initial '\n' in front of the path that we don't return to the caller ** We put an initial '\n' in front of the path that we don't return to the caller
*/ */
if( (rv = malloc(2)) == NULL ) if( (rv = malloc(2)) == NULL )
goto out; goto out;
strcpy(rv, "\n"); strcpy(rv, "\n");
for(i=1; ; i++) { for(i=1; ; i++) {
GetIndString(pathitem, resource_id, i); GetIndString(pathitem, resource_id, i);
if( pathitem[0] == 0 ) if( pathitem[0] == 0 )
break; break;
if ( pathitem[0] >= 9 && strncmp((char *)pathitem+1, "$(PYTHON)", 9) == 0 ) { if ( pathitem[0] >= 9 && strncmp((char *)pathitem+1, "$(PYTHON)", 9) == 0 ) {
/* We have to put the directory in place */ /* We have to put the directory in place */
char *dir = PyMac_GetPythonDir(); char *dir = PyMac_GetPythonDir();
newlen = strlen(rv) + strlen(dir) + (pathitem[0]-9) + 2; newlen = strlen(rv) + strlen(dir) + (pathitem[0]-9) + 2;
if( (rv=realloc(rv, newlen)) == NULL) if( (rv=realloc(rv, newlen)) == NULL)
goto out; goto out;
strcat(rv, dir); strcat(rv, dir);
/* Skip a colon at the beginning of the item */ /* Skip a colon at the beginning of the item */
if ( pathitem[0] > 9 && pathitem[1+9] == ':' ) { if ( pathitem[0] > 9 && pathitem[1+9] == ':' ) {
memcpy(rv+strlen(rv), pathitem+1+10, pathitem[0]-10); memcpy(rv+strlen(rv), pathitem+1+10, pathitem[0]-10);
newlen--; newlen--;
} else { } else {
memcpy(rv+strlen(rv), pathitem+1+9, pathitem[0]-9); memcpy(rv+strlen(rv), pathitem+1+9, pathitem[0]-9);
} }
rv[newlen-2] = '\n'; rv[newlen-2] = '\n';
rv[newlen-1] = 0; rv[newlen-1] = 0;
} else if ( pathitem[0] >= 14 && strncmp((char *)pathitem+1, "$(APPLICATION)", 14) == 0 ) { } else if ( pathitem[0] >= 14 && strncmp((char *)pathitem+1, "$(APPLICATION)", 14) == 0 ) {
/* This is the application itself */ /* This is the application itself */
if ( (err=PyMac_init_process_location()) != 0 ) { if ( (err=PyMac_init_process_location()) != 0 ) {
printf("Cannot get application location, error %d\n", err); printf("Cannot get application location, error %d\n", err);
exit(1); exit(1);
} }
newlen = strlen(rv) + strlen(PyMac_ApplicationPath) + 2; newlen = strlen(rv) + strlen(PyMac_ApplicationPath) + 2;
if( (rv=realloc(rv, newlen)) == NULL) if( (rv=realloc(rv, newlen)) == NULL)
goto out; goto out;
strcpy(rv+strlen(rv), PyMac_ApplicationPath); strcpy(rv+strlen(rv), PyMac_ApplicationPath);
rv[newlen-2] = '\n'; rv[newlen-2] = '\n';
rv[newlen-1] = 0; rv[newlen-1] = 0;
} else { } else {
/* Use as-is */ /* Use as-is */
newlen = strlen(rv) + (pathitem[0]) + 2; newlen = strlen(rv) + (pathitem[0]) + 2;
if( (rv=realloc(rv, newlen)) == NULL) if( (rv=realloc(rv, newlen)) == NULL)
goto out; goto out;
memcpy(rv+strlen(rv), pathitem+1, pathitem[0]); memcpy(rv+strlen(rv), pathitem+1, pathitem[0]);
rv[newlen-2] = '\n'; rv[newlen-2] = '\n';
rv[newlen-1] = 0; rv[newlen-1] = 0;
} }
} }
if( strlen(rv) == 1) { if( strlen(rv) == 1) {
free(rv); free(rv);
@ -377,44 +377,44 @@ PyMac_PreferenceOptions(PyMac_PrefRecord *pr)
int action; int action;
oldrh = CurResFile(); oldrh = CurResFile();
/* Attempt to load overrides from application */ /* Attempt to load overrides from application */
UseResFile(PyMac_AppRefNum); UseResFile(PyMac_AppRefNum);
handle = Get1Resource('Popt', PYTHONOPTIONSOVERRIDE_ID); handle = Get1Resource('Popt', PYTHONOPTIONSOVERRIDE_ID);
UseResFile(oldrh); UseResFile(oldrh);
/* Otherwise get options from prefs file or any other open resource file */ /* Otherwise get options from prefs file or any other open resource file */
if ( handle == NULL ) { if ( handle == NULL ) {
prefrh = PyMac_OpenPrefFile(); prefrh = PyMac_OpenPrefFile();
handle = GetResource('Popt', PYTHONOPTIONS_ID); handle = GetResource('Popt', PYTHONOPTIONS_ID);
} }
if ( handle == NULL ) { if ( handle == NULL ) {
return; return;
} }
HLock(handle); HLock(handle);
size = GetHandleSize(handle); size = GetHandleSize(handle);
p = (PyMac_PrefRecord *)*handle; p = (PyMac_PrefRecord *)*handle;
if ( p->version == POPT_VERSION_CURRENT && size == sizeof(PyMac_PrefRecord) ) { if ( p->version == POPT_VERSION_CURRENT && size == sizeof(PyMac_PrefRecord) ) {
*pr = *p; *pr = *p;
} else { } else {
action = CautionAlert(BADPREFERENCES_ID, NULL); action = CautionAlert(BADPREFERENCES_ID, NULL);
if ( action == BADPREF_DELETE ) { if ( action == BADPREF_DELETE ) {
OSErr err; OSErr err;
RemoveResource(handle); RemoveResource(handle);
if ( (err=ResError()) ) printf("RemoveResource: %d\n", err); if ( (err=ResError()) ) printf("RemoveResource: %d\n", err);
if ( prefrh != -1 ) { if ( prefrh != -1 ) {
UpdateResFile(prefrh); UpdateResFile(prefrh);
if ( (err=ResError()) ) printf("UpdateResFile: %d\n", err); if ( (err=ResError()) ) printf("UpdateResFile: %d\n", err);
} }
} else if ( action == BADPREF_QUIT ) } else if ( action == BADPREF_QUIT )
exit(1); exit(1);
} }
HUnlock(handle); HUnlock(handle);
if ( prefrh != -1) CloseResFile(prefrh); if ( prefrh != -1) CloseResFile(prefrh);
UseResFile(oldrh); UseResFile(oldrh);
} }
#ifdef USE_GUSI #ifdef USE_GUSI
@ -438,6 +438,6 @@ PyMac_SetGUSIOptions()
} }
if ( h ) GUSILoadConfiguration(h); if ( h ) GUSILoadConfiguration(h);
if ( prefrh != -1) CloseResFile(prefrh); if ( prefrh != -1) CloseResFile(prefrh);
UseResFile(oldrh); UseResFile(oldrh);
} }
#endif /* USE_GUSI */ #endif /* USE_GUSI */