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