From: Mike Lowis Date: Tue, 18 Oct 2016 19:30:18 +0000 (-0400) Subject: Fixed CRLF handling and added some defines for default charset and default CRLF mode X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=22db86ee72bdcee270566c100c2a4ce957381b77;p=projs%2Ftide.git Fixed CRLF handling and added some defines for default charset and default CRLF mode --- diff --git a/Makefile b/Makefile index 54d6525..fdceb9c 100644 --- 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 8bd9752..75533a6 100644 --- 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; diff --git a/charset.c b/charset.c index 7a475ff..5ef1e07 100644 --- 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 2570b12..674e49b 100644 --- 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 + diff --git a/keyboard.c b/keyboard.c index 16cf0e7..e6e78d2 100644 --- a/keyboard.c +++ b/keyboard.c @@ -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 e17c92b..7c1ee3d 100644 --- 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 */