Skip to content

Commit

Permalink
Add compatibility with POSIX more.
Browse files Browse the repository at this point in the history
  • Loading branch information
gwsw committed Jan 13, 2007
1 parent 8e2cc74 commit 08a5ba8
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 14 deletions.
2 changes: 2 additions & 0 deletions NEWS.VER
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

Major changes between "less" versions 394 and @@VERSION@@

* Add compatibility with POSIX more.

* Allow "/dev/null" as synomym for "-" in LESSHISTFILE.

* Make -f work for directories.
Expand Down
7 changes: 3 additions & 4 deletions command.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

extern int erase_char, erase2_char, kill_char;
extern int sigs;
extern int quit_at_eof;
extern int quit_if_one_screen;
extern int squished;
extern int hit_eof;
Expand Down Expand Up @@ -606,7 +605,7 @@ prompt()
* {{ Relying on "first prompt" to detect a single-screen file
* fails if +G is used, for example. }}
*/
if ((quit_at_eof == OPT_ONPLUS || quit_if_one_screen) &&
if ((get_quit_at_eof() == OPT_ONPLUS || quit_if_one_screen) &&
hit_eof && !(ch_getflags() & CH_HELPFILE) &&
next_ifile(curr_ifile) == NULL_IFILE)
quit(QUIT_OK);
Expand All @@ -616,7 +615,7 @@ prompt()
* If the -e flag is set and we've hit EOF on the last file,
* and the file is squished (shorter than the screen), quit.
*/
if (quit_at_eof && squished &&
if (get_quit_at_eof() && squished &&
next_ifile(curr_ifile) == NULL_IFILE)
quit(QUIT_OK);
#endif
Expand Down Expand Up @@ -1386,7 +1385,7 @@ commands()
number = 1;
if (edit_next((int) number))
{
if (quit_at_eof && hit_eof &&
if (get_quit_at_eof() && hit_eof &&
!(ch_getflags() & CH_HELPFILE))
quit(QUIT_OK);
parg.p_string = (number > 1) ? "(N-th) " : "";
Expand Down
3 changes: 1 addition & 2 deletions forwback.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ extern int sigs;
extern int top_scroll;
extern int quiet;
extern int sc_width, sc_height;
extern int quit_at_eof;
extern int plusoption;
extern int forw_scroll;
extern int back_scroll;
Expand Down Expand Up @@ -324,7 +323,7 @@ forward(n, force, only_last)
{
POSITION pos;

if (quit_at_eof && hit_eof && !(ch_getflags() & CH_HELPFILE))
if (get_quit_at_eof() && hit_eof && !(ch_getflags() & CH_HELPFILE))
{
/*
* If the -e flag is set and we're trying to go
Expand Down
36 changes: 35 additions & 1 deletion less.nro.VER
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,7 @@ By default, any forward movement causes scrolling.
Changes the default scrolling window size to \fIn\fP lines.
The default is one screenful.
The z and w commands can also be used to change the window size.
The "z" may be omitted for compatibility with
The "z" may be omitted for compatibility with some versions of
.I more.
If the number
.I n
Expand Down Expand Up @@ -1446,6 +1446,36 @@ filename completion (TAB, ^L)
.PP
Less can also be compiled to be permanently in "secure" mode.

.SH "COMPATIBILITY WITH MORE"
If the environment variable LESS_IS_MORE is set to 1,
or if the program is invoked via a file link named "more",
.I less
behaves (mostly) in conformance with the POSIX "more" command specification.
In this mode, less behaves differently in these ways:
.PP
The \-e option works differently.
If the \-e option is not set,
.I less
behaves as if the \-E option were set.
If the \-e option is set,
.I less
behaves as if the \-e and \-F options were set.
.PP
The \-m option works differently.
If the \-m option is not set, the medium prompt is used,
and it is prefixed with the string "--More--".
If the \-m option is set, the short prompt is used.
.PP
The \-n option acts like the \-z option.
The normal behavior of the \-n option is unavailable in this mode.
.PP
The parameter to the \-p option is taken to be a
.I less
command rather than a search pattern.
.PP
The LESS environment variable is ignored,
and the MORE environment variable is used in its place.

.SH "ENVIRONMENT VARIABLES"
Environment variables may be specified either in the system environment
as usual, or in a
Expand Down Expand Up @@ -1538,6 +1568,10 @@ See discussion under SECURITY.
String to be appended to a directory name in filename completion.
.IP LESSUTFBINFMT
Format for displaying non-printable Unicode code points.
.IP LESS_IS_MORE
Emulate the
.I more
(1) command.
.IP LINES
Sets the number of lines on the screen.
Takes precedence over the number of lines specified by the TERM variable.
Expand Down
26 changes: 24 additions & 2 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public char * progname;
public int quitting;
public int secure;
public int dohelp;
public int less_is_more;

#if LOGFILE
public int logfile = -1;
Expand All @@ -56,6 +57,8 @@ static char consoleTitle[256];

extern int missing_cap;
extern int know_dumb;
extern int quit_if_one_screen;
extern int pr_type;


/*
Expand Down Expand Up @@ -111,12 +114,28 @@ main(argc, argv)
is_tty = isatty(1);
get_term();
init_cmds();
init_prompt();
init_charset();
init_line();
init_cmdhist();
init_option();
s = lgetenv("LESS");

/*
* If the name of the executable program is "more",
* act like LESS_IS_MORE is set.
*/
for (s = argv[0] + strlen(argv[0]); s > argv[0]; s--)
{
if (s[-1] == '/')
break;
if (s[-1] == '\\')
break;
}
if (strcmp(s, "more") == 0)
less_is_more = 1;

init_prompt();

s = lgetenv(less_is_more ? "MORE" : "LESS");
if (s != NULL)
scan_option(save(s));

Expand All @@ -141,6 +160,9 @@ main(argc, argv)
quit(QUIT_OK);
}

if (less_is_more && get_quit_at_eof())
quit_if_one_screen = TRUE;

#if EDITOR
editor = lgetenv("VISUAL");
if (editor == NULL || *editor == '\0')
Expand Down
4 changes: 2 additions & 2 deletions optfunc.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ extern int sc_height;
extern int secure;
extern int dohelp;
extern int any_display;
extern int less_is_more;
extern char openquote;
extern char closequote;
extern char *prproto[];
Expand All @@ -55,6 +54,7 @@ extern int logfile;
public char *tagoption = NULL;
extern char *tags;
extern int jump_sline;
extern int less_is_more;
#endif
#if MSDOS_COMPILER
extern int nm_fg_color, nm_bg_color;
Expand Down Expand Up @@ -267,7 +267,7 @@ opt_p(type, s)
* In "more" mode, the -p argument is a command,
* not a search string, so we don't need a slash.
*/
if (!less_is_more);
if (!less_is_more)
ungetsc("/");
break;
}
Expand Down
18 changes: 18 additions & 0 deletions option.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ static char *optstring();
static int flip_triple();

extern int screen_trashed;
extern int less_is_more;
extern int quit_at_eof;
extern char *every_first_cmd;

/*
Expand Down Expand Up @@ -132,6 +134,10 @@ scan_option(s)
s--;
optc = 'z';
break;
case 'n':
if (less_is_more)
optc = 'z';
break;
}

/*
Expand Down Expand Up @@ -631,3 +637,15 @@ getnum(sp, printopt, errp)
n = -n;
return (n);
}

/*
* Get the value of the -e flag.
*/
public int
get_quit_at_eof()
{
if (!less_is_more)
return quit_at_eof;
/* When less_is_more is set, the -e flag semantics are different. */
return quit_at_eof ? OPT_ON : OPT_ONPLUS;
}
9 changes: 7 additions & 2 deletions prompt.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ extern int linenums;
extern int hshift;
extern int sc_height;
extern int jump_sline;
extern int less_is_more;
extern IFILE curr_ifile;
#if EDITOR
extern char *editor;
Expand All @@ -52,6 +53,8 @@ static constant char h_proto[] =
"HELP -- ?eEND -- Press g to see it again:Press RETURN for more., or q when done";
static constant char w_proto[] =
"Waiting for data";
static constant char more_proto[] =
"--More--(?eEND ?x- Next\\: %x.:?pB%pB\\%:byte %bB?s/%s...%t)";

public char *prproto[3];
public char constant *eqproto = e_proto;
Expand All @@ -68,7 +71,7 @@ static char *mp;
init_prompt()
{
prproto[0] = save(s_proto);
prproto[1] = save(m_proto);
prproto[1] = save(less_is_more ? more_proto : m_proto);
prproto[2] = save(M_proto);
eqproto = save(e_proto);
hproto = save(h_proto);
Expand Down Expand Up @@ -561,9 +564,11 @@ eq_message()
pr_string()
{
char *prompt;
int type;

type = (!less_is_more) ? pr_type : pr_type ? 0 : 1;
prompt = pr_expand((ch_getflags() & CH_HELPFILE) ?
hproto : prproto[pr_type],
hproto : prproto[type],
sc_width-so_s_width-so_e_width-2);
new_file = 0;
return (prompt);
Expand Down
3 changes: 2 additions & 1 deletion version.c
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,7 @@ v395 1/12/07 Update Unicode tables (thanks to Charles Levert);
make -f work for directories; support DESTDIR in Makefile;
fix setset_t detection in configure;
make "t" cmd traverse tags in correct order
v396 1/13/07 Add compatibility with POSIX more.
*/

char version[] = "395";
char version[] = "396";

0 comments on commit 08a5ba8

Please sign in to comment.