Skip to content

Commit

Permalink
Add --no-search-header-lines and --no-search-header-columns.
Browse files Browse the repository at this point in the history
Fix --header option when used on the command line.
  • Loading branch information
gwsw committed Dec 2, 2023
1 parent 8bd9c6c commit 6e9f84a
Show file tree
Hide file tree
Showing 9 changed files with 128 additions and 46 deletions.
4 changes: 3 additions & 1 deletion NEWS
Expand Up @@ -11,14 +11,16 @@

======================================================================

Major changes between "less" versions 643 and 649
Major changes between "less" versions 643 and 650

* Add --match-shift option.

* Add --lesskey-content option (github #447).

* Add LESSKEY_CONTENT environment variable.

* Add --no-search-header-lines and --no-search-header-columns options.

* Allow expansion of environment variables in lesskey files.

* Add LESSSECURE_ALLOW environment variable (github #449).
Expand Down
2 changes: 1 addition & 1 deletion edit.c
Expand Up @@ -664,7 +664,7 @@ public int edit_ifile(IFILE ifile)
}
if (want_filesize)
scan_eof();
set_header(0, 0, NULL_POSITION);
set_header(ch_zero());
}
return (0);
}
Expand Down
6 changes: 5 additions & 1 deletion less.hlp
Expand Up @@ -235,8 +235,12 @@
Remove duplicates from command history.
--no-number-headers
Don't give line numbers to header lines.
--no-search-header-lines
Searches do not include header lines.
--no-search-header-columns
Searches do not include header columns.
--no-search-headers
Don't search in header lines or columns.
Searches do not include header lines or columns.
--no-vbell
Disable the terminal's visual bell.
--redraw-on-quit
Expand Down
4 changes: 4 additions & 0 deletions less.nro.VER
Expand Up @@ -1323,6 +1323,10 @@ Normally, a string may appear multiple times.
.IP "\-\-no-number-headers"
Header lines (defined via the \-\-header option) are not assigned line numbers.
Line number 1 is assigned to the first line after any header lines.
.IP "\-\-no-search-header-lines"
Searches do not include header lines, but still include header columns.
.IP "\-\-no-search-header-columns"
Searches do not include header columns, but still include header lines.
.IP "\-\-no-search-headers"
Searches do not include header lines or header columns.
.IP "\-\-no-vbell"
Expand Down
50 changes: 49 additions & 1 deletion optfunc.c
Expand Up @@ -67,6 +67,8 @@ extern int tabstops[];
extern int ntabstops;
extern int tabdefault;
extern char intr_char;
extern int nosearch_header_lines;
extern int nosearch_header_cols;
extern POSITION header_start_pos;
#if LOGFILE
extern char *namelogfile;
Expand Down Expand Up @@ -1069,7 +1071,9 @@ public void opt_header(int type, constant char *s)
if (start_pos == NULL_POSITION) start_pos = ch_zero();
if (!parse_header(s, &lines, &cols, &start_pos))
break;
set_header(lines, cols, start_pos);
header_lines = lines;
header_cols = cols;
set_header(start_pos);
calc_jump_sline();
break; }
case QUERY: {
Expand Down Expand Up @@ -1144,6 +1148,50 @@ public void opt_search_type(int type, constant char *s)
}
}

/*
* Handler for the --no-search-headers, --no-search-header-lines
* and --no-search-header-cols options.
*/
static void do_nosearch_headers(int type, int no_header_lines, int no_header_cols)
{
switch (type)
{
case INIT:
break;
case TOGGLE:
nosearch_header_lines = no_header_lines;
nosearch_header_cols = no_header_cols;
break;
case QUERY:
if (nosearch_header_lines && nosearch_header_cols)
error("Search does not include header lines or columns", NULL_PARG);
else if (nosearch_header_lines)
error("Search includes header columns but not header lines", NULL_PARG);
else if (nosearch_header_cols)
error("Search includes header lines but not header columns", NULL_PARG);
else
error("Search includes header lines and columns", NULL_PARG);
}
}

/*ARGSUSED*/
public void opt_nosearch_headers(int type, constant char *s)
{
do_nosearch_headers(type, 1, 1);
}

/*ARGSUSED*/
public void opt_nosearch_header_lines(int type, constant char *s)
{
do_nosearch_headers(type, 1, 0);
}

/*ARGSUSED*/
public void opt_nosearch_header_cols(int type, constant char *s)
{
do_nosearch_headers(type, 0, 1);
}

#if LESSTEST
/*
* Handler for the --tty option.
Expand Down
71 changes: 42 additions & 29 deletions option.c
Expand Up @@ -239,18 +239,24 @@ public void scan_option(constant char *s)
case BOOL:
if (o->otype & UNSUPPORTED)
break;
if (set_default)
*(o->ovar) = o->odefault;
else
*(o->ovar) = ! o->odefault;
if (o->ovar != NULL)
{
if (set_default)
*(o->ovar) = o->odefault;
else
*(o->ovar) = ! o->odefault;
}
break;
case TRIPLE:
if (o->otype & UNSUPPORTED)
break;
if (set_default)
*(o->ovar) = o->odefault;
else
*(o->ovar) = flip_triple(o->odefault, lc);
if (o->ovar != NULL)
{
if (set_default)
*(o->ovar) = o->odefault;
else
*(o->ovar) = flip_triple(o->odefault, lc);
}
break;
case STRING:
if (*s == '\0')
Expand Down Expand Up @@ -365,17 +371,20 @@ public void toggle_option(struct loption *o, int lower, constant char *s, int ho
/*
* Boolean.
*/
switch (how_toggle)
if (o->ovar != NULL)
{
case OPT_TOGGLE:
*(o->ovar) = ! *(o->ovar);
break;
case OPT_UNSET:
*(o->ovar) = o->odefault;
break;
case OPT_SET:
*(o->ovar) = ! o->odefault;
break;
switch (how_toggle)
{
case OPT_TOGGLE:
*(o->ovar) = ! *(o->ovar);
break;
case OPT_UNSET:
*(o->ovar) = o->odefault;
break;
case OPT_SET:
*(o->ovar) = ! o->odefault;
break;
}
}
break;
case TRIPLE:
Expand All @@ -386,17 +395,20 @@ public void toggle_option(struct loption *o, int lower, constant char *s, int ho
* If user gave the upper case letter, then switch
* to 2 unless already 2, in which case make it 0.
*/
switch (how_toggle)
if (o->ovar != NULL)
{
case OPT_TOGGLE:
*(o->ovar) = flip_triple(*(o->ovar), lower);
break;
case OPT_UNSET:
*(o->ovar) = o->odefault;
break;
case OPT_SET:
*(o->ovar) = flip_triple(o->odefault, lower);
break;
switch (how_toggle)
{
case OPT_TOGGLE:
*(o->ovar) = flip_triple(*(o->ovar), lower);
break;
case OPT_UNSET:
*(o->ovar) = o->odefault;
break;
case OPT_SET:
*(o->ovar) = flip_triple(o->odefault, lower);
break;
}
}
break;
case STRING:
Expand Down Expand Up @@ -460,7 +472,8 @@ public void toggle_option(struct loption *o, int lower, constant char *s, int ho
/*
* Print the odesc message.
*/
error(o->odesc[*(o->ovar)], NULL_PARG);
if (o->ovar != NULL)
error(o->odesc[*(o->ovar)], NULL_PARG);
break;
case NUMBER:
/*
Expand Down
23 changes: 18 additions & 5 deletions opttbl.c
Expand Up @@ -70,7 +70,8 @@ public int status_line; /* Highlight entire marked lines */
public int header_lines; /* Freeze header lines at top of screen */
public int header_cols; /* Freeze header columns at left of screen */
public int nonum_headers; /* Don't give headers line numbers */
public int nosearch_headers; /* Don't search in header lines or columns */
public int nosearch_header_lines = 0; /* Don't search in header lines */
public int nosearch_header_cols = 0; /* Don't search in header columns */
public int redraw_on_quit; /* Redraw last screen after term deinit */
public int def_search_type; /* */
public int exit_F_on_close; /* Exit F command when input closes */
Expand Down Expand Up @@ -162,6 +163,8 @@ static struct optname status_line_optname = { "status-line", NULL };
static struct optname header_optname = { "header", NULL };
static struct optname nonum_headers_optname = { "no-number-headers", NULL };
static struct optname nosearch_headers_optname = { "no-search-headers", NULL };
static struct optname nosearch_header_lines_optname = { "no-search-header-lines", NULL };
static struct optname nosearch_header_cols_optname = { "no-search-header-columns", NULL };
static struct optname redraw_on_quit_optname = { "redraw-on-quit", NULL };
static struct optname search_type_optname = { "search-options", NULL };
static struct optname exit_F_on_close_optname = { "exit-follow-on-close", NULL };
Expand Down Expand Up @@ -625,11 +628,21 @@ static struct loption option[] =
}
},
{ OLETTER_NONE, &nosearch_headers_optname,
BOOL|HL_REPAINT, 0, &nosearch_headers, NULL,
BOOL|HL_REPAINT, 0, NULL, opt_nosearch_headers,
{
"Search includes header lines",
"Search does not include header lines",
NULL
NULL, NULL, NULL
}
},
{ OLETTER_NONE, &nosearch_header_lines_optname,
BOOL|HL_REPAINT, 0, NULL, opt_nosearch_header_lines,
{
NULL, NULL, NULL
}
},
{ OLETTER_NONE, &nosearch_header_cols_optname,
BOOL|HL_REPAINT, 0, NULL, opt_nosearch_header_cols,
{
NULL, NULL, NULL
}
},
{ OLETTER_NONE, &redraw_on_quit_optname,
Expand Down
12 changes: 5 additions & 7 deletions search.c
Expand Up @@ -37,7 +37,8 @@ extern int sc_width;
extern int sc_height;
extern int hshift;
extern int match_shift;
extern int nosearch_headers;
extern int nosearch_header_lines;
extern int nosearch_header_cols;
extern int header_lines;
extern int header_cols;
extern char rscroll_char;
Expand Down Expand Up @@ -499,12 +500,9 @@ static int hilited_range_attr(POSITION pos, POSITION epos)
/*
* Set header parameters.
*/
public void set_header(int lines, int cols, POSITION pos)
public void set_header(POSITION pos)
{
header_cols = cols;
header_lines = lines;
header_start_pos = (header_lines == 0) ? NULL_POSITION : pos;

if (header_start_pos != NULL_POSITION)
{
int ln;
Expand Down Expand Up @@ -1239,7 +1237,7 @@ static int search_range(POSITION pos, POSITION endpos, int search_type, int matc
size_t sheight = (size_t) (sc_height - sindex_from_sline(jump_sline));

linenum = find_linenum(pos);
if (nosearch_headers && linenum <= header_lines)
if (nosearch_header_lines && linenum <= header_lines)
{
linenum = header_lines + 1;
pos = find_pos(linenum);
Expand Down Expand Up @@ -1356,7 +1354,7 @@ static int search_range(POSITION pos, POSITION endpos, int search_type, int matc
if (is_filtered(linepos))
continue;
#endif
if (nosearch_headers)
if (nosearch_header_cols)
skip_bytes = skip_columns(header_cols, &line, &line_len);

/*
Expand Down
2 changes: 1 addition & 1 deletion version.c
Expand Up @@ -1005,7 +1005,7 @@ v646 11/6/23 Bug fixes.
v647 11/16/23 Fix --+option; fix compiler warnings.
v648 11/16/23 Add lang.h to release.
v649 12/1/23 Add line number param to --header.
v650
v650 Add --no-search-header-lines and --no-search-header-columns.
*/

char version[] = "650x";

0 comments on commit 6e9f84a

Please sign in to comment.