citrun

watch C/C++ source code execute
Log | Files | Refs | LICENSE

commit 117d53039de2febe15db9c31072afa472f015e10
parent e7c8b868bf51828f9b64d333bfce8690ca13f9c3
Author: Kyle Milz <kyle@windows.krwm.net>
Date:   Tue,  3 Jan 2017 18:24:52 -0800

src: revert citrun_wrap c++ conversion

- turns out there's an easy windows batch file trick

Diffstat:
MJamfile | 8++++++--
Awrap.bat | 7+++++++
Dwrap.cc | 105-------------------------------------------------------------------------------
Awrap.sh | 7+++++++
4 files changed, 20 insertions(+), 107 deletions(-)

diff --git a/Jamfile b/Jamfile @@ -45,8 +45,12 @@ Shell citrun_check : check.sh ; # # citrun_wrap # -ObjectDefines wrap.cc : CITRUN_SHARE=\\\"$(CITRUN_SHARE)\\\" ; -Main citrun_wrap : wrap.cc ; +if $(NT) { + File citrun_wrap.bat : wrap.bat ; + Clean clean : citrun_wrap.bat ; +} else { + Shell citrun_wrap : wrap.sh ; +} # # citrun_term diff --git a/wrap.bat b/wrap.bat @@ -0,0 +1,7 @@ +@ECHO off + +SETLOCAL +SET Path=C:\Users\kyle\citrun\compilers;%Path% +CALL %* +exit /B %ERRORLEVEL% +ENDLOCAL diff --git a/wrap.cc b/wrap.cc @@ -1,105 +0,0 @@ -// -// if [[ ${1} = -* ]]; then -// echo "usage: citrun_wrap <build cmd>" -// exit 1 -// fi -// -// export PATH="`citrun_inst --print-share`:$PATH" -// exec $@ -// -#include <limits.h> // PATH_MAX -#include <sstream> -#include <stdlib.h> // setenv -#include <stdio.h> - -#ifdef _WIN32 -#include <windows.h> -#include <tchar.h> -#else // _WIN32 -#include <err.h> -#include <unistd.h> // execvp -#endif // _WIN32 - -static void -usage(void) -{ - fprintf(stderr, "usage: citrun_wrap <build_cmd>\n"); - exit(1); -} - -#ifdef _WIN32 -TCHAR *argv0; - -static void -Err(int code, const char *fmt) -{ - char buf[256]; - - FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buf, 256, NULL); - - fprintf(stderr, "%s: %s: %s\n", argv0, fmt, buf); - ExitProcess(code); -} - -int -_tmain(int argc, TCHAR *argv[]) -{ - argv0 = argv[0]; - - STARTUPINFO si; - PROCESS_INFORMATION pi; - - ZeroMemory(&si, sizeof(si)); - si.cb = sizeof(si); - ZeroMemory(&pi, sizeof(pi)); - - if (argc < 2) - usage(); - - std::stringstream path; - path << CITRUN_SHARE << ";"; - path << getenv("Path"); - - if (SetEnvironmentVariable("PATH", path.str().c_str()) == 0) - Err(1, "SetEnvironmentVariable"); - - std::stringstream arg_string; - arg_string << argv[1]; - for (unsigned int i = 2; i < argc; ++i) - arg_string << " " << argv[i]; - - if (!CreateProcess( NULL, (LPSTR) arg_string.str().c_str(), NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)) - Err(1, "CreateProcess"); - - if (WaitForSingleObject(pi.hProcess, INFINITE) == WAIT_FAILED) - Err(1, "WaitForSingleObject"); - - DWORD exit_code; - if (GetExitCodeProcess(pi.hProcess, &exit_code) == FALSE) - Err(1, "GetExitCodeProcess"); - - CloseHandle(pi.hProcess); - CloseHandle(pi.hThread); - - return exit_code; -} -#else // _WIN32 -int -main(int argc, char *argv[]) -{ - if (argc < 2) - usage(); - - std::stringstream path; - path << CITRUN_SHARE ":"; - path << getenv("PATH"); - - if (setenv("PATH", path.str().c_str(), 1)) - err(1, "setenv"); - - argv[argc] = NULL; - if (execvp(argv[1], argv + 1)) - err(1, "execvp"); -} -#endif // _WIN32 diff --git a/wrap.sh b/wrap.sh @@ -0,0 +1,7 @@ +if [[ ${1} = -* ]]; then + echo "usage: citrun_wrap <build cmd>" + exit 1 +fi + +export PATH="%CITRUN_SHARE%:$PATH" +exec $@