From 7d5f9e847a75c65f97068b3fd7980e62717c16fc Mon Sep 17 00:00:00 2001 From: Jack Jansen Date: Sat, 7 Sep 1996 17:09:31 +0000 Subject: - Put all options in a struct - Unified initialization code for interpreter and applet - Implemented new options to skip AE-processing for argc/argv and for disabling interactive option setting --- Mac/Include/pythonresources.h | 16 ++- Mac/Python/macgetargv.c | 11 +- Mac/Python/macgetpath.c | 21 ++- Mac/Python/macglue.c | 6 +- Mac/Python/macmain.c | 298 +++++++++++++++++++++++------------------- 5 files changed, 196 insertions(+), 156 deletions(-) diff --git a/Mac/Include/pythonresources.h b/Mac/Include/pythonresources.h index 02607bd..514eb40 100644 --- a/Mac/Include/pythonresources.h +++ b/Mac/Include/pythonresources.h @@ -95,13 +95,23 @@ #define POPT_NOINTOPT 7 /* Not settable interactively */ #define POPT_NOARGS 8 /* Not settable interactively */ +typedef struct PyMac_PrefRecord { + unsigned char inspect; + unsigned char verbose; + unsigned char suppress_print; + unsigned char unbuffered; + unsigned char debugging; + unsigned char keep_normal; + unsigned char keep_error; + unsigned char nointopt; + unsigned char noargs; +} PyMac_PrefRecord; + /* The GUSI options resources */ #define GUSIOPTIONS_ID 10240 #define GUSIOPTIONSOVERRIDE_ID 10241 /* From macgetpath.c: */ -void PyMac_PreferenceOptions Py_PROTO((int *inspect, int *verbose, int *suppress_print, - int *unbuffered, int *debugging, int *keep_normal, - int *keep_error)); +void PyMac_PreferenceOptions Py_PROTO((PyMac_PrefRecord *)); diff --git a/Mac/Python/macgetargv.c b/Mac/Python/macgetargv.c index a06b100..e0ecb8e 100644 --- a/Mac/Python/macgetargv.c +++ b/Mac/Python/macgetargv.c @@ -295,16 +295,19 @@ event_loop() /* Get the argv vector, return argc */ int -PyMac_GetArgv(pargv) +PyMac_GetArgv(pargv, noevents) char ***pargv; + int noevents; { arg_count = 0; arg_vector[arg_count++] = strdup(get_application_name()); - set_ae_handlers(); - event_loop(); - reset_ae_handlers(); + if( !noevents ) { + set_ae_handlers(); + event_loop(); + reset_ae_handlers(); + } arg_vector[arg_count] = NULL; diff --git a/Mac/Python/macgetpath.c b/Mac/Python/macgetpath.c index 5c2cafd..466f073 100644 --- a/Mac/Python/macgetpath.c +++ b/Mac/Python/macgetpath.c @@ -310,9 +310,7 @@ out: #endif /* !USE_BUILTIN_PATH */ void -PyMac_PreferenceOptions(int *inspect, int *verbose, int *suppress_print, - int *unbuffered, int *debugging, int *keep_normal, - int *keep_error) +PyMac_PreferenceOptions(PyMac_PrefRecord *pr) { short oldrh, prefrh = -1; Handle handle; @@ -339,14 +337,15 @@ PyMac_PreferenceOptions(int *inspect, int *verbose, int *suppress_print, size = GetHandleSize(handle); p = (char *)*handle; - if ( size > POPT_INSPECT ) *inspect = p[POPT_INSPECT]; - if ( size > POPT_VERBOSE ) *verbose = p[POPT_VERBOSE]; - if ( size > POPT_SUPPRESS ) *suppress_print = p[POPT_SUPPRESS]; - if ( size > POPT_UNBUFFERED ) *unbuffered = p[POPT_UNBUFFERED]; - if ( size > POPT_DEBUGGING ) *debugging = p[POPT_DEBUGGING]; - if ( size > POPT_KEEPNORM ) *keep_normal = p[POPT_KEEPNORM]; - if ( size > POPT_KEEPERR ) *keep_error = p[POPT_KEEPERR]; - /* The rest are not implemented yet */ + if ( size > POPT_INSPECT ) pr->inspect = p[POPT_INSPECT]; + if ( size > POPT_VERBOSE ) pr->verbose = p[POPT_VERBOSE]; + if ( size > POPT_SUPPRESS ) pr->suppress_print = p[POPT_SUPPRESS]; + if ( size > POPT_UNBUFFERED ) pr->unbuffered = p[POPT_UNBUFFERED]; + if ( size > POPT_DEBUGGING ) pr->debugging = p[POPT_DEBUGGING]; + if ( size > POPT_KEEPNORM ) pr->keep_normal = p[POPT_KEEPNORM]; + if ( size > POPT_KEEPERR ) pr->keep_error = p[POPT_KEEPERR]; + if ( size > POPT_NOINTOPT ) pr->nointopt = p[POPT_NOINTOPT]; + if ( size > POPT_NOARGS ) pr->noargs = p[POPT_NOARGS]; HUnlock(handle); diff --git a/Mac/Python/macglue.c b/Mac/Python/macglue.c index 17bbff0..3df1a8a 100644 --- a/Mac/Python/macglue.c +++ b/Mac/Python/macglue.c @@ -178,9 +178,11 @@ PyMac_FixGUSIcd() return; } -#ifdef __CFM68K__ +/* +** SpinCursor (needed by GUSI) drags in heaps of stuff, so we +** provide a dummy here. +*/ void SpinCursor(short x) { /* Dummy */ } -#endif /* __CFM68K */ /* ** Replacement GUSI Spin function diff --git a/Mac/Python/macmain.c b/Mac/Python/macmain.c index 095673e..b464872 100644 --- a/Mac/Python/macmain.c +++ b/Mac/Python/macmain.c @@ -60,16 +60,15 @@ extern char *Py_GetVersion Py_PROTO((void)); extern char *Py_GetCopyright Py_PROTO((void)); -/* For Py_GetProgramName(); set by main() */ -static char *argv0; +/* #define OBSOLETE_ARGCARGV 1 /* I think this is not needed anymore... */ +#ifdef OBSOLETE_ARGCARGV /* For Py_GetArgcArgv(); set by main() */ static char **orig_argv; static int orig_argc; +#endif -/* Flags indicating whether stdio window should stay open on termination */ -static int keep_normal; -static int keep_error = 1; +PyMac_PrefRecord options; static void Py_Main Py_PROTO((int, char **)); /* Forward */ void PyMac_Exit Py_PROTO((int)); /* Forward */ @@ -93,10 +92,108 @@ init_mac_world() #endif } -/* Initialization code shared by interpreter and applets */ +/* +** 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; + int old_argc = *argcp; + int i; + + /* + ** If the preferences disallows interactive options we return, + ** similarly of