} /* }}} */
-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];
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));
}
#ifdef HAVE_LIBREADLINE
- if (cmd) {
+ if (!buffered && cmd) {
free(cmd);
}
#endif
}
} /* }}} */
-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;
"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(
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;
-} /* }}} */
/**
* 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);
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++;
{
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) {
}
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 {