Mercurial > repos > blastem
comparison tern.c @ 792:724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Sat, 25 Jul 2015 18:22:07 -0700 |
parents | 2f48a3c187c6 |
children | 110251ea369e |
comparison
equal
deleted
inserted
replaced
791:60686f8d5e48 | 792:724bbec47f86 |
---|---|
6 #include "tern.h" | 6 #include "tern.h" |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdlib.h> | 8 #include <stdlib.h> |
9 #include <string.h> | 9 #include <string.h> |
10 #include <stdio.h> | 10 #include <stdio.h> |
11 #include "util.h" | |
11 | 12 |
12 tern_node * tern_insert(tern_node * head, char * key, tern_val value) | 13 tern_node * tern_insert(tern_node * head, char * key, tern_val value) |
13 { | 14 { |
14 tern_node ** cur = &head; | 15 tern_node ** cur = &head; |
15 while(*key) | 16 while(*key) |
188 if (head->left) { | 189 if (head->left) { |
189 tern_foreach_int(head->left, fun, data, keybuf, pos); | 190 tern_foreach_int(head->left, fun, data, keybuf, pos); |
190 } | 191 } |
191 if (head->el) { | 192 if (head->el) { |
192 if (pos == MAX_ITER_KEY) { | 193 if (pos == MAX_ITER_KEY) { |
193 fputs("exceeded maximum key size", stderr); | 194 fatal_error("tern_foreach_int: exceeded maximum key size"); |
194 exit(1); | |
195 } | 195 } |
196 keybuf[pos] = head->el; | 196 keybuf[pos] = head->el; |
197 tern_foreach_int(head->straight.next, fun, data, keybuf, pos+1); | 197 tern_foreach_int(head->straight.next, fun, data, keybuf, pos+1); |
198 } | 198 } |
199 if (head->right) { | 199 if (head->right) { |