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)
78 static const struct option o_option[] = {
79 {
"options-file", required_argument, NULL,
'O' },
84 static char* parse_O_arg(
int argc,
char** argv)
89 for (i = 0; i < argc; i += 1) {
90 if (strcmp(argv[i],
"-O") != 0 &&
91 strcmp(argv[i],
"--options-file") != 0)
96 if (path && access(path, R_OK) != 0) {
97 fprintf(stderr,
"Cannot open options file %s for read\n",
107 void options_load(
int argc,
char**
const argv,
108 const char* path_arg,
109 void (*parse_options)(
int,
char**
const))
113 const char* path = path_arg;
116 log_warn(
"Error:Cowardly refusing to process" 117 " options-file option within a file\n");
121 setenv(
"POSIXLY_CORRECT",
"1", 1);
123 path = parse_O_arg(argc, argv);
129 if (getcwd(buff2,
sizeof(buff2)) == NULL)
131 snprintf(buff,
sizeof(buff),
"%s/%s", buff2, path);
134 if (access(path, R_OK) == 0) {
136 if (lirc_options == NULL) {
137 log_warn(
"Cannot load options file %s\n", path);
141 fprintf(stderr,
"Warning: cannot open %s\n", path);
145 if (parse_options != NULL)
146 parse_options(argc, argv);
147 if (options_debug == -1)
148 options_debug = getenv(LIRC_DEBUG_OPTIONS) != NULL;
149 if (options_debug && lirc_options != NULL) {
150 fprintf(stderr,
"Dumping parsed option values:\n");
162 s = getenv(
"LIRC_LOGLEVEL");
164 if (level != LIRC_BADLEVEL)
166 if (lirc_options == NULL)
167 options_load(0, NULL, NULL, NULL);
168 if (level == LIRC_BADLEVEL && app != NULL) {
169 snprintf(buff,
sizeof(buff),
"%s:debug", app);
173 if (level == LIRC_BADLEVEL) {
176 if (level == LIRC_BADLEVEL)
183 void options_add_defaults(
const char*
const defaults[])
189 for (i = 0; defaults[i] != NULL; i += 2) {
191 value = defaults[i + 1];
193 options_set_opt((
char*)key, (
char*)value);
197 void options_unload(
void)
201 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,...)
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.
loglevel_t options_get_app_loglevel(const char *app)
#define LIRC_OPTIONS_PATH
void ciniparser_dump(dictionary *d, FILE *f)
Dump a dictionary to an opened file pointer.
#define log_perror_warn(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)