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
}
}
-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)
{
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;
}
-
}