diff options
author | Tristan Riehs <tristan.riehs@bordeaux-inp.fr> | 2024-06-30 17:00:48 +0900 |
---|---|---|
committer | Tristan Riehs <tristan.riehs@bordeaux-inp.fr> | 2024-06-30 17:00:48 +0900 |
commit | c48f0176412f2c15fbb3cbc6052550959f581da9 (patch) | |
tree | 8d637080281f0b50f3a303e5a62ccb44e2201b21 | |
parent | 46e6de294243e8dc593551bfe8c0e7090d03a159 (diff) |
Displays are not shared libraries, but object files that are part of
the final executable.
-rw-r--r-- | src/Makefile.am | 4 | ||||
-rw-r--r-- | src/calculer.c | 2 | ||||
-rw-r--r-- | src/cli.c | 12 | ||||
-rw-r--r-- | src/disp.c | 23 | ||||
-rw-r--r-- | src/ray.c | 11 | ||||
-rw-r--r-- | src/tui.c | 11 |
6 files changed, 58 insertions, 5 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index d8f6457..3c4c982 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -28,7 +28,9 @@ linenoise_lib.c: endif # USE_READLINE_COND else # DEBUG_COND -AM_CFLAGS += -DNDEBUG -Wno-unused-variable +AM_CFLAGS += -DNDEBUG +calculer_SOURCES += calc_data.c input.c cli.c tui.c ray.c +AM_LDFLAGS += -lncurses if USE_READLINE_COND AM_LDFLAGS += -lreadline diff --git a/src/calculer.c b/src/calculer.c index 705fb74..6bf8fbb 100644 --- a/src/calculer.c +++ b/src/calculer.c @@ -153,7 +153,7 @@ main(int argc, char *argv[]) time_t now = time(NULL); struct tm *tm = localtime(&now); size_t bytes_written = strftime(logbuf, sizeof(logbuf), "%F\t", tm); - assert(bytes_written); + assert(bytes_written); /* TODO: better handling */ int opt; while ((opt = getopt(argc, argv, ":Vhl:m:M:i:")) != -1) @@ -29,6 +29,7 @@ void cli_display_calc(int x, int y) { printf("%d + %d = ", x, y); + fflush(stdout); } int @@ -60,3 +61,14 @@ void cli_destroy(void) {} void *cli_pre_reload(void) {return NULL;} void cli_post_reload(void *) {} #endif + +#ifdef NDEBUG +static struct disp __cli_disp = { + .init = cli_init, + .display_calc = cli_display_calc, + .read_input = cli_read_input, + .display_res = cli_display_res, + .destroy = cli_destroy +}; +struct disp *cli_disp = &__cli_disp; +#endif @@ -25,6 +25,13 @@ #include "disp.h" +#ifdef NDEBUG +extern struct disp *cli_disp; +extern struct disp *tui_disp; +extern struct disp *ray_disp; +#endif + +#ifndef NDEBUG static void * load_generic_symbol(struct disp *disp, char *base_name) { @@ -46,8 +53,9 @@ load_generic_symbol(struct disp *disp, char *base_name) return ptr; } +#endif - +#ifndef NDEBUG static void load_symbols(struct disp *disp) { @@ -72,6 +80,7 @@ load_symbols(struct disp *disp) printf("INFO: successfully loaded symbols from \"%s\"\n", disp->so_path); } +#endif struct disp * get_disp(char *disp_name) @@ -90,9 +99,15 @@ get_disp(char *disp_name) return disp; #else -# error "not available yet" -#endif + if (strcmp(disp_name, "cli") == 0) + return cli_disp; + if (strcmp(disp_name, "tui") == 0) + return tui_disp; + if (strcmp(disp_name, "ray") == 0) + return ray_disp; + return NULL; +#endif } void @@ -101,11 +116,13 @@ destroy_disp(struct disp *disp) if (disp->destroy) disp->destroy(); +#ifndef NDEBUG if (disp->dl_handle) dlclose(disp->dl_handle); free(disp->so_path); free(disp); +#endif } #ifndef NDEBUG @@ -292,3 +292,14 @@ ray_post_reload(void *state) TraceLog(LOG_INFO, "post-reload actions done"); } #endif + +#ifdef NDEBUG +static struct disp __ray_disp = { + .init = ray_init, + .display_calc = ray_display_calc, + .read_input = ray_read_input, + .display_res = ray_display_res, + .destroy = ray_destroy +}; +struct disp *ray_disp = &__ray_disp; +#endif @@ -171,3 +171,14 @@ tui_post_reload(void *state) redraw(); } #endif + +#ifdef NDEBUG +static struct disp __tui_disp = { + .init = tui_init, + .display_calc = tui_display_calc, + .read_input = tui_read_input, + .display_res = tui_display_res, + .destroy = tui_destroy +}; +struct disp *tui_disp = &__tui_disp; +#endif |