From 204a9e063be46f42ad3edcd7cf5c664c86bcf7e2 Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Mon, 17 Sep 2018 16:10:38 -0400 Subject: [PATCH] fixed build errors due to use of non-forward declared symbols --- lib/buf.c | 68 +++++++++++++++++++++++++++---------------------------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/lib/buf.c b/lib/buf.c index efeda37..fe740ce 100644 --- a/lib/buf.c +++ b/lib/buf.c @@ -16,6 +16,39 @@ static size_t pagealign(size_t sz) { return sz; } +static void buf_resize(Buf* buf, size_t sz) { + /* allocate the new buffer and gap */ + Buf copy = *buf; + copy.bufsize = sz; + copy.bufstart = (char*)malloc(copy.bufsize); + copy.bufend = copy.bufstart + copy.bufsize; + copy.gapstart = copy.bufstart; + copy.gapend = copy.bufend; + /* copy the data from the old buffer to the new one */ + for (char* curr = buf->bufstart; curr < buf->gapstart; curr++) + *(copy.gapstart++) = *(curr); + for (char* curr = buf->gapend; curr < buf->bufend; curr++) + *(copy.gapstart++) = *(curr); + /* free the buffer and commit the changes */ + free(buf->bufstart); + memcpy(buf, ©, sizeof(Buf)); +} + +static void buf_syncgap(Buf* buf, size_t off) { + assert(off <= buf_end(buf)); + /* If the buffer is full, resize it before syncing */ + if (0 == (buf->gapend - buf->gapstart)) + buf_resize(buf, buf->bufsize << 1); + /* Move the gap to the desired offset */ + char* newpos = (buf->bufstart + off); + if (newpos < buf->gapstart) + while (newpos < buf->gapstart) + *(--buf->gapend) = *(--buf->gapstart); + else + while (newpos > buf->gapstart) + *(buf->gapstart++) = *(buf->gapend++); +} + static char getb(Buf* buf, size_t off) { if (off >= buf_end(buf)) return '\n'; // TODO: get rid of this hack size_t bsz = (buf->gapstart - buf->bufstart); @@ -89,7 +122,7 @@ void buf_load(Buf* buf, char* path) { buf->status = NORMAL; buf->modtime = (uint64_t)sb.st_mtime; buf_logclear(buf); - + /* use the EOL style of the first line to determine EOL style */ DosLineFeed = (getb(buf, buf_eol(buf, 0)) == '\r'); } @@ -125,39 +158,6 @@ int buf_save(Buf* buf, char* path) { return buf->status; } -static void buf_resize(Buf* buf, size_t sz) { - /* allocate the new buffer and gap */ - Buf copy = *buf; - copy.bufsize = sz; - copy.bufstart = (char*)malloc(copy.bufsize); - copy.bufend = copy.bufstart + copy.bufsize; - copy.gapstart = copy.bufstart; - copy.gapend = copy.bufend; - /* copy the data from the old buffer to the new one */ - for (char* curr = buf->bufstart; curr < buf->gapstart; curr++) - *(copy.gapstart++) = *(curr); - for (char* curr = buf->gapend; curr < buf->bufend; curr++) - *(copy.gapstart++) = *(curr); - /* free the buffer and commit the changes */ - free(buf->bufstart); - memcpy(buf, ©, sizeof(Buf)); -} - -static void buf_syncgap(Buf* buf, size_t off) { - assert(off <= buf_end(buf)); - /* If the buffer is full, resize it before syncing */ - if (0 == (buf->gapend - buf->gapstart)) - buf_resize(buf, buf->bufsize << 1); - /* Move the gap to the desired offset */ - char* newpos = (buf->bufstart + off); - if (newpos < buf->gapstart) - while (newpos < buf->gapstart) - *(--buf->gapend) = *(--buf->gapstart); - else - while (newpos > buf->gapstart) - *(buf->gapstart++) = *(buf->gapend++); -} - static Sel buf_getsel(Buf* buf) { size_t temp; Sel sel = buf->selection; -- 2.49.0