summaryrefslogtreecommitdiffstats
path: root/contrib/less/option.c
diff options
context:
space:
mode:
authordelphij <delphij@FreeBSD.org>2011-05-09 21:51:59 +0000
committerdelphij <delphij@FreeBSD.org>2011-05-09 21:51:59 +0000
commit142a49a4be37258477d8ce2b19011a75c36bd418 (patch)
treee6e6402d1f7ea7e3382a94b4f654586f41b93f2c /contrib/less/option.c
parent39f7e10a268694e139c11157f966ca179b834212 (diff)
downloadFreeBSD-src-142a49a4be37258477d8ce2b19011a75c36bd418.zip
FreeBSD-src-142a49a4be37258477d8ce2b19011a75c36bd418.tar.gz
MFV: Update to less v443.
MFC after: 1 month
Diffstat (limited to 'contrib/less/option.c')
-rw-r--r--contrib/less/option.c100
1 files changed, 51 insertions, 49 deletions
diff --git a/contrib/less/option.c b/contrib/less/option.c
index 9841916..acb8962 100644
--- a/contrib/less/option.c
+++ b/contrib/less/option.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 1984-2009 Mark Nudelman
+ * Copyright (C) 1984-2011 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.
@@ -24,7 +24,6 @@
static struct loption *pendopt;
public int plusoption = FALSE;
-static char *propt();
static char *optstring();
static int flip_triple();
@@ -33,6 +32,35 @@ extern int less_is_more;
extern int quit_at_eof;
extern char *every_first_cmd;
+/*
+ * Return a printable description of an option.
+ */
+ static char *
+opt_desc(o)
+ struct loption *o;
+{
+ static char buf[OPTNAME_MAX + 10];
+ if (o->oletter == OLETTER_NONE)
+ SNPRINTF1(buf, sizeof(buf), "--%s", o->onames->oname);
+ else
+ SNPRINTF2(buf, sizeof(buf), "-%c (--%s)", o->oletter, o->onames->oname);
+ return (buf);
+}
+
+/*
+ * Return a string suitable for printing as the "name" of an option.
+ * For example, if the option letter is 'x', just return "-x".
+ */
+ public char *
+propt(c)
+ int c;
+{
+ static char buf[8];
+
+ sprintf(buf, "-%s", prchar(c));
+ return (buf);
+}
+
/*
* Scan an argument (either from the command line or from the
* LESS environment variable) and process it.
@@ -69,7 +97,7 @@ scan_option(s)
(*pendopt->ofunc)(INIT, s);
break;
case NUMBER:
- printopt = propt(pendopt->oletter);
+ printopt = opt_desc(pendopt);
*(pendopt->ovar) = getnum(&s, printopt, (int*)NULL);
break;
}
@@ -261,12 +289,12 @@ scan_option(s)
* OPT_SET set to the inverse of the default value
*/
public void
-toggle_option(c, s, how_toggle)
- int c;
+toggle_option(o, lower, s, how_toggle)
+ struct loption *o;
+ int lower;
char *s;
int how_toggle;
{
- register struct loption *o;
register int num;
int no_prompt;
int err;
@@ -275,27 +303,22 @@ toggle_option(c, s, how_toggle)
no_prompt = (how_toggle & OPT_NO_PROMPT);
how_toggle &= ~OPT_NO_PROMPT;
- /*
- * Look up the option letter in the option table.
- */
- o = findopt(c);
if (o == NULL)
{
- parg.p_string = propt(c);
- error("There is no %s option", &parg);
+ error("No such option", NULL_PARG);
return;
}
if (how_toggle == OPT_TOGGLE && (o->otype & NO_TOGGLE))
{
- parg.p_string = propt(c);
+ parg.p_string = opt_desc(o);
error("Cannot change the %s option", &parg);
return;
- }
+ }
if (how_toggle == OPT_NO_TOGGLE && (o->otype & NO_QUERY))
{
- parg.p_string = propt(c);
+ parg.p_string = opt_desc(o);
error("Cannot query the %s option", &parg);
return;
}
@@ -355,15 +378,13 @@ toggle_option(c, s, how_toggle)
switch (how_toggle)
{
case OPT_TOGGLE:
- *(o->ovar) = flip_triple(*(o->ovar),
- ASCII_IS_LOWER(c));
+ *(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,
- ASCII_IS_LOWER(c));
+ *(o->ovar) = flip_triple(o->odefault, lower);
break;
}
break;
@@ -465,33 +486,17 @@ flip_triple(val, lc)
}
/*
- * Return a string suitable for printing as the "name" of an option.
- * For example, if the option letter is 'x', just return "-x".
- */
- static char *
-propt(c)
- int c;
-{
- static char buf[8];
-
- sprintf(buf, "-%s", prchar(c));
- return (buf);
-}
-
-/*
- * Determine if an option is a single character option (BOOL or TRIPLE),
- * or if it a multi-character option (NUMBER).
+ * Determine if an option takes a parameter.
*/
public int
-single_char_option(c)
- int c;
+opt_has_param(o)
+ struct loption *o;
{
- register struct loption *o;
-
- o = findopt(c);
if (o == NULL)
- return (TRUE);
- return ((o->otype & (BOOL|TRIPLE|NOVAR|NO_TOGGLE)) != 0);
+ return (0);
+ if (o->otype & (BOOL|TRIPLE|NOVAR|NO_TOGGLE))
+ return (0);
+ return (1);
}
/*
@@ -499,14 +504,11 @@ single_char_option(c)
* Only string and number valued options have prompts.
*/
public char *
-opt_prompt(c)
- int c;
+opt_prompt(o)
+ struct loption *o;
{
- register struct loption *o;
-
- o = findopt(c);
if (o == NULL || (o->otype & (STRING|NUMBER)) == 0)
- return (NULL);
+ return ("?");
return (o->odesc[0]);
}
@@ -541,7 +543,7 @@ nostring(printopt)
public void
nopendopt()
{
- nostring(propt(pendopt->oletter));
+ nostring(opt_desc(pendopt));
}
/*
OpenPOWER on IntegriCloud