[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 1/8] allow user message to use new-generation greeting format
From: |
Sami Kerola |
Subject: |
[PATCH 1/8] allow user message to use new-generation greeting format |
Date: |
Wed, 9 Oct 2013 20:20:10 +0100 |
---
src/hello.c | 58 +++++++++++++++++++++++++++-------------------------------
tests/last-1 | 4 +++-
2 files changed, 30 insertions(+), 32 deletions(-)
diff --git a/src/hello.c b/src/hello.c
index 2a9587a..6c1fdbd 100644
--- a/src/hello.c
+++ b/src/hello.c
@@ -32,20 +32,22 @@ static const struct option longopts[] =
/* Different types of greetings; only one per invocation. */
typedef enum {
- greet_gnu, greet_new, greet_traditional, greet_user
+ greet_traditional,
+ greet_new
} greeting_type;
/* Forward declarations. */
static void print_help (void);
static void print_version (void);
+static void print_frame (const char *greeting_msg);
int
main (int argc, char *argv[])
{
int optc;
int lose = 0;
- const char *greeting_msg = NULL;
- greeting_type g = greet_gnu;
+ const char *greeting_msg = _("Hello, world!");
+ greeting_type g = greet_traditional;
set_program_name (argv[0]);
@@ -74,7 +76,6 @@ main (int argc, char *argv[])
break;
case 'g':
greeting_msg = optarg;
- g = greet_user;
break;
case 'h':
print_help ();
@@ -84,7 +85,8 @@ main (int argc, char *argv[])
g = greet_new;
break;
case 't':
- g = greet_traditional;
+ g = greet_traditional;
+ greeting_msg = _("hello, world");
break;
default:
lose = 1;
@@ -103,39 +105,33 @@ main (int argc, char *argv[])
}
/* Print greeting message and exit. */
- if (g == greet_traditional)
- printf (_("hello, world\n"));
-
- else if (g == greet_new)
- /* TRANSLATORS: Use box drawing characters or other fancy stuff
- if your encoding (e.g., UTF-8) allows it. If done so add the
- following note, please:
-
- [Note: For best viewing results use a UTF-8 locale, please.]
- */
- printf (_("\
-+---------------+\n\
-| Hello, world! |\n\
-+---------------+\n\
-"));
-
- else if (g == greet_user)
+ if (g != greet_new)
puts (greeting_msg);
-
- else if (g == greet_gnu)
- puts (_("Hello, world!"));
-
- else {
- /* No need for this impossible message to be translated. */
- fprintf (stderr, "Impossible hello value %d\n", g);
- exit (EXIT_FAILURE);
- }
+ else
+ {
+ print_frame (greeting_msg);
+ printf ("| %s |\n", greeting_msg);
+ print_frame (greeting_msg);
+ }
exit (EXIT_SUCCESS);
}
+/* Print new format upper and lower frame. */
+
+void
+print_frame (const char *greeting_msg)
+{
+ size_t i, len = strlen (greeting_msg);
+ fputs ("+-", stdout);
+ for (i = 0; i < len; i++)
+ putchar ('-');
+ fputs ("-+\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. */
diff --git a/tests/last-1 b/tests/last-1
index 2dab7e7..49a21a9 100755
--- a/tests/last-1
+++ b/tests/last-1
@@ -21,7 +21,9 @@ export LANGUAGE LC_ALL LC_MESSAGES LANG
tmpfiles="last-test1.ok"
cat <<EOF > last-test1.ok
-my hello
++----------+
+| my hello |
++----------+
EOF
tmpfiles="$tmpfiles last-test1.out"
--
1.8.2.3
- [PATCH 1/8] allow user message to use new-generation greeting format,
Sami Kerola <=
- [PATCH 2/8] bootstrap: update from gnulib, Sami Kerola, 2013/10/09
- [PATCH 4/8] clean up configure.ac syntax, Sami Kerola, 2013/10/09
- [PATCH 3/8] reuse AM_INIT_AUTOMAKE bug-email address, Sami Kerola, 2013/10/09
- [PATCH 5/8] use PACKAGE_NAME from config.h, Sami Kerola, 2013/10/09
- [PATCH 6/8] re-indent to match with gnu coding style, Sami Kerola, 2013/10/09
- [PATCH 7/8] make copyright year pseudo dynamic, Sami Kerola, 2013/10/09
- [PATCH 8/8] make hello unicode aware, Sami Kerola, 2013/10/09