From 7b91712416953c25f2722fedb57b474504460a48 Mon Sep 17 00:00:00 2001 From: Brian Ashworth Date: Mon, 16 Jul 2018 12:17:16 -0400 Subject: Switch to using getopt_long for config flag --- swaylock/main.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'swaylock') diff --git a/swaylock/main.c b/swaylock/main.c index 4ca53b84..ae5b86b9 100644 --- a/swaylock/main.c +++ b/swaylock/main.c @@ -789,13 +789,16 @@ int main(int argc, char **argv) { wlr_log_init(WLR_DEBUG, NULL); char *config_path = NULL; - for (int i = 0; i < argc; i++) { - if (strcmp(argv[i], "-C") == 0 || strcmp(argv[i], "--config") == 0) { - if (i + 1 == argc) { - wlr_log(WLR_ERROR, "Config file path is missing"); - return 1; - } - config_path = strdup(argv[i + 1]); + static struct option long_options[] = { + {"config", required_argument, NULL, 'C'}, + {0, 0, 0, 0}, + }; + while (1) { + int c = getopt_long(argc, argv, "C:", long_options, NULL); + if (c == -1) { + break; + } else if (c == 'C') { + config_path = strdup(optarg); break; } } -- cgit v1.2.3-54-g00ecf