conworlds

diff src/vr/opt.c @ 8:90abf4b93cc9

fixed line endings fixed viewport when returning to original framebuffer
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 22 Aug 2014 17:24:43 +0300
parents bd8202d6d28d
children e3f0ca1d008a
line diff
     1.1 --- a/src/vr/opt.c	Fri Aug 22 16:55:16 2014 +0300
     1.2 +++ b/src/vr/opt.c	Fri Aug 22 17:24:43 2014 +0300
     1.3 @@ -1,81 +1,77 @@
     1.4 -#include <stdio.h>
     1.5 -#include <stdlib.h>
     1.6 -#include <string.h>
     1.7 -#include <errno.h>
     1.8 -#include "opt.h"
     1.9 -#include "rbtree.h"
    1.10 -
    1.11 -static void opt_del_func(void *opt, void *cls)
    1.12 -{
    1.13 -	free(opt);
    1.14 -}
    1.15 -
    1.16 -void *create_options(void)
    1.17 -{
    1.18 -	struct rbtree *db = rb_create(RB_KEY_STRING);
    1.19 -	rb_set_delete_func(db, opt_del_func, 0);
    1.20 -	return db;
    1.21 -}
    1.22 -
    1.23 -void destroy_options(void *optdb)
    1.24 -{
    1.25 -	rb_destroy(optdb);
    1.26 -}
    1.27 -
    1.28 -void set_option_int(void *optdb, const char *key, int val)
    1.29 -{
    1.30 -	struct option *opt = malloc(sizeof *opt);
    1.31 -	if(!opt) {
    1.32 -		fprintf(stderr, "failed to set option: %s: %s\n", key, strerror(errno));
    1.33 -		return;
    1.34 -	}
    1.35 -	opt->type = OTYPE_INT;
    1.36 -	opt->ival = val;
    1.37 -	opt->fval = (float)val;
    1.38 -
    1.39 -	if(rb_insert(optdb, (void*)key, opt) == -1) {
    1.40 -		fprintf(stderr, "failed to set option: %s\n", key);
    1.41 -	}
    1.42 -	printf("stored %s -> %p\n", key, opt);
    1.43 -}
    1.44 -
    1.45 -void set_option_float(void *optdb, const char *key, float val)
    1.46 -{
    1.47 -	struct option *opt = malloc(sizeof *opt);
    1.48 -	if(!opt) {
    1.49 -		fprintf(stderr, "failed to set option: %s: %s\n", key, strerror(errno));
    1.50 -		return;
    1.51 -	}
    1.52 -	opt->type = OTYPE_FLOAT;
    1.53 -	opt->fval = val;
    1.54 -	opt->ival = (int)val;
    1.55 -
    1.56 -	if(rb_insert(optdb, (void*)key, opt) == -1) {
    1.57 -		fprintf(stderr, "failed to set option: %s\n", key);
    1.58 -	}
    1.59 -	printf("stored %s -> %p\n", key, opt);
    1.60 -}
    1.61 -
    1.62 -int get_option_int(void *optdb, const char *key, int *val)
    1.63 -{
    1.64 -	struct option *opt = rb_find(optdb, (void*)key);
    1.65 -	if(!opt) {
    1.66 -		*val = 0;
    1.67 -		return -1;
    1.68 -	}
    1.69 -	printf("got %s -> %p\n", key, opt);
    1.70 -	*val = opt->ival;
    1.71 -	return 0;
    1.72 -}
    1.73 -
    1.74 -int get_option_float(void *optdb, const char *key, float *val)
    1.75 -{
    1.76 -	struct option *opt = rb_find(optdb, (void*)key);
    1.77 -	if(!opt) {
    1.78 -		*val = 0.0f;
    1.79 -		return -1;
    1.80 -	}
    1.81 -	printf("got %s -> %p\n", key, opt);
    1.82 -	*val = opt->fval;
    1.83 -	return 0;
    1.84 -}
    1.85 +#include <stdio.h>
    1.86 +#include <stdlib.h>
    1.87 +#include <string.h>
    1.88 +#include <errno.h>
    1.89 +#include "opt.h"
    1.90 +#include "rbtree.h"
    1.91 +
    1.92 +static void opt_del_func(void *opt, void *cls)
    1.93 +{
    1.94 +	free(opt);
    1.95 +}
    1.96 +
    1.97 +void *create_options(void)
    1.98 +{
    1.99 +	struct rbtree *db = rb_create(RB_KEY_STRING);
   1.100 +	rb_set_delete_func(db, opt_del_func, 0);
   1.101 +	return db;
   1.102 +}
   1.103 +
   1.104 +void destroy_options(void *optdb)
   1.105 +{
   1.106 +	rb_destroy(optdb);
   1.107 +}
   1.108 +
   1.109 +void set_option_int(void *optdb, const char *key, int val)
   1.110 +{
   1.111 +	struct option *opt = malloc(sizeof *opt);
   1.112 +	if(!opt) {
   1.113 +		fprintf(stderr, "failed to set option: %s: %s\n", key, strerror(errno));
   1.114 +		return;
   1.115 +	}
   1.116 +	opt->type = OTYPE_INT;
   1.117 +	opt->ival = val;
   1.118 +	opt->fval = (float)val;
   1.119 +
   1.120 +	if(rb_insert(optdb, (void*)key, opt) == -1) {
   1.121 +		fprintf(stderr, "failed to set option: %s\n", key);
   1.122 +	}
   1.123 +}
   1.124 +
   1.125 +void set_option_float(void *optdb, const char *key, float val)
   1.126 +{
   1.127 +	struct option *opt = malloc(sizeof *opt);
   1.128 +	if(!opt) {
   1.129 +		fprintf(stderr, "failed to set option: %s: %s\n", key, strerror(errno));
   1.130 +		return;
   1.131 +	}
   1.132 +	opt->type = OTYPE_FLOAT;
   1.133 +	opt->fval = val;
   1.134 +	opt->ival = (int)val;
   1.135 +
   1.136 +	if(rb_insert(optdb, (void*)key, opt) == -1) {
   1.137 +		fprintf(stderr, "failed to set option: %s\n", key);
   1.138 +	}
   1.139 +}
   1.140 +
   1.141 +int get_option_int(void *optdb, const char *key, int *val)
   1.142 +{
   1.143 +	struct option *opt = rb_find(optdb, (void*)key);
   1.144 +	if(!opt) {
   1.145 +		*val = 0;
   1.146 +		return -1;
   1.147 +	}
   1.148 +	*val = opt->ival;
   1.149 +	return 0;
   1.150 +}
   1.151 +
   1.152 +int get_option_float(void *optdb, const char *key, float *val)
   1.153 +{
   1.154 +	struct option *opt = rb_find(optdb, (void*)key);
   1.155 +	if(!opt) {
   1.156 +		*val = 0.0f;
   1.157 +		return -1;
   1.158 +	}
   1.159 +	*val = opt->fval;
   1.160 +	return 0;
   1.161 +}