exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
}
-int
-main (int argc, char *argv[])
+void
+parse_options (int argc, char *argv[], const char **greeting_msg)
{
int optc;
int lose = 0;
- const char *greeting_msg;
- wchar_t *mb_greeting;
- mbstate_t mbstate = { 0, };
- size_t len;
-
enum {
OPT_HELP = CHAR_MAX + 1,
OPT_VERSION
{NULL, 0, NULL, 0}
};
- set_program_name (argv[0]);
-
- /* Set locale via LC_ALL. */
- setlocale (LC_ALL, "");
-
-#if ENABLE_NLS
- /* Set the text message domain. */
- bindtextdomain (PACKAGE, LOCALEDIR);
- textdomain (PACKAGE);
-#endif
-
- /* Having initialized gettext, get the default message. */
- greeting_msg = _("Hello, world!");
-
- /* Even exiting has subtleties. On exit, if any writes failed, change
- the exit status. The /dev/full device on GNU/Linux can be used for
- testing; for instance, hello >/dev/full should exit unsuccessfully.
- This is implemented in the Gnulib module "closeout". */
- atexit (close_stdout);
-
while ((optc = getopt_long (argc, argv, "g:t", longopts, NULL)) != -1)
switch (optc)
{
exit (EXIT_SUCCESS);
break;
case 'g':
- greeting_msg = optarg;
+ *greeting_msg = optarg;
break;
case OPT_HELP:
print_help (stdout);
case 't':
- greeting_msg = _("hello, world");
+ *greeting_msg = _("hello, world");
break;
default:
lose = 1;
emit_try_help ();
exit (EXIT_FAILURE);
}
+}
+
+int
+main (int argc, char *argv[])
+{
+ const char *greeting_msg;
+ wchar_t *mb_greeting;
+ mbstate_t mbstate = { 0, };
+ size_t len;
+
+ set_program_name (argv[0]);
+
+ /* Set locale via LC_ALL. */
+ setlocale (LC_ALL, "");
+
+#if ENABLE_NLS
+ /* Set the text message domain. */
+ bindtextdomain (PACKAGE, LOCALEDIR);
+ textdomain (PACKAGE);
+#endif
+
+ /* Having initialized gettext, get the default message. */
+ greeting_msg = _("Hello, world!");
+
+ /* Even exiting has subtleties. On exit, if any writes failed, change
+ the exit status. The /dev/full device on GNU/Linux can be used for
+ testing; for instance, hello >/dev/full should exit unsuccessfully.
+ This is implemented in the Gnulib module "closeout". */
+ atexit (close_stdout);
+
+ parse_options(argc, argv, &greeting_msg);
len = strlen(greeting_msg) + 1;
mb_greeting = xmalloc(len * sizeof(wchar_t));