From: khamidou Date: Thu, 9 Jul 2009 10:00:43 +0000 (+0200) Subject: fixed an end-of-file bug X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=f0b4e8beb54590bd9be1d1bad9e2be3ada4eb0ea;p=te.git fixed an end-of-file bug --- diff --git a/Makefile b/Makefile index 222c065..757b300 100644 --- 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 *~ diff --git a/buffer.c b/buffer.c index a0276af..b38ae7e 100644 --- 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 e14c061..c227ac2 100644 --- 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 0802e5c..d52a57d 100644 --- 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(); diff --git a/screen.c b/screen.c index acb7f81..dcf1acb 100644 --- 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); diff --git a/screen.h b/screen.h index 6a3bc4d..96dd6aa 100644 --- 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);