Refactor code.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
4e72aeb8d7
commit
76d0f779d8
|
@ -12,7 +12,7 @@ AC_INIT([ctlseqs], [0.1.0], [bug-report@cismon.net])
|
||||||
AC_CONFIG_SRCDIR([src/ctlseqs.c])
|
AC_CONFIG_SRCDIR([src/ctlseqs.c])
|
||||||
AC_CONFIG_HEADERS([config.h])
|
AC_CONFIG_HEADERS([config.h])
|
||||||
AC_CONFIG_MACRO_DIR([m4])
|
AC_CONFIG_MACRO_DIR([m4])
|
||||||
AM_INIT_AUTOMAKE([foreign info-in-builddir])
|
AM_INIT_AUTOMAKE([foreign])
|
||||||
AM_EXTRA_RECURSIVE_TARGETS([install-man uninstall-man])
|
AM_EXTRA_RECURSIVE_TARGETS([install-man uninstall-man])
|
||||||
LT_PREREQ([2.4.2])
|
LT_PREREQ([2.4.2])
|
||||||
LT_INIT
|
LT_INIT
|
||||||
|
|
|
@ -6,5 +6,7 @@
|
||||||
# this notice are preserved. This file is offered as-is, without any warranty.
|
# this notice are preserved. This file is offered as-is, without any warranty.
|
||||||
#
|
#
|
||||||
|
|
||||||
|
AUTOMAKE_OPTIONS = info-in-builddir
|
||||||
|
|
||||||
info_TEXINFOS = ctlseqs.texi
|
info_TEXINFOS = ctlseqs.texi
|
||||||
ctlseqs_TEXINFOS = fdl.texi
|
ctlseqs_TEXINFOS = fdl.texi
|
||||||
|
|
|
@ -179,10 +179,11 @@ decrqm(
|
||||||
print_error(ctx, "failed to get %s status", name);
|
print_error(ctx, "failed to get %s status", name);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
int mode_value = result[1].num;
|
||||||
if ( result[0].num != mode
|
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 false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -313,7 +314,7 @@ init(
|
||||||
.fd = ctx->in_fd,
|
.fd = ctx->in_fd,
|
||||||
.maxlen = 4096,
|
.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");
|
print_error(ctx, "failed to set reader options");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -604,12 +604,13 @@ ctlseqs_cold void
|
||||||
ctlseqs_matcher_free(
|
ctlseqs_matcher_free(
|
||||||
struct ctlseqs_matcher *matcher
|
struct ctlseqs_matcher *matcher
|
||||||
) {
|
) {
|
||||||
if (ctlseqs_likely(matcher != NULL)) {
|
if (ctlseqs_likely(matcher == NULL)) {
|
||||||
for (size_t idx = 1; idx <= matcher->pool_idx; ++idx) {
|
return;
|
||||||
free(matcher->node_pools[idx]);
|
|
||||||
}
|
|
||||||
free(matcher);
|
|
||||||
}
|
}
|
||||||
|
for (size_t idx = 1; idx <= matcher->pool_idx; ++idx) {
|
||||||
|
free(matcher->node_pools[idx]);
|
||||||
|
}
|
||||||
|
free(matcher);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ctlseqs_reader *
|
struct ctlseqs_reader *
|
||||||
|
@ -701,8 +702,9 @@ ctlseqs_cold void
|
||||||
ctlseqs_reader_free(
|
ctlseqs_reader_free(
|
||||||
struct ctlseqs_reader *reader
|
struct ctlseqs_reader *reader
|
||||||
) {
|
) {
|
||||||
if (ctlseqs_likely(reader != NULL)) {
|
if (ctlseqs_unlikely(reader == NULL)) {
|
||||||
free(reader->rbuf);
|
return;
|
||||||
free(reader);
|
|
||||||
}
|
}
|
||||||
|
free(reader->rbuf);
|
||||||
|
free(reader);
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,5 +14,5 @@ tcsgrep_CPPFLAGS = -I$(top_srcdir)/include
|
||||||
tcsgrep_SOURCES = tcsgrep.c
|
tcsgrep_SOURCES = tcsgrep.c
|
||||||
tcsgrep_LDADD = $(top_builddir)/src/libctlseqs.la
|
tcsgrep_LDADD = $(top_builddir)/src/libctlseqs.la
|
||||||
|
|
||||||
RUNTESTDEFAULTFLAGS = TCSGREP_BIN=$(builddir)/tcsgrep
|
RUNTESTFLAGS = TCSGREP_BIN=$(builddir)/tcsgrep
|
||||||
EXTRA_DEJAGNU_SITE_CONFIG = $(srcdir)/init.exp
|
EXTRA_DEJAGNU_SITE_CONFIG = $(srcdir)/init.exp
|
||||||
|
|
|
@ -107,11 +107,11 @@ print_char(
|
||||||
"CAN", "EM", "SUB", "ESC", "FS", "GS", "RS", "US"
|
"CAN", "EM", "SUB", "ESC", "FS", "GS", "RS", "US"
|
||||||
};
|
};
|
||||||
if (ch == ' ') {
|
if (ch == ' ') {
|
||||||
fprintf(ctx->out_file, " SP");
|
fwrite(" SP", 3, 1, ctx->out_file);
|
||||||
} else if (isprint(ch)) {
|
} else if (isprint(ch)) {
|
||||||
fprintf(ctx->out_file, " %c", ch);
|
fprintf(ctx->out_file, " %c", ch);
|
||||||
} else if (ch == 0x7f) {
|
} else if (ch == 0x7f) {
|
||||||
fprintf(ctx->out_file, " DEL");
|
fwrite(" DEL", 4, 1, ctx->out_file);
|
||||||
} else if (!iscntrl(ch)) {
|
} else if (!iscntrl(ch)) {
|
||||||
fprintf(ctx->out_file, " \\x%02x", (unsigned char)ch);
|
fprintf(ctx->out_file, " \\x%02x", (unsigned char)ch);
|
||||||
} else {
|
} else {
|
||||||
|
@ -133,7 +133,7 @@ print_generic_seq(
|
||||||
print_char(ctx, (unsigned)seq[idx]);
|
print_char(ctx, (unsigned)seq[idx]);
|
||||||
}
|
}
|
||||||
if (newline) {
|
if (newline) {
|
||||||
fprintf(ctx->out_file, "\n");
|
fwrite("\n", 1, 1, ctx->out_file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -148,24 +148,24 @@ print_matching_seq(
|
||||||
print_generic_seq(ctx, "OK", result, false);
|
print_generic_seq(ctx, "OK", result, false);
|
||||||
result += 2;
|
result += 2;
|
||||||
} else {
|
} else {
|
||||||
fprintf(ctx->out_file, "OK");
|
fwrite("OK", 3, 1, ctx->out_file);
|
||||||
}
|
}
|
||||||
fprintf(ctx->out_file, " %s", seq->name);
|
fprintf(ctx->out_file, " %s", seq->name);
|
||||||
for (int idx = 0; idx < 8; ++idx) {
|
for (int idx = 0; idx < 8; ++idx) {
|
||||||
char placeholder = seq->args[idx];
|
char placeholder = seq->args[idx];
|
||||||
switch (placeholder) {
|
switch (placeholder) {
|
||||||
case 0x0e: // CTLSEQS_PH_NUM
|
case 0x0e: // CTLSEQS_PH_NUM
|
||||||
fprintf(ctx->out_file, " %lu", result[idx].num);
|
fprintf(ctx->out_file, " %lu", result[idx].num);
|
||||||
break;
|
break;
|
||||||
case 0x10: // CTLSEQS_PH_STR
|
case 0x10: // CTLSEQS_PH_STR
|
||||||
fprintf(ctx->out_file, " %.*s",
|
fprintf(ctx->out_file, " %.*s",
|
||||||
(int)result[idx].len, result[idx + 1].str);
|
(int)result[idx].len, result[idx + 1].str);
|
||||||
break;
|
break;
|
||||||
case 0x0f: // CTLSEQS_PH_NUMS
|
case 0x0f: // CTLSEQS_PH_NUMS
|
||||||
for (size_t i = 1; i <= result[idx].len; ++i) {
|
for (size_t i = 1; i <= result[idx].len; ++i) {
|
||||||
fprintf(ctx->out_file, " %lu", result[idx + i].num);
|
fprintf(ctx->out_file, " %lu", result[idx + i].num);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fprintf(ctx->out_file, "\n");
|
fprintf(ctx->out_file, "\n");
|
||||||
|
@ -219,7 +219,7 @@ main(
|
||||||
print_error(&ctx, "failed to get file status flags");
|
print_error(&ctx, "failed to get file status flags");
|
||||||
return 1;
|
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");
|
print_error(&ctx, "failed to set file status flags");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -400,7 +400,7 @@ main(
|
||||||
.patterns = patterns,
|
.patterns = patterns,
|
||||||
.npatterns = npatterns,
|
.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");
|
print_error(&ctx, "matcher setopt failed");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -416,13 +416,13 @@ main(
|
||||||
.result = result,
|
.result = result,
|
||||||
.flags = ctx.verbose ? CTLSEQS_READER_SAVE_MATCHED_SEQS : 0,
|
.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");
|
print_error(&ctx, "reader setopt failed");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct termios old_termios;
|
struct termios old_termios;
|
||||||
if (tcgetattr(ctx.in_fd, &old_termios) != 0) {
|
if (0 != tcgetattr(ctx.in_fd, &old_termios)) {
|
||||||
ctx.not_tty = true;
|
ctx.not_tty = true;
|
||||||
} else {
|
} else {
|
||||||
struct termios new_termios = old_termios;
|
struct termios new_termios = old_termios;
|
||||||
|
|
Loading…
Reference in New Issue