]> granicus.if.org Git - php/commitdiff
...
authorkrakjoe <joe.watkins@live.co.uk>
Fri, 22 Nov 2013 16:15:24 +0000 (16:15 +0000)
committerkrakjoe <joe.watkins@live.co.uk>
Fri, 22 Nov 2013 16:15:24 +0000 (16:15 +0000)
phpdbg.c
phpdbg.h
phpdbg_cmd.c
phpdbg_utils.h

index 27fedee9b45d8c8fd3b9c739019164b8a8e08c8b..f15f49f589a72bb3f543b2d22a59e44e40fb83b6 100644 (file)
--- a/phpdbg.c
+++ b/phpdbg.c
@@ -44,6 +44,9 @@ static inline void php_phpdbg_globals_ctor(zend_phpdbg_globals *pg) /* {{{ */
     pg->lcmd = NULL;
     pg->flags = PHPDBG_DEFAULT_FLAGS;
     pg->oplog = NULL;
+    pg->io[PHPDBG_STDIN] = NULL;
+    pg->io[PHPDBG_STDOUT] = NULL;
+    pg->io[PHPDBG_STDERR] = NULL;
     memset(&pg->lparam, 0, sizeof(phpdbg_param_t));
 } /* }}} */
 
@@ -339,7 +342,9 @@ static inline int php_sapi_phpdbg_ub_write(const char *message, unsigned int len
 
 static inline void php_sapi_phpdbg_flush(void *context)  /* {{{ */
 {
-       fflush(stdout);
+       TSRMLS_FETCH();
+       
+       fflush(PHPDBG_G(io)[PHPDBG_STDOUT]);
 } /* }}} */
 
 /* {{{ sapi_module_struct phpdbg_sapi_module
@@ -636,6 +641,11 @@ phpdbg_main:
 
                PG(modules_activated) = 0;
 
+               /* set up basic io here */
+               PHPDBG_G(io)[PHPDBG_STDIN] = stdin;
+               PHPDBG_G(io)[PHPDBG_STDOUT] = stdout;
+               PHPDBG_G(io)[PHPDBG_STDERR] = stderr;
+
         if (exec) { /* set execution context */
             PHPDBG_G(exec) = phpdbg_resolve_path(
                 exec TSRMLS_CC);
index 1cff51ee9f6bf9525c05aeacf14b8d4eebccad96..aa6c7ca7c2d32108ac9daff4ff1eb02d51d77594 100644 (file)
--- a/phpdbg.h
+++ b/phpdbg.h
 #define PHPDBG_ISSUES "http://github.com/krakjoe/phpdbg/issues"
 #define PHPDBG_VERSION "0.0.2-dev" /* }}} */
 
+/* {{{ output descriptors */
+#define PHPDBG_STDIN                   0
+#define PHPDBG_STDOUT                  1
+#define PHPDBG_STDERR                  2 /* }}} */
+
 /* {{{ structs */
 ZEND_BEGIN_MODULE_GLOBALS(phpdbg)
     HashTable bp[PHPDBG_BREAK_TABLES];  /* break points */
@@ -127,6 +132,7 @@ ZEND_BEGIN_MODULE_GLOBALS(phpdbg)
        HashTable seek;                                         /* seek oplines */
        zend_ulong flags;                   /* phpdbg flags */
        HashTable registered;                           /* registered */
+       FILE *io[3];                                            /* stdin/stdout/stderr */
 ZEND_END_MODULE_GLOBALS(phpdbg) /* }}} */
 
 #endif /* PHPDBG_H */
index 75b55dfb693e9a1d013fd649d4b8630167923ebf..28f085e8dbaab13e915d5055889ef29d938e03d7 100644 (file)
@@ -218,7 +218,7 @@ phpdbg_input_t *phpdbg_read_input(char *buffered TSRMLS_DC) /* {{{ */
 #ifndef HAVE_LIBREADLINE
                        char buf[PHPDBG_MAX_CMD];
                        if (!phpdbg_write(PROMPT) ||
-                               !fgets(buf, PHPDBG_MAX_CMD, stdin)) {
+                               !fgets(buf, PHPDBG_MAX_CMD, PHPDBG_G(io)[PHPDBG_STDIN])) {
                                /* the user has gone away */
                                phpdbg_error("Failed to read console !");
                                PHPDBG_G(flags) |= PHPDBG_IS_QUITTING;
index 0a6ad4f4fa8416664b55ca96ac1abe12deb55ab4..1178dcace865303fc301ed6920117e59ab91ca1a 100644 (file)
@@ -44,11 +44,11 @@ enum {
 
 int phpdbg_print(int TSRMLS_DC, FILE*, const char*, ...);
 
-#define phpdbg_error(fmt, ...)              phpdbg_print(P_ERROR   TSRMLS_CC, stdout, fmt, ##__VA_ARGS__)
-#define phpdbg_notice(fmt, ...)             phpdbg_print(P_NOTICE  TSRMLS_CC, stdout, fmt, ##__VA_ARGS__)
-#define phpdbg_writeln(fmt, ...)            phpdbg_print(P_WRITELN TSRMLS_CC, stdout, fmt, ##__VA_ARGS__)
-#define phpdbg_write(fmt, ...)              phpdbg_print(P_WRITE   TSRMLS_CC, stdout, fmt, ##__VA_ARGS__)
-#define phpdbg_log(fmt, ...)                phpdbg_print(P_LOG     TSRMLS_CC, stdout, fmt, ##__VA_ARGS__)
+#define phpdbg_error(fmt, ...)              phpdbg_print(P_ERROR   TSRMLS_CC, PHPDBG_G(io)[PHPDBG_STDOUT], fmt, ##__VA_ARGS__)
+#define phpdbg_notice(fmt, ...)             phpdbg_print(P_NOTICE  TSRMLS_CC, PHPDBG_G(io)[PHPDBG_STDOUT], fmt, ##__VA_ARGS__)
+#define phpdbg_writeln(fmt, ...)            phpdbg_print(P_WRITELN TSRMLS_CC, PHPDBG_G(io)[PHPDBG_STDOUT], fmt, ##__VA_ARGS__)
+#define phpdbg_write(fmt, ...)              phpdbg_print(P_WRITE   TSRMLS_CC, PHPDBG_G(io)[PHPDBG_STDOUT], fmt, ##__VA_ARGS__)
+#define phpdbg_log(fmt, ...)                phpdbg_print(P_LOG     TSRMLS_CC, PHPDBG_G(io)[PHPDBG_STDOUT], fmt, ##__VA_ARGS__)
 
 #define phpdbg_error_ex(out, fmt, ...)      phpdbg_print(P_ERROR   TSRMLS_CC, out, fmt, ##__VA_ARGS__)
 #define phpdbg_notice_ex(out, fmt, ...)     phpdbg_print(P_NOTICE  TSRMLS_CC, out, fmt, ##__VA_ARGS__)
@@ -57,7 +57,7 @@ int phpdbg_print(int TSRMLS_DC, FILE*, const char*, ...);
 #define phpdbg_log_ex(out, fmt, ...)        phpdbg_print(P_LOG     TSRMLS_CC, out, fmt, ##__VA_ARGS__)
 
 #if PHPDBG_DEBUG
-#   define phpdbg_debug(fmt, ...)           phpdbg_print(P_LOG   TSRMLS_CC, stderr, fmt, ##__VA_ARGS__)
+#   define phpdbg_debug(fmt, ...)           phpdbg_print(P_LOG   TSRMLS_CC, PHPDBG_G(io)[PHPDBG_STDERR], fmt, ##__VA_ARGS__)
 #else
 #   define phpdbg_debug(fmt, ...)
 #endif