summaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
authorPhil Jones <philj56@gmail.com>2022-12-01 20:24:35 +0000
committerPhil Jones <philj56@gmail.com>2022-12-01 20:24:35 +0000
commitfff5211d2776185348d6b813f2a16cedd5f485d0 (patch)
tree2a4c7f38491e3168c14db4c6fc633210950cbd04 /src/main.c
parentdd36bf1c53216e1828d136cb735d65816575571f (diff)
Add --ascii-input option.
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/main.c b/src/main.c
index 7a92c19..cde56b4 100644
--- a/src/main.c
+++ b/src/main.c
@@ -48,7 +48,7 @@ static uint32_t gettime_ms() {
/* Read all of stdin into a buffer. */
-static char *read_stdin() {
+static char *read_stdin(bool normalize) {
const size_t block_size = BUFSIZ;
size_t num_blocks = 1;
size_t buf_size = block_size;
@@ -66,12 +66,21 @@ static char *read_stdin() {
stdin);
if (bytes_read != block_size) {
if (!feof(stdin) && ferror(stdin)) {
- log_error("Error reading stdin\n");
+ log_error("Error reading stdin.\n");
}
buf[block * block_size + bytes_read] = '\0';
break;
}
}
+ if (normalize) {
+ if (utf8_validate(buf)) {
+ char *tmp = utf8_normalize(buf);
+ free(buf);
+ buf = tmp;
+ } else {
+ log_error("Invalid UTF-8 in stdin.\n");
+ }
+ }
return buf;
}
@@ -875,6 +884,7 @@ const struct option long_options[] = {
{"terminal", required_argument, NULL, 0},
{"hint-font", required_argument, NULL, 0},
{"multi-instance", required_argument, NULL, 0},
+ {"ascii-input", required_argument, NULL, 0},
{"output", required_argument, NULL, 0},
{"scale", required_argument, NULL, 0},
{"late-keyboard-init", optional_argument, NULL, 'k'},
@@ -1360,7 +1370,7 @@ int main(int argc, char *argv[])
log_debug("App list generated.\n");
} else {
log_debug("Reading stdin.\n");
- char *buf = read_stdin();
+ char *buf = read_stdin(!tofi.ascii_input);
tofi.window.entry.command_buffer = buf;
tofi.window.entry.commands = string_ref_vec_from_buffer(buf);
if (tofi.use_history) {