+
+/*********************************************************************
+ *
+ * Function : map
+ *
+ * Description : Add a mapping from given name to given value to a
+ * given map.
+ *
+ * Note: Since all strings will be free()d in free_map()
+ * later, use the copy flags for constants or
+ * strings that will be independantly free()d.
+ *
+ * Parameters :
+ * 1 : the_map = map to add to
+ * 2 : name = name to add
+ * 3 : nc = flag set if a copy of name should be used
+ * 4 : value = value to add
+ * 5 : vc = flag set if a copy of value should be used
+ *
+ * Returns : N/A
+ *
+ *********************************************************************/
+void map(struct map *the_map, const char *name, int nc, const char *value, int vc)
+{
+ struct map_entry *new_entry;
+
+ if (NULL == (new_entry = zalloc(sizeof(*new_entry))))
+ {
+ return;
+ }
+
+ new_entry->name = nc ? strdup(name) : name;
+ new_entry->value = vc ? strdup(value) : value;
+ /* new_entry->next = NULL; - implied by zalloc */
+
+ if (the_map->last)
+ {
+ the_map->last = the_map->last->next = new_entry;
+ }
+ else
+ {
+ the_map->last = the_map->first = new_entry;
+ }
+
+}
+
+
+/*********************************************************************
+ *
+ * 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
+ *
+ *********************************************************************/
+const char *lookup(const struct map *the_map, const char *name)
+{
+ const struct map_entry *cur_entry = the_map->first;
+
+ while (cur_entry)
+ {
+ if (!strcmp(name, cur_entry->name))
+ {
+ return cur_entry->value;
+ }
+ cur_entry = cur_entry->next;
+ }
+ return "";
+}
+
+
+/*********************************************************************
+ *
+ * Function : new_nap
+ *
+ * Description : Create a new, empty map.
+ *
+ * Parameters :
+ *
+ * Returns : A new, empty map, or NULL if out of memory.
+ *
+ *********************************************************************/
+struct map *new_map(void)
+{
+ return (struct map *) zalloc(sizeof(struct map));
+}
+
+
+/*********************************************************************
+ *
+ * Function : free_map
+ *
+ * Description : Free the memory occupied by a map and its
+ * depandant strings
+ *
+ * Parameters :
+ * 1 : cur_entry = map to be freed. May be NULL.
+ *
+ * Returns : N/A
+ *
+ *********************************************************************/
+void free_map(struct map *the_map)
+{
+ struct map_entry *cur_entry;
+ struct map_entry *next_entry;
+
+ if (the_map == NULL)
+ {
+ return;
+ }
+
+ for (cur_entry = the_map->first; cur_entry != NULL; cur_entry = next_entry)
+ {
+ freez((char *)cur_entry->name);
+ freez((char *)cur_entry->value);
+
+ next_entry = cur_entry->next;
+ free(cur_entry);
+ }
+
+ the_map->first = the_map->last = NULL;
+
+ free(the_map);
+}
+
+