com php-src: - Added phpdbg_trim(): phpdbg_cmd.c phpdbg_utils.c phpdbg_utils.h
| From: | Bob Weinand | Date: | Tue, 19 Nov 2013 21:26:40 +0000 |
| Subject: | com php-src: - Added phpdbg_trim(): phpdbg_cmd.c phpdbg_utils.c phpdbg_utils.h | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-74791@lists.php.net to get a copy of this message | ||
Commit: 3853f5b370c4b8f741e427eb0000dbef01c08dad
Author: Felipe Pena <felipensp@gmail.com> Tue, 19 Nov 2013 19:26:40 -0200
Parents: dee048c22ac885f3447b6c02c492550573e65680
Branches: PHP-5.6
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=3853f5b370c4b8f741e427eb0000dbef01c08dad
Log:
- Added phpdbg_trim()
Changed paths:
M phpdbg_cmd.c
M phpdbg_utils.c
M phpdbg_utils.h
Diff:
diff --git a/phpdbg_cmd.c b/phpdbg_cmd.c
index 3ba736d..f6a15b4 100644
--- a/phpdbg_cmd.c
+++ b/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
diff --git a/phpdbg_utils.c b/phpdbg_utils.c
index 0828374..4fabd8a 100644
--- a/phpdbg_utils.c
+++ b/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;
diff --git a/phpdbg_utils.h b/phpdbg_utils.h
index 3de4010..0a6ad4f 100644
--- a/phpdbg_utils.h
+++ b/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