static const struct option longopts[] = {
{"greeting", required_argument, NULL, 'g'},
{"help", no_argument, NULL, 'h'},
- {"next-generation", no_argument, NULL, 'n'},
{"traditional", no_argument, NULL, 't'},
{"version", no_argument, NULL, 'v'},
{NULL, 0, NULL, 0}
};
-/* Different types of greetings; only one per invocation. */
-typedef enum
-{
- greet_traditional,
- greet_new
-} greeting_type;
-
/* Forward declarations. */
static void print_help (void);
static void print_version (void);
-static void print_box (wchar_t * mb_greeting);
-static void print_frame (const size_t len);
int
main (int argc, char *argv[])
const char *greeting_msg;
wchar_t *mb_greeting;
size_t len;
- greeting_type g = greet_traditional;
set_program_name (argv[0]);
This is implemented in the Gnulib module "closeout". */
atexit (close_stdout);
- while ((optc = getopt_long (argc, argv, "g:hntv", longopts, NULL)) != -1)
+ while ((optc = getopt_long (argc, argv, "g:htv", longopts, NULL)) != -1)
switch (optc)
{
/* --help and --version exit immediately, per GNU coding standards. */
print_help ();
exit (EXIT_SUCCESS);
break;
- case 'n':
- g = greet_new;
- break;
case 't':
- g = greet_traditional;
greeting_msg = _("hello, world");
break;
default:
mbsrtowcs(mb_greeting, &greeting_msg, len + 1, NULL);
/* Print greeting message and exit. */
- if (g != greet_new)
- wprintf (L"%ls\n", mb_greeting);
- else
- print_box(mb_greeting);
+ wprintf (L"%ls\n", mb_greeting);
free(mb_greeting);
exit (EXIT_SUCCESS);
}
-/* New format message in box. */
-
-void
-print_box (wchar_t * greeting)
-{
- wchar_t *ignored;
- size_t longest_line = 0;
-
- struct parts
- {
- wchar_t *str;
- size_t len;
- struct parts *next;
- };
- struct parts *first, *p;
-
- first = xmalloc (sizeof (struct parts));
- first->next = NULL;
- p = first;
-
- p->str = wcstok (greeting, L"\n", &ignored);
- p->len = wcslen (p->str);
- while (p->str != NULL)
- {
- size_t i, len_tabs = 0;
- for (i = 0; *(p->str + i) != '\0'; i++)
- {
- if (*(p->str + i) == '\t')
- len_tabs += 8 - (len_tabs + 2) % 8;
- else
- len_tabs++;
- }
- p->len = len_tabs - i;
- if (longest_line < len_tabs)
- longest_line = len_tabs;
- p->next = xmalloc (sizeof (struct parts));
- p = p->next;
- p->str = wcstok (NULL, L"\n", &ignored);
- }
-
- print_frame (longest_line);
- for (p = first; p->str != NULL; p = p->next)
- {
- wprintf (L"| %-*ls |\n", longest_line - p->len, p->str);
- free (p);
- }
- print_frame (longest_line);
- free (p);
-}
-
-
-/* Print new format upper and lower frame. */
-
-void
-print_frame (const size_t len)
-{
- size_t i;
- fputws (L"+-", stdout);
- for (i = 0; i < len; i++)
- putwchar (L'-');
- fputws (L"-+\n", stdout);
-}
-
-
/* Print help info. This long message is split into
several pieces to help translators be able to align different
blocks and identify the various pieces. */
no-wrap */
fputs (_("\
-t, --traditional use traditional greeting\n\
- -n, --next-generation use next-generation greeting\n\
-g, --greeting=TEXT use TEXT as the greeting message\n"), stdout);
printf ("\n");
tmpfiles="last-test1.ok"
cat <<EOF > last-test1.ok
-+----------+
-| my hello |
-+----------+
+my hello
EOF
tmpfiles="$tmpfiles last-test1.out"
: ${HELLO=hello}
-${HELLO} -t -n -g 'my hello' | tr -d '\r' \
+${HELLO} -t -g 'my hello' | tr -d '\r' \
| tr -d '\r' >last-test1.out
: ${DIFF=diff}
-#! /bin/sh
-# Test that last greeting option specified is what counts.
-#
-# Copyright 2013 Free Software Foundation, Inc.
-#
-# Copying and distribution of this file, with or without modification,
-# are permitted in any medium without royalty provided the copyright
-# notice and this notice are preserved.
-# This script takes one argument.
-
-trap 'rm -fr $tmpfiles' 1 2 3 15
-
-# We force the C locale here, since we are checking normal output,
-# which will be translated.
-
-LANGUAGE=
-LC_ALL=C
-LC_MESSAGES=
-LANG=
-export LANGUAGE LC_ALL LC_MESSAGES LANG
-
-tmpfiles="multiline-box-test1.ok"
-cat <<EOF > multiline-box-test1.ok
-+----------+
-| abcd |
-| 1 23 |
-+----------+
-EOF
-
-tmpfiles="$tmpfiles multiline-box-test1.out"
-: ${HELLO=hello}
-${HELLO} -n -g "$(printf abcd\\n1\\t23\\n)" | tr -d '\r' \
-| tr -d '\r' >multiline-box-test1.out
-
-: ${DIFF=diff}
-${DIFF} multiline-box-test1.ok multiline-box-test1.out
-result=$?
-
-rm -fr $tmpfiles
-
-exit $result