aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTristan Riehs <tristan.riehs@bordeaux-inp.fr>2024-05-31 21:56:22 +0900
committerTristan Riehs <tristan.riehs@bordeaux-inp.fr>2024-05-31 21:56:22 +0900
commit1b50145b6f74f0d398bc01ae25d21fd18457a7c5 (patch)
tree111c1d1b5b3a1757ea49924c10fd6a1f4afd2842 /src
parente6aa60e042fce31347c297954b2b15c0875f3482 (diff)
Switch to linenoise instead of readline
The API is the exact same, and this implementation is much lighter and memory-leak-free.
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am9
-rw-r--r--src/calculer.c5
2 files changed, 9 insertions, 5 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index ddf7c6b..728ef88 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,4 +1,7 @@
bin_PROGRAMS = calculer
-AM_CFLAGS = -std=c99 -Wall -Wextra
-AM_LDFLAGS = -lreadline
-calculer_SOURCES = calculer.c
+AM_CFLAGS = -Wall -Wextra -I../linenoise-master/
+calculer_SOURCES = calculer.c linenoise.c
+BUILT_SOURCES: linenoise.c
+
+linenoise.c:
+ cp ../linenoise-master/linenoise.c .
diff --git a/src/calculer.c b/src/calculer.c
index 6ed5983..0c9fe8b 100644
--- a/src/calculer.c
+++ b/src/calculer.c
@@ -24,7 +24,7 @@
#include <string.h>
#include <time.h>
-#include <readline/readline.h>
+#include "linenoise.h"
static int lower = 0;
static int upper = 100;
@@ -67,6 +67,7 @@ main(void)
int x, y, res;
char *input;
+ srand(time(NULL));
logfile = fopen("./calculer.log", "a");
assert(logfile);
@@ -78,7 +79,7 @@ main(void)
res = x+y;
assert(!measure_after(measure_data));
sprintf(prompt, "%d + %d = ", x, y);
- input = readline(prompt);
+ input = linenoise(prompt);
if (strcmp(input, "q") == 0)
{