foo
[deeprace] / tools / mklevel / src / main.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include "goat3d.h"
5
6 int parse_args(int argc, char **argv);
7
8 const char *opt_fname;
9 struct goat3d *gscn;
10
11 int main(int argc, char **argv)
12 {
13         if(parse_args(argc, argv) == -1) {
14                 return 1;
15         }
16
17         if(!(gscn = goat3d_create()) || goat3d_load(gscn, opt_fname) == -1) {
18                 return 1;
19         }
20
21         goat3d_free(gscn);
22         return 0;
23 }
24
25 int parse_args(int argc, char **argv)
26 {
27         static const char *usage_fmt = "Usage: %s [options] <goat3d scene file>\n"
28                 "Options:\n"
29                 " -h: print usage and exit\n\n";
30         int i;
31
32         for(i=1; i<argc; i++) {
33                 if(argv[i][0] == '-') {
34                         if(argv[i][2]) {
35                                 fprintf(stderr, "invalid option: %s\n", argv[i]);
36                                 return -1;
37                         }
38                         switch(argv[i][1]) {
39                         case 'h':
40                                 printf(usage_fmt, argv[0]);
41                                 exit(0);
42
43                         default:
44                                 fprintf(stderr, "invalid option: %s\n", argv[i]);
45                                 return -1;
46                         }
47                 } else {
48                         if(opt_fname) {
49                                 fprintf(stderr, "unexpected argument: %s\n", argv[i]);
50                                 return -1;
51                         }
52                         opt_fname = argv[i];
53                 }
54         }
55
56         if(!opt_fname) {
57                 fprintf(stderr, "pass a goat3d scene file to process\n");
58                 return -1;
59         }
60
61         return 0;
62 }