added -c option
-c is used to override the default config files and instead use the speocified one
This commit is contained in:
parent
5db72c0b43
commit
472daace31
7
hkd.1
7
hkd.1
@ -6,6 +6,7 @@ hkd \- simple HotKey Daemon
|
||||
.SH SYNOPSIS
|
||||
.SY hkd
|
||||
.OP \-v
|
||||
.OP \-c file
|
||||
.YS
|
||||
|
||||
.SH DESCRIPTION
|
||||
@ -22,6 +23,10 @@ correctly.
|
||||
.IP \-v
|
||||
verbose, prints the internal pressed key buffer upon change acting as a crude
|
||||
keylogger :^)
|
||||
.IP "\-c file"
|
||||
override default configuration file location, instead using the specified
|
||||
.I file
|
||||
as the temporary config file
|
||||
|
||||
.SH FILES
|
||||
The configuration files are searched in the following order:
|
||||
@ -86,6 +91,8 @@ Known bugs are:
|
||||
.IP -
|
||||
Commands in the config file cannot be multiline
|
||||
.IP -
|
||||
Invalid config files are not detected properly, or at least not explicitly
|
||||
.IP -
|
||||
Child processes
|
||||
are waited at program exit possibly causing the process tree to hang as there is
|
||||
no real child process control
|
||||
|
38
hkd.c
38
hkd.c
@ -206,9 +206,12 @@ struct hotkey_list_e {
|
||||
};
|
||||
|
||||
struct hotkey_list_e *hotkey_list = NULL;
|
||||
int dead = 0; // exit flag
|
||||
const char evdev_root_dir[] = "/dev/input/";
|
||||
unsigned long hotkey_size_mask = 0;
|
||||
char *ext_config_file = NULL;
|
||||
/* Flags */
|
||||
int vflag = 0;
|
||||
int dead = 0; // exit flag
|
||||
|
||||
/* key buffer operations */
|
||||
int key_buffer_add (struct key_buffer*, unsigned short);
|
||||
@ -237,15 +240,17 @@ int main (int argc, char *argv[])
|
||||
action.sa_handler = int_handler;
|
||||
sigaction(SIGINT, &action, NULL);
|
||||
|
||||
/* Verbose flag */
|
||||
int vflag = 0;
|
||||
|
||||
/* Parse command line arguments */
|
||||
int opc;
|
||||
while ((opc = getopt(argc, argv, "v")) != -1) {
|
||||
while ((opc = getopt(argc, argv, "vc:")) != -1) {
|
||||
switch (opc) {
|
||||
case 'v':
|
||||
vflag = 1;
|
||||
case 'c':
|
||||
ext_config_file = malloc(strlen(optarg) + 1);
|
||||
if (!ext_config_file)
|
||||
die("malloc in main()");
|
||||
strcpy(ext_config_file, optarg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -588,9 +593,29 @@ void hotkey_list_add (struct hotkey_list_e *head, struct key_buffer *kb, char *c
|
||||
|
||||
void parse_config_file (void)
|
||||
{
|
||||
|
||||
wordexp_t result = {0};
|
||||
FILE *fd;
|
||||
if (ext_config_file) {
|
||||
switch (wordexp(ext_config_file, &result, 0)) {
|
||||
case 0:
|
||||
break;
|
||||
case WRDE_NOSPACE:
|
||||
/* If the error was WRDE_NOSPACE,
|
||||
* then perhaps part of the result was allocated */
|
||||
wordfree (&result);
|
||||
die("not enough space")
|
||||
default:
|
||||
/* Some other error */
|
||||
die("path not valid");
|
||||
}
|
||||
|
||||
fd = fopen(result.we_wordv[0], "r");
|
||||
wordfree(&result);
|
||||
if (!fd)
|
||||
die("error opening config file");
|
||||
free(ext_config_file);
|
||||
ext_config_file = NULL;
|
||||
} else {
|
||||
for (int i = 0; i < array_size_const(config_paths); i++) {
|
||||
switch (wordexp(config_paths[i], &result, 0)) {
|
||||
case 0:
|
||||
@ -613,6 +638,7 @@ void parse_config_file (void)
|
||||
}
|
||||
if (!fd)
|
||||
die("could not open any config files, check the log for more details");
|
||||
}
|
||||
|
||||
struct key_buffer kb;
|
||||
for (int linenum = 1;; linenum++) {
|
||||
|
Loading…
Reference in New Issue
Block a user