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
|
/*-----------------------------------------------------------------------------------*/
/* Interface with system C function */
/* Copyright (Allan CORNET) INRIA 2005 */
/*-----------------------------------------------------------------------------------*/
#include<stdio.h>
#ifdef WIN32
#include <windows.h>
#include "../wsci/GetOS.h"
#include "../os_specific/win_mem_alloc.h" /* MALLOC */
#else
#include "../os_specific/sci_mem_alloc.h" /* MALLOC */
#endif
#include "../machine.h"
/*-----------------------------------------------------------------------------------*/
#if WIN32
extern BOOL IsAFile(char *chainefichier);
BOOL CallWindowsShell(char *command,BOOL WaitInput);
#endif
/*-----------------------------------------------------------------------------------*/
#ifdef __STDC__
#include <stdlib.h>
#else
int system();
#endif
/*-----------------------------------------------------------------------------------*/
int C2F(systemc)(char *command, integer *stat)
{
#if WIN32
{
int OS=GetOSVersion();
if ( (OS==OS_WIN32_WINDOWS_NT_3_51) ||
(OS==OS_WIN32_WINDOWS_NT_4_0) ||
(OS==OS_WIN32_WINDOWS_95) ||
(OS==OS_WIN32_WINDOWS_98) ||
(OS==OS_WIN32_WINDOWS_Me) )
{
int status;
status=system(command);
*stat=(integer)status;
}
else
{
BOOL Status=FALSE;
Status=CallWindowsShell(command,FALSE);
if (Status)
{
*stat=(integer)0;
}
else
{
*stat=(integer)1;
}
}
}
#else
{
int status;
status=system(command);
*stat=(integer)status;
}
#endif
return(0);
}
/*-----------------------------------------------------------------------------------*/
#if WIN32
BOOL CallWindowsShell(char *command,BOOL WaitInput)
{
BOOL bReturn=FALSE;
char shellCmd[_MAX_PATH];
char *CmdLine=NULL;
PROCESS_INFORMATION piProcInfo;
STARTUPINFO siStartInfo;
SECURITY_ATTRIBUTES saAttr;
DWORD ExitCode;
char *TMPDir=NULL;
char FileTMPDir[MAX_PATH];
saAttr.nLength = sizeof(SECURITY_ATTRIBUTES);
saAttr.bInheritHandle = TRUE;
saAttr.lpSecurityDescriptor = NULL;
ZeroMemory( &piProcInfo, sizeof(PROCESS_INFORMATION) );
ZeroMemory( &siStartInfo, sizeof(STARTUPINFO) );
siStartInfo.cb = sizeof(STARTUPINFO);
siStartInfo.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES;
siStartInfo.wShowWindow = SW_HIDE;
if (WaitInput)
{
siStartInfo.hStdInput=GetStdHandle(STD_INPUT_HANDLE);
}
else
{
siStartInfo.hStdInput=NULL;
}
siStartInfo.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
siStartInfo.hStdError = GetStdHandle(STD_ERROR_HANDLE);
GetEnvironmentVariable("ComSpec", shellCmd, _MAX_PATH);
TMPDir=getenv("TMPDIR");
sprintf(FileTMPDir,"%s\\DOS.OK",TMPDir);
CmdLine=(char*)MALLOC( (strlen(shellCmd)+strlen(command)+strlen(FileTMPDir)+strlen("%s /a /c %s && echo DOS>%s")+1)*sizeof(char) );
sprintf(CmdLine,"%s /a /c %s && echo DOS>%s",shellCmd,command,FileTMPDir);
if (IsAFile(FileTMPDir)) DeleteFile(FileTMPDir);
if (CreateProcess(NULL, CmdLine, NULL, NULL, TRUE,0, NULL, NULL, &siStartInfo, &piProcInfo))
{
WaitForSingleObject(piProcInfo.hProcess,INFINITE);
if ( GetExitCodeProcess(piProcInfo.hProcess,&ExitCode) == STILL_ACTIVE )
{
TerminateProcess(piProcInfo.hProcess,0);
}
CloseHandle(piProcInfo.hProcess);
if (CmdLine) {FREE(CmdLine);CmdLine=NULL;}
if (IsAFile(FileTMPDir))
{
DeleteFile(FileTMPDir);
bReturn=TRUE;
}
else
{
bReturn=FALSE;
}
}
else
{
CloseHandle(piProcInfo.hProcess);
if (CmdLine) {FREE(CmdLine);CmdLine=NULL;}
bReturn=FALSE;
}
return bReturn;
}
#endif
/*-----------------------------------------------------------------------------------*/
|