From ef3108b43051c3c3d1ca51e3ac32c6b00f1614e6 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 | 35 +++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) (limited to 'experimental/keyboard-leds-trayicons.c') diff --git a/experimental/keyboard-leds-trayicons.c b/experimental/keyboard-leds-trayicons.c index 676849e..9e32822 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,40 @@ 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 \tDisplay this help message\n"); + printf("\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 fprint_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