Project Info Name.......: gnu-hello
Description: GNU Hello


gnu-hello       
Info
Commit...:91b548af72ef0775c74148798e82702b54a8f22a
Author...:karl <>
Committer:karl <>
Date.....:Fri Nov 28 18:04:37 2008 +0000
Parents..:3802a3e1356de2c4662d7020b117f10ef5746013

Message
[project @ 2008-11-28 18:04:36 by karl]
make last greeting option the one that counts

Changes
diff --git a/doc/ChangeLog b/doc/ChangeLog
line changes: +5/-0
index bae4b25..26ee46a
--- a/doc/ChangeLog
+++ b/doc/ChangeLog
@@ -1,3 +1,8 @@
+2008-11-28  Karl Berry  <karl@gnu.org>
+
+	* hello.texi (Invoking hello): mention that the last-specified
+	greeting option is what counts.
+
 2008-11-05  Karl Berry  <karl@gnu.org>
 
 	* fdl.texi: update to 1.3.

diff --git a/doc/hello.texi b/doc/hello.texi
line changes: +17/-14
index d23858f..9f7c75b
--- a/doc/hello.texi
+++ b/doc/hello.texi
@@ -57,8 +57,8 @@ This manual is for GNU Hello (version @value{VERSION}, @value{UPDATED}).
 
 @menu
 * Overview::		General purpose and information.
-* Sample output::	Sample output from @code{hello}.
-* Invoking hello::	How to run @code{hello}.
+* Sample output::	Sample output from @command{hello}.
+* Invoking hello::	How to run @command{hello}.
 * Reporting bugs::	Sending bug reports and feature suggestions.
 * GNU Free Documentation License:: Copying and sharing this documentation.
 * Concept index::	Index of concepts.
@@ -71,7 +71,7 @@ This manual is for GNU Hello (version @value{VERSION}, @value{UPDATED}).
 @cindex greetings
 @cindex overview
 
-The GNU @code{hello} program
+The GNU @command{hello} program
 (@url{http://www.gnu.org/software/hello/}) produces a familiar,
 friendly greeting.  It allows nonprogrammers to use a classic computer
 science tool which would otherwise be unavailable to them.  Because it
@@ -186,27 +186,30 @@ hi
 
 
 @node Invoking hello
-@chapter Invoking @code{hello}
+@chapter Invoking @command{hello}
 
 @cindex invoking
 @cindex options
 @cindex usage
 @cindex help
 
-The format for running the @code{hello} program is:
+The format for running the @command{hello} program is:
 
 @example
 hello @var{option} @dots{}
 @end example
 
-@code{hello} supports the following options:
+With no options, @command{hello} prints the greeting @samp{Hello,
+world!}.
+
+@command{hello} supports the following options:
 
 @table @option
 @item --greeting=@var{text}
 @itemx -g @var{text}
 @opindex --greeting
 @opindex -g
-Output @var{text}.
+Output @var{text} instead of the default greeting.
 
 @item --help
 @itemx -h
@@ -226,10 +229,8 @@ be mentioned (Hello doesn't have any).
 @itemx -n
 @opindex --next-generation
 @opindex -n
-@cindex Unicode
-@cindex UTF-8
-Output a modern greeting, possibly including box-drawing
-characters or other fancy stuff, using the Unicode UTF-8 locale.
+Output @samp{Hello, world!}, but possibly including box-drawing
+characters or other fancy stuff.
 
 @item --traditional
 @itemx -t
@@ -237,8 +238,7 @@ characters or other fancy stuff, using the Unicode UTF-8 locale.
 @opindex -t
 @cindex traditional
 @cindex modern
-Use the traditional greeting message @samp{hello, world} rather
-than the more modern @samp{Hello, world!}.
+Output the traditional greeting message @samp{hello, world}.
 
 @item --version
 @itemx -v
@@ -249,6 +249,10 @@ standard output and then exit successfully.
 
 @end table
 
+If more than one of the greeting options (@option{-g}, @option{-n},
+@option{-t}, and their long-named equivalents) is specified, whichever
+comes last takes precedence.
+
 
 @node Reporting bugs
 @chapter Reporting bugs
@@ -296,7 +300,6 @@ Emacs Manual}).  Please follow the existing coding style.
 @node Concept index
 @unnumbered Concept index
 
-@cindex tail recursion
 @printindex cp
 
 @bye

diff --git a/doc/version.texi b/doc/version.texi
line changes: +2/-2
index 6405bab..7f3a6e6
--- a/doc/version.texi
+++ b/doc/version.texi
@@ -1,4 +1,4 @@
-@set UPDATED 24 September 2008
-@set UPDATED-MONTH September 2008
+@set UPDATED 28 November 2008
+@set UPDATED-MONTH November 2008
 @set EDITION 2.3.91
 @set VERSION 2.3.91

diff --git a/src/ChangeLog b/src/ChangeLog
line changes: +5/-0
index ec40608..c89e450
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,8 @@
+2008-11-28  Karl Berry  <karl@gnu.org>
+
+	* hello.c (greeting_type): new type.
+	(main): make last greeting option be the one that counts.
+
 2007-06-26  Karl Berry  <karl@gnu.org>
 
 	* hello.c (print_version): update notice in --version.

diff --git a/src/hello.c b/src/hello.c
line changes: +31/-20
index 6e2c7eb..23b5d5f
--- a/src/hello.c
+++ b/src/hello.c
@@ -32,6 +32,12 @@ static const struct option longopts[] =
   { NULL, 0, NULL, 0 }
 };
 
+/* Different types of greetings; only one per invocation.  */
+typedef enum {
+  greet_gnu, greet_new, greet_traditional, greet_user
+} greeting_type;
+
+/* Forward declarations.  */
 static void print_help (void);
 static void print_version (void);
 
@@ -39,8 +45,9 @@ int
 main (int argc, char *argv[])
 {
   int optc;
-  int t = 0, n = 0, lose = 0;
-  const char *greeting = NULL;
+  int lose = 0;
+  const char *greeting_msg = NULL;
+  greeting_type g = greet_gnu;
 
   program_name = argv[0];
 
@@ -53,34 +60,33 @@ main (int argc, char *argv[])
   textdomain (PACKAGE);
 #endif
 
-  /* Even exiting has subtleties.  The /dev/full device on GNU/Linux
-     can be used for testing whether writes are checked properly.  For
-     instance, hello >/dev/full should exit unsuccessfully.  On exit,
-     if any writes failed, change the exit status.  This is
-     implemented in the Gnulib module "closeout".  */
+  /* 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:hntv", longopts, NULL)) != -1)
     switch (optc)
       {
-      /* One goal here is having --help and --version exit immediately,
-         per GNU coding standards.  */
+      /* --help and --version exit immediately, per GNU coding standards.  */
       case 'v':
         print_version ();
         exit (EXIT_SUCCESS);
         break;
       case 'g':
-        greeting = optarg;
+        greeting_msg = optarg;
+        g = greet_user;
         break;
       case 'h':
         print_help ();
         exit (EXIT_SUCCESS);
         break;
       case 'n':
-        n = 1;
+        g = greet_new;
         break;
       case 't':
-        t = 1;
+        g = greet_traditional;
         break;
       default:
         lose = 1;
@@ -99,10 +105,10 @@ main (int argc, char *argv[])
     }
 
   /* Print greeting message and exit. */
-  if (t)
+  if (g == greet_traditional)
     printf (_("hello, world\n"));
 
-  else if (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:
@@ -115,13 +121,18 @@ main (int argc, char *argv[])
 +---------------+\n\
 "));
 
-  else
-    {
-      if (!greeting)
-        greeting = _("Hello, world!");
-      puts (greeting);
-    }
+  else if (g == greet_user)
+    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);
+  }
+
   exit (EXIT_SUCCESS);
 }
 

This website is licensed under AGPL-3.0. Feel free to copy!