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