summaryrefslogtreecommitdiff
path: root/src/choices.c
diff options
context:
space:
mode:
authorAshkan Kiani <ashkan.k.kiani@gmail.com>2019-05-03 03:30:13 -0700
committerJohn Hawthorn <john@hawthorn.email>2019-08-16 01:05:01 -0700
commitc4524ae7aaa85f1569d6be1a8538b3650bc06f89 (patch)
tree326bc7c96be446cba02b99f7dad3e6b9e08aad39 /src/choices.c
parenta318e00e30df4056c78ff4edf38376feb4d57dab (diff)
Add ability to use null as input delimiter.
Update tty to print newline as space Add tty_putc
Diffstat (limited to 'src/choices.c')
-rw-r--r--src/choices.c11
1 files changed, 9 insertions, 2 deletions
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);
}