diff --git a/Tuprules.tup b/Tuprules.tup index 0708ae2..7509a14 100644 --- a/Tuprules.tup +++ b/Tuprules.tup @@ -9,11 +9,11 @@ GOFLAGS += -g GOFLAGS += -O3 CFLAGS += -Wall -CFLAGS += -Werror +#CFLAGS += -Werror !nim = |> ^ Nim: %f -> %o^ nim c $(NIMFLAGS) -o:%o %f && rm -rf .nimcache |> !gccgo = |> ^ GCCGo: %f -> %o^ gccgo $(GOFLAGS) -o %o %f |> -!cc = |> ^ CC obj: %f -> %o^ gcc $(CFLAGS) -o %o %f |> -!obj = |> ^ CC: %f -> %o^ gcc $(CFLAGS) -c -o %o %f |> +!cc = |> gcc $(CFLAGS) -o %o %f |> +!obj = |> gcc $(CFLAGS) -c -o %o %f |> !moon = |> ^ Moonscript: %f -> %o^ moonc -o %o %f |> !luascript = |> ^ Lua script: %f -> %o^ echo "#!/usr/bin/lua" >> %o && cat %f >> %o && chmod u+x %o |> diff --git a/src/.gitignore b/src/.gitignore index 220954d..1c9068c 100644 --- a/src/.gitignore +++ b/src/.gitignore @@ -3,3 +3,5 @@ ##### Do not edit. /.gitignore /reaper.o +/string_compare_guy.log +/string_compare_guy.o diff --git a/src/Tupfile b/src/Tupfile index d224ff6..4a15911 100644 --- a/src/Tupfile +++ b/src/Tupfile @@ -5,4 +5,8 @@ include_rules : foreach *.go |> !gccgo |> ../bin/%B : foreach *.c |> !obj |> %B.o + : reaper.o |> !cc |> ../bin/reaper +: string_compare_guy.o |> !cc |> ../bin/string_compare_guy + +: ../bin/string_compare_guy |> ../bin/string_compare_guy | tee %o |> ./string_compare_guy.log diff --git a/src/string_compare_guy.c b/src/string_compare_guy.c new file mode 100644 index 0000000..1ad5d8f --- /dev/null +++ b/src/string_compare_guy.c @@ -0,0 +1,42 @@ +#include +#include +#include + +static int string_compare_guy(char* lhs, int llength, char* rhs, int rlength) { + char* lnz = malloc(llength + 1); + memcpy(lnz, lhs, llength); + lnz[llength] = 0; + + char* rnz = malloc(rlength + 1); + memcpy(rnz, rhs, rlength); + rnz[rlength] = 0; + + int result = strstr(lnz, rhs); + + free(lnz); + free(rnz); + + return result; +} + +int main() { + int retcode = 0; + + printf("Comparing foo and bar\n"); + if(string_compare_guy("foo", 3, "bar", 3)) { + retcode++; + printf("failure\n"); + } else { + printf("passed\n"); + } + + printf("trying to find foo in foobar\n"); + if(string_compare_guy("foo", 3, "foobar", 6)) { + retcode++; + printf("failure\n"); + } else { + printf("passed\n"); + } + + return retcode; +}