From: Michael D. Lowis Date: Tue, 28 Feb 2017 15:37:55 +0000 (-0500) Subject: Fixed issue where default crlf was being ignored for new files X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=6e5e8e2dcf92ab4cc5e4b2f4d7be23be63b6ab5d;p=projs%2Ftide.git Fixed issue where default crlf was being ignored for new files --- diff --git a/foo b/foo new file mode 100644 index 0000000..d3f5a12 --- /dev/null +++ b/foo @@ -0,0 +1 @@ + diff --git a/lib/buf.c b/lib/buf.c index 58f06df..b94675c 100644 --- a/lib/buf.c +++ b/lib/buf.c @@ -206,6 +206,7 @@ unsigned buf_load(Buf* buf, char* path) { /* load the file and determine the character set */ FMap file = mmap_readonly(buf->path); filetype(buf, file); + if (buf->charset > UTF_8) die("Unsupported character set"); @@ -220,7 +221,7 @@ unsigned buf_load(Buf* buf, char* path) { } buf_insert(buf, false, buf_end(buf), r); } - + /* jump to address if we got one */ if (addr) off = buf_setln(buf, strtoul(addr, NULL, 0)); diff --git a/lib/filetype.c b/lib/filetype.c index 57e14ce..0670c90 100644 --- a/lib/filetype.c +++ b/lib/filetype.c @@ -15,7 +15,6 @@ static const char Utf8Valid[256] = { void filetype(Buf* buf, FMap file) { size_t crs = 0, lfs = 0, tabs = 0; - /* look for bytes that are invalid in utf-8 and count tabs, carriage returns, and line feeds */ int type = buf->charset; @@ -30,7 +29,8 @@ void filetype(Buf* buf, FMap file) { } /* setup filetype attributes in the buffer */ - buf->crlf = (crs == lfs); + if (crs || lfs) + buf->crlf = (crs == lfs); buf->charset = type; buf->expand_tabs = (tabs == 0); }