com php-src: - Added initial code for a simple prompt: .gitignore config.m4 phpdbg.c phpdbg_prompt.c phpdbg_prompt.h
| From: | Bob Weinand | Date: | Sun, 10 Nov 2013 01:30:32 +0000 |
| Subject: | com php-src: - Added initial code for a simple prompt: .gitignore config.m4 phpdbg.c phpdbg_prompt.c phpdbg_prompt.h | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-75236@lists.php.net to get a copy of this message | ||
Commit: 612d6b258243968db00a79eab2876a4eaa94aa86
Author: Felipe Pena <felipensp@gmail.com> Sat, 9 Nov 2013 23:30:32 -0200
Parents: 1c7ae5f1a69686eba3acac66f7fe45318befe19d
Branches: PHP-5.6
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=612d6b258243968db00a79eab2876a4eaa94aa86
Log:
- Added initial code for a simple prompt
Changed paths:
M .gitignore
M config.m4
M phpdbg.c
A phpdbg_prompt.c
A phpdbg_prompt.h
Diff:
diff --git a/.gitignore b/.gitignore
index 2969ad7..a9e84f8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,5 +1,5 @@
.libs/
phpdbg
-phpdbg.lo
-phpdbg.o
+*.lo
+*.o
diff --git a/config.m4 b/config.m4
index 94e8727..d2dac4a 100644
--- a/config.m4
+++ b/config.m4
@@ -7,13 +7,13 @@ PHP_ARG_ENABLE(phpdbg, for phpdbg support,
if test "$PHP_PHPDBG" != "no"; then
AC_DEFINE(HAVE_PHPDBG, 1, [ ])
-
+
PHP_PHPDBG_CFLAGS=-I$abs_srcdir/sapi/phpdbg
- PHP_PHPDBG_FILES=phpdbg.c
+ PHP_PHPDBG_FILES="phpdbg.c phpdbg_prompt.c"
- PHP_ADD_MAKEFILE_FRAGMENT([$abs_srcdir/sapi/phpdbg/Makefile.frag])
+ PHP_ADD_MAKEFILE_FRAGMENT([$abs_srcdir/sapi/phpdbg/Makefile.frag])
PHP_SELECT_SAPI(phpdbg, program, $PHP_PHPDBG_FILES, $PHP_PHPDBG_CFLAGS, [$(SAPI_PHPDBG_PATH)])
-
+
BUILD_BINARY="sapi/phpdbg/phpdbg"
BUILD_PHPDBG="\$(LIBTOOL) --mode=link \
\$(CC) -export-dynamic \$(CFLAGS_CLEAN) \$(EXTRA_CFLAGS) \$(EXTRA_LDFLAGS_PROGRAM)
\$(LDFLAGS) \$(PHP_RPATHS) \
diff --git a/phpdbg.c b/phpdbg.c
index 375e4ff..b29a799 100644
--- a/phpdbg..c
+++ b/phpdbg.c
@@ -83,11 +83,6 @@ static sapi_module_struct phpdbg_sapi_module = {
};
/* }}} */
-static inline int zend_machine(int argc, char **argv TSRMLS_DC) /* {{{ */
-{
- php_printf("Hello World :)\n");
-} /* }}} */
-
int main(int argc, char **argv) /* {{{ */
{
sapi_module_struct *phpdbg = &phpdbg_sapi_module;
@@ -124,12 +119,9 @@ int main(int argc, char **argv) /* {{{ */
zend_activate_modules(TSRMLS_C);
} zend_end_try();
- /* START: ZEND INITIALIZED */
- {
- /* do the thing */
- zend_machine(argc, argv TSRMLS_CC);
- }
- /* END: ZEND BLOCK */
+ zend_try {
+ phpdbg_iteractive(argc, argv);
+ } zend_end_try();
if (PG(modules_activated)) {
zend_try {
diff --git a/phpdbg_prompt.c b/phpdbg_prompt.c
new file mode 100644
index 0000000..475cbc3
--- /dev/null
+++ b/phpdbg_prompt.c
@@ -0,0 +1,72 @@
+/*
+ +----------------------------------------------------------------------+
+ | PHP Version 5 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997-2013 The PHP Group |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 3.01 of the PHP license, |
+ | that is bundled with this package in the file LICENSE, and is |
+ | available through the world-wide-web at the following url: |
+ | http://www.php.net/license/3_01.txt
|
+ | If you did not receive a copy of the PHP license and are unable to |
+ | obtain it through the world-wide-web, please send a note to |
+ | license@php.net so we can mail you a copy immediately. |
+ +----------------------------------------------------------------------+
+ | Authors: Felipe Pena <felipe@php.net> |
+ +----------------------------------------------------------------------+
+*/
+
+#include <stdio.h>
+#include <string.h>
+#include "zend.h"
+#include "phpdbg_prompt.h"
+
+void do_quit(const char *params) /* {{{ */
+{
+ zend_bailout();
+} /* }}} */
+
+static const phpdbg_command prompt_commands[] = {
+ {PHPDBG_STRL("quit"), do_quit},
+ {NULL, 0, 0}
+};
+
+static void do_cmd(char *cmd_line) /* {{{ */
+{
+ const phpdbg_command *command = prompt_commands;
+ char *params = NULL;
+ const char *cmd = strtok_r(cmd_line, " ", ¶ms);
+ size_t cmd_len = cmd ? strlen(cmd) : 0;
+
+ while (command && command->name) {
+ if (command->name_len == cmd_len
+ && memcmp(cmd, command->name, cmd_len) == 0) {
+ /* Command find */
+ command->handler(params);
+ return;
+ }
+ ++command;
+ }
+
+ printf("command not found!\n");
+
+} /* }}} */
+
+void phpdbg_iteractive(int argc, char **argv) /* {{{ */
+{
+ char cmd[PHPDBG_MAX_CMD];
+
+ printf("phpdbg> ");
+
+ while (fgets(cmd, PHPDBG_MAX_CMD, stdin) != NULL) {
+ size_t cmd_len = strlen(cmd) - 1;
+
+ if (cmd[cmd_len] == '\n') {
+ cmd[cmd_len] = 0;
+ }
+ if (cmd_len) {
+ do_cmd(cmd);
+ }
+ printf("phpdbg> ");
+ }
+} /* }}} */
diff --git a/phpdbg_prompt.h b/phpdbg_prompt.h
new file mode 100644
index 0000000..0740a94
--- /dev/null
+++ b/phpdbg_prompt..h
@@ -0,0 +1,43 @@
+/*
+ +----------------------------------------------------------------------+
+ | PHP Version 5 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997-2013 The PHP Group |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 3.01 of the PHP license, |
+ | that is bundled with this package in the file LICENSE, and is |
+ | available through the world-wide-web at the following url: |
+ | http://www.php.net/license/3_01.txt
|
+ | If you did not receive a copy of the PHP license and are unable to |
+ | obtain it through the world-wide-web, please send a note to |
+ | license@php.net so we can mail you a copy immediately. |
+ +----------------------------------------------------------------------+
+ | Authors: Felipe Pena <felipe@php.net> |
+ +----------------------------------------------------------------------+
+*/
+
+#ifndef PHPDBG_PROMPT_H
+#define PHPDBG_PROMPT_H
+
+/**
+ * Maximum command length
+ */
+#define PHPDBG_MAX_CMD 500
+
+#define PHPDBG_STRL(s) s, sizeof(s)-1
+
+/**
+ * Command handler
+ */
+typedef void (*phpdbg_command_handler)(const char*);
+
+/**
+ * Command representation
+ */
+typedef struct _phpdbg_command {
+ const char *name; /* Command name */
+ size_t name_len; /* Command name length */
+ phpdbg_command_handler handler; /* Command handler */
+} phpdbg_command;
+
+#endif