From: Antoine Beaupré Date: Fri, 6 Dec 2013 05:16:28 +0000 (-0500) Subject: add commandline flag for forcing or disabling unicode X-Git-Tag: liboping-1.7.0~5^2~4 X-Git-Url: https://git.tokkee.org/?p=liboping.git;a=commitdiff_plain;h=a58f361afd7a6e0d2b112806bd280d173faf9bef add commandline flag for forcing or disabling unicode note that "forcing" may not work: ncurses still expects your locale to be correct, so maybe the force flag should also explicitely set a utf8 locale? --- diff --git a/src/oping.c b/src/oping.c index aa99ef9..c8d3cdf 100644 --- a/src/oping.c +++ b/src/oping.c @@ -159,6 +159,8 @@ static char *opt_filename = NULL; static int opt_count = -1; static int opt_send_ttl = 64; static uint8_t opt_send_qos = 0; +static int opt_utf8_force = 0; +static int opt_utf8_disable = 0; static int host_num = 0; @@ -505,7 +507,7 @@ static int read_options (int argc, char **argv) /* {{{ */ while (1) { - optchar = getopt (argc, argv, "46c:hi:I:t:Q:f:D:"); + optchar = getopt (argc, argv, "46uUc:hi:I:t:Q:f:D:"); if (optchar == -1) break; @@ -517,6 +519,13 @@ static int read_options (int argc, char **argv) /* {{{ */ opt_addrfamily = (optchar == '4') ? AF_INET : AF_INET6; break; + case 'u': + opt_utf8_force = 1; + break; + case 'U': + opt_utf8_disable = 1; + break; + case 'c': { int new_count; @@ -584,6 +593,9 @@ static int read_options (int argc, char **argv) /* {{{ */ } } + if (opt_utf8_disable && opt_utf8_force) + fprintf (stderr, "Ignoring contradictory unicode flags\n"); + return (optind); } /* }}} read_options */ @@ -637,7 +649,7 @@ static void time_calc (struct timespec *ts_dest, /* {{{ */ #if USE_NCURSES static int unicode_locale() /* {{{ */ { - return _nc_unicode_locale(); + return ( _nc_unicode_locale() || opt_utf8_force ) && !opt_utf8_disable; } /* }}} int unicode_locale */ static int update_prettyping_graph (ping_context_t *ctx, /* {{{ */