]> khamidou — GitHub mirrors - te.git/commitdiff
Clean up the code to have it build on clang.
authorKarim Hamidou <khamidou@gmail.com>
Mon, 23 Jan 2017 00:03:28 +0000 (16:03 -0800)
committerKarim Hamidou <khamidou@gmail.com>
Mon, 23 Jan 2017 00:03:28 +0000 (16:03 -0800)
Makefile
bstrlib.c
buffer.c
buffer.h
errors.h
keyb.c
main.c
screen.c
screen.h

index 2fd6261986d42c55690052fa07ae99b4bbd1e3e7..c662d9ccc7bae637ec7587dbb70e744742a5d5b8 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -27,7 +27,6 @@ interp.o: interp.c
 bstrlib.o: bstrlib.c
        $(CC) $(CFLAGS) bstrlib.c
 
-clean: 
+clean:
        rm $(OBJS)
-       rm *~
-       rm te
\ No newline at end of file
+       rm te
index 44520dad7ea11d735d05137bc3feec110066990d..68fa94d4258103f8a3382005f921553ca212e26d 100644 (file)
--- a/bstrlib.c
+++ b/bstrlib.c
@@ -2736,12 +2736,6 @@ struct genBstrList g;
 #define START_VSNBUFF (256)\r
 #else\r
 \r
-#ifdef __GNUC__\r
-/* Something is making gcc complain about this prototype not being here, so \r
-   I've just gone ahead and put it in. */\r
-extern int vsnprintf (char *buf, size_t count, const char *format, va_list arg);\r
-#endif\r
-\r
 #define exvsnprintf(r,b,n,f,a) {r = vsnprintf (b,n,f,a);}\r
 #endif\r
 #endif\r
index b828f6991d7e78e717dab51eb984b064ae6317d1..b3af6516cbeeb238f36220f79e7091f3ad05896d 100644 (file)
--- a/buffer.c
+++ b/buffer.c
@@ -2,10 +2,12 @@
 #include <curses.h>
 
 #include "zalloc.h"
-#include "error.h"
+#include "errors.h"
 #include "buffer.h"
 #include "interp.h"
 #include "util.h"
+#include "screen.h"
+
 
 void init_buffers(void)
 {
@@ -51,13 +53,15 @@ void free_all_buffers(void)
 struct te_buffer* search_buffer(char *name)
 {
        if (name == NULL)
-               return;
+               return NULL;
 
        struct te_buffer *b;
        TAILQ_FOREACH(b, &buffers_head, buffers) {
                if (strcmp(name, b->name) == 0)
                        return b;
        }
+
+    return NULL;
 }
 
 struct te_buffer* load_buffer(char *filename)
@@ -71,7 +75,7 @@ struct te_buffer* load_buffer(char *filename)
                fail("Unable to allocate memory for buffer contents");
 
        FILE *fp = fopen(filename, "r");
-       
+
        if (fp == NULL) {
                miniprintf("Creating an empty buffer");
        } else {
@@ -108,12 +112,14 @@ int line_length(bstring b, int point)
 int screen_numchar_to_offset(bstring s, int x)
 {
        int i = 0;
-       
+
        for (i = 0; i < x; i++)
                if (bchar(s, i) == '\t')
                        i += TAB_LEN;
                else
                        i += 1;
+
+    return i;
 }
 /*
   The length of a line as displayed on the screen.
@@ -173,7 +179,7 @@ bstring current_line_as_bstring(bstring b, int point)
 int prev_char(struct te_buffer *buf)
 {
        if (buf == NULL)
-               return;
+               return -1;
 
        return bchar(buf->contents, buf->point - 1);
 }
@@ -181,7 +187,7 @@ int prev_char(struct te_buffer *buf)
 int curr_char(struct te_buffer *buf)
 {
        if (buf == NULL)
-               return;
+               return -1;
 
        return bchar(buf->contents, buf->point);
 }
@@ -189,7 +195,7 @@ int curr_char(struct te_buffer *buf)
 int next_char(struct te_buffer *buf)
 {
        if (buf == NULL)
-               return;
+               return -1;
 
        return bchar(buf->contents, buf->point + 1);
 }
@@ -197,7 +203,7 @@ int next_char(struct te_buffer *buf)
 int move_left(struct te_buffer *buf)
 {
        if (buf == NULL)
-               return;
+               return -1;
 
        if (buf->point > 0) {
                buf->point--;
@@ -214,7 +220,7 @@ int move_left(struct te_buffer *buf)
 int move_right(struct te_buffer *buf)
 {
        if (buf == NULL)
-               return;
+               return -1;
 
        if (buf->point < blength(buf->contents)) {
                buf->point++;
index 03d5c8d067aa7799ba462c8f6eccd2e424c77243..322b71d8e34fcbc5077f425b5f4dace51288d159 100644 (file)
--- a/buffer.h
+++ b/buffer.h
@@ -41,5 +41,6 @@ int                           move_left(struct te_buffer *buf);
 void                           insert_char(struct te_buffer *buf, char c);
 void                           delete_char(struct te_buffer *buf);
 int                            is_last_line(bstring s, int point);
+void                write_buffer(struct te_buffer *buf);
 
 #endif
index baf0f4b4ecf1f580a7f326dd25a52a0e9cfc37c4..7efe4283766d4b32db5223b29457f32eb13020fd 100644 (file)
--- a/errors.h
+++ b/errors.h
@@ -4,6 +4,7 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <stdarg.h>
+#include <curses.h>
 
 void fail(char *fmt, ...);
 
diff --git a/keyb.c b/keyb.c
index 22d58153a19d427f0fbb0ee398607de0c56219c6..660e75a5154ea665c190d5c507233073ebdbb423 100644 (file)
--- a/keyb.c
+++ b/keyb.c
@@ -8,11 +8,12 @@ void input_loop(void)
        while(1) {
 
                int c = getch();
-               
-               if (command_mode)
+
+               if (command_mode) {
                        process_command(c);
-               else 
+               } else {
                        process_input(c);
+        }
 
                refresh();
 
diff --git a/main.c b/main.c
index c66cc8875ba6daef1bb5de9e7294a3c72fdf1621..efd8a2fd4aab3ec634dfc93457f9a84e59ed1c2b 100644 (file)
--- a/main.c
+++ b/main.c
@@ -7,6 +7,7 @@
 #include <curses.h>
 #include "interp.h"
 #include "screen.h"
+#include "keyb.h"
 
 void init_interp(void);
 void cmdline_help(void);
@@ -23,9 +24,8 @@ int main(int argc, char **argv)
        init_windows();
        init_buffers();
 
-       for (argv++; *argv != NULL ; argv++) 
+       for (argv++; *argv != NULL ; argv++)
                current_buf = load_buffer(*argv);
-               
 
        paint_buffer(current_buf);
        statusprintf("%s", current_buf->name);
index 41d1f9b6bc701b18beb587bbce2798d995597d66..e0d96283a1b68dff63aaee8d66b4af2366581785 100644 (file)
--- a/screen.c
+++ b/screen.c
@@ -2,6 +2,7 @@
 #include "screen.h"
 #include "util.h"
 #include "keyb.h"
+#include "errors.h"
 
 
 #define saveyx() { int scr_y, scr_x; getyx(stdscr, scr_y, scr_x); do { } while(0)
@@ -120,7 +121,7 @@ void draw_line(bstring s, int y)
        saveyx();
        move(y, 0);
        clrtoeol();
-       
+
        /* FIXME : wrap line if we go beyond COLS */
        for (i = 0; i < blength(s); i++) {
                if (i == COLS - 1) {
@@ -128,7 +129,7 @@ void draw_line(bstring s, int y)
                        goto bail_out;
                        return;
                }
-               
+
                if (bchar(s, i) == '\t') {
                        for (j = 0; j < TAB_LEN; j++)
                                mvwaddch(buffer_win, y, screen_abs++, ' ');
@@ -137,7 +138,7 @@ void draw_line(bstring s, int y)
                        screen_abs++;
                }
        }
-       
+
 bail_out:
        restoreyx();
 }
@@ -216,17 +217,17 @@ int screen_move_left(struct te_buffer *buf)
 
        if(move_left(buf) == ERR)
                return ERR;
-       
        if (curr_char(buf) == '\n') {
                        screen_prev_line(buf);
                        buf->x = screen_line_length(buf->contents, buf->point);
-       } else { 
-               if (buf->x > 0)
+       } else {
+               if (buf->x > 0) {
                        if (curr_char(buf) == '\t') {
                                buf->x -= TAB_LEN;
                        } else {
                                        buf->x--;
                        }
+        }
        }
 
        move(buf->y, buf->x);
@@ -243,7 +244,7 @@ int screen_move_right(struct te_buffer *buf)
 
        if (prev_char(buf) == '\n') {
                screen_next_line(buf);
-       } else { 
+       } else {
                /* tab is the only character larger than 1 */
                        if (prev_char(buf) == '\t') {
                                buf->x += TAB_LEN;
@@ -251,7 +252,7 @@ int screen_move_right(struct te_buffer *buf)
                                buf->x++;
                        }
 
-                       if(buf->x == COLS - 1) { 
+                       if(buf->x == COLS - 1) {
                                bstring s = current_line_as_bstring(buf->contents, buf->point);
                                int off = screen_numchar_to_offset(s, COLS - 1);
                                bstring s2 = bmidstr(s, off, blength(s) - off);
index 71d988fc01e6a835cb83ceab427b3ca2b1635608..56089326698cb943263bbcc73479f82caa80f51f 100644 (file)
--- a/screen.h
+++ b/screen.h
@@ -26,6 +26,8 @@ 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 screen_delete_char(struct te_buffer *buf);
+void screen_insert_char(struct te_buffer *buf, char c);
 
 void statusprintf(char *fmt, ...);
 void miniprintf(char *fmt, ...);