Lines Matching refs:rope
223 gsm_rope_init( GsmRope rope )
225 rope->data = NULL;
226 rope->pos = 0;
227 rope->max = 0;
228 rope->error = 0;
232 gsm_rope_init_alloc( GsmRope rope, int count )
234 rope->data = rope->data0;
235 rope->pos = 0;
236 rope->max = sizeof(rope->data0);
237 rope->error = 0;
240 rope->data = calloc( count, 1 );
241 rope->max = count;
243 if (rope->data == NULL) {
244 rope->error = 1;
245 rope->max = 0;
251 gsm_rope_done( GsmRope rope )
253 int result = rope->error;
255 if (rope->data && rope->data != rope->data0)
256 free(rope->data);
258 rope->data = NULL;
259 rope->pos = 0;
260 rope->max = 0;
261 rope->error = 0;
268 gsm_rope_done_acquire( GsmRope rope, int *psize )
270 bytes_t result = rope->data;
272 *psize = rope->pos;
273 if (result == rope->data0) {
274 result = malloc( rope->pos );
276 memcpy( result, rope->data, rope->pos );
283 gsm_rope_ensure( GsmRope rope, int new_count )
285 if (rope->data != NULL) {
286 int old_max = rope->max;
287 bytes_t old_data = rope->data == rope->data0 ? NULL : rope->data;
296 rope->error = 1;
299 rope->data = new_data;
300 rope->max = new_max;
302 rope->max = new_count;
308 gsm_rope_can_grow( GsmRope rope, int count )
310 if (!rope->data || rope->error)
313 if (rope->pos + count > rope->max)
315 if (rope->data == NULL)
316 rope->max = rope->pos + count;
318 else if (rope->error ||
319 gsm_rope_ensure( rope, rope->pos + count ) < 0)
326 gsm_rope_add_c( GsmRope rope, char c )
328 if (gsm_rope_can_grow(rope, 1)) {
329 rope->data[ rope->pos ] = (byte_t) c;
331 rope->pos += 1;
335 gsm_rope_add( GsmRope rope, const void* buf, int buflen )
337 if (gsm_rope_can_grow(rope, buflen)) {
338 memcpy( rope->data + rope->pos, (const char*)buf, buflen );
340 rope->pos += buflen;
344 gsm_rope_reserve( GsmRope rope, int count )
348 if (gsm_rope_can_grow(rope, count))
350 if (rope->data != NULL)
351 result = rope->data + rope->pos;
353 rope->pos += count;