Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Error message pretty printing (to ease grepping on the automatic ranking of my studen...
[simgrid.git] / tools / tesh / buff.c
index 4c8cbd6..691d53d 100644 (file)
 
 #include "buff.h"
 
+XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(tesh);
+
 /**
  ** Buffer code
  **/
 
-void buff_empty(buff_t *b) {
+void buff_empty(buff_t b) {
   b->used=0;
   b->data[0]='\n';
   b->data[1]='\0';
 }
-buff_t *buff_new(void) {
-  buff_t *res=malloc(sizeof(buff_t));
+buff_t buff_new(void) {
+  buff_t res=malloc(sizeof(s_buff_t));
   res->data=malloc(512);
   res->size=512;
   buff_empty(res);
   return res;
 }
-void buff_free(buff_t *b) {
+void buff_free(buff_t b) {
   if (b) {
     if (b->data)
       free(b->data);
     free(b);
   }
 }
-void buff_append(buff_t *b, char *toadd) {
-  int addlen=strlen(toadd);
-  int needed_space=b->used+addlen+1;
+void buff_append(buff_t b, const char *toadd) {
+  int addlen;
+  int needed_space;
+
+  if (!b)
+    THROW0(arg_error,0,"Asked to append stuff to NULL buffer");
+
+  addlen = strlen(toadd);
+  needed_space=b->used+addlen+1;
 
   if (needed_space > b->size) {
     b->data = realloc(b->data, needed_space);
@@ -49,7 +57,7 @@ void buff_append(buff_t *b, char *toadd) {
   strcpy(b->data+b->used, toadd);
   b->used += addlen;  
 }
-void buff_chomp(buff_t *b) {
+void buff_chomp(buff_t b) {
   while (b->data[b->used] == '\n') {
     b->data[b->used] = '\0';
     if (b->used)
@@ -57,7 +65,7 @@ void buff_chomp(buff_t *b) {
   }
 }
 
-void buff_trim(buff_t* b) {
+void buff_trim(buff_t b) {
   xbt_str_trim(b->data," ");
   b->used = strlen(b->data);
 }