From: Anicka Bernathova Date: Fri, 17 Jul 2009 19:24:44 +0000 (+0200) Subject: fix modify_headers X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=172e811b5426aa677f05d45bf9cb49d1254227a0;p=umpf.git fix modify_headers --- diff --git a/int.c b/int.c index 5215640..935a726 100644 --- a/int.c +++ b/int.c @@ -161,24 +161,58 @@ fold(const char* value, int taken) return ret; } +static char* +unfold(const char* u) +{ + char* new; + const char* pu = u; + char* pn; + + new = xmalloc(strlen(u)+1); + pn = new; + +#define IS_WHITE(c) ((c) == '\t' || (c)==' ' || c=='\n') + + while (IS_WHITE(*pu)) + pu++; + + while (*pu != 0){ + if (IS_WHITE(*pu)){ + while (IS_WHITE(*pu)) + pu++; + if (*pu != 0) + *pn++ = ' '; + } else + *pn++ = *pu++; + } + *pn = 0; + + return new; +} + static void modify_headers(struct list* headers, struct list* hash) { struct hlist* p; int i; struct variable* pv; + char* u, * value; LIST_FOREACH(p, headers){ pv = get_var_struct(p->name, hash); if (!pv) continue; - if (pv->modified){ + u = unfold(p->value); + value = get_var(pv->varcode); + if (strcmp(u, value)){ pv->modified = 0; free_string(p->value); - p->value = fold(get_var(pv->varcode), + p->value = fold(value, strlen(p->name) + 2); } + free_string(u); + free_string(value); } // find new headers @@ -484,35 +518,6 @@ print_vars(struct list* hash) } } -static char* -unfold(const char* u) -{ - char* new; - const char* pu = u; - char* pn; - - new = xmalloc(strlen(u)+1); - pn = new; - -#define IS_WHITE(c) ((c) == '\t' || (c)==' ' || c=='\n') - - while (IS_WHITE(*pu)) - pu++; - - while (*pu != 0){ - if (IS_WHITE(*pu)){ - while (IS_WHITE(*pu)) - pu++; - if (*pu != 0) - *pn++ = ' '; - } else - *pn++ = *pu++; - } - *pn = 0; - - return new; -} - void save_current_headers(struct list* hash) { @@ -524,13 +529,10 @@ save_current_headers(struct list* hash) pv = get_var_struct(p->name, hash); if (!pv) continue; - if (!get_var(pv->varcode)) - continue; u = unfold(p->value); set_var(pv->varcode, u); - set_var(pv->varcode, p->value); + free_string(u); pv->modified = 0; p->have_var = 1; } - }