From d46e4a60a994dcbaa6ba0fa3fc17fa04142021f5 Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Mon, 26 Mar 2018 14:27:43 -0400 Subject: [PATCH] Removed RUNE_CRLF --- inc/utf.h | 1 - lib/buf.c | 31 +++++++------------------------ lib/utf8.c | 2 +- lib/view.c | 23 +++++++---------------- lib/x11.c | 4 ---- tide.c | 2 +- 6 files changed, 16 insertions(+), 47 deletions(-) diff --git a/inc/utf.h b/inc/utf.h index b057363..3a8a74e 100644 --- a/inc/utf.h +++ b/inc/utf.h @@ -4,7 +4,6 @@ enum { RUNE_ERR = 0xFFFD, /* rune value representing an error */ RUNE_MAX = 0x10FFFF, /* Maximum decodable rune value */ RUNE_EOF = -1, /* rune value representing end of file */ - RUNE_CRLF = -2, /* rune value representing a \r\n sequence */ }; /* Represents a unicode code point */ diff --git a/lib/buf.c b/lib/buf.c index b712569..cc78016 100644 --- a/lib/buf.c +++ b/lib/buf.c @@ -90,17 +90,8 @@ void buf_save(Buf* buf) { if (buf->path) { FMap file = mmap_readwrite(buf->path, buf_end(buf) * UTF_MAX); if (file.buf) { - for (size_t i = 0, end = buf_end(buf); i < end; i++) { - Rune r = buf_get(buf, i); - if (r == RUNE_CRLF) { - file.buf[wrlen++] = '\r'; - file.buf[wrlen++] = '\n'; - } else if (buf->charset == BINARY) { - file.buf[wrlen++] = (char)r; - } else { - wrlen += utf8encode((char*)&(file.buf[wrlen]), r); - } - } + for (size_t i = 0, end = buf_end(buf); i < end; i++) + file.buf[wrlen++] = buf_get(buf, i); mmap_close(file); truncate(buf->path, wrlen); buf->modified = false; @@ -129,7 +120,7 @@ size_t buf_end(Buf* buf) { } size_t buf_insert(Buf* buf, bool fmt, size_t off, Rune rune) { - bool is_eol = (rune == '\n' || rune == RUNE_CRLF); + bool is_eol = (rune == '\n'); buf->modified = true; if (fmt && buf->expand_tabs && rune == '\t') { size_t tabwidth = TabWidth; @@ -185,7 +176,7 @@ void buf_chomp(Buf* buf) { size_t end = buf_end(buf); if (!end) return; Rune r = buf_get(buf, end-1); - if (r == RUNE_CRLF || r == '\n') { + if (r == '\n') { delete(buf, end-1); if (buf->undo->insert && buf->undo->data.ins.end == end) buf->undo->data.ins.end--; @@ -219,7 +210,7 @@ void buf_logclear(Buf* buf) { bool buf_iseol(Buf* buf, size_t off) { Rune r = buf_get(buf, off); - return (r == '\n' || r == RUNE_CRLF); + return (r == '\n'); } size_t buf_bol(Buf* buf, size_t off) { @@ -532,17 +523,9 @@ static void delete(Buf* buf, size_t off) { } static size_t insert(Buf* buf, size_t off, Rune rune) { - size_t rcount = 1; syncgap(buf, off); - if (buf->crlf && rune == '\n' && buf_get(buf, off-1) == '\r') { - rcount = 0; - *(buf->gapstart-1) = RUNE_CRLF; - } else if (buf->crlf && rune == '\n') { - *(buf->gapstart++) = RUNE_CRLF; - } else { - *(buf->gapstart++) = rune; - } - return rcount; + *(buf->gapstart++) = rune; + return 1; } static int rune_match(Buf* buf, size_t mbeg, size_t mend, Rune* runes) { diff --git a/lib/utf8.c b/lib/utf8.c index 9cae795..28e8bfd 100644 --- a/lib/utf8.c +++ b/lib/utf8.c @@ -122,7 +122,7 @@ bool riscmd(Rune r) { } bool risblank(Rune r) { - return (r == ' ' || r == '\t' || r == '\n' || r == '\r' || r == RUNE_CRLF); + return (r == ' ' || r == '\t' || r == '\n' || r == '\r'); } bool risbigword(Rune r) { diff --git a/lib/view.c b/lib/view.c index beeceba..3dc6f00 100644 --- a/lib/view.c +++ b/lib/view.c @@ -60,7 +60,7 @@ size_t view_limitrows(View* view, size_t maxrows, size_t ncols) { while (nrows < maxrows && pos < buf_end(&(view->buffer))) { Rune r = buf_get(&(view->buffer), pos++); col += runewidth(col, r); - if (col >= ncols || r == RUNE_CRLF || r == '\n') + if (col >= ncols || r == '\n') col = 0, nrows++; } return nrows; @@ -296,17 +296,10 @@ char* view_getstr(View* view, Sel* range) { char* str = NULL; for (; sel.beg < sel.end; sel.beg++) { Rune rune = buf_get(buf, sel.beg); - if (rune == RUNE_CRLF) { - str = realloc(str, len + 2); - str[len + 0] = '\r'; - str[len + 1] = '\n'; - len += 2; - } else { - size_t n = utf8encode(utf, rune); - str = realloc(str, len + n); - memcpy(str+len, utf, n); - len += n; - } + size_t n = utf8encode(utf, rune); + str = realloc(str, len + n); + memcpy(str+len, utf, n); + len += n; } if (str) { str = realloc(str, len+1); @@ -449,7 +442,7 @@ static void select_context(View* view, bool (*isword)(Rune), Sel* sel) { buf_getblock(buf, '[', ']', sel); } else if (r == '{' || r == '}') { buf_getblock(buf, '{', '}', sel); - } else if (sel->end == bol || r == '\n' || r == RUNE_CRLF) { + } else if (sel->end == bol || r == '\n') { sel->beg = bol; sel->end = buf_eol(buf, sel->end); } else if (risword(r)) { @@ -522,9 +515,7 @@ static size_t setcell(View* view, size_t row, size_t col, uint32_t attr, Rune r) int ncols = runewidth(col, r); /* write the rune to the screen buf */ scrrow->cols[col].attr = attr; - if (r == RUNE_CRLF) - scrrow->cols[col].rune = '\n'; - else if (r == '\t') + if (r == '\t') scrrow->cols[col].rune = ' '; else scrrow->cols[col].rune = r; diff --git a/lib/x11.c b/lib/x11.c index 6350d9d..877bb20 100644 --- a/lib/x11.c +++ b/lib/x11.c @@ -578,10 +578,6 @@ static void oninput(int mods, Rune key) { } } - /* translate to crlf if needed */ - if (key == '\n' && win_view(FOCUSED)->buffer.crlf) - key = RUNE_CRLF; - /* fallback to just inserting the rune if it doesn't fall in the private use area. * the private use area is used to encode special keys */ if (key < 0xE000 || key > 0xF8FF) { diff --git a/tide.c b/tide.c index 97006d5..39751c7 100644 --- a/tide.c +++ b/tide.c @@ -57,7 +57,7 @@ static void join_lines(void) { Rune r = view_getrune(view); for (; r == '\t' || r == ' '; r = view_getrune(view)) view_byrune(view, RIGHT, true); - if (r != '\n' && r != RUNE_CRLF) + if (r != '\n') view_insert(view, false, ' '); } -- 2.54.0