com php-src: implement init file and command line options: phpdbg.c phpdbg_prompt.c phpdbg_prompt.h
| From: | Bob Weinand | Date: | Thu, 14 Nov 2013 16:58:50 +0000 |
| Subject: | com php-src: implement init file and command line options: phpdbg.c phpdbg_prompt.c phpdbg_prompt.h | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-74968@lists.php.net to get a copy of this message | ||
Commit: 1ee3950747df0ac9dfc73fb7ad24c937263e9939
Author: krakjoe <joe.watkins@live.co.uk> Thu, 14 Nov 2013 16:58:50 +0000
Parents: 1544562b49b17a365d96b3fb358645ef20774276
Branches: PHP-5.6
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=1ee3950747df0ac9dfc73fb7ad24c937263e9939
Log:
implement init file and command line options
Changed paths:
M phpdbg.c
M phpdbg_prompt.c
M phpdbg_prompt.h
Diff:
diff --git a/phpdbg.c b/phpdbg.c
index 207e4ca..7eabfe9 100644
--- a/phpdbg.c
+++ b/phpdbg.c
@@ -297,6 +297,7 @@ const opt_struct OPTIONS[] = { /* {{{ */
{'s', 0, "step"},
{'b', 0, "boring colours"},
{'i', 1, "init"},
+ {'I', 0, "ignore-init"},
{'-', 0, NULL}
}; /* }}} */
@@ -331,6 +332,7 @@ int main(int argc, char **argv) /* {{{ */
size_t exec_len;
char *init_file;
size_t init_file_len;
+ zend_bool init_file_default;
zend_ulong flags;
char *php_optarg;
int php_optind;
@@ -361,6 +363,7 @@ phpdbg_main:
exec_len = 0;
init_file = NULL;
init_file_len = 0;
+ init_file_default = 1;
flags = PHPDBG_DEFAULT_FLAGS;
php_optarg = NULL;
php_optind = 1;
@@ -417,6 +420,10 @@ phpdbg_main:
}
break;
+ case 'I': { /* ignore .phpdbginit */
+ init_file_default = 0;
+ } break;
+
case 'i': /* set init file */
init_file_len = strlen(php_optarg);
if (init_file_len) {
@@ -487,7 +494,7 @@ phpdbg_main:
} zend_end_try();
/* initialize from file */
- phpdbg_init(init_file, init_file_len TSRMLS_CC);
+ phpdbg_init(init_file, init_file_len, init_file_default TSRMLS_CC);
/* print blurb */
phpdbg_welcome(cleaning TSRMLS_CC);
diff --git a/phpdbg_prompt.c b/phpdbg_prompt.c
index dd0c3a2..e8d6156 100644
--- a/phpdbg_prompt.c
+++ b/phpdbg_prompt.c
@@ -71,11 +71,54 @@ static const phpdbg_command_t phpdbg_prompt_commands[] = {
ZEND_EXTERN_MODULE_GLOBALS(phpdbg);
-void phpdbg_init(char *init_file, size_t init_file_len TSRMLS_DC) /* {{{ */
+void phpdbg_init(char *init_file, size_t init_file_len, zend_bool use_default TSRMLS_DC) /* {{{ */
{
+ zend_bool init_default = 0;
+
+ if (!init_file && use_default) {
+ struct stat sb;
+
+ if (VCWD_STAT(".phpdbginit", &sb) != -1) {
+ init_file = ".phpdbginit";
+ init_file_len = strlen(".phpdbginit");
+ init_default = 1;
+ }
+ }
+
if (init_file) {
+ FILE *fp = fopen(init_file, "r");
+ if (fp) {
+ char cmd[PHPDBG_MAX_CMD];
+ size_t cmd_len = 0L;
+ int line = 1;
+
+ while (fgets(cmd, PHPDBG_MAX_CMD, fp) != NULL) {
+ cmd_len = strlen(cmd)-1;
+
+ while (*cmd && isspace(cmd[cmd_len-1]))
+ cmd_len--;
+
+ cmd[cmd_len] = '\0';
+
+ if (*cmd && cmd_len > 0L && cmd[0] != '#') {
+ switch (phpdbg_do_cmd(phpdbg_prompt_commands, cmd, cmd_len TSRMLS_CC)) {
+ case FAILURE:
+ phpdbg_error(
+ "Unrecognized command in %s:%d: %s!", init_file, line, cmd);
+ break;
+ }
+ }
+ line++;
+ }
+ fclose(fp);
+ } else {
+ phpdbg_error(
+ "Failed to open %s for initialization", init_file);
+ }
- free(init_file);
+ if (!init_default) {
+ free(init_file);
+ }
}
} /* }}} */
diff --git a/phpdbg_prompt.h b/phpdbg_prompt.h
index 2ffe672..1f6afc2 100644
--- a/phpdbg_prompt.h
+++ b/phpdbg_prompt.h
@@ -61,7 +61,7 @@ int phpdbg_do_cmd(const phpdbg_command_t *command, char *cmd_line, size_t cmd_le
#define PHPDBG_COMMAND(name) \
int phpdbg_do_##name(const char *expr, size_t expr_len TSRMLS_DC)
-void phpdbg_init(char *init_file, size_t init_file_len TSRMLS_DC);
+void phpdbg_init(char *init_file, size_t init_file_len, zend_bool use_default TSRMLS_DC);
void phpdbg_welcome(zend_bool cleaning TSRMLS_DC);
int phpdbg_interactive(TSRMLS_D);
void phpdbg_execute_ex(zend_execute_data *execute_data TSRMLS_DC);