Reduce diff lines between vti and vti6 help printing code.

Use @struct link_util ->id field to print correct link help:
all callers now pass this data structure to vti_print_help().

Get rid of custom print_usage() and usage() functions and use
vti_print_help() directly, return from function on "... type
<help|garbage>" instead of exit(2).

While there replace vti6 function prefix with vti to reduce
diff lines too.

Signed-off-by: Serhey Popovych <serhe.popov...@gmail.com>
---
 ip/link_vti.c  |   42 ++++++++++++++++++------------------------
 ip/link_vti6.c |   45 ++++++++++++++++++++-------------------------
 2 files changed, 38 insertions(+), 49 deletions(-)

diff --git a/ip/link_vti.c b/ip/link_vti.c
index 49b87e9..f128e6b 100644
--- a/ip/link_vti.c
+++ b/ip/link_vti.c
@@ -23,29 +23,27 @@
 #include "ip_common.h"
 #include "tunnel.h"
 
-
-static void print_usage(FILE *f)
+static void vti_print_help(struct link_util *lu, int argc, char **argv, FILE 
*f)
 {
        fprintf(f,
-               "Usage: ... vti [ remote ADDR ]\n"
-               "               [ local ADDR ]\n"
-               "               [ [i|o]key KEY ]\n"
-               "               [ dev PHYS_DEV ]\n"
-               "               [ fwmark MARK ]\n"
+               "Usage: ... %-4s [ remote ADDR ]\n",
+               lu->id
+       );
+       fprintf(f,
+               "                [ local ADDR ]\n"
+               "                [ [i|o]key KEY ]\n"
+               "                [ dev PHYS_DEV ]\n"
+               "                [ fwmark MARK ]\n"
                "\n"
-               "Where: ADDR := { IP_ADDRESS }\n"
+       );
+       fprintf(f,
+               "Where: ADDR := { IP%s_ADDRESS }\n"
                "       KEY  := { DOTTED_QUAD | NUMBER }\n"
-               "       MARK := { 0x0..0xffffffff }\n"
+               "       MARK := { 0x0..0xffffffff }\n",
+               ""
        );
 }
 
-static void usage(void) __attribute__((noreturn));
-static void usage(void)
-{
-       print_usage(stderr);
-       exit(-1);
-}
-
 static int vti_parse_opt(struct link_util *lu, int argc, char **argv,
                         struct nlmsghdr *n)
 {
@@ -147,8 +145,10 @@ get_failed:
                        NEXT_ARG();
                        if (get_u32(&fwmark, *argv, 0))
                                invarg("invalid fwmark\n", *argv);
-               } else
-                       usage();
+               } else {
+                       vti_print_help(lu, argc, argv, stderr);
+                       return -1;
+               }
                argc--; argv++;
        }
 
@@ -208,12 +208,6 @@ static void vti_print_opt(struct link_util *lu, FILE *f, 
struct rtattr *tb[])
        }
 }
 
-static void vti_print_help(struct link_util *lu, int argc, char **argv,
-       FILE *f)
-{
-       print_usage(f);
-}
-
 struct link_util vti_link_util = {
        .id = "vti",
        .maxattr = IFLA_VTI_MAX,
diff --git a/ip/link_vti6.c b/ip/link_vti6.c
index d1fbec5..0a888cd 100644
--- a/ip/link_vti6.c
+++ b/ip/link_vti6.c
@@ -24,30 +24,29 @@
 #include "ip_common.h"
 #include "tunnel.h"
 
-static void print_usage(FILE *f)
+static void vti_print_help(struct link_util *lu, int argc, char **argv, FILE 
*f)
 {
        fprintf(f,
-               "Usage: ... vti6 [ remote ADDR ]\n"
+               "Usage: ... %-4s [ remote ADDR ]\n",
+               lu->id
+       );
+       fprintf(f,
                "                [ local ADDR ]\n"
                "                [ [i|o]key KEY ]\n"
                "                [ dev PHYS_DEV ]\n"
                "                [ fwmark MARK ]\n"
                "\n"
-               "Where: ADDR := { IPV6_ADDRESS }\n"
+       );
+       fprintf(f,
+               "Where: ADDR := { IP%s_ADDRESS }\n"
                "       KEY  := { DOTTED_QUAD | NUMBER }\n"
-               "       MARK := { 0x0..0xffffffff }\n"
+               "       MARK := { 0x0..0xffffffff }\n",
+               "V6"
        );
 }
 
-static void usage(void) __attribute__((noreturn));
-static void usage(void)
-{
-       print_usage(stderr);
-       exit(-1);
-}
-
-static int vti6_parse_opt(struct link_util *lu, int argc, char **argv,
-                         struct nlmsghdr *n)
+static int vti_parse_opt(struct link_util *lu, int argc, char **argv,
+                        struct nlmsghdr *n)
 {
        struct ifinfomsg *ifi = NLMSG_DATA(n);
        struct {
@@ -153,8 +152,10 @@ get_failed:
                        NEXT_ARG();
                        if (get_u32(&fwmark, *argv, 0))
                                invarg("invalid fwmark\n", *argv);
-               } else
-                       usage();
+               } else {
+                       vti_print_help(lu, argc, argv, stderr);
+                       return -1;
+               }
                argc--; argv++;
        }
 
@@ -169,7 +170,7 @@ get_failed:
        return 0;
 }
 
-static void vti6_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
+static void vti_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
 {
        char s2[64];
 
@@ -214,16 +215,10 @@ static void vti6_print_opt(struct link_util *lu, FILE *f, 
struct rtattr *tb[])
        }
 }
 
-static void vti6_print_help(struct link_util *lu, int argc, char **argv,
-       FILE *f)
-{
-       print_usage(f);
-}
-
 struct link_util vti6_link_util = {
        .id = "vti6",
        .maxattr = IFLA_VTI_MAX,
-       .parse_opt = vti6_parse_opt,
-       .print_opt = vti6_print_opt,
-       .print_help = vti6_print_help,
+       .parse_opt = vti_parse_opt,
+       .print_opt = vti_print_opt,
+       .print_help = vti_print_help,
 };
-- 
1.7.10.4

Reply via email to