]> mj.ucw.cz Git - umpf.git/commitdiff
fix modify_headers
authorAnicka Bernathova <anicka@anicka.net>
Fri, 17 Jul 2009 19:24:44 +0000 (21:24 +0200)
committerAnicka Bernathova <anicka@anicka.net>
Fri, 17 Jul 2009 19:24:44 +0000 (21:24 +0200)
int.c

diff --git a/int.c b/int.c
index 521564030369833215e958c7370e3ba5f3e8dc6b..935a7260dc24fe2a6bf94f85a53f8bc95f70fe11 100644 (file)
--- 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;
        }
-
 }