diff --git a/.gitattributes b/.gitattributes index f4ba754..6b770aa 100644 --- a/.gitattributes +++ b/.gitattributes @@ -7,6 +7,6 @@ # # Attributes for GitHub Linguist -*.h linguist-language=c +*.h linguist-language=c configure.ac linguist-detectable=false -Makefile.am linguist-detectable=false +Makefile.am linguist-detectable=false diff --git a/.gitignore b/.gitignore index fc00a8e..49bde8b 100644 --- a/.gitignore +++ b/.gitignore @@ -9,7 +9,8 @@ # IDE & plugins .idea/ .vscode/ -.ccls* +.ccls-cache/ +.ccls # OSX stuff .DS_Store diff --git a/examples/sixdraw.c b/examples/sixdraw.c index ec8047d..a7888ac 100644 --- a/examples/sixdraw.c +++ b/examples/sixdraw.c @@ -193,12 +193,13 @@ sixdraw_prepare(struct sixdraw_ctx *ctx) } // Set terminal to noncanonical mode - struct termios termios; if (tcgetattr(ctx->in_fd, &ctx->termios) != 0) { sixdraw_print_error(ctx, "failed to get terminal attributes"); return false; } - termios = ctx->termios; + struct termios termios = ctx->termios; + termios.c_cc[VMIN] = 0; + termios.c_cc[VTIME] = 0; termios.c_lflag &= ~(ICANON | ISIG | ECHO); if (tcsetattr(ctx->in_fd, TCSANOW, &termios) != 0) { sixdraw_print_error(ctx, "failed to get terminal attributes"); diff --git a/src/Makefile.am b/src/Makefile.am index 8446166..7bcb706 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,22 +1,13 @@ -## -## Copyright (C) 2020 CismonX -## -## This file is free software: you can redistribute it and/or modify -## it under the terms of the GNU General Public License as published by -## the Free Software Foundation, either version 3 of the License, or -## (at your option) any later version. -## -## This file is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with this file. If not, see . -## +# +# Copyright (C) 2020 CismonX +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty, provided the copyright notice and +# this notice are preserved. This file is offered as-is, without any warranty. +# lib_LTLIBRARIES = libctlseqs.la libctlseqs_la_SOURCES = ctlseqs.c -libctlseqs_la_LDFLAGS = -version-info ${CTLSEQS_LT_VERSION} +libctlseqs_la_LDFLAGS = -version-info $(CTLSEQS_LT_VERSION) include_HEADERS = ctlseqs.h diff --git a/src/ctlseqs.c b/src/ctlseqs.c index e5a8836..d01c33e 100644 --- a/src/ctlseqs.c +++ b/src/ctlseqs.c @@ -521,13 +521,11 @@ ctlseqs_read(struct ctlseqs_reader *reader, struct ctlseqs_matcher const *matche void ctlseqs_purge(struct ctlseqs_reader *reader, size_t nbytes) { - size_t bufsize = reader->buf_end - reader->buf_start; - nbytes = nbytes > bufsize ? bufsize : nbytes; - if (nbytes == 0) { + if (CTLSEQS_UNLIKELY(nbytes == 0)) { return; } reader->buf_start += nbytes; - if (reader->buf_start == reader->buf_end) { + if (reader->buf_start >= reader->buf_end) { reader->buf_start = 0; reader->buf_end = 0; } diff --git a/tests/tcsgrep.c b/tests/tcsgrep.c index 5005c28..21a7f83 100644 --- a/tests/tcsgrep.c +++ b/tests/tcsgrep.c @@ -359,6 +359,8 @@ main(int argc, char **argv) return 1; } struct termios new_termios = old_termios; + new_termios.c_cc[VMIN] = 0; + new_termios.c_cc[VTIME] = 0; new_termios.c_lflag &= ~(ICANON | ISIG | ECHO); if (tcsetattr(STDIN_FILENO, TCSANOW, &new_termios) != 0) { print_error(&ctx, "failed to set terminal attributes");