diff options
Diffstat (limited to 'Mac/Python')
-rw-r--r-- | Mac/Python/getapplbycreator.c | 163 | ||||
-rw-r--r-- | Mac/Python/gusiconfig.cpp | 137 | ||||
-rw-r--r-- | Mac/Python/macapplication.c | 83 | ||||
-rw-r--r-- | Mac/Python/macgetargv.c | 247 | ||||
-rw-r--r-- | Mac/Python/macgetcompiler.c | 61 | ||||
-rw-r--r-- | Mac/Python/macgetpath.c | 442 | ||||
-rw-r--r-- | Mac/Python/macgetplatform.c | 39 | ||||
-rw-r--r-- | Mac/Python/macglue.c | 617 | ||||
-rw-r--r-- | Mac/Python/macimport.c | 445 | ||||
-rw-r--r-- | Mac/Python/macmain.c | 640 | ||||
-rw-r--r-- | Mac/Python/macsetfiletype.c | 75 | ||||
-rw-r--r-- | Mac/Python/macshlglue.c | 128 | ||||
-rw-r--r-- | Mac/Python/pyGUSISIOUX.cp | 239 |
13 files changed, 0 insertions, 3316 deletions
diff --git a/Mac/Python/getapplbycreator.c b/Mac/Python/getapplbycreator.c deleted file mode 100644 index 8c0b00fd93..0000000000 --- a/Mac/Python/getapplbycreator.c +++ /dev/null @@ -1,163 +0,0 @@ -/*********************************************************** -Copyright 1991-1997 by Stichting Mathematisch Centrum, Amsterdam, -The Netherlands. - - All Rights Reserved - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation, and that the names of Stichting Mathematisch -Centrum or CWI or Corporation for National Research Initiatives or -CNRI not be used in advertising or publicity pertaining to -distribution of the software without specific, written prior -permission. - -While CWI is the initial source for this software, a modified version -is made available by the Corporation for National Research Initiatives -(CNRI) at the Internet address ftp://ftp.python.org. - -STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH -REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH -CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL -DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR -PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER -TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR -PERFORMANCE OF THIS SOFTWARE. - -******************************************************************/ - -/* -** FindApplicationFromCreator uses the Desktop Database to -** locate the creator application for the given document -** -** this routine will check the desktop database of all local -** disks, then the desktop databases of all server volumes -** (so up to two passes will be made) -** -** This code was created from FindApplicationFromDocument -** routine, origin unknown. -*/ - -#ifdef WITHOUT_FRAMEWORKS -#include <Types.h> -#include <Files.h> -#include <Errors.h> -#else -#include <Carbon/Carbon.h> -#endif -#include "getapplbycreator.h" - - -OSErr FindApplicationFromCreator(OSType creator, - FSSpecPtr applicationFSSpecPtr) -{ - enum { localPass, remotePass, donePass } volumePass; - DTPBRec desktopParams; - HParamBlockRec hfsParams; - short volumeIndex; - Boolean foundFlag; - GetVolParmsInfoBuffer volumeInfoBuffer; - OSErr retCode; - -/* dkj 12/94 initialize flag to false (thanks to Peter Baral for pointing out this bug) */ - foundFlag = false; - - volumePass = localPass; - volumeIndex = 0; - - do { - /* - ** first, find the vRefNum of the volume whose Desktop Database - ** we're checking this time - */ - - volumeIndex++; - - /* convert the volumeIndex into a vRefNum */ - - hfsParams.volumeParam.ioNamePtr = nil; - hfsParams.volumeParam.ioVRefNum = 0; - hfsParams.volumeParam.ioVolIndex = volumeIndex; - retCode = PBHGetVInfoSync(&hfsParams); - - /* a nsvErr indicates that the current pass is over */ - if (retCode == nsvErr) goto SkipThisVolume; - if (retCode != noErr) goto Bail; - - /* - ** call GetVolParms to determine if this volume is a server - ** (a remote volume) - */ - - hfsParams.ioParam.ioBuffer = (Ptr) &volumeInfoBuffer; - hfsParams.ioParam.ioReqCount = sizeof(GetVolParmsInfoBuffer); - retCode = PBHGetVolParmsSync(&hfsParams); - if (retCode != noErr) goto Bail; - - /* - ** if the vMServerAdr field of the volume information buffer - ** is zero, this is a local volume; skip this volume - ** if it's local on a remote pass or remote on a local pass - */ - - if ((volumeInfoBuffer.vMServerAdr != 0) != - (volumePass == remotePass)) goto SkipThisVolume; - - /* okay, now we've found the vRefNum for our desktop database call */ - - desktopParams.ioVRefNum = hfsParams.volumeParam.ioVRefNum; - - /* - ** find the path refNum for the desktop database for - ** the volume we're interested in - */ - - desktopParams.ioNamePtr = nil; - - retCode = PBDTGetPath(&desktopParams); - if (retCode == noErr && desktopParams.ioDTRefNum != 0) { - - /* - ** use the GetAPPL call to find the preferred application - ** for opening any document with this one's creator - */ - - desktopParams.ioIndex = 0; - desktopParams.ioFileCreator = creator; - desktopParams.ioNamePtr = applicationFSSpecPtr->name; - retCode = PBDTGetAPPLSync(&desktopParams); - - if (retCode == noErr) { - /* - ** okay, found it; fill in the application file spec - ** and set the flag indicating we're done - */ - - applicationFSSpecPtr->parID = desktopParams.ioAPPLParID; - applicationFSSpecPtr->vRefNum = desktopParams.ioVRefNum; - foundFlag = true; - - } - } - - SkipThisVolume: - /* - ** if retCode indicates a no such volume error or if this - ** was the first pass, it's time to move on to the next pass - */ - - if (retCode == nsvErr) { - volumePass++; - volumeIndex = 0; - } - - } while (foundFlag == false && volumePass != donePass); - -Bail: - if (retCode == nsvErr) - return fnfErr; /* More logical than "No such volume" */ - return retCode; -} diff --git a/Mac/Python/gusiconfig.cpp b/Mac/Python/gusiconfig.cpp deleted file mode 100644 index ec6b57d578..0000000000 --- a/Mac/Python/gusiconfig.cpp +++ /dev/null @@ -1,137 +0,0 @@ -/* - * Generated with the GUSIConfig application and then hand-modified by jack. - */ - -#define GUSI_SOURCE -#include <GUSIConfig.h> -#include <sys/cdefs.h> -#include <Resources.h> - -#include "Python.h" -#include "macglue.h" -#include "pythonresources.h" - -static void -PyMac_GUSISpin(bool wait) -{ - static Boolean inForeground = true; - int maxsleep = 6; /* 6 ticks is "normal" sleeptime */ - - if (PyMac_ConsoleIsDead) return; - - if ( !wait ) - maxsleep = 0; - - PyMac_DoYield(maxsleep, 0); /* XXXX or is it safe to call python here? */ -} - - -/* Declarations of Socket Factories */ - -__BEGIN_DECLS -void GUSIwithInetSockets(); -void GUSIwithLocalSockets(); -void GUSIwithMTInetSockets(); -void GUSIwithMTTcpSockets(); -void GUSIwithMTUdpSockets(); -void GUSIwithOTInetSockets(); -void GUSIwithOTTcpSockets(); -void GUSIwithOTUdpSockets(); -void GUSIwithPPCSockets(); -void GUSISetupFactories(); -__END_DECLS - -/* Configure Socket Factories */ - -void GUSISetupFactories() -{ -#ifdef GUSISetupFactories_BeginHook - GUSISetupFactories_BeginHook -#endif - GUSIwithInetSockets(); -#ifdef GUSISetupFactories_EndHook - GUSISetupFactories_EndHook -#endif -} - -/* Declarations of File Devices */ - -__BEGIN_DECLS -void GUSIwithDConSockets(); -void GUSIwithNullSockets(); -void GUSISetupDevices(); -__END_DECLS - -/* Configure File Devices */ - -void GUSISetupDevices() -{ -#ifdef GUSISetupDevices_BeginHook - GUSISetupDevices_BeginHook -#endif -#ifdef GUSISetupDevices_EndHook - GUSISetupDevices_EndHook -#endif -} - -#ifndef __cplusplus -#error GUSISetupConfig() needs to be written in C++ -#endif - -GUSIConfiguration::FileSuffix sSuffices[] = { - "", '????', '????' -}; -extern "C" void GUSISetupConfig() -{ - Handle h; - short oldrh, prefrh = -1; - short resource_id = GUSIConfiguration::kNoResource; - - oldrh = CurResFile(); - - /* Try override from the application resource fork */ - UseResFile(PyMac_AppRefNum); - h = Get1Resource('GU\267I', GUSIOPTIONSOVERRIDE_ID); - if ( h ) { - resource_id = GUSIOPTIONSOVERRIDE_ID; - } else { - /* Next try normal resource from preference file */ - UseResFile(oldrh); - prefrh = PyMac_OpenPrefFile(); - h = Get1Resource('GU\267I', GUSIOPTIONS_ID); - if ( h ) { - resource_id = GUSIOPTIONS_ID; - } else { - /* Finally try normal resource from application */ - if ( prefrh != -1 ) { - CloseResFile(prefrh); - prefrh = -1; - } - resource_id = GUSIOPTIONS_ID; - } - } - - /* Now we have the right resource file topmost and the id. Init GUSI. */ - GUSIConfiguration * config = - GUSIConfiguration::CreateInstance(resource_id); - - /* Finally restore the old resource file */ - if ( prefrh != -1) CloseResFile(prefrh); - UseResFile(oldrh); - - config->ConfigureDefaultTypeCreator('TEXT', 'R*ch'); -#if 0 - config->ConfigureSuffices( - sizeof(sSuffices)/sizeof(GUSIConfiguration::FileSuffix)-1, sSuffices); -#endif - config->ConfigureAutoInitGraf(false); - config->ConfigureAutoSpin(false); - config->ConfigureHandleAppleEvents(false); - config->ConfigureSigInt(false); - config->ConfigureSigPipe(true); - - GUSISetHook(GUSI_SpinHook, (GUSIHook)PyMac_GUSISpin); - -} - -/**************** END GUSI CONFIGURATION *************************/ diff --git a/Mac/Python/macapplication.c b/Mac/Python/macapplication.c deleted file mode 100644 index 4c71234637..0000000000 --- a/Mac/Python/macapplication.c +++ /dev/null @@ -1,83 +0,0 @@ -/*********************************************************** -Copyright 1991-1997 by Stichting Mathematisch Centrum, Amsterdam, -The Netherlands. - - All Rights Reserved - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation, and that the names of Stichting Mathematisch -Centrum or CWI not be used in advertising or publicity pertaining to -distribution of the software without specific, written prior permission. - -STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO -THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND -FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE -FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT -OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - -******************************************************************/ - -/* Macintosh Python main program for both applets and interpreter */ - -#include <Resources.h> -#include <CodeFragments.h> - -extern void PyMac_InitApplication(void); -#ifdef USE_MAC_APPLET_SUPPORT -extern void PyMac_InitApplet(void); -#endif /* USE_MAC_APPLET_SUPPORT */ - -/* From the MSL runtime: */ -extern void __initialize(void); - -/* -** Alternative initialization entry point for some very special cases. -** Use this in stead of __initialize in the PEF settings to remember (and -** re-open as resource file) the application. This is needed if we link against -** a dynamic library that, in its own __initialize routine, opens a resource -** file. This would mess up our finding of override preferences. -** Only set this entrypoint in your apps if you notice sys.path or some such is -** messed up. -*/ -static int application_fss_valid; -static FSSpec application_fss; - -OSErr pascal -__initialize_remember_app_fsspec(CFragInitBlockPtr data) -{ - /* Call the MW runtime's initialization routine */ - __initialize(); - if ( data == nil ) return noErr; - if ( data->fragLocator.where == kDataForkCFragLocator ) { - application_fss = *data->fragLocator.u.onDisk.fileSpec; - application_fss_valid = 1; - } else if ( data->fragLocator.where == kResourceCFragLocator ) { - application_fss = *data->fragLocator.u.inSegs.fileSpec; - application_fss_valid = 1; - } - return noErr; -} - -void -main() { - if ( application_fss_valid ) - (void)FSpOpenResFile(&application_fss, fsRdPerm); -#ifdef USE_MAC_APPLET_SUPPORT - { - Handle mainpyc; - - mainpyc = Get1NamedResource('PYC ', "\p__main__"); - if (mainpyc != NULL) - PyMac_InitApplet(); - else - PyMac_InitApplication(); - } -#else - PyMac_InitApplication(); -#endif /* USE_MAC_APPLET_SUPPORT */ -} diff --git a/Mac/Python/macgetargv.c b/Mac/Python/macgetargv.c deleted file mode 100644 index f301bab074..0000000000 --- a/Mac/Python/macgetargv.c +++ /dev/null @@ -1,247 +0,0 @@ -/*********************************************************** -Copyright 1991-1997 by Stichting Mathematisch Centrum, Amsterdam, -The Netherlands. - - All Rights Reserved - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation, and that the names of Stichting Mathematisch -Centrum or CWI not be used in advertising or publicity pertaining to -distribution of the software without specific, written prior permission. - -STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO -THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND -FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE -FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT -OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - -******************************************************************/ - -/* Construct argc and argv for main() by using Apple Events */ -/* From Jack's implementation for STDWIN */ - -#include <stdlib.h> - -#ifdef WITHOUT_FRAMEWORKS -#include <Types.h> -#include <Files.h> -#include <Events.h> -#include <Memory.h> -#include <Processes.h> -#include <Errors.h> -#include <AppleEvents.h> -#include <AEObjects.h> -#include <Fonts.h> -#include <TextEdit.h> -#include <Menus.h> -#include <Dialogs.h> -#include <Windows.h> -#else -#include <Carbon/Carbon.h> -#endif /* WITHOUT_FRAMEWORKS */ - -typedef long refcontype; - -#include "Python.h" -#include "macglue.h" - -#define PATHNAMELEN 256 - -static int arg_count; -static char *arg_vector[256]; -FSSpec PyMac_ApplicationFSSpec; -char PyMac_ApplicationPath[PATHNAMELEN]; - -/* Duplicate a string to the heap. We also export this since it isn't standard -** and others use it -*/ -#ifndef HAVE_STRDUP -char * -strdup(const char *src) -{ - char *dst = malloc(strlen(src) + 1); - if (dst) - strcpy(dst, src); - return dst; -} -#endif - -/* Initialize FSSpec and full name of current application */ - -OSErr -PyMac_init_process_location(void) -{ - ProcessSerialNumber currentPSN; - ProcessInfoRec info; - OSErr err; - static int applocation_inited; - - if ( applocation_inited ) return 0; - currentPSN.highLongOfPSN = 0; - currentPSN.lowLongOfPSN = kCurrentProcess; - info.processInfoLength = sizeof(ProcessInfoRec); - info.processName = NULL; - info.processAppSpec = &PyMac_ApplicationFSSpec; - if ( err=GetProcessInformation(¤tPSN, &info)) - return err; - if ( err=PyMac_GetFullPathname(&PyMac_ApplicationFSSpec, PyMac_ApplicationPath, PATHNAMELEN) ) - return err; - applocation_inited = 1; - return 0; -} - -/* Check that there aren't any args remaining in the event */ - -static OSErr -get_missing_params(const AppleEvent *theAppleEvent) -{ - DescType theType; - Size actualSize; - OSErr err; - - err = AEGetAttributePtr(theAppleEvent, keyMissedKeywordAttr, typeWildCard, - &theType, nil, 0, &actualSize); - if (err == errAEDescNotFound) - return noErr; - else - return errAEEventNotHandled; -} - -static int got_one; /* Flag that we can stop getting events */ - -/* Handle the Print or Quit events (by failing) */ - -static pascal OSErr -handle_not(const AppleEvent *theAppleEvent, AppleEvent *reply, refcontype refCon) -{ - #pragma unused (reply, refCon) - got_one = 1; - return errAEEventNotHandled; -} - -/* Handle the Open Application event (by ignoring it) */ - -static pascal OSErr -handle_open_app(const AppleEvent *theAppleEvent, AppleEvent *reply, refcontype refCon) -{ - #pragma unused (reply, refCon) -#if 0 - /* Test by Jack: would removing this facilitate debugging? */ - got_one = 1; -#endif - return get_missing_params(theAppleEvent); -} - -/* Handle the Open Document event, by adding an argument */ - -static pascal OSErr -handle_open_doc(const AppleEvent *theAppleEvent, AppleEvent *reply, refcontype refCon) -{ - #pragma unused (reply, refCon) - OSErr err; - AEDescList doclist; - AEKeyword keywd; - DescType rttype; - long i, ndocs, size; - FSSpec fss; - char path[PATHNAMELEN]; - - got_one = 1; - if ((err = AEGetParamDesc(theAppleEvent, - keyDirectObject, typeAEList, &doclist))) - return err; - if ((err = get_missing_params(theAppleEvent))) - return err; - if ((err = AECountItems(&doclist, &ndocs))) - return err; - for(i = 1; i <= ndocs; i++) { - err = AEGetNthPtr(&doclist, i, typeFSS, - &keywd, &rttype, &fss, sizeof(fss), &size); - if (err) - break; - PyMac_GetFullPathname(&fss, path, PATHNAMELEN); - arg_vector[arg_count++] = strdup(path); - } - return err; -} - -/* Install standard core event handlers */ -AEEventHandlerUPP open_doc_upp; -AEEventHandlerUPP open_app_upp; -AEEventHandlerUPP not_upp; - -static void -set_ae_handlers(void) -{ - open_doc_upp = NewAEEventHandlerUPP(&handle_open_doc); - open_app_upp = NewAEEventHandlerUPP(&handle_open_app); - not_upp = NewAEEventHandlerUPP(&handle_not); - - AEInstallEventHandler(kCoreEventClass, kAEOpenApplication, - open_app_upp, 0L, false); - AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments, - open_doc_upp, 0L, false); - AEInstallEventHandler(kCoreEventClass, kAEPrintDocuments, - not_upp, 0L, false); - AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, - not_upp, 0L, false); -} - -/* Uninstall standard core event handlers */ - -static void -reset_ae_handlers(void) -{ - AERemoveEventHandler(kCoreEventClass, kAEOpenApplication, - open_app_upp, false); - AERemoveEventHandler(kCoreEventClass, kAEOpenDocuments, - open_doc_upp, false); - AERemoveEventHandler(kCoreEventClass, kAEPrintDocuments, - not_upp, false); - AERemoveEventHandler(kCoreEventClass, kAEQuitApplication, - not_upp, false); -} - -/* Wait for events until a core event has been handled */ - -static void -event_loop(void) -{ - EventRecord event; - int n; - int ok; - - got_one = 0; - for (n = 0; n < 100 && !got_one; n++) { - ok = GetNextEvent(everyEvent, &event); - if (ok && event.what == kHighLevelEvent) { - AEProcessAppleEvent(&event); - } - } -} - -/* Get the argv vector, return argc */ - -int -PyMac_GetArgv(char ***pargv, int noevents) -{ - arg_count = 0; - (void)PyMac_init_process_location(); - arg_vector[arg_count++] = strdup(PyMac_ApplicationPath); - - if( !noevents ) { - set_ae_handlers(); - event_loop(); - reset_ae_handlers(); - } - - arg_vector[arg_count] = NULL; - - *pargv = arg_vector; - return arg_count; -} diff --git a/Mac/Python/macgetcompiler.c b/Mac/Python/macgetcompiler.c deleted file mode 100644 index b5da2bf6dc..0000000000 --- a/Mac/Python/macgetcompiler.c +++ /dev/null @@ -1,61 +0,0 @@ -/*********************************************************** -Copyright 1991-1997 by Stichting Mathematisch Centrum, Amsterdam, -The Netherlands. - - All Rights Reserved - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation, and that the names of Stichting Mathematisch -Centrum or CWI or Corporation for National Research Initiatives or -CNRI not be used in advertising or publicity pertaining to -distribution of the software without specific, written prior -permission. - -While CWI is the initial source for this software, a modified version -is made available by the Corporation for National Research Initiatives -(CNRI) at the Internet address ftp://ftp.python.org. - -STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH -REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH -CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL -DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR -PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER -TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR -PERFORMANCE OF THIS SOFTWARE. - -******************************************************************/ - -/* Return a string representing the compiler name */ - -#include "pyconfig.h" -#include "Python.h" - -#ifdef __MWERKS__ -#ifdef USE_GUSI2 -#define HASGUSI "" -#else -#define HASGUSI " WITHOUT_GUSI2" -#endif - -#ifdef WITH_THREAD -#define HASTHREAD "" -#else -#define HASTHREAD " WITHOUT_THREAD" -#endif - -#define COMPILER " [CW" HASGUSI HASTHREAD"]" -#endif - -#ifdef MPW -#define COMPILER " [Apple MPW]" -#endif - -const char * -Py_GetCompiler(void) -{ - return COMPILER; -} diff --git a/Mac/Python/macgetpath.c b/Mac/Python/macgetpath.c deleted file mode 100644 index d98d481206..0000000000 --- a/Mac/Python/macgetpath.c +++ /dev/null @@ -1,442 +0,0 @@ -/*********************************************************** -Copyright 1991-1997 by Stichting Mathematisch Centrum, Amsterdam, -The Netherlands. - - All Rights Reserved - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation, and that the names of Stichting Mathematisch -Centrum or CWI or Corporation for National Research Initiatives or -CNRI not be used in advertising or publicity pertaining to -distribution of the software without specific, written prior -permission. - -While CWI is the initial source for this software, a modified version -is made available by the Corporation for National Research Initiatives -(CNRI) at the Internet address ftp://ftp.python.org. - -STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH -REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH -CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL -DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR -PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER -TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR -PERFORMANCE OF THIS SOFTWARE. - -******************************************************************/ - -#include "Python.h" -#include "osdefs.h" -#include "macglue.h" -#include "macdefs.h" -#include "pythonresources.h" -#ifdef HAVE_UNISTD_H -#include <unistd.h> -#endif - -#define PATHNAMELEN 256 - -/* Return the initial python search path. This is called once from -** initsys() to initialize sys.path. -** -** If USE_BUILTIN_PATH is defined the path defined here is used -** (after prepending the python home dir to each item). -** If it is not defined the path is gotten from a resource in the -** Preferences file. -** -** XXXX This code needs cleaning up. The routines here have moved -** around quite a bit, and they're pretty messy for that reason. -*/ - -#include <Files.h> -#include <Aliases.h> -#include <Folders.h> -#include <Resources.h> -#include <TextUtils.h> -#include <Dialogs.h> - -#ifndef USE_BUILTIN_PATH -static char *PyMac_GetPythonPath(); -#endif - -#define PYTHONPATH "\ -:\n\ -:Lib\n\ -:Lib:stdwin\n\ -:Lib:test\n\ -:Lib:mac" - -static int -getpreffilefss(FSSpec *fssp) -{ - static int diditbefore=0; - static int rv = 1; - static FSSpec fss; - short prefdirRefNum; - long prefdirDirID; - long pyprefdirDirID; - Handle namehandle; - OSErr err; - - if ( !diditbefore ) { - if ( (namehandle=GetNamedResource('STR ', PREFFILENAME_NAME)) == NULL ) { - (void)StopAlert(NOPREFNAME_ID, NULL); - exit(1); - } - - if ( **namehandle == '\0' ) { - /* Empty string means don't use preferences file */ - rv = 0; - } else { - /* There is a filename, construct the fsspec */ - if ( FindFolder(kOnSystemDisk, 'pref', kDontCreateFolder, &prefdirRefNum, - &prefdirDirID) != noErr ) { - /* Something wrong with preferences folder */ - (void)StopAlert(NOPREFDIR_ID, NULL); - exit(1); - } - /* make fsspec for the "Python" folder inside the prefs folder */ - err = FSMakeFSSpec(prefdirRefNum, prefdirDirID, "\pPython", &fss); - if (err == fnfErr) { - /* it doesn't exist: create it */ - err = FSpDirCreate(&fss, smSystemScript, &pyprefdirDirID); - } else { - /* it does exist, now find out the dirID of the Python prefs folder, brrr. */ - CInfoPBRec info; - info.dirInfo.ioVRefNum = fss.vRefNum; - info.dirInfo.ioDrDirID = fss.parID; - info.dirInfo.ioNamePtr = fss.name; - info.dirInfo.ioFDirIndex = 0; - info.dirInfo.ioACUser = 0; - err = PBGetCatInfo(&info, 0); - if (err == noErr) { - pyprefdirDirID = info.dirInfo.ioDrDirID; - } - } - if (err != noErr) { - (void)StopAlert(NOPREFDIR_ID, NULL); - exit(1); - } - HLock(namehandle); - err = FSMakeFSSpec(fss.vRefNum, pyprefdirDirID, (unsigned char *)*namehandle, &fss); - HUnlock(namehandle); - if (err != noErr && err != fnfErr) { - (void)StopAlert(NOPREFDIR_ID, NULL); - exit(1); - } - } - ReleaseResource(namehandle); - diditbefore = 1; - } - *fssp = fss; - return rv; -} - -char * -Py_GetPath() -{ - /* Modified by Jack to do something a bit more sensible: - ** - Prepend the python home-directory (which is obtained from a Preferences - ** resource) - ** - Add : - */ - static char *pythonpath; - char *p, *endp; - int newlen; - char *curwd; - - if ( pythonpath ) return pythonpath; -#ifndef USE_BUILTIN_PATH - if ( pythonpath = PyMac_GetPythonPath() ) - return pythonpath; - printf("Warning: No pythonpath resource found, using builtin default\n"); -#endif - curwd = PyMac_GetPythonDir(); - p = PYTHONPATH; - endp = p; - pythonpath = malloc(2); - if ( pythonpath == NULL ) return PYTHONPATH; - strcpy(pythonpath, ":"); - while (*endp) { - endp = strchr(p, '\n'); - if ( endp == NULL ) - endp = p + strlen(p); - newlen = strlen(pythonpath) + 1 + strlen(curwd) + (endp-p); - pythonpath = realloc(pythonpath, newlen+1); - if ( pythonpath == NULL ) return PYTHONPATH; - strcat(pythonpath, "\n"); - if ( *p == ':' ) { - p++; - strcat(pythonpath, curwd); - strncat(pythonpath, p, (endp-p)); - newlen--; /* Ok, ok, we've allocated one byte too much */ - } else { - /* We've allocated too much in this case */ - newlen -= strlen(curwd); - pythonpath = realloc(pythonpath, newlen+1); - if ( pythonpath == NULL ) return PYTHONPATH; - strncat(pythonpath, p, (endp-p)); - } - pythonpath[newlen] = '\0'; - p = endp + 1; - } - return pythonpath; -} - - -/* -** Open/create the Python Preferences file, return the handle -*/ -short -PyMac_OpenPrefFile() -{ - AliasHandle handle; - FSSpec dirspec; - short prefrh; - OSErr err; - - if ( !getpreffilefss(&dirspec)) - return -1; - prefrh = FSpOpenResFile(&dirspec, fsRdWrShPerm); - if ( prefrh < 0 ) { - FSpCreateResFile(&dirspec, 'Pyth', 'pref', 0); - prefrh = FSpOpenResFile(&dirspec, fsRdWrShPerm); - if ( prefrh == -1 ) { - /* This "cannot happen":-) */ - printf("Cannot create preferences file, error %d\n", ResError()); - exit(1); - } - if ( (err=PyMac_init_process_location()) != 0 ) { - printf("Cannot get application location, error %d\n", err); - exit(1); - } - dirspec = PyMac_ApplicationFSSpec; - dirspec.name[0] = 0; - if ((err=NewAlias(NULL, &dirspec, &handle)) != 0 ) { - printf("Cannot make alias to application directory, error %d\n", err); - exit(1); - } - AddResource((Handle)handle, 'alis', PYTHONHOME_ID, "\p"); - UpdateResFile(prefrh); - - } else { - UseResFile(prefrh); - } - return prefrh; -} - -/* -** Return the name of the Python directory -*/ -char * -PyMac_GetPythonDir() -{ - static int diditbefore = 0; - static char name[PATHNAMELEN] = {':', '\0'}; - AliasHandle handle; - FSSpec dirspec; - Boolean modified = 0; - short oldrh, prefrh = -1, homerh; - - if ( diditbefore ) - return name; - - oldrh = CurResFile(); - - /* First look for an override in the application file */ - UseResFile(PyMac_AppRefNum); - handle = (AliasHandle)Get1Resource('alis', PYTHONHOMEOVERRIDE_ID); - UseResFile(oldrh); - if ( handle != NULL ) { - homerh = PyMac_AppRefNum; - } else { - /* Try to open preferences file in the preferences folder. */ - prefrh = PyMac_OpenPrefFile(); - handle = (AliasHandle)Get1Resource('alis', PYTHONHOME_ID); - if ( handle == NULL ) { - /* (void)StopAlert(BADPREFFILE_ID, NULL); */ - diditbefore=1; - return ":"; - } - homerh = prefrh; - } - /* It exists. Resolve it (possibly updating it) */ - if ( ResolveAlias(NULL, handle, &dirspec, &modified) != noErr ) { - (void)StopAlert(BADPREFFILE_ID, NULL); - diditbefore=1; - return ":"; - } - if ( modified ) { - ChangedResource((Handle)handle); - UpdateResFile(homerh); - } - if ( prefrh != -1 ) CloseResFile(prefrh); - UseResFile(oldrh); - - if ( PyMac_GetFullPathname(&dirspec, name, PATHNAMELEN) == 0 ) { - strcat(name, ":"); - } else { - /* If all fails, we return the current directory */ - printf("Python home dir exists but I cannot find the pathname!!\n"); - name[0] = 0; - (void)getcwd(name, sizeof(name)); - } - diditbefore = 1; - return name; -} - -#ifndef USE_BUILTIN_PATH -char * -PyMac_GetPythonPath(void) -{ - short oldrh, prefrh = -1; - char *rv; - int i, newlen; - Str255 pathitem; - int resource_id; - OSErr err; - Handle h; - - oldrh = CurResFile(); - /* - ** This is a bit tricky. We check here whether the application file - ** contains an override. This is to forestall us finding another STR# resource - ** with "our" id and using that for path initialization - */ - UseResFile(PyMac_AppRefNum); - SetResLoad(0); - if ( (h=Get1Resource('STR#', PYTHONPATHOVERRIDE_ID)) ) { - ReleaseResource(h); - resource_id = PYTHONPATHOVERRIDE_ID; - } else { - resource_id = PYTHONPATH_ID; - } - SetResLoad(1); - UseResFile(oldrh); - - /* Open the preferences file only if there is no override */ - if ( resource_id != PYTHONPATHOVERRIDE_ID ) - prefrh = PyMac_OpenPrefFile(); - /* 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 - ** 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 - */ - if( (rv = malloc(2)) == NULL ) - goto out; - strcpy(rv, "\n"); - - for(i=1; ; i++) { - GetIndString(pathitem, resource_id, i); - if( pathitem[0] == 0 ) - break; - if ( pathitem[0] >= 9 && strncmp((char *)pathitem+1, "$(PYTHON)", 9) == 0 ) { - /* We have to put the directory in place */ - char *dir = PyMac_GetPythonDir(); - - newlen = strlen(rv) + strlen(dir) + (pathitem[0]-9) + 2; - if( (rv=realloc(rv, newlen)) == NULL) - goto out; - strcat(rv, dir); - /* Skip a colon at the beginning of the item */ - if ( pathitem[0] > 9 && pathitem[1+9] == ':' ) { - memcpy(rv+strlen(rv), pathitem+1+10, pathitem[0]-10); - newlen--; - } else { - memcpy(rv+strlen(rv), pathitem+1+9, pathitem[0]-9); - } - 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 */ - - if ( (err=PyMac_init_process_location()) != 0 ) { - printf("Cannot get application location, error %d\n", err); - exit(1); - } - - newlen = strlen(rv) + strlen(PyMac_ApplicationPath) + 2; - if( (rv=realloc(rv, newlen)) == NULL) - goto out; - strcpy(rv+strlen(rv), PyMac_ApplicationPath); - rv[newlen-2] = '\n'; - rv[newlen-1] = 0; - - } else { - /* Use as-is */ - newlen = strlen(rv) + (pathitem[0]) + 2; - if( (rv=realloc(rv, newlen)) == NULL) - goto out; - memcpy(rv+strlen(rv), pathitem+1, pathitem[0]); - rv[newlen-2] = '\n'; - rv[newlen-1] = 0; - } - } - if( strlen(rv) == 1) { - free(rv); - rv = NULL; - } - if ( rv ) { - rv[strlen(rv)-1] = 0; - rv++; - } -out: - if ( prefrh != -1) CloseResFile(prefrh); - UseResFile(oldrh); - return rv; -} -#endif /* !USE_BUILTIN_PATH */ - -void -PyMac_PreferenceOptions(PyMac_PrefRecord *pr) -{ - short oldrh, prefrh = -1; - Handle handle; - int size; - PyMac_PrefRecord *p; - int action; - - - oldrh = CurResFile(); - - /* Attempt to load overrides from application */ - 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); - } - if ( handle == NULL ) { - return; - } - HLock(handle); - size = GetHandleSize(handle); - p = (PyMac_PrefRecord *)*handle; - if ( p->version == POPT_VERSION_CURRENT && size == sizeof(PyMac_PrefRecord) ) { - *pr = *p; - } else { - action = CautionAlert(BADPREFERENCES_ID, NULL); - if ( action == BADPREF_DELETE ) { - OSErr err; - - RemoveResource(handle); - if ( (err=ResError()) ) printf("RemoveResource: %d\n", err); - if ( prefrh != -1 ) { - UpdateResFile(prefrh); - if ( (err=ResError()) ) printf("UpdateResFile: %d\n", err); - } - } else if ( action == BADPREF_QUIT ) - exit(1); - } - HUnlock(handle); - - if ( prefrh != -1) CloseResFile(prefrh); - UseResFile(oldrh); -} diff --git a/Mac/Python/macgetplatform.c b/Mac/Python/macgetplatform.c deleted file mode 100644 index 3640d760ee..0000000000 --- a/Mac/Python/macgetplatform.c +++ /dev/null @@ -1,39 +0,0 @@ -/*********************************************************** -Copyright 1991-1997 by Stichting Mathematisch Centrum, Amsterdam, -The Netherlands. - - All Rights Reserved - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation, and that the names of Stichting Mathematisch -Centrum or CWI or Corporation for National Research Initiatives or -CNRI not be used in advertising or publicity pertaining to -distribution of the software without specific, written prior -permission. - -While CWI is the initial source for this software, a modified version -is made available by the Corporation for National Research Initiatives -(CNRI) at the Internet address ftp://ftp.python.org. - -STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH -REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH -CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL -DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR -PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER -TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR -PERFORMANCE OF THIS SOFTWARE. - -******************************************************************/ - -#include "Python.h" - -const char * -Py_GetPlatform(void) -{ - return "mac"; -} - diff --git a/Mac/Python/macglue.c b/Mac/Python/macglue.c deleted file mode 100644 index 371161020e..0000000000 --- a/Mac/Python/macglue.c +++ /dev/null @@ -1,617 +0,0 @@ -/*********************************************************** -Copyright 1991-1997 by Stichting Mathematisch Centrum, Amsterdam, -The Netherlands. - - All Rights Reserved - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation, and that the names of Stichting Mathematisch -Centrum or CWI not be used in advertising or publicity pertaining to -distribution of the software without specific, written prior permission. - -STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO -THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND -FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE -FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT -OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - -******************************************************************/ - - -#include "Python.h" - -#include "macglue.h" -#include "marshal.h" -#include "import.h" -#include "importdl.h" -#include "pymactoolbox.h" - -#include "pythonresources.h" - -#ifdef WITHOUT_FRAMEWORKS -#include <OSUtils.h> /* for Set(Current)A5 */ -#include <Files.h> -#include <StandardFile.h> -#include <Resources.h> -#include <Memory.h> -#include <Windows.h> -#include <Traps.h> -#include <Processes.h> -#include <Fonts.h> -#include <Menus.h> -#include <TextUtils.h> -#include <LowMem.h> -#include <Events.h> -#else -#include <Carbon/Carbon.h> -#endif - -#ifdef __MWERKS__ -#include <SIOUX.h> -extern void SIOUXSetupMenus(void); -extern void SIOUXDoAboutBox(void); -#endif -#ifdef USE_GUSI -/* Functions we redefine because they're in obscure libraries */ -extern void SpinCursor(short x); -extern void RotateCursor(short x); -extern pascal unsigned char * PLstrcpy(unsigned char *, const unsigned char *); -extern pascal short PLstrcmp(const unsigned char *, const unsigned char *); -extern pascal char *PLstrrchr(const unsigned char *, short); - -#endif - -/* The ID of the Sioux apple menu */ -#define SIOUX_APPLEID 32000 - -#include <signal.h> -#include <stdio.h> - -/* -** When less than this amount of stackspace is left we -** raise a MemoryError. -*/ -#ifndef MINIMUM_STACK_SIZE -#define MINIMUM_STACK_SIZE 8192 -#endif - -/* -** On MacOSX StackSpace() lies: it gives the distance from heap end to stack pointer, -** but the stack cannot grow that far due to rlimit values. We cannot get at this value -** from Carbon, so we set a maximum to the stack here that is based on the default -** stack limit of 512K. -*/ -#define MAXIMUM_STACK_SIZE (256*1024) - -/* -** We have to be careful, since we can't handle -** things like updates (and they'll keep coming back if we don't -** handle them). Note that we don't know who has windows open, so -** even handing updates off to SIOUX under MW isn't going to work. -*/ -#define MAINLOOP_EVENTMASK (mDownMask|keyDownMask|osMask|activMask) - -#include <signal.h> - -/* XXX We should include Errors.h here, but it has a name conflict -** with the python errors.h. */ -#define fnfErr -43 - -/* Interrupt code variables: */ -static int interrupted; /* Set to true when cmd-. seen */ -static RETSIGTYPE intcatcher(int); - -#if !TARGET_API_MAC_OSX -static int PyMac_Yield(void); -#endif - -/* -** These are the real scheduling parameters that control what we check -** in the event loop, and how often we check. The values are initialized -** from pyMac_SchedParamStruct. -*/ - -struct real_sched_param_struct { - int check_interrupt; /* if true check for command-dot */ - int process_events; /* if nonzero enable evt processing, this mask */ - int besocial; /* if nonzero be a little social with CPU */ - unsigned long check_interval; /* how often to check, in ticks */ - unsigned long bg_yield; /* yield so long when in background */ - /* these are computed from previous and clock and such */ - int enabled; /* check_interrupt OR process_event OR yield */ - unsigned long next_check; /* when to check/yield next, in ticks */ -}; - -static struct real_sched_param_struct schedparams = - { 1, MAINLOOP_EVENTMASK, 1, 15, 15, 1, 0}; - -/* -** Workaround for sioux/gusi combo: set when we are exiting -*/ -int PyMac_ConsoleIsDead; - -/* -** Sioux menu bar, saved early so we can restore it -*/ -static MenuBarHandle sioux_mbar; - -/* -** The python-code event handler -*/ -static PyObject *python_event_handler; - -/* Given an FSSpec, return the FSSpec of the parent folder */ - -static OSErr -get_folder_parent (FSSpec * fss, FSSpec * parent) -{ - CInfoPBRec rec; - short err; - - * parent = * fss; - rec.hFileInfo.ioNamePtr = parent->name; - rec.hFileInfo.ioVRefNum = parent->vRefNum; - rec.hFileInfo.ioDirID = parent->parID; - rec.hFileInfo.ioFDirIndex = -1; - rec.hFileInfo.ioFVersNum = 0; - if (err = PBGetCatInfoSync (& rec)) - return err; - parent->parID = rec.dirInfo.ioDrParID; -/* parent->name[0] = 0; */ - return 0; -} - -/* Given an FSSpec return a full, colon-separated pathname */ - -OSErr -PyMac_GetFullPathname (FSSpec *fss, char *buf, int length) -{ - short err; - FSSpec fss_parent, fss_current; - char tmpbuf[1024]; - int plen; - - fss_current = *fss; - plen = fss_current.name[0]; - if ( plen+2 > length ) { - *buf = 0; - return errFSNameTooLong; - } - memcpy(buf, &fss_current.name[1], plen); - buf[plen] = 0; - /* Special case for disk names */ - if ( fss_current.parID <= 1 ) { - buf[plen++] = ':'; - buf[plen] = 0; - return 0; - } - while (fss_current.parID > 1) { - /* Get parent folder name */ - if (err = get_folder_parent(&fss_current, &fss_parent)) { - *buf = 0; - return err; - } - fss_current = fss_parent; - /* Prepend path component just found to buf */ - plen = fss_current.name[0]; - if (strlen(buf) + plen + 1 > 1024) { - /* Oops... Not enough space (shouldn't happen) */ - *buf = 0; - return errFSNameTooLong; - } - memcpy(tmpbuf, &fss_current.name[1], plen); - tmpbuf[plen] = ':'; - strcpy(&tmpbuf[plen+1], buf); - if ( strlen(tmpbuf) > length ) { - *buf = 0; - return errFSNameTooLong; - } - strcpy(buf, tmpbuf); - } - return 0; -} - - -#ifdef USE_GUSI -/* -** SpinCursor (needed by GUSI) drags in heaps of stuff, so we -** provide a dummy here. -*/ -void SpinCursor(short x) { /* Dummy */ } -void RotateCursor(short x) { /* Dummy */ } - - -/* Called at exit() time thru atexit(), to stop event processing */ -void -PyMac_StopGUSISpin() { - PyMac_ConsoleIsDead = 1; -} - -#endif /* USE_GUSI */ - - -/* Convert C to Pascal string. Returns pointer to static buffer. */ -unsigned char * -Pstring(char *str) -{ - static Str255 buf; - int len; - - len = strlen(str); - if (len > 255) - len = 255; - buf[0] = (unsigned char)len; - strncpy((char *)buf+1, str, len); - return buf; -} - - -#ifdef USE_STACKCHECK -/* Check for stack overflow */ -int -PyOS_CheckStack() -{ - char here; - static char *sentinel = 0; - static PyThreadState *thread_for_sentinel = 0; - - if ( sentinel == 0 ) { - unsigned long stackspace = StackSpace(); - -#ifdef MAXIMUM_STACK_SIZE - /* See the comment at the definition */ - if ( stackspace > MAXIMUM_STACK_SIZE ) - stackspace = MAXIMUM_STACK_SIZE; -#endif - sentinel = &here - stackspace + MINIMUM_STACK_SIZE; - } - if ( thread_for_sentinel == 0 ) { - thread_for_sentinel = PyThreadState_Get(); - } - if ( &here < sentinel ) { - if (thread_for_sentinel == PyThreadState_Get()) { - return -1; - } - } - return 0; -} -#endif /* USE_STACKCHECK */ - -#if !TARGET_API_MAC_OSX -void -PyErr_SetInterrupt(void) -{ - interrupted = 1; -} - -/* The catcher routine (which may not be used for all compilers) */ -static RETSIGTYPE -intcatcher(sig) - int sig; -{ - interrupted = 1; - signal(SIGINT, intcatcher); -} - -void -PyOS_InitInterrupts() -{ - if (signal(SIGINT, SIG_IGN) != SIG_IGN) - signal(SIGINT, intcatcher); -} - -void -PyOS_FiniInterrupts() -{ -} - -/* Check whether we are in the foreground */ -static int -PyMac_InForeground(void) -{ - static ProcessSerialNumber ours; - static inited; - ProcessSerialNumber curfg; - Boolean eq; - - if ( inited == 0 ) { - (void)GetCurrentProcess(&ours); - inited = 1; - } - if ( GetFrontProcess(&curfg) < 0 ) - eq = 1; - else if ( SameProcess(&ours, &curfg, &eq) < 0 ) - eq = 1; - return (int)eq; -} - -/* -** This routine scans the event queue looking for cmd-. -*/ -static void -scan_event_queue(force) - int force; -{ - if ( interrupted || (!schedparams.check_interrupt && !force) ) - return; - if ( CheckEventQueueForUserCancel() ) - interrupted = 1; -} - -int -PyErr_CheckSignals() -{ - if (schedparams.enabled) { - if ( interrupted || (unsigned long)TickCount() > schedparams.next_check ) { - scan_event_queue(0); - if (interrupted) { - interrupted = 0; - PyErr_SetNone(PyExc_KeyboardInterrupt); - return -1; - } - if ( PyMac_Yield() < 0) - return -1; - schedparams.next_check = (unsigned long)TickCount() - + schedparams.check_interval; - } - } - return 0; -} - -int -PyOS_InterruptOccurred() -{ - scan_event_queue(0); - if ( !interrupted ) - return 0; - interrupted = 0; - return 1; -} -#endif - -int -PyMac_SetEventHandler(PyObject *evh) -{ - if ( evh && python_event_handler ) { - PyErr_SetString(PyExc_RuntimeError, "Python event handler already set"); - return 0; - } - if ( python_event_handler ) - Py_DECREF(python_event_handler); - if ( evh ) - Py_INCREF(evh); - python_event_handler = evh; - return 1; -} - -/* -** Handle an event, either one found in the mainloop eventhandler or -** one passed back from the python program. -*/ -void -PyMac_HandleEventIntern(evp) - EventRecord *evp; -{ -#ifdef __MWERKS__ - { - int siouxdidit; - - /* If SIOUX wants it we're done */ - siouxdidit = SIOUXHandleOneEvent(evp); - if ( siouxdidit ) - return; - } -#else - /* Other compilers are just unlucky... */ -#endif /* !__MWERKS__ */ -} - -/* -** Handle an event, either through HandleEvent or by passing it to the Python -** event handler. -*/ -int -PyMac_HandleEvent(evp) - EventRecord *evp; -{ - PyObject *rv; - - if ( python_event_handler ) { - rv = PyObject_CallFunction(python_event_handler, "(O&)", - PyMac_BuildEventRecord, evp); - if ( rv ) - Py_DECREF(rv); - else - return -1; /* Propagate exception */ - } else { - PyMac_HandleEventIntern(evp); - } - return 0; -} - -#if !TARGET_API_MAC_OSX -/* -** Yield the CPU to other tasks without processing events. -*/ -int -PyMac_DoYield(int maxsleep, int maycallpython) -{ - EventRecord ev; - int gotone; - long latest_time_ready; - static int in_here = 0; - - in_here++; - - /* - ** Check which of the eventloop cases we have: - ** - process events - ** - don't process events but do yield - ** - do neither - */ - if( in_here > 1 || !schedparams.process_events || - (python_event_handler && !maycallpython) ) { - if ( maxsleep >= 0 ) { - /* XXXX Need to do something here */ - } - } else { - latest_time_ready = TickCount() + maxsleep; - do { - /* XXXX Hack by Jack. - ** In time.sleep() you can click to another application - ** once only. If you come back to Python you cannot get away - ** again. - **/ - gotone = WaitNextEvent(schedparams.process_events, &ev, maxsleep, NULL); - /* Get out quickly if nothing interesting is happening */ - if ( !gotone || ev.what == nullEvent ) - break; - if ( PyMac_HandleEvent(&ev) < 0 ) { - in_here--; - return -1; - } - maxsleep = latest_time_ready - TickCount(); - } while ( maxsleep > 0 ); - } - in_here--; - return 0; -} - -/* -** Process events and/or yield the CPU to other tasks if opportune -*/ -int -PyMac_Yield() { - unsigned long maxsleep; - - if( PyMac_InForeground() ) - maxsleep = 0; - else - maxsleep = schedparams.bg_yield; - - return PyMac_DoYield(maxsleep, 1); -} - -/* -** Return current scheduler parameters -*/ -void -PyMac_GetSchedParams(PyMacSchedParams *sp) -{ - sp->check_interrupt = schedparams.check_interrupt; - sp->process_events = schedparams.process_events; - sp->besocial = schedparams.besocial; - sp->check_interval = schedparams.check_interval / 60.0; - sp->bg_yield = schedparams.bg_yield / 60.0; -} - -/* -** Set current scheduler parameters -*/ -void -PyMac_SetSchedParams(PyMacSchedParams *sp) -{ - schedparams.check_interrupt = sp->check_interrupt; - schedparams.process_events = sp->process_events; - schedparams.besocial = sp->besocial; - schedparams.check_interval = (unsigned long)(sp->check_interval*60); - schedparams.bg_yield = (unsigned long)(sp->bg_yield*60); - if ( schedparams.check_interrupt || schedparams.process_events || - schedparams.besocial ) - schedparams.enabled = 1; - else - schedparams.enabled = 0; - schedparams.next_check = 0; /* Check immedeately */ -} - -/* -** Install our menu bar. -*/ -void -PyMac_InitMenuBar() -{ - MenuHandle applemenu; - Str255 about_text; - static unsigned char about_sioux[] = "\pAbout SIOUX"; - - if ( sioux_mbar ) return; - if ( (sioux_mbar=GetMenuBar()) == NULL || GetMenuHandle(SIOUX_APPLEID) == NULL) { - /* Sioux menu not installed yet. Do so */ - SIOUXSetupMenus(); - if ( (sioux_mbar=GetMenuBar()) == NULL ) - return; - } - if ( (applemenu=GetMenuHandle(SIOUX_APPLEID)) == NULL ) return; - GetMenuItemText(applemenu, 1, about_text); - if ( about_text[0] == about_sioux[0] && - strncmp((char *)(about_text+1), (char *)(about_sioux+1), about_text[0]) == 0 ) - SetMenuItemText(applemenu, 1, "\pAbout Python..."); -} - -/* -** Restore sioux menu bar -*/ -void -PyMac_RestoreMenuBar() -{ - MenuBarHandle curmenubar; - - curmenubar = GetMenuBar(); - if ( sioux_mbar ) { - SetMenuBar(sioux_mbar); - DrawMenuBar(); - } else { - PyMac_InitMenuBar(); - DrawMenuBar(); - } -} - -void -PyMac_RaiseConsoleWindow() -{ - /* Note: this is a hack. SIOUXTextWindow is SIOUX's internal structure - ** and we happen to know that the first entry is the window pointer. - */ - extern WindowRef *SIOUXTextWindow; - - if ( SIOUXTextWindow == NULL || *SIOUXTextWindow == NULL ) - return; - if ( FrontWindow() != *SIOUXTextWindow ) - BringToFront(*SIOUXTextWindow); -} - -/* -** Our replacement about box -*/ - -#include "patchlevel.h" - -void -SIOUXDoAboutBox(void) -{ - DialogPtr theDialog; - WindowPtr theWindow; - short item; - short fontID; - - if( (theDialog = GetNewDialog(ABOUT_ID, NULL, (WindowPtr)-1)) == NULL ) - return; - theWindow = GetDialogWindow(theDialog); - SetPortWindowPort(theWindow); - GetFNum("\pPython-Sans", &fontID); - if (fontID == 0) - fontID = kFontIDGeneva; - TextFont(fontID); - TextSize(9); - ParamText(Pstring(PY_VERSION), "\p", "\p", "\p"); - ShowWindow(theWindow); - ModalDialog(NULL, &item); - DisposeDialog(theDialog); -} - -#endif /* !TARGET_API_MAC_OSX */ diff --git a/Mac/Python/macimport.c b/Mac/Python/macimport.c deleted file mode 100644 index e6c432b5d5..0000000000 --- a/Mac/Python/macimport.c +++ /dev/null @@ -1,445 +0,0 @@ -/*********************************************************** -Copyright 1991-1997 by Stichting Mathematisch Centrum, Amsterdam, -The Netherlands. - - All Rights Reserved - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation, and that the names of Stichting Mathematisch -Centrum or CWI not be used in advertising or publicity pertaining to -distribution of the software without specific, written prior permission. - -STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO -THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND -FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE -FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT -OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - -******************************************************************/ - - -#include "Python.h" - -#include "macglue.h" -#include "marshal.h" -#include "import.h" -#include "importdl.h" - -#include "pythonresources.h" - -#include <Types.h> -#include <Files.h> -#include <Resources.h> -#include <CodeFragments.h> -#include <StringCompare.h> - -typedef void (*dl_funcptr)(); -#define FUNCNAME_PATTERN "init%.200s" - -static int -fssequal(FSSpec *fs1, FSSpec *fs2) -{ - if ( fs1->vRefNum != fs2->vRefNum || fs1->parID != fs2->parID ) - return 0; - return EqualString(fs1->name, fs2->name, false, true); -} -/* -** findnamedresource - Common code for the various *ResourceModule functions. -** Check whether a file contains a resource of the correct name and type, and -** optionally return the value in it. -*/ -static int -findnamedresource( - PyStringObject *obj, - char *module, - char *filename, - OSType restype, - StringPtr dataptr) -{ - FSSpec fss; - FInfo finfo; - short oldrh, filerh; - int ok; - Handle h; - - /* - ** Find_module takes care of interning all - ** sys.path components. We then keep a record of all sys.path - ** components for which GetFInfo has failed (usually because the - ** component in question is a folder), and we don't try opening these - ** as resource files again. - */ -#define MAXPATHCOMPONENTS 32 - static PyStringObject *not_a_file[MAXPATHCOMPONENTS]; - static int max_not_a_file = 0; - int i; - - if (obj && PyString_Check(obj) && PyString_CHECK_INTERNED(obj) ) { - for( i=0; i< max_not_a_file; i++ ) - if ( obj == not_a_file[i] ) - return 0; - } - if ( FSMakeFSSpec(0, 0, Pstring(filename), &fss) != noErr ) { - /* doesn't exist or is folder */ - if ( obj && max_not_a_file < MAXPATHCOMPONENTS && PyString_Check(obj) && PyString_CHECK_INTERNED(obj) ) { - Py_INCREF(obj); - not_a_file[max_not_a_file++] = obj; - if (Py_VerboseFlag > 1) - PySys_WriteStderr("# %s is not a file\n", filename); - } - return 0; - } - if ( fssequal(&fss, &PyMac_ApplicationFSSpec) ) { - /* - ** Special case: the application itself. Use a shortcut to - ** forestall opening and closing the application numerous times - ** (which is dead slow when running from CDROM) - */ - oldrh = CurResFile(); - UseResFile(PyMac_AppRefNum); - filerh = -1; - } else { - if ( FSpGetFInfo(&fss, &finfo) != noErr ) { - /* doesn't exist or is folder */ - if ( obj && max_not_a_file < MAXPATHCOMPONENTS && PyString_Check(obj) && PyString_CHECK_INTERNED(obj) ) { - Py_INCREF(obj); - not_a_file[max_not_a_file++] = obj; - if (Py_VerboseFlag > 1) - PySys_WriteStderr("# %s is not a file\n", filename); - } - return 0; - } - oldrh = CurResFile(); - filerh = FSpOpenResFile(&fss, fsRdPerm); - if ( filerh == -1 ) - return 0; - UseResFile(filerh); - } - if ( dataptr == NULL ) - SetResLoad(0); - if (Py_VerboseFlag > 1) - PySys_WriteStderr("# Look for ('PYC ', %s) in %s\n", module, filename); - h = Get1NamedResource(restype, Pstring(module)); - SetResLoad(1); - ok = (h != NULL); - if ( ok && dataptr != NULL ) { - HLock(h); - /* XXXX Unsafe if resource not correctly formatted! */ - /* for ppc we take the first pstring */ - *dataptr = **h; - memcpy(dataptr+1, (*h)+1, (int)*dataptr); - HUnlock(h); - } - if ( filerh != -1 ) - CloseResFile(filerh); - UseResFile(oldrh); - return ok; -} - -/* -** Returns true if the argument has a resource fork, and it contains -** a 'PYC ' resource of the correct name -*/ -int -PyMac_FindResourceModule(obj, module, filename) -PyStringObject *obj; -char *module; -char *filename; -{ - int ok; - - ok = findnamedresource(obj, module, filename, 'PYC ', (StringPtr)0); - return ok; -} - -/* -** Returns true if the argument has a resource fork, and it contains -** a 'PYD ' resource of the correct name -*/ -int -PyMac_FindCodeResourceModule(obj, module, filename) -PyStringObject *obj; -char *module; -char *filename; -{ - int ok; - - ok = findnamedresource(obj, module, filename, 'PYD ', (StringPtr)0); - return ok; -} - - -/* -** Load the specified module from a code resource -*/ -PyObject * -PyMac_LoadCodeResourceModule(name, pathname) - char *name; - char *pathname; -{ - PyObject *m, *d, *s; - char funcname[258]; - char *lastdot, *shortname, *packagecontext; - dl_funcptr p = NULL; - Str255 fragmentname; - CFragConnectionID connID; - Ptr mainAddr; - Str255 errMessage; - OSErr err; - char buf[512]; - Ptr symAddr; - CFragSymbolClass class; - - if ((m = _PyImport_FindExtension(name, name)) != NULL) { - Py_INCREF(m); - return m; - } - lastdot = strrchr(name, '.'); - if (lastdot == NULL) { - packagecontext = NULL; - shortname = name; - } - else { - packagecontext = name; - shortname = lastdot+1; - } - PyOS_snprintf(funcname, sizeof(funcname), FUNCNAME_PATTERN, shortname); - if( !findnamedresource((PyStringObject *)0, name, pathname, 'PYD ', fragmentname)) { - PyErr_SetString(PyExc_ImportError, "PYD resource not found"); - return NULL; - } - - /* Load the fragment - (or return the connID if it is already loaded */ - err = GetSharedLibrary(fragmentname, kCompiledCFragArch, - kLoadCFrag, &connID, &mainAddr, - errMessage); - if ( err ) { - PyOS_snprintf(buf, sizeof(buf), "%.*s: %.200s", - errMessage[0], errMessage+1, - PyMac_StrError(err)); - PyErr_SetString(PyExc_ImportError, buf); - return NULL; - } - /* Locate the address of the correct init function */ - err = FindSymbol(connID, Pstring(funcname), &symAddr, &class); - if ( err ) { - PyOS_snprintf(buf, sizeof(buf), "%s: %.200s", - funcname, PyMac_StrError(err)); - PyErr_SetString(PyExc_ImportError, buf); - return NULL; - } - p = (dl_funcptr)symAddr; - if (p == NULL) { - PyErr_Format(PyExc_ImportError, - "dynamic module does not define init function (%.200s)", - funcname); - return NULL; - } - _Py_PackageContext = packagecontext; - (*p)(); - _Py_PackageContext = NULL; - if (PyErr_Occurred()) - return NULL; - if (_PyImport_FixupExtension(name, name) == NULL) - return NULL; - - m = PyDict_GetItemString(PyImport_GetModuleDict(), name); - if (m == NULL) { - PyErr_SetString(PyExc_SystemError, - "dynamic module not initialized properly"); - return NULL; - } - /* Remember the filename as the __file__ attribute */ - d = PyModule_GetDict(m); - s = PyString_FromString(pathname); - if (s == NULL || PyDict_SetItemString(d, "__file__", s) != 0) - PyErr_Clear(); /* Not important enough to report */ - Py_XDECREF(s); - if (Py_VerboseFlag) - PySys_WriteStderr("import %s # pyd fragment %#s loaded from %s\n", - name, fragmentname, pathname); - Py_INCREF(m); - return m; -} - -/* -** Load the specified module from a resource -*/ -PyObject * -PyMac_LoadResourceModule(module, filename) -char *module; -char *filename; -{ - FSSpec fss; - FInfo finfo; - short oldrh, filerh; - Handle h; - OSErr err; - PyObject *m, *co; - long num, size; - - if ( (err=FSMakeFSSpec(0, 0, Pstring(filename), &fss)) != noErr ) - goto error; - if ( fssequal(&fss, &PyMac_ApplicationFSSpec) ) { - /* - ** Special case: the application itself. Use a shortcut to - ** forestall opening and closing the application numerous times - ** (which is dead slow when running from CDROM) - */ - oldrh = CurResFile(); - UseResFile(PyMac_AppRefNum); - filerh = -1; - } else { - if ( (err=FSpGetFInfo(&fss, &finfo)) != noErr ) - goto error; - oldrh = CurResFile(); - filerh = FSpOpenResFile(&fss, fsRdPerm); - if ( filerh == -1 ) { - err = ResError(); - goto error; - } - UseResFile(filerh); - } - h = Get1NamedResource('PYC ', Pstring(module)); - if ( h == NULL ) { - err = ResError(); - goto error; - } - HLock(h); - /* - ** XXXX The next few lines are intimately tied to the format of pyc - ** files. I'm not sure whether this code should be here or in import.c -- Jack - */ - size = GetHandleSize(h); - if ( size < 8 ) { - PyErr_SetString(PyExc_ImportError, "Resource too small"); - co = NULL; - } else { - num = (*h)[0] & 0xff; - num = num | (((*h)[1] & 0xff) << 8); - num = num | (((*h)[2] & 0xff) << 16); - num = num | (((*h)[3] & 0xff) << 24); - if ( num != PyImport_GetMagicNumber() ) { - PyErr_SetString(PyExc_ImportError, "Bad MAGIC in resource"); - co = NULL; - } else { - co = PyMarshal_ReadObjectFromString((*h)+8, size-8); - /* - ** Normally, byte 4-7 are the time stamp, but that is not used - ** for 'PYC ' resources. We abuse byte 4 as a flag to indicate - ** that it is a package rather than an ordinary module. - ** See also py_resource.py. (jvr) - */ - if ((*h)[4] & 0xff) { - /* it's a package */ - /* Set __path__ to the package name */ - PyObject *d, *s; - int err; - - m = PyImport_AddModule(module); - if (m == NULL) { - co = NULL; - goto packageerror; - } - d = PyModule_GetDict(m); - s = PyString_InternFromString(module); - if (s == NULL) { - co = NULL; - goto packageerror; - } - err = PyDict_SetItemString(d, "__path__", s); - Py_DECREF(s); - if (err != 0) { - co = NULL; - goto packageerror; - } - } - } - } -packageerror: - HUnlock(h); - if ( filerh != -1 ) - CloseResFile(filerh); - else - ReleaseResource(h); - UseResFile(oldrh); - if ( co ) { - m = PyImport_ExecCodeModuleEx(module, co, "<pyc resource>"); - Py_DECREF(co); - } else { - m = NULL; - } - if (Py_VerboseFlag) - PySys_WriteStderr("import %s # pyc resource from %s\n", - module, filename); - return m; -error: - { - char buf[512]; - - PyOS_snprintf(buf, sizeof(buf), "%s: %s", filename, PyMac_StrError(err)); - PyErr_SetString(PyExc_ImportError, buf); - return NULL; - } -} - -/* -** Look for a module in a single folder. Upon entry buf and len -** point to the folder to search, upon exit they refer to the full -** pathname of the module found (if any). -*/ -struct filedescr * -PyMac_FindModuleExtension(char *buf, size_t *lenp, char *module) -{ - struct filedescr *fdp; - unsigned char fnbuf[64]; - int modnamelen = strlen(module); - FSSpec fss; - short refnum; - long dirid; - - /* - ** Copy the module name to the buffer (already :-terminated) - ** We also copy the first suffix, if this matches immedeately we're - ** lucky and return immedeately. - */ - if ( !_PyImport_Filetab[0].suffix ) - return 0; - - strcpy(buf+*lenp, _PyImport_Filetab[0].suffix); - if ( FSMakeFSSpec(0, 0, Pstring(buf), &fss) == noErr ) - return _PyImport_Filetab; - /* - ** We cannot check for fnfErr (unfortunately), it can mean either that - ** the file doesn't exist (fine, we try others) or the path leading to it. - */ - refnum = fss.vRefNum; - dirid = fss.parID; - if ( refnum == 0 || dirid == 0 ) /* Fail on nonexistent dir */ - return 0; - /* - ** We now have the folder parameters. Setup the field for the filename - */ - if ( modnamelen > 54 ) return 0; /* Leave room for extension */ - strcpy((char *)fnbuf+1, module); - buf[*lenp] = '\0'; - - for( fdp = _PyImport_Filetab+1; fdp->suffix; fdp++ ) { - strcpy((char *)fnbuf+1+modnamelen, fdp->suffix); - fnbuf[0] = strlen((char *)fnbuf+1); - if (Py_VerboseFlag > 1) - PySys_WriteStderr("# trying %s%s\n", buf, fdp->suffix); - if ( FSMakeFSSpec(refnum, dirid, fnbuf, &fss) == noErr ) { - /* Found it. */ - strcpy(buf+*lenp, fdp->suffix); - return fdp; - } - } - return 0; -} diff --git a/Mac/Python/macmain.c b/Mac/Python/macmain.c deleted file mode 100644 index d257142976..0000000000 --- a/Mac/Python/macmain.c +++ /dev/null @@ -1,640 +0,0 @@ -/*********************************************************** -Copyright 1991-1997 by Stichting Mathematisch Centrum, Amsterdam, -The Netherlands. - - All Rights Reserved - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation, and that the names of Stichting Mathematisch -Centrum or CWI not be used in advertising or publicity pertaining to -distribution of the software without specific, written prior permission. - -STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO -THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND -FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE -FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT -OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - -******************************************************************/ - -/* Python interpreter main program */ - -#include "Python.h" -#include "pythonresources.h" -#include "import.h" -#include "marshal.h" -#include "macglue.h" - -#ifdef WITHOUT_FRAMEWORKS -#include <Memory.h> -#include <Resources.h> -#include <stdio.h> -#include <Events.h> -#include <Windows.h> -#include <Fonts.h> -#include <Balloons.h> -#include <CFBundle.h> -#include <CFURL.h> -#include <CFString.h> -#include <CFBase.h> -#include <CFArray.h> -#include <Gestalt.h> -#include <Appearance.h> -#else -#include <Carbon/Carbon.h> -#endif /* WITHOUT_FRAMEWORKS */ - -#ifdef __MWERKS__ -#include <SIOUX.h> -#define USE_SIOUX -extern int ccommand(char ***); -#if __profile__ == 1 -#include <profiler.h> -#endif /* __profile__ */ -#endif /* __MWERKS__ */ - -#include <unistd.h> -#ifdef USE_MAC_SHARED_LIBRARY -extern PyMac_AddLibResources(void); -#endif - -#define STARTUP "PythonStartup" - -#define COPYRIGHT \ - "Type \"copyright\", \"credits\" or \"license\" for more information." - -short PyMac_AppRefNum; /* RefNum of application resource fork */ - -/* For Py_GetArgcArgv(); set by main() */ -static char **orig_argv; -static int orig_argc; - -/* A flag which remembers whether the user has acknowledged all the console -** output (by typing something) -*/ -#define STATE_UNKNOWN 0 -#define STATE_LASTREAD 1 -#define STATE_LASTWRITE 2 -int console_output_state = STATE_UNKNOWN; - -PyMac_PrefRecord PyMac_options; - -static void PyMac_Main(int, char **, char *); /* Forward */ -void PyMac_Exit(int); /* Forward */ - -/* Initialize the Mac toolbox world */ - -static void -init_mac_world(void) -{ - InitCursor(); -} - -/* -** PyMac_InteractiveOptions - Allow user to set options if option key is pressed -*/ -static void -PyMac_InteractiveOptions(PyMac_PrefRecord *p, int *argcp, char ***argvp) -{ - KeyMap rmap; - unsigned char *map; - short item, type; - ControlHandle handle; - DialogPtr dialog; - Rect rect; - - /* - ** If the preferences disallows interactive options we return, - ** similarly of <option> isn't pressed. - */ - if (p->nointopt) return; - - GetKeys(rmap); - map = (unsigned char *)rmap; - if ( ( map[0x3a>>3] & (1<<(0x3a&7)) ) == 0 ) /* option key is 3a */ - return; - - dialog = GetNewDialog(OPT_DIALOG, NULL, (WindowPtr)-1); - if ( dialog == NULL ) { - printf("Option dialog not found - cannot set options\n"); - return; - } - SetDialogDefaultItem(dialog, OPT_OK); - SetDialogCancelItem(dialog, OPT_CANCEL); - - /* Set default values */ -#define SET_OPT_ITEM(num, var) \ - GetDialogItem(dialog, (num), &type, (Handle *)&handle, &rect); \ - SetControlValue(handle, (short)p->var); - - SET_OPT_ITEM(OPT_INSPECT, inspect); - SET_OPT_ITEM(OPT_VERBOSE, verbose); - /* OPT_VERBOSEVERBOSE is default off */ - SET_OPT_ITEM(OPT_OPTIMIZE, optimize); - SET_OPT_ITEM(OPT_UNBUFFERED, unbuffered); - SET_OPT_ITEM(OPT_DEBUGGING, debugging); - GetDialogItem(dialog, OPT_KEEPALWAYS, &type, (Handle *)&handle, &rect); - SetControlValue(handle, (short)(p->keep_console == POPT_KEEPCONSOLE_ALWAYS)); - GetDialogItem(dialog, OPT_KEEPOUTPUT, &type, (Handle *)&handle, &rect); - SetControlValue(handle, (short)(p->keep_console == POPT_KEEPCONSOLE_OUTPUT)); - GetDialogItem(dialog, OPT_KEEPERROR, &type, (Handle *)&handle, &rect); - SetControlValue(handle, (short)(p->keep_console == POPT_KEEPCONSOLE_ERROR)); - GetDialogItem(dialog, OPT_KEEPNEVER, &type, (Handle *)&handle, &rect); - SetControlValue(handle, (short)(p->keep_console == POPT_KEEPCONSOLE_NEVER)); -/* SET_OPT_ITEM(OPT_KEEPCONSOLE, keep_console); */ - SET_OPT_ITEM(OPT_TABWARN, tabwarn); - SET_OPT_ITEM(OPT_NOSITE, nosite); - SET_OPT_ITEM(OPT_DIVISIONWARN, divisionwarn); - SET_OPT_ITEM(OPT_UNIXNEWLINES, unixnewlines); - /* The rest are not settable interactively */ - -#undef SET_OPT_ITEM - - while (1) { - handle = NULL; - ModalDialog(NULL, &item); - if ( item == OPT_OK ) - break; - if ( item == OPT_CANCEL ) { - DisposeDialog(dialog); - exit(0); - } - if ( item == OPT_CMDLINE ) { - int old_argc = *argcp; - int i; - int new_argc, newer_argc; - char **new_argv, **newer_argv; - - new_argc = ccommand(&new_argv); - newer_argc = (new_argc-1) + old_argc; - newer_argv = malloc((newer_argc+1)*sizeof(char *)); - if( !newer_argv ) - Py_FatalError("Cannot malloc argv\n"); - for(i=0; i<old_argc; i++) - newer_argv[i] = (*argvp)[i]; - for(i=old_argc; i<=newer_argc; i++) /* Copy the NULL too */ - newer_argv[i] = new_argv[i-old_argc+1]; - *argvp = newer_argv; - *argcp = newer_argc; - - /* XXXX Is it not safe to use free() here, apparently */ - } -#define OPT_ITEM(num, var) \ - if ( item == (num) ) { \ - p->var = !p->var; \ - GetDialogItem(dialog, (num), &type, (Handle *)&handle, &rect); \ - SetControlValue(handle, (short)p->var); \ - } - - OPT_ITEM(OPT_INSPECT, inspect); - OPT_ITEM(OPT_VERBOSE, verbose); - if ( item == OPT_VERBOSEVERBOSE ) { - if ( p->verbose == 2 ) - p->verbose = 1; - else - p->verbose = 2; - GetDialogItem(dialog, OPT_VERBOSE, &type, (Handle *)&handle, &rect); - SetControlValue(handle, 1); - } - GetDialogItem(dialog, OPT_VERBOSEVERBOSE, &type, (Handle *)&handle, &rect); - SetControlValue(handle, p->verbose == 2); - OPT_ITEM(OPT_OPTIMIZE, optimize); - OPT_ITEM(OPT_UNBUFFERED, unbuffered); - OPT_ITEM(OPT_DEBUGGING, debugging); - if ( item == OPT_KEEPALWAYS ) p->keep_console = POPT_KEEPCONSOLE_ALWAYS; - if ( item == OPT_KEEPOUTPUT ) p->keep_console = POPT_KEEPCONSOLE_OUTPUT; - if ( item == OPT_KEEPERROR ) p->keep_console = POPT_KEEPCONSOLE_ERROR; - if ( item == OPT_KEEPNEVER ) p->keep_console = POPT_KEEPCONSOLE_NEVER; - GetDialogItem(dialog, OPT_KEEPALWAYS, &type, (Handle *)&handle, &rect); - SetControlValue(handle, (short)(p->keep_console == POPT_KEEPCONSOLE_ALWAYS)); - GetDialogItem(dialog, OPT_KEEPOUTPUT, &type, (Handle *)&handle, &rect); - SetControlValue(handle, (short)(p->keep_console == POPT_KEEPCONSOLE_OUTPUT)); - GetDialogItem(dialog, OPT_KEEPERROR, &type, (Handle *)&handle, &rect); - SetControlValue(handle, (short)(p->keep_console == POPT_KEEPCONSOLE_ERROR)); - GetDialogItem(dialog, OPT_KEEPNEVER, &type, (Handle *)&handle, &rect); - SetControlValue(handle, (short)(p->keep_console == POPT_KEEPCONSOLE_NEVER)); - OPT_ITEM(OPT_TABWARN, tabwarn); - OPT_ITEM(OPT_NOSITE, nosite); - OPT_ITEM(OPT_DIVISIONWARN, divisionwarn); - OPT_ITEM(OPT_UNIXNEWLINES, unixnewlines); - -#undef OPT_ITEM - } - DisposeDialog(dialog); -} - -/* -** Initialization code, shared by interpreter and applets -*/ -static void -init_common(int *argcp, char ***argvp, int embedded) -{ - /* Remember resource fork refnum, for later */ - PyMac_AppRefNum = CurResFile(); - - /* Initialize toolboxes */ - init_mac_world(); - -#ifdef USE_MAC_SHARED_LIBRARY - /* Add the shared library to the stack of resource files */ - (void)PyMac_init_process_location(); - PyMac_AddLibResources(); -#endif - -#if defined(USE_GUSI) - atexit(PyMac_StopGUSISpin); -#endif - -#ifdef USE_SIOUX - /* Set various SIOUX flags. Some are changed later based on options */ - SIOUXSettings.asktosaveonclose = 0; - SIOUXSettings.showstatusline = 0; - SIOUXSettings.tabspaces = 4; -#endif - - /* Get options from preference file (or from applet resource fork) */ - PyMac_options.keep_console = POPT_KEEPCONSOLE_OUTPUT; /* default-default */ - PyMac_options.unixnewlines = 1; - PyMac_PreferenceOptions(&PyMac_options); - - if ( embedded ) { - static char *emb_argv[] = {"embedded-python", 0}; - - *argcp = 1; - *argvp = emb_argv; - } else { - /* Create argc/argv. Do it before we go into the options event loop. - ** In MachoPython we skip this step if we already have plausible - ** command line arguments. - */ - *argcp = PyMac_GetArgv(argvp, PyMac_options.noargs); -#ifndef NO_ARGV0_CHDIR - if (*argcp >= 1 && (*argvp)[0] && (*argvp)[0][0]) { - /* Workaround for MacOS X, which currently (DP4) doesn't set - ** the working folder correctly - */ - char app_wd[256], *p; - - strncpy(app_wd, (*argvp)[0], 256); - p = strrchr(app_wd, ':'); - if ( p ) *p = 0; - chdir(app_wd); - } -#endif - /* Do interactive option setting, if allowed and <option> depressed */ - PyMac_InteractiveOptions(&PyMac_options, argcp, argvp); - } - - /* Copy selected options to where the machine-independent stuff wants it */ - Py_VerboseFlag = PyMac_options.verbose; -/* Py_SuppressPrintingFlag = PyMac_options.suppress_print; */ - Py_OptimizeFlag = PyMac_options.optimize; - Py_DebugFlag = PyMac_options.debugging; - Py_NoSiteFlag = PyMac_options.nosite; - Py_TabcheckFlag = PyMac_options.tabwarn; - Py_DivisionWarningFlag = PyMac_options.divisionwarn; - if ( PyMac_options.noargs ) { - /* don't process events at all without the scripts permission */ - PyMacSchedParams scp; - - PyMac_GetSchedParams(&scp); - scp.process_events = 0; - /* Should we disable command-dot as well? */ - PyMac_SetSchedParams(&scp); - } - - /* Set buffering */ - if (PyMac_options.unbuffered) { -#ifndef MPW - setbuf(stdout, (char *)NULL); - setbuf(stderr, (char *)NULL); -#else - /* On MPW (3.2) unbuffered seems to hang */ - setvbuf(stdout, (char *)NULL, _IOLBF, BUFSIZ); - setvbuf(stderr, (char *)NULL, _IOLBF, BUFSIZ); -#endif - } -#if __profile__ == 1 - /* collectSummary or collectDetailed, timebase, #routines, max stack depth */ - ProfilerInit(collectSummary, bestTimeBase, 8000, 250); -#endif - - /* Tell the rest of python about our argc/argv */ - orig_argc = *argcp; /* For Py_GetArgcArgv() */ - orig_argv = *argvp; - Py_SetProgramName((*argvp)[0]); -} - -/* -** Inspection mode after script/applet termination -*/ -static int -run_inspect(void) -{ - int sts = 0; - - if (PyMac_options.inspect && isatty((int)fileno(stdin))) - sts = PyRun_AnyFile(stdin, "<stdin>") != 0; - return sts; -} - -#ifdef USE_MAC_APPLET_SUPPORT -/* Applet support */ - -/* Run a compiled Python Python script from 'PYC ' resource __main__ */ -static int -run_main_resource(void) -{ - Handle h; - long size; - PyObject *code; - PyObject *result; - - h = GetNamedResource('PYC ', "\p__main__"); - if (h == NULL) { - Alert(NOPYC_ALERT, NULL); - return 1; - } - size = GetResourceSizeOnDisk(h); - HLock(h); - code = PyMarshal_ReadObjectFromString(*h + 8, (int)(size - 8)); - HUnlock(h); - ReleaseResource(h); - if (code == NULL) { - PyErr_Print(); - return 1; - } - result = PyImport_ExecCodeModule("__main__", code); - Py_DECREF(code); - if (result == NULL) { - PyErr_Print(); - return 1; - } - Py_DECREF(result); - return 0; -} - -/* Initialization sequence for applets */ -void -PyMac_InitApplet(void) -{ - int argc; - char **argv; - int err; - - init_common(&argc, &argv, 0); - - Py_Initialize(); - PySys_SetArgv(argc, argv); - - err = run_main_resource(); - - err = (run_inspect() || err); - - fflush(stderr); - fflush(stdout); - PyMac_Exit(err); - /* XXX Should we bother to Py_Exit(sts)? */ -} - -/* -** Hook for embedding python. -*/ -void -PyMac_Initialize(void) -{ - int argc; - char **argv; - - init_common(&argc, &argv, 1); - Py_Initialize(); - PySys_SetArgv(argc, argv); -} - -#endif /* USE_MAC_APPLET_SUPPORT */ - -/* For normal application */ -void -PyMac_InitApplication(void) -{ - int argc; - char **argv; - OSType filetype; - - static char scriptpath[1024]; - char *script = NULL; - - init_common(&argc, &argv, 0); - - if ( argc > 1 ) { - /* We're running a script. Attempt to change current directory */ - char curwd[256], *endp; - - strcpy(curwd, argv[1]); - endp = strrchr(curwd, ':'); - if ( endp && endp > curwd ) { - *endp = '\0'; - - chdir(curwd); - } - /* Check that the first argument is a text file */ - filetype = PyMac_getfiletype(argv[1]); - if ( filetype != 'TEXT' && filetype != 0 ) { - Alert(NOTASCRIPT_ID, NULL); - exit(0); - } - } - PyMac_Main(argc, argv, script); -} - -/* Main program */ - -static void -PyMac_Main(int argc, char **argv, char *filename) -{ - int sts; - char *command = NULL; - FILE *fp = stdin; - - if ( filename ) { - /* Someone else has found our "script" already */ - argv[0] = filename; - } else { - filename = argv[1]; - argv++; - argc--; - } - - if (Py_VerboseFlag || - (command == NULL && filename == NULL && isatty((int)fileno(fp)))) - fprintf(stderr, "%s %s on %s\n%s\n", - "Python", - Py_GetVersion(), Py_GetPlatform(), COPYRIGHT); - - if (filename != NULL) { - if ((fp = fopen(filename, "r" PY_STDIOTEXTMODE)) == NULL) { - fprintf(stderr, "%s: can't open file '%s'\n", - argv[0], filename); - PyMac_Exit(2); - } - } - - /* We initialize the menubar here, hoping SIOUX is initialized by now */ - PyMac_InitMenuBar(); - - Py_Initialize(); - -#if 0 - /* According to Martin v. Loewis this is a bad idea... */ - PyUnicode_SetDefaultEncoding(PyMac_getscript()); -#endif - - PySys_SetArgv(argc, argv); - - if (filename == NULL && isatty((int)fileno(fp))) { - FILE *fp = fopen(STARTUP, "r" PY_STDIOTEXTMODE); - if (fp != NULL) { - (void) PyRun_SimpleFile(fp, STARTUP); - PyErr_Clear(); - fclose(fp); - } - } - sts = PyRun_AnyFile( - fp, filename == NULL ? "<stdin>" : filename) != 0; - if (filename != NULL) - fclose(fp); - - if ( filename != NULL || command != NULL ) - sts = (run_inspect() || sts); - - Py_Exit(sts); - /*NOTREACHED*/ -} - -/* -** Reset the "unseen output" flag -*/ -void -PyMac_OutputSeen(void) -{ - if ( console_output_state == STATE_UNKNOWN ) - PyMac_InitMenuBar(); - console_output_state = STATE_LASTREAD; -} - -/* -** Set the "unseen output" flag -*/ -void -PyMac_OutputNotSeen(void) -{ - if ( console_output_state == STATE_UNKNOWN ) - PyMac_InitMenuBar(); - console_output_state = STATE_LASTWRITE; -} - -/* -** Override abort() - The default one is not what we want. -*/ -void -abort(void) -{ - console_output_state = STATE_LASTWRITE; - PyMac_Exit(1); -} - -/* -** Terminate application -*/ -void -PyMac_Exit(int status) -{ -#ifdef USE_SIOUX - int keep = 0; -#endif - -#if __profile__ == 1 - ProfilerDump("\pPython Profiler Results"); - ProfilerTerm(); -#endif - -#ifdef USE_SIOUX - switch (PyMac_options.keep_console) { - case POPT_KEEPCONSOLE_NEVER: - keep = 0; - break; - case POPT_KEEPCONSOLE_OUTPUT: - if (console_output_state == STATE_LASTWRITE || - console_output_state == STATE_UNKNOWN ) - keep = 1; - else - keep = 0; - break; - case POPT_KEEPCONSOLE_ERROR: - keep = (status != 0); - break; - default: - keep = 1; - } - if (keep) { - SIOUXSettings.standalone = 1; - SIOUXSettings.autocloseonquit = 0; - SIOUXSetTitle("\p\307terminated\310"); - PyMac_RaiseConsoleWindow(); - PyMac_RestoreMenuBar(); -#ifdef USE_MSL - /* - ** Temporary workaround: autocloseonquit clearing does not - ** currently work for the MSL/GUSI combo. - */ - while(getchar() > 0); -#endif - } - else - SIOUXSettings.autocloseonquit = 1; -#endif /* USE_SIOUX */ - - exit(status); -} - -/* Make the *original* argc/argv available to other modules. - This is rare, but it is needed by the secureware extension. */ - -void -Py_GetArgcArgv(int *argc,char ***argv) -{ - *argc = orig_argc; - *argv = orig_argv; -} - -/* More cruft that shouldn't really be here, used in sysmodule.c */ -/* Return the program name -- some code out there needs this. */ -char * -Py_GetProgramFullPath(void) -{ - return orig_argv[0]; -} - -char * -Py_GetPrefix(void) -{ - return PyMac_GetPythonDir(); -} - -char * -Py_GetExecPrefix(void) -{ - return PyMac_GetPythonDir(); -} - -int -PyMac_GetDelayConsoleFlag(void) -{ - return (int)PyMac_options.delayconsole; -} - diff --git a/Mac/Python/macsetfiletype.c b/Mac/Python/macsetfiletype.c deleted file mode 100644 index b2d9531e5f..0000000000 --- a/Mac/Python/macsetfiletype.c +++ /dev/null @@ -1,75 +0,0 @@ -/*********************************************************** -Copyright 1991-1997 by Stichting Mathematisch Centrum, Amsterdam, -The Netherlands. - - All Rights Reserved - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation, and that the names of Stichting Mathematisch -Centrum or CWI or Corporation for National Research Initiatives or -CNRI not be used in advertising or publicity pertaining to -distribution of the software without specific, written prior -permission. - -While CWI is the initial source for this software, a modified version -is made available by the Corporation for National Research Initiatives -(CNRI) at the Internet address ftp://ftp.python.org. - -STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH -REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH -CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL -DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR -PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER -TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR -PERFORMANCE OF THIS SOFTWARE. - -******************************************************************/ - -/* - * macsetfiletype - Set the mac's idea of file type - * - */ - -#include "Python.h" -#include "macglue.h" -#include "macdefs.h" - -int -PyMac_setfiletype(name, creator, type) -char *name; -long creator, type; -{ - FInfo info; - FSSpec fss; - unsigned char *pname; - - pname = (StringPtr) Pstring(name); - if (FSMakeFSSpec(0, 0, pname, &fss) < 0 ) - return -1; - if ( FSpGetFInfo(&fss, &info) < 0 ) - return -1; - info.fdType = type; - info.fdCreator = creator; - return FSpSetFInfo(&fss, &info); -} - -long -PyMac_getfiletype(name) -char *name; -{ - FInfo info; - unsigned char *pname; - FSSpec fss; - - pname = (StringPtr) Pstring(name); - if (FSMakeFSSpec(0, 0, pname, &fss) < 0 ) - return -1; - if ( FSpGetFInfo(&fss, &info) < 0 ) - return -1; - return info.fdType; -} - diff --git a/Mac/Python/macshlglue.c b/Mac/Python/macshlglue.c deleted file mode 100644 index d88d4434e0..0000000000 --- a/Mac/Python/macshlglue.c +++ /dev/null @@ -1,128 +0,0 @@ -/*********************************************************** -Copyright 1991-1997 by Stichting Mathematisch Centrum, Amsterdam, -The Netherlands. - - All Rights Reserved - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation, and that the names of Stichting Mathematisch -Centrum or CWI or Corporation for National Research Initiatives or -CNRI not be used in advertising or publicity pertaining to -distribution of the software without specific, written prior -permission. - -While CWI is the initial source for this software, a modified version -is made available by the Corporation for National Research Initiatives -(CNRI) at the Internet address ftp://ftp.python.org. - -STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH -REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH -CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL -DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR -PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER -TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR -PERFORMANCE OF THIS SOFTWARE. - -******************************************************************/ - -/* -** Shared library initialization code. -** -** This code calls the MetroWerks shared-library initialization code -** and performs one extra step: it remembers the FSSpec of the file -** we are loaded from, so we can later call PyMac_AddLibResources to -** add the file to our resource file chain. -** -** This file is needed for PythonCore and for any dynamically loaded -** module that has interesting resources in its .slb file. -** Use by replacing __initialize in the "CFM preferences" init field -** by __initialize_with_resources. -*/ - -#include <Types.h> -#include <Quickdraw.h> -#include <SegLoad.h> -#include <CodeFragments.h> -#include <Files.h> -#include <Resources.h> - -/* Defined in the MSL runtime: */ -extern void __initialize(void); - -/* Defined either in macglue.c or in a MPW library: */ -extern pascal short PLstrcmp(const unsigned char *, const unsigned char *); - -/* -** Variables passed from shared lib initialization to PyMac_AddLibResources. -*/ -static int library_fss_valid; -static FSSpec library_fss; - -/* -** Routine called upon fragment load. We attempt to save the FSSpec from which we're -** loaded. We always return noErr (we just continue without the resources). -*/ -OSErr pascal -__initialize_with_resources(CFragInitBlockPtr data) -{ - /* Call the MW runtime's initialization routine */ - __initialize(); - - if ( data == nil ) return noErr; - if ( data->fragLocator.where == kDataForkCFragLocator ) { - library_fss = *data->fragLocator.u.onDisk.fileSpec; - library_fss_valid = 1; - } else if ( data->fragLocator.where == kResourceCFragLocator ) { - library_fss = *data->fragLocator.u.inSegs.fileSpec; - library_fss_valid = 1; - } - return noErr; -} - -/* -** compare two FSSpecs, return true if equal, false if different -** XXX where could this function live? (jvr) -*/ - -static int -FSpCompare(FSSpec *fss1, FSSpec *fss2) { - if (fss1->vRefNum != fss2->vRefNum) - return 0; - if (fss1->parID != fss2->parID) - return 0; - return !PLstrcmp(fss1->name, fss2->name); -} - -/* XXX can't include "macglue.h" somehow (jvr) */ -extern FSSpec PyMac_ApplicationFSSpec; /* Application location (from macargv.c) */ - -/* -** Insert the library resources into the search path. Put them after -** the resources from the application (which we assume is the current -** resource file). Again, we ignore errors. -*/ -void -PyMac_AddLibResources() -{ - if ( !library_fss_valid || FSpCompare(&library_fss, &PyMac_ApplicationFSSpec)) - return; - (void)FSpOpenResFile(&library_fss, fsRdPerm); -} - -/* -** Dummy main() program to keep linker happy: we want to -** use the MW AppRuntime in our shared library (better than building -** custom runtime libraries as we did before) but AppRuntime -** expects a main program. Note that it -*/ - -#pragma export off -int -main(int argc, char **argv) { - DebugStr("\pCannot happen: PythonCore dummy main called!"); -} -#pragma export reset diff --git a/Mac/Python/pyGUSISIOUX.cp b/Mac/Python/pyGUSISIOUX.cp deleted file mode 100644 index 4e63ebe616..0000000000 --- a/Mac/Python/pyGUSISIOUX.cp +++ /dev/null @@ -1,239 +0,0 @@ -/* -** Modified version of GUSISIOUX.cp especially for Python. -** Changes (by Jack): -** - Optionally delay the console window until something is written to it. -** - Tell the upper layers whether the last command was a read or a write. -** - Tell SIOUX not to use WaitNextEvent (both Python and SIOUX trying to be -** nice to background apps means we're yielding almost 100% of the time). -** - Make sure signals are processed when returning from read/write. -*/ -#define GUSI_SOURCE -#include "GUSIInternal.h" -#include "GUSISIOUX.h" -#include "GUSIDevice.h" -#include "GUSIDescriptor.h" -#include "GUSIBasics.h" -#include "GUSIDiag.h" -//#ifndef WITHOUT_JACK_MODS -//#include "GUSIConfig.h" -//#endif - -#include <LowMem.h> - -#include <fcntl.h> -#include <sys/stat.h> -#include <sys/ioctl.h> -#include <errno.h> -#include <console.h> - -#include "Python.h" -#include "macglue.h" -extern Boolean SIOUXUseWaitNextEvent; - -static PyReadHandler sInConsole = 0L; -static PyWriteHandler sOutConsole = 0L; -static PyWriteHandler sErrConsole = 0L; - -inline bool hasCustomConsole(void) { return sInConsole != 0L; } - -class GUSISIOUXSocket : public GUSISocket { -public: - ~GUSISIOUXSocket(); - - -ssize_t read(const GUSIScatterer & buffer); -ssize_t write(const GUSIGatherer & buffer); -virtual int ioctl(unsigned int request, va_list arg); -virtual int fstat(struct stat * buf); -virtual int isatty(); -bool select(bool * canRead, bool * canWrite, bool *); - - static GUSISIOUXSocket * Instance(int fd); -private: - GUSISIOUXSocket(int fd); - static bool initialized; - static void Initialize(); - int fFd; -}; -class GUSISIOUXDevice : public GUSIDevice { -public: - static GUSISIOUXDevice * Instance(); - - -virtual bool Want(GUSIFileToken & file); -virtual GUSISocket * open(GUSIFileToken &, int flags); -private: - GUSISIOUXDevice() {} - - static GUSISIOUXDevice * sInstance; -}; - -GUSISIOUXSocket * GUSISIOUXSocket::Instance(int fd) -{ - return new GUSISIOUXSocket(fd); -} -// This declaration lies about the return type -extern "C" void SIOUXHandleOneEvent(EventRecord *userevent); - -bool GUSISIOUXSocket::initialized = false; - -GUSISIOUXSocket::GUSISIOUXSocket(int fd) : fFd(fd) -{ - if (!hasCustomConsole()) { - if (!PyMac_GetDelayConsoleFlag() && !initialized) - Initialize(); - /* Tell the upper layers there's no unseen output */ - PyMac_OutputSeen(); - } -} - -void -GUSISIOUXSocket::Initialize() -{ - if(!initialized && !hasCustomConsole()) - { - initialized = true; - InstallConsole(0); - GUSISetHook(GUSI_EventHook+nullEvent, (GUSIHook)SIOUXHandleOneEvent); - GUSISetHook(GUSI_EventHook+mouseDown, (GUSIHook)SIOUXHandleOneEvent); - GUSISetHook(GUSI_EventHook+mouseUp, (GUSIHook)SIOUXHandleOneEvent); - GUSISetHook(GUSI_EventHook+updateEvt, (GUSIHook)SIOUXHandleOneEvent); - GUSISetHook(GUSI_EventHook+diskEvt, (GUSIHook)SIOUXHandleOneEvent); - GUSISetHook(GUSI_EventHook+activateEvt, (GUSIHook)SIOUXHandleOneEvent); - GUSISetHook(GUSI_EventHook+osEvt, (GUSIHook)SIOUXHandleOneEvent); - PyMac_InitMenuBar(); - } -} -GUSISIOUXSocket::~GUSISIOUXSocket() -{ - if ( !initialized || hasCustomConsole() ) - return; - - initialized = false; - RemoveConsole(); -} -ssize_t GUSISIOUXSocket::read(const GUSIScatterer & buffer) -{ - if(hasCustomConsole()) - { - if(fFd == 0) - return buffer.SetLength( - sInConsole((char *) buffer.Buffer(), (int)buffer.Length())); - - return 0; - } - - if ( !initialized ) Initialize(); - GUSIStdioFlush(); - PyMac_OutputSeen(); - PyMac_RaiseConsoleWindow(); - return buffer.SetLength( - ReadCharsFromConsole((char *) buffer.Buffer(), (int)buffer.Length())); - GUSIContext::Yield(kGUSIPoll); -} -ssize_t GUSISIOUXSocket::write(const GUSIGatherer & buffer) -{ - if(hasCustomConsole()) - { - if(fFd == 1) - return sOutConsole((char *) buffer.Buffer(), (int)buffer.Length()); - else if(fFd == 2) - return sErrConsole((char *) buffer.Buffer(), (int)buffer.Length()); - - return 0; - } - - ssize_t rv; - - if ( !initialized ) Initialize(); - PyMac_OutputNotSeen(); - SIOUXUseWaitNextEvent = false; - rv = WriteCharsToConsole((char *) buffer.Buffer(), (int)buffer.Length()); - GUSIContext::Yield(kGUSIPoll); - return rv; -} -int GUSISIOUXSocket::ioctl(unsigned int request, va_list) -{ - switch (request) { - case FIOINTERACTIVE: - return 0; - default: - return GUSISetPosixError(EOPNOTSUPP); - } -} -int GUSISIOUXSocket::fstat(struct stat * buf) -{ - GUSISocket::fstat(buf); - buf->st_mode = S_IFCHR | 0666; - - return 0; -} -int GUSISIOUXSocket::isatty() -{ - return 1; -} -static bool input_pending() -{ - return false; -} - -bool GUSISIOUXSocket::select(bool * canRead, bool * canWrite, bool *) -{ - if ( !initialized ) Initialize(); - bool cond = false; - if (canRead) - if (*canRead = input_pending()) - cond = true; - if (canWrite) - cond = *canWrite = true; - - return cond; -} -GUSISIOUXDevice * GUSISIOUXDevice::sInstance; -GUSISIOUXDevice * GUSISIOUXDevice::Instance() -{ - if (!sInstance) - sInstance = new GUSISIOUXDevice(); - return sInstance; -} -bool GUSISIOUXDevice::Want(GUSIFileToken & file) -{ - switch (file.WhichRequest()) { - case GUSIFileToken::kWillOpen: - return file.IsDevice() && (file.StrStdStream(file.Path()) > -1); - default: - return false; - } -} -GUSISocket * GUSISIOUXDevice::open(GUSIFileToken &, int) -{ - return GUSISIOUXSocket::Instance(1); -} -void GUSISetupConsoleDescriptors() -{ - GUSIDescriptorTable * table = GUSIDescriptorTable::Instance(); - - table->InstallSocket(GUSISIOUXSocket::Instance(0)); - table->InstallSocket(GUSISIOUXSocket::Instance(1)); - table->InstallSocket(GUSISIOUXSocket::Instance(2)); -} - -void PyMac_SetConsoleHandler(PyReadHandler stdinH, PyWriteHandler stdoutH, PyWriteHandler stderrH) -{ - if(stdinH && stdoutH && stderrH) - { - sInConsole = stdinH; - sOutConsole = stdoutH; - sErrConsole = stderrH; - } -} - -long PyMac_DummyReadHandler(char *buffer, long n) -{ - return 0; -} - -long PyMac_DummyWriteHandler(char *buffer, long n) -{ - return 0; -} |