[digraphanalysis-cvs] digraphanalysis/src list.c,JBREKER list.h,JBREKER main.c,JBREKER main.h,JBREKE
Status: Planning
Brought to you by:
jbreker
|
From: Jeff B. <jb...@us...> - 2005-03-28 02:10:00
|
Update of /cvsroot/digraphanalysis/digraphanalysis/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29420 Modified Files: Tag: JBREKER list.c list.h main.c main.h node.h Log Message: more LIST_* usage conversion Index: node.h =================================================================== RCS file: /cvsroot/digraphanalysis/digraphanalysis/src/Attic/node.h,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -C2 -d -r1.1.2.2 -r1.1.2.3 *** node.h 20 Mar 2005 17:30:48 -0000 1.1.2.2 --- node.h 28 Mar 2005 02:09:51 -0000 1.1.2.3 *************** *** 17,21 **** #ifndef _NODE_H_ - #define _NODE_H_ --- 17,20 ---- *************** *** 27,31 **** float msd; char *name; ! list_t *signatures; }; --- 26,30 ---- float msd; char *name; ! struct list_t *signatures; }; *************** *** 35,39 **** int pgpkey_compare_msd(void *, void *); unsigned int pgpkey_distance(pgpkey_t *, pgpkey_t *); ! void pgpkey_msd(pgpkey_t *, list_t *); pgpkey_t *pgpkey_new(char *, char *); --- 34,38 ---- int pgpkey_compare_msd(void *, void *); unsigned int pgpkey_distance(pgpkey_t *, pgpkey_t *); ! void pgpkey_msd(pgpkey_t *, struct list_t *); pgpkey_t *pgpkey_new(char *, char *); Index: list.h =================================================================== RCS file: /cvsroot/digraphanalysis/digraphanalysis/src/list.h,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -C2 -d -r1.1.2.1 -r1.1.2.2 *** list.h 28 Mar 2005 00:48:23 -0000 1.1.2.1 --- list.h 28 Mar 2005 02:09:51 -0000 1.1.2.2 *************** *** 17,23 **** #ifndef _LIST_H_ - #define _LIST_H_ struct node_t { --- 17,24 ---- #ifndef _LIST_H_ #define _LIST_H_ + #include <sys/queue.h> + struct node_t { *************** *** 28,41 **** LIST_HEAD(list_t, node_t); ! int list_add_object(struct list_t *, void *); ! struct list_t *list_duplicate(struct list_t *); ! void *list_find_object(struct list_t *, void *); void list_free(struct list_t *); ! struct list_t *list_merge_list(struct list_t *, struct list_t *); ! struct list_t *list_new(int (*) (void *, void *)); ! struct node_t *list_new_node(void *, struct node_t *, struct node_t *); ! void list_remove(struct list_t *, void *); ! struct list_t *list_resort(struct list_t *); ! struct list_t *list_union(struct list_t *, struct list_t *); #endif --- 29,42 ---- LIST_HEAD(list_t, node_t); ! int list_add_object(struct list_t *, void *, int (*)(void *, void *)); ! struct list_t *list_duplicate(struct list_t *, int (*)(void *, void *)); ! void *list_find_object(struct list_t *, void *, int (*)(void *, void *)); void list_free(struct list_t *); ! struct list_t *list_merge_list(struct list_t *, struct list_t *, int (*)(void *, void *)); ! struct list_t *list_new(); ! struct node_t *list_new_node(void *); ! void list_remove(struct list_t *, void *, int (*)(void *, void *)); ! struct list_t *list_resort(struct list_t *, int (*)(void *, void *)); ! struct list_t *list_union(struct list_t *, struct list_t *, int (*)(void *, void *)); #endif Index: list.c =================================================================== RCS file: /cvsroot/digraphanalysis/digraphanalysis/src/list.c,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -C2 -d -r1.1.2.1 -r1.1.2.2 *** list.c 28 Mar 2005 00:48:22 -0000 1.1.2.1 --- list.c 28 Mar 2005 02:09:51 -0000 1.1.2.2 *************** *** 16,19 **** --- 16,21 ---- */ + #include <sys/queue.h> + #include <errno.h> #include <stdio.h> *************** *** 29,33 **** * This might be more usefull if we returned the object that is in the list or NULL on error */ ! int list_add_object(struct list_t *list, void *object) { int i; --- 31,35 ---- * This might be more usefull if we returned the object that is in the list or NULL on error */ ! int list_add_object(struct list_t *list, void *object, int (*compare)(void *, void *)) { int i; *************** *** 41,56 **** return 1; } ! while(iter->next != NULL) { ! if((i = list->compare(object, iter->object)) < 0) { ! if((iter = list_new_node(object, iter, iter->prev)) == NULL) ! return -1; ! if(iter->prev == NULL) ! list->head = iter; else ! iter->prev->next = iter; ! iter->next->prev = iter; ! ++(list->size); return 1; } --- 43,54 ---- return 1; } ! while(LIST_NEXT(iter, entries) != NULL) { ! if((i = compare(object, iter->object)) < 0) { ! if(iter == LIST_FIRST(list)) ! LIST_INSERT_HEAD(list, list_new_node(object), entries); else ! LIST_INSERT_BEFORE(iter, list_new_node(object), entries); return 1; } *************** *** 58,73 **** if(i == 0) return 0; ! iter = iter->next; } ! if((i = list->compare(object, iter->object)) < 0) { ! if((iter = list_new_node(object, iter, iter->prev)) == NULL) ! return -1; ! if(iter->prev == NULL) ! list->head = iter; else ! iter->prev->next = iter; ! iter->next->prev = iter; ! ++(list->size); return 1; } --- 56,67 ---- if(i == 0) return 0; ! iter = LIST_NEXT(iter, entries); } ! if((i = compare(object, iter->object)) < 0) { ! if(iter == LIST_FIRST(list)) ! LIST_INSERT_HEAD(list, list_new_node(object), entries); else ! LIST_INSERT_BEFORE(iter, list_new_node(object), entries); return 1; } *************** *** 75,82 **** if(i == 0) return 0; ! if((iter->next = list->tail = list_new_node(object, NULL, iter)) == NULL) ! return -1; ! ++(list->size); ! return 1; } --- 69,73 ---- if(i == 0) return 0; ! LIST_INSERT_AFTER(iter, list_new_node(object), entries); return 1; } *************** *** 84,94 **** /* Returns NULL on error */ ! struct list_t *list_duplicate(struct list_t *list) { struct list_t *ret_list; ! if((ret_list = list_new(list->compare)) == NULL) return NULL; ! if(list_merge_list(ret_list, list) == NULL) return NULL; --- 75,85 ---- /* Returns NULL on error */ ! struct list_t *list_duplicate(struct list_t *list, int (*compare)(void *, void *)) { struct list_t *ret_list; ! if((ret_list = list_new()) == NULL) return NULL; ! if(list_merge_list(ret_list, list, compare) == NULL) return NULL; *************** *** 96,136 **** } ! void list_free(struct list_t *list) { ! node_t *iter; ! iter = list->head; while(iter != NULL) { ! list->head = iter->next; ! free(iter); ! iter = list->head; } ! free(list); ! list = NULL; ! ! return; } ! void *list_find_object(struct list_t *list, void *object) { ! int i; ! node_t *iter; ! iter = list->head; while(iter != NULL) { ! if((i = list->compare(iter->object, object)) == 0) ! return iter->object; ! else ! if(i > 0) ! break; ! iter = iter->next; } ! return NULL; } --- 87,127 ---- } ! void *list_find_object(struct list_t *list, void *object, int (*compare)(void *, void*)) { ! int i; ! struct node_t *iter; ! iter = LIST_FIRST(list); while(iter != NULL) { ! if((i = compare(iter->object, object)) == 0) ! return iter->object; ! else ! if(i > 0) ! break; ! iter = LIST_NEXT(iter, entries); } ! return NULL; } ! void list_free(struct list_t *list) { ! struct node_t *iter; ! iter = LIST_FIRST(list); while(iter != NULL) { ! LIST_FIRST(list) = LIST_NEXT(iter, entries); ! free(iter); ! iter = LIST_FIRST(list); } ! free(list); ! list = NULL; ! ! return; } *************** *** 139,153 **** * list1 on success */ ! struct list_t *list_merge_list(struct list_t *list1, struct list_t *list2) { ! node_t *iter; ! iter = list2->head; while(iter != NULL) { ! if(list_add_object(list1, iter->object) == -1) return NULL; ! iter = iter->next; } --- 130,144 ---- * list1 on success */ ! struct list_t *list_merge_list(struct list_t *list1, struct list_t *list2, int (*compare)(void *, void *)) { ! struct node_t *iter; ! iter = LIST_FIRST(list2); while(iter != NULL) { ! if(list_add_object(list1, iter->object, compare) == -1) return NULL; ! iter = LIST_NEXT(iter, entries); } *************** *** 157,171 **** /* Returns NULL on error */ ! struct list_t *list_new(int (*compare) (void *, void *)) { struct list_t *list; ! if((list = (stuct list_t *) malloc(sizeof(struct list_t))) == NULL) return NULL; - list->compare = compare; - list->size = 0; - list->head = list->tail = NULL; - return list; } --- 148,158 ---- /* Returns NULL on error */ ! struct list_t *list_new() { struct list_t *list; ! if((list = (struct list_t *) malloc(sizeof(struct list_t))) == NULL) return NULL; return list; } *************** *** 173,210 **** /* Returns NULL on error */ ! node_t *list_new_node(void *object, node_t *next, node_t *prev) { ! node_t *node; ! if((node = (node_t *) malloc(sizeof(node_t))) == NULL) return NULL; node->object = object; - node->next = next; - node->prev = prev; return node; } ! void list_remove(struct list_t *list, void *object) { ! node_t *iter; int i; ! iter = list->head; while(iter != NULL) { ! if((i = list->compare(iter->object, object)) == 0) { ! --(list->size); ! if(iter->next != NULL) ! iter->next->prev = iter->prev; ! else ! list->tail = iter->prev; ! if(iter->prev != NULL) ! iter->prev->next = iter->next; ! else ! list->head = iter->next; free(iter); break; --- 160,187 ---- /* Returns NULL on error */ ! struct node_t *list_new_node(void *object) { ! struct node_t *node; ! if((node = (struct node_t *) malloc(sizeof(struct node_t))) == NULL) return NULL; node->object = object; return node; } ! void list_remove(struct list_t *list, void *object, int (*compare)(void *, void *)) { ! struct node_t *iter; int i; ! iter = LIST_FIRST(list); while(iter != NULL) { ! if((i = compare(iter->object, object)) == 0) { ! LIST_REMOVE(iter, entries); free(iter); break; *************** *** 213,217 **** if(i < 0) break; ! iter = iter->next; } --- 190,194 ---- if(i < 0) break; ! iter = LIST_NEXT(iter, entries); } *************** *** 220,237 **** /* Optimize with quicksort or heapsort I think */ ! struct list_t *list_resort(struct list_t *list) { ! node_t *iter, *tmpiter; ! iter = list->head; ! list->head = list->tail = NULL; ! list->size = 0; while(iter != NULL) { ! if(list_add_object(list, iter->object) == -1) return NULL; tmpiter = iter; ! iter = iter->next; free(tmpiter); } --- 197,213 ---- /* Optimize with quicksort or heapsort I think */ ! struct list_t *list_resort(struct list_t *list, int (*compare)(void *, void *)) { ! struct node_t *iter, *tmpiter; ! iter = LIST_FIRST(list); ! LIST_FIRST(list) = NULL; while(iter != NULL) { ! if(list_add_object(list, iter->object, compare) == -1) return NULL; tmpiter = iter; ! iter = LIST_NEXT(iter, entries); free(tmpiter); } *************** *** 244,256 **** * list on success */ ! struct list_t *list_union(struct list_t *list1, struct list_t *list2) { struct list_t *list; ! if((list = list_new(list1->compare)) == NULL) return NULL; ! if(list_merge_list(list, list1) == NULL) return NULL; ! return list_merge_list(list, list2); } --- 220,232 ---- * list on success */ ! struct list_t *list_union(struct list_t *list1, struct list_t *list2, int (*compare)(void *, void *)) { struct list_t *list; ! if((list = list_new()) == NULL) return NULL; ! if(list_merge_list(list, list1, compare) == NULL) return NULL; ! return list_merge_list(list, list2, compare); } Index: main.c =================================================================== RCS file: /cvsroot/digraphanalysis/digraphanalysis/src/main.c,v retrieving revision 1.2.2.4 retrieving revision 1.2.2.5 diff -C2 -d -r1.2.2.4 -r1.2.2.5 *** main.c 20 Mar 2005 17:42:55 -0000 1.2.2.4 --- main.c 28 Mar 2005 02:09:51 -0000 1.2.2.5 *************** *** 31,48 **** #include "nodedata.h" ! int analyze_key(pgpkey_t *key, list_t *keys, list_t *nnlist, list_t *nslist, list_t *snlist, list_t *sslist) { ! node_t *iter; ! iter = keys->head; pgpkey_msd(key, keys); while(iter != NULL) { ! if(list_find_object(key->signatures, iter->object) != NULL) { ! if(list_find_object(((pgpkey_t *) iter->object)->signatures, key) != NULL) { ! if(list_add_object(sslist, iter->object) == -1) { return -1; --- 31,48 ---- #include "nodedata.h" ! int analyze_key(pgpkey_t *key, struct list_t *keys, struct list_t *nnlist, struct list_t *nslist, struct list_t *snlist, struct list_t *sslist) { ! struct node_t *iter; ! iter = LIST_FIRST(keys); pgpkey_msd(key, keys); while(iter != NULL) { ! if(list_find_object(key->signatures, iter->object, pgpkey_compare) != NULL) { ! if(list_find_object(((pgpkey_t *) iter->object)->signatures, key, pgpkey_compare) != NULL) { ! if(list_add_object(sslist, iter->object, pgpkey_compare) == -1) { return -1; *************** *** 51,55 **** else { ! if(list_add_object(nslist, iter->object) == -1) { return -1; --- 51,55 ---- else { ! if(list_add_object(nslist, iter->object, pgpkey_compare) == -1) { return -1; *************** *** 59,65 **** else { ! if(list_find_object(((pgpkey_t *) iter->object)->signatures, key) != NULL) { ! if(list_add_object(snlist, iter->object) == -1) { return -1; --- 59,65 ---- else { ! if(list_find_object(((pgpkey_t *) iter->object)->signatures, key, pgpkey_compare) != NULL) { ! if(list_add_object(snlist, iter->object, pgpkey_compare) == -1) { return -1; *************** *** 68,72 **** else { ! if(list_add_object(nnlist, iter->object) == -1) { return -1; --- 68,72 ---- else { ! if(list_add_object(nnlist, iter->object, pgpkey_compare) == -1) { return -1; *************** *** 74,78 **** } } ! iter = iter->next; } --- 74,78 ---- } } ! iter = LIST_NEXT(iter, entries); } Index: main.h =================================================================== RCS file: /cvsroot/digraphanalysis/digraphanalysis/src/main.h,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -C2 -d -r1.1.2.2 -r1.1.2.3 *** main.h 20 Mar 2005 17:30:48 -0000 1.1.2.2 --- main.h 28 Mar 2005 02:09:51 -0000 1.1.2.3 *************** *** 25,33 **** #include "node.h" ! int analyze_key(pgpkey_t *, list_t *, list_t *, list_t *, list_t *, list_t *); ! int do_analysis(list_t *, char *); ! void output_file(pgpkey_t *, list_t *, list_t *, list_t *, list_t *); ! list_t *parse_keyring(void); ! void print_list(FILE *, list_t *); void usage(void); int wot_compare(void *, void *); --- 25,33 ---- #include "node.h" ! int analyze_key(pgpkey_t *, struct list_t *, struct list_t *, struct list_t *, struct list_t *, struct list_t *); ! int do_analysis(struct list_t *, char *); ! void output_file(pgpkey_t *, struct list_t *, struct list_t *, struct list_t *, struct list_t *); ! struct list_t *parse_keyring(void); ! void print_list(FILE *, struct list_t *); void usage(void); int wot_compare(void *, void *); |