break;
}
}
-
+
} /* }}} */
static inline phpdbg_input_t** phpdbg_read_argv(char *buffer, int *argc TSRMLS_DC) /* {{{ */
{
- char *p, *s;
+ char *p;
char b[PHPDBG_MAX_CMD];
int l=0;
enum states {
IN_BETWEEN,
- IN_WORD,
- IN_STRING
+ IN_WORD,
+ IN_STRING
} state = IN_BETWEEN;
phpdbg_input_t **argv = NULL;
-
+
argv = (phpdbg_input_t**) emalloc(sizeof(phpdbg_input_t**));
(*argc) = 0;
-
+
#define RESET_STATE() do {\
phpdbg_input_t *arg = emalloc(sizeof(phpdbg_input_t));\
if (arg) {\
}
if (c == '"') {
state = IN_STRING;
- s = p + 1;
continue;
}
state = IN_WORD;
- s = p;
b[l++]=c;
continue;
continue;
}
}
-
+
switch (state) {
case IN_WORD: {
RESET_STATE();
} break;
-
+
case IN_STRING:
phpdbg_error(
- "Malformed command line (unclosed quote) @ %d: %s!",
+ "Malformed command line (unclosed quote) @ %d: %s!",
(p - buffer)-1, &buffer[(p - buffer)-1]);
break;
}
-
+
if ((*argc) == 0) {
/* not needed */
efree(argv);
-
+
/* to be sure */
return NULL;
}
-
+
return argv;
} /* }}} */
-phpdbg_input_t* phpdbg_read_input(TSRMLS_D) /* {{{ */
+phpdbg_input_t *phpdbg_read_input(TSRMLS_D) /* {{{ */
{
if (!(PHPDBG_G(flags) & PHPDBG_IS_QUITTING)) {
phpdbg_input_t *buffer = NULL;
#ifndef HAVE_LIBREADLINE
char *cmd = NULL;
- char buf[PHPDBG_MAX_CMD];
+ char buf[PHPDBG_MAX_CMD];
if (!phpdbg_write(PROMPT) ||
!fgets(buf, PHPDBG_MAX_CMD, stdin)) {
/* the user has gone away */
zend_bailout();
return NULL;
}
-
+
cmd = buf;
#else
char *cmd = readline(PROMPT);
while (*cmd && isspace(cmd[cmd_len-1]))
cmd_len--;
cmd[cmd_len] = '\0';
-
+
/* allocate and sanitize buffer */
buffer = (phpdbg_input_t*) emalloc(sizeof(phpdbg_input_t));
if (buffer) {
buffer->string[buffer->length] = '\0';
/* store constant pointer to start of buffer */
buffer->start = (char* const*) buffer->string;
- {
- /* temporary, when we switch to argv/argc handling
+ {
+ /* temporary, when we switch to argv/argc handling
will be unnecessary */
char *store = (char*) estrdup(buffer->string);
-
+
buffer->argv = phpdbg_read_argv(
store, &buffer->argc TSRMLS_CC);
-
+
if (buffer->argc) {
int arg = 0;
-
+
while (arg < buffer->argc) {
phpdbg_debug(
"argv %d=%s", arg, buffer->argv[arg]->string);
arg++;
}
}
-
+
efree(store);
}
}
return buffer;
}
-
+
return NULL;
} /* }}} */
void phpdbg_destroy_input(phpdbg_input_t **input TSRMLS_DC) /*{{{ */
{
if (*input) {
-
+
if ((*input)->string) {
efree((*input)->string);
}
-
+
if ((*input)->argc > 0) {
int arg;
for (arg=0; arg<(*input)->argc; arg++) {
if ((*input)->argv) {
efree((*input)->argv);
}
-
+
efree(*input);
}
} /* }}} */
if (input->argc > 0) {
while (command && command->name && command->handler) {
- if (((command->name_len == input->argv[0]->length) &&
+ if (((command->name_len == input->argv[0]->length) &&
(memcmp(command->name, input->argv[0]->string, command->name_len) == SUCCESS)) ||
(command->alias &&
- (input->argv[0]->length == 1) &&
+ (input->argv[0]->length == 1) &&
(command->alias == *input->argv[0]->string))) {
if (command->subs && input->argc > 1) {
phpdbg_input_t sub;
-
+
sub.argc = input->argc-1;
sub.argv = &input->argv[1];
-
+
return phpdbg_do_cmd_ex(command->subs, &sub TSRMLS_CC);
}
-
+
phpdbg_debug(
- "found command %s for %s with %d arguments",
+ "found command %s for %s with %d arguments",
command->name, input->argv[0]->string, input->argc-1);
{
int arg;
for (arg=1; arg<input->argc; arg++) {
phpdbg_debug(
- "\t#%d: [%s=%d]",
- arg,
+ "\t#%d: [%s=%d]",
+ arg,
input->argv[arg]->string,
input->argv[arg]->length);
}
phpdbg_error(
"No function executed !!");
}
-
+
return rc;
} /* }}} */
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;