]> granicus.if.org Git - php/commitdiff
use new input handling everywhere
authorkrakjoe <joe.watkins@live.co.uk>
Wed, 20 Nov 2013 10:04:05 +0000 (10:04 +0000)
committerkrakjoe <joe.watkins@live.co.uk>
Wed, 20 Nov 2013 10:04:05 +0000 (10:04 +0000)
phpdbg_cmd.c
phpdbg_cmd.h
phpdbg_prompt.c

index 6e03d5b3b24e6c49143a02cac18fdc17e21c681e..d730001cfa99ce173a32c8c60fa2bc2eb76af29f 100644 (file)
@@ -118,7 +118,7 @@ void phpdbg_clear_param(phpdbg_param_t *param TSRMLS_DC) /* {{{ */
 
 } /* }}} */
 
-static inline phpdbg_input_t** phpdbg_read_argv(char *buffer, int *argc TSRMLS_DC) /* {{{ */
+phpdbg_input_t** phpdbg_read_argv(char *buffer, int *argc TSRMLS_DC) /* {{{ */
 {
        char *p;
        char b[PHPDBG_MAX_CMD];
@@ -208,37 +208,39 @@ static inline phpdbg_input_t** phpdbg_read_argv(char *buffer, int *argc TSRMLS_D
        return argv;
 } /* }}} */
 
-phpdbg_input_t *phpdbg_read_input(TSRMLS_D) /* {{{ */
+phpdbg_input_t *phpdbg_read_input(char *buffered TSRMLS_DC) /* {{{ */
 {
-       if (!(PHPDBG_G(flags) & PHPDBG_IS_QUITTING)) {
-               phpdbg_input_t *buffer = NULL;
-               size_t cmd_len = 0L;
+       phpdbg_input_t *buffer = NULL;
+       size_t cmd_len = 0L;
+       char *cmd = NULL;
 
+       if (!(PHPDBG_G(flags) & PHPDBG_IS_QUITTING)) {
+               if (buffered == NULL) {
 #ifndef HAVE_LIBREADLINE
-               char *cmd = NULL;
-               char buf[PHPDBG_MAX_CMD];
-               if (!phpdbg_write(PROMPT) ||
-                       !fgets(buf, PHPDBG_MAX_CMD, stdin)) {
-                       /* the user has gone away */
-                       phpdbg_error("Failed to read console !");
-                       PHPDBG_G(flags) |= PHPDBG_IS_QUITTING;
-                       zend_bailout();
-                       return NULL;
-               }
+                       char buf[PHPDBG_MAX_CMD];
+                       if (!phpdbg_write(PROMPT) ||
+                               !fgets(buf, PHPDBG_MAX_CMD, stdin)) {
+                               /* the user has gone away */
+                               phpdbg_error("Failed to read console !");
+                               PHPDBG_G(flags) |= PHPDBG_IS_QUITTING;
+                               zend_bailout();
+                               return NULL;
+                       }
 
-               cmd = buf;
+                       cmd = buf;
 #else
-               char *cmd = readline(PROMPT);
-               if (!cmd) {
-                       /* the user has gone away */
-                       phpdbg_error("Failed to read console !");
-                       PHPDBG_G(flags) |= PHPDBG_IS_QUITTING;
-                       zend_bailout();
-                       return NULL;
-               }
+                       cmd = readline(PROMPT);
+                       if (!cmd) {
+                               /* the user has gone away */
+                               phpdbg_error("Failed to read console !");
+                               PHPDBG_G(flags) |= PHPDBG_IS_QUITTING;
+                               zend_bailout();
+                               return NULL;
+                       }
 
-               add_history(cmd);
+                       add_history(cmd);
 #endif
+               } else cmd = buffered;
 
                /* allocate and sanitize buffer */
                buffer = (phpdbg_input_t*) emalloc(sizeof(phpdbg_input_t));
@@ -273,7 +275,7 @@ phpdbg_input_t *phpdbg_read_input(TSRMLS_D) /* {{{ */
                }
 
 #ifdef HAVE_LIBREADLINE
-               if (cmd) {
+               if (!buffered && cmd) {
                        free(cmd);
                }
 #endif
@@ -307,7 +309,7 @@ void phpdbg_destroy_input(phpdbg_input_t **input TSRMLS_DC) /*{{{ */
        }
 } /* }}} */
 
-int phpdbg_do_cmd_ex(const phpdbg_command_t *command, phpdbg_input_t *input TSRMLS_DC) /* {{{ */
+int phpdbg_do_cmd(const phpdbg_command_t *command, phpdbg_input_t *input TSRMLS_DC) /* {{{ */
 {
        int rc = FAILURE;
 
@@ -334,13 +336,13 @@ int phpdbg_do_cmd_ex(const phpdbg_command_t *command, phpdbg_input_t *input TSRM
                                                        "trying sub commands in \"%s\" for \"%s\" with %d arguments", 
                                                        command->name, sub.argv[0]->string, sub.argc-1);
                                        
-                                               return phpdbg_do_cmd_ex(command->subs, &sub TSRMLS_CC);
+                                               return phpdbg_do_cmd(command->subs, &sub TSRMLS_CC);
                                        } else {
                                                phpdbg_parse_param(
                                                        input->argv[1]->string,
                                                        input->argv[1]->length,
                                                        &param TSRMLS_CC);
-                                       }       
+                                       }
                                }
                                
                                phpdbg_debug(
@@ -376,51 +378,3 @@ int phpdbg_do_cmd_ex(const phpdbg_command_t *command, phpdbg_input_t *input TSRM
        return rc;
 } /* }}} */
 
-int phpdbg_do_cmd(const phpdbg_command_t *command, char *cmd_line, size_t cmd_len TSRMLS_DC) /* {{{ */
-{
-       int rc = FAILURE;
-       char *expr = NULL;
-#ifndef _WIN32
-       const char *cmd = strtok_r(cmd_line, " ", &expr);
-#else
-       const char *cmd = strtok_s(cmd_line, " ", &expr);
-#endif
-       size_t expr_len = (cmd != NULL) ? strlen(cmd) : 0;
-
-       while (command && command->name && command->handler) {
-               if ((command->name_len == expr_len && memcmp(cmd, command->name, expr_len) == 0)
-                       || (expr_len == 1 && command->alias && command->alias == cmd_line[0])) {
-                       phpdbg_param_t param;
-                       phpdbg_parse_param(
-                               expr,
-                               (cmd_len - expr_len) ? (((cmd_len - expr_len) - sizeof(" "))+1) : 0,
-                               &param TSRMLS_CC);
-
-                       if (command->subs && param.type == STR_PARAM) {
-                               if (phpdbg_do_cmd(command->subs, param.str, param.len TSRMLS_CC) == SUCCESS) {
-                                       rc = SUCCESS;
-                                       goto done;
-                               }
-                       }
-
-                       if (command->arg_type == REQUIRED_ARG && param.type == EMPTY_PARAM) {
-                               phpdbg_error("This command requires argument!");
-                               rc = FAILURE;
-                       } else if (command->arg_type == NO_ARG && param.type != EMPTY_PARAM) {
-                               phpdbg_error("This command does not expect argument!");
-                               rc = FAILURE;
-                       } else {
-                               PHPDBG_G(lcmd) = (phpdbg_command_t*) command;
-                               phpdbg_clear_param(
-                                       &PHPDBG_G(lparam) TSRMLS_CC);
-                               PHPDBG_G(lparam) = param;
-                               rc = command->handler(&param TSRMLS_CC);
-                       }
-                       break;
-               }
-               ++command;
-       }
-
-done:
-       return rc;
-} /* }}} */
index 47ada44902d02b2a2535edf7470ab584ed540530..90aa40aa39166e3afc07df1c0053de8cd01da89d 100644 (file)
@@ -87,9 +87,9 @@ struct _phpdbg_command_t {
 /**
  * Command Executor
  */
-phpdbg_input_t* phpdbg_read_input(TSRMLS_D);
-int phpdbg_do_cmd_ex(const phpdbg_command_t*, phpdbg_input_t *input TSRMLS_DC);
-int phpdbg_do_cmd(const phpdbg_command_t*, char*, size_t TSRMLS_DC);
+phpdbg_input_t* phpdbg_read_input(char *buffered TSRMLS_DC);
+phpdbg_input_t** phpdbg_read_argv(char *buffer, int *argc TSRMLS_DC);
+int phpdbg_do_cmd(const phpdbg_command_t*, phpdbg_input_t *input TSRMLS_DC);
 phpdbg_param_type phpdbg_parse_param(const char*, size_t, phpdbg_param_t* TSRMLS_DC);
 void phpdbg_clear_param(phpdbg_param_t* TSRMLS_DC);
 const char* phpdbg_get_param_type(const phpdbg_param_t* TSRMLS_DC);
index 468cd63a105db17fbf23cbcc89d1468fa3640ee5..366a67a5500cc5cf274186f5555fe704f0d3ac02 100644 (file)
@@ -154,12 +154,17 @@ void phpdbg_init(char *init_file, size_t init_file_len, zend_bool use_default TS
                                                goto next_line;
                                        }
                                        
-                                       switch (phpdbg_do_cmd(phpdbg_prompt_commands, cmd, cmd_len TSRMLS_CC)) {
-                                               case FAILURE:
-                                                       phpdbg_error(
-                                                               "Unrecognized command in %s:%d: %s!", init_file, line, cmd);
-                                               break;
+                                       {
+                                               phpdbg_input_t *input = phpdbg_read_input(cmd TSRMLS_CC);
+                                               switch (phpdbg_do_cmd(phpdbg_prompt_commands, input TSRMLS_CC)) {
+                                                       case FAILURE:
+                                                               phpdbg_error(
+                                                                       "Unrecognized command in %s:%d: %s!", init_file, line, cmd);
+                                                       break;
+                                               }
+                                               phpdbg_destroy_input(&input TSRMLS_CC);
                                        }
+                                       
                                }
 next_line:
                                line++;
@@ -977,11 +982,11 @@ int phpdbg_interactive(TSRMLS_D) /* {{{ */
 {
        int ret = SUCCESS;
 
-       phpdbg_input_t* input = phpdbg_read_input(TSRMLS_C);
+       phpdbg_input_t* input = phpdbg_read_input(NULL TSRMLS_CC);
 
        if (input && input->length > 0L) {
                do {
-                       switch (ret = phpdbg_do_cmd_ex(phpdbg_prompt_commands, input TSRMLS_CC)) {
+                       switch (ret = phpdbg_do_cmd(phpdbg_prompt_commands, input TSRMLS_CC)) {
                                case FAILURE:
                                        if (!(PHPDBG_G(flags) & PHPDBG_IS_QUITTING)) {
                                                if (phpdbg_call_register(input TSRMLS_CC) == FAILURE) {
@@ -1002,9 +1007,9 @@ int phpdbg_interactive(TSRMLS_D) /* {{{ */
                        }
 
                        phpdbg_destroy_input(&input TSRMLS_CC);
-               } while ((input = phpdbg_read_input(TSRMLS_C)) && (input->length > 0L));
+               } while ((input = phpdbg_read_input(NULL TSRMLS_CC)) && (input->length > 0L));
 
-               if (!input->length)
+               if (input && !input->length)
                        goto last;
 
        } else {