From: krakjoe Date: Sun, 23 Feb 2014 07:33:48 +0000 (+0000) Subject: set colors working X-Git-Tag: php-5.6.0beta2~1^2~37^2~20^2~13 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4b738cee2b789228b34bc5ef0f246e325890fd78;p=php set colors working --- diff --git a/phpdbg_cmd.c b/phpdbg_cmd.c index 814939758a..a71c396945 100644 --- a/phpdbg_cmd.c +++ b/phpdbg_cmd.c @@ -551,7 +551,7 @@ PHPDBG_API int phpdbg_stack_verify(const phpdbg_command_t *command, phpdbg_param } asprintf(why, - "%s expected no arguments", + "The command \"%s\" expected no arguments", phpdbg_command_name(command, buffer)); return FAILURE; } @@ -572,7 +572,7 @@ PHPDBG_API int phpdbg_stack_verify(const phpdbg_command_t *command, phpdbg_param #define verify_arg(e, a, t) if (!(a)) { \ if (!optional) { \ asprintf(why, \ - "%s expected %s and got nothing at parameter %lu", \ + "The command \"%s\" expected %s and got nothing at parameter %lu", \ phpdbg_command_name(command, buffer), \ (e), \ current); \ @@ -580,7 +580,7 @@ PHPDBG_API int phpdbg_stack_verify(const phpdbg_command_t *command, phpdbg_param } \ } else if ((a)->type != (t)) { \ asprintf(why, \ - "%s expected %s and got %s at parameter %lu", \ + "The command \"%s\" expected %s and got %s at parameter %lu", \ phpdbg_command_name(command, buffer), \ (e),\ phpdbg_get_param_type((a) TSRMLS_CC), \ @@ -623,7 +623,7 @@ PHPDBG_API int phpdbg_stack_verify(const phpdbg_command_t *command, phpdbg_param if ((received < least)) { asprintf(why, - "%s expected at least %lu arguments (%s) and received %lu", + "The command \"%s\" expected at least %lu arguments (%s) and received %lu", phpdbg_command_name(command, buffer), least, command->args, @@ -676,13 +676,17 @@ PHPDBG_API const phpdbg_command_t* phpdbg_stack_resolve(const phpdbg_command_t * } switch (matches) { - case 0: if (!parent) { - asprintf( + case 0: { + if (parent) { + asprintf( + why, + "The command \"%s %s\" could not be found", + parent->name, name->str); + } else asprintf( why, - "The command %s could not be found", + "The command \"%s\" could not be found", name->str); - return NULL; - } else return parent; + } return parent; case 1: { (*top) = (*top)->next; @@ -718,7 +722,7 @@ PHPDBG_API const phpdbg_command_t* phpdbg_stack_resolve(const phpdbg_command_t * asprintf( why, - "The command %s is ambigious, matching %lu commands (%s)", + "The command \"%s\" is ambigious, matching %lu commands (%s)", name->str, matches, list); free(list); } return NULL; @@ -740,13 +744,13 @@ PHPDBG_API int phpdbg_stack_execute(phpdbg_param_t *stack, char **why) { if (stack->type != STACK_PARAM) { asprintf( - why, "the passed argument was not a stack !!"); + why, "The passed argument was not a stack !!"); return FAILURE; } if (!stack->len) { asprintf( - why, "the stack contains nothing !!"); + why, "The stack contains nothing !!"); return FAILURE; } @@ -772,7 +776,7 @@ PHPDBG_API int phpdbg_stack_execute(phpdbg_param_t *stack, char **why) { default: asprintf( - why, "the first parameter makes no sense !!"); + why, "The first parameter makes no sense !!"); return FAILURE; } diff --git a/phpdbg_help.c b/phpdbg_help.c index e091fb86f6..1796db7f60 100644 --- a/phpdbg_help.c +++ b/phpdbg_help.c @@ -248,8 +248,7 @@ PHPDBG_COMMAND(help) /* {{{ */ } } } - - phpdbg_error("No help can be found for the subject \"%s\"", param->str); + return FAILURE; } /* }}} */ diff --git a/phpdbg_lexer.c b/phpdbg_lexer.c index 730c5fb68c..1feed66ab9 100644 --- a/phpdbg_lexer.c +++ b/phpdbg_lexer.c @@ -360,7 +360,7 @@ struct yy_trans_info }; static yyconst flex_int16_t yy_accept[67] = { 0, - 12, 12, 0, 0, 16, 12, 14, 1, 9, 9, + 0, 0, 0, 0, 16, 12, 14, 1, 9, 9, 3, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 12, 14, 9, 12, 2, 12, 12, 4, 12, 6, 8, 12, 7, 5, 12, 12, 12, diff --git a/phpdbg_prompt.c b/phpdbg_prompt.c index 534d883d9c..c733117b75 100644 --- a/phpdbg_prompt.c +++ b/phpdbg_prompt.c @@ -745,7 +745,7 @@ PHPDBG_COMMAND(info) /* {{{ */ PHPDBG_COMMAND(set) /* {{{ */ { phpdbg_error( - "No information command selected!"); + "No set command selected!"); return SUCCESS; } /* }}} */ @@ -952,7 +952,9 @@ int phpdbg_interactive(TSRMLS_D) /* {{{ */ case FAILURE: if (!(PHPDBG_G(flags) & PHPDBG_IS_QUITTING)) { if (phpdbg_call_register(&stack TSRMLS_CC) == FAILURE) { - phpdbg_error("%s", why); + if (why) { + phpdbg_error("%s", why); + } } } @@ -973,18 +975,18 @@ int phpdbg_interactive(TSRMLS_D) /* {{{ */ } } } - + if (why) { free(why); why = NULL; } - + yy_delete_buffer(state, scanner); yylex_destroy(scanner); - + phpdbg_stack_free(&stack); phpdbg_destroy_input(&input TSRMLS_CC); - + } while ((input = phpdbg_read_input(NULL TSRMLS_CC))); if (!input) @@ -1003,6 +1005,10 @@ out: if (input) { phpdbg_destroy_input(&input TSRMLS_CC); } + + if (why) { + free(why); + } phpdbg_stack_free(&stack); diff --git a/phpdbg_set.c b/phpdbg_set.c index 739acd3c71..fa462e2f18 100644 --- a/phpdbg_set.c +++ b/phpdbg_set.c @@ -102,43 +102,43 @@ PHPDBG_SET(breaks) /* {{{ */ #ifndef _WIN32 PHPDBG_SET(color) /* {{{ */ { - /*if ((param->type == STR_PARAM) && (input->argc == 3)) { - const phpdbg_color_t *color = phpdbg_get_color( - input->argv[2]->string, input->argv[2]->length TSRMLS_CC); - int element = PHPDBG_COLOR_INVALID; - - if (color) { - if (phpdbg_argv_is(1, "prompt")) { - phpdbg_notice( - "setting prompt color to %s (%s)", color->name, color->code); - element = PHPDBG_COLOR_PROMPT; - if (PHPDBG_G(prompt)[1]) { - free(PHPDBG_G(prompt)[1]); - PHPDBG_G(prompt)[1]=NULL; - } - } else if (phpdbg_argv_is(1, "error")) { - phpdbg_notice( - "setting error color to %s (%s)", color->name, color->code); - element = PHPDBG_COLOR_ERROR; - - } else if (phpdbg_argv_is(1, "notice")) { - phpdbg_notice( - "setting notice color to %s (%s)", color->name, color->code); - element = PHPDBG_COLOR_NOTICE; - - } else goto usage; - - phpdbg_set_color(element, color TSRMLS_CC); - } else { - phpdbg_error( - "Failed to find the requested color (%s)", input->argv[2]->string); - } - } else { -usage: + const phpdbg_color_t *color = phpdbg_get_color( + param->next->str, param->next->len TSRMLS_CC); + + if (!color) { phpdbg_error( - "set color used incorrectly: set color "); - } */ + "Failed to find the requested color (%s)", param->next->str); + return SUCCESS; + } + switch (phpdbg_get_element(param->str, param->len TSRMLS_CC)) { + case PHPDBG_COLOR_PROMPT: + phpdbg_notice( + "setting prompt color to %s (%s)", color->name, color->code); + if (PHPDBG_G(prompt)[1]) { + free(PHPDBG_G(prompt)[1]); + PHPDBG_G(prompt)[1]=NULL; + } + phpdbg_set_color(PHPDBG_COLOR_PROMPT, color TSRMLS_CC); + break; + + case PHPDBG_COLOR_ERROR: + phpdbg_notice( + "setting error color to %s (%s)", color->name, color->code); + phpdbg_set_color(PHPDBG_COLOR_ERROR, color TSRMLS_CC); + break; + + case PHPDBG_COLOR_NOTICE: + phpdbg_notice( + "setting notice color to %s (%s)", color->name, color->code); + phpdbg_set_color(PHPDBG_COLOR_NOTICE, color TSRMLS_CC); + break; + + default: + phpdbg_error( + "Failed to find the requested element (%s)", param->str); + } + return SUCCESS; } /* }}} */ diff --git a/phpdbg_utils.c b/phpdbg_utils.c index d64d9ad686..b32fce3478 100644 --- a/phpdbg_utils.c +++ b/phpdbg_utils.c @@ -67,6 +67,14 @@ const static phpdbg_color_t colors[] = { PHPDBG_COLOR_END }; /* }}} */ +/* {{{ */ +const static phpdbg_element_t elements[] = { + PHPDBG_ELEMENT_D("prompt", PHPDBG_COLOR_PROMPT), + PHPDBG_ELEMENT_D("error", PHPDBG_COLOR_ERROR), + PHPDBG_ELEMENT_D("notice", PHPDBG_COLOR_NOTICE), + PHPDBG_ELEMENT_END +}; /* }}} */ + PHPDBG_API int phpdbg_is_numeric(const char *str) /* {{{ */ { if (!str) @@ -349,6 +357,21 @@ PHPDBG_API const phpdbg_color_t* phpdbg_get_colors(TSRMLS_D) /* {{{ */ return colors; } /* }}} */ +PHPDBG_API int phpdbg_get_element(const char *name, size_t len) { + const phpdbg_element_t *element = elements; + + while (element && element->name) { + if (len == element->name_length) { + if (strncasecmp(name, element->name, len) == SUCCESS) { + return element->id; + } + } + element++; + } + + return PHPDBG_COLOR_INVALID; +} + PHPDBG_API void phpdbg_set_prompt(const char *prompt TSRMLS_DC) /* {{{ */ { /* free formatted prompt */ diff --git a/phpdbg_utils.h b/phpdbg_utils.h index ee7ff3f5bd..f2be63be10 100644 --- a/phpdbg_utils.h +++ b/phpdbg_utils.h @@ -85,12 +85,17 @@ PHPDBG_API int phpdbg_rlog(FILE *stream, const char *fmt, ...); {color, sizeof(color)-1, code} #define PHPDBG_COLOR_END \ {NULL, 0L, {0}} +#define PHPDBG_ELEMENT_LEN 3 +#define PHPDBG_ELEMENT_D(name, id) \ + {name, sizeof(name)-1, id} +#define PHPDBG_ELEMENT_END \ + {NULL, 0L, 0} #define PHPDBG_COLOR_INVALID -1 -#define PHPDBG_COLOR_PROMPT 0 -#define PHPDBG_COLOR_ERROR 1 -#define PHPDBG_COLOR_NOTICE 2 -#define PHPDBG_COLORS 3 +#define PHPDBG_COLOR_PROMPT 0 +#define PHPDBG_COLOR_ERROR 1 +#define PHPDBG_COLOR_NOTICE 2 +#define PHPDBG_COLORS 3 typedef struct _phpdbg_color_t { char *name; @@ -98,10 +103,17 @@ typedef struct _phpdbg_color_t { const char code[PHPDBG_COLOR_LEN]; } phpdbg_color_t; +typedef struct _phpdbg_element_t { + char *name; + size_t name_length; + int id; +} phpdbg_element_t; + PHPDBG_API const phpdbg_color_t *phpdbg_get_color(const char *name, size_t name_length TSRMLS_DC); PHPDBG_API void phpdbg_set_color(int element, const phpdbg_color_t *color TSRMLS_DC); PHPDBG_API void phpdbg_set_color_ex(int element, const char *name, size_t name_length TSRMLS_DC); -PHPDBG_API const phpdbg_color_t* phpdbg_get_colors(TSRMLS_D); /* }}} */ +PHPDBG_API const phpdbg_color_t* phpdbg_get_colors(TSRMLS_D); +PHPDBG_API int phpdbg_get_element(const char *name, size_t len TSRMLS_DC); /* }}} */ /* {{{ Prompt Management */ PHPDBG_API void phpdbg_set_prompt(const char* TSRMLS_DC);