Browse code

Return exit code from run

John Hawthorn authored on 20/06/2016 06:36:39
Showing 3 changed files

... ...
@@ -13,6 +13,8 @@
13 13
 #include "../config.h"
14 14
 
15 15
 int main(int argc, char *argv[]) {
16
+	int ret = 0;
17
+
16 18
 	options_t options;
17 19
 	options_parse(&options, argc, argv);
18 20
 
... ...
@@ -47,10 +49,10 @@ int main(int argc, char *argv[]) {
47 49
 
48 50
 		tty_interface_t tty_interface;
49 51
 		tty_interface_init(&tty_interface, &tty, &choices, &options);
50
-		tty_interface_run(&tty_interface);
52
+		ret = tty_interface_run(&tty_interface);
51 53
 	}
52 54
 
53 55
 	choices_destroy(&choices);
54 56
 
55
-	return 0;
57
+	return ret;
56 58
 }
... ...
@@ -113,7 +113,7 @@ void tty_interface_init(tty_interface_t *state, tty_t *tty, choices_t *choices,
113 113
 		strncpy(state->search, options->init_search, SEARCH_SIZE_MAX);
114 114
 }
115 115
 
116
-void tty_interface_run(tty_interface_t *state) {
116
+int tty_interface_run(tty_interface_t *state) {
117 117
 	tty_t *tty = state->tty;
118 118
 	choices_t *choices = state->choices;
119 119
 	char *search = state->search;
... ...
@@ -164,7 +164,7 @@ void tty_interface_run(tty_interface_t *state) {
164 164
 			emit(state);
165 165
 
166 166
 			/* Return to eventually exit successfully */
167
-			return;
167
+			return 0;
168 168
 		} else if (ch == KEY_ESC) { /* ESC */
169 169
 			ch = tty_getchar(tty);
170 170
 			if (ch == '[' || ch == 'O') {
... ...
@@ -177,4 +177,6 @@ void tty_interface_run(tty_interface_t *state) {
177 177
 			}
178 178
 		}
179 179
 	} while (1);
180
+
181
+	return 0;
180 182
 }
... ...
@@ -13,9 +13,11 @@ typedef struct {
13 13
 	options_t *options;
14 14
 
15 15
 	char search[SEARCH_SIZE_MAX + 1];
16
+
17
+	int exit;
16 18
 } tty_interface_t;
17 19
 
18 20
 void tty_interface_init(tty_interface_t *state, tty_t *tty, choices_t *choices, options_t *options);
19
-void tty_interface_run(tty_interface_t *state);
21
+int tty_interface_run(tty_interface_t *state);
20 22
 
21 23
 #endif