glviewvol

view src/opt.cc @ 3:32c4a7160350

den kanei kryo stin ellada
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 28 Dec 2014 21:48:15 +0200
parents
children f22be47a3572
line source
1 #include <stdio.h>
2 #include <string.h>
3 #include "opt.h"
5 static struct {
6 const char *name;
7 RendererType rtype;
8 } rend[] = {
9 { "fast", REND_FAST },
10 { 0, REND_NONE }
11 };
13 Options opt;
15 static void init_opt()
16 {
17 opt.fname = 0;
18 opt.rend_type = REND_FAST;
19 }
21 static RendererType renderer_type(const char *name)
22 {
23 for(int i=0; rend[i].name; i++) {
24 if(strcmp(rend[i].name, name) == 0) {
25 return rend[i].rtype;
26 }
27 }
28 return REND_NONE;
29 }
31 int parse_args(int argc, char **argv)
32 {
33 init_opt();
35 for(int i=1; i<argc; i++) {
36 if(argv[i][0] == '-') {
37 if(argv[i][2] == 0) {
38 switch(argv[i][1]) {
39 case 'r':
40 if((opt.rend_type = renderer_type(argv[++i])) == REND_NONE) {
41 if(strcmp(argv[i], "help") == 0) {
42 printf("available renderers: ");
43 for(int j=0; rend[j].name; j++) {
44 printf("%s ", rend[j].name);
45 }
46 putchar('\n');
47 return -1;
48 }
49 fprintf(stderr, "unknown renderer type: %s (use -r help to show list of renderers)\n", argv[i]);
50 return -1;
51 }
52 break;
54 default:
55 fprintf(stderr, "invalid option: %s\n", argv[i]);
56 return -1;
57 }
58 } else {
59 fprintf(stderr, "invalid option: %s\n", argv[i]);
60 return -1;
61 }
62 } else {
63 if(opt.fname) {
64 fprintf(stderr, "unexpected argument: %s\n", argv[i]);
65 return -1;
66 }
67 opt.fname = argv[i];
68 }
69 }
71 return 0;
72 }