man-db-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Man-db-devel] [PATCH 3/3] man(1): check for options conflicting with pa


From: Mihail Konev
Subject: [Man-db-devel] [PATCH 3/3] man(1): check for options conflicting with page./term..
Date: Wed, 7 Dec 2016 04:14:56 +0500

---
 src/man.c | 61 +++++++++++++++++++++++++++++++++++++------------------------
 1 file changed, 37 insertions(+), 24 deletions(-)

diff --git a/src/man.c b/src/man.c
index a03e6457d578..06635eb51028 100644
--- a/src/man.c
+++ b/src/man.c
@@ -346,6 +346,7 @@ static struct argp_option options[] = {
 };
 
 static int apropos, whatis; /* retain values between calls to parse_opt */
+static void check_for_incompatible_options(int, struct argp_state*);
 
 static error_t parse_opt (int key, char *arg, struct argp_state *state)
 {
@@ -533,35 +534,45 @@ static error_t parse_opt (int key, char *arg, struct 
argp_state *state)
                                         ARGP_HELP_STD_HELP);
                        break;
                case ARGP_KEY_SUCCESS:
-                       /* check for incompatible options */
-                       if (troff + whatis + apropos + catman +
-                           (print_where || print_where_cat) > 1) {
-                               char *badopts = xasprintf
-                                       ("%s%s%s%s%s%s",
-                                        troff ? "-[tTZH] " : "",
-                                        whatis ? "-f " : "",
-                                        apropos ? "-k " : "",
-                                        catman ? "-c " : "",
-                                        print_where ? "-w " : "",
-                                        print_where_cat ? "-W " : "");
-                               argp_error (state,
-                                           _("%s: incompatible options"),
-                                           badopts);
-                       }
-                       if (regex_opt + wildcard > 1) {
-                               char *badopts = xasprintf
-                                       ("%s%s",
-                                        regex_opt ? "--regex " : "",
-                                        wildcard ? "--wildcard " : "");
-                               argp_error (state,
-                                           _("%s: incompatible options"),
-                                           badopts);
-                       }
+                       check_for_incompatible_options(0, state);
                        return 0;
        }
        return ARGP_ERR_UNKNOWN;
 }
 
+static void check_for_incompatible_options(int dots, struct argp_state *state) 
{
+       const char *error_msg = dots ?
+               _("cannot be used with \"page.\" or \"term..\"") :
+               _("incompatible options");
+       int x;
+
+       x = troff + whatis + apropos + catman + (print_where || 
print_where_cat);
+       if (dots ? x : (x > 1)) {
+               char *badopts = xasprintf
+                       ("%s%s%s%s%s%s",
+                        troff ? "-[tTZH] " : "",
+                        whatis ? "-f " : "",
+                        apropos ? "-k " : "",
+                        catman ? "-c " : "",
+                        print_where ? "-w " : "",
+                        print_where_cat ? "-W " : "");
+               argp_error (state,
+                           _("%s: %s"),
+                           badopts, error_msg);
+       }
+
+       x = regex_opt + wildcard;
+       if (dots ? x : (x > 1)) {
+               char *badopts = xasprintf
+                       ("%s%s",
+                               regex_opt ? "--regex " : "",
+                               wildcard ? "--wildcard " : "");
+               argp_error (state,
+                           _("%s: %s"),
+                           badopts, error_msg);
+       }
+}
+
 static char *help_filter (int key, const char *text,
                          void *input ATTRIBUTE_UNUSED)
 {
@@ -3981,9 +3992,11 @@ void parse_dots_in_argv1(int argc, int arg1_idx, char 
*argv[]) {
        unsetenv(WHATIS_ONE_ARG_ONLY);
        if (first_arg > argc-1)
                return;
+
        arg1 = argv[arg1_idx];
        len = strlen(arg1);
        if (len >= 1 && arg1[len-1] == '.') {
+               check_for_incompatible_options(1, NULL);
                setenv(WHATIS_ONE_ARG_ONLY, "", 1);
                if (len >= 2 && arg1[len-2] == '.') {
                        external = APROPOS;
-- 
2.9.2




reply via email to

[Prev in Thread] Current Thread [Next in Thread]