21 #if defined(__linux__)
22 #include <linux/types.h>
34 static const char*
const LIRC_DEBUG_OPTIONS =
"LIRC_DEBUG_OPTIONS";
38 static int options_debug = -1;
46 if (level == LIRC_BADLEVEL)
48 snprintf(s,
sizeof(s),
"%d", level);
49 options_set_opt(
"lircd:debug", s);
54 void options_set_opt(
const char* key,
const char* value)
57 log_warn(
"Cannot set option %s to %s\n", key, value);
61 const char* options_getstring(
const char*
const key)
67 int options_getint(
const char*
const key)
73 int options_getboolean(
const char*
const key)
79 static char* parse_O_arg(
int argc,
char** argv)
83 const int opt_len = strlen(
"--options_file");
85 for (i = 0; i < argc; i += 1) {
86 if (strncmp(argv[i],
"-O", 2) != 0 &&
87 strncmp(argv[i],
"--options-file", opt_len) != 0)
89 if (strchr(argv[i],
'=') != NULL) {
90 path = strchr(argv[i],
'=') + 1;
91 }
else if (strncmp(argv[i],
"-O", 2) == 0 &&
95 }
else if (i + 1 < argc) {
100 if (path && access(path, R_OK) != 0) {
101 fprintf(stderr,
"Cannot open options file %s for read\n",
111 void options_load(
int argc,
char**
const argv,
112 const char* path_arg,
113 void (*parse_options)(
int,
char**
const))
117 const char* path = path_arg;
120 log_warn(
"Error:Cowardly refusing to process"
121 " options-file option within a file\n");
125 setenv(
"POSIXLY_CORRECT",
"1", 1);
127 path = parse_O_arg(argc, argv);
133 if (getcwd(buff2,
sizeof(buff2)) == NULL)
135 snprintf(buff,
sizeof(buff),
"%s/%s", buff2, path);
138 if (access(path, R_OK) == 0) {
140 if (lirc_options == NULL) {
141 log_warn(
"Cannot load options file %s\n", path);
145 fprintf(stderr,
"Warning: cannot open %s\n", path);
149 if (parse_options != NULL)
150 parse_options(argc, argv);
151 if (options_debug == -1)
152 options_debug = getenv(LIRC_DEBUG_OPTIONS) != NULL;
153 if (options_debug && lirc_options != NULL) {
154 fprintf(stderr,
"Dumping parsed option values:\n");
166 s = getenv(
"LIRC_LOGLEVEL");
168 if (level != LIRC_BADLEVEL)
170 if (lirc_options == NULL)
171 options_load(0, NULL, NULL, NULL);
172 if (level == LIRC_BADLEVEL && app != NULL) {
173 snprintf(buff,
sizeof(buff),
"%s:debug", app);
177 if (level == LIRC_BADLEVEL) {
180 if (level == LIRC_BADLEVEL)
187 void options_add_defaults(
const char*
const defaults[])
193 for (i = 0; defaults[i] != NULL; i += 2) {
195 value = defaults[i + 1];
197 options_set_opt((
char*)key, (
char*)value);
201 void options_unload(
void)
205 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.
#define log_warn(fmt,...)
Log a warning message.
loglevel_t options_set_loglevel(const char *optarg)
Parse and store a loglevel, returning value (possibly LIRC_BADLEVEL).
dictionary * dictionary_new(int size)
Create a new dictionary object.
logchannel_t
Log channels used to filter messages.
loglevel_t
The defined loglevels.
void dictionary_del(dictionary *d)
Delete a dictionary object.
#define LIRC_OPTIONS_VAR
Environment variable overriding options file path.
loglevel_t options_get_app_loglevel(const char *app)
Return loglevel based on (falling priority)
#define LIRC_OPTIONS_PATH
Default options file path.
void ciniparser_dump(dictionary *d, FILE *f)
Dump a dictionary to an opened file pointer.
#define log_perror_warn(fmt,...)
perror wrapper logging with level LIRC_WARNING.
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)
Convert a string, either a number or 'info', 'trace1', error etc.