summaryrefslogtreecommitdiff
path: root/src/choices.h
blob: 70ef13f0acb155d2d577b0ff04c835f15e050ce9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#ifndef CHOICES_H
#define CHOICES_H CHOICES_H

#include <stdio.h>

#include "match.h"
#include "options.h"

struct scored_result {
	score_t score;
    size_t idx;
};

typedef struct InputItem {
    const char *input_line;
    const char *search_buf;

    char *allocated;
} InputItem;

typedef struct {
	char *buffer;
	size_t buffer_size;

	size_t capacity;
	size_t size;

    InputItem *input_items;
	struct scored_result *results;

	size_t available;
	size_t selection;

	unsigned int worker_count;

    const char *delimiters;
    const FieldSelector *search_fields;
    const FieldSelector *output_fields;
} choices_t;

void choices_init(choices_t *c, options_t *options);
void choices_fread(choices_t *c, FILE *file, char input_delimiter);
void choices_destroy(choices_t *c);
void choices_add(choices_t *c, const char *choice);
size_t choices_available(choices_t *c);
void choices_search(choices_t *c, const char *search);
const char *choices_get_search(choices_t *c, size_t n);
char *choices_get_output(choices_t *c, size_t n);
score_t choices_getscore(choices_t *c, size_t n);
void choices_prev(choices_t *c);
void choices_next(choices_t *c);

#endif