fixed makefile, made lace stub, updated headers
[mc1516pa.git] / modelchecker / main.c
1 #include <stdio.h>
2 #include <stdbool.h>
3 #include <ctype.h>
4 #include <time.h>
5 #include <unistd.h>
6
7 #include <sylvan.h>
8
9 #include "sokoban.h"
10
11 #define ERRPRINT(fmt, as...) fprintf(stderr, fmt, ## as);
12 #define DPRINT(fmt, as...) if(DEBUG) ERRPRINT(fmt, ## as);
13
14 typedef enum {OBJECT, COORD, HYBRID} strategy;
15
16 //Global variables
17 bool DEBUG = false;
18 strategy strat = HYBRID;
19
20 void usage(char *prg)
21 {
22 ERRPRINT("Usage:\n"
23 "\t%s [opts] [FILE [FILE [...]]]\n"
24 "\n"
25 "Options:\n"
26 "\tAll strategies are mutually exclusive\n"
27 "\t-c coordinate based strategy\n"
28 "\t-o object based strategy\n"
29 "\t-y hybrid strategy\n"
30 // "\t-l LURD lURD verification strategy\n"
31 // "\t-r show all positions that are a valid solution\n"
32 "\n"
33 "\t-d enable verbose debug output\n"
34 "\t-h show this help\n"
35 "\n"
36 "Positional arguments:\n"
37 "\tFILE zero or more sokoban screens\n"
38 "\t when no file is specified stdin will be used\n", prg);
39 }
40
41 void solve(FILE *inputstream)
42 {
43 clock_t time_start_read, time_end_read;
44 clock_t time_start_encode, time_end_encode;
45
46 time_start_read = clock();
47 sokoban_screen *screen = parse_screen(inputstream);
48 if (screen == NULL) printf("Something went wrong...\n");
49 sokoban_print(screen);
50 sokoban_free(screen);
51
52 time_end_read = clock();
53 time_start_encode = clock();
54
55 lace_init(0, 1000000);
56 lace_startup(0, NULL, NULL);
57 LACE_ME;
58 sylvan_init_package(1LL<<21, 1LL<<27, 1LL<<20, 1LL<<26);
59 sylvan_init_bdd(6);
60
61 //ENCODE???
62 switch(strat){
63 case COORD:
64 DPRINT("Encoding coordinate based\n");
65 break;
66 case OBJECT:
67 DPRINT("Encoding object based\n");
68 break;
69 case HYBRID:
70 DPRINT("Encoding hybrid based\n");
71 break;
72 default:
73 ERRPRINT("Huh?");
74 exit(2);
75 }
76 time_end_encode = clock();
77
78 //SOLVE???
79
80 ERRPRINT("Reading: %fs\n",
81 ((double) (time_end_read-time_start_read))/CLOCKS_PER_SEC);
82 ERRPRINT("Encoding: %fs\n",
83 ((double) (time_end_encode-time_start_encode))/CLOCKS_PER_SEC);
84 }
85
86 int main(int argc, char **argv)
87 {
88 int optchar;
89
90 while((optchar = getopt(argc, argv, "cdhoy")) != -1){
91 switch(optchar){
92 case 'c':
93 strat = COORD;
94 DPRINT("Strategy changed to Coordinate based\n");
95 break;
96 case 'd':
97 DEBUG = true;
98 DPRINT("Debug enabled\n");
99 break;
100 case 'h':
101 usage(argv[0]);
102 return 0;
103 case 'o':
104 strat = OBJECT;
105 DPRINT("Strategy changed to Object based\n");
106 break;
107 case 'y':
108 strat = HYBRID;
109 DPRINT("Strategy changed to Hybrid\n");
110 break;
111 case '?':
112 if(isprint(optopt)){
113 ERRPRINT("Unknown option `-%c'.\n", optopt);
114 } else {
115 ERRPRINT("Unknown option char `-\\x%x'.\n", optopt);
116 }
117 return 2;
118 default:
119 break;
120 }
121 }
122
123 if(optind == argc){
124 ERRPRINT("You have not specified a file, reading from stdin\n");
125 solve(stdin);
126 }
127
128 for(int filepathindex = optind; filepathindex < argc; filepathindex++){
129 char *currentfilepath = argv[filepathindex];
130 ERRPRINT("Processing: %s\n", currentfilepath);
131 FILE *currentfile = fopen(currentfilepath, "r");
132 DPRINT("Opening file\n");
133 solve(currentfile);
134 DPRINT("Closing file\n");
135 fclose(currentfile);
136 }
137 return 0;
138 }