better call register

This commit is contained in:
krakjoe 2013-11-19 10:56:50 +00:00
parent 7c077f7040
commit 2ebb9e48be

View file

@ -910,43 +910,8 @@ static PHPDBG_COMMAND(list) /* {{{ */
return SUCCESS;
} /* }}} */
int phpdbg_interactive(TSRMLS_D) /* {{{ */
static inline int phpdbg_call_register(const char *cmd, size_t cmd_len, const char * start TSRMLS_DC)
{
size_t cmd_len;
int ret = SUCCESS;
char *start = NULL;
#ifndef HAVE_LIBREADLINE
char cmd[PHPDBG_MAX_CMD];
while (!(PHPDBG_G(flags) & PHPDBG_IS_QUITTING) &&
phpdbg_write(PROMPT) &&
(fgets(cmd, PHPDBG_MAX_CMD, stdin) != NULL)) {
cmd_len = strlen(cmd) - 1;
#else
char *cmd = NULL;
while (!(PHPDBG_G(flags) & PHPDBG_IS_QUITTING)) {
cmd = readline(PROMPT);
cmd_len = cmd ? strlen(cmd) : 0;
#endif
start = estrndup(cmd, cmd_len);
/* trim space from end of input */
while (*cmd && isspace(cmd[cmd_len-1]))
cmd_len--;
/* ensure string is null terminated */
cmd[cmd_len] = '\0';
if (*cmd && cmd_len > 0L) {
#ifdef HAVE_LIBREADLINE
add_history(cmd);
#endif
switch (ret = phpdbg_do_cmd(phpdbg_prompt_commands, cmd, cmd_len TSRMLS_CC)) {
case FAILURE:
if (!(PHPDBG_G(flags) & PHPDBG_IS_QUITTING)) {
size_t offset = strlen(cmd)+(sizeof(" ")-1);
if (zend_hash_exists(&PHPDBG_G(registered), cmd, strlen(cmd))) {
@ -988,7 +953,51 @@ int phpdbg_interactive(TSRMLS_D) /* {{{ */
fretval, 0 TSRMLS_CC);
phpdbg_writeln(EMPTY);
}
} else {
return SUCCESS;
}
return FAILURE;
}
int phpdbg_interactive(TSRMLS_D) /* {{{ */
{
size_t cmd_len;
int ret = SUCCESS;
char* const* start;
#ifndef HAVE_LIBREADLINE
char cmd[PHPDBG_MAX_CMD];
while (!(PHPDBG_G(flags) & PHPDBG_IS_QUITTING) &&
phpdbg_write(PROMPT) &&
(fgets(cmd, PHPDBG_MAX_CMD, stdin) != NULL)) {
cmd_len = strlen(cmd) - 1;
#else
char *cmd = NULL;
while (!(PHPDBG_G(flags) & PHPDBG_IS_QUITTING)) {
cmd = readline(PROMPT);
cmd_len = cmd ? strlen(cmd) : 0;
#endif
start = (char* const*) cmd;
/* trim space from end of input */
while (*cmd && isspace(cmd[cmd_len-1]))
cmd_len--;
/* ensure string is null terminated */
cmd[cmd_len] = '\0';
if (*cmd && cmd_len > 0L) {
#ifdef HAVE_LIBREADLINE
add_history(cmd);
#endif
switch (ret = phpdbg_do_cmd(phpdbg_prompt_commands, cmd, cmd_len TSRMLS_CC)) {
case FAILURE:
if (!(PHPDBG_G(flags) & PHPDBG_IS_QUITTING)) {
if (phpdbg_call_register(cmd, cmd_len, (const char*) start TSRMLS_CC) == FAILURE) {
phpdbg_error("Failed to execute %s!", cmd);
}
}
@ -1001,9 +1010,6 @@ int phpdbg_interactive(TSRMLS_D) /* {{{ */
if (!EG(in_execution)) {
phpdbg_error("Not running");
}
if (start) {
efree(start);
}
goto out;
}
}
@ -1015,20 +1021,12 @@ int phpdbg_interactive(TSRMLS_D) /* {{{ */
}
#endif
} else {
if (start) {
efree(start);
}
if (PHPDBG_G(lcmd)) {
ret = PHPDBG_G(lcmd)->handler(
&PHPDBG_G(lparam) TSRMLS_CC);
goto out;
}
}
if (start) {
efree(start);
}
}
out: