summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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);