From fe971ea9a828496838648ff4630945752fe73461 Mon Sep 17 00:00:00 2001 From: "B. Stack" Date: Mon, 3 Oct 2022 10:39:38 -0400 Subject: 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. --- experimental/keyboard-leds-trayicons.c | 37 +++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) 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) { -- cgit