From 98bc17525c76803e5784560ed8c2e0e276d83444 Mon Sep 17 00:00:00 2001 From: Jan Klemkow Date: Sun, 25 Sep 2011 01:34:31 +0200 Subject: Add glib parsing function for argc and argv. --- src/cmumble.c | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/cmumble.c b/src/cmumble.c index 3599f91..82af149 100644 --- a/src/cmumble.c +++ b/src/cmumble.c @@ -239,20 +239,43 @@ cmumble_protocol_init(struct cmumble_context *ctx) g_source_unref(source); } +gchar *user = "unkown"; +gchar *host = "localhost"; +gint port = 64738; + +static GOptionEntry entries[] = { + { + "user", 'u', 0, G_OPTION_ARG_STRING, &user, + "user name", "N" + }, + { + "host", 'h', 0, G_OPTION_ARG_STRING, &host, + "Host name or ip address of the mumble server", "N" + }, + { + "port", 'p', 0, G_OPTION_ARG_INT, &port, + "port of the mumble server", "N" + }, + { NULL } +}; + int main(int argc, char **argv) { - char *host = "localhost"; - unsigned int port = 64738; struct cmumble_context ctx; + GError *error = NULL; + GOptionContext *context; + + context = g_option_context_new ("command line mumble client"); + g_option_context_add_main_entries (context, entries, "cmumble"); - if (argc >= 3) - host = argv[2]; - if (argc >= 4) - port = atoi(argv[3]); + if (!g_option_context_parse (context, &argc, &argv, &error)) { + g_print("option parsing failed: %s\n", error->message); + exit(1); + } memset(&ctx, 0, sizeof(ctx)); - ctx.user_name = argv[1]; + ctx.user_name = user; ctx.users = NULL; g_type_init(); -- cgit