From: Sami Kerola Date: Wed, 18 Mar 2020 20:12:59 +0000 (+0000) Subject: more: tell in run time help what the 'v' will execute as editor X-Git-Tag: v2.36-rc1~158^2~7 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f8492042f52198265a5a2423ac63e4e99a05fc0f;p=thirdparty%2Futil-linux.git more: tell in run time help what the 'v' will execute as editor In same go use well known paths from system include file. Signed-off-by: Sami Kerola --- diff --git a/text-utils/more.c b/text-utils/more.c index f6a59e4868..4801317c31 100644 --- a/text-utils/more.c +++ b/text-utils/more.c @@ -62,6 +62,7 @@ #include #include #include +#include #if defined(HAVE_NCURSESW_TERM_H) # include @@ -82,8 +83,6 @@ # define NON_INTERACTIVE_MORE 1 #endif -#define VI "vi" /* found on the user's path */ - #define BS "\b" #define BSB "\b \b" #define CARAT "^" @@ -1390,6 +1389,18 @@ notfound: } } +static char *find_editor(void) +{ + static char *editor; + + editor = getenv("VISUAL"); + if (editor == NULL || *editor == '\0') + editor = getenv("EDITOR"); + if (editor == NULL || *editor == '\0') + editor = _PATH_VI; + return editor; +} + /* Read a command and do it. A command consists of an optional integer * argument followed by the command character. Return the number of * lines to display in the next screenful. If there is nothing more to @@ -1604,8 +1615,8 @@ static int more_key_command(struct more_control *ctl, char *filename, FILE *f) "Star (*) indicates argument becomes new default.\n"), stdout); puts("---------------------------------------" "----------------------------------------"); - fputs(_ - (" Display next k lines of text [current screen size]\n" + fprintf(stdout, + _(" Display next k lines of text [current screen size]\n" "z Display next k lines of text [current screen size]*\n" " Display next k lines of text [1]*\n" "d or ctrl-D Scroll k lines [current scroll size, initially 11]*\n" @@ -1618,12 +1629,12 @@ static int more_key_command(struct more_control *ctl, char *filename, FILE *f) "/ Search for kth occurrence of regular expression [1]\n" "n Search for kth occurrence of last r.e [1]\n" "! or :! Execute in a subshell\n" - "v Start up /usr/bin/vi at current line\n" + "v Start up '%s' at current line\n" "ctrl-L Redraw screen\n" ":n Go to kth next file [1]\n" ":p Go to kth previous file [1]\n" ":f Display current file name and line number\n" - ". Repeat previous command\n"), stdout); + ". Repeat previous command\n"), find_editor()); puts("---------------------------------------" "----------------------------------------"); output_prompt(ctl, filename); @@ -1638,12 +1649,7 @@ static int more_key_command(struct more_control *ctl, char *filename, FILE *f) ctl->current_line - (ctl->lines_per_screen + 1) / 2); int split = 0; - editor = getenv("VISUAL"); - if (editor == NULL || *editor == '\0') - editor = getenv("EDITOR"); - if (editor == NULL || *editor == '\0') - editor = VI; - + editor = find_editor(); p = strrchr(editor, '/'); if (p) p++; @@ -1869,7 +1875,7 @@ static void initterm(struct more_control *ctl) } if ((ctl->shell = getenv("SHELL")) == NULL) - ctl->shell = "/bin/sh"; + ctl->shell = _PATH_BSHELL; } ctl->no_tty_in = tcgetattr(STDIN_FILENO, &ctl->output_tty); tcgetattr(STDERR_FILENO, &ctl->output_tty);