aboutsummaryrefslogtreecommitdiff
path: root/zyklonb.c
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2015-02-11 02:07:52 +0100
committerPřemysl Janouch <p.janouch@gmail.com>2015-02-11 02:07:52 +0100
commitcd1a55a0d1f77aedb078ab9fef96dac94b41c86b (patch)
tree8618c6f854a0f19c87590bdb93f96a4c83566c62 /zyklonb.c
parent59b1c5c056269a5151ef7a17cdedf8a3caccfc61 (diff)
downloadxK-cd1a55a0d1f77aedb078ab9fef96dac94b41c86b.tar.gz
xK-cd1a55a0d1f77aedb078ab9fef96dac94b41c86b.tar.xz
xK-cd1a55a0d1f77aedb078ab9fef96dac94b41c86b.zip
Import option handler from ponymap
Diffstat (limited to 'zyklonb.c')
-rw-r--r--zyklonb.c81
1 files changed, 33 insertions, 48 deletions
diff --git a/zyklonb.c b/zyklonb.c
index 257de7d..f9624b9 100644
--- a/zyklonb.c
+++ b/zyklonb.c
@@ -1,7 +1,7 @@
/*
* zyklonb.c: the experimental IRC bot
*
- * Copyright (c) 2014, Přemysl Janouch <p.janouch@gmail.com>
+ * Copyright (c) 2014 - 2015, Přemysl Janouch <p.janouch@gmail.com>
* All rights reserved.
*
* Permission to use, copy, modify, and/or distribute this software for any
@@ -2150,65 +2150,50 @@ on_signal_pipe_readable (const struct pollfd *fd, struct bot_context *ctx)
}
}
-static void
-print_usage (const char *program_name)
-{
- fprintf (stderr,
- "Usage: %s [OPTION]...\n"
- "Experimental IRC bot.\n"
- "\n"
- " -d, --debug run in debug mode\n"
- " -h, --help display this help and exit\n"
- " -V, --version output version information and exit\n"
- " --write-default-cfg [filename]\n"
- " write a default configuration file and exit\n",
- program_name);
-}
-
int
main (int argc, char *argv[])
{
- const char *invocation_name = argv[0];
str_vector_init (&g_original_argv);
str_vector_add_vector (&g_original_argv, argv);
- static struct option opts[] =
+ static const struct opt opts[] =
{
- { "debug", no_argument, NULL, 'd' },
- { "help", no_argument, NULL, 'h' },
- { "version", no_argument, NULL, 'V' },
- { "write-default-cfg", optional_argument, NULL, 'w' },
- { NULL, 0, NULL, 0 }
+ { 'd', "debug", NULL, 0, "run in debug mode" },
+ { 'h', "help", NULL, 0, "display this help and exit" },
+ { 'V', "version", NULL, 0, "output version information and exit" },
+ { 'w', "write-default-cfg", "FILENAME",
+ OPT_OPTIONAL_ARG | OPT_LONG_ONLY,
+ "write a default configuration file and exit" },
+ { 0, NULL, NULL, 0, NULL }
};
- while (1)
- {
- int c, opt_index;
+ struct opt_handler oh;
+ opt_handler_init (&oh, argc, argv, opts, NULL, "Experimental IRC bot.");
- c = getopt_long (argc, argv, "dhV", opts, &opt_index);
- if (c == -1)
- break;
-
- switch (c)
- {
- case 'd':
- g_debug_mode = true;
- break;
- case 'h':
- print_usage (invocation_name);
- exit (EXIT_SUCCESS);
- case 'V':
- printf (PROGRAM_NAME " " PROGRAM_VERSION "\n");
- exit (EXIT_SUCCESS);
- case 'w':
- call_write_default_config (optarg, g_config_table);
- exit (EXIT_SUCCESS);
- default:
- print_error ("wrong options");
- exit (EXIT_FAILURE);
- }
+ int c;
+ while ((c = opt_handler_get (&oh)) != -1)
+ switch (c)
+ {
+ case 'd':
+ g_debug_mode = true;
+ break;
+ case 'h':
+ opt_handler_usage (&oh, stdout);
+ exit (EXIT_SUCCESS);
+ case 'V':
+ printf (PROGRAM_NAME " " PROGRAM_VERSION "\n");
+ exit (EXIT_SUCCESS);
+ case 'w':
+ call_write_default_config (optarg, g_config_table);
+ exit (EXIT_SUCCESS);
+ default:
+ print_error ("wrong options");
+ opt_handler_usage (&oh, stderr);
+ exit (EXIT_FAILURE);
}
+ opt_handler_free (&oh);
+
print_status (PROGRAM_NAME " " PROGRAM_VERSION " starting");
setup_signal_handlers ();