From 5811bf4d79f23864c99a96a4320c5d135cd7aebf Mon Sep 17 00:00:00 2001 From: nishi Date: Tue, 23 Apr 2024 02:55:26 +0000 Subject: [PATCH] configgen works git-svn-id: file:///raid/svn-main/nishi-serenade/trunk@8 0f02c867-ac3d-714e-8a88-971ba1f6efcf --- Makefile | 6 +++++- Tool/configgen.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 59 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 3f0f096..3c117fe 100644 --- a/Makefile +++ b/Makefile @@ -10,17 +10,21 @@ SUFFIX = .PHONY: all ./Serenade ./Tool replace -all: ./Tool ./Serenade +all: ./Tool ./config.h ./Serenade ./Tool:: $(MAKE) -C ./Tool CC="$(CC)" CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" LIBS="$(LIBS)" SUFFIX="$(SUFFIX)" +./config.h: + ./Tool/configgen $@ + ./Serenade:: $(MAKE) -C ./Serenade CC="$(CC)" CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" LIBS="$(LIBS)" SUFFIX="$(SUFFIX)" clean: $(MAKE) -C ./Tool clean $(MAKE) -C ./Serenade clean + rm -f config.h FILES = `find . -name "*.c" -or -name "*.h"` diff --git a/Tool/configgen.c b/Tool/configgen.c index 0d84d51..c39df45 100644 --- a/Tool/configgen.c +++ b/Tool/configgen.c @@ -29,5 +29,58 @@ /* --- END LICENSE --- */ #include +#include +#include -int main(){} +const char* asks[] = { + "y", + "HAS_REPL_SUPPORT", + "Do you want the REPL support?", + "n", + "HAS_FFI_SUPPORT", + "Do you want the FFI support?", + NULL +}; + +void show_dialog(int n){ + fprintf(stderr, "[default is %c] %s ", asks[n * 3][0], asks[n * 3 + 2]); + fflush(stderr); +} + +int main(int argc, char** argv){ + FILE* out = stdout; + bool load = false; + if(argv[1] != NULL){ + out = fopen(argv[1], "w"); + if(out != NULL){ + load = true; + }else{ + fprintf(stderr, "%s: %s: couldn't open the file\n", argv[0], argv[1]); + return 1; + } + } + fprintf(out, "/* Autogenerated config */\n"); + char c; + char oldc; + bool nl = false; + int n = 0; + show_dialog(n); + while(true){ + oldc = c; + if(fread(&c, 1, 1, stdin) <= 0) break; + if(c == '\n'){ + char ch = asks[n * 3][0]; + if(nl){ + ch = tolower(oldc); + } + fprintf(out, "#%s %s\n", ch == 'y' ? "define" : "undef", asks[n * 3 + 1]); + n++; + nl = false; + if(asks[n * 3] == NULL) break; + show_dialog(n); + }else{ + nl = true; + } + } + if(load) fclose(out); +} -- 2.43.0