| 1 | 1 |
deleted file mode 100644 |
| ... | ... |
@@ -1,36 +0,0 @@ |
| 1 |
-#ifndef CHOICES_H |
|
| 2 |
-#define CHOICES_H CHOICES_H |
|
| 3 |
- |
|
| 4 |
-#include <stdio.h> |
|
| 5 |
- |
|
| 6 |
-struct scored_result {
|
|
| 7 |
- double score; |
|
| 8 |
- const char *str; |
|
| 9 |
-}; |
|
| 10 |
- |
|
| 11 |
-typedef struct {
|
|
| 12 |
- char *buffer; |
|
| 13 |
- size_t buffer_size; |
|
| 14 |
- |
|
| 15 |
- size_t capacity; |
|
| 16 |
- size_t size; |
|
| 17 |
- |
|
| 18 |
- const char **strings; |
|
| 19 |
- struct scored_result *results; |
|
| 20 |
- |
|
| 21 |
- size_t available; |
|
| 22 |
- size_t selection; |
|
| 23 |
-} choices_t; |
|
| 24 |
- |
|
| 25 |
-void choices_init(choices_t *c); |
|
| 26 |
-void choices_fread(choices_t *c, FILE *file); |
|
| 27 |
-void choices_destroy(choices_t *c); |
|
| 28 |
-void choices_add(choices_t *c, const char *choice); |
|
| 29 |
-size_t choices_available(choices_t *c); |
|
| 30 |
-void choices_search(choices_t *c, const char *search); |
|
| 31 |
-const char *choices_get(choices_t *c, size_t n); |
|
| 32 |
-double choices_getscore(choices_t *c, size_t n); |
|
| 33 |
-void choices_prev(choices_t *c); |
|
| 34 |
-void choices_next(choices_t *c); |
|
| 35 |
- |
|
| 36 |
-#endif |
To clarify that we aren't freeing the choices structure, just the
buffers associated with it.
| ... | ... |
@@ -24,7 +24,7 @@ typedef struct {
|
| 24 | 24 |
|
| 25 | 25 |
void choices_init(choices_t *c); |
| 26 | 26 |
void choices_fread(choices_t *c, FILE *file); |
| 27 |
-void choices_free(choices_t *c); |
|
| 27 |
+void choices_destroy(choices_t *c); |
|
| 28 | 28 |
void choices_add(choices_t *c, const char *choice); |
| 29 | 29 |
size_t choices_available(choices_t *c); |
| 30 | 30 |
void choices_search(choices_t *c, const char *search); |
This would allow reading from multiple files (which we don't need) as
well as allowing us to free the buffer with the rest of the choices
structure (which is nice).
Also refactored and added comments.
| ... | ... |
@@ -1,6 +1,8 @@ |
| 1 | 1 |
#ifndef CHOICES_H |
| 2 | 2 |
#define CHOICES_H CHOICES_H |
| 3 | 3 |
|
| 4 |
+#include <stdio.h> |
|
| 5 |
+ |
|
| 4 | 6 |
struct scored_result {
|
| 5 | 7 |
double score; |
| 6 | 8 |
const char *str; |
| ... | ... |
@@ -18,6 +20,7 @@ typedef struct {
|
| 18 | 20 |
} choices_t; |
| 19 | 21 |
|
| 20 | 22 |
void choices_init(choices_t *c); |
| 23 |
+void choices_fread(choices_t *c, FILE *file); |
|
| 21 | 24 |
void choices_free(choices_t *c); |
| 22 | 25 |
void choices_add(choices_t *c, const char *choice); |
| 23 | 26 |
size_t choices_available(choices_t *c); |
| ... | ... |
@@ -1,9 +1,9 @@ |
| 1 | 1 |
#ifndef CHOICES_H |
| 2 | 2 |
#define CHOICES_H CHOICES_H |
| 3 | 3 |
|
| 4 |
-struct scored_position {
|
|
| 5 |
- size_t position; |
|
| 4 |
+struct scored_result {
|
|
| 6 | 5 |
double score; |
| 6 |
+ const char *str; |
|
| 7 | 7 |
}; |
| 8 | 8 |
|
| 9 | 9 |
typedef struct {
|
| ... | ... |
@@ -11,7 +11,7 @@ typedef struct {
|
| 11 | 11 |
size_t size; |
| 12 | 12 |
|
| 13 | 13 |
const char **strings; |
| 14 |
- struct scored_position *results; |
|
| 14 |
+ struct scored_result *results; |
|
| 15 | 15 |
|
| 16 | 16 |
size_t available; |
| 17 | 17 |
size_t selection; |
Fixes Bus Error on BSDs due to qsort_r not being the same qsort_r as
linux.
| ... | ... |
@@ -1,14 +1,18 @@ |
| 1 | 1 |
#ifndef CHOICES_H |
| 2 | 2 |
#define CHOICES_H CHOICES_H |
| 3 | 3 |
|
| 4 |
+struct scored_position {
|
|
| 5 |
+ size_t position; |
|
| 6 |
+ double score; |
|
| 7 |
+}; |
|
| 8 |
+ |
|
| 4 | 9 |
typedef struct {
|
| 5 | 10 |
size_t capacity; |
| 6 | 11 |
size_t size; |
| 7 | 12 |
|
| 8 | 13 |
const char **strings; |
| 9 |
- double *scores; |
|
| 14 |
+ struct scored_position *results; |
|
| 10 | 15 |
|
| 11 |
- size_t *sorted; |
|
| 12 | 16 |
size_t available; |
| 13 | 17 |
size_t selection; |
| 14 | 18 |
} choices_t; |
| ... | ... |
@@ -1,3 +1,6 @@ |
| 1 |
+#ifndef CHOICES_H |
|
| 2 |
+#define CHOICES_H CHOICES_H |
|
| 3 |
+ |
|
| 1 | 4 |
typedef struct {
|
| 2 | 5 |
size_t capacity; |
| 3 | 6 |
size_t size; |
| ... | ... |
@@ -20,3 +23,4 @@ double choices_getscore(choices_t *c, size_t n); |
| 20 | 23 |
void choices_prev(choices_t *c); |
| 21 | 24 |
void choices_next(choices_t *c); |
| 22 | 25 |
|
| 26 |
+#endif |
| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,22 @@ |
| 1 |
+typedef struct {
|
|
| 2 |
+ size_t capacity; |
|
| 3 |
+ size_t size; |
|
| 4 |
+ |
|
| 5 |
+ const char **strings; |
|
| 6 |
+ double *scores; |
|
| 7 |
+ |
|
| 8 |
+ size_t *sorted; |
|
| 9 |
+ size_t available; |
|
| 10 |
+ size_t selection; |
|
| 11 |
+} choices_t; |
|
| 12 |
+ |
|
| 13 |
+void choices_init(choices_t *c); |
|
| 14 |
+void choices_free(choices_t *c); |
|
| 15 |
+void choices_add(choices_t *c, const char *choice); |
|
| 16 |
+size_t choices_available(choices_t *c); |
|
| 17 |
+void choices_search(choices_t *c, const char *search); |
|
| 18 |
+const char *choices_get(choices_t *c, size_t n); |
|
| 19 |
+double choices_getscore(choices_t *c, size_t n); |
|
| 20 |
+void choices_prev(choices_t *c); |
|
| 21 |
+void choices_next(choices_t *c); |
|
| 22 |
+ |