]> mj.ucw.cz Git - umpf.git/blobdiff - ham.c
use clist for headers
[umpf.git] / ham.c
diff --git a/ham.c b/ham.c
index 40444e1dc5955a718107eb02c3ec0708b64898b5..04153c5bb68ee9db8b3215d66398c8acd2a296c3 100644 (file)
--- a/ham.c
+++ b/ham.c
@@ -8,7 +8,7 @@
 
 int curbufsize;
 
-static char*
+static char* //TODO: rewrite
 buf_double(char* buf, int size)
 {
        buf = realloc(buf, 2*size);
@@ -20,19 +20,15 @@ buf_double(char* buf, int size)
 
 }
 
-static struct hlist* 
-new_header(char* buf, struct hlist* end)
+static void
+new_header(char* buf, struct list* h)
 {
        char* p;
        struct hlist* new;
 
        new = xmalloc(sizeof(struct hlist));
 
-       if (end)
-               end->next = new;
-
        p = strchr(buf, ':');
-
        if (!p)
                new->value = xstrdup("");
        else {
@@ -40,19 +36,19 @@ new_header(char* buf, struct hlist* end)
                new->value = xstrdup(p+1);
        }
        new->name = xstrdup(buf);
-       new->next = NULL;
 
-       return new;
+       list_add_last(h, &new->car);
 }
 
-struct hlist*
+struct list*
 make_hlist(void)
 {
-       struct hlist* start = NULL, *end = NULL;
+       struct list* l = xmalloc(sizeof(struct list));
        char* buf;
        int i = 0; /* current position */
        int c, last = 0;
 
+       list_init(l);
        buf = xmalloc(BUFSIZE);
        curbufsize = BUFSIZE;
        
@@ -73,9 +69,7 @@ make_hlist(void)
                                if (c != EOF)
                                        ungetc(c, stdin);
                                buf[i] = 0;
-                               end = new_header(buf, end);
-                               if (!start)
-                                       start = end;
+                               new_header(buf, l);
                                i = 0;
                        } else
                                buf[i++] = c;
@@ -83,18 +77,16 @@ make_hlist(void)
                        last = c;
        }
        free(buf);
-       return start;
+       return l;
 }
 
 void
-print_headers(struct hlist* h)
+print_headers(struct list* l)
 {
-       struct hlist* p = h;
+       struct hlist* p;
 
-       while (p){
+       LIST_FOREACH(p,l)
                printf("%s:%s",p->name,p->value);
-               p = p->next;
-       }
 }
 
 void