comparison Python/pythonrun.c @ 10534:a4a268b725b2 legacy-trunk

Alas, get rid of the Win specific hack to ask the user to press Return before exiting when an error happened. This didn't work right when Python is invoked from a daemon.
author Guido van Rossum <guido@python.org>
date Wed, 07 Apr 1999 18:32:51 +0000
parents caf2c65a6bcf
children be8ec828c072
comparison
equal deleted inserted replaced
10533:32ba09c86917 10534:a4a268b725b2
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();
105 void 104 void
106 Py_Initialize() 105 Py_Initialize()
107 { 106 {
108 PyInterpreterState *interp; 107 PyInterpreterState *interp;
109 PyThreadState *tstate; 108 PyThreadState *tstate;
111 char *p; 110 char *p;
112 111
113 if (initialized) 112 if (initialized)
114 return; 113 return;
115 initialized = 1; 114 initialized = 1;
116 #ifdef MS_WINDOWS
117 win_pre_init();
118 #endif
119 115
120 if ((p = getenv("PYTHONDEBUG")) && *p != '\0') 116 if ((p = getenv("PYTHONDEBUG")) && *p != '\0')
121 Py_DebugFlag = 1; 117 Py_DebugFlag = 1;
122 if ((p = getenv("PYTHONVERBOSE")) && *p != '\0') 118 if ((p = getenv("PYTHONVERBOSE")) && *p != '\0')
123 Py_VerboseFlag = 1; 119 Py_VerboseFlag = 1;
1100 Py_Finalize(); 1096 Py_Finalize();
1101 1097
1102 #ifdef macintosh 1098 #ifdef macintosh
1103 PyMac_Exit(sts); 1099 PyMac_Exit(sts);
1104 #else 1100 #else
1105 #ifdef MS_WINDOWS
1106 win_pre_exit(sts);
1107 #endif
1108 exit(sts); 1101 exit(sts);
1109 #endif 1102 #endif
1110 } 1103 }
1111 1104
1112 static void 1105 static void
1167 return 0; 1160 return 0;
1168 return (filename == NULL) || 1161 return (filename == NULL) ||
1169 (strcmp(filename, "<stdin>") == 0) || 1162 (strcmp(filename, "<stdin>") == 0) ||
1170 (strcmp(filename, "???") == 0); 1163 (strcmp(filename, "???") == 0);
1171 } 1164 }
1172
1173 #ifdef MS_WINDOWS
1174
1175 #include <windows.h>
1176 #include <conio.h>
1177
1178 static int its_my_console = -1;
1179
1180 static void
1181 win_pre_init()
1182 {
1183 HANDLE console;
1184 CONSOLE_SCREEN_BUFFER_INFO info;
1185 if (its_my_console >= 0)
1186 return;
1187 its_my_console = 0;
1188 console = GetStdHandle(STD_OUTPUT_HANDLE);
1189 if (console == INVALID_HANDLE_VALUE)
1190 return;
1191 if (!GetConsoleScreenBufferInfo(console, &info)) {
1192 return;
1193 }
1194 if (info.dwCursorPosition.Y == 0)
1195 its_my_console = 1;
1196 }
1197
1198 static void
1199 win_pre_exit(sts)
1200 int sts;
1201 {
1202 if (sts == 0)
1203 return;
1204 if (its_my_console <= 0)
1205 return;
1206 fprintf(stderr, "Hit any key to exit...");
1207 fflush(stderr);
1208 _getch();
1209 }
1210
1211 #endif