]> granicus.if.org Git - php/commitdiff
Fix issue krakjoe/phpdbg#97 - list now appends a newline if there is none
authorBob Weinand <bobwei9@hotmail.com>
Sun, 29 Jun 2014 10:18:39 +0000 (12:18 +0200)
committerBob Weinand <bobwei9@hotmail.com>
Sun, 29 Jun 2014 10:18:39 +0000 (12:18 +0200)
The prompt should always ensure it is on a newline

phpdbg_list.c

index 037c6c38b2a1d749b9210a6aa127109841fa83f2..c74522222437cc274a82913b12b0eb5be2d1ce2c 100644 (file)
@@ -130,7 +130,7 @@ void phpdbg_list_file(const char *filename, long count, long offset, int highlig
        char *opened = NULL;
        char buffer[8096] = {0,};
        long line = 0;
-       
+
        php_stream *stream = NULL;
        
        if (VCWD_STAT(filename, &st) == FAILURE) {
@@ -146,6 +146,8 @@ void phpdbg_list_file(const char *filename, long count, long offset, int highlig
        }
        
        while (php_stream_gets(stream, buffer, sizeof(buffer)) != NULL) {
+               long linelen = strlen(buffer);
+
                ++line;
                
                if (!offset || offset <= line) {
@@ -159,9 +161,13 @@ void phpdbg_list_file(const char *filename, long count, long offset, int highlig
                                        phpdbg_write(">%05ld: %s", line, buffer);
                                }
                        }
+
+                       if (buffer[linelen - 1] != '\n') {
+                               phpdbg_write("\n");
+                       }
                }
-               
-               if ((count + (offset-1)) == line)
+
+               if ((count + (offset - 1)) == line)
                        break;
        }