int curbufsize;
-static char*
+static char* //TODO: rewrite
buf_double(char* buf, int size)
{
buf = realloc(buf, 2*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 {
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;
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;
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