From: khamidou Date: Tue, 24 Nov 2009 21:13:25 +0000 (+0100) Subject: some disorganized fixes X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=282b708cf446bd7fd2c92f549602e7d1ef9c4745;p=te.git some disorganized fixes --- diff --git a/buffer.c b/buffer.c index 4947fe0..a60de7a 100644 --- a/buffer.c +++ b/buffer.c @@ -62,11 +62,7 @@ struct te_buffer* search_buffer(char *name) struct te_buffer* load_buffer(char *filename) { - FILE *fp = fopen(filename, "r"); - - if (fp == NULL) - fail("Unable to open %s", filename); - + struct te_buffer *b = alloc_and_insert_buffer(); b->name = strdup(filename); @@ -74,10 +70,16 @@ struct te_buffer* load_buffer(char *filename) if (b->contents == NULL) fail("Unable to allocate memory for buffer contents"); - if (breada(b->contents, (bNread) &fread, fp) != 0) - fail("Unable to read file contents"); + FILE *fp = fopen(filename, "r"); - statusprintf("%s", filename); + if (fp == NULL) { + miniprintf("Creating an empty buffer"); + } else { + if (breada(b->contents, (bNread) &fread, fp) != 0) + fail("Unable to read file contents"); + + fclose(fp); + } return b; } @@ -256,6 +258,7 @@ void write_buffer(struct te_buffer *buf) fwrite(c, strlen(c), sizeof(char), fp); + fclose(fp); free(c); } diff --git a/errors.c b/errors.c index c079004..33fcacc 100644 --- a/errors.c +++ b/errors.c @@ -7,7 +7,7 @@ void fail(char *fmt, ...) va_start(ap, fmt); vfprintf(stderr, fmt, ap); va_end(ap); - + puts(""); fflush(stdout); exit(EXIT_FAILURE); } diff --git a/keyb.c b/keyb.c index 546b075..19a3e8a 100644 --- a/keyb.c +++ b/keyb.c @@ -6,6 +6,7 @@ char *str; void input_loop(void) { while(1) { + int c = getch(); if (command_mode) diff --git a/main.c b/main.c index a3c174e..85dd87f 100644 --- a/main.c +++ b/main.c @@ -3,30 +3,37 @@ */ #include +#include #include #include "interp.h" #include "screen.h" void init_interp(void); +void cmdline_help(void); extern struct te_buffer *current_buf; int main(int argc, char **argv) { init_buffers(); - init_windows(); - if (argc != 1) - current_buf = load_buffer(argv[1]); + if (argc > 1) + for (argv++; *argv != NULL ; argv++) + current_buf = load_buffer(*argv); else - current_buf = load_buffer("tests/bufferfuncs.c"); + cmdline_help(); - load_buffer("README"); - load_buffer("main.c"); - + init_windows(); paint_buffer(current_buf); + statusprintf("%s", current_buf->name); + refresh(); input_loop(); } +void cmdline_help(void) +{ + puts("te file1 file2"); + exit(EXIT_SUCCESS); +} diff --git a/screen.c b/screen.c index b2eba9d..5149c91 100644 --- a/screen.c +++ b/screen.c @@ -126,7 +126,11 @@ void draw_line(bstring s, int y) /* mvwaddstr(buffer_win, y, screen_abs++, "\\n"); */ /* screen_abs++; */ /* mvwaddch(buffer_win, y, screen_abs++, '\n'); */ -/* } */ else { + /* } */ + else if (i == COLS - 1) { + mvwaddch(buffer_win, y, screen_abs, '\\'); + screen_next_line(current_buf); + } else { mvwaddch(buffer_win, y, screen_abs, bchar(s, i)); screen_abs++; } @@ -360,7 +364,7 @@ void screen_delete_char(struct te_buffer *buf) buf->x = screen_line_length(s, 0); move(buf->y, buf->x); } else { - bstring s = current_line_as_bstring(buf->contents, buf->point); + bstring s = current_line_as_bstring(buf->contents, buf->point - 1); draw_line(s, buf->y); screen_move_left(buf); move_right(buf); /* yes it's ugly but I don't feel like recoding screen_move_right atm */ @@ -412,7 +416,6 @@ void statusprintf(char *fmt, ...) } wrefresh(status_win); - restoreyx(); }