]> khamidou — GitHub mirrors - te.git/commitdiff
fixed a bug : when the file didn\'t finish with a \\n, the last line was printed...
authorkhamidou <karim@lambda-expr.org>
Fri, 4 Dec 2009 07:05:01 +0000 (08:05 +0100)
committerkhamidou <karim@lambda-expr.org>
Fri, 4 Dec 2009 07:05:01 +0000 (08:05 +0100)
README
buffer.c
screen.c

diff --git a/README b/README
index eff196ebc8b0bfc6731698dbe1d27bd7b0883acc..852cfc323e772f75d2613ed96593d31cbb2a4a5b 100644 (file)
--- a/README
+++ b/README
@@ -3,4 +3,4 @@ Te, a text editor
 
 
 This is the readme for te, a small text editor that tries to bring some innovation into a field
-that has been left still since the 70's
\ No newline at end of file
+that has been left still since the 70's. The Great Rock'n roll swindle !
\ No newline at end of file
index a60de7af12d4adce83671314707c0f1eea14bcaa..2a0b30629d43595620389770e051aa9b37bd3fdb 100644 (file)
--- a/buffer.c
+++ b/buffer.c
@@ -129,17 +129,24 @@ int screen_line_length(bstring b, int point)
 
 bstring current_line_as_bstring(bstring b, int point)
 {
+       if (point > blength(b) - 1)
+               point = blength(b) - 1;
+
        int s_offset = bstrrchrp(b, '\n', max(point, 0));
        if (s_offset == BSTR_ERR)
                s_offset = 0;
 
        int e_offset = bstrchrp(b, '\n', point + 1);
-       if (e_offset == BSTR_ERR)
+       if (e_offset == BSTR_ERR) {
                e_offset = blength(b);
+       }
 
-       if (s_offset == 0) /* the first line of the file */
+       if (s_offset == 0)      /* the first line of the file */
                return bmidstr(b, s_offset, e_offset - s_offset);
-       else 
+       else if (e_offset == blength(b)) {
+               return bmidstr(b, s_offset + 1, e_offset + 1 - s_offset);
+       }
+       else                    /* otherwise, skip the first '\n' character */
                return bmidstr(b, s_offset + 1, e_offset - s_offset);
 }
 
index 3d03f81ebe2b87564f2c3e7027a498034723f5bb..260ef5b6a7160fb8a88fa112d991e786ae40c144 100644 (file)
--- a/screen.c
+++ b/screen.c
@@ -58,13 +58,14 @@ void paint_buffer_nlines(struct te_buffer *buf, int nlines)
        for(i = 0; i < nlines; i++) {
                s = current_line_as_bstring(buf->contents, count);
                draw_line(s, i);
-               count += blength(s);
+               count += blength(s) + 1;
 
                bdestroy(s);
                if (count >= blength(buf->contents))
                    break;
        }
-       
+
+       miniprintf("count %d", count);
        restoreyx();
        refresh();
 
@@ -192,6 +193,9 @@ void screen_next_line(struct te_buffer *buf)
        else {
                scroll_up(buffer_win);
                bstring s = current_line_as_bstring(buf->contents, buf->point - 1);
+               if (biseq(bfromcstr(""), s))
+                       return;
+
                draw_line(s, LINES - 4);
                bdestroy(s);