mirror of
				https://github.com/python/cpython.git
				synced 2025-10-30 21:21:22 +00:00 
			
		
		
		
	Added options for keeping window open on normal/error termination
Moved whole exit-handling of console window here (from pythonrun.c)
This commit is contained in:
		
							parent
							
								
									66a8977b0e
								
							
						
					
					
						commit
						0168f279cc
					
				
					 2 changed files with 47 additions and 10 deletions
				
			
		|  | @ -41,6 +41,8 @@ | ||||||
| #define OPT_SUPPRESS	5 | #define OPT_SUPPRESS	5 | ||||||
| #define OPT_UNBUFFERED	6 | #define OPT_UNBUFFERED	6 | ||||||
| #define OPT_DEBUGGING	7 | #define OPT_DEBUGGING	7 | ||||||
|  | #define OPT_KEEPNORMAL	8 | ||||||
|  | #define OPT_KEEPERROR	9 | ||||||
| 
 | 
 | ||||||
| /* Dialog for 'No preferences directory' */ | /* Dialog for 'No preferences directory' */ | ||||||
| #define NOPREFDIR_ID	133 | #define NOPREFDIR_ID	133 | ||||||
|  |  | ||||||
|  | @ -40,6 +40,10 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||||||
| #include <SIOUX.h> | #include <SIOUX.h> | ||||||
| #endif | #endif | ||||||
| 
 | 
 | ||||||
|  | #ifdef THINK_C | ||||||
|  | #include <console.h> | ||||||
|  | #endif | ||||||
|  | 
 | ||||||
| #define STARTUP "PythonStartup" | #define STARTUP "PythonStartup" | ||||||
| 
 | 
 | ||||||
| extern int Py_DebugFlag; /* For parser.c, declared in pythonrun.c */ | extern int Py_DebugFlag; /* For parser.c, declared in pythonrun.c */ | ||||||
|  | @ -59,6 +63,10 @@ static char *argv0; | ||||||
| static char **orig_argv; | static char **orig_argv; | ||||||
| static int  orig_argc; | static int  orig_argc; | ||||||
| 
 | 
 | ||||||
|  | /* Flags indicating whether stdio window should stay open on termination */ | ||||||
|  | static int keep_normal; | ||||||
|  | static int keep_error = 1; | ||||||
|  | 
 | ||||||
| #ifdef USE_MAC_APPLET_SUPPORT | #ifdef USE_MAC_APPLET_SUPPORT | ||||||
| /* Applet support */ | /* Applet support */ | ||||||
| 
 | 
 | ||||||
|  | @ -117,12 +125,7 @@ PyMac_InitApplet() | ||||||
| 	err = run_main_resource(); | 	err = run_main_resource(); | ||||||
| 	fflush(stderr); | 	fflush(stderr); | ||||||
| 	fflush(stdout); | 	fflush(stdout); | ||||||
| #ifdef __MWERKS__ | 	PyMac_Exit(err); | ||||||
| 	if (!err) |  | ||||||
| 		SIOUXSettings.autocloseonquit = 1; |  | ||||||
| 	else |  | ||||||
| 		printf("\n[Terminated]\n"); |  | ||||||
| #endif |  | ||||||
| 	/* XXX Should we bother to Py_Exit(sts)? */ | 	/* XXX Should we bother to Py_Exit(sts)? */ | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -164,7 +167,8 @@ PyMac_InitApplication() | ||||||
| */ | */ | ||||||
| void | void | ||||||
| PyMac_InteractiveOptions(int *inspect, int *verbose, int *suppress_print,  | PyMac_InteractiveOptions(int *inspect, int *verbose, int *suppress_print,  | ||||||
| 						 int *unbuffered, int *debugging) | 						 int *unbuffered, int *debugging, int *keep_normal, | ||||||
|  | 						 int *keep_error) | ||||||
| { | { | ||||||
| 	KeyMap rmap; | 	KeyMap rmap; | ||||||
| 	unsigned char *map; | 	unsigned char *map; | ||||||
|  | @ -183,6 +187,11 @@ PyMac_InteractiveOptions(int *inspect, int *verbose, int *suppress_print, | ||||||
| 		printf("Option dialog not found - cannot set options\n"); | 		printf("Option dialog not found - cannot set options\n"); | ||||||
| 		return; | 		return; | ||||||
| 	} | 	} | ||||||
|  | 	 | ||||||
|  | 	/* Set keep-open-on-error */ | ||||||
|  | 	GetDialogItem(dialog, OPT_KEEPERROR, &type, (Handle *)&handle, &rect); | ||||||
|  | 	SetCtlValue(handle, *keep_error); | ||||||
|  | 	 | ||||||
| 	while (1) { | 	while (1) { | ||||||
| 		handle = NULL; | 		handle = NULL; | ||||||
| 		ModalDialog(NULL, &item); | 		ModalDialog(NULL, &item); | ||||||
|  | @ -204,6 +213,8 @@ PyMac_InteractiveOptions(int *inspect, int *verbose, int *suppress_print, | ||||||
| 		OPT_ITEM(OPT_SUPPRESS, suppress_print); | 		OPT_ITEM(OPT_SUPPRESS, suppress_print); | ||||||
| 		OPT_ITEM(OPT_UNBUFFERED, unbuffered); | 		OPT_ITEM(OPT_UNBUFFERED, unbuffered); | ||||||
| 		OPT_ITEM(OPT_DEBUGGING, debugging); | 		OPT_ITEM(OPT_DEBUGGING, debugging); | ||||||
|  | 		OPT_ITEM(OPT_KEEPNORMAL, keep_normal); | ||||||
|  | 		OPT_ITEM(OPT_KEEPERROR, keep_error); | ||||||
| 		 | 		 | ||||||
| #undef OPT_ITEM | #undef OPT_ITEM | ||||||
| 	} | 	} | ||||||
|  | @ -228,8 +239,7 @@ Py_Main(argc, argv) | ||||||
| 	argv0 = argv[0];	/* For getprogramname() */ | 	argv0 = argv[0];	/* For getprogramname() */ | ||||||
| 	 | 	 | ||||||
| 	PyMac_InteractiveOptions(&inspect, &Py_VerboseFlag, &Py_SuppressPrintingFlag, | 	PyMac_InteractiveOptions(&inspect, &Py_VerboseFlag, &Py_SuppressPrintingFlag, | ||||||
| 			&unbuffered, &Py_DebugFlag); | 			&unbuffered, &Py_DebugFlag, &keep_normal, &keep_error); | ||||||
| 
 |  | ||||||
| 
 | 
 | ||||||
| 	if (unbuffered) { | 	if (unbuffered) { | ||||||
| #ifndef MPW | #ifndef MPW | ||||||
|  | @ -253,7 +263,7 @@ Py_Main(argc, argv) | ||||||
| 		if ((fp = fopen(filename, "r")) == NULL) { | 		if ((fp = fopen(filename, "r")) == NULL) { | ||||||
| 			fprintf(stderr, "%s: can't open file '%s'\n", | 			fprintf(stderr, "%s: can't open file '%s'\n", | ||||||
| 				argv[0], filename); | 				argv[0], filename); | ||||||
| 			exit(2); | 			PyMac_Exit(2); | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 	 | 	 | ||||||
|  | @ -282,6 +292,31 @@ Py_Main(argc, argv) | ||||||
| 	/*NOTREACHED*/ | 	/*NOTREACHED*/ | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | /*
 | ||||||
|  | ** Terminate application | ||||||
|  | */ | ||||||
|  | PyMac_Exit(status) | ||||||
|  | 	int status; | ||||||
|  | { | ||||||
|  | 	int keep; | ||||||
|  | 	 | ||||||
|  | 	if ( status ) | ||||||
|  | 		keep = keep_error; | ||||||
|  | 	else | ||||||
|  | 		keep = keep_normal; | ||||||
|  | 		 | ||||||
|  | #ifdef __MWERKS__ | ||||||
|  | 	if (keep) | ||||||
|  | 		printf("\n[Terminated]\n"); | ||||||
|  | 	else | ||||||
|  | 		SIOUXSettings.autocloseonquit = 1; | ||||||
|  | #endif | ||||||
|  | #ifdef THINK_C | ||||||
|  | 	console_options.pause_atexit = keep; | ||||||
|  | #endif | ||||||
|  | 
 | ||||||
|  | 	exit(status); | ||||||
|  | } | ||||||
| 
 | 
 | ||||||
| /* Return the program name -- some code out there needs this. */ | /* Return the program name -- some code out there needs this. */ | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Jack Jansen
						Jack Jansen