/[anubis]/anubis/src/misc.c
ViewVC logotype

Diff of /anubis/src/misc.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.3 by polak, Tue Feb 11 21:07:29 2003 UTC revision 1.4 by gray, Wed Feb 26 16:53:30 2003 UTC
# Line 25  Line 25 
25  #include "headers.h"  #include "headers.h"
26  #include "extern.h"  #include "extern.h"
27    
28  struct list *  /* String lists */
29  new_element(struct list *p, struct list **head, char *newline)  
30    static int
31    _mem_free(void *item, void *data)
32  {  {
33          struct list *new;          free(item);
34          new = (struct list *)xmalloc(sizeof(struct list));          return 0;
35    }
36    
37          if (*head == NULL)  void
38                  p = NULL;  destroy_string_list(struct list **plist)
39    {
40            list_destroy(plist, _mem_free, NULL);
41    }
42    
43          if (p) {  static int
44                  p->next = new;  _assoc_free(void *item, void *data)
45                  new->next = NULL;  {
46                  new->modify = NULL;          assoc_free(item);
47                  new->line = strdup(newline);          return 0;
48          }  }
         else {  
                 new->next = *head;  
                 new->line = strdup(newline);  
                 new->modify = NULL;  
                 *head = new;  
         }  
49    
50          return (struct list *)new;  void
51    destroy_assoc_list(struct list **plist)
52    {
53            list_destroy(plist, _assoc_free, NULL);
54  }  }
55    
56  void  void
57  destroy_list(struct list **head)  assoc_free(ASSOC *asc)
58  {  {
59          struct list *p1 = *head;          free(asc->key);
60          struct list *p2 = NULL;          free(asc->value);
61            free(asc);
62    }
63    
64          if (*head == NULL)  ASSOC *
65                  return;  header_assoc(char *line)
66          do {  {
67                  p2 = p1->next;          char *p = strchr(line, ':');
68                  free(p1->line);          ASSOC *entry = xmalloc(sizeof(*entry));
69                  if (p1->modify)          if (p) {
70                          free(p1->modify);                  int len = p - line;
71                  free(p1);                  entry->key = xmalloc(len + 1);
72                  if (p2)                  memcpy(entry->key, line, len);
73                          p1 = p2;                  entry->key[len] = 0;
74          } while (p2 != NULL);                  entry->value = strdup(p + 1);
75          *head = NULL;          } else {
76                    /* Malformed header. Save everything as rhs */
77                    entry->key = NULL;
78                    entry->value = strdup(line);
79            }
80            return entry;
81    }
82    
83    char *
84    assoc_to_header(ASSOC *asc)
85    {
86            char *buf;
87    
88          return;          if (asc->key) {
89                    buf = xmalloc(strlen(asc->key) + strlen(asc->value) + 3);
90                    sprintf(buf, "%s: %s", asc->key, asc->value);
91            } else
92                    buf = strdup(asc->value);
93            return buf;
94  }  }
95    
96  /****************************  /****************************

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.4

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26