From: krakjoe Date: Wed, 20 Nov 2013 10:04:05 +0000 (+0000) Subject: use new input handling everywhere X-Git-Tag: php-5.6.0alpha1~110^2~190 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6417e472b4aa73cf760593815e602dde66e818e0;p=php use new input handling everywhere --- diff --git a/phpdbg_cmd.c b/phpdbg_cmd.c index 6e03d5b3b2..d730001cfa 100644 --- a/phpdbg_cmd.c +++ b/phpdbg_cmd.c @@ -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, ¶m 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, - ¶m 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(¶m TSRMLS_CC); - } - break; - } - ++command; - } - -done: - return rc; -} /* }}} */ diff --git a/phpdbg_cmd.h b/phpdbg_cmd.h index 47ada44902..90aa40aa39 100644 --- a/phpdbg_cmd.h +++ b/phpdbg_cmd.h @@ -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); diff --git a/phpdbg_prompt.c b/phpdbg_prompt.c index 468cd63a10..366a67a550 100644 --- a/phpdbg_prompt.c +++ b/phpdbg_prompt.c @@ -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 {