151 lines
3.3 KiB
C
151 lines
3.3 KiB
C
// mCppLib.h: interface for the mCppLib.
|
|
//
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
#ifndef __mCppLIB__
|
|
#define __mCppLIB__
|
|
|
|
|
|
unsigned int mCppLib_PreProcess(const XString& xsIn,const char *opt,XString& xsOut,XString& PreProcErr);
|
|
|
|
BOOL DoWinExec(const XString& command)
|
|
{
|
|
#ifdef _XBOX
|
|
return FALSE;
|
|
#else
|
|
STARTUPINFO si;
|
|
PROCESS_INFORMATION pi;
|
|
|
|
ZeroMemory( &si, sizeof(si) );
|
|
si.cb = sizeof(si);
|
|
ZeroMemory( &pi, sizeof(pi) );
|
|
|
|
// Start the child process.
|
|
if( !CreateProcess( NULL, // No module name (use command line).
|
|
const_cast<CKSTRING>(command.CStr()), // Command line.
|
|
NULL, // Process handle not inheritable.
|
|
NULL, // Thread handle not inheritable.
|
|
FALSE, // Set handle inheritance to FALSE.
|
|
CREATE_NO_WINDOW, // No creation flags.
|
|
NULL, // Use parent's environment block.
|
|
NULL, // Use parent's starting directory.
|
|
&si, // Pointer to STARTUPINFO structure.
|
|
&pi ) // Pointer to PROCESS_INFORMATION structure.
|
|
)
|
|
return FALSE;
|
|
|
|
// Wait until child process exits.
|
|
WaitForSingleObject( pi.hProcess, INFINITE );
|
|
|
|
DWORD code = 0;
|
|
GetExitCodeProcess( pi.hProcess, &code );
|
|
|
|
// Close process and thread handles.
|
|
CloseHandle( pi.hProcess );
|
|
CloseHandle( pi.hThread );
|
|
|
|
return code == 0;
|
|
#endif
|
|
|
|
}
|
|
unsigned int mCppLib_PreProcess(const XString& xsIn,const char *opt,XString& xsOut,XString& PreProcErr)
|
|
{
|
|
char pth[_MAX_PATH];
|
|
char src[_MAX_PATH];
|
|
char dst[_MAX_PATH];
|
|
char err[_MAX_PATH];
|
|
|
|
GetTempPath(_MAX_PATH,pth);
|
|
GetTempFileName(pth, "mcpp", 0,src);
|
|
GetTempFileName(pth, "mcpp", 0,dst);
|
|
|
|
_makepath(err,NULL,pth,"cpp",".err");
|
|
::DeleteFile(err);
|
|
|
|
VxFile fSrc;
|
|
fSrc.Open(src,VxFile::WRITEONLY);
|
|
XASSERT(fSrc.IsValid());
|
|
fSrc.Write(xsIn.CStr(),xsIn.Length());
|
|
fSrc.Close();
|
|
|
|
char oldPth[_MAX_PATH];
|
|
::GetCurrentDirectory(_MAX_PATH,oldPth);
|
|
::SetCurrentDirectory(pth);
|
|
|
|
|
|
XString tmp;
|
|
tmp << '"';
|
|
tmp << CKGetStartPath();
|
|
tmp << "fxp.exe\" ";
|
|
tmp << src;
|
|
tmp << " ";
|
|
tmp << dst;
|
|
tmp << " -Q ";
|
|
tmp << opt;
|
|
DWORD sz = -1;
|
|
|
|
BOOL res = DoWinExec(tmp.CStr());
|
|
if(res){
|
|
::SetCurrentDirectory(oldPth);
|
|
|
|
VxFile fDst;
|
|
fDst.Open(dst,VxFile::READONLY);
|
|
if(fDst.IsValid()){
|
|
|
|
sz = fDst.Size();
|
|
xsOut.Resize((unsigned short)sz);
|
|
fDst.Read(xsOut.Str(),sz);
|
|
fDst.Close();
|
|
|
|
VxFile fErr;
|
|
fErr.Open(err,VxFile::READONLY);
|
|
if(fErr.IsValid()){
|
|
sz = fErr.Size();
|
|
if(sz){
|
|
PreProcErr.Resize((unsigned short)sz);
|
|
fErr.Read(PreProcErr.Str(),sz);
|
|
|
|
// Format the error
|
|
XDWORD pos = 0;
|
|
DWORD l = strlen(src);
|
|
while(XString::NOTFOUND != (pos = PreProcErr.Find(src,pos))){
|
|
pos += (XDWORD) l;
|
|
PreProcErr[pos++] = '(';
|
|
while(isdigit(PreProcErr[pos]))
|
|
pos++;
|
|
|
|
PreProcErr[pos] = ')';
|
|
|
|
}
|
|
|
|
char s[3];
|
|
s[0] = 0x0D;
|
|
s[1] = 0x0A;
|
|
s[2] = 0x00;
|
|
|
|
PreProcErr.Replace(src,"");
|
|
PreProcErr.Replace(s,"\n");
|
|
|
|
|
|
}else{
|
|
PreProcErr = "";
|
|
}
|
|
fErr.Close();
|
|
}else{
|
|
PreProcErr = "Unable to open pre processor error file.";
|
|
}
|
|
fDst.Close();
|
|
}
|
|
}else{
|
|
PreProcErr = "Unable to launch fxp.exe";
|
|
}
|
|
::DeleteFile(src);
|
|
::DeleteFile(dst);
|
|
::DeleteFile(err);
|
|
|
|
return sz ? E_FAIL: S_OK;
|
|
}
|
|
|
|
|
|
#endif
|