#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);
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;
int CALLBACK
LibMain(
HINSTANCE hinst,
WORD wDS,
WORD cbHeap,
LPSTR unused)
{
hInstance = hinst;
wDS = wDS;
cbHeap = cbHeap;
unused = unused;
return TRUE;
}
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]);
}
}
static int
WinSpawn(command)
char *command;
{
return WaitForExit(WinExec(command, SW_SHOW));
}
static int
DosSpawn(command, fromFileName, toFileName)
char *command;
char *fromFileName;
char *toFileName;
{
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;
}
static int
WaitForExit(inst)
int inst;
{
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;
}
}
}