226 lines
6.6 KiB
Diff
226 lines
6.6 KiB
Diff
|
|
From 22a4cc173a2712dc07e1a8298e4756dcab22fd33 Mon Sep 17 00:00:00 2001
|
||
|
|
From: Mark Nudelman <markn@greenwoodsoftware.com>
|
||
|
|
Date: Sun, 9 Oct 2022 10:39:34 -0700
|
||
|
|
Subject: [PATCH 05/48] lesstest: in interactive mode, call setup_term before
|
||
|
|
less_envp so that terminfo is populated.
|
||
|
|
|
||
|
|
---
|
||
|
|
lesstest/lesstest.h | 2 +-
|
||
|
|
lesstest/lt_screen.c | 29 ++++++++++++++++++++---------
|
||
|
|
lesstest/pipeline.c | 2 +-
|
||
|
|
lesstest/run.c | 15 +++++----------
|
||
|
|
lesstest/runtest | 1 +
|
||
|
|
lesstest/term.c | 17 +----------------
|
||
|
|
6 files changed, 29 insertions(+), 37 deletions(-)
|
||
|
|
|
||
|
|
diff --git a/lesstest/lesstest.h b/lesstest/lesstest.h
|
||
|
|
index 2a964e6..8585f34 100644
|
||
|
|
--- a/lesstest/lesstest.h
|
||
|
|
+++ b/lesstest/lesstest.h
|
||
|
|
@@ -73,7 +73,7 @@ void free_test_setup(TestSetup* setup);
|
||
|
|
TestSetup* read_test_setup(FILE* fd, char const* less);
|
||
|
|
int read_zline(FILE* fd, char* line, int line_len);
|
||
|
|
void raw_mode(int tty, int on);
|
||
|
|
-int setup_term(char* const* envp);
|
||
|
|
+int setup_term(void);
|
||
|
|
void display_screen(const byte* img, int imglen, int screen_width, int screen_height, int move_cursor);
|
||
|
|
const char* get_envp(char* const* envp, const char* name);
|
||
|
|
int run_interactive(char* const* argv, int argc, char* const* envp);
|
||
|
|
diff --git a/lesstest/lt_screen.c b/lesstest/lt_screen.c
|
||
|
|
index 1dbf3b6..1552557 100644
|
||
|
|
--- a/lesstest/lt_screen.c
|
||
|
|
+++ b/lesstest/lt_screen.c
|
||
|
|
@@ -8,7 +8,7 @@
|
||
|
|
|
||
|
|
static const char version[] = "lt_screen|v=1";
|
||
|
|
|
||
|
|
-int usage() {
|
||
|
|
+int usage(void) {
|
||
|
|
fprintf(stderr, "usage: lt_screen\n");
|
||
|
|
return 0;
|
||
|
|
}
|
||
|
|
@@ -46,7 +46,7 @@ static int verbose = 0;
|
||
|
|
|
||
|
|
// ------------------------------------------------------------------
|
||
|
|
|
||
|
|
-static void screen_init() {
|
||
|
|
+static void screen_init(void) {
|
||
|
|
screen.w = 80;
|
||
|
|
screen.h = 24;
|
||
|
|
screen.cx = 0;
|
||
|
|
@@ -58,7 +58,7 @@ static void screen_init() {
|
||
|
|
screen.params[0] = 0;
|
||
|
|
}
|
||
|
|
|
||
|
|
-static void param_print() {
|
||
|
|
+static void param_print(void) {
|
||
|
|
int i;
|
||
|
|
fprintf(stderr, "(");
|
||
|
|
for (i = 0; i <= screen.param_top; ++i)
|
||
|
|
@@ -72,7 +72,7 @@ static void param_push(int v) {
|
||
|
|
screen.params[++screen.param_top] = v;
|
||
|
|
}
|
||
|
|
|
||
|
|
-static int param_pop(){
|
||
|
|
+static int param_pop(void){
|
||
|
|
if (screen.param_top < 0)
|
||
|
|
return 0; // missing param is assumed to be 0
|
||
|
|
return screen.params[screen.param_top--];
|
||
|
|
@@ -162,25 +162,25 @@ static int screen_move(int x, int y) {
|
||
|
|
return 1;
|
||
|
|
}
|
||
|
|
|
||
|
|
-static int screen_cr() {
|
||
|
|
+static int screen_cr(void) {
|
||
|
|
screen.cx = 0;
|
||
|
|
return 1;
|
||
|
|
}
|
||
|
|
|
||
|
|
-static int screen_bs() {
|
||
|
|
+static int screen_bs(void) {
|
||
|
|
if (screen.cx <= 0) return 0;
|
||
|
|
--screen.cx;
|
||
|
|
return 1;
|
||
|
|
}
|
||
|
|
|
||
|
|
-static int screen_scroll() {
|
||
|
|
+static int screen_scroll(void) {
|
||
|
|
int len = screen.w * (screen.h-1);
|
||
|
|
memmove(screen_char(0,0), screen_char(0,1), len * sizeof(ScreenChar));
|
||
|
|
screen_clear(0, screen.h-1, screen.w);
|
||
|
|
return 1;
|
||
|
|
}
|
||
|
|
|
||
|
|
-static int screen_rscroll() {
|
||
|
|
+static int screen_rscroll(void) {
|
||
|
|
int len = screen.w * (screen.h-1);
|
||
|
|
memmove(screen_char(0,1), screen_char(0,0), len * sizeof(ScreenChar));
|
||
|
|
screen_clear(0, 0, screen.w);
|
||
|
|
@@ -199,7 +199,7 @@ static int screen_clear_attr(int attr) {
|
||
|
|
|
||
|
|
// ------------------------------------------------------------------
|
||
|
|
|
||
|
|
-static void beep() {
|
||
|
|
+static void beep(void) {
|
||
|
|
if (!quiet)
|
||
|
|
fprintf(stderr, "\7");
|
||
|
|
}
|
||
|
|
@@ -350,7 +350,18 @@ static int setup(int argc, char** argv) {
|
||
|
|
return 1;
|
||
|
|
}
|
||
|
|
|
||
|
|
+static void set_signal(int signum, void (*handler)(int)) {
|
||
|
|
+ struct sigaction sa;
|
||
|
|
+ sa.sa_handler = handler;
|
||
|
|
+ sa.sa_flags = 0;
|
||
|
|
+ sigemptyset(&sa.sa_mask);
|
||
|
|
+ sigaction(signum, &sa, NULL);
|
||
|
|
+}
|
||
|
|
+
|
||
|
|
int main(int argc, char** argv) {
|
||
|
|
+ set_signal(SIGINT, SIG_IGN);
|
||
|
|
+ set_signal(SIGQUIT, SIG_IGN);
|
||
|
|
+ set_signal(SIGKILL, SIG_IGN);
|
||
|
|
if (!setup(argc, argv))
|
||
|
|
return RUN_ERR;
|
||
|
|
for (;;) {
|
||
|
|
diff --git a/lesstest/pipeline.c b/lesstest/pipeline.c
|
||
|
|
index 8f225c7..4e60e49 100644
|
||
|
|
--- a/lesstest/pipeline.c
|
||
|
|
+++ b/lesstest/pipeline.c
|
||
|
|
@@ -74,7 +74,7 @@ static void become_child_screen(char* lt_screen, int screen_width, int screen_he
|
||
|
|
exit(1);
|
||
|
|
}
|
||
|
|
|
||
|
|
-static LessPipeline* new_pipeline() {
|
||
|
|
+static LessPipeline* new_pipeline(void) {
|
||
|
|
LessPipeline* pipeline = malloc(sizeof(LessPipeline));
|
||
|
|
pipeline->less_in_pipe[RD] = pipeline->less_in_pipe[WR] = -1;
|
||
|
|
pipeline->screen_in_pipe[RD] = pipeline->screen_in_pipe[WR] = -1;
|
||
|
|
diff --git a/lesstest/run.c b/lesstest/run.c
|
||
|
|
index d2b7ff6..e1d4881 100644
|
||
|
|
--- a/lesstest/run.c
|
||
|
|
+++ b/lesstest/run.c
|
||
|
|
@@ -32,17 +32,12 @@ static void child_handler(int signum) {
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
-static void intr_handler(int signum) {
|
||
|
|
- less_quit = 1;
|
||
|
|
- longjmp(run_catch, 1);
|
||
|
|
-}
|
||
|
|
-
|
||
|
|
static void set_intr_handler(int set) {
|
||
|
|
- set_signal(SIGINT, set ? intr_handler : SIG_DFL);
|
||
|
|
- set_signal(SIGQUIT, set ? intr_handler : SIG_DFL);
|
||
|
|
- set_signal(SIGKILL, set ? intr_handler : SIG_DFL);
|
||
|
|
- set_signal(SIGCHLD, set ? child_handler : SIG_DFL);
|
||
|
|
+ set_signal(SIGINT, set ? SIG_IGN : SIG_DFL);
|
||
|
|
+ set_signal(SIGQUIT, set ? SIG_IGN : SIG_DFL);
|
||
|
|
+ set_signal(SIGKILL, set ? SIG_IGN : SIG_DFL);
|
||
|
|
set_signal(SIGPIPE, set ? SIG_IGN : SIG_DFL);
|
||
|
|
+ set_signal(SIGCHLD, set ? child_handler : SIG_DFL);
|
||
|
|
}
|
||
|
|
|
||
|
|
static void send_char(LessPipeline* pipeline, wchar ch) {
|
||
|
|
@@ -90,8 +85,8 @@ static int curr_screen_match(LessPipeline* pipeline, const byte* img, int imglen
|
||
|
|
}
|
||
|
|
|
||
|
|
int run_interactive(char* const* argv, int argc, char* const* prog_envp) {
|
||
|
|
+ setup_term();
|
||
|
|
char* const* envp = less_envp(prog_envp, 1);
|
||
|
|
- setup_term(envp);
|
||
|
|
LessPipeline* pipeline = create_less_pipeline(argv, argc, envp);
|
||
|
|
if (pipeline == NULL)
|
||
|
|
return 0;
|
||
|
|
diff --git a/lesstest/runtest b/lesstest/runtest
|
||
|
|
index 8fbcefb..93ae80f 100755
|
||
|
|
--- a/lesstest/runtest
|
||
|
|
+++ b/lesstest/runtest
|
||
|
|
@@ -56,6 +56,7 @@ sub run {
|
||
|
|
print "ERR cannot open $file\n";
|
||
|
|
return 1;
|
||
|
|
}
|
||
|
|
+ print "TEST $file\n";
|
||
|
|
my $cmd = "$lesstest -s '$lt_screen' -t '$file' '$less'";
|
||
|
|
my $err = system $cmd;
|
||
|
|
if ($err) {
|
||
|
|
diff --git a/lesstest/term.c b/lesstest/term.c
|
||
|
|
index 440f771..db294a6 100644
|
||
|
|
--- a/lesstest/term.c
|
||
|
|
+++ b/lesstest/term.c
|
||
|
|
@@ -28,21 +28,6 @@ int env_number(const char* s) {
|
||
|
|
return (s == NULL) ? 0 : atoi(s);
|
||
|
|
}
|
||
|
|
|
||
|
|
-#if 0
|
||
|
|
-int get_screen_size(int* screen_width, int* screen_height) {
|
||
|
|
- *screen_width = env_number("COLUMNS");
|
||
|
|
- *screen_height = env_number("ROWS");
|
||
|
|
- if (*screen_width == 0 || *screen_height == 0) {
|
||
|
|
- struct winsize w;
|
||
|
|
- if (ioctl(2, TIOCGWINSZ, &w) == 0) {
|
||
|
|
- *screen_height = w.ws_row;
|
||
|
|
- *screen_width = w.ws_col;
|
||
|
|
- }
|
||
|
|
- }
|
||
|
|
- return (*screen_width > 0 && *screen_height > 0);
|
||
|
|
-}
|
||
|
|
-#endif
|
||
|
|
-
|
||
|
|
static void setup_mode(char* enter_cap, char* exit_cap, char** enter_str, char** exit_str, char** spp) {
|
||
|
|
*enter_str = tgetstr(enter_cap, spp);
|
||
|
|
if (*enter_str == NULL) *enter_str = "";
|
||
|
|
@@ -51,7 +36,7 @@ static void setup_mode(char* enter_cap, char* exit_cap, char** enter_str, char**
|
||
|
|
if (*exit_str == NULL) *exit_str = "";
|
||
|
|
}
|
||
|
|
|
||
|
|
-int setup_term(char* const* envp) {
|
||
|
|
+int setup_term(void) {
|
||
|
|
static char termbuf[4096];
|
||
|
|
static char sbuf[4096];
|
||
|
|
char* term = getenv("TERM");
|
||
|
|
--
|
||
|
|
2.27.0
|
||
|
|
|