Mercurial > repos > blastem
comparison config.c @ 495:39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Mon, 28 Oct 2013 19:37:30 -0700 |
parents | 140af5509ce7 |
children | 6fc71114d145 |
comparison
equal
deleted
inserted
replaced
492:dffc07104b09 | 495:39cad98d2789 |
---|---|
1 /* | 1 /* |
2 Copyright 2013 Michael Pavone | 2 Copyright 2013 Michael Pavone |
3 This file is part of BlastEm. | 3 This file is part of BlastEm. |
4 BlastEm is free software distributed under the terms of the GNU General Public License version 3 or greater. See COPYING for full license text. | 4 BlastEm is free software distributed under the terms of the GNU General Public License version 3 or greater. See COPYING for full license text. |
5 */ | 5 */ |
6 #include "tern.h" | 6 #include "tern.h" |
7 #include "util.h" | |
7 #include <stdio.h> | 8 #include <stdio.h> |
8 #include <stdlib.h> | 9 #include <stdlib.h> |
9 #include <string.h> | 10 #include <string.h> |
10 #include <stdarg.h> | |
11 #include <ctype.h> | |
12 | 11 |
13 #include <sys/types.h> | 12 #include <sys/types.h> |
14 #include <sys/stat.h> | 13 #include <sys/stat.h> |
15 #include <unistd.h> | 14 #include <unistd.h> |
16 | |
17 char * alloc_concat(char * first, char * second) | |
18 { | |
19 int flen = strlen(first); | |
20 int slen = strlen(second); | |
21 char * ret = malloc(flen + slen + 1); | |
22 memcpy(ret, first, flen); | |
23 memcpy(ret+flen, second, slen+1); | |
24 return ret; | |
25 } | |
26 | |
27 char * alloc_concat_m(int num_parts, char ** parts) | |
28 { | |
29 int total = 0; | |
30 for (int i = 0; i < num_parts; i++) { | |
31 total += strlen(parts[i]); | |
32 } | |
33 char * ret = malloc(total + 1); | |
34 *ret = 0; | |
35 for (int i = 0; i < num_parts; i++) { | |
36 strcat(ret, parts[i]); | |
37 } | |
38 return ret; | |
39 } | |
40 | |
41 long file_size(FILE * f) | |
42 { | |
43 fseek(f, 0, SEEK_END); | |
44 long fsize = ftell(f); | |
45 fseek(f, 0, SEEK_SET); | |
46 return fsize; | |
47 } | |
48 | |
49 char * strip_ws(char * text) | |
50 { | |
51 while (*text && (!isprint(*text) || isblank(*text))) | |
52 { | |
53 text++; | |
54 } | |
55 char * ret = text; | |
56 text = ret + strlen(ret) - 1; | |
57 while (text > ret && (!isprint(*text) || isblank(*text))) | |
58 { | |
59 *text = 0; | |
60 text--; | |
61 } | |
62 return ret; | |
63 } | |
64 | |
65 char * split_keyval(char * text) | |
66 { | |
67 while (*text && !isblank(*text)) | |
68 { | |
69 text++; | |
70 } | |
71 if (!*text) { | |
72 return text; | |
73 } | |
74 *text = 0; | |
75 return text+1; | |
76 } | |
77 | 15 |
78 #define MAX_NEST 30 //way more than I'll ever need | 16 #define MAX_NEST 30 //way more than I'll ever need |
79 | 17 |
80 tern_node * parse_config(char * config_data) | 18 tern_node * parse_config(char * config_data) |
81 { | 19 { |
199 if (ret) { | 137 if (ret) { |
200 goto success; | 138 goto success; |
201 } | 139 } |
202 free(path); | 140 free(path); |
203 load_in_app_dir: | 141 load_in_app_dir: |
204 | 142 |
205 linktext = readlink_alloc("/proc/self/exe"); | 143 linktext = readlink_alloc("/proc/self/exe"); |
206 if (!linktext) { | 144 if (!linktext) { |
207 goto link_prob; | 145 goto link_prob; |
208 } | 146 } |
209 char * cur; | 147 char * cur; |