Browse code

Move sources into src directory

John Hawthorn authored on 21/05/2016 21:56:03
Showing 1 changed files
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
Browse code

Rename choices_free to choices_destroy

To clarify that we aren't freeing the choices structure, just the
buffers associated with it.

John Hawthorn authored on 03/05/2016 04:45:26
Showing 1 changed files
... ...
@@ -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);
Browse code

Store read buffer on choices structure

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).

John Hawthorn authored on 01/05/2016 00:28:55
Showing 1 changed files
... ...
@@ -9,6 +9,9 @@ struct scored_result {
9 9
 };
10 10
 
11 11
 typedef struct {
12
+	char *buffer;
13
+	size_t buffer_size;
14
+
12 15
 	size_t capacity;
13 16
 	size_t size;
14 17
 
Browse code

Move input reading to choices.c

Also refactored and added comments.

John Hawthorn authored on 23/04/2016 18:25:47
Showing 1 changed files
... ...
@@ -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);
Browse code

Store string in result instead of position

John Hawthorn authored on 21/09/2014 21:40:36
Showing 1 changed files
... ...
@@ -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;
Browse code

Use AoS instead of SoA; don't use qsort_r

Fixes Bus Error on BSDs due to qsort_r not being the same qsort_r as
linux.

John Hawthorn authored on 17/09/2014 17:43:01 • John Hawthorn committed on 18/09/2014 02:11:14
Showing 1 changed files
... ...
@@ -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;
Browse code

Cleanup headers

John Hawthorn authored on 15/09/2014 02:42:43
Showing 1 changed files
... ...
@@ -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
Browse code

Refactor into choices.c

John Hawthorn authored on 14/09/2014 05:19:52
Showing 1 changed files
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
+