]> khamidou — GitHub mirrors - te.git/commitdiff
some disorganized fixes
authorkhamidou <karim@lambda-expr.org>
Tue, 24 Nov 2009 21:13:25 +0000 (22:13 +0100)
committerkhamidou <karim@lambda-expr.org>
Tue, 24 Nov 2009 21:13:25 +0000 (22:13 +0100)
buffer.c
errors.c
keyb.c
main.c
screen.c

index 4947fe0de4af47f013de1a9ac065a08fe5296af7..a60de7af12d4adce83671314707c0f1eea14bcaa 100644 (file)
--- 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);
 }
 
index c079004a90ac0646e9542dac06d1a98c8619945c..33fcacc552a525f76061fa34e9465264671ffedc 100644 (file)
--- 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 546b07594022340d5236f2f0c67ab6de28d3e1da..19a3e8ab14fbe2fb86f4db90d3568af6bc3be8f8 100644 (file)
--- 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 a3c174edf0397ed4a1d56a9f1b945e24d0cbb01d..85dd87fe3b2492ffe630a55bad229185b16da0e8 100644 (file)
--- a/main.c
+++ b/main.c
@@ -3,30 +3,37 @@
 */
 
 #include <stdio.h>
+#include <stdlib.h>
 #include <curses.h>
 #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);
+}
index b2eba9d7150b6521026154ed6d364a82217cb12e..5149c918b35f23ab60d814d165834ce832c462f4 100644 (file)
--- 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();
 
 }