From 3e79a5ca8b9f3186f04c75c89d3d73858a17598c Mon Sep 17 00:00:00 2001 From: Loui Chang Date: Fri, 15 Aug 2014 19:04:39 -0400 Subject: [PATCH 1/3] 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; From f5401df2c7dfb78edd76218f0bc434ef58392309 Mon Sep 17 00:00:00 2001 From: Loui Chang Date: Fri, 15 Aug 2014 19:26:06 -0400 Subject: [PATCH 2/3] doc/toxic: Add missing flags and sort alphabetically. Signed-off-by: Loui Chang --- doc/toxic.1 | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/doc/toxic.1 b/doc/toxic.1 index 58a06b2..13ca3b2 100644 --- a/doc/toxic.1 +++ b/doc/toxic.1 @@ -1,4 +1,4 @@ -.TH TOXIC 1 "June 2014" "Toxic v__VERSION__" "User Manual" +.TH TOXIC 1 "August 2014" "Toxic v__VERSION__" "User Manual" .SH NAME Toxic \- CLI client for Tox .SH SYNOPSYS @@ -14,32 +14,40 @@ Toxic is an ncurses-based instant messaging client for Tox which formerly resided in the Tox core repository, and is now available as a standalone application. .SH OPTIONS -.IP "\-f, \-\-file data\-file" -Use specified -.I data\-file -instead of -.IR ~/.config/tox/data -.IP "\-x, \-\-nodata" -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" Use specified +.IP "\-d, \-\-default_locale +Use default locale .I config\-file instead of .IR ~/.config/tox/toxic.conf +.IP "\-f, \-\-file data\-file" +Use specified +.I data\-file +instead of +.IR ~/.config/tox/data +.IP "\-h, \-\-help" +Show help message .IP "\-n, \-\-nodes nodes\-file" Use specified .I nodes\-file for DHT bootstrap nodes, instead of .IR __DATADIR__/DHTnodes -.IP "\-h, \-\-help" -Show help message +.IP "\-o, \-\-noconnect" +Do not connect to the DHT network +.IP "\-p, \-\-proxy" +Use proxy: Requires [IP] [port] +.IP "\-r, \-\-dnslist" +Use specified DNSservers file +.IP "\-t, \-\-force\-tcp" +Force TCP connection (use this with proxies) +.IP "\-x, \-\-nodata" +Ignore data file .SH FILES .IP __DATADIR__/DHTnodes Default list of DHT bootstrap nodes. From 595e42b5874210256cd2dc3f43794f67c0c4a26e Mon Sep 17 00:00:00 2001 From: Loui Chang Date: Sat, 16 Aug 2014 02:35:21 -0400 Subject: [PATCH 3/3] Clarify function of -b switch. Signed-off-by: Loui Chang --- doc/toxic.1 | 2 +- src/toxic.c | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/doc/toxic.1 b/doc/toxic.1 index 13ca3b2..8d58691 100644 --- a/doc/toxic.1 +++ b/doc/toxic.1 @@ -17,7 +17,7 @@ application. .IP "\-4, \-\-ipv4" Force IPv4 connection .IP "\-b, \-\-debug -Enable debugging messages (prints to stderr). Redirect output to avoid breaking +Enable stderr for debugging. Redirect output to avoid breaking the curses interface and better capture messages. .IP "\-c, \-\-config config\-file" Use specified diff --git a/src/toxic.c b/src/toxic.c index 09b7ec9..8dd2067 100644 --- a/src/toxic.c +++ b/src/toxic.c @@ -518,7 +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, " -b --debug Enable stderr for 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"); @@ -711,8 +711,7 @@ int main(int argc, char *argv[]) Tox *m = init_tox(); init_term(); - /* Enable debugging: This should be refactored to print error messages to - the command window */ + /* enable stderr for debugging */ if (!arg_opts.debug) freopen("/dev/null", "w", stderr);