From 7f9ab03b3cf069248a2beed0b5aaf39a92e73de3 Mon Sep 17 00:00:00 2001 From: Tim Morgan Date: Mon, 25 Feb 2019 22:50:01 -0600 Subject: [PATCH] Allow building without editline I couldn't get multibyte characters to work in Ubuntu with editline. So I'm just disabling it for the tests. --- .build.yml | 2 +- Dockerfile | 4 ++++ Makefile | 11 +++++++---- malcc.c | 2 +- readline.c | 31 +++++++++++++++++++++++++++++++ readline.h | 9 +++++++++ tests/{unicode.mal => utf-8.mal} | 0 7 files changed, 53 insertions(+), 6 deletions(-) create mode 100644 readline.c create mode 100644 readline.h rename tests/{unicode.mal => utf-8.mal} (100%) diff --git a/.build.yml b/.build.yml index 69d11c6..1abaddb 100644 --- a/.build.yml +++ b/.build.yml @@ -10,7 +10,7 @@ sources: tasks: - build: | cd malcc - make all + make -e CEXTRAFLAGS='-DNOEDITLINE' all - test: | cd malcc make test diff --git a/Dockerfile b/Dockerfile index 3ca974f..2361ee1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,6 +18,10 @@ RUN cd /tmp && \ ./configure && \ make install +ENV LANG C.UTF-8 +ENV LC_CTYPE C.UTF-8 +ENV LC_ALL C.UTF-8 + WORKDIR /malcc CMD ["bash"] diff --git a/Makefile b/Makefile index c84718c..d87c9e1 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ OS:=$(shell uname) CC=gcc -CFLAGS=-Itinycc -Wall -Wextra -Werror -g +CFLAGS=-Itinycc -Wall -Wextra -Werror -g $(CEXTRAFLAGS) LDLIBS=-ledit -lgc -lpcre -ldl ALL_STEPS=step0_repl step1_read_print step2_eval step3_env step4_if_fn_do step5_tco step6_file step7_quote step8_macros step9_try stepA_mal malcc @@ -20,7 +20,7 @@ step7_quote: step7_quote.o core.o env.o hashmap.o printer.o reader.o types.o uti step8_macros: step8_macros.o core.o env.o hashmap.o printer.o reader.o types.o util.o tinycc/libtcc.a step9_try: step9_try.o core.o env.o hashmap.o printer.o reader.o types.o util.o tinycc/libtcc.a stepA_mal: stepA_mal.o core.o env.o hashmap.o printer.o reader.o types.o util.o tinycc/libtcc.a -malcc: malcc.o core.o env.o hashmap.o printer.o reader.o types.o util.o tinycc/libtcc.a +malcc: malcc.o core.o env.o hashmap.o printer.o reader.o readline.o types.o util.o tinycc/libtcc.a tinycc/libtcc.a: cd tinycc && ./configure && make @@ -98,7 +98,7 @@ test-self-hosted: all $(RUN_TEST_CMD) --test-timeout 30 stepA_mal.mal ../../self_hosted_run test-supplemental: all - $(RUN_TEST_CMD) --test-timeout 30 ../../tests/unicode.mal ../../malcc + $(RUN_TEST_CMD) --test-timeout 30 ../../tests/utf-8.mal ../../malcc perf: all cd mal/tests && ../../malcc perf1.mal && ../../malcc perf2.mal && ../../malcc perf3.mal @@ -115,7 +115,10 @@ docker-bash: docker-build $(RUN_DOCKER_CMD) bash docker-test: docker-build - $(RUN_DOCKER_CMD) make test + $(RUN_DOCKER_CMD) make -e CEXTRAFLAGS='-DNOEDITLINE' test + +docker-test-supplemental: docker-build + $(RUN_DOCKER_CMD) make -e CEXTRAFLAGS='-DNOEDITLINE' test-supplemental docker-watch: docker-build $(RUN_DOCKER_CMD) bash -c "ls *.c *.h Makefile | entr -c -s 'make test'" diff --git a/malcc.c b/malcc.c index 903bb67..43a968f 100644 --- a/malcc.c +++ b/malcc.c @@ -1,5 +1,4 @@ #include -#include #include #include #include @@ -11,6 +10,7 @@ #include "env.h" #include "printer.h" #include "reader.h" +#include "readline.h" #include "util.h" char program_template[] = diff --git a/readline.c b/readline.c new file mode 100644 index 0000000..f545a32 --- /dev/null +++ b/readline.c @@ -0,0 +1,31 @@ +#include +#include + +#ifdef NOEDITLINE + +char* readline(const char *prompt) { + char* input = malloc(1000); + printf("%s", prompt); + return fgets(input, 1000, stdin); +} + +int read_history(const char *filename) { + (void)filename; + return 1; +} + +int add_history(const char *input) { + (void)input; + return 1; +} + +int write_history(const char *filename) { + (void)filename; + return 1; +} + +#else + +#include + +#endif diff --git a/readline.h b/readline.h new file mode 100644 index 0000000..d0124c2 --- /dev/null +++ b/readline.h @@ -0,0 +1,9 @@ +#ifndef __MAL_READLINE__ +#define __MAL_READLINE__ + +char* readline(const char *prompt); +int read_history(const char *filename); +int add_history(const char *input); +int write_history(const char *filename); + +#endif diff --git a/tests/unicode.mal b/tests/utf-8.mal similarity index 100% rename from tests/unicode.mal rename to tests/utf-8.mal -- 2.45.2