From b55057556029d57f34b5a7a139912688ff264099 Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Thu, 29 Mar 2018 23:42:09 -0400 Subject: [PATCH] removed errfn, may need to bring it back later... --- Makefile | 1 + inc/edit.h | 5 ++--- inc/win.h | 2 +- lib/buf.c | 13 +++++-------- lib/view.c | 4 ++-- lib/x11.c | 8 ++++---- tide.c | 11 +++-------- 7 files changed, 18 insertions(+), 26 deletions(-) diff --git a/Makefile b/Makefile index 4d1a0ac..1f30231 100644 --- a/Makefile +++ b/Makefile @@ -77,3 +77,4 @@ tests/pick: tests/pick.o libedit.a # load generate dependencies -include *.d lib/*.d tests/*.d tests/lib/*.d + diff --git a/inc/edit.h b/inc/edit.h index 4b8d67e..8f173a7 100644 --- a/inc/edit.h +++ b/inc/edit.h @@ -46,7 +46,6 @@ typedef struct { Log* redo; /* redo list */ bool modified; /* tracks whether the buffer has been modified */ uint transid; /* tracks the last used transaction id for log entries */ - void (*errfn)(char*); /* callback for error messages */ } Buf; /* cursor/selection representation */ @@ -56,7 +55,7 @@ typedef struct { size_t col; } Sel; -void buf_init(Buf* buf, void (*errfn)(char*)); +void buf_init(Buf* buf); size_t buf_load(Buf* buf, char* path); void buf_reload(Buf* buf); void buf_save(Buf* buf); @@ -122,7 +121,7 @@ enum { DOWN = +1 }; -void view_init(View* view, char* file, void (*errfn)(char*)); +void view_init(View* view, char* file); void view_reload(View* view); size_t view_limitrows(View* view, size_t maxrows, size_t ncols); void view_resize(View* view, size_t nrows, size_t ncols); diff --git a/inc/win.h b/inc/win.h index 4d8b5d5..d07027f 100644 --- a/inc/win.h +++ b/inc/win.h @@ -28,7 +28,7 @@ typedef struct { View view; } Region; -void win_init(KeyBinding* bindings, void (*errfn)(char*)); +void win_init(KeyBinding* bindings); void win_save(char* path); void win_loop(void); void win_quit(void); diff --git a/lib/buf.c b/lib/buf.c index b536139..4362810 100644 --- a/lib/buf.c +++ b/lib/buf.c @@ -22,7 +22,7 @@ static void swaplog(Buf* buf, Log** from, Log** to, Sel* sel); static size_t next_size(size_t curr); static Rune nextrune(Buf* buf, size_t off, int move, bool (*testfn)(Rune)); -void buf_init(Buf* buf, void (*errfn)(char*)) { +void buf_init(Buf* buf) { /* cleanup old data if there is any */ if (buf->bufstart) { free(buf->bufstart); @@ -38,7 +38,6 @@ void buf_init(Buf* buf, void (*errfn)(char*)) { buf->gapend = buf->bufend; buf->undo = NULL; buf->redo = NULL; - buf->errfn = errfn; assert(buf->bufstart); } @@ -65,7 +64,6 @@ size_t buf_load(Buf* buf, char* path) { /* Read the file into the buffer */ while (sb.st_size && (nread = read(fd, buf->gapstart, sb.st_size)) > 0) buf->gapstart += nread, sb.st_size -= nread; - if (nread < 0) buf->errfn("Failed to read file"); } if (fd > 0) close(fd); @@ -81,9 +79,8 @@ size_t buf_load(Buf* buf, char* path) { } void buf_reload(Buf* buf) { - void (*errfn)(char*) = buf->errfn; char* path = buf->path; - buf_init(buf, errfn); + buf_init(buf); buf_load(buf, path); } @@ -109,10 +106,10 @@ void buf_save(Buf* buf) { /* report success or failure */ if (nwrite >= 0) buf->modified = false; - else - buf->errfn("Failed to write file"); + //else + // buf->errfn("Failed to write file"); } else { - buf->errfn("Need a filename: SaveAs "); + //buf->errfn("Need a filename: SaveAs "); } } diff --git a/lib/view.c b/lib/view.c index b099051..e37dab3 100644 --- a/lib/view.c +++ b/lib/view.c @@ -22,7 +22,7 @@ static unsigned scroll_dn(View* view); static void sync_center(View* view, size_t csr); static size_t getoffset(View* view, size_t row, size_t col); -void view_init(View* view, char* file, void (*errfn)(char*)) { +void view_init(View* view, char* file) { if (view->nrows) { for (size_t i = 0; i < view->nrows; i++) free(view->rows[i]); @@ -35,7 +35,7 @@ void view_init(View* view, char* file, void (*errfn)(char*)) { view->sync_center = true; view->prev_csr = 0; /* load the file and jump to the address returned from the load function */ - buf_init(&(view->buffer), errfn); + buf_init(&(view->buffer)); if (file) { size_t pos = buf_load(&(view->buffer), file); if (pos > 0) { diff --git a/lib/x11.c b/lib/x11.c index 4d37618..43ce8b2 100644 --- a/lib/x11.c +++ b/lib/x11.c @@ -130,9 +130,9 @@ char* SearchTerm = NULL; /******************************************************************************/ -void win_init(KeyBinding* bindings, void (*errfn)(char*)) { +void win_init(KeyBinding* bindings) { for (int i = 0; i < SCROLL; i++) - view_init(&(Regions[i].view), NULL, errfn); + view_init(&(Regions[i].view), NULL); x11_init(); CurrFont = x11_font_load(FontString); Regions[SCROLL].clrnor = Colors[ClrScrollNor]; @@ -201,7 +201,7 @@ void win_quit(void) { if (!win_buf(EDIT)->modified || (now-before) <= (uint64_t)ClickTime) exit(0); else - win_buf(EDIT)->errfn("File is modified."); + view_append(win_view(TAGS), "File is modified."); before = now; } @@ -505,7 +505,7 @@ static void xfocus(XEvent* e) { (e->type == FocusIn ? XSetICFocus : XUnsetICFocus)(X.xic); Buf* buf = win_buf(EDIT); if (buf->path && buf->modtime != modtime(buf->path)) - buf->errfn("File modified externally: Get {Put }"); + view_append(win_view(TAGS), "File modified externally: Get {Put }"); } static void xkeypress(XEvent* e) { diff --git a/tide.c b/tide.c index a7b9361..a66f7a7 100644 --- a/tide.c +++ b/tide.c @@ -279,11 +279,6 @@ void exec(char* cmd) { /* Action Callbacks ******************************************************************************/ -static void ondiagmsg(char* msg) { - view_append(win_view(TAGS), msg); - win_setregion(TAGS); -} - static void trim_whitespace(char* arg) { Buf* buf = win_buf(EDIT); if (TrimOnSave && buf_end(buf) > 0) { @@ -322,7 +317,7 @@ static void save(char* arg) { static void get(char* arg) { if (arg) - view_init(win_view(EDIT), arg, ondiagmsg); + view_init(win_view(EDIT), arg); else view_reload(win_view(EDIT)); } @@ -554,11 +549,11 @@ int main(int argc, char** argv) { if (!ShellCmd[0]) ShellCmd[0] = "/bin/sh"; /* create the window */ - win_init(Bindings, ondiagmsg); + win_init(Bindings); x11_window("tide"); /* if we still have args left we're going to open it in this instance */ - if (*argv) view_init(win_view(EDIT), *argv, ondiagmsg); + if (*argv) view_init(win_view(EDIT), *argv); /* now create the window and start the event loop */ win_loop(); -- 2.54.0