+
+/*********************************************************************
+ *
+ * Function : map
+ *
+ * Description : Add a mapping from given name to given value to a
+ * given map.
+ *
+ * Parameters :
+ * 1 : map = map to add to
+ * 2 : name = name to add
+ * 3 : nc = flag set if name is string constant, and
+ * must be strdup()d, so it can later be free()d (FIXME!)
+ * 4 : value = value to add
+ * 5 : vc = flag set if value is string constant
+ *
+ * Returns : pointer to extended map, or NULL if failiure
+ *
+ *********************************************************************/
+struct map *map(struct map *map, char *name, int nc, char *value, int vc)
+{
+ struct map *cur;
+
+ if (NULL == (cur = zalloc(sizeof(*cur))))
+ {
+ return(NULL);
+ }
+
+ cur->name = nc ? strdup(name) : name;
+ cur->value = vc ? strdup(value) : value;
+ cur->next = map;
+
+ return(cur);
+
+}
+
+
+/*********************************************************************
+ *
+ * Function : lookup
+ *
+ * Description : Look up an item with a given name in a map, and
+ * return its value
+ *
+ * Parameters :
+ * 1 : name = name parameter to look for
+ *
+ * Returns : the value if found, else the empty string
+ *
+ *********************************************************************/
+char *lookup(struct map *map, char *name)
+{
+ struct map *p = map;
+
+ while (p)
+ {
+ if (!strcmp(name, p->name))
+ {
+ return p->value;
+ }
+ p = p->next;
+ }
+ return "";
+}
+
+
+/*********************************************************************
+ *
+ * Function : free_map
+ *
+ * Description : Free the memory occupied by a map and its
+ * depandant strings
+ *
+ * Parameters :
+ * 1 : list = list to bee freed
+ *
+ * Returns : N/A
+ *
+ *********************************************************************/
+void free_map(struct map *map)
+{
+ struct map *p = map;
+
+ while (p)
+ {
+ free(p->name);
+ free(p->value);
+
+ map = p->next;
+ free(p);
+ p = map;
+ }
+
+}
+
+