]> granicus.if.org Git - php/commitdiff
Always add a newline before a warning or a notice
authorBob Weinand <bobwei9@hotmail.com>
Wed, 24 Sep 2014 22:55:17 +0000 (00:55 +0200)
committerBob Weinand <bobwei9@hotmail.com>
Wed, 24 Sep 2014 22:55:17 +0000 (00:55 +0200)
phpdbg.c
phpdbg.h
phpdbg_cmd.c
phpdbg_utils.c

index 1e1642fb761c0fa5c4fc3ffb926a1ec69820da86..e30d35d71fcd7c190a892ef395653b90d78d8e28 100644 (file)
--- a/phpdbg.c
+++ b/phpdbg.c
@@ -63,6 +63,7 @@ static inline void php_phpdbg_globals_ctor(zend_phpdbg_globals *pg) /* {{{ */
        pg->exec = NULL;
        pg->exec_len = 0;
        pg->buffer = NULL;
+       pg->last_was_newline = 1;
        pg->ops = NULL;
        pg->vmret = 0;
        pg->bp_count = 0;
index 2fa2d5093a8959cf6e20ce916cbad2510f422350..f9ca0f2a710fefa270073ab1f1219fb36cb740be 100644 (file)
--- a/phpdbg.h
+++ b/phpdbg.h
@@ -64,7 +64,7 @@
 # include "TSRM.h"
 #endif
 
-#ifdef HAVE_LIBREADLINE
+#ifdef LIBREADLINE
 #   include <readline/readline.h>
 #   include <readline/history.h>
 #endif
@@ -208,6 +208,7 @@ ZEND_BEGIN_MODULE_GLOBALS(phpdbg)
        char *prompt[2];                             /* prompt */
        const phpdbg_color_t *colors[PHPDBG_COLORS]; /* colors */
        char *buffer;                                /* buffer */
+       zend_bool last_was_newline;                  /* check if we don't need to output a newline upon next phpdbg_error or phpdbg_notice */
 
        zend_ulong flags;                            /* phpdbg flags */
 ZEND_END_MODULE_GLOBALS(phpdbg) /* }}} */
index a45513bee6b39012493c5f474d6925567854bd60..8ca56aa25cced7aad72cf361f7a100d30f163c3c 100644 (file)
@@ -816,6 +816,7 @@ disconnect:
                                if (!phpdbg_write("%s", phpdbg_get_prompt(TSRMLS_C))) {
                                        goto disconnect;
                                }
+                               PHPDBG_G(last_was_newline) = 1;
                        }
                        
                        /* note: EOF is ignored */
@@ -836,7 +837,10 @@ readline:
                                if (fgets(buf, PHPDBG_MAX_CMD, PHPDBG_G(io)[PHPDBG_STDIN])) {
                                        cmd = buf;
                                } else goto disconnect;
-                       } else cmd = readline(phpdbg_get_prompt(TSRMLS_C));
+                       } else {
+                               cmd = readline(phpdbg_get_prompt(TSRMLS_C));
+                               PHPDBG_G(last_was_newline) = 1;
+                       }
 
                        if (!cmd) {
                                goto readline;
index 3ce2fade17de7ad2435b76fdcbb7e33c8732678c..22a7b56282507a71aea596069f1a5007f924dac2 100644 (file)
@@ -240,6 +240,10 @@ PHPDBG_API int phpdbg_print(int type TSRMLS_DC, FILE *fp, const char *format, ..
 
        switch (type) {
                case P_ERROR:
+                       if (!PHPDBG_G(last_was_newline)) {
+                               fprintf(fp, "\n");
+                               PHPDBG_G(last_was_newline) = 1;
+                       }
                        if (PHPDBG_G(flags) & PHPDBG_IS_COLOURED) {
                                rc = fprintf(fp,
                                                "\033[%sm[%s]\033[0m\n",
@@ -250,6 +254,10 @@ PHPDBG_API int phpdbg_print(int type TSRMLS_DC, FILE *fp, const char *format, ..
                break;
 
                case P_NOTICE:
+                       if (!PHPDBG_G(last_was_newline)) {
+                               fprintf(fp, "\n");
+                               PHPDBG_G(last_was_newline) = 1;
+                       }
                        if (PHPDBG_G(flags) & PHPDBG_IS_COLOURED) {
                                rc = fprintf(fp,
                                                "\033[%sm[%s]\033[0m\n",
@@ -265,11 +273,13 @@ PHPDBG_API int phpdbg_print(int type TSRMLS_DC, FILE *fp, const char *format, ..
                        } else {
                                rc = fprintf(fp, "\n");
                        }
+                       PHPDBG_G(last_was_newline) = 1;
                } break;
 
                case P_WRITE:
                        if (buffer) {
                                rc = fprintf(fp, "%s", buffer);
+                               PHPDBG_G(last_was_newline) = buffer[strlen(buffer) - 1] == '\n';
                        }
                break;