summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex AUVOLAT <alex.auvolat@ens.fr>2013-11-28 10:37:37 +0100
committerAlex AUVOLAT <alex.auvolat@ens.fr>2013-11-28 10:37:37 +0100
commite765e5623ae6c3efd59f1d903b661cd1b7540406 (patch)
tree68bb0d07532696de1c7d17b1c1a560d6d02503ca
parentdc7b29b7dab2a8386f739c02b6a2ac09ebfccefb (diff)
downloadAlgoProg-Projet-e765e5623ae6c3efd59f1d903b661cd1b7540406.tar.gz
AlgoProg-Projet-e765e5623ae6c3efd59f1d903b661cd1b7540406.zip
Added option to dump graph as graphwiz ; unexpected segmentation fault appears.
-rw-r--r--main.c21
1 files 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 <stdlib.h>
+
#include "sets.h"
#include "graph.h"
@@ -40,20 +42,25 @@ void usage(char *pname) {
printf("\nUsage:\n\t%s [options] [<graph file>]\n\n", pname);
printf("Available options:\n");
printf("\n -d\n\tRead input in DIMACS format\n");
+ printf("\n -o <file.dot>\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);