Work on acceptance tests.
[agg.git] / text.c
blob39957c126bd96cfd08e0f01e06cbd709ad55f98f
1 #include <string.h>
2 #include "config.h"
3 #include "stack.h"
4 #include "expat.h"
5 #include "text.h"
7 char buffer[TEXT_BUFFER_SIZE] = { 0 };
8 char* cursor = buffer;
10 const char* text_get()
12 return buffer;
15 void text_buffer(const char* str, size_t len)
17 /* We want to append a trailing \0, so we have one
18 * element less. Beware, this will underflow! */
19 size_t free = buffer + TEXT_BUFFER_SIZE - cursor - 1;
20 size_t n = len < free ? len : free;
22 /* Prevent overflow in memcpy(). */
23 if (cursor == buffer + TEXT_BUFFER_SIZE) return;
25 memcpy(cursor, str, n);
26 cursor += n;
27 *cursor = 0;
30 void text_enable()
32 expat_use_text_buffer = true;
33 cursor = buffer;
34 *cursor = 0;
37 void text_disable()
39 expat_use_text_buffer = false;
40 cursor = buffer;
41 *cursor = 0;