21 #if defined(__linux__)
22 #include <linux/types.h>
32 static const char*
const LIRC_DEBUG_OPTIONS =
"LIRC_DEBUG_OPTIONS";
36 static int options_debug = -1;
44 if (level == LIRC_BADLEVEL)
46 snprintf(s,
sizeof(s),
"%d", level);
47 options_set_opt(
"lircd:debug", s);
52 void options_set_opt(
const char* key,
const char* value)
55 logprintf(LIRC_WARNING,
56 "Cannot set option %s to %s\n", key, value);
60 const char* options_getstring(
const char*
const key)
66 int options_getint(
const char*
const key)
72 int options_getboolean(
const char*
const key)
77 static const struct option o_option[] = {
78 {
"options-file", required_argument, NULL,
'O' },
83 static char* parse_O_arg(
int argc,
char** argv)
93 while ((c = getopt_long(argc, argv,
"wO:", o_option, NULL)) != -1)
99 if (path && access(path, R_OK) != 0) {
100 fprintf(stderr,
"Cannot open options file %s for read\n",
108 void options_load(
int argc,
char**
const argv,
109 const char* path_arg,
110 void (*parse_options)(
int,
char**
const))
114 const char* path = path_arg;
117 logprintf(LIRC_WARNING,
118 "Error:Cowardly refusing to process"
119 " options-file option within a file\n");
123 setenv(
"POSIXLY_CORRECT",
"1", 1);
125 path = parse_O_arg(argc, argv);
131 if (getcwd(buff2,
sizeof(buff2)) == NULL)
132 logperror(LIRC_WARNING,
"options_load: getcwd():");
133 snprintf(buff,
sizeof(buff),
"%s/%s", buff2, path);
136 if (access(path, R_OK) == 0) {
138 if (lirc_options == NULL) {
139 logprintf(LIRC_WARNING,
140 "Cannot load options file %s\n", path);
144 fprintf(stderr,
"Warning: cannot open %s\n", path);
145 logprintf(LIRC_WARNING,
"Cannot open %s\n", path);
148 parse_options(argc, argv);
149 if (options_debug == -1)
150 options_debug = getenv(LIRC_DEBUG_OPTIONS) != NULL;
151 if (options_debug && lirc_options != NULL) {
152 fprintf(stderr,
"Dumping parsed option values:\n");
158 void options_add_defaults(
const char*
const defaults[])
164 for (i = 0; defaults[i] != NULL; i += 2) {
166 value = defaults[i + 1];
168 options_set_opt((
char*)key, (
char*)value);
172 void options_unload(
void)
176 if (lirc_options != NULL) {
const char * ciniparser_getstring(dictionary *d, const char *key, char *def)
Get the string associated to a key.
int dictionary_set(dictionary *d, const char *key, const char *val)
Set a value in a dictionary.
dictionary * ciniparser_load(const char *ininame)
Parse an ini file and return an allocated dictionary object.
int ciniparser_getint(dictionary *d, const char *key, int notfound)
Get the string associated to a key, convert to an int.
Options management: options file, parse and retrieve.
loglevel_t options_set_loglevel(const char *optarg)
dictionary * dictionary_new(int size)
Create a new dictionary object.
void dictionary_del(dictionary *d)
Delete a dictionary object.
#define LIRC_OPTIONS_PATH
void ciniparser_dump(dictionary *d, FILE *f)
Dump a dictionary to an opened file pointer.
void logperror(loglevel_t prio, const char *fmt,...)
int ciniparser_getboolean(dictionary *d, const char *key, int notfound)
Get the string associated to a key, convert to a boolean.
loglevel_t string2loglevel(const char *s)