159 lines
5.8 KiB
Diff
159 lines
5.8 KiB
Diff
|
|
From b224ee8e6150b87fb42be4896fd9cf1f91c9c4f5 Mon Sep 17 00:00:00 2001
|
||
|
|
From: Mark Nudelman <markn@greenwoodsoftware.com>
|
||
|
|
Date: Thu, 6 Oct 2022 19:59:21 -0700
|
||
|
|
Subject: [PATCH] Pass less-specific env variables to lesstest; get rid of LT_*
|
||
|
|
env variables.
|
||
|
|
|
||
|
|
---
|
||
|
|
lesstest/env.c | 34 +++++++++++++++++++++-------------
|
||
|
|
lesstest/lesstest.c | 1 +
|
||
|
|
lesstest/lesstest.h | 2 +-
|
||
|
|
lesstest/lt_types.h | 1 -
|
||
|
|
lesstest/run.c | 4 ++--
|
||
|
|
lesstest/term.c | 3 +--
|
||
|
|
6 files changed, 26 insertions(+), 19 deletions(-)
|
||
|
|
|
||
|
|
diff --git a/lesstest/env.c b/lesstest/env.c
|
||
|
|
index 69cda65..8670a52 100644
|
||
|
|
--- a/lesstest/env.c
|
||
|
|
+++ b/lesstest/env.c
|
||
|
|
@@ -48,7 +48,21 @@ void env_addintpair(EnvBuf* env, const char* name, int value) {
|
||
|
|
env_addpair(env, name, buf);
|
||
|
|
}
|
||
|
|
|
||
|
|
-static void env_setup(EnvBuf* env, char* const* prog_env, const char* env_prefix) {
|
||
|
|
+static int is_less_env(const char* name, int name_len) {
|
||
|
|
+ static char* const less_names[] = {
|
||
|
|
+ "LESS*", "COLUMNS", "LINES", "LANG", "LC_CTYPE", "MORE", NULL
|
||
|
|
+ };
|
||
|
|
+ for (char* const* n = less_names; *n != NULL; ++n) {
|
||
|
|
+ int ln = strlen(*n);
|
||
|
|
+ if (ln == name_len && strncmp(*n, name, ln) == 0)
|
||
|
|
+ return 1;
|
||
|
|
+ if ((*n)[ln-1] == '*' && strncmp(*n, name, ln-1) == 0)
|
||
|
|
+ return 1;
|
||
|
|
+ }
|
||
|
|
+ return 0;
|
||
|
|
+}
|
||
|
|
+
|
||
|
|
+static void env_setup(EnvBuf* env, char* const* prog_env, int interactive) {
|
||
|
|
env_addpair(env, "LESS_TERMCAP_am", "1");
|
||
|
|
env_addpair(env, "LESS_TERMCAP_cd", "\33S");
|
||
|
|
env_addpair(env, "LESS_TERMCAP_ce", "\33L");
|
||
|
|
@@ -73,22 +87,16 @@ static void env_setup(EnvBuf* env, char* const* prog_env, const char* env_prefix
|
||
|
|
env_addpair(env, "LESS_TERMCAP_kh", terminfo.key_home ? terminfo.key_home : "");
|
||
|
|
env_addpair(env, "LESS_TERMCAP_@7", terminfo.key_end ? terminfo.key_end : "");
|
||
|
|
|
||
|
|
- char* const* envp;
|
||
|
|
- int len = strlen(env_prefix);
|
||
|
|
- for (envp = prog_env; *envp != NULL; ++envp) {
|
||
|
|
- if (strncmp(*envp, env_prefix, len) == 0) {
|
||
|
|
- const char* ename = *envp + len;
|
||
|
|
+ if (interactive) {
|
||
|
|
+ for (char* const* envp = prog_env; *envp != NULL; ++envp) {
|
||
|
|
+ const char* ename = *envp;
|
||
|
|
const char* eq = strchr(ename, '=');
|
||
|
|
- if (eq != NULL) {
|
||
|
|
+ if (eq != NULL && is_less_env(ename, eq-ename)) {
|
||
|
|
env_addlpair(env, ename, eq-ename, eq+1);
|
||
|
|
log_env(ename, eq-ename, eq+1);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
- if (get_envp(env->env_list, "LINES") == NULL)
|
||
|
|
- env_addpair(env, "LINES", get_envp(prog_env, "LINES"));
|
||
|
|
- if (get_envp(env->env_list, "COLUMNS") == NULL)
|
||
|
|
- env_addpair(env, "COLUMNS", get_envp(prog_env, "COLUMNS"));
|
||
|
|
}
|
||
|
|
|
||
|
|
const char* get_envp(char* const* envp, const char* name) {
|
||
|
|
@@ -101,12 +109,12 @@ const char* get_envp(char* const* envp, const char* name) {
|
||
|
|
return NULL;
|
||
|
|
}
|
||
|
|
|
||
|
|
-char* const* less_envp(char* const* envp, const char* env_prefix) {
|
||
|
|
+char* const* less_envp(char* const* envp, int interactive) {
|
||
|
|
static EnvBuf less_env;
|
||
|
|
static int init = 0;
|
||
|
|
if (!init) {
|
||
|
|
env_init(&less_env);
|
||
|
|
- env_setup(&less_env, envp, env_prefix);
|
||
|
|
+ env_setup(&less_env, envp, interactive);
|
||
|
|
init = 1;
|
||
|
|
}
|
||
|
|
return less_env.env_list;
|
||
|
|
diff --git a/lesstest/lesstest.c b/lesstest/lesstest.c
|
||
|
|
index bc434bd..909472e 100644
|
||
|
|
--- a/lesstest/lesstest.c
|
||
|
|
+++ b/lesstest/lesstest.c
|
||
|
|
@@ -65,6 +65,7 @@ int main(int argc, char* const* argv, char* const* envp) {
|
||
|
|
log_file_header();
|
||
|
|
printf("%s%s", terminfo.init_term, terminfo.enter_keypad);
|
||
|
|
ok = run_interactive(argv+optind, argc-optind, envp);
|
||
|
|
+ if (verbose) fprintf(stderr, "run_interactive return %d\n", ok);
|
||
|
|
printf("%s%s", terminfo.exit_keypad, terminfo.deinit_term);
|
||
|
|
log_close();
|
||
|
|
}
|
||
|
|
diff --git a/lesstest/lesstest.h b/lesstest/lesstest.h
|
||
|
|
index 062b241..f3a9921 100644
|
||
|
|
--- a/lesstest/lesstest.h
|
||
|
|
+++ b/lesstest/lesstest.h
|
||
|
|
@@ -80,5 +80,5 @@ int run_interactive(char* const* argv, int argc, char* const* envp);
|
||
|
|
int run_testfile(const char* testfile, const char* less);
|
||
|
|
void env_init(EnvBuf* env);
|
||
|
|
void env_addpair(EnvBuf* env, const char* name, const char* value);
|
||
|
|
-char* const* less_envp(char* const* envp, const char* env_prefix);
|
||
|
|
+char* const* less_envp(char* const* envp, int interactive);
|
||
|
|
void child_handler(int signum);
|
||
|
|
diff --git a/lesstest/lt_types.h b/lesstest/lt_types.h
|
||
|
|
index b83682c..2b3c1bc 100644
|
||
|
|
--- a/lesstest/lt_types.h
|
||
|
|
+++ b/lesstest/lt_types.h
|
||
|
|
@@ -14,7 +14,6 @@ typedef unsigned char Color;
|
||
|
|
#define LESS_DUMP_CHAR '\35'
|
||
|
|
#define UNICODE_MAX_BYTES 4
|
||
|
|
#define MAX_SCREENBUF_SIZE 8192
|
||
|
|
-#define LT_ENV_PREFIX "LT_"
|
||
|
|
|
||
|
|
#define RUN_OK 0
|
||
|
|
#define RUN_ERR 1
|
||
|
|
diff --git a/lesstest/run.c b/lesstest/run.c
|
||
|
|
index 6e2dbd1..caba5a8 100644
|
||
|
|
--- a/lesstest/run.c
|
||
|
|
+++ b/lesstest/run.c
|
||
|
|
@@ -81,7 +81,7 @@ static int curr_screen_match(LessPipeline* pipeline, const byte* img, int imglen
|
||
|
|
|
||
|
|
int run_interactive(char* const* argv, int argc, char* const* prog_envp) {
|
||
|
|
signal(SIGCHLD, child_handler);
|
||
|
|
- char* const* envp = less_envp(prog_envp, LT_ENV_PREFIX);
|
||
|
|
+ char* const* envp = less_envp(prog_envp, 1);
|
||
|
|
setup_term(envp);
|
||
|
|
LessPipeline* pipeline = create_less_pipeline(argv, argc, envp);
|
||
|
|
if (pipeline == NULL)
|
||
|
|
@@ -116,7 +116,7 @@ int run_test(TestSetup* setup, FILE* testfd) {
|
||
|
|
const char* setup_name = setup->argv[setup->argc-1];
|
||
|
|
fprintf(stderr, "RUN %s\n", setup_name);
|
||
|
|
LessPipeline* pipeline = create_less_pipeline(setup->argv, setup->argc,
|
||
|
|
- less_envp(setup->env.env_list, ""));
|
||
|
|
+ less_envp(setup->env.env_list, 0));
|
||
|
|
if (pipeline == NULL)
|
||
|
|
return 0;
|
||
|
|
less_quit = 0;
|
||
|
|
diff --git a/lesstest/term.c b/lesstest/term.c
|
||
|
|
index cfd4b4a..440f771 100644
|
||
|
|
--- a/lesstest/term.c
|
||
|
|
+++ b/lesstest/term.c
|
||
|
|
@@ -54,8 +54,7 @@ static void setup_mode(char* enter_cap, char* exit_cap, char** enter_str, char**
|
||
|
|
int setup_term(char* const* envp) {
|
||
|
|
static char termbuf[4096];
|
||
|
|
static char sbuf[4096];
|
||
|
|
- ///char* term = getenv("TERM");
|
||
|
|
- char const* term = get_envp(envp, "TERM");
|
||
|
|
+ char* term = getenv("TERM");
|
||
|
|
if (term == NULL) term = "dumb";
|
||
|
|
if (tgetent(termbuf, term) <= 0) {
|
||
|
|
fprintf(stderr, "cannot setup terminal %s\n", term);
|
||
|
|
--
|
||
|
|
2.27.0
|
||
|
|
|