mirror of
https://github.com/python/cpython.git
synced 2025-11-09 14:06:30 +00:00
Added PyMac_GetPythonDir routine which obtains python home directory
from an alias resource (or from the user). Note: this uses a dialog resource so there's an accompanying change in the resource file.
This commit is contained in:
parent
b3642579fd
commit
8cd2b720f6
2 changed files with 77 additions and 0 deletions
|
|
@ -42,6 +42,8 @@ void PyMac_HandleEvent Py_PROTO((EventRecord *)); /* Handle one event, if possib
|
||||||
|
|
||||||
int PyMac_Idle(void); /* Idle routine */
|
int PyMac_Idle(void); /* Idle routine */
|
||||||
|
|
||||||
|
char *PyMac_GetPythonDir(); /* Return the name of the python dir */
|
||||||
|
|
||||||
int PyMac_GetOSType(PyObject *, OSType *); /* argument parser for OSType */
|
int PyMac_GetOSType(PyObject *, OSType *); /* argument parser for OSType */
|
||||||
PyObject *PyMac_BuildOSType(OSType); /* Convert OSType to PyObject */
|
PyObject *PyMac_BuildOSType(OSType); /* Convert OSType to PyObject */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,8 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
|
||||||
#include <OSUtils.h> /* for Set(Current)A5 */
|
#include <OSUtils.h> /* for Set(Current)A5 */
|
||||||
#include <Files.h>
|
#include <Files.h>
|
||||||
|
#include <Aliases.h>
|
||||||
|
#include <StandardFile.h>
|
||||||
#include <Resources.h>
|
#include <Resources.h>
|
||||||
#include <Memory.h>
|
#include <Memory.h>
|
||||||
#include <Events.h>
|
#include <Events.h>
|
||||||
|
|
@ -40,6 +42,11 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
|
||||||
|
#define NOPYTHON_ALERT 128
|
||||||
|
#define YES_ITEM 1
|
||||||
|
#define NO_ITEM 2
|
||||||
|
#define CURWD_ITEM 3
|
||||||
|
|
||||||
#ifdef __MWERKS__
|
#ifdef __MWERKS__
|
||||||
/*
|
/*
|
||||||
** With MW we can pass the event off to the console window, so
|
** With MW we can pass the event off to the console window, so
|
||||||
|
|
@ -359,6 +366,74 @@ PyMac_Idle()
|
||||||
return intrpeek();
|
return intrpeek();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Return the name of the Python directory
|
||||||
|
*/
|
||||||
|
char *
|
||||||
|
PyMac_GetPythonDir()
|
||||||
|
{
|
||||||
|
int item;
|
||||||
|
static char name[256];
|
||||||
|
AliasHandle handle;
|
||||||
|
FSSpec dirspec;
|
||||||
|
int ok = 0, exists = 0;
|
||||||
|
Boolean modified = 0;
|
||||||
|
StandardFileReply sfreply;
|
||||||
|
|
||||||
|
handle = (AliasHandle)GetResource('alis', 128);
|
||||||
|
if ( handle ) {
|
||||||
|
if ( ResolveAlias(NULL, handle, &dirspec, &modified) == noErr )
|
||||||
|
ok = 1;
|
||||||
|
exists = 1;
|
||||||
|
}
|
||||||
|
if ( !ok ) {
|
||||||
|
item = Alert(NOPYTHON_ALERT, NULL);
|
||||||
|
if ( item == YES_ITEM ) {
|
||||||
|
StandardGetFile(NULL, 0, NULL, &sfreply);
|
||||||
|
if ( sfreply.sfGood ) {
|
||||||
|
if ( sfreply.sfIsFolder ) {
|
||||||
|
dirspec = sfreply.sfFile;
|
||||||
|
ok = 1;
|
||||||
|
modified = 1;
|
||||||
|
} else {
|
||||||
|
/* User selected a file. Use folder containing it */
|
||||||
|
if (FSMakeFSSpec(sfreply.sfFile.vRefNum,
|
||||||
|
sfreply.sfFile.parID, "\p", &dirspec) == 0) {
|
||||||
|
ok = 1;
|
||||||
|
modified = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if ( item == CURWD_ITEM ) {
|
||||||
|
if ( getwd(name) ) {
|
||||||
|
if ( FSMakeFSSpec(0, 0, Pstring(name), &dirspec) == 0 ) {
|
||||||
|
ok = 1;
|
||||||
|
modified = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( ok && modified ) {
|
||||||
|
if ( !exists ) {
|
||||||
|
if (NewAlias(NULL, &dirspec, &handle) == 0 )
|
||||||
|
AddResource((Handle)handle, 'alis', 128, "\p");
|
||||||
|
} else {
|
||||||
|
ChangedResource((Handle)handle);
|
||||||
|
}
|
||||||
|
UpdateResFile(CurResFile());
|
||||||
|
}
|
||||||
|
if ( ok ) {
|
||||||
|
ok = (nfullpath(&dirspec, name) == 0);
|
||||||
|
if ( ok ) strcat(name, ":");
|
||||||
|
}
|
||||||
|
if ( !ok ) {
|
||||||
|
/* If all fails, we return the current directory */
|
||||||
|
name[0] = 0;
|
||||||
|
(void)getwd(name);
|
||||||
|
}
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Convert a 4-char string object argument to an OSType value */
|
/* Convert a 4-char string object argument to an OSType value */
|
||||||
int
|
int
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue