Skip to content

Commit

Permalink
Add isnullenv.
Browse files Browse the repository at this point in the history
  • Loading branch information
gwsw committed Nov 12, 2018
1 parent 74c8c82 commit 1ef7141
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 23 deletions.
2 changes: 1 addition & 1 deletion charset.c
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ set_charset()
* LESSCHARSET is not defined: try LESSCHARDEF.
*/
s = lgetenv("LESSCHARDEF");
if (s != NULL && *s != '\0')
if (!isnullenv(s))
{
ichardef(s);
return;
Expand Down
6 changes: 3 additions & 3 deletions cmdbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -1398,7 +1398,7 @@ histfile_name()

/* See if filename is explicitly specified by $LESSHISTFILE. */
name = lgetenv("LESSHISTFILE");
if (name != NULL && *name != '\0')
if (!isnullenv(name))
{
if (strcmp(name, "-") == 0 || strcmp(name, "/dev/null") == 0)
/* $LESSHISTFILE == "-" means don't use a history file. */
Expand All @@ -1412,11 +1412,11 @@ histfile_name()

/* Otherwise, file is in $HOME. */
home = lgetenv("HOME");
if (home == NULL || *home == '\0')
if (isnullenv(home))
{
#if OS2
home = lgetenv("INIT");
if (home == NULL || *home == '\0')
if (isnullenv(home))
#endif
return (NULL);
}
Expand Down
10 changes: 10 additions & 0 deletions decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,16 @@ lgetenv(var)
return (NULL);
}

/*
* Is a string null or empty?
*/
public int
isnullenv(s)
char* s;
{
return (s == NULL || *s == '\0');
}

#if USERFILE
/*
* Get an "integer" from a lesskey file.
Expand Down
4 changes: 2 additions & 2 deletions filename.c
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ shellcmd(cmd)
char *shell;

shell = lgetenv("SHELL");
if (shell != NULL && *shell != '\0')
if (!isnullenv(shell))
{
char *scmd;
char *esccmd;
Expand Down Expand Up @@ -745,7 +745,7 @@ lglob(filename)
return (filename);
}
lessecho = lgetenv("LESSECHO");
if (lessecho == NULL || *lessecho == '\0')
if (isnullenv(lessecho))
lessecho = "lessecho";
/*
* Invoke lessecho, and read its output (a globbed list of filenames).
Expand Down
12 changes: 7 additions & 5 deletions less.nro.VER
Original file line number Diff line number Diff line change
Expand Up @@ -942,14 +942,16 @@ will display the contents of that new file.
Enables mouse input:
scrolling the mouse wheel down moves forward in the file,
scrolling the mouse wheel up moves backwards in the file,
and clicking the mouse will set the "#" mark to the line
on which the mouse cursor sits.
and clicking the mouse sets the "#" mark to the line
where the mouse is clicked.
The number of lines to scroll when the wheel is moved
can be set by the \-\-wheel-lines option.
Mouse input works only on terminals which support X11 mouse reporting
and on the Windows version.
Mouse input works only on terminals which support X11 mouse reporting,
and on the Windows version of
.IR less .
.IP "\-\-MOUSE"
Like \-\-mouse, except the scrolling direction is reversed.
Like \-\-mouse, except the direction scrolled
on mouse wheel movement is reversed.
.IP "\-\-no-keypad"
Disables sending the keypad initialization and deinitialization strings
to the terminal.
Expand Down
4 changes: 2 additions & 2 deletions line.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ static POSITION mbc_pos;
init_line()
{
end_ansi_chars = lgetenv("LESSANSIENDCHARS");
if (end_ansi_chars == NULL || *end_ansi_chars == '\0')
if (isnullenv(end_ansi_chars))
end_ansi_chars = "m";

mid_ansi_chars = lgetenv("LESSANSIMIDCHARS");
if (mid_ansi_chars == NULL || *mid_ansi_chars == '\0')
if (isnullenv(mid_ansi_chars))
mid_ansi_chars = "0123456789:;[?!\"'#%()*+ ";

linebuf = (char *) ecalloc(LINEBUF_SIZE, sizeof(char));
Expand Down
6 changes: 3 additions & 3 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ main(argc, argv)

secure = 0;
s = lgetenv("LESSSECURE");
if (s != NULL && *s != '\0')
if (!isnullenv(s))
secure = 1;

#ifdef WIN32
Expand Down Expand Up @@ -159,11 +159,11 @@ main(argc, argv)
if (editor == NULL || *editor == '\0')
{
editor = lgetenv("EDITOR");
if (editor == NULL || *editor == '\0')
if (isnullenv(editor))
editor = EDIT_PGM;
}
editproto = lgetenv("LESSEDIT");
if (editproto == NULL || *editproto == '\0')
if (isnullenv(editproto))
editproto = "%E ?lm+%lm. %g";
#endif

Expand Down
2 changes: 1 addition & 1 deletion opttbl.c
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ init_option()
char *p;

p = lgetenv("LESS_IS_MORE");
if (p != NULL && *p != '\0')
if (!isnullenv(p))
less_is_more = 1;

for (o = option; o->oletter != '\0'; o++)
Expand Down
10 changes: 5 additions & 5 deletions screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ struct keyRecord
static int keyCount = 0;
static WORD curr_attr;
static int pending_scancode = 0;
static char x11mousebuf[] = "[M???"; /* \e is separate */
static char x11mousebuf[] = "[M???"; /* Mouse report, after ESC */
static int x11mousePos, x11mouseCount;

static HANDLE con_out_save = INVALID_HANDLE_VALUE; /* previous console */
Expand Down Expand Up @@ -637,7 +637,7 @@ ltget_env(capname)
char *s;

s = lgetenv("LESS_TERMCAP_DEBUG");
if (s != NULL && *s != '\0')
if (!isnullenv(s))
{
struct env { struct env *next; char *name; char *value; };
static struct env *envs = NULL;
Expand Down Expand Up @@ -1141,7 +1141,7 @@ get_term()
* Make sure the termcap database is available.
*/
sp = lgetenv("TERMCAP");
if (sp == NULL || *sp == '\0')
if (isnullenv(sp))
{
char *termcap;
if ((sp = homefile("termcap.dat")) != NULL)
Expand Down Expand Up @@ -1222,10 +1222,10 @@ get_term()
kent = ltgetstr("@8", &sp);

sc_s_mousecap = lgetenv("LESS_TERMCAP_MOUSE_START");
if (sc_s_mousecap == NULL || *sc_s_mousecap == '\0')
if (isnullenv(sc_s_mousecap))
sc_s_mousecap = "\33[?1000h";
sc_e_mousecap = lgetenv("LESS_TERMCAP_MOUSE_END");
if (sc_e_mousecap == NULL || *sc_e_mousecap == '\0')
if (isnullenv(sc_e_mousecap))
sc_e_mousecap = "\33[?1000l";

sc_init = ltgetstr("ti", &sp);
Expand Down
2 changes: 1 addition & 1 deletion tags.c
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ findgtag(tag, type)
char *qtag;
char *cmd = lgetenv("LESSGLOBALTAGS");

if (cmd == NULL || *cmd == '\0')
if (isnullenv(cmd))
return TAG_NOFILE;
/* Get suitable flag value for global(1). */
switch (type)
Expand Down

0 comments on commit 1ef7141

Please sign in to comment.