]> granicus.if.org Git - php/commitdiff
set colors working
authorkrakjoe <joe.watkins@live.co.uk>
Sun, 23 Feb 2014 07:33:48 +0000 (07:33 +0000)
committerkrakjoe <joe.watkins@live.co.uk>
Sun, 23 Feb 2014 07:33:48 +0000 (07:33 +0000)
phpdbg_cmd.c
phpdbg_help.c
phpdbg_lexer.c
phpdbg_prompt.c
phpdbg_set.c
phpdbg_utils.c
phpdbg_utils.h

index 814939758aa698a7fc319bccfc22c1bbced2afe6..a71c396945833089f26f6c021dd157445623ace4 100644 (file)
@@ -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;
        }
        
index e091fb86f6ece57d01a602a03bc9c57375eeaa33..1796db7f60f7d38abe4f059ac923781d6adcf777 100644 (file)
@@ -248,8 +248,7 @@ PHPDBG_COMMAND(help) /* {{{ */
                        }
                }
        }
-       phpdbg_error("No help can be found for the subject \"%s\"", param->str);
+
        return FAILURE;
 
 } /* }}} */
index 730c5fb68c1bdddf3512dad19f22cac24aa15770..1feed66ab9b3c3060387d7e84db03c4f17911e17 100644 (file)
@@ -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,
index 534d883d9c9c837b9775bc7ccc126d08f8173c53..c733117b75b4d6f19176015d820b16bcab6bb8d8 100644 (file)
@@ -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);
 
index 739acd3c714a3d3af1940393ed242ec36cdc6aa5..fa462e2f182be9c0a7335e44f844b5cb01cd99c9 100644 (file)
@@ -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 <prompt|error|notice> <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;
 } /* }}} */
 
index d64d9ad6860a8e1eda0448da537dd3d2cbbfbf18..b32fce347834a7e12fd2c50abee9c4d2452e1f03 100644 (file)
@@ -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 */
index ee7ff3f5bd19bd50947134fd0318ce79c845b1dc..f2be63be1044e528c02151b2332335546287b419 100644 (file)
@@ -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);