/* 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
if (g != greet_new)
wprintf (L"%ls\n", mb_greeting);
else
- {
- print_frame (len);
- wprintf (L"| %ls |\n", mb_greeting);
- print_frame (len);
- }
+ print_box(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
+#! /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