8000 Make GNU Readline usage optional (USE_READLINE define). Still enabled. · jpralves/micropython@fa02767 · GitHub
[go: up one dir, main page]

Skip to content

Commit fa02767

Browse files
committed
Make GNU Readline usage optional (USE_READLINE define). Still enabled.
Readline is GPL, so linking with it casts the binary GPL.
1 parent 903b24f commit fa02767

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

unix/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ PYSRC=../py
22
BUILD=build
33

44
CC = gcc
5-
CFLAGS = -I. -I$(PYSRC) -Wall -Werror -ansi -std=gnu99 -Os #-DNDEBUG
5+
CFLAGS = -I. -I$(PYSRC) -Wall -Werror -ansi -std=gnu99 -Os -DUSE_READLINE #-DNDEBUG
66
LDFLAGS = -lm
77

88
SRC_C = \

unix/main.c

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@
1515
#include "runtime.h"
1616
#include "repl.h"
1717

18+
#ifdef USE_READLINE
1819
#include <readline/readline.h>
1920
#include <readline/history.h>
21+
#endif
2022

2123
static char *str_join(const char *s1, int sep_char, const char *s2) {
2224
int l1 = strlen(s1);
@@ -32,17 +34,41 @@ static char *str_join(const char *s1, int sep_char, const char *s2) {
3234
return s;
3335
}
3436

37+
static char *prompt(char *p) {
38+
#ifdef USE_READLINE
39+
char *line = readline(p);
40+
if (line) {
41+
add_history(line);
42+
}
43+
#else
44+
static char buf[256];
45+
fputs(p, stdout);
46+
char *s = fgets(buf, sizeof(buf), stdin);
47+
if (!s) {
48+
return NULL;
49+
}
50+
int l = strlen(buf);
51+
if (buf[l - 1] == '\n') {
52+
buf[l - 1] = 0;
53+
} else {
54+
l++;
55+
}
56+
char *line = m_new(char, l);
57+
memcpy(line, buf, l);
58+
#endif
59+
return line;
60+
}
61+
3562
static void do_repl(void) {
3663
for (;;) {
37-
char *line = readline(">>> ");
64+
char *line = prompt(">>> ");
3865
if (line == NULL) {
3966
// EOF
4067
return;
4168
}
42-
add_history(line);
4369
if (mp_repl_is_compound_stmt(line)) {
4470
for (;;) {
45-
char *line2 = readline("... ");
71+
char *line2 = prompt("... ");
4672
if (line2 == NULL || strlen(line2) == 0) {
4773
break;
4874
}

0 commit comments

Comments
 (0)
0