From c4524ae7aaa85f1569d6be1a8538b3650bc06f89 Mon Sep 17 00:00:00 2001 From: Ashkan Kiani Date: Fri, 3 May 2019 03:30:13 -0700 Subject: Add ability to use null as input delimiter. Update tty to print newline as space Add tty_putc --- src/choices.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src/choices.c') diff --git a/src/choices.c b/src/choices.c index a8c24b6..b6d5f0e 100644 --- a/src/choices.c +++ b/src/choices.c @@ -72,9 +72,10 @@ void choices_fread(choices_t *c, FILE *file) { */ /* Tokenize input and add to choices */ + const char *line_end = c->buffer + c->buffer_size; char *line = c->buffer + buffer_start; do { - char *nl = strchr(line, '\n'); + char *nl = strchr(line, c->input_delimiter); if (nl) *nl++ = '\0'; @@ -83,7 +84,7 @@ void choices_fread(choices_t *c, FILE *file) { choices_add(c, line); line = nl; - } while (line); + } while (line && line < line_end); } static void choices_resize(choices_t *c, size_t new_capacity) { @@ -113,6 +114,12 @@ void choices_init(choices_t *c, options_t *options) { c->worker_count = (int)sysconf(_SC_NPROCESSORS_ONLN); } + if (options->read_null) { + c->input_delimiter = '\0'; + } else { + c->input_delimiter = '\n'; + } + choices_reset_search(c); } -- cgit v1.2.3