From 7bb4e7925697145f67b1fe6e358678dfce43b34c Mon Sep 17 00:00:00 2001 From: Keith Bowes Date: Mon, 9 Mar 2020 21:20:04 -0400 Subject: [PATCH] Openbox-esque help --- waybox/main.c | 39 +++++++++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/waybox/main.c b/waybox/main.c index e09f805..8b8b03a 100644 --- a/waybox/main.c +++ b/waybox/main.c @@ -1,24 +1,38 @@ #include -#include #include #include #include "waybox/server.h" +bool show_help(char *name) +{ + printf(_("Syntax: %s [options]\n"), name); + printf(_("\nOptions:\n")); + printf(_(" --help Display this help and exit\n")); + printf(_(" --version Display the version and exit\n")); + /* TRANSLATORS: If you translate FILE, be sure the text remains aligned. */ + printf(_(" --config-file FILE Specify the path to the config file to use\n")); + printf(_(" --sm-disable Disable connection to the session manager\n")); + printf(_(" --startup CMD Run CMD after starting\n")); + printf(_(" --debug Display debugging output\n")); + printf(_("\nOther Openbox options aren't accepted, " + "mostly due to them being nonsensical on Wayland.\n")); + + return true; +} + int main(int argc, char **argv) { - textdomain(GETTEXT_PACKAGE); + setlocale(LC_ALL, ""); bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR); - setlocale(LC_ALL, NULL); + textdomain(GETTEXT_PACKAGE); char *startup_cmd = NULL; bool debug = false; - if (argc > 0) { + if (argc > 1) { int i; for (i = 0; i < argc; i++) { if (!strcmp("--debug", argv[i]) || !strcmp("-v", argv[i])) { debug = true; - } else if (!strcmp("--exit", argv[i])) { - fprintf(stderr, _("Warning: option %s is currently unimplemented\n"), argv[i]); } else if ((!strcmp("--startup", argv[i]) || !strcmp("-s", argv[i]))) { if (i < argc - 1) { startup_cmd = argv[i + 1]; @@ -28,9 +42,18 @@ int main(int argc, char **argv) { } else if (!strcmp("--version", argv[i]) || !strcmp("-V", argv[i])) { printf(PACKAGE_NAME " " PACKAGE_VERSION "\n"); return 0; + } else if (!strcmp("--help", argv[i]) || !strcmp("-h", argv[i])) { + show_help(argv[0]); + return 0; + } else if (!strcmp("--config-file", argv[i]) || + !strcmp("--sm-disable", argv[i])) { + fprintf(stderr, _("Warning: option '%s' hasn't been implemented yet.\n"), argv[i]); + if (i == argc - 1) { + fprintf(stderr, _("%s requires an argument\n"), argv[i]); + } } else if (argv[i][0] == '-') { - printf(_("Usage: %s [--debug] [--exit] [--help] [--startup CMD] [--version]\n"), argv[0]); - return strcmp("--help", argv[i]) != 0 && strcmp("-h", argv[i]) != 0; + show_help(argv[0]); + return 1; } } }