Fix the DEBUG_cli_parsed() macro

Was logging a blank line instead of "parsed `key`=`value`..."
This commit is contained in:
Andrew Bettison 2016-09-06 11:18:59 +09:30
parent c3a94a7ac3
commit fc47bc541f
4 changed files with 9 additions and 5 deletions

8
cli.c
View File

@ -312,7 +312,11 @@ int cli_parse(const int argc, const char *const *args, const struct cli_schema *
void _debug_cli_parsed(struct __sourceloc __whence, const char *tag, const struct cli_parsed *parsed) void _debug_cli_parsed(struct __sourceloc __whence, const char *tag, const struct cli_parsed *parsed)
{ {
_DEBUG_argv(tag, parsed->argc, parsed->args); strbuf t = strbuf_alloca(strlen(tag) + 3);
strbuf_putc(t, '{');
strbuf_puts(t, tag);
strbuf_putc(t, '}');
_DEBUG_argv(strbuf_str(t), parsed->argc, parsed->args);
strbuf b = strbuf_alloca(1024); strbuf b = strbuf_alloca(1024);
unsigned i; unsigned i;
for (i = 0; i < parsed->labelc; ++i) { for (i = 0; i < parsed->labelc; ++i) {
@ -321,7 +325,7 @@ void _debug_cli_parsed(struct __sourceloc __whence, const char *tag, const struc
} }
if (parsed->varargi >= 0) if (parsed->varargi >= 0)
strbuf_sprintf(b, " varargi=%d", parsed->varargi); strbuf_sprintf(b, " varargi=%d", parsed->varargi);
_DEBUGF(tag, "parsed%s", strbuf_str(b)); _DEBUGF_TAG(tag, "parsed%s", strbuf_str(b));
} }
int cli_invoke(const struct cli_parsed *parsed, struct cli_context *context) int cli_invoke(const struct cli_parsed *parsed, struct cli_context *context)

2
cli.h
View File

@ -74,7 +74,7 @@ struct cli_parsed {
void _debug_cli_parsed(struct __sourceloc __whence, const char *tag, const struct cli_parsed *parsed); void _debug_cli_parsed(struct __sourceloc __whence, const char *tag, const struct cli_parsed *parsed);
#define DEBUG_cli_parsed(FLAG,parsed) do { if (IF_DEBUG(FLAG)) _debug_cli_parsed(__WHENCE__, "{" #FLAG "}", parsed); } while (0) #define DEBUG_cli_parsed(FLAG,parsed) do { if (IF_DEBUG(FLAG)) _debug_cli_parsed(__WHENCE__, #FLAG, parsed); } while (0)
int cli_usage(const struct cli_schema *commands, const struct cli_schema *end_commands, XPRINTF xpf); int cli_usage(const struct cli_schema *commands, const struct cli_schema *end_commands, XPRINTF xpf);
int cli_usage_args(const int argc, const char *const *args, const struct cli_schema *commands, const struct cli_schema *end_commands, XPRINTF xpf); int cli_usage_args(const int argc, const char *const *args, const struct cli_schema *commands, const struct cli_schema *end_commands, XPRINTF xpf);

View File

@ -41,7 +41,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#define DEBUG(FLAG,X) DEBUGF(FLAG, "%s", (X)) #define DEBUG(FLAG,X) DEBUGF(FLAG, "%s", (X))
#define DEBUGF_perror(FLAG,F,...) do { if (IF_DEBUG(FLAG)) _DEBUGF_TAG_perror(#FLAG, F, ##__VA_ARGS__); } while (0) #define DEBUGF_perror(FLAG,F,...) do { if (IF_DEBUG(FLAG)) _DEBUGF_TAG_perror(#FLAG, F, ##__VA_ARGS__); } while (0)
#define DEBUG_perror(FLAG,X) DEBUGF_perror(FLAG, "%s", (X)) #define DEBUG_perror(FLAG,X) DEBUGF_perror(FLAG, "%s", (X))
#define DEBUG_argv(FLAG,X,ARGC,ARGV) do { if (IF_DEBUG(FLAG)) _DEBUG_TAG_argv(#FLAG, X, (ARGC), (ARGV)); } while (0) #define DEBUG_argv(FLAG,X,ARGC,ARGV) do { if (IF_DEBUG(FLAG)) _DEBUGF_TAG_argv(#FLAG, X, (ARGC), (ARGV)); } while (0)
#define D(FLAG) DEBUG(FLAG, "D") #define D(FLAG) DEBUG(FLAG, "D")
#define T DEBUG(trace, "T") #define T DEBUG(trace, "T")

2
log.h
View File

@ -122,7 +122,7 @@ __SERVAL_LOG_INLINE int logErrorAndReturnNegativeOne(struct __sourceloc whence,
#define _DEBUGF_TAG(TAG,F,...) _DEBUGF("{%s} " F, (TAG), ##__VA_ARGS__) #define _DEBUGF_TAG(TAG,F,...) _DEBUGF("{%s} " F, (TAG), ##__VA_ARGS__)
#define _DEBUGF_TAG_perror(TAG,F,...) _DEBUGF_perror("{%s} " F, (TAG), ##__VA_ARGS__) #define _DEBUGF_TAG_perror(TAG,F,...) _DEBUGF_perror("{%s} " F, (TAG), ##__VA_ARGS__)
#define _DEBUGF_TAG_argv(TAG,X,ARGC,ARGV) _DEBUGF_argv("{" TAG "} " X, (ARGC), (ARGV)) #define _DEBUG_TAG_argv(TAG,X,ARGC,ARGV) _DEBUG_argv("{" TAG "} " X, (ARGC), (ARGV))
#define dump(X,A,N) logDump(LOG_LEVEL_DEBUG, __WHENCE__, (X), (const unsigned char *)(A), (size_t)(N)) #define dump(X,A,N) logDump(LOG_LEVEL_DEBUG, __WHENCE__, (X), (const unsigned char *)(A), (size_t)(N))