diff options
author | oharboe <oharboe@b42882b7-edfa-0310-969c-e2dbd0fdcd60> | 2008-02-28 08:11:18 +0000 |
---|---|---|
committer | oharboe <oharboe@b42882b7-edfa-0310-969c-e2dbd0fdcd60> | 2008-02-28 08:11:18 +0000 |
commit | 0689e3dd6752f45f493eceb3edf040fbc7849846 (patch) | |
tree | 57c2d288e4ea01551e0ea7806957cd1f5a2165dc /src/helper/command.c | |
parent | b70e262867b724f7d265f0c6b206801a29ba284b (diff) |
- Added TARGET_REQ_DEBUGCHAR target_request debugmsg. This
provides a better impeadance match for debug output char fn's, e.g. eCos.
- Line endings are now added at the caller site of command_print*(). command_print()
still adds a line ending
- echo of commands in scripts are now available via debug_level instead of
forced echo
- Added a USER_SAMELINE() for printing without a lineend.
git-svn-id: svn://svn.berlios.de/openocd/trunk@364 b42882b7-edfa-0310-969c-e2dbd0fdcd60
Diffstat (limited to 'src/helper/command.c')
-rw-r--r-- | src/helper/command.c | 47 |
1 files changed, 23 insertions, 24 deletions
diff --git a/src/helper/command.c b/src/helper/command.c index 15cddcdc..3d496b68 100644 --- a/src/helper/command.c +++ b/src/helper/command.c @@ -260,7 +260,7 @@ int parse_line(char *line, char *words[], int max_words) return nwords; } -void command_print(command_context_t *context, char *format, ...) +static void command_printv(command_context_t *context, char *format, va_list ap) { char *buffer = NULL; int n, size = 0; @@ -269,8 +269,6 @@ void command_print(command_context_t *context, char *format, ...) /* process format string */ for (;;) { - va_list ap; - va_start(ap, format); if (!buffer || (n = vsnprintf(buffer, size, format, ap)) >= size) { /* increase buffer until it fits the whole string */ @@ -279,16 +277,13 @@ void command_print(command_context_t *context, char *format, ...) /* gotta free up */ if (buffer) free(buffer); - va_end(ap); return; } buffer = p; - va_end(ap); continue; } - va_end(ap); break; } @@ -300,23 +295,31 @@ void command_print(command_context_t *context, char *format, ...) return; } - p = buffer; + context->output_handler(context, buffer); - /* process lines in buffer */ - do { - char *next = strchr(p, '\n'); - - if (next) - *next++ = 0; + if (buffer) + free(buffer); +} - if (context->output_handler) - context->output_handler(context, p); +void command_print_sameline(command_context_t *context, char *format, ...) +{ + va_list ap; + va_start(ap, format); + command_printv(context, format, ap); + va_end(ap); +} - p = next; - } while (p); +void command_print(command_context_t *context, char *format, ...) +{ + char *t=malloc(strlen(format)+2); + strcpy(t, format); + strcat(t, "\n"); + va_list ap; + va_start(ap, format); + command_printv(context, t, ap); + va_end(ap); + free(t); - if (buffer) - free(buffer); } int find_and_run_command(command_context_t *context, command_t *commands, char *words[], int num_words, int start_word) @@ -396,10 +399,7 @@ int command_run_line(command_context_t *context, char *line) if (*line && (line[0] == '#')) return ERROR_OK; - if (context->echo) - { - command_print(context, "%s", line); - } + DEBUG("%s", line); nwords = parse_line(line, words, sizeof(words) / sizeof(words[0])); @@ -550,7 +550,6 @@ command_context_t* command_init() context->mode = COMMAND_EXEC; context->commands = NULL; context->current_target = 0; - context->echo = 0; context->output_handler = NULL; context->output_handler_priv = NULL; |