From 8d7bfe241b730e26175aa49a800c5fc9fdb4909c Mon Sep 17 00:00:00 2001 From: Alex AUVOLAT Date: Mon, 25 Nov 2013 17:39:24 +0100 Subject: Added parser for DIMACS format + some examples. --- main.c | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) (limited to 'main.c') diff --git a/main.c b/main.c index ad07324..50a9f64 100644 --- a/main.c +++ b/main.c @@ -28,11 +28,49 @@ void max_clique_a(const graph g, set k, set c, set *mc) { delete_set(k2); delete_set(c2); } + delete_set(cc); } } -int main() { - graph g = load_graph(stdin); + +// Driver + +void usage(char *pname) { + printf("\nUsage:\n\t%s [options] []\n\n", pname); + printf("Available options:\n"); + printf("\n -d\n\tRead input in DIMACS format\n"); + printf("\n -h, --help\n\tShow this help page\n"); +} + +int main(int argc, char **argv) { + int i; + int dimacs = 0; + char *filename = "-"; + + for (i = 1; i < argc; i++) { + if (!strcmp(argv[i], "-d")) { + dimacs = 1; + } else if (argv[i][0] == '-') { + usage(argv[0]); + return 0; + } else { + filename = argv[i]; + } + } + + FILE *f = stdin; + if (strcmp(filename, "-")) { + f = fopen(filename, "r"); + if (f == NULL) { + fprintf(stderr, "Error: could not open file %s\n", filename); + return 1; + } + } + graph g = (dimacs ? load_graph_dimacs(f) : load_graph(f)); + if (g == NULL) { + fprintf(stderr, "Error loading file %s\n", filename); + return 1; + } dump_graphviz(g, stdout); // do stuff with graph -- cgit v1.2.3