]> khamidou — GitHub mirrors - te.git/commitdiff
fixed an end-of-file bug
authorkhamidou <karim@lambda-expr.org>
Thu, 9 Jul 2009 10:00:43 +0000 (12:00 +0200)
committerkhamidou <karim@lambda-expr.org>
Thu, 9 Jul 2009 10:00:43 +0000 (12:00 +0200)
Makefile
buffer.c
keyb.c
main.c
screen.c
screen.h

index 222c065a25cc561100e74dace71ab24b92515fa7..757b300e68a7a642c55aa958ec825838a7dd2369 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,7 @@
 CC=gcc
-CFLAGS=-c -g
-LDFLAGS=-lcurses
-OBJS=main.o errors.o screen.o buffer.o keyb.o bstrlib.o
+CFLAGS=-c -g `lua-config --include`
+LDFLAGS=-lcurses `lua-config --libs`
+OBJS=main.o errors.o screen.o buffer.o keyb.o bstrlib.o lua-api.o
 
 te: $(OBJS)
        $(CC) $(LDFLAGS) -o te $(OBJS)
@@ -24,6 +24,9 @@ keyb.o: keyb.c
 bstrlib.o: bstrlib.c
        $(CC) $(CFLAGS) bstrlib.c
 
+lua-api.o: lua-api.c
+       $(CC) $(CFLAGS) lua-api.c
+
 clean: 
        rm $(OBJS)
        rm *~
index a0276afa234f16863c91906fa67c025d839855f3..b38ae7ef83b6fb19ffde609d85e7215b0ba49272 100644 (file)
--- a/buffer.c
+++ b/buffer.c
@@ -92,7 +92,7 @@ int screen_line_length(bstring b, int point)
 
        int s_offset = bstrrchrp(b, '\n', max(point - 1, 0));
 
-       for (i = s_offset + 1; bchar(b, i) != '\n'; i++) {
+       for (i = s_offset + 1; bchar(b, i) != '\n' && i < blength(b); i++) {
                if (bchar(b, i) == '\t')
                        count += TAB_LEN;
                else
diff --git a/keyb.c b/keyb.c
index e14c061abae5c042a162884edc234d6c66b25e09..c227ac2a7f5ce9849ed7a55dc2819acbbf55d821 100644 (file)
--- a/keyb.c
+++ b/keyb.c
@@ -29,9 +29,8 @@ void input_loop(void)
                        screen_delete_char(current_buf);
                        break;
 
-               case 'u':
-                       wscrl(buffer_win, -10);
-                       touchwin(stdscr);
+               case 'w':
+                       write_buffer(current_buf);
                        break;
                default:
                        screen_insert_char(current_buf, c);
diff --git a/main.c b/main.c
index 0802e5c24e05e3391b6f7a9b95ac8bdd788946d2..d52a57da45e8d8da9e7b2741146b7633164b2fa2 100644 (file)
--- a/main.c
+++ b/main.c
@@ -13,7 +13,7 @@ int main(int argc, char **argv)
        init_buffers();
        init_windows();
 
-       current_buf = load_buffer("buffer.c");
+       current_buf = load_buffer("README");
        paint_buffer(current_buf);
        refresh();
        input_loop();
index acb7f8192b460e8c0f52b0d4bce4c76ddc1329fc..dcf1acbe1f109158f131353e2d02763cbf906b33 100644 (file)
--- a/screen.c
+++ b/screen.c
@@ -131,13 +131,13 @@ void screen_next_line(struct te_buffer *buf)
        }
 }
 
-void screen_move_left(struct te_buffer *buf)
+int screen_move_left(struct te_buffer *buf)
 {
        if (buf == NULL)
-               return;
+               return ERR;
 
        if(move_left(buf) == ERR)
-               return;
+               return ERR;
        
        if (curr_char(buf) == '\n') {
                        screen_prev_line(buf);
@@ -152,15 +152,16 @@ void screen_move_left(struct te_buffer *buf)
        }
 
        move(buf->y, buf->x);
+       return OK;
 }
 
-void screen_move_right(struct te_buffer *buf)
+int screen_move_right(struct te_buffer *buf)
 {
        if (buf == NULL)
-               return;
+               return ERR;
 
        if (move_right(buf) == ERR) /* last char of the document */
-               return;
+               return ERR;
 
        if (prev_char(buf) == '\n') {
                screen_next_line(buf);
@@ -174,6 +175,7 @@ void screen_move_right(struct te_buffer *buf)
        }
 
        move(buf->y, buf->x);
+       return OK;
 }
 
 void screen_move_up(struct te_buffer *buf)
@@ -186,7 +188,6 @@ void screen_move_up(struct te_buffer *buf)
 
        /* move until the first character of the line */
        while(prev_char(buf) != '\n') {
-
                if(move_left(buf) == ERR)
                        break;
        } 
@@ -194,7 +195,6 @@ void screen_move_up(struct te_buffer *buf)
 
        /* then, move to the beginning of the previous line */
        while(prev_char(buf) != '\n') {
-
                if(move_left(buf) == ERR)
                        break;
        }
@@ -205,7 +205,8 @@ void screen_move_up(struct te_buffer *buf)
        /* mimic emacs' behaviour of moving the user to the exact offset we were on */
                
        while(buf->x < old_x && next_char(buf) != '\n' && curr_char(buf) != '\n') {
-               screen_move_right(buf);
+               if (screen_move_right(buf) == ERR)
+                       break;
        }
 
        move(buf->y, buf->x);
@@ -217,6 +218,9 @@ void screen_move_down(struct te_buffer *buf)
        if (buf == NULL)
                return;
 
+       if (buf->point == blength(buf->contents))
+           return;
+
        int     i = 0;
        int     old_x = buf->x;
 
@@ -231,7 +235,8 @@ void screen_move_down(struct te_buffer *buf)
 
        /* mimic emacs' behaviour of moving the user to the exact offset we were on */
        while (buf->x < old_x && curr_char(buf) != '\n') {
-               screen_move_right(buf);
+               if(screen_move_right(buf) == ERR)
+                       return;
        }
 
        move(buf->y, buf->x);
index 6a3bc4dba7dd4c26cc46595eb64fd78f51367136..96dd6aa2de3491c628527d42917af5ab923f41e9 100644 (file)
--- a/screen.h
+++ b/screen.h
@@ -19,13 +19,14 @@ void draw_line(bstring s, int y);
 
 void scroll_up(struct te_buffer *buf);
 void scroll_down(struct te_buffer *buf);
-void screen_move_left(struct te_buffer *buf);
-void screen_move_right(struct te_buffer *buf);
+int  screen_move_left(struct te_buffer *buf);
+int  screen_move_right(struct te_buffer *buf);
 void screen_move_up(struct te_buffer *buf);
 void screen_move_down(struct te_buffer *buf);
 
 void statusprintf(char *fmt, ...);
 void miniprintf(char *fmt, ...);
+void notifyprintf(char *fmt, ...);
 
 void console_signal_handler(int sig);