diff options
Diffstat (limited to 'yxml.c')
-rw-r--r-- | yxml.c | 19 |
1 files changed, 9 insertions, 10 deletions
@@ -13,9 +13,9 @@ typedef struct buffer { } buffer; buffer *buffer_new() { - // allocate struct and buffer in one go - buffer *buf = malloc(sizeof(buffer)+BUFSIZE); - if (!buf) { + buffer *buf = malloc(sizeof(buffer)); + buf->buffer = malloc(BUFSIZE); + if (!buf || !buf->buffer) { fprintf(stderr, "Could not allocate memory for buffer struct.\n"); exit(1); } @@ -32,12 +32,10 @@ buffer *buffer_reset(buffer *buf) { } buffer *buffer_append(buffer *buf, char *data) { - int i; - - for (i = buf->len; data; i++) { - buf->buffer[i] = data[i]; + for (int i = 0; data[i]; i++) { + buf->buffer[buf->len] = data[i]; + buf->len++; } - buf->len += i+1; return buf; } @@ -82,9 +80,10 @@ int process(char *fn, yxml_t *state) { yxml_init(state, state+1, BUFSIZE); for (; *parsebuffer; parsebuffer++) { - //fprintf(stderr, "pb: %c\n", *parsebuffer); yxml_ret_t r = yxml_parse(state, *parsebuffer); - fprintf(stderr, "parse_state: %d\n", r); + + //fprintf(stderr, "parse_state: %d\n", r); + if(r < 0) { printf("Parsing error at %s: line %u, byte %lu, offset %lu\n", fn, state->line, state->byte, state->total); |