From 7c908780622319671337986186cda1428b9e0272 Mon Sep 17 00:00:00 2001 From: James Booth Date: Fri, 20 Jul 2012 00:39:21 +0100 Subject: Command line args and welcome message --- src/main.c | 42 +++++++++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 13 deletions(-) (limited to 'src/main.c') diff --git a/src/main.c b/src/main.c index 520fb4bb..8bd5df56 100644 --- a/src/main.c +++ b/src/main.c @@ -19,30 +19,46 @@ * along with Profanity. If not, see . * */ +#include #include #include +#include + #include "profanity.h" +static gboolean disable_tls = FALSE; +static gboolean version = FALSE; + int main(int argc, char **argv) { - int disable_tls = 0; + static GOptionEntry entries[] = + { + { "version", 'v', 0, G_OPTION_ARG_NONE, &version, "Show version information", NULL }, + { "disable-tls", 'd', 0, G_OPTION_ARG_NONE, &disable_tls, "Disable TLS", NULL }, + { NULL } + }; + + GError *error = NULL; + GOptionContext *context; - // more than one argument - if (argc > 2) { - printf("Usage: profanity [-notls]\n"); + context = g_option_context_new(NULL); + g_option_context_add_main_entries(context, entries, NULL); + //g_option_context_add_group(context, gtk_get_option_group (TRUE)); + if (!g_option_context_parse(context, &argc, &argv, &error)) { + g_print("%s\n", error->message); return 1; + } - // argument is not -notls - } else if (argc == 2) { - char *arg1 = argv[1]; - if (strcmp(arg1, "-notls") != 0) { - printf("Usage: profanity [-notls]\n"); - return 1; - } else { - disable_tls = 1; - } + if (version == TRUE) { + g_print("Profanity, version %s\n", PACKAGE_VERSION); + g_print("Copyright (C) 2012 James Booth <%s>.\n", PACKAGE_BUGREPORT); + g_print("License GPLv3+: GNU GPL version 3 or later \n"); + g_print("\n"); + g_print("This is free software; you are free to change and redistribute it.\n"); + g_print("There is NO WARRANTY, to the extent permitted by law.\n"); + return 0; } profanity_init(disable_tls); -- cgit 1.4.1-2-gfad0