From e765e5623ae6c3efd59f1d903b661cd1b7540406 Mon Sep 17 00:00:00 2001 From: Alex AUVOLAT Date: Thu, 28 Nov 2013 10:37:37 +0100 Subject: Added option to dump graph as graphwiz ; unexpected segmentation fault appears. --- main.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/main.c b/main.c index 0c2d794..0fe2d65 100644 --- a/main.c +++ b/main.c @@ -7,6 +7,8 @@ (cf maxclique.pdf) */ +#include + #include "sets.h" #include "graph.h" @@ -40,20 +42,25 @@ 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 -o \n\tDump graph in graphwiz .dot format\n"); printf("\n -h, --help\n\tShow this help page\n"); + exit(1); } int main(int argc, char **argv) { int i; int dimacs = 0; char *filename = "-"; + char *dump = NULL; for (i = 1; i < argc; i++) { if (!strcmp(argv[i], "-d")) { dimacs = 1; + } else if (!strcmp(argv[i], "-o")) { + if (++i == argc) usage(argv[0]); + dump = argv[i]; } else if (argv[i][0] == '-') { usage(argv[0]); - return 0; } else { filename = argv[i]; } @@ -72,7 +79,17 @@ int main(int argc, char **argv) { fprintf(stderr, "Error loading file %s\n", filename); return 1; } - dump_graphviz(g, stdout); + fclose(f); + + if (dump != NULL) { + f = fopen(dump, "w"); + if (f == NULL) { + fprintf(stderr, "Error: could not open file %s for writing\n", dump); + return 1; + } + dump_graphviz(g, f); + fclose(f); + } // do stuff with graph set max_clique = empty_set(g->N); -- cgit v1.2.3