|
|
|
@ -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,24 +148,24 @@ 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) {
|
|
|
|
|
char placeholder = seq->args[idx];
|
|
|
|
|
switch (placeholder) {
|
|
|
|
|
case 0x0e: // CTLSEQS_PH_NUM
|
|
|
|
|
fprintf(ctx->out_file, " %lu", result[idx].num);
|
|
|
|
|
break;
|
|
|
|
|
case 0x10: // CTLSEQS_PH_STR
|
|
|
|
|
fprintf(ctx->out_file, " %.*s",
|
|
|
|
|
(int)result[idx].len, result[idx + 1].str);
|
|
|
|
|
break;
|
|
|
|
|
case 0x0f: // CTLSEQS_PH_NUMS
|
|
|
|
|
for (size_t i = 1; i <= result[idx].len; ++i) {
|
|
|
|
|
fprintf(ctx->out_file, " %lu", result[idx + i].num);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 0x0e: // CTLSEQS_PH_NUM
|
|
|
|
|
fprintf(ctx->out_file, " %lu", result[idx].num);
|
|
|
|
|
break;
|
|
|
|
|
case 0x10: // CTLSEQS_PH_STR
|
|
|
|
|
fprintf(ctx->out_file, " %.*s",
|
|
|
|
|
(int)result[idx].len, result[idx + 1].str);
|
|
|
|
|
break;
|
|
|
|
|
case 0x0f: // CTLSEQS_PH_NUMS
|
|
|
|
|
for (size_t i = 1; i <= result[idx].len; ++i) {
|
|
|
|
|
fprintf(ctx->out_file, " %lu", result[idx + i].num);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
fprintf(ctx->out_file, "\n");
|
|
|
|
@ -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;
|
|
|
|
|