[digraphanalysis-cvs] digraphanalysis/src list.c,JBREKER list.h,JBREKER main.c,JBREKER
Status: Planning
Brought to you by:
jbreker
|
From: Jeff B. <jb...@us...> - 2005-04-10 04:00:00
|
Update of /cvsroot/digraphanalysis/digraphanalysis/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3187 Modified Files: Tag: JBREKER list.c list.h main.c Log Message: various changes Index: list.h =================================================================== RCS file: /cvsroot/digraphanalysis/digraphanalysis/src/list.h,v retrieving revision 1.1.2.3 retrieving revision 1.1.2.4 diff -C2 -d -r1.1.2.3 -r1.1.2.4 *** list.h 4 Apr 2005 03:27:36 -0000 1.1.2.3 --- list.h 10 Apr 2005 03:59:48 -0000 1.1.2.4 *************** *** 29,33 **** 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 *)); --- 29,33 ---- LIST_HEAD(list_t, node_t); ! void *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 *)); Index: main.c =================================================================== RCS file: /cvsroot/digraphanalysis/digraphanalysis/src/main.c,v retrieving revision 1.2.2.10 retrieving revision 1.2.2.11 diff -C2 -d -r1.2.2.10 -r1.2.2.11 *** main.c 9 Apr 2005 05:05:02 -0000 1.2.2.10 --- main.c 10 Apr 2005 03:59:48 -0000 1.2.2.11 *************** *** 24,27 **** --- 24,28 ---- #include <stdlib.h> #include <string.h> + #include <sysexits.h> #include <unistd.h> *************** *** 29,33 **** #include "main.h" #include "node.h" - #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) --- 30,33 ---- *************** *** 41,77 **** { 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; ! } ! } else ! { ! if(list_add_object(nslist, iter->object, pgpkey_compare) == -1) ! { ! return -1; ! } ! } ! } 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; ! } ! } else ! { ! if(list_add_object(nnlist, iter->object, pgpkey_compare) == -1) ! { ! return -1; ! } ! } ! } iter = LIST_NEXT(iter, entries); } --- 41,53 ---- { if(list_find_object(key->signatures, iter->object, pgpkey_compare) != NULL) if(list_find_object(((pgpkey_t *) iter->object)->signatures, key, pgpkey_compare) != NULL) ! list_add_object(sslist, iter->object, pgpkey_compare); else ! list_add_object(nslist, iter->object, pgpkey_compare); else if(list_find_object(((pgpkey_t *) iter->object)->signatures, key, pgpkey_compare) != NULL) ! list_add_object(snlist, iter->object, pgpkey_compare); else ! list_add_object(nnlist, iter->object, pgpkey_compare); iter = LIST_NEXT(iter, entries); } *************** *** 133,139 **** { if(((tmplist1 = list_new()) == NULL) || ! ((tmplist2 = list_new()) == NULL) || ! (list_add_object(tmplist1, LIST_FIRST(keys2)->object, &pgpkey_compare_msd) == -1)) return -1; list_remove(keys2, LIST_FIRST(keys2)->object, &pgpkey_compare); while(list_size(tmplist1) != list_size(tmplist2)) --- 109,115 ---- { if(((tmplist1 = list_new()) == NULL) || ! ((tmplist2 = list_new()) == NULL)) return -1; + list_add_object(tmplist1, LIST_FIRST(keys2)->object, &pgpkey_compare_msd); list_remove(keys2, LIST_FIRST(keys2)->object, &pgpkey_compare); while(list_size(tmplist1) != list_size(tmplist2)) *************** *** 150,155 **** if(pgpkey_distance(iter2->object, iter1->object) != 0) { ! if(list_add_object(tmplist1, iter2->object, &pgpkey_compare_msd) == -1) ! return -1; list_remove(keys2, iter2->object, &pgpkey_compare); } --- 126,130 ---- if(pgpkey_distance(iter2->object, iter1->object) != 0) { ! list_add_object(tmplist1, iter2->object, &pgpkey_compare_msd); list_remove(keys2, iter2->object, &pgpkey_compare); } *************** *** 159,164 **** } } ! if(list_add_object(wots, tmplist1, &wot_compare) == -1) ! return -1; list_free(tmplist2); tmplist2 = NULL; --- 134,138 ---- } } ! list_add_object(wots, tmplist1, &wot_compare); list_free(tmplist2); tmplist2 = NULL; *************** *** 236,239 **** --- 210,237 ---- } + char *get_field() + { + char c, *string; + size_t size = 0; + + while(((c = getchar()) != ':') && (c != EOF)) + { + if(!isdigit(c)) + errx(EX_DATAERR, "Invalid data input!\n"); + size = size * 10; + size = size + c - '0'; + printf("%u", size); + } + if(c == EOF) + errx(EX_DATAERR, "Unexpected termination of data input!\n"); + ++size; + string = (char *) malloc(size); + if(string == NULL) + return NULL; + fgets(string, size, stdin); + *(string + size) = '\0'; + return string; + } + int main(int argc, char **argv) { *************** *** 336,340 **** struct list_t *parse_keyring() { ! char c, type; pgpkey_t *key1, *key2, *tmpkey; struct list_t *keys; --- 334,338 ---- struct list_t *parse_keyring() { ! char c, type, *field1, *field2; pgpkey_t *key1, *key2, *tmpkey; struct list_t *keys; *************** *** 342,364 **** keys = list_new(); ! for(c = type = fgetc(stdin); c == 'e' || c == 'n'; c = type = fgetc(stdin)) { ! if(((c = fgetc(stdin)) != ':') && (c != EOF)) ! errx(EX_DATAERR, "Invalid character, %c (ASCII: %d), encountered!\n", c, c); if(c == EOF) break; if((field1 = get_field()) == NULL) ! errx(EX_OSERR, "Cannot allocate memory!\n"); if(*field1 == EOF) break; ! if(((c = fgetc(stdin)) != ':') && (c != EOF)) ! errx(EX_DATAERR, "Invalid character, %c (ASCII: %d), encountered!\n", c, c); if(c == EOF) break; if((field2 = get_field()) == NULL) ! errx(EX_OSERR, "Cannot allocate memory!\n"); if(*field2 == EOF) ! &break; ! if(((c = fgetc()) != '\n') && (c != EOF)) errx(EX_DATAERR, "Invalid character, %c (ASCII: %d), encountered!\n", c, c); --- 340,362 ---- keys = list_new(); ! for(c = type = getchar(); c == 'e' || c == 'n'; c = type = getchar()) { ! if(((c = getchar()) != ':') && (c != EOF)) ! errx(EX_DATAERR, "001 Invalid character, %c (ASCII: %d), encountered!\n", c, c); if(c == EOF) break; if((field1 = get_field()) == NULL) ! errx(EX_OSERR, "001 Cannot allocate memory!\n"); if(*field1 == EOF) break; ! if(((c = getchar()) != ':') && (c != EOF)) ! errx(EX_DATAERR, "002 Invalid character, %c (ASCII: %d), encountered!\n", c, c); if(c == EOF) break; if((field2 = get_field()) == NULL) ! errx(EX_OSERR, "002 Cannot allocate memory!\n"); if(*field2 == EOF) ! break; ! if(((c = getchar()) != '\n') && (c != EOF)) errx(EX_DATAERR, "Invalid character, %c (ASCII: %d), encountered!\n", c, c); *************** *** 376,379 **** --- 374,378 ---- } } + printf(key1->keyid); } else Index: list.c =================================================================== RCS file: /cvsroot/digraphanalysis/digraphanalysis/src/list.c,v retrieving revision 1.1.2.3 retrieving revision 1.1.2.4 diff -C2 -d -r1.1.2.3 -r1.1.2.4 *** list.c 4 Apr 2005 03:27:36 -0000 1.1.2.3 --- list.c 10 Apr 2005 03:59:48 -0000 1.1.2.4 *************** *** 25,35 **** /* Returns: ! * -1 on error ! * 0 if object was not added (ie a compare() call returned 0 with one of the already present objects) ! * 1 if the object was added ! * ! * 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; --- 25,31 ---- /* Returns: ! * object that is in the list or NULL on error */ ! void *list_add_object(struct list_t *list, void *object, int (*compare)(void *, void *)) { int i; *************** *** 41,45 **** { LIST_INSERT_HEAD(list, list_new_node(object), entries); ! return 1; } while(LIST_NEXT(iter, entries) != NULL) --- 37,41 ---- { LIST_INSERT_HEAD(list, list_new_node(object), entries); ! return object; } while(LIST_NEXT(iter, entries) != NULL) *************** *** 51,59 **** else LIST_INSERT_BEFORE(iter, list_new_node(object), entries); ! return 1; } else if(i == 0) ! return 0; iter = LIST_NEXT(iter, entries); } --- 47,55 ---- else LIST_INSERT_BEFORE(iter, list_new_node(object), entries); ! return object; } else if(i == 0) ! return iter->object; iter = LIST_NEXT(iter, entries); } *************** *** 64,74 **** else LIST_INSERT_BEFORE(iter, list_new_node(object), entries); ! return 1; } else if(i == 0) ! return 0; LIST_INSERT_AFTER(iter, list_new_node(object), entries); ! return 1; } --- 60,70 ---- else LIST_INSERT_BEFORE(iter, list_new_node(object), entries); ! return object; } else if(i == 0) ! return iter->object; LIST_INSERT_AFTER(iter, list_new_node(object), entries); ! return object; } *************** *** 134,145 **** 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); ! } return list1; --- 130,135 ---- struct node_t *iter; ! for(iter = LIST_FIRST(list2); iter != NULL; iter = LIST_NEXT(iter, entries)) ! list_add_object(list1, iter->object, compare); return list1; *************** *** 206,211 **** while(iter != NULL) { ! if(list_add_object(list, iter->object, compare) == -1) ! return NULL; tmpiter = iter; iter = LIST_NEXT(iter, entries); --- 196,200 ---- while(iter != NULL) { ! list_add_object(list, iter->object, compare); tmpiter = iter; iter = LIST_NEXT(iter, entries); |