Mercurial > repos > blastem
comparison util.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 | |
children | 6fc71114d145 |
comparison
equal
deleted
inserted
replaced
492:dffc07104b09 | 495:39cad98d2789 |
---|---|
1 #include <string.h> | |
2 #include <stdlib.h> | |
3 #include <stdio.h> | |
4 #include <ctype.h> | |
5 | |
6 char * alloc_concat(char * first, char * second) | |
7 { | |
8 int flen = strlen(first); | |
9 int slen = strlen(second); | |
10 char * ret = malloc(flen + slen + 1); | |
11 memcpy(ret, first, flen); | |
12 memcpy(ret+flen, second, slen+1); | |
13 return ret; | |
14 } | |
15 | |
16 char * alloc_concat_m(int num_parts, char ** parts) | |
17 { | |
18 int total = 0; | |
19 for (int i = 0; i < num_parts; i++) { | |
20 total += strlen(parts[i]); | |
21 } | |
22 char * ret = malloc(total + 1); | |
23 *ret = 0; | |
24 for (int i = 0; i < num_parts; i++) { | |
25 strcat(ret, parts[i]); | |
26 } | |
27 return ret; | |
28 } | |
29 | |
30 long file_size(FILE * f) | |
31 { | |
32 fseek(f, 0, SEEK_END); | |
33 long fsize = ftell(f); | |
34 fseek(f, 0, SEEK_SET); | |
35 return fsize; | |
36 } | |
37 | |
38 char * strip_ws(char * text) | |
39 { | |
40 while (*text && (!isprint(*text) || isblank(*text))) | |
41 { | |
42 text++; | |
43 } | |
44 char * ret = text; | |
45 text = ret + strlen(ret) - 1; | |
46 while (text > ret && (!isprint(*text) || isblank(*text))) | |
47 { | |
48 *text = 0; | |
49 text--; | |
50 } | |
51 return ret; | |
52 } | |
53 | |
54 char * split_keyval(char * text) | |
55 { | |
56 while (*text && !isblank(*text)) | |
57 { | |
58 text++; | |
59 } | |
60 if (!*text) { | |
61 return text; | |
62 } | |
63 *text = 0; | |
64 return text+1; | |
65 } |