]> git.mdlowis.com Git - projs/tide.git/commitdiff
moved crlf detection into buf.c and removed usage of DosLineFeed from view_insert...
authorMichael D. Lowis <mike.lowis@gentex.com>
Mon, 17 Sep 2018 20:00:34 +0000 (16:00 -0400)
committerMichael D. Lowis <mike.lowis@gentex.com>
Mon, 17 Sep 2018 20:00:34 +0000 (16:00 -0400)
lib/buf.c
lib/view.c

index 63e9950876aa06c35767a739d96775364133315e..efeda373b75c7add085bcde601ec313c2b41bdaf 100644 (file)
--- a/lib/buf.c
+++ b/lib/buf.c
@@ -16,6 +16,23 @@ static size_t pagealign(size_t sz) {
     return sz;
 }
 
+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);
+    if (off < bsz)
+        return *(buf->bufstart + off);
+    else
+        return *(buf->gapend + (off - bsz));
+}
+
+static void putb(Buf* buf, char b, Sel* p_sel) {
+    buf_syncgap(buf, p_sel->end);
+    *(buf->gapstart++) = b;
+    p_sel->end = p_sel->end + 1u;
+    p_sel->beg = p_sel->end;
+    buf->status = MODIFIED;
+}
+
 void buf_init(Buf* buf) {
     /* cleanup old data if there is any */
     if (buf->bufstart) {
@@ -72,6 +89,9 @@ 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');
 }
 
 void buf_reload(Buf* buf) {
@@ -148,14 +168,6 @@ static Sel buf_getsel(Buf* buf) {
 
 /* Undo/Redo Operations
  ******************************************************************************/
-static void putb(Buf* buf, char b, Sel* p_sel) {
-    buf_syncgap(buf, p_sel->end);
-    *(buf->gapstart++) = b;
-    p_sel->end = p_sel->end + 1u;
-    p_sel->beg = p_sel->end;
-    buf->status = MODIFIED;
-}
-
 static Log* mklog(Buf* buf, size_t beg, size_t end, char* data, Log* next) {
     Log* log = calloc(1, sizeof(Log));
     log->transid = (buf->transid < 0 ? 0 : buf->transid);
@@ -295,15 +307,6 @@ void buf_lastins(Buf* buf) {
 
 /* Basic Operations and Accessors
  ******************************************************************************/
-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);
-    if (off < bsz)
-        return *(buf->bufstart + off);
-    else
-        return *(buf->gapend + (off - bsz));
-}
-
 size_t buf_end(Buf* buf) {
     size_t bufsz = buf->bufend - buf->bufstart;
     size_t gapsz = buf->gapend - buf->gapstart;
index 31bde213b56adafa342303d83316f7e98ff878d7..c2c3e102ece6f7e831c52393b55273f51d3aa9ab 100644 (file)
@@ -74,11 +74,7 @@ void view_init(View* view, char* file) {
     view->nvisible = 0;
     /* load the file and jump to the address returned from the load function */
     buf_init(BUF);
-    if (file) {
-        buf_load(BUF, file);
-        /* use the EOL style of the first line to determine EOL style */
-        DosLineFeed = (buf_getrat(BUF, buf_eol(BUF, 0)) == '\r');
-    }
+    if (file) buf_load(BUF, file);
 }
 
 void view_reload(View* view) {
@@ -271,9 +267,7 @@ void view_insert(View* view, Rune rune) {
          size_t off = buf_selbeg(BUF);
          size_t beg = buf_bol(BUF, off-1), end = beg;
          for (; end < buf_end(BUF) && (' ' == buf_getrat(BUF, end) || '\t' == buf_getrat(BUF, end)); end++);
-        if (DosLineFeed) 
-            buf_putc(BUF, '\r'); 
-        buf_putc(BUF, '\n'); 
+        buf_putc(BUF, '\n');
         for (; beg < end; beg++)
              buf_putc(BUF, buf_getrat(BUF, beg));
     } else {