]> git.mdlowis.com Git - projs/tide.git/commitdiff
Removed RUNE_CRLF
authorMichael D. Lowis <mike.lowis@gentex.com>
Mon, 26 Mar 2018 18:27:43 +0000 (14:27 -0400)
committerMichael D. Lowis <mike.lowis@gentex.com>
Mon, 26 Mar 2018 18:27:43 +0000 (14:27 -0400)
inc/utf.h
lib/buf.c
lib/utf8.c
lib/view.c
lib/x11.c
tide.c

index b0573633c7a4495690ecaa574fecc3245b1f8323..3a8a74e77481b9a471a1a5aa0bda633afc180252 100644 (file)
--- 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 */
index b7125697ea0805d262b91836be370a4d5a3d0a2a..cc78016e3d0056d1b52b09153950f6320ec2d1ca 100644 (file)
--- 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) {
index 9cae7952ac7145054607266cf3407eb4709b02ae..28e8bfdf3aec500b243ed30e2d6d67a8b157966d 100644 (file)
@@ -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) {
index beeceba004a7771291c0c240a54299e7a14f1c9d..3dc6f007f3128e33771e283fc5ec3984fd54ad4f 100644 (file)
@@ -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;
index 6350d9d363488cedca5c7f6351d6df31806d8118..877bb20adc2b330fcf323a3b49aa541e78a1b190 100644 (file)
--- 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 97006d583bd6c0255ea3df6482c6e1465490976f..39751c76ecc14c23bc199c79ae46b59c5d711b72 100644 (file)
--- 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, ' ');
 }