main: Add debug_parser() to avoid #ifdefs

Define a simple debug condition at the top of the file, to avoid using
lots of #ifdefs later on.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Joe Hershberger <joe.hershberger@ni.com>
This commit is contained in:
Simon Glass 2013-05-15 06:24:00 +00:00 committed by Tom Rini
parent fbcdf32af7
commit 3e4088737b

View File

@ -48,7 +48,11 @@ void show_boot_progress (int val) __attribute__((weak, alias("__show_boot_progre
#define MAX_DELAY_STOP_STR 32 #define MAX_DELAY_STOP_STR 32
#undef DEBUG_PARSER #define DEBUG_PARSER 0 /* set to 1 to debug */
#define debug_parser(fmt, args...) \
debug_cond(DEBUG_PARSER, fmt, ##args)
char console_buffer[CONFIG_SYS_CBSIZE + 1]; /* console I/O buffer */ char console_buffer[CONFIG_SYS_CBSIZE + 1]; /* console I/O buffer */
@ -1179,9 +1183,7 @@ int parse_line (char *line, char *argv[])
{ {
int nargs = 0; int nargs = 0;
#ifdef DEBUG_PARSER debug_parser("parse_line: \"%s\"\n", line);
printf ("parse_line: \"%s\"\n", line);
#endif
while (nargs < CONFIG_SYS_MAXARGS) { while (nargs < CONFIG_SYS_MAXARGS) {
/* skip any white space */ /* skip any white space */
@ -1190,10 +1192,8 @@ int parse_line (char *line, char *argv[])
if (*line == '\0') { /* end of line, no more args */ if (*line == '\0') { /* end of line, no more args */
argv[nargs] = NULL; argv[nargs] = NULL;
#ifdef DEBUG_PARSER debug_parser("parse_line: nargs=%d\n", nargs);
printf ("parse_line: nargs=%d\n", nargs); return nargs;
#endif
return (nargs);
} }
argv[nargs++] = line; /* begin of argument string */ argv[nargs++] = line; /* begin of argument string */
@ -1204,10 +1204,8 @@ int parse_line (char *line, char *argv[])
if (*line == '\0') { /* end of line, no more args */ if (*line == '\0') { /* end of line, no more args */
argv[nargs] = NULL; argv[nargs] = NULL;
#ifdef DEBUG_PARSER debug_parser("parse_line: nargs=%d\n", nargs);
printf ("parse_line: nargs=%d\n", nargs); return nargs;
#endif
return (nargs);
} }
*line++ = '\0'; /* terminate current arg */ *line++ = '\0'; /* terminate current arg */
@ -1215,9 +1213,7 @@ int parse_line (char *line, char *argv[])
printf ("** Too many args (max. %d) **\n", CONFIG_SYS_MAXARGS); printf ("** Too many args (max. %d) **\n", CONFIG_SYS_MAXARGS);
#ifdef DEBUG_PARSER debug_parser("parse_line: nargs=%d\n", nargs);
printf ("parse_line: nargs=%d\n", nargs);
#endif
return (nargs); return (nargs);
} }
@ -1235,12 +1231,10 @@ static void process_macros (const char *input, char *output)
/* 1 = waiting for '(' or '{' */ /* 1 = waiting for '(' or '{' */
/* 2 = waiting for ')' or '}' */ /* 2 = waiting for ')' or '}' */
/* 3 = waiting for ''' */ /* 3 = waiting for ''' */
#ifdef DEBUG_PARSER
char *output_start = output; char *output_start = output;
printf ("[PROCESS_MACROS] INPUT len %d: \"%s\"\n", strlen (input), debug_parser("[PROCESS_MACROS] INPUT len %zd: \"%s\"\n", strlen(input),
input); input);
#endif
prev = '\0'; /* previous character */ prev = '\0'; /* previous character */
@ -1328,10 +1322,8 @@ static void process_macros (const char *input, char *output)
else else
*(output - 1) = 0; *(output - 1) = 0;
#ifdef DEBUG_PARSER debug_parser("[PROCESS_MACROS] OUTPUT len %zd: \"%s\"\n",
printf ("[PROCESS_MACROS] OUTPUT len %d: \"%s\"\n", strlen(output_start), output_start);
strlen (output_start), output_start);
#endif
} }
/**************************************************************************** /****************************************************************************
@ -1362,12 +1354,12 @@ static int builtin_run_command(const char *cmd, int flag)
int repeatable = 1; int repeatable = 1;
int rc = 0; int rc = 0;
#ifdef DEBUG_PARSER debug_parser("[RUN_COMMAND] cmd[%p]=\"", cmd);
printf ("[RUN_COMMAND] cmd[%p]=\"", cmd); if (DEBUG_PARSER) {
puts (cmd ? cmd : "NULL"); /* use puts - string may be loooong */ /* use puts - string may be loooong */
puts ("\"\n"); puts(cmd ? cmd : "NULL");
#endif puts("\"\n");
}
clear_ctrlc(); /* forget any previous Control C */ clear_ctrlc(); /* forget any previous Control C */
if (!cmd || !*cmd) { if (!cmd || !*cmd) {
@ -1385,9 +1377,7 @@ static int builtin_run_command(const char *cmd, int flag)
* repeatable commands * repeatable commands
*/ */
#ifdef DEBUG_PARSER debug_parser("[PROCESS_SEPARATORS] %s\n", cmd);
printf ("[PROCESS_SEPARATORS] %s\n", cmd);
#endif
while (*str) { while (*str) {
/* /*
@ -1416,9 +1406,7 @@ static int builtin_run_command(const char *cmd, int flag)
} }
else else
str = sep; /* no more commands for next pass */ str = sep; /* no more commands for next pass */
#ifdef DEBUG_PARSER debug_parser("token: \"%s\"\n", token);
printf ("token: \"%s\"\n", token);
#endif
/* find macros in this token and replace them */ /* find macros in this token and replace them */
process_macros (token, finaltoken); process_macros (token, finaltoken);