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