glviewvol

view src/opt.cc @ 14:0d2447b9c512

did the histogram... doesn't seem to work right
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 01 Jan 2015 06:36:45 +0200
parents f22be47a3572
children
line source
1 /*
2 glviewvol is an OpenGL 3D volume data viewer
3 Copyright (C) 2014 John Tsiombikas <nuclear@member.fsf.org>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 #include <stdio.h>
19 #include <string.h>
20 #include "opt.h"
22 static struct {
23 const char *name;
24 RendererType rtype;
25 } rend[] = {
26 { "fast", REND_FAST },
27 { 0, REND_NONE }
28 };
30 Options opt;
32 static void init_opt()
33 {
34 opt.fname = 0;
35 opt.rend_type = REND_FAST;
36 opt.xsz = 800;
37 opt.ysz = 800;
38 }
40 static RendererType renderer_type(const char *name)
41 {
42 for(int i=0; rend[i].name; i++) {
43 if(strcmp(rend[i].name, name) == 0) {
44 return rend[i].rtype;
45 }
46 }
47 return REND_NONE;
48 }
50 int parse_args(int argc, char **argv)
51 {
52 init_opt();
54 for(int i=1; i<argc; i++) {
55 if(argv[i][0] == '-') {
56 if(argv[i][2] == 0) {
57 switch(argv[i][1]) {
58 case 's':
59 if(sscanf(argv[++i], "%dx%d", &opt.xsz, &opt.ysz) != 2) {
60 fprintf(stderr, "-s must be followed by the window size (WxH)\n");
61 return -1;
62 }
63 break;
65 case 'r':
66 if((opt.rend_type = renderer_type(argv[++i])) == REND_NONE) {
67 if(strcmp(argv[i], "help") == 0) {
68 printf("available renderers: ");
69 for(int j=0; rend[j].name; j++) {
70 printf("%s ", rend[j].name);
71 }
72 putchar('\n');
73 return -1;
74 }
75 fprintf(stderr, "unknown renderer type: %s (use -r help to show list of renderers)\n", argv[i]);
76 return -1;
77 }
78 break;
80 default:
81 fprintf(stderr, "invalid option: %s\n", argv[i]);
82 return -1;
83 }
84 } else {
85 fprintf(stderr, "invalid option: %s\n", argv[i]);
86 return -1;
87 }
88 } else {
89 if(opt.fname) {
90 fprintf(stderr, "unexpected argument: %s\n", argv[i]);
91 return -1;
92 }
93 opt.fname = argv[i];
94 }
95 }
97 return 0;
98 }