From 3e79a5ca8b9f3186f04c75c89d3d73858a17598c Mon Sep 17 00:00:00 2001 From: Loui Chang Date: Fri, 15 Aug 2014 19:04:39 -0400 Subject: [PATCH] Add -b flag for debugging For now this just prints messages to stderr, so the user should manually redirect stderr to avoid breaking the ui. This can be later expanded upon to provide debugging messages in the command window. Signed-off-by: Loui Chang --- doc/toxic.1 | 3 +++ src/toxic.c | 16 ++++++++++++---- src/windows.h | 1 + 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/doc/toxic.1 b/doc/toxic.1 index 24682e4..58a06b2 100644 --- a/doc/toxic.1 +++ b/doc/toxic.1 @@ -23,6 +23,9 @@ instead of Ignore data file .IP "\-4, \-\-ipv4" Force IPv4 connection +.IP "\-b, \-\-debug +Enable debugging messages (prints to stderr). Redirect output to avoid breaking +the curses interface and better capture messages. .IP "\-d, \-\-default_locale Use default locale .IP "\-c, \-\-config config\-file" diff --git a/src/toxic.c b/src/toxic.c index 08590d9..09b7ec9 100644 --- a/src/toxic.c +++ b/src/toxic.c @@ -518,6 +518,7 @@ static void print_usage(void) { fprintf(stderr, "usage: toxic [OPTION] [FILE ...]\n"); fprintf(stderr, " -4, --ipv4 Force IPv4 connection\n"); + fprintf(stderr, " -b --debug Enable debugging\n"); fprintf(stderr, " -c, --config Use specified config file\n"); fprintf(stderr, " -d, --default-locale Use default locale\n"); fprintf(stderr, " -f, --file Use specified data file\n"); @@ -534,6 +535,7 @@ static void set_default_opts(void) { arg_opts.use_ipv4 = 0; arg_opts.ignore_data_file = 0; + arg_opts.debug = 0; arg_opts.default_locale = 0; arg_opts.use_custom_data = 0; arg_opts.no_connect = 0; @@ -549,6 +551,7 @@ static void parse_args(int argc, char *argv[]) {"file", required_argument, 0, 'f'}, {"nodata", no_argument, 0, 'x'}, {"ipv4", no_argument, 0, '4'}, + {"debug", no_argument, 0, 'b'}, {"default-locale", no_argument, 0, 'd'}, {"config", required_argument, 0, 'c'}, {"nodes", required_argument, 0, 'n'}, @@ -559,7 +562,7 @@ static void parse_args(int argc, char *argv[]) {"proxy", required_argument, 0, 'p'}, }; - const char *opts_str = "4dhotxc:f:n:r:p:"; + const char *opts_str = "4bdhotxc:f:n:r:p:"; int opt, indexptr; while ((opt = getopt_long(argc, argv, opts_str, long_opts, &indexptr)) != -1) { @@ -568,6 +571,10 @@ static void parse_args(int argc, char *argv[]) arg_opts.use_ipv4 = 1; break; + case 'b': + arg_opts.debug = 1; + break; + case 'c': snprintf(arg_opts.config_path, sizeof(arg_opts.config_path), "%s", optarg); break; @@ -704,9 +711,10 @@ int main(int argc, char *argv[]) Tox *m = init_tox(); init_term(); - /* Redirect stderr to /dev/null - NOTE: Might not be best solution. Comment out for debugging. */ - freopen("/dev/null", "w", stderr); + /* Enable debugging: This should be refactored to print error messages to + the command window */ + if (!arg_opts.debug) + freopen("/dev/null", "w", stderr); if (m == NULL) exit_toxic_err("failed in main", FATALERR_NETWORKINIT); diff --git a/src/windows.h b/src/windows.h index ac95ea7..9b1bb08 100644 --- a/src/windows.h +++ b/src/windows.h @@ -75,6 +75,7 @@ struct arg_opts { int ignore_data_file; int use_ipv4; int force_tcp; + int debug; int default_locale; int use_custom_data; int no_connect;