aboutsummaryrefslogtreecommitdiff
path: root/src/lib/libc/readline.c
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2016-07-16 15:59:46 +0200
committerAlex Auvolat <alex@adnab.me>2016-07-16 15:59:46 +0200
commit3d6a857b9186ef6304ea6cf04627c2b787169f29 (patch)
tree756179ce1e1838f75c57e3efec2a570d72051594 /src/lib/libc/readline.c
parent59000174aa50ed6b2d24a71576d15e6a53c5be0c (diff)
downloadkogata-3d6a857b9186ef6304ea6cf04627c2b787169f29.tar.gz
kogata-3d6a857b9186ef6304ea6cf04627c2b787169f29.zip
Make way for libc implementation
Diffstat (limited to 'src/lib/libc/readline.c')
-rw-r--r--src/lib/libc/readline.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/lib/libc/readline.c b/src/lib/libc/readline.c
new file mode 100644
index 0000000..20c2007
--- /dev/null
+++ b/src/lib/libc/readline.c
@@ -0,0 +1,49 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#include <readline/readline.h>
+
+// ** READLINE
+
+#define READLINE_MAX_LEN 256
+
+typedef struct _rdln_hist {
+ int max;
+ int n;
+ char **str;
+} readline_history;
+
+readline_history stdio_history = {0, 0, 0};
+
+
+char *readline(const char* prompt) {
+ // readline_history *h = &stdio_history;
+
+ puts(prompt);
+
+ char* buf = malloc(READLINE_MAX_LEN);
+ if (buf == NULL) return NULL;
+
+ char* ret = fgets(buf, READLINE_MAX_LEN, stdin);
+ if (ret == NULL) {
+ free(buf);
+ return NULL;
+ }
+
+ int n = strlen(ret);
+ if (n > 0 && ret[n-1] == '\n') ret[n-1] = 0;
+
+ // TODO
+
+ return ret;
+}
+
+void add_history(const char* line) {
+ // readline_history *h = &stdio_history;
+
+ // TODO
+}
+
+
+/* vim: set sts=0 ts=4 sw=4 tw=0 noet :*/