diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..314a6c96 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,7 @@ +language: c + +script: make test + +compiler: + - clang + - gcc diff --git a/Makefile b/Makefile index 6361ab01..5d0faf7b 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ ###################################################### ##### Set global variables for all gst Makefiles ##### ###################################################### -CFLAGS=-std=c99 -Wall -Wextra -Wpedantic -I./include -lreadline -g +CFLAGS=-std=c99 -Wall -Wextra -Wpedantic -I./include -g PREFIX=/usr/local GST_TARGET=client/gst GST_CORELIB=core/libgst.a diff --git a/client/main.c b/client/main.c index 702acb0c..a4e5a5e6 100644 --- a/client/main.c +++ b/client/main.c @@ -24,9 +24,35 @@ #include #include -/* Use readline support for now */ -#include -#include +/* Simple read line functionality */ +char *getline() { + char *line = malloc(100); + char *linep = line; + size_t lenmax = 100; + size_t len = lenmax; + int c; + if (line == NULL) + return NULL; + for (;;) { + c = fgetc(stdin); + if (c == EOF) + break; + if (--len == 0) { + len = lenmax; + char *linen = realloc(linep, lenmax *= 2); + if (linen == NULL) { + free(linep); + return NULL; + } + line = linen + (line - linep); + linep = linen; + } + if ((*line++ = c) == '\n') + break; + } + *line = '\0'; + return linep; +} /* Compile and run an ast */ int debug_compile_and_run(Gst *vm, GstValue ast, GstValue last) { @@ -98,7 +124,7 @@ int debug_run(Gst *vm, FILE *in) { /* A simple repl */ int debug_repl(Gst *vm) { - const char *buffer, *reader; + char *buffer, *reader; GstParser p; buffer = reader = NULL; for (;;) { @@ -109,10 +135,12 @@ int debug_repl(Gst *vm) { if (p.status == GST_PARSER_ERROR || p.status == GST_PARSER_FULL) break; if (!reader || *reader == '\0') { - buffer = readline(">> "); - if (*buffer == '\0') + printf("\x1B[32m>>\x1B[0m "); + if (buffer) + free(buffer); + buffer = getline(); + if (!buffer || *buffer == '\0') return 0; - add_history(buffer); reader = buffer; } reader += gst_parse_cstring(&p, reader);