diff options
author | James Booth <boothj5@gmail.com> | 2012-07-20 00:39:21 +0100 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2012-07-20 00:39:21 +0100 |
commit | 7c908780622319671337986186cda1428b9e0272 (patch) | |
tree | 51136a90815575b485cdffe00659f0ca3d79e46f /src/main.c | |
parent | 696848bdc3299e62b883ff71fea8f962f74e2153 (diff) | |
download | profani-tty-7c908780622319671337986186cda1428b9e0272.tar.gz |
Command line args and welcome message
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 42 |
1 files changed, 29 insertions, 13 deletions
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 <http://www.gnu.org/licenses/>. * */ +#include <config.h> #include <stdio.h> #include <string.h> +#include <glib.h> + #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 <http://gnu.org/licenses/gpl.html>\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); |