1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <strings.h>
5 #include "struct.h"
6
7 #define return_fail(str) { \
8 fprintf(stderr,"%s\n",str); \
9 return(1); \
10 }
11
load_board(file)12 load_board(file)
13 char *file;
14 {
15 FILE *fp;
16 char line[1024],*tok;
17 int x_board_size,y_board_size,xpos,ypos;
18
19 if (!(fp = fopen(file,"r"))) {
20 fprintf(stderr,"Could not open board file %s\n",file);
21 return(1);
22 }
23
24 /* Read board size */
25 fgets(line,1024,fp);
26 if (!(tok= (char *) strtok(line,TOKS)))
27 return_fail("Could not read board size");
28 x_board_size = atoi(tok);
29 if (!(tok=(char *) strtok(NULL,TOKS)))
30 return_fail("Could not read board size");
31 y_board_size = atoi(tok);
32
33 if (allocate_board(x_board_size,y_board_size))
34 return_fail("Invalid board size");
35
36 /* Now for the obstructions */
37 for (fgets(line,1024,fp),fgets(line,1024,fp);
38 (tok= (char *) strtok(line,TOKS));fgets(line,1024,fp)) {
39 xpos = atoi(tok);
40 if (!(tok=(char *) strtok(NULL,TOKS)))
41 return_fail("Invalid pair in obstructions");
42 ypos = atoi(tok);
43 if (add_obstruction(xpos,ypos))
44 return_fail("Obstruction out of range");
45 }
46
47 return(0);
48 }
49