From: <no...@so...> - 2002-11-28 18:14:57
|
Update of /cvsroot/ijbswa/current In directory sc8-pr-cvs1:/tmp/cvs-serv29910 Modified Files: Tag: v_3_0_branch list.c list.h Log Message: Added unmap function that removes all items with a given name from a map. Index: list.c =================================================================== RCS file: /cvsroot/ijbswa/current/Attic/list.c,v retrieving revision 1.15 retrieving revision 1.15.2.1 diff -u -d -r1.15 -r1.15.2.1 --- list.c 26 Mar 2002 22:29:55 -0000 1.15 +++ list.c 28 Nov 2002 18:14:54 -0000 1.15.2.1 @@ -34,6 +34,10 @@ * * Revisions : * $Log$ + * Revision 1.15.2.1 2002/11/28 18:14:54 oes + * Added unmap function that removes all items with a given + * name from a map. + * * Revision 1.15 2002/03/26 22:29:55 swa * we have a new homepage! * @@ -1021,6 +1025,71 @@ the_map->last = new_entry; } + return JB_ERR_OK; +} + + +/********************************************************************* + * + * Function : unmap + * + * Description : Remove all map_entry structs with a given name from + * a given map. + * + * Parameters : + * 1 : the_map = map to look in + * 2 : name = name to unmap + * + * Returns : JB_ERR_OK + * + *********************************************************************/ +jb_err unmap(struct map *the_map, const char *name) +{ + struct map_entry *cur_entry, *last_entry; + + assert(the_map); + assert(name); + + last_entry = the_map->first; + + for (cur_entry = the_map->first; cur_entry != NULL; cur_entry = cur_entry->next) + { + if (!strcmp(name, cur_entry->name)) + { + /* + * Update the incoming pointer + */ + if (cur_entry == the_map->first) + { + the_map->first = cur_entry->next; + } + else + { + last_entry->next = cur_entry->next; + } + + /* + * Update the map's last pointer + */ + if (cur_entry == the_map->last) + { + the_map->last = last_entry; + } + + /* + * Free the map_entry + */ + freez(cur_entry->name); + freez(cur_entry->value); + freez(cur_entry); + + cur_entry = last_entry; + } + else + { + last_entry = cur_entry; + } + } return JB_ERR_OK; } Index: list.h =================================================================== RCS file: /cvsroot/ijbswa/current/Attic/list.h,v retrieving revision 1.12 retrieving revision 1.12.2.1 diff -u -d -r1.12 -r1.12.2.1 --- list.h 26 Mar 2002 22:29:55 -0000 1.12 +++ list.h 28 Nov 2002 18:14:54 -0000 1.12.2.1 @@ -36,6 +36,10 @@ * * Revisions : * $Log$ + * Revision 1.12.2.1 2002/11/28 18:14:54 oes + * Added unmap function that removes all items with a given + * name from a map. + * * Revision 1.12 2002/03/26 22:29:55 swa * we have a new homepage! * @@ -144,9 +148,11 @@ extern struct map * new_map (void); extern void free_map (struct map * the_map); -extern int map (struct map * the_map, +extern jb_err map (struct map * the_map, const char * name, int name_needs_copying, const char * value, int value_needs_copying); +extern jb_err unmap (struct map *the_map, + const char *name); extern const char * lookup (const struct map * the_map, const char * name); |