citrun

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

commit 33859664c2d4ff096058d7f4a9a268c1682171e2
parent 98ebe01a88b1a8d88f36614c506fed5ba0201cdb
Author: Kyle Milz <kyle@0x30.net>
Date:   Sat, 31 Dec 2016 23:47:13 -0700

src: replace wrap.sh with c

Diffstat:
Msrc/Jamfile | 15++++++++++-----
Asrc/wrap.c | 28++++++++++++++++++++++++++++
Dsrc/wrap.sh | 8--------
3 files changed, 38 insertions(+), 13 deletions(-)

diff --git a/src/Jamfile b/src/Jamfile @@ -7,11 +7,16 @@ ObjectCcFlags lib.c : -fPIC -ansi ; Library libcitrun : lib.c ; # -# citrun_wrap, citrun_check +# citrun_check # -MakeLocate citrun_check citrun_wrap : $(LOCATE_SOURCE) ; +MakeLocate citrun_check : $(LOCATE_SOURCE) ; Shell citrun_check : check.sh ; -Shell citrun_wrap : wrap.sh ; + +# +# citrun_wrap +# +ObjectDefines wrap.c : CITRUN_SHARE=\\\"$(CITRUN_SHARE)\\\" ; +Main citrun_wrap : wrap.c ; # # citrun_term @@ -97,8 +102,8 @@ actions SymLink # install # InstallLib $(PREFIX)/share/citrun : libcitrun.a ; -InstallShell $(PREFIX)/bin : citrun_wrap citrun_check ; -InstallBin $(PREFIX)/bin : citrun_gl citrun_inst ; +InstallShell $(PREFIX)/bin : citrun_check ; +InstallBin $(PREFIX)/bin : citrun_wrap citrun_gl citrun_inst ; InstallSyms $(PREFIX)/share/citrun : cc gcc clang clang++ g++ c++ egcc eg++ ; SubInclude TOP src glyphy ; diff --git a/src/wrap.c b/src/wrap.c @@ -0,0 +1,28 @@ +/* + * 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 <stdlib.h> /* setenv */ +#include <unistd.h> /* execvp */ + +int +main(int argc, char *argv[]) +{ + char path[PATH_MAX]; + + strlcpy(path, CITRUN_SHARE ":", PATH_MAX); + strlcat(path, getenv("PATH"), PATH_MAX); + + if (setenv("PATH", path, 1)) + err(1, "setenv"); + + argv[argc] = NULL; + if (execvp(argv[1], argv + 1)) + err(1, "execv"); +} diff --git a/src/wrap.sh b/src/wrap.sh @@ -1,8 +0,0 @@ - -if [[ ${1} = -* ]]; then - echo "usage: citrun_wrap <build cmd>" - exit 1 -fi - -export PATH="`citrun_inst --print-share`:$PATH" -exec $@