summaryrefslogtreecommitdiffstats
path: root/parser.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2021-08-20 05:47:57 -0700
committerKaz Kylheku <kaz@kylheku.com>2021-08-20 05:47:57 -0700
commit4aaf96f5aaab5c249c3c8ea6d24ee6683bca6f10 (patch)
treea55a4672b67612a05726e820ce9c99f5b8e6a503 /parser.c
parentf374abcd23a63f628a9ec7b84e2d797d3fc28342 (diff)
downloadtxr-4aaf96f5aaab5c249c3c8ea6d24ee6683bca6f10.tar.gz
txr-4aaf96f5aaab5c249c3c8ea6d24ee6683bca6f10.tar.bz2
txr-4aaf96f5aaab5c249c3c8ea6d24ee6683bca6f10.zip
listener: unbundle from termios.
This commit fixes the conceptual issue that when there is no termios support (HAVE_TERMIOS is absent/false), then there is no listener at all, even though the listener supports plain mode that doesn't require termios. * Makefile (linenoise/linenoise.o): Link in unconditionally, not subject to have_termios. * linenoise.c: Include termios-related header only if HAVE_TERMIOS. (struct lino_state): Define the completion_callback and orig_termios members only if HAVE_TERMIOS. (wcnsprintf, atexit_handler, enable_raw_mode, disable_raw_mode, get_cursor_position, get_columns, lino_clear_screen, refresh_line, handle_resize, generate_beep, delete_undo, free_undo_stack, record_undo, record_triv_undo, remove_noop_undo, restore_undo, undo_subst_hist_idx, undo_renumber_hist_idx, free_completions, sync_data_to_buf, compare_completions, complete_line, lino_set_completion_cb, lino_add_completion, next_hist_match, copy_display_params, history_search, ab_init, ab_append, ab_free, sync_data_to_buf, copy_display_params, refresh_singleline, col_offset_in_str, refresh_multiline, refresh_line, move_cursor_multiline, move_cursor, scan_match_rev, scan_rev, scan_match_fwd, scan_fwd, find_nearest_paren, usec_delay, paren_jump, flash, yank, yank_by_ptr, update_sel, clear_sel, yank_sel, delete_sel, edit_insert, edit_insert_str, edit_move_left, edit_move_right, edit_move_home, edit_move_sol, edit_move_end, edit_move_eol, edit_move_matching_paren, edit_history_next, edit_delete, edit_backspace, edit_delete_prev_all, edit_delete_to_eol, edit_delete_prev_word, edit_delete_line, tr, char, edit_in_editor, edit, sigwinch_handler): Functions defined only if HAVE_TERMIOS. (struct abuf, struct row_values): Struct types defined only if HAVE_TERMIOS. (screen_rows): Defined only if HAVE_TERMIOS. (linenoise): Support only noninteractive read loop unless HAVE_TERMIOS. (lino_make): If HAVE_TERMIOS is false, then set the noninteractive flag, so the linenoise function enters the plain-mode loop. (lino_cleanup, lino_hist_add): Add #ifdefs to avoid calling nonexistent functions when HAVE_TERMIOS is false. * linenoise/linenoise.h (struct lino_completions, lino_compl_cb_t): Define these types only if HAVE_TERMIOS. (lino_set_completion_cb, lino_add_completion): Declare only if HAVE_TERMIOS. * parser.c: Include linenoise/linenoise.h unconditionally. (report_security_problem, load_rcfile, repl_intr, read_eval_ret_last, get_home_path, repl_warning, is_balanced_line, hist_save): Now define regardless of HAVE_TERMIOS. (repl): Define regardless of HAVE_TERMIOS, but don't set completion or atom callback if HAVE_TERMIOS is false. * parser.h (repl): Declare unconditionally, not subject to HAVE_TERMIOS. * txr.c (if_termios): New macro. (opt_noninteractive): Initialize to 1 if HAVE_TERMIOS is false. (help): Text about entering into listener mode is always present now, even in a build withou HAVE_TERMIOS. (banner): Function is always defined. If we don't HAVE_TERMIOS, then the unused string literal that will never be printed is replaced by nil. (hint): Function removed. (txr_main): Blocks conditional on HAVE_TERMIOS that either call banner and go to the repl, or else call hint and exit, are reduced to unconditionally calling banner and going to the repl. All #if HAVE_TERMIOS blocks are similarly replaced with just the HAVE_TERMIOS case.
Diffstat (limited to 'parser.c')
-rw-r--r--parser.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/parser.c b/parser.c
index bfbfa625..6df51fda 100644
--- a/parser.c
+++ b/parser.c
@@ -66,9 +66,7 @@
#include "vm.h"
#include "ffi.h"
#include "txr.h"
-#if HAVE_TERMIOS
#include "linenoise/linenoise.h"
-#endif
val parser_s, unique_s, circref_s;
val listener_hist_len_s, listener_multi_line_p_s, listener_sel_inclusive_p_s;
@@ -863,8 +861,6 @@ val txr_parse(val source_in, val error_stream,
return pi->syntax_tree;
}
-#if HAVE_TERMIOS
-
static void report_security_problem(val name)
{
val self = lit("listener");
@@ -928,6 +924,8 @@ static void load_rcfile(val name)
uw_catch_end;
}
+#if HAVE_TERMIOS
+
static val get_visible_syms(val package, int include_fallback)
{
val fblist;
@@ -1159,6 +1157,8 @@ static wchar_t *provide_atom(lino_t *l, const wchar_t *str, int n, void *ctx)
return out;
}
+#endif
+
static val repl_intr(val signo, val async_p)
{
(void) signo;
@@ -1520,8 +1520,11 @@ val repl(val bindings, val in_stream, val out_stream, val env)
reg_varl(result_hash_sym, result_hash);
+#if HAVE_TERMIOS
lino_set_completion_cb(ls, provide_completions, 0);
lino_set_atom_cb(ls, provide_atom, 0);
+#endif
+
lino_set_enter_cb(ls, is_balanced_line, 0);
lino_set_tempfile_suffix(ls, ".tl");
@@ -1680,8 +1683,6 @@ val repl(val bindings, val in_stream, val out_stream, val env)
return nil;
}
-#endif
-
val parser_errors(val parser)
{
val self = lit("parser-errors");