diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2021-08-20 06:43:20 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2021-08-20 06:43:20 -0700 |
commit | e263e2ed5cf155936d16a3cd2d91096c02a5e0f1 (patch) | |
tree | 45f2a68fe8246af60e477ec5bdda4ff764407e57 | |
parent | cabd313483e2f2d23aebb9710458b67f0933f98b (diff) | |
download | txr-e263e2ed5cf155936d16a3cd2d91096c02a5e0f1.tar.gz txr-e263e2ed5cf155936d16a3cd2d91096c02a5e0f1.tar.bz2 txr-e263e2ed5cf155936d16a3cd2d91096c02a5e0f1.zip |
configure: implement full-repl option.
This patch unbundles the building of the full-featured REPL
from HAVE_TERMIOS. We make it subject to its own configuration
option CONFIG_FULL_REPL, which is 1 by default. This way, the
downstream users or package maintainers can build TXR without
the full-featured REPL even if HAVE_TERMIOS is 1, and the
other termios material is built-in.
* configure (full_repl): New variable.
(help): Include full-repl in the help text.
In the termios test, if we don't detect termios, then
negate the full_repl variable.
In the final config variable generation section, generate
the CONFIG_FULL_REPL 1 define in config.h, if full_repl
is true, ensuring it is subject to HAVE_TERMIOS, too.
* linenoise/linenoise.c: Replace HAVE_TERMIOS with
CONFIG_FULL_REPL.
* linenoise/linenoise.h: Likewise.
* parser.c: Likewise.
* txr.c: Likewise and ...
(if_termios): Macro renamed to if_full_repl.
(if_full_repl): New macro.
(opt_noninteractive): Use if_full_repl macro for
initializing.
(banner): Use if_ful_repl macro instead of if_termios.
-rwxr-xr-x | configure | 14 | ||||
-rw-r--r-- | linenoise/linenoise.c | 44 | ||||
-rw-r--r-- | linenoise/linenoise.h | 2 | ||||
-rw-r--r-- | parser.c | 16 | ||||
-rw-r--r-- | txr.c | 16 |
5 files changed, 53 insertions, 39 deletions
@@ -186,6 +186,7 @@ extra_debugging= debug_support=y gen_gc=y small_mem= +full_repl=y have_dbl_decimal_dig= have_unistd= have_sys_stat= @@ -546,6 +547,12 @@ small-mem [$small_mem] and certain global book-keeping arrays in the generational garbage collector are smaller, resulting in more frequent collections. +full-repl [$full_repl] + + Support the full listener with editing features. If this is disabled, + only the plain-mode listener is available. Failure to detect the + presence of termios at build configuration time time also disables it. + build-id [$build_id] This option specifies the value of the build_id make variable. @@ -3231,6 +3238,7 @@ if conftest ; then have_termios=y else printf "no\n" + full_repl= fi printf "Checking for struct winsize ... " @@ -3816,6 +3824,12 @@ $make conftest.clean [ -n "$gen_gc" ] && printf "#define CONFIG_GEN_GC 1\n" >> config.h [ "$small_mem" ] && printf "#define CONFIG_SMALL_MEM 1\n" >> config.h +[ "$full_repl" ] && cat >> config.h <<! +#if HAVE_TERMIOS +#define CONFIG_FULL_REPL 1 +#endif +! + # # Regenerate config.make # diff --git a/linenoise/linenoise.c b/linenoise/linenoise.c index 9e2b159f..ec88f378 100644 --- a/linenoise/linenoise.c +++ b/linenoise/linenoise.c @@ -56,7 +56,7 @@ #include <stdarg.h> #include <unistd.h> #include "config.h" -#if HAVE_TERMIOS +#if CONFIG_FULL_REPL #include <termios.h> #include <sys/types.h> #include <sys/ioctl.h> @@ -94,23 +94,23 @@ struct lino_state { lino_t *next, *prev; /* Links for global list: must be first */ /* Lifetime enduring state */ -#if HAVE_TERMIOS +#if CONFIG_FULL_REPL lino_compl_cb_t *completion_callback; #endif void *cb_ctx; /* User context for completion callback */ -#if HAVE_TERMIOS +#if CONFIG_FULL_REPL lino_atom_cb_t *atom_callback; void *ca_ctx; /* User context for atom callback */ #endif lino_enter_cb_t *enter_callback; void *ce_ctx; /* User context for enter callback */ -#if HAVE_TERMIOS +#if CONFIG_FULL_REPL struct termios orig_termios; /* In order to restore at exit.*/ #endif #ifdef __CYGWIN__ int orig_imode, orig_omode; #endif -#if HAVE_TERMIOS +#if CONFIG_FULL_REPL int rawmode; /* For atexit() function to check if restore is needed*/ int mlmode; /* Multi line mode. Default is single line. */ #endif @@ -118,7 +118,7 @@ struct lino_state { int history_len; int loaded_lines; /* How many lines come from load. */ wchar_t **history; -#if HAVE_TERMIOS +#if CONFIG_FULL_REPL wchar_t *clip; /* Selection */ wchar_t *result; /* Previous command result. */ #endif @@ -127,13 +127,13 @@ struct lino_state { int save_hist_idx; /* Jump to history position on entry into edit */ /* Volatile state pertaining to just one linenoise call */ -#if HAVE_TERMIOS +#if CONFIG_FULL_REPL wchar_t buf[LINENOISE_MAX_DISP]; /* Displayed line buffer. */ #endif wchar_t data[LINENOISE_MAX_LINE]; /* True data corresponding to display */ const wchar_t *prompt; /* Prompt to display. */ const char *suffix; /* Suffix when creating temp file. */ -#if HAVE_TERMIOS +#if CONFIG_FULL_REPL int plen; /* Prompt length. */ int pos; /* Current cursor position. */ int sel; /* Selection start in terms of display. */ @@ -154,7 +154,7 @@ struct lino_state { int noninteractive; /* No character editing, even if input is tty. */ #endif int show_prompt; /* Show prompting in non-interactive mode. */ -#if HAVE_TERMIOS +#if CONFIG_FULL_REPL struct lino_undo *undo_stack; #endif lino_error_t error; /* Most recent error. */ @@ -180,13 +180,13 @@ enum key_action { static lino_os_t lino_os; static lino_t lino_list; volatile sig_atomic_t lino_list_busy; -#if HAVE_TERMIOS +#if CONFIG_FULL_REPL static int atexit_registered = 0; /* Register atexit just 1 time. */ #endif #define nelem(array) (sizeof (array) / sizeof (array)[0]) -#if HAVE_TERMIOS +#if CONFIG_FULL_REPL static int wcsnprintf(wchar_t *s, size_t nchar, const wchar_t *fmt, ...) { @@ -204,7 +204,7 @@ static int wcsnprintf(wchar_t *s, size_t nchar, const wchar_t *fmt, ...) /* ======================= Low level terminal handling ====================== */ -#if HAVE_TERMIOS +#if CONFIG_FULL_REPL /* Set if to use or not the multi line mode. */ void lino_set_multiline(lino_t *ls, int ml) { ls->mlmode = ml; @@ -241,7 +241,7 @@ void lino_enable_noninteractive_prompt(lino_t *ls, int enable) ls->show_prompt = enable; } -#if HAVE_TERMIOS +#if CONFIG_FULL_REPL void lino_set_atom_cb(lino_t *l, lino_atom_cb_t *cb, void *ctx) { @@ -257,7 +257,7 @@ void lino_set_enter_cb(lino_t *l, lino_enter_cb_t *cb, void *ctx) l->ce_ctx = ctx; } -#if HAVE_TERMIOS +#if CONFIG_FULL_REPL static void atexit_handler(void); @@ -2568,7 +2568,7 @@ wchar_t *linenoise(lino_t *ls, const wchar_t *prompt) { int ifd = lino_os.fileno_fn(ls->tty_ifs); -#if HAVE_TERMIOS +#if CONFIG_FULL_REPL int noninteractive = ls->noninteractive; int plain = noninteractive || !isatty(ifd); #else @@ -2632,7 +2632,7 @@ wchar_t *linenoise(lino_t *ls, const wchar_t *prompt) return ret; } else { wchar_t *ret = 0; -#if HAVE_TERMIOS +#if CONFIG_FULL_REPL int count; #ifdef SIGWINCH static struct sigaction blank; @@ -2707,7 +2707,7 @@ lino_t *lino_copy(lino_t *le) *ls = *le; ls->history_len = 0; ls->history = 0; -#if HAVE_TERMIOS +#if CONFIG_FULL_REPL ls->rawmode = 0; ls->clip = 0; ls->result = 0; @@ -2725,11 +2725,11 @@ static void free_hist(lino_t *ls); static void lino_cleanup(lino_t *ls) { -#if HAVE_TERMIOS +#if CONFIG_FULL_REPL disable_raw_mode(ls); #endif free_hist(ls); -#if HAVE_TERMIOS +#if CONFIG_FULL_REPL free_undo_stack(ls); lino_os.free_fn(ls->clip); ls->clip = 0; @@ -2781,7 +2781,7 @@ static void free_hist(lino_t *ls) { } } -#if HAVE_TERMIOS +#if CONFIG_FULL_REPL /* At exit we'll try to fix the terminal to the initial conditions. */ static void atexit_handler(void) { @@ -2832,7 +2832,7 @@ int lino_hist_add(lino_t *ls, const wchar_t *line) { } ls->history[ls->history_len] = linecopy; ls->history_len++; -#if HAVE_TERMIOS +#if CONFIG_FULL_REPL undo_renumber_hist_idx(ls, 1); #endif return 1; @@ -2935,7 +2935,7 @@ int lino_have_new_lines(lino_t *ls) return ls->history_len > ls->loaded_lines; } -#if HAVE_TERMIOS +#if CONFIG_FULL_REPL void lino_set_result(lino_t *ls, wchar_t *res) { diff --git a/linenoise/linenoise.h b/linenoise/linenoise.h index 4ad3ce64..5564afb4 100644 --- a/linenoise/linenoise.h +++ b/linenoise/linenoise.h @@ -92,7 +92,7 @@ typedef struct lino_os { wide_disp \ } -#if HAVE_TERMIOS +#if CONFIG_FULL_REPL typedef struct lino_completions { size_t len; @@ -924,7 +924,7 @@ static void load_rcfile(val name) uw_catch_end; } -#if HAVE_TERMIOS +#if CONFIG_FULL_REPL static val get_visible_syms(val package, int include_fallback) { @@ -1491,7 +1491,7 @@ val repl(val bindings, val in_stream, val out_stream, val env) val rcfile = if2(home && !opt_noprofile, scat2(home, lit("/.txr_profile"))); val old_sig_handler = set_sig_handler(num(SIGINT), func_n2(repl_intr)); val hist_len_var = lookup_global_var(listener_hist_len_s); -#if HAVE_TERMIOS +#if CONFIG_FULL_REPL val multi_line_var = lookup_global_var(listener_multi_line_p_s); val sel_inclusive_var = lookup_global_var(listener_sel_inclusive_p_s); #endif @@ -1522,7 +1522,7 @@ val repl(val bindings, val in_stream, val out_stream, val env) reg_varl(result_hash_sym, result_hash); -#if HAVE_TERMIOS +#if CONFIG_FULL_REPL lino_set_completion_cb(ls, provide_completions, 0); lino_set_atom_cb(ls, provide_atom, 0); #endif @@ -1543,7 +1543,7 @@ val repl(val bindings, val in_stream, val out_stream, val env) } } -#if HAVE_TERMIOS +#if CONFIG_FULL_REPL lino_set_noninteractive(ls, opt_noninteractive); #endif @@ -1556,7 +1556,7 @@ val repl(val bindings, val in_stream, val out_stream, val env) uw_frame_t uw_handler; lino_hist_set_max_len(ls, c_num(cdr(hist_len_var), self)); -#if HAVE_TERMIOS +#if CONFIG_FULL_REPL lino_set_multiline(ls, cdr(multi_line_var) != nil); lino_set_selinclusive(ls, cdr(sel_inclusive_var) != nil); #endif @@ -1564,7 +1564,7 @@ val repl(val bindings, val in_stream, val out_stream, val env) reg_varl(var_counter_sym, var_counter); line_w = linenoise(ls, c_str(prompt, self)); -#if HAVE_TERMIOS +#if CONFIG_FULL_REPL rplacd(multi_line_var, tnil(lino_get_multiline(ls))); #endif @@ -1628,13 +1628,13 @@ val repl(val bindings, val in_stream, val out_stream, val env) in_stream, out_stream)); val pprin = cdr(pprint_var); val (*pfun)(val, val) = if3(pprin, pprinl, prinl); -#if HAVE_TERMIOS +#if CONFIG_FULL_REPL val (*tsfun)(val) = if3(pprin, tostringp, tostring); #endif reg_varl(var_sym, value); sethash(result_hash, var_counter, value); pfun(value, out_stream); -#if HAVE_TERMIOS +#if CONFIG_FULL_REPL lino_set_result(ls, chk_strdup(c_str(tsfun(value), self))); #endif lino_hist_add(ls, line_w); @@ -63,10 +63,10 @@ #endif #include "txr.h" -#if HAVE_TERMIOS -#define if_termios(THEN, ELSE) (THEN) +#if CONFIG_FULL_REPL +#define if_full_repl(THEN, ELSE) (THEN) #else -#define if_termios(THEN, ELSE) (ELSE) +#define if_full_repl(THEN, ELSE) (ELSE) #endif const wchli_t *version = wli(TXR_VER); @@ -76,7 +76,7 @@ const wchli_t *build_id = wli(TXR_BUILD_ID); wchar_t *progname; static const char *progname_u8; static val prog_path = nil, sysroot_path = nil; -int opt_noninteractive = if_termios(0, 1); +int opt_noninteractive = if_full_repl(0, 1); int opt_noprofile; int opt_compat; int opt_dbg_expansion; @@ -195,10 +195,10 @@ static void banner(val self) if3(opt_noninteractive, lit("This is the TXR Lisp plain mode listener of TXR ~a.\n" "Quit with :quit or Ctrl-D on an empty line.\n"), - if_termios(lit("This is the TXR Lisp interactive " - "listener of TXR ~a.\n" - "Quit with :quit or Ctrl-D on an empty line. " - "Ctrl-X ? for cheatsheet.\n"), nil)), + if_full_repl(lit("This is the TXR Lisp interactive " + "listener of TXR ~a.\n" + "Quit with :quit or Ctrl-D on an empty line. " + "Ctrl-X ? for cheatsheet.\n"), nil)), static_str(version), nao); } |