Home | History | Annotate | Line # | Download | only in src
      1 #ifdef HAVE_CONFIG_H
      2 #include "config.h"
      3 #endif
      4 
      5 #include <stdlib.h>
      6 #include <strings.h>
      7 
      8 #include <xf86.h>
      9 #include <xf86Opt.h>
     10 
     11 #include "qxl_option_helpers.h"
     12 
     13 int get_int_option(OptionInfoPtr options, int token,
     14                    const char *env_name)
     15 {
     16     int value;
     17     if (env_name && getenv(env_name)) {
     18         return atoi(getenv(env_name));
     19     }
     20     return xf86GetOptValInteger(options, token, &value) ? value : 0;
     21 }
     22 
     23 const char *get_str_option(OptionInfoPtr options, int token,
     24                            const char *env_name)
     25 {
     26     if (getenv(env_name)) {
     27         return getenv(env_name);
     28     }
     29     return xf86GetOptValString(options, token);
     30 }
     31 
     32 int get_bool_option(OptionInfoPtr options, int token,
     33                      const char *env_name)
     34 {
     35     const char* value = getenv(env_name);
     36 
     37     if (!value) {
     38         return xf86ReturnOptValBool(options, token, FALSE);
     39     }
     40     if (strcmp(value, "0") == 0 ||
     41         strcasecmp(value, "off") == 0 ||
     42         strcasecmp(value, "false") == 0 ||
     43         strcasecmp(value, "no") == 0) {
     44         return FALSE;
     45     }
     46     if (strcmp(value, "1") == 0 ||
     47         strcasecmp(value, "on") == 0 ||
     48         strcasecmp(value, "true") == 0 ||
     49         strcasecmp(value, "yes") == 0) {
     50         return TRUE;
     51     }
     52 
     53     fprintf(stderr, "spice: invalid %s: %s\n", env_name, value);
     54     exit(1);
     55 }
     56