From da8120f5c85aa1b41cb133fa0c5a5669c12b3b28 Mon Sep 17 00:00:00 2001 From: q66 Date: Wed, 5 Oct 2016 21:33:59 +0200 Subject: [PATCH] repl cleanup --- Makefile | 3 +-- tools/edit_linenoise.hh | 8 -------- tools/edit_readline.hh | 8 -------- tools/repl.cc | 10 +++------- 4 files changed, 4 insertions(+), 25 deletions(-) diff --git a/Makefile b/Makefile index 87b972ac..32241365 100644 --- a/Makefile +++ b/Makefile @@ -30,8 +30,7 @@ $(LIBCS_LIB): $(LIBCS_OBJ) repl: $(LIBCS_LIB) tools/repl.cc tools/linenoise.cc tools/linenoise.hh $(CXX) $(CXXFLAGS) $(LIBCS_CXXFLAGS) $(LDFLAGS) \ - -DCS_REPL_USE_LINENOISE -DCS_REPL_HAS_HINTS -DCS_REPL_HAS_COMPLETE \ - tools/linenoise.cc tools/repl.cc -o repl $(LIBCS_LIB) + -DCS_REPL_USE_LINENOISE tools/linenoise.cc tools/repl.cc -o repl $(LIBCS_LIB) clean: rm -f $(LIBCS_LIB) $(LIBCS_OBJ) repl diff --git a/tools/edit_linenoise.hh b/tools/edit_linenoise.hh index 5bc89639..91b973ad 100644 --- a/tools/edit_linenoise.hh +++ b/tools/edit_linenoise.hh @@ -15,7 +15,6 @@ static CsState *ln_cs = nullptr; -#ifdef CS_REPL_HAS_COMPLETE static void ln_complete(char const *buf, linenoiseCompletions *lc) { ostd::ConstCharRange cmd = get_complete_cmd(buf); for (auto id: ln_cs->get_idents()) { @@ -31,9 +30,7 @@ static void ln_complete(char const *buf, linenoiseCompletions *lc) { } } } -#endif /* CS_REPL_HAS_COMPLETE */ -#ifdef CS_REPL_HAS_HINTS static char *ln_hint(char const *buf, int *color, int *bold) { CsCommand *cmd = get_hint_cmd(*ln_cs, buf); if (!cmd) { @@ -52,19 +49,14 @@ static char *ln_hint(char const *buf, int *color, int *bold) { static void ln_hint_free(void *hint) { delete[] static_cast(hint); } -#endif /* CS_REPL_HAS_HINTS */ static void init_lineedit(CsState &cs, ostd::ConstCharRange) { /* sensible default history size */ linenoiseHistorySetMaxLen(1000); ln_cs = &cs; -#ifdef CS_REPL_HAS_COMPLETE linenoiseSetCompletionCallback(ln_complete); -#endif -#ifdef CS_REPL_HAS_HINTS linenoiseSetHintsCallback(ln_hint); linenoiseSetFreeHintsCallback(ln_hint_free); -#endif } static ostd::Maybe read_line(CsState &, CsSvar *pr) { diff --git a/tools/edit_readline.hh b/tools/edit_readline.hh index 1873350b..039963eb 100644 --- a/tools/edit_readline.hh +++ b/tools/edit_readline.hh @@ -13,7 +13,6 @@ static CsState *rd_cs = nullptr; -#ifdef CS_REPL_HAS_COMPLETE static char *ln_complete_list(char const *buf, int state) { static ostd::ConstCharRange cmd; static ostd::PointerRange itr; @@ -45,9 +44,7 @@ static char **ln_complete(char const *buf, int, int) { rl_attempted_completion_over = 1; return rl_completion_matches(buf, ln_complete_list); } -#endif -#ifdef CS_REPL_HAS_HINTS void ln_hint() { CsCommand *cmd = get_hint_cmd(*rd_cs, rl_line_buffer); if (!cmd) { @@ -64,16 +61,11 @@ void ln_hint() { rl_redisplay(); rl_replace_line(old.data(), 0); } -#endif static void init_lineedit(CsState &cs, ostd::ConstCharRange) { rd_cs = &cs; -#ifdef CS_REPL_HAS_COMPLETE rl_attempted_completion_function = ln_complete; -#endif -#ifdef CS_REPL_HAS_HINTS rl_redisplay_function = ln_hint; -#endif } static ostd::Maybe read_line(CsState &, CsSvar *pr) { diff --git a/tools/repl.cc b/tools/repl.cc index d4d8f23f..75e202ee 100644 --- a/tools/repl.cc +++ b/tools/repl.cc @@ -27,8 +27,7 @@ static bool stdin_is_tty() { /* line editing support */ -#ifdef CS_REPL_HAS_COMPLETE -static ostd::ConstCharRange get_complete_cmd(ostd::ConstCharRange buf) { +static inline ostd::ConstCharRange get_complete_cmd(ostd::ConstCharRange buf) { ostd::ConstCharRange not_allowed = "\"/;()[] \t\r\n\0"; ostd::ConstCharRange found = ostd::find_one_of(buf, not_allowed); while (!found.empty()) { @@ -38,9 +37,7 @@ static ostd::ConstCharRange get_complete_cmd(ostd::ConstCharRange buf) { } return buf; } -#endif /* CS_REPL_HAS_COMPLETE */ -#ifdef CS_REPL_HAS_HINTS static inline ostd::ConstCharRange get_arg_type(char arg) { switch (arg) { case 'i': @@ -73,7 +70,7 @@ static inline ostd::ConstCharRange get_arg_type(char arg) { return "illegal"; } -static void fill_cmd_args(ostd::String &writer, ostd::ConstCharRange args) { +static inline void fill_cmd_args(ostd::String &writer, ostd::ConstCharRange args) { char variadic = '\0'; int nrep = 0; if (!args.empty() && ((args.back() == 'V') || (args.back() == 'C'))) { @@ -130,7 +127,7 @@ static void fill_cmd_args(ostd::String &writer, ostd::ConstCharRange args) { } } -static CsCommand *get_hint_cmd(CsState &cs, ostd::ConstCharRange buf) { +static inline CsCommand *get_hint_cmd(CsState &cs, ostd::ConstCharRange buf) { ostd::ConstCharRange nextchars = "([;"; auto lp = ostd::find_one_of(buf, nextchars); if (!lp.empty()) { @@ -153,7 +150,6 @@ static CsCommand *get_hint_cmd(CsState &cs, ostd::ConstCharRange buf) { } return nullptr; } -#endif /* CS_REPL_HAS_HINTS */ #include "edit_linenoise.hh" #include "edit_readline.hh"