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;
43 if (level == LIRC_BADLEVEL)
45 snprintf(s,
sizeof(s),
"%d", level);
46 options_set_opt(
"lircd:debug", s);
51 void options_set_opt(
const char* key,
const char* value)
54 logprintf(LIRC_WARNING,
55 "Cannot set option %s to %s\n", key, value);
59 const char* options_getstring(
const char*
const key)
65 int options_getint(
const char*
const key)
71 int options_getboolean(
const char*
const key)
76 static const struct option o_option[] = {
77 {
"options-file", required_argument, NULL,
'O'},
82 static char* parse_O_arg(
int argc,
char** argv)
92 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);
132 if (getcwd(buff2,
sizeof(buff2)) == NULL) {
133 logperror(LIRC_WARNING,
"options_load: getcwd():");
135 snprintf(buff,
sizeof(buff),
"%s/%s", buff2, path);
138 if (access(path, R_OK) == 0) {
140 if (lirc_options == NULL) {
141 logprintf(LIRC_WARNING,
142 "Cannot load options file %s\n", path);
147 fprintf(stderr,
"Warning: cannot open %s\n", path);
148 logprintf(LIRC_WARNING,
"Warning: cannot open %s\n", path);
151 parse_options(argc, argv);
152 if (options_debug == -1)
153 options_debug = getenv(LIRC_DEBUG_OPTIONS) != NULL;
154 if (options_debug && lirc_options != NULL ) {
155 fprintf(stderr,
"Dumping parsed option values:\n" );
161 void options_add_defaults(
const char*
const defaults[])
167 for(i = 0; defaults[i] != NULL; i += 2){
169 value = defaults[i + 1];
171 options_set_opt((
char*)key, (
char*)value);
175 void options_unload(
void)
179 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)