author | Medo <smaxein@googlemail.com> |
Thu, 05 Jul 2012 00:33:24 +0200 | |
changeset 7316 | f7b49b2c5d84 |
parent 7314 | 6171f0bad318 |
child 10017 | de822cd3df3a |
permissions | -rw-r--r-- |
7314
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
1 |
/* |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
2 |
* Hedgewars, a free turn based strategy game |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
3 |
* Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com> |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
4 |
* |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
5 |
* This program is free software; you can redistribute it and/or |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
6 |
* modify it under the terms of the GNU General Public License |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
7 |
* as published by the Free Software Foundation; either version 2 |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
8 |
* of the License, or (at your option) any later version. |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
9 |
* |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
10 |
* This program is distributed in the hope that it will be useful, |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
13 |
* GNU General Public License for more details. |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
14 |
* |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
16 |
* along with this program; if not, write to the Free Software |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
17 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
18 |
*/ |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
19 |
|
7162
fe76d24a25d7
Demo recording for the frontend library
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
20 |
#include "buffer.h" |
fe76d24a25d7
Demo recording for the frontend library
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
21 |
#include "logging.h" |
7224
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
22 |
#include "util.h" |
7162
fe76d24a25d7
Demo recording for the frontend library
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
23 |
|
fe76d24a25d7
Demo recording for the frontend library
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
24 |
#include <stdlib.h> |
fe76d24a25d7
Demo recording for the frontend library
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
25 |
#include <limits.h> |
fe76d24a25d7
Demo recording for the frontend library
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
26 |
#include <string.h> |
fe76d24a25d7
Demo recording for the frontend library
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
27 |
|
7224
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
28 |
#define MIN_VECTOR_CAPACITY 16 |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
29 |
|
7271
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
30 |
struct _flib_vector { |
7162
fe76d24a25d7
Demo recording for the frontend library
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
31 |
void *data; |
fe76d24a25d7
Demo recording for the frontend library
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
32 |
size_t size; |
fe76d24a25d7
Demo recording for the frontend library
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
33 |
size_t capacity; |
7271
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
34 |
}; |
7162
fe76d24a25d7
Demo recording for the frontend library
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
35 |
|
7224
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
36 |
flib_vector *flib_vector_create() { |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
37 |
flib_vector *result = NULL; |
7271
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
38 |
flib_vector *tmpVector = flib_calloc(1, sizeof(flib_vector)); |
7224
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
39 |
if(tmpVector) { |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
40 |
tmpVector->data = flib_malloc(MIN_VECTOR_CAPACITY); |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
41 |
if(tmpVector->data) { |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
42 |
tmpVector->size = 0; |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
43 |
tmpVector->capacity = MIN_VECTOR_CAPACITY; |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
44 |
result = tmpVector; |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
45 |
tmpVector = NULL; |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
46 |
} |
7162
fe76d24a25d7
Demo recording for the frontend library
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
47 |
} |
7224
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
48 |
flib_vector_destroy(tmpVector); |
7162
fe76d24a25d7
Demo recording for the frontend library
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
49 |
return result; |
fe76d24a25d7
Demo recording for the frontend library
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
50 |
} |
fe76d24a25d7
Demo recording for the frontend library
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
51 |
|
fe76d24a25d7
Demo recording for the frontend library
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
52 |
void flib_vector_destroy(flib_vector *vec) { |
7224
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
53 |
if(vec) { |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
54 |
free(vec->data); |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
55 |
free(vec); |
7162
fe76d24a25d7
Demo recording for the frontend library
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
56 |
} |
fe76d24a25d7
Demo recording for the frontend library
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
57 |
} |
fe76d24a25d7
Demo recording for the frontend library
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
58 |
|
7234
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
59 |
static int setCapacity(flib_vector *vec, size_t newCapacity) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
60 |
if(newCapacity == vec->capacity) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
61 |
return 0; |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
62 |
} |
7162
fe76d24a25d7
Demo recording for the frontend library
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
63 |
void *newData = realloc(vec->data, newCapacity); |
fe76d24a25d7
Demo recording for the frontend library
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
64 |
if(newData) { |
fe76d24a25d7
Demo recording for the frontend library
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
65 |
vec->data = newData; |
fe76d24a25d7
Demo recording for the frontend library
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
66 |
vec->capacity = newCapacity; |
7234
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
67 |
return 0; |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
68 |
} else { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
69 |
return -1; |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
70 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
71 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
72 |
|
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
73 |
static int allocateExtraCapacity(flib_vector *vec, size_t extraCapacity) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
74 |
if(extraCapacity <= SIZE_MAX - vec->capacity) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
75 |
return setCapacity(vec, vec->capacity + extraCapacity); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
76 |
} else { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
77 |
return -1; |
7162
fe76d24a25d7
Demo recording for the frontend library
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
78 |
} |
fe76d24a25d7
Demo recording for the frontend library
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
79 |
} |
fe76d24a25d7
Demo recording for the frontend library
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
80 |
|
7234
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
81 |
int flib_vector_resize(flib_vector *vec, size_t newSize) { |
7316
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
82 |
if(log_badargs_if(vec==NULL)) { |
7234
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
83 |
return -1; |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
84 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
85 |
|
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
86 |
if(vec->capacity < newSize) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
87 |
// Resize exponentially for constant amortized time, |
7271
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
88 |
// But at least by as much as we need of course |
7234
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
89 |
size_t extraCapacity = (vec->capacity)/2; |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
90 |
size_t minExtraCapacity = newSize - vec->capacity; |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
91 |
if(extraCapacity < minExtraCapacity) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
92 |
extraCapacity = minExtraCapacity; |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
93 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
94 |
|
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
95 |
if(allocateExtraCapacity(vec, extraCapacity)) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
96 |
allocateExtraCapacity(vec, minExtraCapacity); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
97 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
98 |
} else if(vec->capacity/2 > newSize) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
99 |
size_t newCapacity = newSize+newSize/4; |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
100 |
if(newCapacity < MIN_VECTOR_CAPACITY) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
101 |
newCapacity = MIN_VECTOR_CAPACITY; |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
102 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
103 |
setCapacity(vec, newCapacity); |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
104 |
} |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
105 |
|
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
106 |
if(vec->capacity >= newSize) { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
107 |
vec->size = newSize; |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
108 |
return 0; |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
109 |
} else { |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
110 |
return -1; |
613998625a3c
frontlib: Started work on the server connection code
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
111 |
} |
7162
fe76d24a25d7
Demo recording for the frontend library
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
112 |
} |
fe76d24a25d7
Demo recording for the frontend library
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
113 |
|
7224
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
114 |
int flib_vector_append(flib_vector *vec, const void *data, size_t len) { |
7316
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
115 |
if(!log_badargs_if2(vec==NULL, data==NULL && len>0) |
7275
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
116 |
&& !log_oom_if(len > SIZE_MAX-vec->size)) { |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
117 |
size_t oldSize = vec->size; |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
118 |
if(!log_oom_if(flib_vector_resize(vec, vec->size+len))) { |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
119 |
memmove(((uint8_t*)vec->data) + oldSize, data, len); |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
120 |
return 0; |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
121 |
} |
7162
fe76d24a25d7
Demo recording for the frontend library
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
122 |
} |
7275
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
123 |
return -1; |
7162
fe76d24a25d7
Demo recording for the frontend library
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
124 |
} |
fe76d24a25d7
Demo recording for the frontend library
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
125 |
|
7271
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
126 |
int flib_vector_appendf(flib_vector *vec, const char *fmt, ...) { |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
127 |
int result = -1; |
7316
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
128 |
if(!log_badargs_if2(vec==NULL, fmt==NULL)) { |
7271
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
129 |
va_list argp; |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
130 |
va_start(argp, fmt); |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
131 |
char *formatted = flib_vasprintf(fmt, argp); |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
132 |
va_end(argp); |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
133 |
|
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
134 |
|
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
135 |
if(formatted) { |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
136 |
size_t len = strlen(formatted); |
7275
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
137 |
result = flib_vector_append(vec, formatted, len); |
7271
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
138 |
} |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
139 |
} |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
140 |
return result; |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
141 |
} |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7234
diff
changeset
|
142 |
|
7224
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
143 |
flib_buffer flib_vector_as_buffer(flib_vector *vec) { |
7316
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
144 |
if(log_badargs_if(vec==NULL)) { |
7224
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
145 |
flib_buffer result = {NULL, 0}; |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
146 |
return result; |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
147 |
} else { |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
148 |
flib_buffer result = {vec->data, vec->size}; |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
149 |
return result; |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
150 |
} |
7162
fe76d24a25d7
Demo recording for the frontend library
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
151 |
} |
fe76d24a25d7
Demo recording for the frontend library
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
152 |
|
7224
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
153 |
flib_constbuffer flib_vector_as_constbuffer(flib_vector *vec) { |
7316
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
154 |
if(log_badargs_if(vec==NULL)) { |
7224
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
155 |
flib_constbuffer result = {NULL, 0}; |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
156 |
return result; |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
157 |
} else { |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
158 |
flib_constbuffer result = {vec->data, vec->size}; |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
159 |
return result; |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
160 |
} |
7162
fe76d24a25d7
Demo recording for the frontend library
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
161 |
} |
7224
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
162 |
|
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
163 |
void *flib_vector_data(flib_vector *vec) { |
7316
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
164 |
if(log_badargs_if(vec==NULL)) { |
7224
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
165 |
return NULL; |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
166 |
} else { |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
167 |
return vec->data; |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
168 |
} |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
169 |
} |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
170 |
|
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
171 |
size_t flib_vector_size(flib_vector *vec) { |
7316
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
172 |
if(log_badargs_if(vec==NULL)) { |
7224
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
173 |
return 0; |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
174 |
} else { |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
175 |
return vec->size; |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
176 |
} |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
177 |
} |