diff --git a/tools/edit_fallback.hh b/tools/edit_fallback.hh index 5175509d..ebebdc72 100644 --- a/tools/edit_fallback.hh +++ b/tools/edit_fallback.hh @@ -5,20 +5,15 @@ #include -static void init_lineedit(cs_state &, ostd::string_range) { +inline void init_lineedit(cs_state &, ostd::string_range) { } -static std::optional read_line(cs_state &, cs_svar *pr) { +inline std::optional read_line(cs_state &, cs_svar *pr) { ostd::write(pr->get_value()); - std::string ret; - /* i really need to implement some sort of get_line for ostd streams */ - for (char c = ostd::in.getchar(); c && (c != '\n'); c = ostd::in.getchar()) { - ret += c; - } - return std::move(ret); + return std::move(ostd::cin.get_line(ostd::appender()).get()); } -static void add_history(cs_state &, ostd::string_range) { +inline void add_history(cs_state &, ostd::string_range) { } #endif diff --git a/tools/edit_linenoise.hh b/tools/edit_linenoise.hh index 750017b5..cdb98d19 100644 --- a/tools/edit_linenoise.hh +++ b/tools/edit_linenoise.hh @@ -16,7 +16,7 @@ static cs_state *ln_cs = nullptr; -static void ln_complete(char const *buf, linenoiseCompletions *lc) { +inline void ln_complete(char const *buf, linenoiseCompletions *lc) { ostd::string_range cmd = get_complete_cmd(buf); for (auto id: ln_cs->get_idents()) { if (!id->is_command()) { @@ -32,7 +32,7 @@ static void ln_complete(char const *buf, linenoiseCompletions *lc) { } } -static char *ln_hint(char const *buf, int *color, int *bold) { +inline char *ln_hint(char const *buf, int *color, int *bold) { cs_command *cmd = get_hint_cmd(*ln_cs, buf); if (!cmd) { return nullptr; @@ -47,11 +47,11 @@ static char *ln_hint(char const *buf, int *color, int *bold) { return ret; } -static void ln_hint_free(void *hint) { +inline void ln_hint_free(void *hint) { delete[] static_cast(hint); } -static void init_lineedit(cs_state &cs, ostd::string_range) { +inline void init_lineedit(cs_state &cs, ostd::string_range) { /* sensible default history size */ linenoiseHistorySetMaxLen(1000); ln_cs = &cs; @@ -60,7 +60,7 @@ static void init_lineedit(cs_state &cs, ostd::string_range) { linenoiseSetFreeHintsCallback(ln_hint_free); } -static std::optional read_line(cs_state &, cs_svar *pr) { +inline std::optional read_line(cs_state &, cs_svar *pr) { auto line = linenoise(pr->get_value().data()); if (!line) { /* linenoise traps ctrl-c, detect it and let the user exit */ @@ -75,7 +75,7 @@ static std::optional read_line(cs_state &, cs_svar *pr) { return std::move(ret); } -static void add_history(cs_state &, ostd::string_range line) { +inline void add_history(cs_state &, ostd::string_range line) { /* backed by std::string so it's terminated */ linenoiseHistoryAdd(line.data()); } diff --git a/tools/edit_readline.hh b/tools/edit_readline.hh index d7462a01..0d97db50 100644 --- a/tools/edit_readline.hh +++ b/tools/edit_readline.hh @@ -14,9 +14,9 @@ static cs_state *rd_cs = nullptr; -static char *ln_complete_list(char const *buf, int state) { +inline char *ln_complete_list(char const *buf, int state) { static ostd::string_range cmd; - static ostd::PointerRange itr; + static ostd::iterator_range itr; if (!state) { cmd = get_complete_cmd(buf); @@ -41,12 +41,12 @@ static char *ln_complete_list(char const *buf, int state) { return nullptr; } -static char **ln_complete(char const *buf, int, int) { +inline char **ln_complete(char const *buf, int, int) { rl_attempted_completion_over = 1; return rl_completion_matches(buf, ln_complete_list); } -void ln_hint() { +inline void ln_hint() { cs_command *cmd = get_hint_cmd(*rd_cs, rl_line_buffer); if (!cmd) { rl_redisplay(); @@ -63,13 +63,13 @@ void ln_hint() { rl_replace_line(old.data(), 0); } -static void init_lineedit(cs_state &cs, ostd::string_range) { +inline void init_lineedit(cs_state &cs, ostd::string_range) { rd_cs = &cs; rl_attempted_completion_function = ln_complete; rl_redisplay_function = ln_hint; } -static std::optional read_line(cs_state &, cs_svar *pr) { +inline std::optional read_line(cs_state &, cs_svar *pr) { auto line = readline(pr->get_value().data()); if (!line) { return std::string(); @@ -79,7 +79,7 @@ static std::optional read_line(cs_state &, cs_svar *pr) { return std::move(ret); } -static void add_history(cs_state &, ostd::string_range line) { +inline void add_history(cs_state &, ostd::string_range line) { /* backed by std::string so it's terminated */ add_history(line.data()); } diff --git a/tools/repl.cc b/tools/repl.cc index dac40dd5..aca84e39 100644 --- a/tools/repl.cc +++ b/tools/repl.cc @@ -28,7 +28,7 @@ static bool stdin_is_tty() { /* line editing support */ -static inline ostd::string_range get_complete_cmd(ostd::string_range buf) { +inline ostd::string_range get_complete_cmd(ostd::string_range buf) { ostd::string_range not_allowed = "\"/;()[] \t\r\n\0"; ostd::string_range found = ostd::find_one_of(buf, not_allowed); while (!found.empty()) { @@ -39,7 +39,7 @@ static inline ostd::string_range get_complete_cmd(ostd::string_range buf) { return buf; } -static inline ostd::string_range get_arg_type(char arg) { +inline ostd::string_range get_arg_type(char arg) { switch (arg) { case 'i': return "int"; @@ -71,7 +71,7 @@ static inline ostd::string_range get_arg_type(char arg) { return "illegal"; } -static inline void fill_cmd_args(std::string &writer, ostd::string_range args) { +inline void fill_cmd_args(std::string &writer, ostd::string_range args) { char variadic = '\0'; int nrep = 0; if (!args.empty() && ((args.back() == 'V') || (args.back() == 'C'))) { @@ -128,7 +128,7 @@ static inline void fill_cmd_args(std::string &writer, ostd::string_range args) { } } -static inline cs_command *get_hint_cmd(cs_state &cs, ostd::string_range buf) { +inline cs_command *get_hint_cmd(cs_state &cs, ostd::string_range buf) { ostd::string_range nextchars = "([;"; auto lp = ostd::find_one_of(buf, nextchars); if (!lp.empty()) {