Guido van Rossum | b0f3c82 | 1994-08-23 13:34:25 +0000 | [diff] [blame] | 1 | /*********************************************************** |
Guido van Rossum | 9954699 | 1995-01-08 14:33:34 +0000 | [diff] [blame] | 2 | Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam, |
| 3 | The Netherlands. |
Guido van Rossum | b0f3c82 | 1994-08-23 13:34:25 +0000 | [diff] [blame] | 4 | |
| 5 | All Rights Reserved |
| 6 | |
| 7 | Permission to use, copy, modify, and distribute this software and its |
| 8 | documentation for any purpose and without fee is hereby granted, |
| 9 | provided that the above copyright notice appear in all copies and that |
| 10 | both that copyright notice and this permission notice appear in |
| 11 | supporting documentation, and that the names of Stichting Mathematisch |
| 12 | Centrum or CWI not be used in advertising or publicity pertaining to |
| 13 | distribution of the software without specific, written prior permission. |
| 14 | |
| 15 | STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO |
| 16 | THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND |
| 17 | FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE |
| 18 | FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 19 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 20 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT |
| 21 | OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 22 | |
| 23 | ******************************************************************/ |
| 24 | |
Jack Jansen | 696c958 | 1995-08-14 12:33:20 +0000 | [diff] [blame] | 25 | /* Python interpreter main program */ |
Guido van Rossum | b0f3c82 | 1994-08-23 13:34:25 +0000 | [diff] [blame] | 26 | |
Jack Jansen | 696c958 | 1995-08-14 12:33:20 +0000 | [diff] [blame] | 27 | #include "Python.h" |
| 28 | #include "pythonresources.h" |
| 29 | #include "import.h" |
| 30 | #include "marshal.h" |
Jack Jansen | f6865f7 | 1996-09-04 15:24:59 +0000 | [diff] [blame^] | 31 | #include "macglue.h" |
Guido van Rossum | b0f3c82 | 1994-08-23 13:34:25 +0000 | [diff] [blame] | 32 | |
Jack Jansen | 696c958 | 1995-08-14 12:33:20 +0000 | [diff] [blame] | 33 | #include <Memory.h> |
| 34 | #include <Resources.h> |
Guido van Rossum | b0f3c82 | 1994-08-23 13:34:25 +0000 | [diff] [blame] | 35 | #include <stdio.h> |
Jack Jansen | 696c958 | 1995-08-14 12:33:20 +0000 | [diff] [blame] | 36 | #include <Events.h> |
| 37 | #include <Windows.h> |
| 38 | #include <Desk.h> |
Jack Jansen | 2429c72 | 1996-03-07 15:17:11 +0000 | [diff] [blame] | 39 | #include <Fonts.h> |
Guido van Rossum | b0f3c82 | 1994-08-23 13:34:25 +0000 | [diff] [blame] | 40 | |
Jack Jansen | c76fd39 | 1995-02-02 14:27:31 +0000 | [diff] [blame] | 41 | #ifdef __MWERKS__ |
| 42 | #include <SIOUX.h> |
Jack Jansen | 1e8557a | 1995-11-10 14:51:26 +0000 | [diff] [blame] | 43 | #define USE_SIOUX |
Jack Jansen | c76fd39 | 1995-02-02 14:27:31 +0000 | [diff] [blame] | 44 | #endif |
| 45 | |
Jack Jansen | 0168f27 | 1995-10-27 13:32:30 +0000 | [diff] [blame] | 46 | #ifdef THINK_C |
| 47 | #include <console.h> |
| 48 | #endif |
| 49 | |
Jack Jansen | 696c958 | 1995-08-14 12:33:20 +0000 | [diff] [blame] | 50 | #define STARTUP "PythonStartup" |
Jack Jansen | bac428d | 1994-12-14 13:47:30 +0000 | [diff] [blame] | 51 | |
Jack Jansen | 696c958 | 1995-08-14 12:33:20 +0000 | [diff] [blame] | 52 | extern int Py_DebugFlag; /* For parser.c, declared in pythonrun.c */ |
| 53 | extern int Py_VerboseFlag; /* For import.c, declared in pythonrun.c */ |
| 54 | extern int Py_SuppressPrintingFlag; /* For ceval.c, declared in pythonrun.c */ |
| 55 | |
| 56 | |
| 57 | /* Subroutines that live in their own file */ |
Jack Jansen | a547dca | 1996-07-10 15:48:25 +0000 | [diff] [blame] | 58 | extern char *Py_GetVersion Py_PROTO((void)); |
| 59 | extern char *Py_GetCopyright Py_PROTO((void)); |
Jack Jansen | 696c958 | 1995-08-14 12:33:20 +0000 | [diff] [blame] | 60 | |
| 61 | |
Jack Jansen | 1d2f863 | 1996-08-02 15:16:16 +0000 | [diff] [blame] | 62 | /* For Py_GetProgramName(); set by main() */ |
Jack Jansen | 696c958 | 1995-08-14 12:33:20 +0000 | [diff] [blame] | 63 | static char *argv0; |
| 64 | |
Jack Jansen | 1d2f863 | 1996-08-02 15:16:16 +0000 | [diff] [blame] | 65 | /* For Py_GetArgcArgv(); set by main() */ |
Jack Jansen | 696c958 | 1995-08-14 12:33:20 +0000 | [diff] [blame] | 66 | static char **orig_argv; |
| 67 | static int orig_argc; |
| 68 | |
Jack Jansen | 0168f27 | 1995-10-27 13:32:30 +0000 | [diff] [blame] | 69 | /* Flags indicating whether stdio window should stay open on termination */ |
| 70 | static int keep_normal; |
| 71 | static int keep_error = 1; |
| 72 | |
Jack Jansen | 76ceece | 1996-08-19 11:18:24 +0000 | [diff] [blame] | 73 | static void Py_Main Py_PROTO((int, char **)); /* Forward */ |
| 74 | void PyMac_Exit Py_PROTO((int)); /* Forward */ |
| 75 | |
Jack Jansen | 01fbc68 | 1996-02-28 15:42:47 +0000 | [diff] [blame] | 76 | /* Initialize the Mac toolbox world */ |
| 77 | |
| 78 | static void |
| 79 | init_mac_world() |
| 80 | { |
| 81 | #ifdef THINK_C |
| 82 | printf("\n"); |
| 83 | #else |
| 84 | MaxApplZone(); |
| 85 | InitGraf(&qd.thePort); |
| 86 | InitFonts(); |
| 87 | InitWindows(); |
| 88 | TEInit(); |
| 89 | InitDialogs((long)0); |
| 90 | InitMenus(); |
| 91 | InitCursor(); |
| 92 | #endif |
| 93 | } |
| 94 | |
| 95 | /* Initialization code shared by interpreter and applets */ |
| 96 | |
| 97 | static void |
| 98 | init_common() |
| 99 | { |
| 100 | |
| 101 | /* Initialize toolboxes */ |
| 102 | init_mac_world(); |
| 103 | |
| 104 | #ifdef USE_MAC_SHARED_LIBRARY |
| 105 | /* Add the shared library to the stack of resource files */ |
| 106 | PyMac_AddLibResources(); |
| 107 | #endif |
| 108 | |
| 109 | #if defined(USE_GUSI) |
| 110 | /* Setup GUSI */ |
| 111 | GUSIDefaultSetup(); |
Jack Jansen | f6865f7 | 1996-09-04 15:24:59 +0000 | [diff] [blame^] | 112 | PyMac_SetGUSISpin(); |
Jack Jansen | 01fbc68 | 1996-02-28 15:42:47 +0000 | [diff] [blame] | 113 | #endif |
| 114 | |
| 115 | #ifdef USE_SIOUX |
| 116 | /* Set various SIOUX flags. Some are changed later based on options */ |
| 117 | SIOUXSettings.asktosaveonclose = 0; |
| 118 | SIOUXSettings.showstatusline = 0; |
| 119 | SIOUXSettings.tabspaces = 4; |
| 120 | #endif |
| 121 | |
| 122 | } |
| 123 | |
| 124 | |
Jack Jansen | 696c958 | 1995-08-14 12:33:20 +0000 | [diff] [blame] | 125 | #ifdef USE_MAC_APPLET_SUPPORT |
| 126 | /* Applet support */ |
| 127 | |
| 128 | /* Run a compiled Python Python script from 'PYC ' resource __main__ */ |
| 129 | static int |
| 130 | run_main_resource() |
| 131 | { |
| 132 | Handle h; |
| 133 | long size; |
| 134 | PyObject *code; |
| 135 | PyObject *result; |
| 136 | |
| 137 | h = GetNamedResource('PYC ', "\p__main__"); |
| 138 | if (h == NULL) { |
| 139 | Alert(NOPYC_ALERT, NULL); |
| 140 | return 1; |
| 141 | } |
| 142 | size = GetResourceSizeOnDisk(h); |
| 143 | HLock(h); |
| 144 | code = PyMarshal_ReadObjectFromString(*h + 8, (int)(size - 8)); |
| 145 | HUnlock(h); |
| 146 | ReleaseResource(h); |
| 147 | if (code == NULL) { |
| 148 | PyErr_Print(); |
| 149 | return 1; |
| 150 | } |
| 151 | result = PyImport_ExecCodeModule("__main__", code); |
| 152 | Py_DECREF(code); |
| 153 | if (result == NULL) { |
| 154 | PyErr_Print(); |
| 155 | return 1; |
| 156 | } |
| 157 | Py_DECREF(result); |
| 158 | return 0; |
| 159 | } |
| 160 | |
| 161 | /* Initialization sequence for applets */ |
| 162 | void |
| 163 | PyMac_InitApplet() |
| 164 | { |
Guido van Rossum | b0f3c82 | 1994-08-23 13:34:25 +0000 | [diff] [blame] | 165 | int argc; |
| 166 | char **argv; |
Jack Jansen | 696c958 | 1995-08-14 12:33:20 +0000 | [diff] [blame] | 167 | int err; |
| 168 | |
Jack Jansen | 01fbc68 | 1996-02-28 15:42:47 +0000 | [diff] [blame] | 169 | init_common(); |
Jack Jansen | 696c958 | 1995-08-14 12:33:20 +0000 | [diff] [blame] | 170 | argc = PyMac_GetArgv(&argv); |
| 171 | Py_Initialize(); |
| 172 | PySys_SetArgv(argc, argv); |
| 173 | err = run_main_resource(); |
| 174 | fflush(stderr); |
| 175 | fflush(stdout); |
Jack Jansen | 0168f27 | 1995-10-27 13:32:30 +0000 | [diff] [blame] | 176 | PyMac_Exit(err); |
Jack Jansen | 696c958 | 1995-08-14 12:33:20 +0000 | [diff] [blame] | 177 | /* XXX Should we bother to Py_Exit(sts)? */ |
| 178 | } |
| 179 | |
| 180 | #endif /* USE_MAC_APPLET_SUPPORT */ |
| 181 | |
| 182 | /* For normal application */ |
| 183 | void |
| 184 | PyMac_InitApplication() |
| 185 | { |
| 186 | int argc; |
| 187 | char **argv; |
| 188 | |
Jack Jansen | 01fbc68 | 1996-02-28 15:42:47 +0000 | [diff] [blame] | 189 | init_common(); |
Jack Jansen | 696c958 | 1995-08-14 12:33:20 +0000 | [diff] [blame] | 190 | argc = PyMac_GetArgv(&argv); |
| 191 | if ( argc > 1 ) { |
| 192 | /* We're running a script. Attempt to change current directory */ |
| 193 | char curwd[256], *endp; |
| 194 | |
| 195 | strcpy(curwd, argv[1]); |
| 196 | endp = strrchr(curwd, ':'); |
| 197 | if ( endp && endp > curwd ) { |
| 198 | *endp = '\0'; |
| 199 | |
| 200 | chdir(curwd); |
Jack Jansen | 378815c | 1996-03-06 16:21:34 +0000 | [diff] [blame] | 201 | #ifdef USE_GUSI |
| 202 | /* Change MacOS's idea of wd too */ |
| 203 | PyMac_FixGUSIcd(); |
| 204 | #endif |
Jack Jansen | 696c958 | 1995-08-14 12:33:20 +0000 | [diff] [blame] | 205 | } |
| 206 | } |
| 207 | Py_Main(argc, argv); |
| 208 | } |
| 209 | |
| 210 | /* |
| 211 | ** PyMac_InteractiveOptions - Allow user to set options if option key is pressed |
| 212 | */ |
| 213 | void |
| 214 | PyMac_InteractiveOptions(int *inspect, int *verbose, int *suppress_print, |
Jack Jansen | 0168f27 | 1995-10-27 13:32:30 +0000 | [diff] [blame] | 215 | int *unbuffered, int *debugging, int *keep_normal, |
Jack Jansen | e355c45 | 1996-03-12 13:29:04 +0000 | [diff] [blame] | 216 | int *keep_error, int *argcp, char ***argvp) |
Jack Jansen | 696c958 | 1995-08-14 12:33:20 +0000 | [diff] [blame] | 217 | { |
| 218 | KeyMap rmap; |
| 219 | unsigned char *map; |
| 220 | short item, type; |
| 221 | ControlHandle handle; |
| 222 | DialogPtr dialog; |
| 223 | Rect rect; |
Jack Jansen | e355c45 | 1996-03-12 13:29:04 +0000 | [diff] [blame] | 224 | int old_argc = *argcp; |
| 225 | int i; |
Jack Jansen | 696c958 | 1995-08-14 12:33:20 +0000 | [diff] [blame] | 226 | |
Jack Jansen | a4b7e14 | 1996-02-21 16:46:57 +0000 | [diff] [blame] | 227 | /* Default-defaults: */ |
| 228 | *keep_error = 1; |
| 229 | /* Get default settings from our preference file */ |
Jack Jansen | 01fbc68 | 1996-02-28 15:42:47 +0000 | [diff] [blame] | 230 | PyMac_PreferenceOptions(inspect, verbose, suppress_print, |
| 231 | unbuffered, debugging, keep_normal, keep_error); |
Jack Jansen | a4b7e14 | 1996-02-21 16:46:57 +0000 | [diff] [blame] | 232 | /* If option is pressed override these */ |
Jack Jansen | 696c958 | 1995-08-14 12:33:20 +0000 | [diff] [blame] | 233 | GetKeys(rmap); |
| 234 | map = (unsigned char *)rmap; |
| 235 | if ( ( map[0x3a>>3] & (1<<(0x3a&7)) ) == 0 ) /* option key is 3a */ |
| 236 | return; |
| 237 | |
| 238 | dialog = GetNewDialog(OPT_DIALOG, NULL, (WindowPtr)-1); |
| 239 | if ( dialog == NULL ) { |
| 240 | printf("Option dialog not found - cannot set options\n"); |
| 241 | return; |
| 242 | } |
Jack Jansen | e355c45 | 1996-03-12 13:29:04 +0000 | [diff] [blame] | 243 | SetDialogDefaultItem(dialog, OPT_OK); |
| 244 | SetDialogCancelItem(dialog, OPT_CANCEL); |
Jack Jansen | 0168f27 | 1995-10-27 13:32:30 +0000 | [diff] [blame] | 245 | |
Jack Jansen | a4b7e14 | 1996-02-21 16:46:57 +0000 | [diff] [blame] | 246 | /* Set default values */ |
| 247 | #define SET_OPT_ITEM(num, var) \ |
| 248 | GetDialogItem(dialog, (num), &type, (Handle *)&handle, &rect); \ |
| 249 | SetCtlValue(handle, (short)*(var)); |
| 250 | |
| 251 | SET_OPT_ITEM(OPT_INSPECT, inspect); |
| 252 | SET_OPT_ITEM(OPT_VERBOSE, verbose); |
| 253 | SET_OPT_ITEM(OPT_SUPPRESS, suppress_print); |
| 254 | SET_OPT_ITEM(OPT_UNBUFFERED, unbuffered); |
| 255 | SET_OPT_ITEM(OPT_DEBUGGING, debugging); |
| 256 | SET_OPT_ITEM(OPT_KEEPNORMAL, keep_normal); |
| 257 | SET_OPT_ITEM(OPT_KEEPERROR, keep_error); |
| 258 | |
| 259 | #undef SET_OPT_ITEM |
Jack Jansen | 0168f27 | 1995-10-27 13:32:30 +0000 | [diff] [blame] | 260 | |
Jack Jansen | 696c958 | 1995-08-14 12:33:20 +0000 | [diff] [blame] | 261 | while (1) { |
| 262 | handle = NULL; |
| 263 | ModalDialog(NULL, &item); |
| 264 | if ( item == OPT_OK ) |
| 265 | break; |
| 266 | if ( item == OPT_CANCEL ) { |
| 267 | DisposDialog(dialog); |
| 268 | exit(0); |
| 269 | } |
Jack Jansen | e355c45 | 1996-03-12 13:29:04 +0000 | [diff] [blame] | 270 | if ( item == OPT_CMDLINE ) { |
| 271 | int new_argc, newer_argc; |
| 272 | char **new_argv, **newer_argv; |
| 273 | |
| 274 | new_argc = ccommand(&new_argv); |
| 275 | newer_argc = (new_argc-1) + old_argc; |
| 276 | newer_argv = malloc((newer_argc+1)*sizeof(char *)); |
| 277 | if( !newer_argv ) |
| 278 | Py_FatalError("Cannot malloc argv\n"); |
| 279 | for(i=0; i<old_argc; i++) |
| 280 | newer_argv[i] = (*argvp)[i]; |
| 281 | for(i=old_argc; i<=newer_argc; i++) /* Copy the NULL too */ |
| 282 | newer_argv[i] = new_argv[i-old_argc+1]; |
| 283 | *argvp = newer_argv; |
| 284 | *argcp = newer_argc; |
| 285 | |
| 286 | /* XXXX Is it not safe to use free() here, apparently */ |
| 287 | } |
Jack Jansen | 696c958 | 1995-08-14 12:33:20 +0000 | [diff] [blame] | 288 | #define OPT_ITEM(num, var) \ |
| 289 | if ( item == (num) ) { \ |
| 290 | *(var) = !*(var); \ |
| 291 | GetDialogItem(dialog, (num), &type, (Handle *)&handle, &rect); \ |
| 292 | SetCtlValue(handle, (short)*(var)); \ |
| 293 | } |
| 294 | |
| 295 | OPT_ITEM(OPT_INSPECT, inspect); |
| 296 | OPT_ITEM(OPT_VERBOSE, verbose); |
| 297 | OPT_ITEM(OPT_SUPPRESS, suppress_print); |
| 298 | OPT_ITEM(OPT_UNBUFFERED, unbuffered); |
| 299 | OPT_ITEM(OPT_DEBUGGING, debugging); |
Jack Jansen | 0168f27 | 1995-10-27 13:32:30 +0000 | [diff] [blame] | 300 | OPT_ITEM(OPT_KEEPNORMAL, keep_normal); |
| 301 | OPT_ITEM(OPT_KEEPERROR, keep_error); |
Jack Jansen | 696c958 | 1995-08-14 12:33:20 +0000 | [diff] [blame] | 302 | |
| 303 | #undef OPT_ITEM |
| 304 | } |
| 305 | DisposDialog(dialog); |
| 306 | } |
| 307 | /* Main program */ |
| 308 | |
Jack Jansen | 76ceece | 1996-08-19 11:18:24 +0000 | [diff] [blame] | 309 | static void |
Jack Jansen | 696c958 | 1995-08-14 12:33:20 +0000 | [diff] [blame] | 310 | Py_Main(argc, argv) |
| 311 | int argc; |
| 312 | char **argv; |
| 313 | { |
Jack Jansen | 696c958 | 1995-08-14 12:33:20 +0000 | [diff] [blame] | 314 | int sts; |
| 315 | char *command = NULL; |
| 316 | char *filename = NULL; |
| 317 | FILE *fp = stdin; |
Jack Jansen | 696c958 | 1995-08-14 12:33:20 +0000 | [diff] [blame] | 318 | int inspect = 0; |
| 319 | int unbuffered = 0; |
| 320 | |
Jack Jansen | e355c45 | 1996-03-12 13:29:04 +0000 | [diff] [blame] | 321 | PyMac_InteractiveOptions(&inspect, &Py_VerboseFlag, &Py_SuppressPrintingFlag, |
| 322 | &unbuffered, &Py_DebugFlag, &keep_normal, &keep_error, &argc, &argv); |
| 323 | |
Jack Jansen | 1d2f863 | 1996-08-02 15:16:16 +0000 | [diff] [blame] | 324 | orig_argc = argc; /* For Py_GetArgcArgv() */ |
Jack Jansen | 696c958 | 1995-08-14 12:33:20 +0000 | [diff] [blame] | 325 | orig_argv = argv; |
Jack Jansen | 1d2f863 | 1996-08-02 15:16:16 +0000 | [diff] [blame] | 326 | argv0 = argv[0]; /* For Py_GetProgramName() */ |
Jack Jansen | 696c958 | 1995-08-14 12:33:20 +0000 | [diff] [blame] | 327 | |
| 328 | if (unbuffered) { |
| 329 | #ifndef MPW |
| 330 | setbuf(stdout, (char *)NULL); |
| 331 | setbuf(stderr, (char *)NULL); |
| 332 | #else |
| 333 | /* On MPW (3.2) unbuffered seems to hang */ |
| 334 | setvbuf(stdout, (char *)NULL, _IOLBF, BUFSIZ); |
| 335 | setvbuf(stderr, (char *)NULL, _IOLBF, BUFSIZ); |
| 336 | #endif |
| 337 | } |
| 338 | |
| 339 | filename = argv[1]; |
| 340 | |
| 341 | if (Py_VerboseFlag || |
| 342 | command == NULL && filename == NULL && isatty((int)fileno(fp))) |
| 343 | fprintf(stderr, "Python %s\n%s\n", |
Jack Jansen | a547dca | 1996-07-10 15:48:25 +0000 | [diff] [blame] | 344 | Py_GetVersion(), Py_GetCopyright()); |
Jack Jansen | 696c958 | 1995-08-14 12:33:20 +0000 | [diff] [blame] | 345 | |
| 346 | if (filename != NULL) { |
| 347 | if ((fp = fopen(filename, "r")) == NULL) { |
| 348 | fprintf(stderr, "%s: can't open file '%s'\n", |
| 349 | argv[0], filename); |
Jack Jansen | 0168f27 | 1995-10-27 13:32:30 +0000 | [diff] [blame] | 350 | PyMac_Exit(2); |
Jack Jansen | 696c958 | 1995-08-14 12:33:20 +0000 | [diff] [blame] | 351 | } |
| 352 | } |
| 353 | |
| 354 | Py_Initialize(); |
| 355 | |
| 356 | PySys_SetArgv(argc-1, argv+1); |
| 357 | |
| 358 | if (filename == NULL && isatty((int)fileno(fp))) { |
| 359 | FILE *fp = fopen(STARTUP, "r"); |
| 360 | if (fp != NULL) { |
| 361 | (void) PyRun_SimpleFile(fp, STARTUP); |
| 362 | PyErr_Clear(); |
| 363 | fclose(fp); |
| 364 | } |
| 365 | } |
| 366 | sts = PyRun_AnyFile( |
| 367 | fp, filename == NULL ? "<stdin>" : filename) != 0; |
| 368 | if (filename != NULL) |
| 369 | fclose(fp); |
| 370 | |
| 371 | if (inspect && isatty((int)fileno(stdin)) && |
| 372 | (filename != NULL || command != NULL)) |
| 373 | sts = PyRun_AnyFile(stdin, "<stdin>") != 0; |
| 374 | |
| 375 | Py_Exit(sts); |
| 376 | /*NOTREACHED*/ |
| 377 | } |
| 378 | |
Jack Jansen | 0168f27 | 1995-10-27 13:32:30 +0000 | [diff] [blame] | 379 | /* |
| 380 | ** Terminate application |
| 381 | */ |
Jack Jansen | 76ceece | 1996-08-19 11:18:24 +0000 | [diff] [blame] | 382 | void |
Jack Jansen | 0168f27 | 1995-10-27 13:32:30 +0000 | [diff] [blame] | 383 | PyMac_Exit(status) |
| 384 | int status; |
| 385 | { |
| 386 | int keep; |
| 387 | |
| 388 | if ( status ) |
| 389 | keep = keep_error; |
| 390 | else |
| 391 | keep = keep_normal; |
| 392 | |
Jack Jansen | 1e8557a | 1995-11-10 14:51:26 +0000 | [diff] [blame] | 393 | #ifdef USE_SIOUX |
| 394 | if (keep) { |
| 395 | SIOUXSettings.standalone = 1; |
| 396 | SIOUXSettings.autocloseonquit = 0; |
Jack Jansen | 415571c | 1996-03-25 15:46:03 +0000 | [diff] [blame] | 397 | SIOUXSetTitle("\p\307terminated\310"); |
Jack Jansen | 1e8557a | 1995-11-10 14:51:26 +0000 | [diff] [blame] | 398 | } |
Jack Jansen | 0168f27 | 1995-10-27 13:32:30 +0000 | [diff] [blame] | 399 | else |
| 400 | SIOUXSettings.autocloseonquit = 1; |
Jack Jansen | f6865f7 | 1996-09-04 15:24:59 +0000 | [diff] [blame^] | 401 | #ifdef USE_GUSI |
| 402 | /* |
| 403 | ** Workaround for Sioux/GUSI combo: we should not call |
| 404 | ** SiouxHandleOneEvent after the window is closed |
| 405 | */ |
| 406 | PyMac_ConsoleIsDead = 1; |
| 407 | #endif /* USE_GUSI */ |
| 408 | #endif /* USE_SIOUX */ |
Jack Jansen | 0168f27 | 1995-10-27 13:32:30 +0000 | [diff] [blame] | 409 | #ifdef THINK_C |
| 410 | console_options.pause_atexit = keep; |
| 411 | #endif |
| 412 | |
| 413 | exit(status); |
| 414 | } |
Jack Jansen | 696c958 | 1995-08-14 12:33:20 +0000 | [diff] [blame] | 415 | |
| 416 | /* Return the program name -- some code out there needs this. */ |
| 417 | |
| 418 | char * |
Jack Jansen | 1d2f863 | 1996-08-02 15:16:16 +0000 | [diff] [blame] | 419 | Py_GetProgramName() |
Jack Jansen | 696c958 | 1995-08-14 12:33:20 +0000 | [diff] [blame] | 420 | { |
| 421 | return argv0; |
| 422 | } |
| 423 | |
| 424 | |
| 425 | /* Make the *original* argc/argv available to other modules. |
| 426 | This is rare, but it is needed by the secureware extension. */ |
| 427 | |
| 428 | void |
Jack Jansen | 1d2f863 | 1996-08-02 15:16:16 +0000 | [diff] [blame] | 429 | Py_GetArgcArgv(argc,argv) |
Jack Jansen | 696c958 | 1995-08-14 12:33:20 +0000 | [diff] [blame] | 430 | int *argc; |
| 431 | char ***argv; |
| 432 | { |
| 433 | *argc = orig_argc; |
| 434 | *argv = orig_argv; |
Guido van Rossum | b0f3c82 | 1994-08-23 13:34:25 +0000 | [diff] [blame] | 435 | } |
Jack Jansen | 1d2f863 | 1996-08-02 15:16:16 +0000 | [diff] [blame] | 436 | |
| 437 | /* More cruft that shouldn't really be here, used in sysmodule.c */ |
| 438 | |
| 439 | char * |
| 440 | Py_GetPrefix() |
| 441 | { |
| 442 | return ""; |
| 443 | } |
| 444 | |
| 445 | char * |
| 446 | Py_GetExecPrefix() |
| 447 | { |
| 448 | return ""; |
| 449 | } |