Thread: [digraphanalysis-cvs] digraphanalysis/src/digraph_analyze main.c,
Status: Planning
Brought to you by:
jbreker
|
From: Jeff B. <jb...@us...> - 2005-09-17 22:53:53
|
Update of /cvsroot/digraphanalysis/digraphanalysis/src/digraph_analyze In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21203 Added Files: main.c Log Message: Outline digraph_analyze --- NEW FILE: main.c --- /* $Id: main.c,v 1.1 2005/09/17 22:53:46 jbreker Exp $ * * Copyright (C) 2005 Jeff Breker <jb...@sy...> * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include <err.h> #include <stdio.h> #include <stdlib.h> #include <sysexits.h> #include <unistd.h> struct graph *analyze_msd(struct graph *); struct list *analyze_subgraphs(struct graph *); void dump_partial_analysis(struct graph *, struct graph *, struct list *); struct graph *read_input(FILE *); int resume_analysis(char **, char **, struct graph **, struct graph **, struct list **); void usage(void); int write_output(FILE *, struct graph *, struct list *); /* Iterate through the graph and calculate the msd for each node. */ struct graph *analyze_msd(struct graph *graph) { struct graph *graph_msd = NULL; return graph_msd; } /* Iterate through the graph and seperate the nodes into thier respected strongly connected sets. */ struct list *analyze_subgraphs(struct graph *graph_msd) { struct list *subgraphs; if((subgraphs = list_new()) == NULL) err(EX_UNAVAILABLE, "list_new() == NULL"); return subgraphs; } /* Reads in output from gpg2digraph, calculates msd and dumps data back out to * a file readable by digraph_report. */ int main(int argc, char **argv) { int c = 0; FILE *filein = NULL; FILE *fileout = NULL; struct graph *graph_msd = NULL; struct graph *graph_raw = NULL; char *inputfile = NULL; char *outputfile = NULL; char *resumefile = NULL; int rtncode = EX_OK; struct list *subgraphs = NULL; /* Parse arguments */ while((c = getopt(argc, argv, "i:o:r:")) != -1) switch (c) { case 'i': inputfile = optarg; break; case 'o': outputfile = optarg; break; case 'r': resumefile = optarg; break; default: usage(); exit(EX_USAGE); } /* Load the resume file if given */ if(resumefile != NULL) resume_analysis(&inputfile, &outputfile, &graph_raw, &graph_msd, &subgraphs); /* Open the input file or stdin if no file given */ if(inputfile == NULL) filein = stdin; else if((filein = fopen(inputfile, "r")) == NULL) err(errno, "fopen(\"%s\", \"r\") == NULL", inputfile); /* Open the output file or stdout if no file given */ if(outputfile == NULL) fileout = stdout; else if((fileout = fopen(outputfile, "w")) == NULL) err(errno, "fopen(\"%s\", \"w\") == NULL", outputfile); /* Parse the input data */ if(graph_raw == NULL) { graph_raw = read_input(filein); if(graph_raw == NULL) err(EX_UNAVAILABLE, "read_input(filein) == NULL"); } /* Analyze the msd of each node */ if(graph_msd == NULL) { graph_msd = analyze_msd(graph_raw); if(graph_msd == NULL) err(EX_UNAVAILABLE, "analyze_msd(graph_raw) == NULL"); } /* Analyze the entire digraph, seperating strongly connected sets into thier own subgraph of the master graph. */ if(subgraphs == NULL) { subgraphs = analyze_subgraphs(graph_msd); if(subgraphs_by_msd == NULL) err(EX_UNAVAILABLE, "analyze_subgraphs(graph_msd) == NULL"); } /* Output the analysis data */ rtncode = write_output(fileout, graph_msd, subgraphs); if(rtncode != EX_OK) err(EX_UNAVAILABLE, "write_output(fileout, graph_msd, subgraphs) != EX_OK"); /* Close the input and output streams */ if(filein != stdin) fclose(filein); if(fileout != stdout) fclose(fileout); return EX_OK; } void usage(void) { extern char *__progname; fprintf(stderr, "usage: %s [[-i <inputfile>] [-o <outputfile]] || [-r <resumefile>]\n", __progname); return; } |
|
From: Jeff B. <jb...@us...> - 2005-09-18 03:08:40
|
Update of /cvsroot/digraphanalysis/digraphanalysis/src/digraph_analyze In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2648/digraph_analyze Modified Files: main.c Log Message: implement some parts Index: main.c =================================================================== RCS file: /cvsroot/digraphanalysis/digraphanalysis/src/digraph_analyze/main.c,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** main.c 17 Sep 2005 22:53:46 -0000 1.1 --- main.c 18 Sep 2005 03:08:32 -0000 1.2 *************** *** 34,38 **** struct graph *analyze_msd(struct graph *graph) { ! struct graph *graph_msd = NULL; return graph_msd; --- 34,47 ---- struct graph *analyze_msd(struct graph *graph) { ! struct graph *graph_msd = NULL; ! struct listlink *node_link = NULL; ! ! graph_msd = graph_new(graph->alias_list, list_new(node_compare_msd, node_print)); ! ! LIST_FOREACH(node_link, graph->node_list, list) ! { ! node_msd(node_link->object, graph->node_list); ! graph_add_node(graph_msd, node_link->object); ! } return graph_msd; *************** *** 43,51 **** struct list *analyze_subgraphs(struct graph *graph_msd) { ! struct list *subgraphs; ! if((subgraphs = list_new()) == NULL) ! err(EX_UNAVAILABLE, "list_new() == NULL"); return subgraphs; } --- 52,78 ---- struct list *analyze_subgraphs(struct graph *graph_msd) { ! struct graph *graph; ! struct listlink *graph_link; ! struct node *node; ! struct listlink *node_link; ! struct list *subgraphs; ! if((subgraphs = list_new(graph_compare, graph_print)) == NULL) ! err(EX_UNAVAILABLE, "list_new(graph_compare, graph_print) == NULL"); + LIST_FOREACH(node_link, graph_msd->node_list, list) + { + LIST_FOREACH(graph_link, subgraphs, list) + if((node = graph_find_node(graph_link->object, node_link->object)) != NULL) + break; + if(node == NULL) + { + graph = graph_new(graph_msd->alias_list, list_new(node_compare_msd, node_print)); + graph_add_node(graph, node_link->object); + /* todo: Add strongly connected links */ + list_add(subgraphs, graph); + } + } + return subgraphs; } |
|
From: Jeff B. <jb...@us...> - 2005-09-18 13:40:59
|
Update of /cvsroot/digraphanalysis/digraphanalysis/src/digraph_analyze In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9369 Modified Files: main.c Log Message: finish up analyze_subgraphs Index: main.c =================================================================== RCS file: /cvsroot/digraphanalysis/digraphanalysis/src/digraph_analyze/main.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** main.c 18 Sep 2005 03:08:32 -0000 1.2 --- main.c 18 Sep 2005 13:40:51 -0000 1.3 *************** *** 52,75 **** struct list *analyze_subgraphs(struct graph *graph_msd) { ! struct graph *graph; ! struct listlink *graph_link; ! struct node *node; ! struct listlink *node_link; ! struct list *subgraphs; if((subgraphs = list_new(graph_compare, graph_print)) == NULL) err(EX_UNAVAILABLE, "list_new(graph_compare, graph_print) == NULL"); ! LIST_FOREACH(node_link, graph_msd->node_list, list) { LIST_FOREACH(graph_link, subgraphs, list) ! if((node = graph_find_node(graph_link->object, node_link->object)) != NULL) break; if(node == NULL) { graph = graph_new(graph_msd->alias_list, list_new(node_compare_msd, node_print)); ! graph_add_node(graph, node_link->object); ! /* todo: Add strongly connected links */ list_add(subgraphs, graph); } } --- 52,97 ---- struct list *analyze_subgraphs(struct graph *graph_msd) { ! struct graph *graph = NULL; ! struct listlink *graph_link = NULL; ! struct node *node = NULL; ! struct listlink *node_link1 = NULL; ! struct listlink *node_link2 = NULL; ! struct listlink *node_link3 = NULL; ! unsigned int size_old = 0; ! unsigned int size_new = 0; ! struct list *subgraphs = NULL; if((subgraphs = list_new(graph_compare, graph_print)) == NULL) err(EX_UNAVAILABLE, "list_new(graph_compare, graph_print) == NULL"); ! LIST_FOREACH(node_link1, graph_msd->node_list, list) { LIST_FOREACH(graph_link, subgraphs, list) ! if((node = graph_find_node(graph_link->object, node_link1->object)) != NULL) break; if(node == NULL) { + /* Create a new graph and add the node to it. + */ graph = graph_new(graph_msd->alias_list, list_new(node_compare_msd, node_print)); ! graph_add_node(graph, node_link1->object); ! ! /* Add all strongly connected links to the graph. ! */ ! size_new = list_size(graph->node_list); ! while(size_old != size_new) ! { ! size_old = size_new; ! LIST_FOREACH(node_link2, graph->node_list, list) ! LIST_FOREACH(node_link3, node_link2->object->links, list) ! if(list_find(node_link3->object->links, nodelink2->object) != NULL) ! graph_add_node(graph, node_link3->object); ! size_new = list_size(graph->node_list); ! } ! ! /* Add the graph to subgraphs. ! */ list_add(subgraphs, graph); + graph = NULL; } } |
|
From: Jeff B. <jb...@us...> - 2005-09-19 22:04:00
|
Update of /cvsroot/digraphanalysis/digraphanalysis/src/digraph_analyze In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3325 Modified Files: main.c Log Message: remove option to resume, implement in the future Index: main.c =================================================================== RCS file: /cvsroot/digraphanalysis/digraphanalysis/src/digraph_analyze/main.c,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** main.c 18 Sep 2005 13:40:51 -0000 1.3 --- main.c 19 Sep 2005 22:03:51 -0000 1.4 *************** *** 24,30 **** struct graph *analyze_msd(struct graph *); struct list *analyze_subgraphs(struct graph *); - void dump_partial_analysis(struct graph *, struct graph *, struct list *); struct graph *read_input(FILE *); - int resume_analysis(char **, char **, struct graph **, struct graph **, struct list **); void usage(void); int write_output(FILE *, struct graph *, struct list *); --- 24,28 ---- *************** *** 112,116 **** char *inputfile = NULL; char *outputfile = NULL; - char *resumefile = NULL; int rtncode = EX_OK; struct list *subgraphs = NULL; --- 110,113 ---- *************** *** 118,122 **** /* Parse arguments */ ! while((c = getopt(argc, argv, "i:o:r:")) != -1) switch (c) { --- 115,119 ---- /* Parse arguments */ ! while((c = getopt(argc, argv, "i:o:")) != -1) switch (c) { *************** *** 127,133 **** outputfile = optarg; break; - case 'r': - resumefile = optarg; - break; default: usage(); --- 124,127 ---- *************** *** 135,143 **** } - /* Load the resume file if given - */ - if(resumefile != NULL) - resume_analysis(&inputfile, &outputfile, &graph_raw, &graph_msd, &subgraphs); - /* Open the input file or stdin if no file given */ --- 129,132 ---- *************** *** 199,207 **** } void usage(void) { extern char *__progname; ! fprintf(stderr, "usage: %s [[-i <inputfile>] [-o <outputfile]] || [-r <resumefile>]\n", __progname); return; --- 188,236 ---- } + struct graph *read_input(FILE *filein) + { + struct graph *graph = NULL; + + graph = graph_new(list_new(alias_compare, alias_print), list_new(node_compare, node_print)); + + while((line = read_line(filein)) != NULL) + { + type = get_field(&line); + node1 = node_new(get_field(&line)); + if((node_tmp = graph_add_node(graph, node1)) != node1) + { + node_free(node1); + node1 = node_tmp; + } + if(strcmp(type, "n") == 0) + { + alias1 = alias_new(get_field(&line), get_field(&line), node1); + if((alias_tmp = graph_add_alias(graph, alias)) != alias1) + alias_free(alias1); + } + else + if(strcmp(type. "e") == 0) + { + node2 = node_new(get_field(&line)); + if((node_tmp = graph_add_node(graph, node2)) != node2) + { + node_free(node2); + node2 = node_tmp; + } + node_add_link(node1, node2); + } + else + err(ER_DATAERR, "type(%s) is not valid!\n", type); + } + /* *line should == '\0' by now (ie at the very end of what got returned by read_line */ + + return graph; + } + void usage(void) { extern char *__progname; ! fprintf(stderr, "usage: %s [-i <inputfile>] [-o <outputfile]\n", __progname); return; |