[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; } |