summaryrefslogtreecommitdiffstats
path: root/Lib/test/regrtest.py
Commit message (Expand)AuthorAgeFilesLines
* Issue #25523: Further a-to-an corrections.Serhiy Storchaka2015-11-021-1/+1
* regrtest: the 'bad' and 'environment_changed' sets of tests don't intersect a...Zachary Ware2015-08-091-4/+2
* Issue #24751: When running regrtest with '-w', don't fail if re-run succeeds.Zachary Ware2015-08-051-3/+8
* Issue #22390: test.regrtest now emits a warning if temporary files orSerhiy Storchaka2015-03-291-15/+11
* Issue #22104: Don't hold a reference to the loaded TestSuite in runtest_innerZachary Ware2014-08-041-2/+4
* merge 3.3Benjamin Peterson2014-02-161-6/+3
|\
| * backout fafac90b69c4Benjamin Peterson2014-02-161-7/+4
* | merge 3.3Benjamin Peterson2014-01-091-3/+6
|\ \ | |/
| * clear zip stat cache after each ref leak runBenjamin Peterson2014-01-091-4/+7
* | ssue #19183: Implement PEP 456 'secure and interchangeable hash algorithm'.Christian Heimes2013-11-201-0/+2
* | Remove unused --debug option of regrtest.Eli Bendersky2013-09-031-9/+7
* | Fix docstring and some indentationEli Bendersky2013-09-021-4/+4
* | Refactor the main function of regrtest a bit.Eli Bendersky2013-09-021-23/+33
* | Issue #11798: fix tests for regrtest -R :Andrew Svetlov2013-09-011-0/+5
* | Issue #8713: Cleanup before saving process._dangling.Richard Oudkerk2013-08-291-2/+6
* | Issue #16799: Switched from getopt to argparse style in regrtest's argumentSerhiy Storchaka2013-08-291-290/+243
* | Issue #8713: Support alternative start methods in multiprocessing on Unix.Richard Oudkerk2013-08-141-1/+1
* | Issue #18375: merge with 3.3Florent Xicluna2013-07-061-0/+1
|\ \ | |/
| * Issue #18375: Assume --randomize when --randseed is used for running the test...Florent Xicluna2013-07-061-0/+1
* | Issue #15767: Excise the remaining instances of ModuleNotFoundErrorBrett Cannon2013-07-041-8/+8
* | Issue #17914: Use os.cpu_count() instead of multiprocessing.cpu_count() whereCharles-François Natali2013-06-281-6/+2
* | Issue #17206: test.regrtest and test.script_helper enable faulthandler moduleVictor Stinner2013-06-251-1/+2
* | Issue #18228: Use locale.setlocale(name, None) instead ofVictor Stinner2013-06-171-2/+2
* | Issue #18228: Fix locale test of test.regrtest.saved_test_environmentVictor Stinner2013-06-171-2/+3
* | (Merge 3.3) regrtest.py: Fix another typo in the usage of the faulthandler mo...Victor Stinner2013-06-171-1/+1
|\ \ | |/
| * regrtest.py: Fix another typo in the usage of the faulthandler moduleVictor Stinner2013-06-171-1/+1
* | (Merge 3.3) regrtest.py: Fix typo in the usage of the faulthandler moduleVictor Stinner2013-06-171-3/+3
|\ \ | |/
| * regrtest.py: Fix typo in the usage of the faulthandler moduleVictor Stinner2013-06-171-3/+3
* | Check that warnings.showwarning() is not changed.Brett Cannon2013-06-161-1/+6
* | Move test___all__ over to unittest.main() and use ModuleNotFoundErrorBrett Cannon2013-06-131-8/+8
* | Issue #14135: Let's try this again.Brett Cannon2013-04-011-1/+15
* | Backed out changeset 4fcd50a6dca7 as it totally breaks the test suite here.Antoine Pitrou2013-04-011-10/+1
* | Issue #14135: Make sure tests don't leave the locale changed for anyBrett Cannon2013-04-011-1/+10
* | Issue #17283: Share code between __main__.py and regrtest.py in Lib/test.Chris Jerdonek2013-02-271-18/+20
* | #16259: delete some no-longer-used code from regrtest.R David Murray2013-01-121-9/+1
* | Issue #16854: Fix regrtest.usage() regression introduced in 6e2e5adc0400.Chris Jerdonek2013-01-081-24/+28
* | Issue #15302: Switch regrtest from using getopt to using argparse.Chris Jerdonek2012-12-281-77/+147
* | Merge from 3.3: Issue #15324: Fix regrtest --fromfile, --match, --randomize.Chris Jerdonek2012-12-281-3/+3
|\ \ | |/
| * Merge from 3.2: Issue #15324: Fix regrtest --fromfile, --match, --randomize.Chris Jerdonek2012-12-281-3/+3
| |\
| | * Issue #15324: Fix regrtest parsing of --fromfile, --match, and --randomize.Chris Jerdonek2012-12-281-3/+3
* | | Replace IOError with OSError (#16715)Andrew Svetlov2012-12-251-1/+1
* | | Issue #13390: New function :func:`sys.getallocatedblocks()` returns the numbe...Antoine Pitrou2012-12-091-17/+37
* | | Issue #10966: Remove the concept of unexpected skipped tests.Brett Cannon2012-11-181-293/+0
* | | Use importlib instead of calling __import__ directly.Brett Cannon2012-11-141-2/+1
* | | merge #15889: make regrtest --start succeed in more cases.R David Murray2012-10-271-2/+2
|\ \ \ | |/ /
| * | merge #15889: make regrtest --start succeed in more cases.R David Murray2012-10-271-2/+2
| |\ \ | | |/
| | * #15889: make regrtest --start succeed in more cases.R David Murray2012-10-271-2/+2
* | | Closes #16135: Removal of OS/2 supportJesus Cea2012-10-051-14/+0
|/ /
* | Closes #15632: regrtest.py: fix spurious refleaks due to various cachesStefan Krah2012-08-171-4/+9
* | regrtest: give more information when a child process fails with an errorVictor Stinner2012-08-081-3/+5
s_macro'>novem_saveresult_as_macro Tcl is a high-level, general-purpose, interpreted, dynamic programming language. It was designed with the goal of being very simple but powerful.
summaryrefslogtreecommitdiffstats
path: root/win/tclWin16.c
blob: d8ea801ad6d92051622781ad2374f4decae6718c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
/*
 * tclWin16.c --
 *
 *      This file contains code for a 16-bit DLL to handle 32-to-16 bit
 *      thunking. This is necessary for the Win32s SynchSpawn() call.
 *
 * Copyright (c) 1994-1997 Sun Microsystems, Inc.
 *
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 *
 * SCCS: @(#) tclWin16.c 1.18 97/05/23 13:13:32
 */

#define STRICT

#include <windows.h>  
#include <toolhelp.h> 

#include <stdio.h>
#include <string.h>

static int                      WinSpawn(char *command);
static int                      DosSpawn(char *command, char *fromFileName,
				    char *toFileName);                                          
static int                      WaitForExit(int inst);

/*
 * The following data is used to construct a .pif file that wraps the
 * .bat file that runs the 16-bit application (that Jack built).  
 * The .pif file causes the .bat file to run in an iconified window.
 * Otherwise, when we try to exec something, a DOS box pops up, 
 * obscuring everything, and then almost immediately flickers out of
 * existence, which is rather disconcerting.
 */

static char pifData[545] = {
'\000', '\013', '\040', '\040', '\040', '\040', '\040', '\040', 
'\040', '\040', '\040', '\040', '\040', '\040', '\040', '\040', 
'\040', '\040', '\040', '\040', '\040', '\040', '\040', '\040', 
'\040', '\040', '\040', '\040', '\040', '\040', '\040', '\040', 
'\200', '\000', '\200', '\000', '\103', '\117', '\115', '\115', 
'\101', '\116', '\104', '\056', '\103', '\117', '\115', '\000', 
'\040', '\040', '\040', '\040', '\040', '\040', '\040', '\040', 
'\040', '\040', '\040', '\040', '\040', '\040', '\040', '\040', 
'\040', '\040', '\040', '\040', '\040', '\040', '\040', '\040', 
'\040', '\040', '\040', '\040', '\040', '\040', '\040', '\040', 
'\040', '\040', '\040', '\040', '\040', '\040', '\040', '\040', 
'\040', '\040', '\040', '\040', '\040', '\040', '\040', '\040',
'\040', '\040', '\040', '\020', '\000', '\000', '\040', '\040', 
'\040', '\040', '\040', '\040', '\040', '\040', '\040', '\040', 
'\040', '\040', '\040', '\040', '\040', '\040', '\040', '\040', 
'\040', '\040', '\040', '\040', '\040', '\040', '\040', '\040', 
'\040', '\040', '\040', '\040', '\040', '\040', '\040', '\040', 
'\040', '\040', '\040', '\040', '\040', '\040', '\040', '\040', 
'\040', '\040', '\040', '\040', '\040', '\040', '\040', '\040', 
'\040', '\040', '\040', '\040', '\040', '\040', '\040', '\040',
'\040', '\040', '\040', '\040', '\040', '\000', '\000', '\000', 
'\000', '\000', '\000', '\000', '\000', '\000', '\000', '\000', 
'\000', '\000', '\000', '\000', '\000', '\000', '\000', '\000', 
'\000', '\000', '\000', '\000', '\000', '\000', '\000', '\000', 
'\000', '\000', '\000', '\000', '\000', '\000', '\000', '\000', 
'\000', '\000', '\000', '\000', '\000', '\000', '\000', '\000', 
'\000', '\000', '\000', '\000', '\000', '\000', '\000', '\000', 
'\000', '\000', '\000', '\000', '\000', '\000', '\000', '\000', 
'\000', '\000', '\000', '\000', '\000', '\177', '\001', '\000', 
'\377', '\031', '\120', '\000', '\000', '\007', '\000', '\000', 
'\000', '\000', '\000', '\000', '\000', '\000', '\000', '\000', 
'\000', '\000', '\000', '\000', '\000', '\000', '\000', '\000', 
'\000', '\000', '\000', '\000', '\000', '\000', '\000', '\000', 
'\000', '\000', '\000', '\000', '\000', '\000', '\000', '\000', 
'\000', '\000', '\000', '\000', '\000', '\000', '\000', '\000', 
'\000', '\000', '\000', '\000', '\000', '\000', '\000', '\000', 
'\000', '\000', '\000', '\000', '\000', '\000', '\000', '\000', 
'\000', '\000', '\000', '\000', '\000', '\000', '\000', '\000',
'\000', '\000', '\000', '\000', '\000', '\000', '\000', '\000', 
'\000', '\000', '\000', '\000', '\000', '\000', '\000', '\000', 
'\000', '\000', '\000', '\000', '\000', '\000', '\000', '\000', 
'\000', '\000', '\000', '\000', '\000', '\000', '\000', '\000', 
'\000', '\000', '\000', '\000', '\000', '\000', '\000', '\000', 
'\000', '\000', '\000', '\000', '\000', '\000', '\000', '\000', 
'\000', '\000', '\000', '\000', '\000', '\000', '\000', '\000', 
'\000', '\000', '\000', '\000', '\000', '\000', '\000', '\340', 
'\040', '\115', '\111', '\103', '\122', '\117', '\123', '\117', 
'\106', '\124', '\040', '\120', '\111', '\106', '\105', '\130', 
'\000', '\207', '\001', '\000', '\000', '\161', '\001', '\127', 
'\111', '\116', '\104', '\117', '\127', '\123', '\040', '\063',
'\070', '\066', '\040', '\063', '\056', '\060', '\000', '\005', 
'\002', '\235', '\001', '\150', '\000', '\200', '\002', '\200', 
'\000', '\144', '\000', '\062', '\000', '\000', '\004', '\000', 
'\000', '\000', '\004', '\000', '\000', '\002', '\020', '\002', 
'\000', '\037', '\000', '\000', '\000', '\000', '\000', '\000', 
'\000', '\000', '\000', '\000', '\000', '\000', '\000', '\000', 
'\000', '\000', '\000', '\000', '\000', '\057', '\143', '\040', 
'\146', '\157', '\157', '\056', '\142', '\141', '\164', '\000', 
'\040', '\040', '\040', '\040', '\040', '\040', '\040', '\040', 
'\040', '\040', '\040', '\040', '\040', '\040', '\040', '\040', 
'\040', '\040', '\040', '\040', '\040', '\040', '\040', '\040', 
'\040', '\040', '\040', '\040', '\040', '\040', '\040', '\040', 
'\040', '\040', '\040', '\040', '\040', '\040', '\040', '\040', 
'\040', '\040', '\040', '\040', '\040', '\040', '\040', '\040', 
'\040', '\040', '\040', '\040', '\040', '\127', '\111', '\116', 
'\104', '\117', '\127', '\123', '\040', '\062', '\070', '\066', 
'\040', '\063', '\056', '\060', '\000', '\377', '\377', '\033', 
'\002', '\006', '\000', '\000', '\000', '\000', '\000', '\000', 
'\000'
};

static HINSTANCE hInstance;


/*
 *----------------------------------------------------------------------
 *
 * LibMain --
 *
 *      16-bit DLL entry point.
 *
 * Results:
 *      Returns 1.
 *
 * Side effects:
 *      None.
 *
 *----------------------------------------------------------------------
 */

int CALLBACK
LibMain(
    HINSTANCE hinst,
    WORD wDS,
    WORD cbHeap,
    LPSTR unused)
{
    hInstance   = hinst;
    wDS         = wDS;          /* lint. */
    cbHeap      = cbHeap;       /* lint. */
    unused      = unused;       /* lint. */

    return TRUE;
}

/*
 *----------------------------------------------------------------------
 *
 * UTProc --
 *
 *      Universal Thunk dispatch routine.  Executes a 16-bit DOS
 *      application or a 16-bit or 32-bit Windows application and
 *      waits for it to complete.
 *
 * Results:
 *      1 if the application could be run, 0 or -1 on failure.
 *
 * Side effects:
 *      Executes 16-bit code.
 *
 *----------------------------------------------------------------------
 */

int WINAPI
UTProc(buf, func)
    void *buf;
    DWORD func;
{
    char **args;

    args = (char **) buf;
    if (func == 0) {
	return DosSpawn(args[0], args[1], args[2]);
    } else {
	return WinSpawn(args[0]);
    }
}

/*
 *-------------------------------------------------------------------------
 *
 * WinSpawn --
 *
 *      Start a 16-bit or 32-bit Windows application with optional 
 *      command line arguments and wait for it to finish.  Windows 
 *      applications do not handle input/output redirection.
 *
 * Results:
 *      The return value is 1 if the application could be run, 0 otherwise.
 *
 * Side effects:
 *      Whatever the application does.
 *
 *-------------------------------------------------------------------------
 */

static int
WinSpawn(command)
    char *command;              /* The command line, consisting of the name
				 * of the executable to run followed by any
				 * number of arguments to the executable. */
{
    return WaitForExit(WinExec(command, SW_SHOW));
}

/*
 *---------------------------------------------------------------------------
 *
 * DosSpawn --
 *
 *      Start a 16-bit DOS program with optional command line arguments
 *      and wait for it to finish.  Input and output can be redirected
 *      from the specified files, but there is no such thing as stderr 
 *      under Win32s.
 *      
 *      This procedure to constructs a temporary .pif file that wraps a
 *      temporary .bat file that runs the 16-bit application.  The .bat
 *      file is necessary to get the redirection symbols '<' and '>' to 
 *      work, because WinExec() doesn't accept them.  The .pif file is
 *      necessary to cause the .bat file to run in an iconified window,
 *      to avoid having a large DOS box pop up, obscuring everything, and 
 *      then almost immediately flicker out of existence, which is rather 
 *      disconcerting.
 *
 * Results:
 *      The return value is 1 if the application could be run, 0 otherwise.
 *
 * Side effects:
 *      Whatever the application does.
 *
 *---------------------------------------------------------------------------
 */

static int
DosSpawn(command, fromFileName, toFileName)
    char *command;              /* The name of the program, plus any
				 * arguments, to be run. */
    char *fromFileName;         /* Standard input for the program is to be
				 * redirected from this file, or NULL for no
				 * standard input. */
    char *toFileName;           /* Standard output for the program is to be
				 * redirected to this file, or NULL to
				 * discard standard output. */
{
    int result;
    HFILE batFile, pifFile;
    char batFileName[144], pifFileName[144];

    GetTempFileName(0, "tcl", 0, batFileName);
    unlink(batFileName);
    strcpy(strrchr(batFileName, '.'), ".bat");
    batFile = _lcreat(batFileName, 0);

    GetTempFileName(0, "tcl", 0, pifFileName);
    unlink(pifFileName);
    strcpy(strrchr(pifFileName, '.'), ".pif");
    pifFile = _lcreat(pifFileName, 0);

    _lwrite(batFile, command, strlen(command));
    if (fromFileName == NULL) {
	_lwrite(batFile, " < nul", 6);
    } else {
	_lwrite(batFile, " < ", 3);
	_lwrite(batFile, fromFileName, strlen(fromFileName));
    }
    if (toFileName == NULL) {
	_lwrite(batFile, " > nul", 6);
    } else {
	_lwrite(batFile, " > ", 3);
	_lwrite(batFile, toFileName, strlen(toFileName));
    }
    _lwrite(batFile, "\r\n\032", 3);
    _lclose(batFile);

    strcpy(pifData + 0x1c8, batFileName);
    _lwrite(pifFile, pifData, sizeof(pifData));
    _lclose(pifFile);

    result = WaitForExit(WinExec(pifFileName, SW_MINIMIZE));

    unlink(pifFileName);
    unlink(batFileName);

    return result;
}

/*
 *-------------------------------------------------------------------------
 *
 * WaitForExit --
 *
 *      Wait until the application with the given instance handle has
 *      finished.  PeekMessage() is used to yield the processor; 
 *      otherwise, nothing else could execute on the system.
 *
 * Results:
 *      The return value is 1 if the process exited successfully,
 *      or 0 otherwise.
 *
 * Side effects:
 *      None.
 *
 *---------------------------------------------------------------------------
 */

static int
WaitForExit(inst)
    int inst;                   /* Identifies the instance handle of the
				 * process to wait for. */
{
    TASKENTRY te;
    MSG msg;
    UINT timer;

    if (inst < 32) {
	return 0;
    }

    te.dwSize = sizeof(te);
    te.hInst = 0;
    TaskFirst(&te);
    do {
	if (te.hInst == (HINSTANCE) inst) {
	    break;
	}
    } while (TaskNext(&te) != FALSE);

    if (te.hInst != (HINSTANCE) inst) {
	return 0;
    }

    timer = SetTimer(NULL, 0, 0, NULL);
    while (1) {
	if (GetMessage(&msg, NULL, 0, 0) != 0) {
	    TranslateMessage(&msg);
	    DispatchMessage(&msg);
	}
	TaskFirst(&te);
	do {
	    if (te.hInst == (HINSTANCE) inst) {
		break;
	    }
	} while (TaskNext(&te) != FALSE);

	if (te.hInst != (HINSTANCE) inst) {
	    KillTimer(NULL, timer);
	    return 1;
	}
    }
}