aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/calculer.c2
-rw-r--r--src/cli.c33
-rw-r--r--src/disp.c27
-rw-r--r--src/disp.h15
-rw-r--r--src/ray.c27
-rw-r--r--src/tui.c15
6 files changed, 27 insertions, 92 deletions
diff --git a/src/calculer.c b/src/calculer.c
index 7b5b7db..2abd68a 100644
--- a/src/calculer.c
+++ b/src/calculer.c
@@ -193,13 +193,11 @@ main(int argc, char *argv[])
fclose(logfile);
exit(0);
}
-#ifndef NDEBUG
else if (input == DISP_RELOAD)
{
disp_reload(disp);
continue;
}
-#endif
measure_after(measure_data, input == res);
disp->display_res(input == res, ms);
}
diff --git a/src/cli.c b/src/cli.c
index bf944e0..0ea3eed 100644
--- a/src/cli.c
+++ b/src/cli.c
@@ -18,19 +18,27 @@ cli_display_calc(int x, int y)
int
cli_read_input(void)
{
- char *txt = readline("");
+ char *txt = readline(NULL);
- if ((!txt) || (txt[0] == '\0')) {
+ if (!txt)
+ {
return DISP_QUIT;
}
- else if (txt[0] == 'q') {
+ else if (txt[0] == '\0')
+ {
free(txt);
return DISP_QUIT;
}
-#ifndef NDEBUG
- if ((*txt == 'r') || (*txt == 'g'))
+ else if (txt[0] == 'q')
+ {
+ free(txt);
+ return DISP_QUIT;
+ }
+ else if ((txt[0] == 'r') || (txt[0] == 'g'))
+ {
+ free(txt);
return DISP_RELOAD;
-#endif
+ }
int res = atoi(txt);
free(txt);
@@ -45,18 +53,5 @@ cli_display_res(bool ok, int ms)
void cli_destroy(void) {}
-#ifndef NDEBUG
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
diff --git a/src/disp.c b/src/disp.c
index fa1559c..c4c1cd6 100644
--- a/src/disp.c
+++ b/src/disp.c
@@ -7,13 +7,6 @@
#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)
{
@@ -35,9 +28,7 @@ load_generic_symbol(struct disp *disp, char *base_name)
return ptr;
}
-#endif
-#ifndef NDEBUG
static void
load_symbols(struct disp *disp)
{
@@ -62,12 +53,10 @@ load_symbols(struct disp *disp)
printf("INFO: successfully loaded symbols from \"%s\"\n",
disp->so_path);
}
-#endif
struct disp *
get_disp(char *disp_name)
{
-#ifndef NDEBUG
/* displays are shared libraries */
char so_path[128];
strcpy(so_path, CALCULER_PREFIX);
@@ -81,16 +70,6 @@ get_disp(char *disp_name)
load_symbols(disp);
return disp;
-#else
- 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
@@ -98,17 +77,12 @@ 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
void
disp_reload(struct disp *disp)
{
@@ -126,4 +100,3 @@ disp_reload(struct disp *disp)
printf("INFO: reloading done\n");
}
-#endif
diff --git a/src/disp.h b/src/disp.h
index 4b1a04c..4b7b163 100644
--- a/src/disp.h
+++ b/src/disp.h
@@ -10,33 +10,28 @@
#define DISP_TUI "tui"
/* Reserved return values for the read_input function. */
-#ifndef NDEBUG
-# define DISP_RELOAD INT_MAX
-#endif
+#define DISP_RELOAD INT_MAX
#define DISP_QUIT (INT_MAX - 1)
#define DISP_ERR (INT_MAX - 2)
struct disp {
+ char *name;
+ void *dl_handle;
+ char *so_path;
void (*init)(void);
void (*display_calc)(int, int);
int (*read_input)(void);
void (*display_res)(bool, int);
void (*destroy)(void);
-#ifndef NDEBUG
- char *name;
- void *dl_handle;
- char *so_path;
void *(*pre_reload)(void);
void (*post_reload)(void *);
-#endif
};
/* Get a display handler for the given display type. */
struct disp *get_disp(char *);
+
void destroy_disp(struct disp *);
-#ifndef NDEBUG
void disp_reload(struct disp *);
-#endif /* NDEBUG */
#endif /* DISP_H */
diff --git a/src/ray.c b/src/ray.c
index c99fc3b..5000599 100644
--- a/src/ray.c
+++ b/src/ray.c
@@ -20,11 +20,7 @@ static int current_idx = 0;
void
ray_init(void)
{
-#ifndef NDEBUG
- SetTraceLogLevel(LOG_DEBUG);
-#else
SetTraceLogLevel(LOG_ERROR);
-#endif
InitWindow(DEFAULT_WIDTH, DEFAULT_HEIGHT, "calculer");
@@ -218,15 +214,21 @@ ray_read_input(void)
PollInputEvents();
if (IsWindowResized())
+ {
redraw();
+ }
if (IsKeyPressed(KEY_ENTER))
+ {
return calcs[current_idx].input;
+ }
if (IsKeyPressed(KEY_Q) || IsKeyPressed(KEY_A))
+ {
return DISP_QUIT;
-#ifndef NDEBUG
+ }
if (IsKeyPressed(KEY_R) || IsKeyPressed(KEY_G))
+ {
return DISP_RELOAD;
-#endif
+ }
if (IsKeyPressed(KEY_BACKSPACE))
{
calcs[current_idx].input =
@@ -253,7 +255,6 @@ ray_destroy(void)
CloseWindow();
}
-#ifndef NDEBUG
void *
ray_pre_reload(void)
{
@@ -273,15 +274,3 @@ ray_post_reload(void *state)
free(data);
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
diff --git a/src/tui.c b/src/tui.c
index 3a82414..09a039b 100644
--- a/src/tui.c
+++ b/src/tui.c
@@ -83,11 +83,9 @@ tui_read_input(void)
{
switch(c)
{
-#ifndef NDEBUG
case 'g':
case 'r':
return DISP_RELOAD;
-#endif
case 'q':
return DISP_QUIT;
case '\n':
@@ -133,7 +131,6 @@ tui_destroy(void)
endwin();
}
-#ifndef NDEBUG
void *
tui_pre_reload(void)
{
@@ -154,15 +151,3 @@ tui_post_reload(void *state)
tui_init();
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