blob: 98298c8fcd6b541afb357ea72bf0fc2fe264bce8 [file] [log] [blame]
Guido van Rossumb0f3c821994-08-23 13:34:25 +00001/***********************************************************
Jack Jansen42218ce1997-01-31 16:15:11 +00002Copyright 1991-1997 by Stichting Mathematisch Centrum, Amsterdam,
Guido van Rossum99546991995-01-08 14:33:34 +00003The Netherlands.
Guido van Rossumb0f3c821994-08-23 13:34:25 +00004
5 All Rights Reserved
6
7Permission to use, copy, modify, and distribute this software and its
8documentation for any purpose and without fee is hereby granted,
9provided that the above copyright notice appear in all copies and that
10both that copyright notice and this permission notice appear in
11supporting documentation, and that the names of Stichting Mathematisch
12Centrum or CWI not be used in advertising or publicity pertaining to
13distribution of the software without specific, written prior permission.
14
15STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
16THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
18FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
20ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
21OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22
23******************************************************************/
24
Jack Jansen696c9581995-08-14 12:33:20 +000025/* Python interpreter main program */
Guido van Rossumb0f3c821994-08-23 13:34:25 +000026
Jack Jansen696c9581995-08-14 12:33:20 +000027#include "Python.h"
28#include "pythonresources.h"
29#include "import.h"
30#include "marshal.h"
Jack Jansenf6865f71996-09-04 15:24:59 +000031#include "macglue.h"
Guido van Rossumb0f3c821994-08-23 13:34:25 +000032
Jack Jansen696c9581995-08-14 12:33:20 +000033#include <Memory.h>
34#include <Resources.h>
Guido van Rossumb0f3c821994-08-23 13:34:25 +000035#include <stdio.h>
Jack Jansen696c9581995-08-14 12:33:20 +000036#include <Events.h>
37#include <Windows.h>
Jack Jansen2429c721996-03-07 15:17:11 +000038#include <Fonts.h>
Jack Jansen36b983c1997-09-09 13:53:21 +000039#include <Balloons.h>
Jack Jansen8f5725a1999-12-07 23:08:10 +000040#ifdef USE_APPEARANCE
41#include <Gestalt.h>
42#include <Appearance.h>
43#endif /* USE_APPEARANCE */
Jack Jansenc76fd391995-02-02 14:27:31 +000044#ifdef __MWERKS__
45#include <SIOUX.h>
Jack Jansen1e8557a1995-11-10 14:51:26 +000046#define USE_SIOUX
Jack Jansen8c693211997-01-07 16:19:42 +000047#if __profile__ == 1
48#include <profiler.h>
49#endif
Jack Jansenc76fd391995-02-02 14:27:31 +000050#endif
51
Jack Jansen0168f271995-10-27 13:32:30 +000052#ifdef THINK_C
53#include <console.h>
54#endif
55
Jack Jansen696c9581995-08-14 12:33:20 +000056#define STARTUP "PythonStartup"
Jack Jansenbac428d1994-12-14 13:47:30 +000057
Jack Jansen696c9581995-08-14 12:33:20 +000058extern int Py_DebugFlag; /* For parser.c, declared in pythonrun.c */
59extern int Py_VerboseFlag; /* For import.c, declared in pythonrun.c */
Jack Jansen3f7d2b41996-09-06 22:21:07 +000060short PyMac_AppRefNum; /* RefNum of application resource fork */
Jack Jansen696c9581995-08-14 12:33:20 +000061
Jack Jansen1d2f8631996-08-02 15:16:16 +000062/* For Py_GetArgcArgv(); set by main() */
Jack Jansen696c9581995-08-14 12:33:20 +000063static char **orig_argv;
64static int orig_argc;
65
Jack Jansen7d5f9e81996-09-07 17:09:31 +000066PyMac_PrefRecord options;
Jack Jansen0168f271995-10-27 13:32:30 +000067
Jack Jansen76ceece1996-08-19 11:18:24 +000068static void Py_Main Py_PROTO((int, char **)); /* Forward */
69void PyMac_Exit Py_PROTO((int)); /* Forward */
70
Jack Jansen8f5725a1999-12-07 23:08:10 +000071static void init_appearance()
72{
73#ifdef USE_APPEARANCE
74 OSErr err;
75 SInt32 response;
76
77 err = Gestalt(gestaltAppearanceAttr,&response);
78 if ( err ) goto no_appearance;
79 if ( !(response&(1<<gestaltAppearanceExists)) ) goto no_appearance;
80 /* XXXX Should we check the version? Compat-mode? */
81 PyMac_AppearanceCompliant = 1;
82no_appearance:
83 return;
84#endif /* USE_APPEARANCE */
85}
Jack Jansen01fbc681996-02-28 15:42:47 +000086/* Initialize the Mac toolbox world */
87
88static void
89init_mac_world()
90{
91#ifdef THINK_C
92 printf("\n");
93#else
94 MaxApplZone();
95 InitGraf(&qd.thePort);
96 InitFonts();
97 InitWindows();
98 TEInit();
99 InitDialogs((long)0);
100 InitMenus();
101 InitCursor();
Jack Jansen8f5725a1999-12-07 23:08:10 +0000102 init_appearance();
Jack Jansen01fbc681996-02-28 15:42:47 +0000103#endif
104}
105
Jack Jansen7d5f9e81996-09-07 17:09:31 +0000106/*
107** PyMac_InteractiveOptions - Allow user to set options if option key is pressed
108*/
Jack Jansen01fbc681996-02-28 15:42:47 +0000109static void
Jack Jansen7d5f9e81996-09-07 17:09:31 +0000110PyMac_InteractiveOptions(PyMac_PrefRecord *p, int *argcp, char ***argvp)
111{
112 KeyMap rmap;
113 unsigned char *map;
114 short item, type;
115 ControlHandle handle;
116 DialogPtr dialog;
117 Rect rect;
118 int old_argc = *argcp;
119 int i;
120
121 /*
122 ** If the preferences disallows interactive options we return,
123 ** similarly of <option> isn't pressed.
124 */
125 if (p->nointopt) return;
126
127 GetKeys(rmap);
128 map = (unsigned char *)rmap;
129 if ( ( map[0x3a>>3] & (1<<(0x3a&7)) ) == 0 ) /* option key is 3a */
130 return;
131
132 dialog = GetNewDialog(OPT_DIALOG, NULL, (WindowPtr)-1);
133 if ( dialog == NULL ) {
134 printf("Option dialog not found - cannot set options\n");
135 return;
136 }
137 SetDialogDefaultItem(dialog, OPT_OK);
138 SetDialogCancelItem(dialog, OPT_CANCEL);
139
140 /* Set default values */
141#define SET_OPT_ITEM(num, var) \
142 GetDialogItem(dialog, (num), &type, (Handle *)&handle, &rect); \
Jack Jansen08c3be31997-04-08 15:27:00 +0000143 SetControlValue(handle, (short)p->var);
Jack Jansen7d5f9e81996-09-07 17:09:31 +0000144
145 SET_OPT_ITEM(OPT_INSPECT, inspect);
146 SET_OPT_ITEM(OPT_VERBOSE, verbose);
Jack Jansen36b983c1997-09-09 13:53:21 +0000147 SET_OPT_ITEM(OPT_OPTIMIZE, optimize);
Jack Jansen7d5f9e81996-09-07 17:09:31 +0000148 SET_OPT_ITEM(OPT_UNBUFFERED, unbuffered);
149 SET_OPT_ITEM(OPT_DEBUGGING, debugging);
150 SET_OPT_ITEM(OPT_KEEPNORMAL, keep_normal);
151 SET_OPT_ITEM(OPT_KEEPERROR, keep_error);
Jack Jansen36b983c1997-09-09 13:53:21 +0000152 SET_OPT_ITEM(OPT_OLDEXC, oldexc);
153 SET_OPT_ITEM(OPT_NOSITE, nosite);
Jack Jansen7d5f9e81996-09-07 17:09:31 +0000154 /* The rest are not settable interactively */
155
156#undef SET_OPT_ITEM
157
158 while (1) {
159 handle = NULL;
160 ModalDialog(NULL, &item);
161 if ( item == OPT_OK )
162 break;
163 if ( item == OPT_CANCEL ) {
Jack Jansen08c3be31997-04-08 15:27:00 +0000164 DisposeDialog(dialog);
Jack Jansen7d5f9e81996-09-07 17:09:31 +0000165 exit(0);
166 }
Jack Jansen36b983c1997-09-09 13:53:21 +0000167 if ( item == OPT_HELP ) {
168 HMSetBalloons(!HMGetBalloons());
169 }
Jack Jansen7d5f9e81996-09-07 17:09:31 +0000170 if ( item == OPT_CMDLINE ) {
171 int new_argc, newer_argc;
172 char **new_argv, **newer_argv;
173
174 new_argc = ccommand(&new_argv);
175 newer_argc = (new_argc-1) + old_argc;
176 newer_argv = malloc((newer_argc+1)*sizeof(char *));
177 if( !newer_argv )
178 Py_FatalError("Cannot malloc argv\n");
179 for(i=0; i<old_argc; i++)
180 newer_argv[i] = (*argvp)[i];
181 for(i=old_argc; i<=newer_argc; i++) /* Copy the NULL too */
182 newer_argv[i] = new_argv[i-old_argc+1];
183 *argvp = newer_argv;
184 *argcp = newer_argc;
185
186 /* XXXX Is it not safe to use free() here, apparently */
187 }
188#define OPT_ITEM(num, var) \
189 if ( item == (num) ) { \
190 p->var = !p->var; \
191 GetDialogItem(dialog, (num), &type, (Handle *)&handle, &rect); \
Jack Jansen08c3be31997-04-08 15:27:00 +0000192 SetControlValue(handle, (short)p->var); \
Jack Jansen7d5f9e81996-09-07 17:09:31 +0000193 }
194
195 OPT_ITEM(OPT_INSPECT, inspect);
196 OPT_ITEM(OPT_VERBOSE, verbose);
Jack Jansen36b983c1997-09-09 13:53:21 +0000197 OPT_ITEM(OPT_OPTIMIZE, optimize);
Jack Jansen7d5f9e81996-09-07 17:09:31 +0000198 OPT_ITEM(OPT_UNBUFFERED, unbuffered);
199 OPT_ITEM(OPT_DEBUGGING, debugging);
200 OPT_ITEM(OPT_KEEPNORMAL, keep_normal);
201 OPT_ITEM(OPT_KEEPERROR, keep_error);
Jack Jansen36b983c1997-09-09 13:53:21 +0000202 OPT_ITEM(OPT_OLDEXC, oldexc);
203 OPT_ITEM(OPT_NOSITE, nosite);
Jack Jansen7d5f9e81996-09-07 17:09:31 +0000204
205#undef OPT_ITEM
206 }
Jack Jansen08c3be31997-04-08 15:27:00 +0000207 DisposeDialog(dialog);
Jack Jansen7d5f9e81996-09-07 17:09:31 +0000208}
209
210/*
211** Initialization code, shared by interpreter and applets
212*/
213static void
Jack Jansen52ac0371997-01-15 15:49:08 +0000214init_common(int *argcp, char ***argvp, int embedded)
Jack Jansen01fbc681996-02-28 15:42:47 +0000215{
Jack Jansen3f7d2b41996-09-06 22:21:07 +0000216 /* Remember resource fork refnum, for later */
217 PyMac_AppRefNum = CurResFile();
218
Jack Jansen01fbc681996-02-28 15:42:47 +0000219 /* Initialize toolboxes */
220 init_mac_world();
221
222#ifdef USE_MAC_SHARED_LIBRARY
223 /* Add the shared library to the stack of resource files */
Jack Jansen87c485c1998-07-31 09:38:01 +0000224 (void)PyMac_init_process_location();
Jack Jansen01fbc681996-02-28 15:42:47 +0000225 PyMac_AddLibResources();
226#endif
227
Jack Jansen2d1306b2000-04-07 09:10:49 +0000228#if defined(USE_GUSI1)
Jack Jansen01fbc681996-02-28 15:42:47 +0000229 /* Setup GUSI */
230 GUSIDefaultSetup();
Jack Jansenf6865f71996-09-04 15:24:59 +0000231 PyMac_SetGUSISpin();
Jack Jansen3f7d2b41996-09-06 22:21:07 +0000232 PyMac_SetGUSIOptions();
Jack Jansen01fbc681996-02-28 15:42:47 +0000233#endif
Jack Jansen2d1306b2000-04-07 09:10:49 +0000234#if defined(USE_GUSI)
235 atexit(PyMac_StopGUSISpin);
236#endif
Jack Jansen01fbc681996-02-28 15:42:47 +0000237
238#ifdef USE_SIOUX
239 /* Set various SIOUX flags. Some are changed later based on options */
Jack Jansencaa7c461997-06-12 10:49:13 +0000240/* SIOUXSettings.standalone = 0; /* XXXX Attempting to keep sioux from eating events */
Jack Jansen01fbc681996-02-28 15:42:47 +0000241 SIOUXSettings.asktosaveonclose = 0;
242 SIOUXSettings.showstatusline = 0;
243 SIOUXSettings.tabspaces = 4;
244#endif
245
Jack Jansen7d5f9e81996-09-07 17:09:31 +0000246 /* Get options from preference file (or from applet resource fork) */
247 options.keep_error = 1; /* default-default */
248 PyMac_PreferenceOptions(&options);
249
Jack Jansen52ac0371997-01-15 15:49:08 +0000250 if ( embedded ) {
251 static char *emb_argv[] = {"embedded-python", 0};
252
253 *argcp = 1;
254 *argvp = emb_argv;
255 } else {
256 /* Create argc/argv. Do it before we go into the options event loop. */
257 *argcp = PyMac_GetArgv(argvp, options.noargs);
258
259 /* Do interactive option setting, if allowed and <option> depressed */
260 PyMac_InteractiveOptions(&options, argcp, argvp);
261 }
Jack Jansen7d5f9e81996-09-07 17:09:31 +0000262
263 /* Copy selected options to where the machine-independent stuff wants it */
264 Py_VerboseFlag = options.verbose;
Jack Jansen7330b391997-08-08 14:56:41 +0000265/* Py_SuppressPrintingFlag = options.suppress_print; */
Jack Jansen36b983c1997-09-09 13:53:21 +0000266 Py_OptimizeFlag = options.optimize;
Jack Jansen7d5f9e81996-09-07 17:09:31 +0000267 Py_DebugFlag = options.debugging;
Jack Jansena7a89eb1997-10-07 21:48:57 +0000268 Py_NoSiteFlag = options.nosite;
269 Py_UseClassExceptionsFlag = !(options.oldexc);
Jack Jansene3ae0df1997-06-03 15:28:29 +0000270 if ( options.noargs ) {
271 /* don't process events at all without the scripts permission */
272 PyMacSchedParams scp;
273
274 PyMac_GetSchedParams(&scp);
275 scp.process_events = 0;
276 /* Should we disable command-dot as well? */
277 PyMac_SetSchedParams(&scp);
278 }
Jack Jansen36b983c1997-09-09 13:53:21 +0000279 /* XXXX dispatch oldexc and nosite */
Jack Jansen7d5f9e81996-09-07 17:09:31 +0000280
281 /* Set buffering */
282 if (options.unbuffered) {
283#ifndef MPW
284 setbuf(stdout, (char *)NULL);
285 setbuf(stderr, (char *)NULL);
286#else
287 /* On MPW (3.2) unbuffered seems to hang */
288 setvbuf(stdout, (char *)NULL, _IOLBF, BUFSIZ);
289 setvbuf(stderr, (char *)NULL, _IOLBF, BUFSIZ);
290#endif
291 }
Jack Jansen8c693211997-01-07 16:19:42 +0000292#if __profile__ == 1
293 /* collectSummary or collectDetailed, timebase, #routines, max stack depth */
Jack Jansene7424871999-09-30 11:20:11 +0000294 ProfilerInit(collectSummary, bestTimeBase, 8000, 250);
Jack Jansen8c693211997-01-07 16:19:42 +0000295#endif
Jack Jansen7330b391997-08-08 14:56:41 +0000296
297 /* Tell the rest of python about our argc/argv */
298 orig_argc = *argcp; /* For Py_GetArgcArgv() */
299 orig_argv = *argvp;
300 Py_SetProgramName((*argvp)[0]);
Jack Jansen01fbc681996-02-28 15:42:47 +0000301}
302
Jack Jansen7d5f9e81996-09-07 17:09:31 +0000303/*
304** Inspection mode after script/applet termination
305*/
306static int
307run_inspect()
308{
309 int sts = 0;
310
311 if (options.inspect && isatty((int)fileno(stdin)))
312 sts = PyRun_AnyFile(stdin, "<stdin>") != 0;
313 return sts;
314}
Jack Jansen01fbc681996-02-28 15:42:47 +0000315
Jack Jansen696c9581995-08-14 12:33:20 +0000316#ifdef USE_MAC_APPLET_SUPPORT
317/* Applet support */
318
319/* Run a compiled Python Python script from 'PYC ' resource __main__ */
320static int
321run_main_resource()
322{
323 Handle h;
324 long size;
325 PyObject *code;
326 PyObject *result;
327
328 h = GetNamedResource('PYC ', "\p__main__");
329 if (h == NULL) {
330 Alert(NOPYC_ALERT, NULL);
331 return 1;
332 }
333 size = GetResourceSizeOnDisk(h);
334 HLock(h);
335 code = PyMarshal_ReadObjectFromString(*h + 8, (int)(size - 8));
336 HUnlock(h);
337 ReleaseResource(h);
338 if (code == NULL) {
339 PyErr_Print();
340 return 1;
341 }
342 result = PyImport_ExecCodeModule("__main__", code);
343 Py_DECREF(code);
344 if (result == NULL) {
345 PyErr_Print();
346 return 1;
347 }
348 Py_DECREF(result);
349 return 0;
350}
351
352/* Initialization sequence for applets */
353void
354PyMac_InitApplet()
355{
Guido van Rossumb0f3c821994-08-23 13:34:25 +0000356 int argc;
357 char **argv;
Jack Jansen696c9581995-08-14 12:33:20 +0000358 int err;
359
Jack Jansen52ac0371997-01-15 15:49:08 +0000360 init_common(&argc, &argv, 0);
Jack Jansen7d5f9e81996-09-07 17:09:31 +0000361
Jack Jansen696c9581995-08-14 12:33:20 +0000362 Py_Initialize();
363 PySys_SetArgv(argc, argv);
Jack Jansen7d5f9e81996-09-07 17:09:31 +0000364
Jack Jansen696c9581995-08-14 12:33:20 +0000365 err = run_main_resource();
Jack Jansen7d5f9e81996-09-07 17:09:31 +0000366
367 err = (run_inspect() || err);
368
Jack Jansen696c9581995-08-14 12:33:20 +0000369 fflush(stderr);
370 fflush(stdout);
Jack Jansen0168f271995-10-27 13:32:30 +0000371 PyMac_Exit(err);
Jack Jansen696c9581995-08-14 12:33:20 +0000372 /* XXX Should we bother to Py_Exit(sts)? */
373}
374
Jack Jansen52ac0371997-01-15 15:49:08 +0000375/*
376** Hook for embedding python.
377*/
378void
379PyMac_Initialize()
380{
381 int argc;
382 char **argv;
383
384 init_common(&argc, &argv, 1);
385 Py_Initialize();
386 PySys_SetArgv(argc, argv);
387}
388
Jack Jansen696c9581995-08-14 12:33:20 +0000389#endif /* USE_MAC_APPLET_SUPPORT */
390
391/* For normal application */
392void
393PyMac_InitApplication()
394{
395 int argc;
396 char **argv;
397
Jack Jansen52ac0371997-01-15 15:49:08 +0000398 init_common(&argc, &argv, 0);
Jack Jansen7d5f9e81996-09-07 17:09:31 +0000399
Jack Jansen696c9581995-08-14 12:33:20 +0000400 if ( argc > 1 ) {
401 /* We're running a script. Attempt to change current directory */
402 char curwd[256], *endp;
403
404 strcpy(curwd, argv[1]);
405 endp = strrchr(curwd, ':');
406 if ( endp && endp > curwd ) {
407 *endp = '\0';
408
409 chdir(curwd);
Jack Jansen2d1306b2000-04-07 09:10:49 +0000410#ifdef USE_GUSI1
Jack Jansen378815c1996-03-06 16:21:34 +0000411 /* Change MacOS's idea of wd too */
412 PyMac_FixGUSIcd();
413#endif
Jack Jansen696c9581995-08-14 12:33:20 +0000414 }
415 }
416 Py_Main(argc, argv);
417}
418
Jack Jansen696c9581995-08-14 12:33:20 +0000419/* Main program */
420
Jack Jansen76ceece1996-08-19 11:18:24 +0000421static void
Jack Jansen696c9581995-08-14 12:33:20 +0000422Py_Main(argc, argv)
423 int argc;
424 char **argv;
425{
Jack Jansen696c9581995-08-14 12:33:20 +0000426 int sts;
427 char *command = NULL;
428 char *filename = NULL;
429 FILE *fp = stdin;
Jack Jansen696c9581995-08-14 12:33:20 +0000430
Jack Jansen696c9581995-08-14 12:33:20 +0000431 filename = argv[1];
432
433 if (Py_VerboseFlag ||
434 command == NULL && filename == NULL && isatty((int)fileno(fp)))
435 fprintf(stderr, "Python %s\n%s\n",
Jack Jansena547dca1996-07-10 15:48:25 +0000436 Py_GetVersion(), Py_GetCopyright());
Jack Jansen696c9581995-08-14 12:33:20 +0000437
438 if (filename != NULL) {
439 if ((fp = fopen(filename, "r")) == NULL) {
440 fprintf(stderr, "%s: can't open file '%s'\n",
441 argv[0], filename);
Jack Jansen0168f271995-10-27 13:32:30 +0000442 PyMac_Exit(2);
Jack Jansen696c9581995-08-14 12:33:20 +0000443 }
444 }
445
Jack Jansen7d5f9e81996-09-07 17:09:31 +0000446 /* We initialize the menubar here, hoping SIOUX is initialized by now */
Jack Jansen3469e991996-09-06 00:30:45 +0000447 PyMac_InitMenuBar();
448
Jack Jansen696c9581995-08-14 12:33:20 +0000449 Py_Initialize();
450
451 PySys_SetArgv(argc-1, argv+1);
452
453 if (filename == NULL && isatty((int)fileno(fp))) {
454 FILE *fp = fopen(STARTUP, "r");
455 if (fp != NULL) {
456 (void) PyRun_SimpleFile(fp, STARTUP);
457 PyErr_Clear();
458 fclose(fp);
459 }
460 }
461 sts = PyRun_AnyFile(
462 fp, filename == NULL ? "<stdin>" : filename) != 0;
463 if (filename != NULL)
464 fclose(fp);
Jack Jansen7d5f9e81996-09-07 17:09:31 +0000465
466 if ( filename != NULL || command != NULL )
467 sts = (run_inspect() || sts);
Jack Jansen696c9581995-08-14 12:33:20 +0000468
469 Py_Exit(sts);
470 /*NOTREACHED*/
471}
472
Jack Jansen0168f271995-10-27 13:32:30 +0000473/*
474** Terminate application
475*/
Jack Jansen76ceece1996-08-19 11:18:24 +0000476void
Jack Jansen0168f271995-10-27 13:32:30 +0000477PyMac_Exit(status)
478 int status;
479{
480 int keep;
Jack Jansen8c693211997-01-07 16:19:42 +0000481
482#if __profile__ == 1
483 ProfilerDump("\pPython Profiler Results");
484 ProfilerTerm();
485#endif
Jack Jansen0168f271995-10-27 13:32:30 +0000486 if ( status )
Jack Jansen7d5f9e81996-09-07 17:09:31 +0000487 keep = options.keep_error;
Jack Jansen0168f271995-10-27 13:32:30 +0000488 else
Jack Jansen7d5f9e81996-09-07 17:09:31 +0000489 keep = options.keep_normal;
Jack Jansen0168f271995-10-27 13:32:30 +0000490
Jack Jansen1e8557a1995-11-10 14:51:26 +0000491#ifdef USE_SIOUX
492 if (keep) {
493 SIOUXSettings.standalone = 1;
494 SIOUXSettings.autocloseonquit = 0;
Jack Jansen415571c1996-03-25 15:46:03 +0000495 SIOUXSetTitle("\p\307terminated\310");
Jack Jansencaa7c461997-06-12 10:49:13 +0000496 PyMac_RestoreMenuBar();
Jack Jansene44545f1997-05-07 15:48:54 +0000497#ifdef USE_MSL
498 /*
499 ** Temporary workaround: autocloseonquit clearing does not
500 ** currently work for the MSL/GUSI combo.
501 */
502 while(getchar() > 0);
503#endif
Jack Jansen1e8557a1995-11-10 14:51:26 +0000504 }
Jack Jansen0168f271995-10-27 13:32:30 +0000505 else
506 SIOUXSettings.autocloseonquit = 1;
Jack Jansenf6865f71996-09-04 15:24:59 +0000507#endif /* USE_SIOUX */
Jack Jansen0168f271995-10-27 13:32:30 +0000508#ifdef THINK_C
509 console_options.pause_atexit = keep;
510#endif
511
512 exit(status);
513}
Jack Jansen696c9581995-08-14 12:33:20 +0000514
515/* Return the program name -- some code out there needs this. */
Jack Jansena39f1b01997-05-23 15:35:14 +0000516char *
517Py_GetProgramFullPath()
518{
Jack Jansen7330b391997-08-08 14:56:41 +0000519 return orig_argv[0];
Jack Jansena39f1b01997-05-23 15:35:14 +0000520}
521
Jack Jansen696c9581995-08-14 12:33:20 +0000522
523/* Make the *original* argc/argv available to other modules.
524 This is rare, but it is needed by the secureware extension. */
525
526void
Jack Jansen1d2f8631996-08-02 15:16:16 +0000527Py_GetArgcArgv(argc,argv)
Jack Jansen696c9581995-08-14 12:33:20 +0000528 int *argc;
529 char ***argv;
530{
531 *argc = orig_argc;
532 *argv = orig_argv;
Guido van Rossumb0f3c821994-08-23 13:34:25 +0000533}
Jack Jansen1d2f8631996-08-02 15:16:16 +0000534
535/* More cruft that shouldn't really be here, used in sysmodule.c */
536
537char *
538Py_GetPrefix()
539{
Jack Jansenac625691997-09-08 13:22:22 +0000540 return PyMac_GetPythonDir();
Jack Jansen1d2f8631996-08-02 15:16:16 +0000541}
542
543char *
544Py_GetExecPrefix()
545{
Jack Jansenac625691997-09-08 13:22:22 +0000546 return PyMac_GetPythonDir();
Jack Jansen1d2f8631996-08-02 15:16:16 +0000547}