diff options
author | B. Stack <bgstack15@gmail.com> | 2022-10-03 10:39:38 -0400 |
---|---|---|
committer | B. Stack <bgstack15@gmail.com> | 2022-10-03 10:43:19 -0400 |
commit | ef3108b43051c3c3d1ca51e3ac32c6b00f1614e6 (patch) | |
tree | f49b20c72a6729d54c8847164f28b704b45fe188 /experimental | |
parent | improvements from rwp code review (diff) | |
download | keyboard-leds-trayicons-ef3108b43051c3c3d1ca51e3ac32c6b00f1614e6.tar.gz keyboard-leds-trayicons-ef3108b43051c3c3d1ca51e3ac32c6b00f1614e6.tar.bz2 keyboard-leds-trayicons-ef3108b43051c3c3d1ca51e3ac32c6b00f1614e6.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.
Diffstat (limited to 'experimental')
-rw-r--r-- | experimental/keyboard-leds-trayicons.c | 35 |
1 files changed, 34 insertions, 1 deletions
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) { |