Skip to content

Commit fbf967f

Browse files
committed
[WIP]: Sun Aug 8 05:54:32 PM CEST 2021
1 parent 30df4d9 commit fbf967f

File tree

1 file changed

+37
-5
lines changed

1 file changed

+37
-5
lines changed

src/cli.c

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -294,9 +294,37 @@ void worker(char *copy, fzf_pattern_t *pattern, fzf_slab_t *slab) {
294294
}
295295
}
296296

297+
// TODO(conni2461): multithreaded (makes it slower and we dont even add it to a
298+
// linked list)
299+
//
300+
// int main(int argc, char **argv) {
301+
// pool_t *pool = pool_create(2);
302+
// fzf_pattern_t *pattern = fzf_parse_pattern(case_smart, false, argv[1],
303+
// true);
304+
305+
// char *line = NULL;
306+
// size_t len = 0;
307+
// ssize_t read;
308+
// while ((read = getline(&line, &len, stdin)) != -1) {
309+
// char *copy = (char *)malloc(sizeof(char) * read);
310+
// strncpy(copy, line, read - 1);
311+
// copy[read - 1] = '\0';
312+
// pool_add_work(pool, worker, copy, pattern);
313+
// }
314+
315+
// pool_wait(pool);
316+
317+
// fzf_free_pattern(pattern);
318+
// free(line);
319+
// pool_destroy(pool);
320+
// return 0;
321+
// }
322+
323+
// Singlethreaded
297324
int main(int argc, char **argv) {
298-
pool_t *pool = pool_create(2);
325+
fzf_slab_t *slab = fzf_make_default_slab();
299326
fzf_pattern_t *pattern = fzf_parse_pattern(case_smart, false, argv[1], true);
327+
fzf_linked_list_t *list = fzf_list_create();
300328

301329
char *line = NULL;
302330
size_t len = 0;
@@ -305,13 +333,17 @@ int main(int argc, char **argv) {
305333
char *copy = (char *)malloc(sizeof(char) * read);
306334
strncpy(copy, line, read - 1);
307335
copy[read - 1] = '\0';
308-
pool_add_work(pool, worker, copy, pattern);
309-
}
310336

311-
pool_wait(pool);
337+
int32_t score = fzf_get_score(copy, pattern, slab);
338+
if (score > 0) {
339+
fzf_list_insert(list, (fzf_tuple_t){.str = copy, .score = score});
340+
}
341+
}
312342

343+
fzf_list_print(list);
344+
fzf_list_free(list);
313345
fzf_free_pattern(pattern);
346+
fzf_free_slab(slab);
314347
free(line);
315-
pool_destroy(pool);
316348
return 0;
317349
}

0 commit comments

Comments
 (0)