glviewvol

view src/opt.cc @ 6:f22be47a3572

moved to TransferFuncs completely
author John Tsiombikas <nuclear@member.fsf.org>
date Tue, 30 Dec 2014 06:22:54 +0200
parents 32c4a7160350
children 773f89037a35
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 opt.xsz = 800;
20 opt.ysz = 800;
21 }
23 static RendererType renderer_type(const char *name)
24 {
25 for(int i=0; rend[i].name; i++) {
26 if(strcmp(rend[i].name, name) == 0) {
27 return rend[i].rtype;
28 }
29 }
30 return REND_NONE;
31 }
33 int parse_args(int argc, char **argv)
34 {
35 init_opt();
37 for(int i=1; i<argc; i++) {
38 if(argv[i][0] == '-') {
39 if(argv[i][2] == 0) {
40 switch(argv[i][1]) {
41 case 's':
42 if(sscanf(argv[++i], "%dx%d", &opt.xsz, &opt.ysz) != 2) {
43 fprintf(stderr, "-s must be followed by the window size (WxH)\n");
44 return -1;
45 }
46 break;
48 case 'r':
49 if((opt.rend_type = renderer_type(argv[++i])) == REND_NONE) {
50 if(strcmp(argv[i], "help") == 0) {
51 printf("available renderers: ");
52 for(int j=0; rend[j].name; j++) {
53 printf("%s ", rend[j].name);
54 }
55 putchar('\n');
56 return -1;
57 }
58 fprintf(stderr, "unknown renderer type: %s (use -r help to show list of renderers)\n", argv[i]);
59 return -1;
60 }
61 break;
63 default:
64 fprintf(stderr, "invalid option: %s\n", argv[i]);
65 return -1;
66 }
67 } else {
68 fprintf(stderr, "invalid option: %s\n", argv[i]);
69 return -1;
70 }
71 } else {
72 if(opt.fname) {
73 fprintf(stderr, "unexpected argument: %s\n", argv[i]);
74 return -1;
75 }
76 opt.fname = argv[i];
77 }
78 }
80 return 0;
81 }