Import option handler from ponymap
This commit is contained in:
81
zyklonb.c
81
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)
|
||||
struct opt_handler oh;
|
||||
opt_handler_init (&oh, argc, argv, opts, NULL, "Experimental IRC bot.");
|
||||
|
||||
int c;
|
||||
while ((c = opt_handler_get (&oh)) != -1)
|
||||
switch (c)
|
||||
{
|
||||
int c, opt_index;
|
||||
|
||||
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);
|
||||
}
|
||||
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 ();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user