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