comparison Python/pythonrun.c @ 9819:bd1ce4120e6f legacy-trunk

Hack for Windows so that if (1) the exit status is nonzero and (2) we think we have our own DOS box (i.e. we're not started from a command line shell), we print a message and wait for the user to hit a key before the DOS box is closed. The hacky heuristic for determining whether we have our *own* DOS box (due to Mark Hammond) is to test whether we're on line zero...
author Guido van Rossum <guido@python.org>
date Fri, 08 Jan 1999 15:56:28 +0000
parents d152adf3f094
children c1091e82e5aa
comparison
equal deleted inserted replaced
9818:a3b2525c9370 9819:bd1ce4120e6f
99 (If the lock has not yet been initialized, that's equivalent to 99 (If the lock has not yet been initialized, that's equivalent to
100 having the lock, but you cannot use multiple threads.) 100 having the lock, but you cannot use multiple threads.)
101 101
102 */ 102 */
103 103
104 extern void win_pre_init(), win_pre_exit();
104 void 105 void
105 Py_Initialize() 106 Py_Initialize()
106 { 107 {
107 PyInterpreterState *interp; 108 PyInterpreterState *interp;
108 PyThreadState *tstate; 109 PyThreadState *tstate;
110 char *p; 111 char *p;
111 112
112 if (initialized) 113 if (initialized)
113 return; 114 return;
114 initialized = 1; 115 initialized = 1;
116 #ifdef MS_WINDOWS
117 win_pre_init();
118 #endif
115 119
116 if ((p = getenv("PYTHONDEBUG")) && *p != '\0') 120 if ((p = getenv("PYTHONDEBUG")) && *p != '\0')
117 Py_DebugFlag = 1; 121 Py_DebugFlag = 1;
118 if ((p = getenv("PYTHONVERBOSE")) && *p != '\0') 122 if ((p = getenv("PYTHONVERBOSE")) && *p != '\0')
119 Py_VerboseFlag = 1; 123 Py_VerboseFlag = 1;
1094 Py_Finalize(); 1098 Py_Finalize();
1095 1099
1096 #ifdef macintosh 1100 #ifdef macintosh
1097 PyMac_Exit(sts); 1101 PyMac_Exit(sts);
1098 #else 1102 #else
1103 #ifdef MS_WINDOWS
1104 win_pre_exit(sts);
1105 #endif
1099 exit(sts); 1106 exit(sts);
1100 #endif 1107 #endif
1101 } 1108 }
1102 1109
1103 static void 1110 static void
1158 return 0; 1165 return 0;
1159 return (filename == NULL) || 1166 return (filename == NULL) ||
1160 (strcmp(filename, "<stdin>") == 0) || 1167 (strcmp(filename, "<stdin>") == 0) ||
1161 (strcmp(filename, "???") == 0); 1168 (strcmp(filename, "???") == 0);
1162 } 1169 }
1170
1171 #ifdef MS_WINDOWS
1172
1173 #include <windows.h>
1174 #include <conio.h>
1175
1176 static int its_my_console = -1;
1177
1178 static void
1179 win_pre_init()
1180 {
1181 HANDLE console;
1182 CONSOLE_SCREEN_BUFFER_INFO info;
1183 if (its_my_console >= 0)
1184 return;
1185 its_my_console = 0;
1186 console = GetStdHandle(STD_OUTPUT_HANDLE);
1187 if (console == INVALID_HANDLE_VALUE)
1188 return;
1189 if (!GetConsoleScreenBufferInfo(console, &info)) {
1190 return;
1191 }
1192 if (info.dwCursorPosition.Y == 0)
1193 its_my_console = 1;
1194 }
1195
1196 static void
1197 win_pre_exit(sts)
1198 int sts;
1199 {
1200 if (sts == 0)
1201 return;
1202 if (its_my_console <= 0)
1203 return;
1204 fprintf(stderr, "Hit any key to exit...");
1205 fflush(stderr);
1206 _getch();
1207 }
1208
1209 #endif