]> git.mdlowis.com Git - projs/tide.git/commitdiff
Fixed CRLF handling and added some defines for default charset and default CRLF mode
authorMike Lowis <mike.lowis@gentex.com>
Tue, 18 Oct 2016 19:30:18 +0000 (15:30 -0400)
committerMike Lowis <mike.lowis@gentex.com>
Tue, 18 Oct 2016 19:30:18 +0000 (15:30 -0400)
Makefile
buf.c
charset.c
edit.h
keyboard.c
xedit.c

index 54d6525dbaa94c901d2388fb66f8c0319ecea703..fdceb9c1c1767da527c795413f31a2a7e7ab4aa0 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,5 @@
 LDFLAGS  = -L/opt/X11/lib -lX11 -lXft -lfontconfig
-CFLAGS   = --std=gnu99 -Wall -Wextra -I. -I/opt/X11/include -I/opt/local/include/freetype2 -I/usr/include/freetype2
+CFLAGS   = -Os --std=gnu99 -Wall -Wextra -I. -I/opt/X11/include -I/opt/local/include/freetype2 -I/usr/include/freetype2
 OBJS     = buf.o screen.o utf8.o keyboard.o mouse.o charset.o utils.o
 TESTOBJS = tests/tests.o tests/buf.o tests/utf8.o
 
diff --git a/buf.c b/buf.c
index 8bd9752ee653a5bea71e0984e68a745478dc3e25..75533a6425ff78cd8c34ec1610e57b324cbb6588 100644 (file)
--- a/buf.c
+++ b/buf.c
@@ -82,6 +82,8 @@ static void syncgap(Buf* buf, unsigned off) {
 void buf_init(Buf* buf) {
     buf->insert_mode = false;
     buf->modified    = false;
+    buf->charset     = DEFAULT_CHARSET;
+    buf->crlf        = DEFAULT_CRLF;
     buf->bufsize     = BufSize;
     buf->bufstart    = (Rune*)malloc(buf->bufsize * sizeof(Rune));
     buf->bufend      = buf->bufstart + buf->bufsize;
@@ -105,7 +107,7 @@ void buf_ins(Buf* buf, unsigned off, Rune rune) {
     if (!buf->insert_mode) { return; }
     buf->modified = true;
     syncgap(buf, off);
-    if (rune == '\n' && buf_get(buf, off-1) == '\r')
+    if (buf->crlf && rune == '\n' && buf_get(buf, off-1) == '\r')
         *(buf->gapstart-1) = RUNE_CRLF;
     else
         *(buf->gapstart++) = rune;
index 7a475ff31f670a42a7221571665d8f37587dd6e1..5ef1e07491f115e96804a6ba1612225253b86d5f 100644 (file)
--- a/charset.c
+++ b/charset.c
@@ -41,7 +41,7 @@ int charset(const uint8_t* buf, size_t len, int* crlf) {
         }
     }
     /* report back the linefeed mode */
-    *crlf = (crs > (lfs / 2));
+    *crlf = (crs == lfs);
     return type;
 }
 
diff --git a/edit.h b/edit.h
index 2570b121de3c82546d655185fbb198f466269ab5..674e49b98a8aa3723bef8f90b50c7da2aeda77df 100644 (file)
--- a/edit.h
+++ b/edit.h
@@ -284,3 +284,6 @@ static const Color Palette[][2] = {
 #endif
 
 #define DEFAULT_COLORSCHEME DARK
+#define DEFAULT_CRLF 1
+#define DEFAULT_CHARSET UTF_8
+
index 16cf0e7a5abc21153df2bf3c412a0fc2aa100875..e6e78d234820282104a0551d11d4c7aac7274265 100644 (file)
@@ -66,6 +66,9 @@ static void insert_after(void) {
 }
 
 void handle_key(Rune key) {
+    /* handle the proper line endings */
+    if (key == '\r') key = '\n';
+    if (key == '\n' && Buffer.crlf) key = RUNE_CRLF;
     /* ignore invalid keys */
     if (key == RUNE_ERR) return;
     /* handle the special keys */
diff --git a/xedit.c b/xedit.c
index e17c92be6bb6ca73c7282a064b04add656ef7eb6..7c1ee3d19d4fa1dc76f9d40cfb66d46ffaa50fa5 100644 (file)
--- a/xedit.c
+++ b/xedit.c
@@ -226,7 +226,6 @@ static Rune getkey(XEvent* e) {
     /* decode it */
     if (len > 0) {
         len = 0;
-        if (buf[0] == '\r') buf[0] = '\n';
         for(int i = 0; i < 8 && !utf8decode(&rune, &len, buf[i]); i++);
     }
     /* translate the key code into a unicode codepoint */