From: <n0...@us...> - 2008-11-30 20:53:27
|
Revision: 1273 http://conky.svn.sourceforge.net/conky/?rev=1273&view=rev Author: n0-1 Date: 2008-11-30 20:53:20 +0000 (Sun, 30 Nov 2008) Log Message: ----------- Add debugging output at runtime The new command line option '-D' ('--debug') increases debugging level by one. For debugging output a user could be interested in, use the macros DEBUG() and DEBUG2(). Functionality is equal to the ERR() macro. DEBUG2() prints stuff only if debugging level is greater one, which means that '--debug' has been specified more than once. This patch also includes usage of the macros for the new template object (as debugging syntax errors in templates is one thing a user potentially needs to do). Modified Paths: -------------- trunk/conky1/ChangeLog trunk/conky1/src/conky.c trunk/conky1/src/conky.h Modified: trunk/conky1/ChangeLog =================================================================== --- trunk/conky1/ChangeLog 2008-11-29 13:03:50 UTC (rev 1272) +++ trunk/conky1/ChangeLog 2008-11-30 20:53:20 UTC (rev 1273) @@ -1,5 +1,8 @@ # $Id$ +2008-11-30 + * Added runtime debugging output + 2008-11-29 * Added template support Modified: trunk/conky1/src/conky.c =================================================================== --- trunk/conky1/src/conky.c 2008-11-29 13:03:50 UTC (rev 1272) +++ trunk/conky1/src/conky.c 2008-11-30 20:53:20 UTC (rev 1273) @@ -73,6 +73,9 @@ //#define SIGNAL_BLOCKING #undef SIGNAL_BLOCKING +/* debugging level */ +int global_debug_level = 0; + static void print_version(void) __attribute__((noreturn)); static void print_version(void) @@ -4366,9 +4369,7 @@ for (i = 0; i < argcnt; i++) { char *tmp; tmp = backslash_escape(argsp[i], NULL, 0); -#if 0 - printf("%s: substituted arg '%s' to '%s'\n", tmpl, argsp[i], tmp); -#endif + DEBUG2("%s: substituted arg '%s' to '%s'", tmpl, argsp[i], tmp); sprintf(argsp[i], "%s", tmp); free(tmp); } @@ -4376,9 +4377,8 @@ p = template_dup = strdup(template[template_idx]); eval_text = backslash_escape(template[template_idx], argsp, argcnt); -#if 0 - printf("substituted %s, output is '%s'\n", tmpl, eval_text); -#endif + DEBUG("substituted %s, output is '%s'", tmpl, eval_text); + eval_list = extract_variable_text_internal(eval_text, allow_threaded); if (eval_list) { (*list)->text_objects = realloc((*list)->text_objects, @@ -9142,6 +9142,7 @@ "file.\n" " -v, --version version\n" " -q, --quiet quiet mode\n" + " -D, --debug increase debugging output\n" " -c, --config=FILE config file to load\n" " -d, --daemonize daemonize, fork to background\n" " -h, --help help\n" @@ -9166,7 +9167,7 @@ } /* : means that character before that takes an argument */ -static const char *getopt_string = "vVqdt:u:i:hc:" +static const char *getopt_string = "vVqdDt:u:i:hc:" #ifdef X11 "x:y:w:a:f:" #ifdef OWN_WINDOW @@ -9181,6 +9182,7 @@ static const struct option longopts[] = { { "help", 0, NULL, 'h' }, { "version", 0, NULL, 'V' }, + { "debug", 0, NULL, 'D' }, { "config", 1, NULL, 'c' }, { "daemonize", 0, NULL, 'd' }, #ifdef X11 @@ -9360,7 +9362,9 @@ case 'd': fork_to_background = 1; break; - + case 'D': + global_debug_level++; + break; #ifdef X11 case 'f': set_first_font(optarg); Modified: trunk/conky1/src/conky.h =================================================================== --- trunk/conky1/src/conky.h 2008-11-29 13:03:50 UTC (rev 1272) +++ trunk/conky1/src/conky.h 2008-11-30 20:53:20 UTC (rev 1273) @@ -117,6 +117,17 @@ #define CRIT_ERR(...) \ { ERR(__VA_ARGS__); exit(EXIT_FAILURE); } +/* debugging output */ +extern int global_debug_level; +#define __DBG(level, ...) \ + if (global_debug_level > level) { \ + fprintf(stderr, "DEBUG(%d): ", level); \ + fprintf(stderr, __VA_ARGS__); \ + fprintf(stderr, "\n"); \ + } +#define DEBUG(...) __DBG(0, __VA_ARGS__) +#define DEBUG2(...) __DBG(1, __VA_ARGS__) + struct net_stat { const char *dev; int up; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |