From 50a33a80bb96b94b0db649880a5321d447aa14c4 Mon Sep 17 00:00:00 2001 From: Karim Hamidou Date: Sun, 22 Jan 2017 16:03:28 -0800 Subject: [PATCH] Clean up the code to have it build on clang. --- Makefile | 5 ++--- bstrlib.c | 6 ------ buffer.c | 24 +++++++++++++++--------- buffer.h | 1 + errors.h | 1 + keyb.c | 7 ++++--- main.c | 4 ++-- screen.c | 17 +++++++++-------- screen.h | 2 ++ 9 files changed, 36 insertions(+), 31 deletions(-) diff --git a/Makefile b/Makefile index 2fd6261..c662d9c 100644 --- 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 diff --git a/bstrlib.c b/bstrlib.c index 44520da..68fa94d 100644 --- a/bstrlib.c +++ b/bstrlib.c @@ -2736,12 +2736,6 @@ struct genBstrList g; #define START_VSNBUFF (256) #else -#ifdef __GNUC__ -/* Something is making gcc complain about this prototype not being here, so - I've just gone ahead and put it in. */ -extern int vsnprintf (char *buf, size_t count, const char *format, va_list arg); -#endif - #define exvsnprintf(r,b,n,f,a) {r = vsnprintf (b,n,f,a);} #endif #endif diff --git a/buffer.c b/buffer.c index b828f69..b3af651 100644 --- a/buffer.c +++ b/buffer.c @@ -2,10 +2,12 @@ #include #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++; diff --git a/buffer.h b/buffer.h index 03d5c8d..322b71d 100644 --- 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 diff --git a/errors.h b/errors.h index baf0f4b..7efe428 100644 --- a/errors.h +++ b/errors.h @@ -4,6 +4,7 @@ #include #include #include +#include void fail(char *fmt, ...); diff --git a/keyb.c b/keyb.c index 22d5815..660e75a 100644 --- 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 c66cc88..efd8a2f 100644 --- a/main.c +++ b/main.c @@ -7,6 +7,7 @@ #include #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); diff --git a/screen.c b/screen.c index 41d1f9b..e0d9628 100644 --- 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); diff --git a/screen.h b/screen.h index 71d988f..5608932 100644 --- 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, ...); -- 2.43.0