summaryrefslogtreecommitdiff
path: root/libmailutils/tests/cidr.c
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2020-08-18 17:38:10 +0300
committerSergey Poznyakoff <gray@gnu.org>2020-08-18 17:38:10 +0300
commitd2eb03a3b9db683418cc0bd084915468e4968854 (patch)
treeec40bc0c8e9f9f53acb9cb0b7d76ee197410c85c /libmailutils/tests/cidr.c
parent37713b42a501892469234b90454731d8d8b7a3e6 (diff)
downloadmailutils-d2eb03a3b9db683418cc0bd084915468e4968854.tar.gz
mailutils-d2eb03a3b9db683418cc0bd084915468e4968854.tar.bz2
libmailutils/tests tools: use mu_cli_simple for option handling
Diffstat (limited to 'libmailutils/tests/cidr.c')
-rw-r--r--libmailutils/tests/cidr.c43
1 files changed, 24 insertions, 19 deletions
diff --git a/libmailutils/tests/cidr.c b/libmailutils/tests/cidr.c
index 20e18b0fc..febf92f08 100644
--- a/libmailutils/tests/cidr.c
+++ b/libmailutils/tests/cidr.c
@@ -30,36 +30,40 @@ print_bytes (unsigned char *b, size_t l)
printf ("\n");
}
+static int ipv6_simplify;
+
+struct mu_option options[] = {
+ { "simplify", 's', NULL, MU_OPTION_DEFAULT,
+ "simplify IPv6 addresses", mu_c_bool, &ipv6_simplify },
+ MU_OPTION_END
+};
+
int
main (int argc, char **argv)
{
- int flags = 0;
-
mu_set_program_name (argv[0]);
- if (argc < 2)
+ mu_cli_simple (argc, argv,
+ MU_CLI_OPTION_OPTIONS, options,
+ MU_CLI_OPTION_PROG_DOC, "cidr test tool",
+ MU_CLI_OPTION_PROG_ARGS, "CIDR [CIDR...]",
+ MU_CLI_OPTION_RETURN_ARGC, &argc,
+ MU_CLI_OPTION_RETURN_ARGV, &argv,
+ MU_CLI_OPTION_END);
+
+ if (argc == 0)
{
- mu_error ("usage: %s [-sS] CIDR [CIDR...]", argv[0]);
+ mu_error ("required argument missing; try %s --help for more info",
+ mu_program_name);
return 1;
}
- while (--argc)
+ while (argc--)
{
- char *arg = *++argv;
+ char *arg = *argv++;
struct mu_cidr cidr;
int rc;
char *str;
- if (strcmp (arg, "-s") == 0)
- {
- flags |= MU_CIDR_FMT_SIMPLIFY;
- continue;
- }
- else if (strcmp (arg, "-S") == 0)
- {
- flags &= ~MU_CIDR_FMT_SIMPLIFY;
- continue;
- }
-
rc = mu_cidr_from_string (&cidr, arg);
if (rc)
{
@@ -74,10 +78,11 @@ main (int argc, char **argv)
print_bytes (cidr.address, cidr.len);
printf ("netmask =");
print_bytes (cidr.netmask, cidr.len);
- rc = mu_cidr_format (&cidr, flags, &str);
+ rc = mu_cidr_format (&cidr, ipv6_simplify ? MU_CIDR_FMT_SIMPLIFY : 0,
+ &str);
if (rc)
{
- mu_error ("cannot covert to string: %s", mu_strerror (rc));
+ mu_error ("cannot convert to string: %s", mu_strerror (rc));
return 2;
}

Return to:

Send suggestions and report system problems to the System administrator.