[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Man-db-devel] [PATCH 2/3] man(1): require page./term.. to be the only a
From: |
Mihail Konev |
Subject: |
[Man-db-devel] [PATCH 2/3] man(1): require page./term.. to be the only arg |
Date: |
Wed, 7 Dec 2016 04:14:25 +0500 |
Allow options before and after (for alias man='man ...')
---
include/manconfig.h.in | 4 ++++
src/man.c | 2 ++
src/whatis.c | 19 ++++++++++++++++++-
3 files changed, 24 insertions(+), 1 deletion(-)
diff --git a/include/manconfig.h.in b/include/manconfig.h.in
index 708341be46c1..980fd3d0d809 100644
--- a/include/manconfig.h.in
+++ b/include/manconfig.h.in
@@ -404,6 +404,10 @@ extern char *program_name; /* the basename of the program
(as called) */
*/
#define CTYPE(func,arg) (func((unsigned char)(arg)))
+/* Internal environment variable to alter whatis/apropos option parsing
+ * */
+#define WHATIS_ONE_ARG_ONLY "WHATIS_ONE_ARG_ONLY"
+
/* FSSTND directories */
#define CAT_ROOT "/var/catman" /* required by fsstnd() */
#define MAN_ROOT "/usr" /* required by fsstnd() */
diff --git a/src/man.c b/src/man.c
index 85b07f3399e8..a03e6457d578 100644
--- a/src/man.c
+++ b/src/man.c
@@ -3978,11 +3978,13 @@ void parse_dots_in_argv1(int argc, int arg1_idx, char
*argv[]) {
char *arg1;
int len;
+ unsetenv(WHATIS_ONE_ARG_ONLY);
if (first_arg > argc-1)
return;
arg1 = argv[arg1_idx];
len = strlen(arg1);
if (len >= 1 && arg1[len-1] == '.') {
+ setenv(WHATIS_ONE_ARG_ONLY, "", 1);
if (len >= 2 && arg1[len-2] == '.') {
external = APROPOS;
apropos = 1;
diff --git a/src/whatis.c b/src/whatis.c
index 4cf14a5b6a1b..aced53556ed2 100644
--- a/src/whatis.c
+++ b/src/whatis.c
@@ -879,6 +879,7 @@ int main (int argc, char *argv[])
char *locale_charset;
#endif
int status = OK;
+ int first_arg;
program_name = base_name (argv[0]);
if (STREQ (program_name, APROPOS_NAME)) {
@@ -912,9 +913,25 @@ int main (int argc, char *argv[])
multiple_locale = getenv ("LANGUAGE");
internal_locale = xstrdup (internal_locale ? internal_locale : "C");
+ /* parse the program args */
if (argp_parse (am_apropos ? &apropos_argp : &whatis_argp, argc, argv,
- 0, 0, 0))
+ ARGP_NO_ARGS, &first_arg, 0))
exit (FAIL);
+ num_keywords = 0;
+ keywords = argv + first_arg;
+ /* assumes ARGP_NO_ARGS and no ARGP_IN_ORDER flags to argp_parse
earlier */
+ if (getenv(WHATIS_ONE_ARG_ONLY)) {
+ if (first_arg != argc-1)
+ argp_error (NULL,
+ _("%s: with \"page.\", or \"term..\" ,"
+ " must be the only arg"),
+ argv[first_arg]);
+ exit (FAIL);
+ if (strlen(argv[first_arg]) > 0)
+ num_keywords = 1;
+ } else {
+ num_keywords = argc - first_arg;
+ }
read_config_file (user_config_file != NULL);
--
2.9.2
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Man-db-devel] [PATCH 2/3] man(1): require page./term.. to be the only arg,
Mihail Konev <=