Refactor code.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
CismonX 2021-11-12 18:16:19 +08:00
parent 4e72aeb8d7
commit 76d0f779d8
Signed by: cismonx
GPG Key ID: 3094873E29A482FB
6 changed files with 38 additions and 33 deletions

View File

@ -12,7 +12,7 @@ AC_INIT([ctlseqs], [0.1.0], [bug-report@cismon.net])
AC_CONFIG_SRCDIR([src/ctlseqs.c])
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_MACRO_DIR([m4])
AM_INIT_AUTOMAKE([foreign info-in-builddir])
AM_INIT_AUTOMAKE([foreign])
AM_EXTRA_RECURSIVE_TARGETS([install-man uninstall-man])
LT_PREREQ([2.4.2])
LT_INIT

View File

@ -6,5 +6,7 @@
# this notice are preserved. This file is offered as-is, without any warranty.
#
AUTOMAKE_OPTIONS = info-in-builddir
info_TEXINFOS = ctlseqs.texi
ctlseqs_TEXINFOS = fdl.texi

View File

@ -179,10 +179,11 @@ decrqm(
print_error(ctx, "failed to get %s status", name);
return false;
}
int mode_value = result[1].num;
if ( result[0].num != mode
|| (result[1].num != DECRQM_SET && result[1].num != DECRQM_RST)
|| (mode_value != DECRQM_SET && mode_value != DECRQM_RST)
) {
print_error(ctx, "%s status not recognizable", name);
print_error(ctx, "%s status (%d) not recognizable", name, mode_value);
return false;
}
return true;
@ -313,7 +314,7 @@ init(
.fd = ctx->in_fd,
.maxlen = 4096,
};
if (ctlseqs_reader_config(ctx->reader, &reader_options) != CTLSEQS_OK) {
if (CTLSEQS_OK != ctlseqs_reader_config(ctx->reader, &reader_options)) {
print_error(ctx, "failed to set reader options");
return false;
}

View File

@ -604,12 +604,13 @@ ctlseqs_cold void
ctlseqs_matcher_free(
struct ctlseqs_matcher *matcher
) {
if (ctlseqs_likely(matcher != NULL)) {
if (ctlseqs_likely(matcher == NULL)) {
return;
}
for (size_t idx = 1; idx <= matcher->pool_idx; ++idx) {
free(matcher->node_pools[idx]);
}
free(matcher);
}
}
struct ctlseqs_reader *
@ -701,8 +702,9 @@ ctlseqs_cold void
ctlseqs_reader_free(
struct ctlseqs_reader *reader
) {
if (ctlseqs_likely(reader != NULL)) {
if (ctlseqs_unlikely(reader == NULL)) {
return;
}
free(reader->rbuf);
free(reader);
}
}

View File

@ -14,5 +14,5 @@ tcsgrep_CPPFLAGS = -I$(top_srcdir)/include
tcsgrep_SOURCES = tcsgrep.c
tcsgrep_LDADD = $(top_builddir)/src/libctlseqs.la
RUNTESTDEFAULTFLAGS = TCSGREP_BIN=$(builddir)/tcsgrep
RUNTESTFLAGS = TCSGREP_BIN=$(builddir)/tcsgrep
EXTRA_DEJAGNU_SITE_CONFIG = $(srcdir)/init.exp

View File

@ -107,11 +107,11 @@ print_char(
"CAN", "EM", "SUB", "ESC", "FS", "GS", "RS", "US"
};
if (ch == ' ') {
fprintf(ctx->out_file, " SP");
fwrite(" SP", 3, 1, ctx->out_file);
} else if (isprint(ch)) {
fprintf(ctx->out_file, " %c", ch);
} else if (ch == 0x7f) {
fprintf(ctx->out_file, " DEL");
fwrite(" DEL", 4, 1, ctx->out_file);
} else if (!iscntrl(ch)) {
fprintf(ctx->out_file, " \\x%02x", (unsigned char)ch);
} else {
@ -133,7 +133,7 @@ print_generic_seq(
print_char(ctx, (unsigned)seq[idx]);
}
if (newline) {
fprintf(ctx->out_file, "\n");
fwrite("\n", 1, 1, ctx->out_file);
}
}
@ -148,7 +148,7 @@ print_matching_seq(
print_generic_seq(ctx, "OK", result, false);
result += 2;
} else {
fprintf(ctx->out_file, "OK");
fwrite("OK", 3, 1, ctx->out_file);
}
fprintf(ctx->out_file, " %s", seq->name);
for (int idx = 0; idx < 8; ++idx) {
@ -219,7 +219,7 @@ main(
print_error(&ctx, "failed to get file status flags");
return 1;
}
if (fcntl(ctx.in_fd, F_SETFL, flags | O_NONBLOCK) == -1) {
if (-1 == fcntl(ctx.in_fd, F_SETFL, flags | O_NONBLOCK)) {
print_error(&ctx, "failed to set file status flags");
return 1;
}
@ -400,7 +400,7 @@ main(
.patterns = patterns,
.npatterns = npatterns,
};
if (ctlseqs_matcher_config(matcher, &matcher_options) != CTLSEQS_OK) {
if (CTLSEQS_OK != ctlseqs_matcher_config(matcher, &matcher_options)) {
print_error(&ctx, "matcher setopt failed");
return 1;
}
@ -416,13 +416,13 @@ main(
.result = result,
.flags = ctx.verbose ? CTLSEQS_READER_SAVE_MATCHED_SEQS : 0,
};
if (ctlseqs_reader_config(reader, &reader_options) != CTLSEQS_OK) {
if (CTLSEQS_OK != ctlseqs_reader_config(reader, &reader_options)) {
print_error(&ctx, "reader setopt failed");
return 1;
}
struct termios old_termios;
if (tcgetattr(ctx.in_fd, &old_termios) != 0) {
if (0 != tcgetattr(ctx.in_fd, &old_termios)) {
ctx.not_tty = true;
} else {
struct termios new_termios = old_termios;