Browse Source

- Added phpdbg_trim()

pull/550/head
Felipe Pena 13 years ago
parent
commit
3853f5b370
  1. 54
      phpdbg_cmd.c
  2. 36
      phpdbg_utils.c
  3. 1
      phpdbg_utils.h

54
phpdbg_cmd.c

@ -240,46 +240,36 @@ phpdbg_input_t *phpdbg_read_input(TSRMLS_D) /* {{{ */
add_history(cmd);
#endif
/* strip whitespace */
while (cmd && isspace(*cmd))
cmd++;
cmd_len = strlen(cmd);
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->length = strlen(cmd);
buffer->string = emalloc(buffer->length+1);
if (buffer->string) {
memcpy(
buffer->string, cmd, buffer->length);
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);
if (!buffer) {
return NULL;
}
buffer->argv = phpdbg_read_argv(
store, &buffer->argc TSRMLS_CC);
buffer->string = phpdbg_trim(cmd, strlen(cmd), &buffer->length);
if (buffer->argc) {
int arg = 0;
if (buffer->string) {
/* temporary, when we switch to argv/argc handling
will be unnecessary */
char *store = (char*) estrdup(buffer->string);
while (arg < buffer->argc) {
phpdbg_debug(
"argv %d=%s", arg, buffer->argv[arg]->string);
arg++;
}
}
/* store constant pointer to start of buffer */
buffer->start = (char* const*) buffer->string;
buffer->argv = phpdbg_read_argv(
store, &buffer->argc TSRMLS_CC);
efree(store);
if (buffer->argc) {
int arg = 0;
while (arg < buffer->argc) {
phpdbg_debug(
"argv %d=%s", arg, buffer->argv[arg]->string);
arg++;
}
}
efree(store);
}
#ifdef HAVE_LIBREADLINE

36
phpdbg_utils.c

@ -50,7 +50,7 @@ int phpdbg_is_empty(const char *str) /* {{{ */
{
if (!str)
return 1;
for (; *str; str++) {
if (isspace(*str)) {
continue;
@ -71,7 +71,7 @@ int phpdbg_is_class_method(const char *str, size_t len, char **class, char **met
if (strstr(str, " ") != NULL)
return 0;
sep = strstr(str, "::");
if (!sep || sep == str || sep+2 == str+len-1) {
@ -113,6 +113,36 @@ const char *phpdbg_current_file(TSRMLS_D) /* {{{ */
return file;
} /* }}} */
char *phpdbg_trim(const char *str, size_t len, size_t *new_len) /* {{{ */
{
const char *p = str;
char *new = NULL;
while (p && isspace(*p)) {
++p;
--len;
}
while (*p && isspace(*(p + len-1))) {
--len;
}
if (len == 0) {
*new_len = 0;
return estrndup("", sizeof(""));
}
new = estrndup(p, len);
*(new + len) = '\0';
if (new_len) {
*new_len = len;
}
return new;
} /* }}} */
int phpdbg_print(int type TSRMLS_DC, FILE *fp, const char *format, ...) /* {{{ */
{
int rc = 0;
@ -159,7 +189,7 @@ int phpdbg_print(int type TSRMLS_DC, FILE *fp, const char *format, ...) /* {{{ *
buffer,
((PHPDBG_G(flags) & PHPDBG_IS_COLOURED) ? "\033[0m" : ""));
} break;
/* no formatting on logging output */
case P_LOG: if (buffer) {
struct timeval tp;

1
phpdbg_utils.h

@ -29,6 +29,7 @@ int phpdbg_is_addr(const char*);
int phpdbg_is_class_method(const char*, size_t, char**, char**);
const char *phpdbg_current_file(TSRMLS_D);
char *phpdbg_resolve_path(const char* TSRMLS_DC);
char *phpdbg_trim(const char*, size_t, size_t*);
/**
* Error/notice/formatting helper

Loading…
Cancel
Save