Skip to content
Snippets Groups Projects
Commit fa027672 authored by Paul Sokolovsky's avatar Paul Sokolovsky
Browse files

Make GNU Readline usage optional (USE_READLINE define). Still enabled.

Readline is GPL, so linking with it casts the binary GPL.
parent 903b24f0
No related branches found
No related tags found
No related merge requests found
...@@ -2,7 +2,7 @@ PYSRC=../py ...@@ -2,7 +2,7 @@ PYSRC=../py
BUILD=build BUILD=build
CC = gcc CC = gcc
CFLAGS = -I. -I$(PYSRC) -Wall -Werror -ansi -std=gnu99 -Os #-DNDEBUG CFLAGS = -I. -I$(PYSRC) -Wall -Werror -ansi -std=gnu99 -Os -DUSE_READLINE #-DNDEBUG
LDFLAGS = -lm LDFLAGS = -lm
SRC_C = \ SRC_C = \
......
...@@ -15,8 +15,10 @@ ...@@ -15,8 +15,10 @@
#include "runtime.h" #include "runtime.h"
#include "repl.h" #include "repl.h"
#ifdef USE_READLINE
#include <readline/readline.h> #include <readline/readline.h>
#include <readline/history.h> #include <readline/history.h>
#endif
static char *str_join(const char *s1, int sep_char, const char *s2) { static char *str_join(const char *s1, int sep_char, const char *s2) {
int l1 = strlen(s1); int l1 = strlen(s1);
...@@ -32,17 +34,41 @@ static char *str_join(const char *s1, int sep_char, const char *s2) { ...@@ -32,17 +34,41 @@ static char *str_join(const char *s1, int sep_char, const char *s2) {
return s; return s;
} }
static char *prompt(char *p) {
#ifdef USE_READLINE
char *line = readline(p);
if (line) {
add_history(line);
}
#else
static char buf[256];
fputs(p, stdout);
char *s = fgets(buf, sizeof(buf), stdin);
if (!s) {
return NULL;
}
int l = strlen(buf);
if (buf[l - 1] == '\n') {
buf[l - 1] = 0;
} else {
l++;
}
char *line = m_new(char, l);
memcpy(line, buf, l);
#endif
return line;
}
static void do_repl(void) { static void do_repl(void) {
for (;;) { for (;;) {
char *line = readline(">>> "); char *line = prompt(">>> ");
if (line == NULL) { if (line == NULL) {
// EOF // EOF
return; return;
} }
add_history(line);
if (mp_repl_is_compound_stmt(line)) { if (mp_repl_is_compound_stmt(line)) {
for (;;) { for (;;) {
char *line2 = readline("... "); char *line2 = prompt("... ");
if (line2 == NULL || strlen(line2) == 0) { if (line2 == NULL || strlen(line2) == 0) {
break; break;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment