aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorB. Stack <bgstack15@gmail.com>2022-10-03 10:39:38 -0400
committerB. Stack <bgstack15@gmail.com>2022-10-03 10:39:38 -0400
commitfe971ea9a828496838648ff4630945752fe73461 (patch)
tree18353475a5cdff389b413a499e4ada4843069a74
parentimprovements from rwp code review (diff)
downloadkeyboard-leds-trayicons-fe971ea9a828496838648ff4630945752fe73461.tar.gz
keyboard-leds-trayicons-fe971ea9a828496838648ff4630945752fe73461.tar.bz2
keyboard-leds-trayicons-fe971ea9a828496838648ff4630945752fe73461.zip
WIP: add getopt
Commit for code review from #devuan-dev room. Unfortunately, any use of flags in the while(getopt) loop causes the system tray icons to malfunction. If a parameter-with-value is used, the tray icons are entirely absent. If a parameter flag is used by itself, the tray icons do not load their icons.
-rw-r--r--experimental/keyboard-leds-trayicons.c37
1 files changed, 36 insertions, 1 deletions
diff --git a/experimental/keyboard-leds-trayicons.c b/experimental/keyboard-leds-trayicons.c
index 676849e..ef6471e 100644
--- a/experimental/keyboard-leds-trayicons.c
+++ b/experimental/keyboard-leds-trayicons.c
@@ -654,7 +654,8 @@ typedef struct {
} configuration;
// this should be configurable with -c parameter (getopts?)
-char* conffile = "/home/bgstack15/keyboard-leds-trayicons.conf";
+char* conffile = "NONE";
+int debug = 0;
// slightly modified from example https://github.com/benhoyt/inih
static int handler(void* user, const char* section, const char* name, const char* value) {
@@ -704,8 +705,42 @@ void sig_usr(int signo) {
return;
}
+int fprint_usage(char **argv) {
+ printf("Usage: %s [-c CONFFILE] [-d] [-h]\n", *argv);
+ printf("Create a system tray icon as specified\n");
+ printf("\n");
+ printf(" -c CONFFILE\tUse the specified config file (required)\n");
+ printf(" -d \tTurn debug messages on\n");
+ printf(" -h \t\tDisplay this help message\n");
+ printf("\n");
+ //printf("If a FIFO is not provided, mktrayicon will run until killed\n");
+ //printf("Report bugs at https://github.com/jonhoo/mktrayicon\n");
+ return 0;
+}
+
+
int main(int argc, char **argv) {
+ conffile = "/home/bgstack15/keyboard-leds-trayicons.conf";
+
+ // Step 0: parse parameters
+ int c;
+ while ((c = getopt(argc, argv, "c:dh")) != -1)
+ switch (c) {
+ case 'c':
+ conffile = optarg;
+ break;
+ case 'd':
+ debug = 1;
+ break;
+ case 'h':
+ return print_usage(argv);
+ break;
+ case '?':
+ fprintf(stderr, "Unknown option: %c\n", optopt);
+ return 1;
+ };
+
// Step 1: load config
configuration config;
if (ini_parse(conffile, handler, &config) < 0) {
bgstack15