3 /* buff -- buffers as needed by tesh */
5 /* Copyright (c) 2007 Martin Quinson. */
6 /* All rights reserved. */
8 /* This program is free software; you can redistribute it and/or modify it
9 * under the terms of the license (GNU LGPL) which comes with this package. */
11 /* specific to Borland Compiler */
18 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(tesh);
24 void buff_empty(buff_t b) {
29 buff_t buff_new(void) {
30 buff_t res=malloc(sizeof(s_buff_t));
31 res->data=malloc(512);
36 void buff_free(buff_t b) {
43 void buff_append(buff_t b, const char *toadd) {
48 THROW0(arg_error,0,"Asked to append stuff to NULL buffer");
50 addlen = strlen(toadd);
51 needed_space=b->used+addlen+1;
53 if (needed_space > b->size) {
54 b->data = realloc(b->data, needed_space);
55 b->size = needed_space;
57 strcpy(b->data+b->used, toadd);
60 void buff_chomp(buff_t b) {
61 while (b->data[b->used] == '\n') {
62 b->data[b->used] = '\0';
68 void buff_trim(buff_t b) {
69 xbt_str_trim(b->data," ");
70 b->used = strlen(b->data);