aboutsummaryrefslogtreecommitdiff
path: root/contrib/less/optfunc.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/less/optfunc.c')
-rw-r--r--contrib/less/optfunc.c309
1 files changed, 229 insertions, 80 deletions
diff --git a/contrib/less/optfunc.c b/contrib/less/optfunc.c
index c04f9d4a2480..768fe0e98aed 100644
--- a/contrib/less/optfunc.c
+++ b/contrib/less/optfunc.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 1984-2020 Mark Nudelman
+ * Copyright (C) 1984-2021 Mark Nudelman
*
* You may distribute under the terms of either the GNU General Public
* License or the Less License, as specified in the README file.
@@ -19,9 +19,9 @@
* Each handling function is passed a "type" and, if it is a string
* option, the string which should be "assigned" to the option.
* The type may be one of:
- * INIT The option is being initialized from the command line.
- * TOGGLE The option is being changed from within the program.
- * QUERY The setting of the option is merely being queried.
+ * INIT The option is being initialized from the command line.
+ * TOGGLE The option is being changed from within the program.
+ * QUERY The setting of the option is merely being queried.
*/
#include "less.h"
@@ -36,7 +36,7 @@ extern int sc_width;
extern int sc_height;
extern int secure;
extern int dohelp;
-extern int any_display;
+extern int is_tty;
extern char openquote;
extern char closequote;
extern char *prproto[];
@@ -55,6 +55,9 @@ extern int rscroll_attr;
extern int mousecap;
extern int wheel_lines;
extern int less_is_more;
+extern int linenum_width;
+extern int status_col_width;
+extern int use_color;
#if LOGFILE
extern char *namelogfile;
extern int force_logfile;
@@ -65,6 +68,10 @@ public char *tagoption = NULL;
extern char *tags;
extern char ztags[];
#endif
+#if LESSTEST
+extern char *ttyin_name;
+extern int rstat_file;
+#endif /*LESSTEST*/
#if MSDOS_COMPILER
extern int nm_fg_color, nm_bg_color;
extern int bo_fg_color, bo_bg_color;
@@ -395,13 +402,13 @@ opt_p(type, s)
} else
{
plusoption = TRUE;
- ungetcc(CHAR_END_COMMAND);
- ungetsc(s);
/*
* {{ This won't work if the "/" command is
* changed or invalidated by a .lesskey file. }}
*/
ungetsc("/");
+ ungetsc(s);
+ ungetcc_back(CHAR_END_COMMAND);
}
break;
}
@@ -427,13 +434,13 @@ opt__P(type, s)
*/
switch (*s)
{
- case 's': proto = &prproto[PR_SHORT]; s++; break;
- case 'm': proto = &prproto[PR_MEDIUM]; s++; break;
- case 'M': proto = &prproto[PR_LONG]; s++; break;
- case '=': proto = &eqproto; s++; break;
- case 'h': proto = &hproto; s++; break;
- case 'w': proto = &wproto; s++; break;
- default: proto = &prproto[PR_SHORT]; break;
+ case 's': proto = &prproto[PR_SHORT]; s++; break;
+ case 'm': proto = &prproto[PR_MEDIUM]; s++; break;
+ case 'M': proto = &prproto[PR_LONG]; s++; break;
+ case '=': proto = &eqproto; s++; break;
+ case 'h': proto = &hproto; s++; break;
+ case 'w': proto = &wproto; s++; break;
+ default: proto = &prproto[PR_SHORT]; break;
}
free(*proto);
*proto = save(s);
@@ -504,20 +511,28 @@ opt__V(type, s)
dispversion();
break;
case INIT:
- /*
- * Force output to stdout per GNU standard for --version output.
- */
- any_display = 1;
+ set_output(1); /* Force output to stdout per GNU standard for --version output. */
putstr("less ");
putstr(version);
putstr(" (");
putstr(pattern_lib_name());
putstr(" regular expressions)\n");
- putstr("Copyright (C) 1984-2020 Mark Nudelman\n\n");
+ {
+ char constant *copyright = "Copyright (C) 1984-2021 Mark Nudelman\n\n";
+ if (copyright[0] == '@')
+ copyright = "Copyright (C) 1984 Mark Nudelman\n\n";
+ putstr(copyright);
+ }
+ if (version[strlen(version)-1] == 'x')
+ {
+ putstr("** This is an EXPERIMENTAL build of the 'less' software,\n");
+ putstr("** and may not function correctly.\n");
+ putstr("** Obtain release builds from the web page below.\n\n");
+ }
putstr("less comes with NO WARRANTY, to the extent permitted by law.\n");
putstr("For information about the terms of redistribution,\n");
putstr("see the file named README in the less distribution.\n");
- putstr("Home page: http://www.greenwoodsoftware.com/less\n");
+ putstr("Home page: https://greenwoodsoftware.com/less\n");
quit(QUIT_OK);
break;
}
@@ -527,60 +542,70 @@ opt__V(type, s)
/*
* Parse an MSDOS color descriptor.
*/
- static void
+ static void
colordesc(s, fg_color, bg_color)
char *s;
int *fg_color;
int *bg_color;
{
int fg, bg;
- int err;
#if MSDOS_COMPILER==WIN32C
int ul = 0;
-
+
if (*s == 'u')
{
ul = COMMON_LVB_UNDERSCORE;
- ++s;
- }
-#endif
- fg = getnum(&s, "D", &err);
- if (err)
- {
-#if MSDOS_COMPILER==WIN32C
- if (ul)
- fg = nm_fg_color;
- else
-#endif
- {
- error("Missing fg color in -D", NULL_PARG);
- return;
- }
- }
- if (*s != '.')
- bg = nm_bg_color;
- else
- {
s++;
- bg = getnum(&s, "D", &err);
- if (err)
+ if (*s == '\0')
{
- error("Missing bg color in -D", NULL_PARG);
+ *fg_color = nm_fg_color | ul;
+ *bg_color = nm_bg_color;
return;
}
}
-#if MSDOS_COMPILER==WIN32C
- if (*s == 'u')
+#endif
+ if (parse_color(s, &fg, &bg) == CT_NULL)
{
- ul = COMMON_LVB_UNDERSCORE;
- ++s;
+ PARG p;
+ p.p_string = s;
+ error("Invalid color string \"%s\"", &p);
+ } else
+ {
+ if (fg == CV_NOCHANGE)
+ fg = nm_fg_color;
+ if (bg == CV_NOCHANGE)
+ bg = nm_bg_color;
+#if MSDOS_COMPILER==WIN32C
+ fg |= ul;
+#endif
+ *fg_color = fg;
+ *bg_color = bg;
}
- fg |= ul;
+}
#endif
- if (*s != '\0')
- error("Extra characters at end of -D option", NULL_PARG);
- *fg_color = fg;
- *bg_color = bg;
+
+ static int
+color_from_namechar(namechar)
+ char namechar;
+{
+ switch (namechar)
+ {
+ case 'A': return AT_COLOR_ATTN;
+ case 'B': return AT_COLOR_BIN;
+ case 'C': return AT_COLOR_CTRL;
+ case 'E': return AT_COLOR_ERROR;
+ case 'M': return AT_COLOR_MARK;
+ case 'N': return AT_COLOR_LINENUM;
+ case 'P': return AT_COLOR_PROMPT;
+ case 'R': return AT_COLOR_RSCROLL;
+ case 'S': return AT_COLOR_SEARCH;
+ case 'n': return AT_NORMAL;
+ case 's': return AT_STANDOUT;
+ case 'd': return AT_BOLD;
+ case 'u': return AT_UNDERLINE;
+ case 'k': return AT_BLINK;
+ default: return -1;
+ }
}
/*
@@ -593,48 +618,75 @@ opt_D(type, s)
char *s;
{
PARG p;
+ int attr;
switch (type)
{
case INIT:
case TOGGLE:
- switch (*s++)
+#if MSDOS_COMPILER
+ if (*s == 'a')
{
- case 'n':
- colordesc(s, &nm_fg_color, &nm_bg_color);
- break;
- case 'd':
- colordesc(s, &bo_fg_color, &bo_bg_color);
- break;
- case 'u':
- colordesc(s, &ul_fg_color, &ul_bg_color);
- break;
- case 'k':
- colordesc(s, &bl_fg_color, &bl_bg_color);
- break;
- case 's':
- colordesc(s, &so_fg_color, &so_bg_color);
- break;
- case 'a':
sgr_mode = !sgr_mode;
break;
- default:
- error("-D must be followed by n, d, u, k, s or a", NULL_PARG);
- break;
}
- if (type == TOGGLE)
+#endif
+ attr = color_from_namechar(s[0]);
+ if (attr < 0)
+ {
+ p.p_char = s[0];
+ error("Invalid color specifier '%c'", &p);
+ return;
+ }
+ if (!use_color && (attr & AT_COLOR))
+ {
+ error("Set --use-color before changing colors", NULL_PARG);
+ return;
+ }
+ s++;
+#if MSDOS_COMPILER
+ if (!(attr & AT_COLOR))
+ {
+ switch (attr)
+ {
+ case AT_NORMAL:
+ colordesc(s, &nm_fg_color, &nm_bg_color);
+ break;
+ case AT_BOLD:
+ colordesc(s, &bo_fg_color, &bo_bg_color);
+ break;
+ case AT_UNDERLINE:
+ colordesc(s, &ul_fg_color, &ul_bg_color);
+ break;
+ case AT_BLINK:
+ colordesc(s, &bl_fg_color, &bl_bg_color);
+ break;
+ case AT_STANDOUT:
+ colordesc(s, &so_fg_color, &so_bg_color);
+ break;
+ }
+ if (type == TOGGLE)
+ {
+ at_enter(AT_STANDOUT);
+ at_exit();
+ }
+ } else
+#endif
+ if (set_color_map(attr, s) < 0)
{
- at_enter(AT_STANDOUT);
- at_exit();
+ p.p_string = s;
+ error("Invalid color string \"%s\"", &p);
+ return;
}
break;
+#if MSDOS_COMPILER
case QUERY:
p.p_string = (sgr_mode) ? "on" : "off";
error("SGR mode is %s", &p);
break;
+#endif
}
}
-#endif
/*
* Handler for the -x option.
@@ -759,7 +811,7 @@ opt_rscroll(type, s)
} else
{
rscroll_char = *fmt ? *fmt : '>';
- rscroll_attr = attr;
+ rscroll_attr = attr|AT_COLOR_RSCROLL;
}
break; }
case QUERY: {
@@ -835,6 +887,103 @@ opt_wheel_lines(type, s)
}
/*
+ * Handler for the --line-number-width option.
+ */
+ /*ARGSUSED*/
+ public void
+opt_linenum_width(type, s)
+ int type;
+ char *s;
+{
+ PARG parg;
+
+ switch (type)
+ {
+ case INIT:
+ case TOGGLE:
+ if (linenum_width > MAX_LINENUM_WIDTH)
+ {
+ parg.p_int = MAX_LINENUM_WIDTH;
+ error("Line number width must not be larger than %d", &parg);
+ linenum_width = MIN_LINENUM_WIDTH;
+ }
+ break;
+ case QUERY:
+ break;
+ }
+}
+
+/*
+ * Handler for the --status-column-width option.
+ */
+ /*ARGSUSED*/
+ public void
+opt_status_col_width(type, s)
+ int type;
+ char *s;
+{
+ PARG parg;
+
+ switch (type)
+ {
+ case INIT:
+ case TOGGLE:
+ if (status_col_width > MAX_STATUSCOL_WIDTH)
+ {
+ parg.p_int = MAX_STATUSCOL_WIDTH;
+ error("Status column width must not be larger than %d", &parg);
+ status_col_width = 2;
+ }
+ break;
+ case QUERY:
+ break;
+ }
+}
+
+#if LESSTEST
+/*
+ * Handler for the --tty option.
+ */
+ /*ARGSUSED*/
+ public void
+opt_ttyin_name(type, s)
+ int type;
+ char *s;
+{
+ switch (type)
+ {
+ case INIT:
+ ttyin_name = s;
+ is_tty = 1;
+ break;
+ }
+}
+
+/*
+ * Handler for the --rstat option.
+ */
+ /*ARGSUSED*/
+ public void
+opt_rstat(type, s)
+ int type;
+ char *s;
+{
+ switch (type)
+ {
+ case INIT:
+ rstat_file = open(s, O_WRONLY|O_CREAT, 0664);
+ if (rstat_file < 0)
+ {
+ PARG parg;
+ parg.p_string = s;
+ error("Cannot create rstat file \"%s\"", &parg);
+ }
+ break;
+ }
+}
+#endif /*LESSTEST*/
+
+/*
* Get the "screen window" size.
*/
public int