From: krakjoe Date: Tue, 19 Nov 2013 17:18:58 +0000 (+0000) Subject: argc/argv started X-Git-Tag: php-5.6.0alpha1~110^2~199 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8ac46de2cfb5dee208451653022f6bf1dfac2864;p=php argc/argv started --- diff --git a/phpdbg_cmd.c b/phpdbg_cmd.c index e192c2b953..b03aecc246 100644 --- a/phpdbg_cmd.c +++ b/phpdbg_cmd.c @@ -118,6 +118,73 @@ void phpdbg_clear_param(phpdbg_param_t *param TSRMLS_DC) /* {{{ */ } /* }}} */ +static inline phpdbg_input_t** phpdbg_read_argv(char *buffer, int *count TSRMLS_DC) /* {{{ */ +{ + char *p, *s; + enum states { + IN_BETWEEN, + IN_WORD, + IN_STRING + } state = IN_BETWEEN; + phpdbg_input_t **inputs; + + (*count) = 0; + inputs = (phpdbg_input_t**) emalloc( + sizeof(phpdbg_input_t*) * 1); + +#define RESET_STATE() do {\ + phpdbg_input_t *next = emalloc(sizeof(phpdbg_input_t));\ + if (next) {\ + next->string = estrndup(\ + s, ((p-1) - s)+1);\ + inputs[(*count)++] = next;\ + }\ + state = IN_BETWEEN;\ +} while(0); + + for (p = buffer; *p != '\0'; p++) { + int c = (unsigned char) *p; + switch (state) { + case IN_BETWEEN: + if (isspace(c)) { + continue; + } + if (c == '"') { + state = IN_STRING; + s = p + 1; + continue; + } + state = IN_WORD; + s = p; + continue; + + case IN_STRING: + if (c == '"') { + RESET_STATE(); + } + continue; + + case IN_WORD: + if (isspace(c)) { + RESET_STATE(); + } + continue; + } + } + + switch (state) { + case IN_WORD: { + RESET_STATE(); + } break; + + case IN_STRING: + phpdbg_error("Malformed command line !"); + break; + } + + return inputs; +} /* }}} */ + phpdbg_input_t* phpdbg_read_input(TSRMLS_D) /* {{{ */ { if (!(PHPDBG_G(flags) & PHPDBG_IS_QUITTING)) { @@ -169,6 +236,26 @@ phpdbg_input_t* phpdbg_read_input(TSRMLS_D) /* {{{ */ 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 + 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); + } } } diff --git a/phpdbg_cmd.h b/phpdbg_cmd.h index 03fbd0afc8..a8865ced93 100644 --- a/phpdbg_cmd.h +++ b/phpdbg_cmd.h @@ -40,11 +40,16 @@ typedef enum { NUMERIC_PARAM } phpdbg_param_type; -typedef struct { - char* const* start; - char *string; - size_t length; -} phpdbg_input_t; +typedef struct _phpdbg_input_t phpdbg_input_t; + +struct _phpdbg_input_t { + char* const* start; + char *string; + size_t length; + + phpdbg_input_t **argv; + int argc; +}; typedef struct _phpdbg_param { phpdbg_param_type type; diff --git a/phpdbg_prompt.c b/phpdbg_prompt.c index 9a12454e7c..f84ced0a2c 100644 --- a/phpdbg_prompt.c +++ b/phpdbg_prompt.c @@ -690,7 +690,7 @@ static PHPDBG_COMMAND(register) /* {{{ */ phpdbg_notice( "Registered %s", lcname); } else { - phpdbg_error("Failed to find function %s", param->str); + phpdbg_error("The requested function (%s) could not be found", param->str); } } else { phpdbg_error(