glviewvol

annotate 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
rev   line source
nuclear@3 1 #include <stdio.h>
nuclear@3 2 #include <string.h>
nuclear@3 3 #include "opt.h"
nuclear@3 4
nuclear@3 5 static struct {
nuclear@3 6 const char *name;
nuclear@3 7 RendererType rtype;
nuclear@3 8 } rend[] = {
nuclear@3 9 { "fast", REND_FAST },
nuclear@3 10 { 0, REND_NONE }
nuclear@3 11 };
nuclear@3 12
nuclear@3 13 Options opt;
nuclear@3 14
nuclear@3 15 static void init_opt()
nuclear@3 16 {
nuclear@3 17 opt.fname = 0;
nuclear@3 18 opt.rend_type = REND_FAST;
nuclear@6 19 opt.xsz = 800;
nuclear@6 20 opt.ysz = 800;
nuclear@3 21 }
nuclear@3 22
nuclear@3 23 static RendererType renderer_type(const char *name)
nuclear@3 24 {
nuclear@3 25 for(int i=0; rend[i].name; i++) {
nuclear@3 26 if(strcmp(rend[i].name, name) == 0) {
nuclear@3 27 return rend[i].rtype;
nuclear@3 28 }
nuclear@3 29 }
nuclear@3 30 return REND_NONE;
nuclear@3 31 }
nuclear@3 32
nuclear@3 33 int parse_args(int argc, char **argv)
nuclear@3 34 {
nuclear@3 35 init_opt();
nuclear@3 36
nuclear@3 37 for(int i=1; i<argc; i++) {
nuclear@3 38 if(argv[i][0] == '-') {
nuclear@3 39 if(argv[i][2] == 0) {
nuclear@3 40 switch(argv[i][1]) {
nuclear@6 41 case 's':
nuclear@6 42 if(sscanf(argv[++i], "%dx%d", &opt.xsz, &opt.ysz) != 2) {
nuclear@6 43 fprintf(stderr, "-s must be followed by the window size (WxH)\n");
nuclear@6 44 return -1;
nuclear@6 45 }
nuclear@6 46 break;
nuclear@6 47
nuclear@3 48 case 'r':
nuclear@3 49 if((opt.rend_type = renderer_type(argv[++i])) == REND_NONE) {
nuclear@3 50 if(strcmp(argv[i], "help") == 0) {
nuclear@3 51 printf("available renderers: ");
nuclear@3 52 for(int j=0; rend[j].name; j++) {
nuclear@3 53 printf("%s ", rend[j].name);
nuclear@3 54 }
nuclear@3 55 putchar('\n');
nuclear@3 56 return -1;
nuclear@3 57 }
nuclear@3 58 fprintf(stderr, "unknown renderer type: %s (use -r help to show list of renderers)\n", argv[i]);
nuclear@3 59 return -1;
nuclear@3 60 }
nuclear@3 61 break;
nuclear@3 62
nuclear@3 63 default:
nuclear@3 64 fprintf(stderr, "invalid option: %s\n", argv[i]);
nuclear@3 65 return -1;
nuclear@3 66 }
nuclear@3 67 } else {
nuclear@3 68 fprintf(stderr, "invalid option: %s\n", argv[i]);
nuclear@3 69 return -1;
nuclear@3 70 }
nuclear@3 71 } else {
nuclear@3 72 if(opt.fname) {
nuclear@3 73 fprintf(stderr, "unexpected argument: %s\n", argv[i]);
nuclear@3 74 return -1;
nuclear@3 75 }
nuclear@3 76 opt.fname = argv[i];
nuclear@3 77 }
nuclear@3 78 }
nuclear@3 79
nuclear@3 80 return 0;
nuclear@3 81 }