(WRITTEN_BY): Rename from AUTHORS.
[platform/upstream/coreutils.git] / src / whoami.c
index 0b48479..be7bc04 100644 (file)
@@ -1,5 +1,5 @@
 /* whoami -- print effective userid
-   Copyright (C) 89, 90, 91, 92, 93, 94, 1995 Free Software Foundation, Inc.
+   Copyright (C) 89,90, 1991-1997, 1999-2002 Free Software Foundation, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -12,8 +12,8 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
+   along with this program; if not, write to the Free Software Foundation,
+   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 
 /* Equivalent to `id -un'. */
 /* Written by Richard Mlynarik. */
 #include <pwd.h>
 #include <getopt.h>
 
-#include "version.h"
 #include "system.h"
+#include "long-options.h"
 
-/* The name this program was run with. */
-char *program_name;
+/* The official name of this program (e.g., no `g' prefix).  */
+#define PROGRAM_NAME "whoami"
 
-/* If non-zero, display usage information and exit.  */
-static int show_help;
+#define WRITTEN_BY _("Written by Richard Mlynarik.")
 
-/* If non-zero, print the version on standard output and exit.  */
-static int show_version;
+/* The name this program was run with. */
+char *program_name;
 
 static struct option const long_options[] =
 {
-  {"help", no_argument, &show_help, 1},
-  {"version", no_argument, &show_version, 1},
   {0, 0, 0, 0}
 };
 
-static void
-usage (status)
-     int status;
+void
+usage (int status)
 {
   if (status != 0)
-    fprintf (stderr, "Try `%s --help' for more information.\n",
+    fprintf (stderr, _("Try `%s --help' for more information.\n"),
             program_name);
   else
     {
-      printf ("Usage: %s [OPTION]...\n", program_name);
-      printf ("\
+      printf (_("Usage: %s [OPTION]...\n"), program_name);
+      fputs (_("\
 Print the user name associated with the current effective user id.\n\
 Same as id -un.\n\
 \n\
-  --help      display this help and exit\n\
-  --version   output version information and exit\n");
+"), stdout);
+      fputs (HELP_OPTION_DESCRIPTION, stdout);
+      fputs (VERSION_OPTION_DESCRIPTION, stdout);
+      printf (_("\nReport bugs to <%s>.\n"), PACKAGE_BUGREPORT);
     }
   exit (status);
 }
 
-void
-main (argc, argv)
-     int argc;
-     char *argv[];
+int
+main (int argc, char **argv)
 {
   register struct passwd *pw;
   register uid_t uid;
   int c;
 
+  initialize_main (&argc, &argv);
   program_name = argv[0];
+  setlocale (LC_ALL, "");
+  bindtextdomain (PACKAGE, LOCALEDIR);
+  textdomain (PACKAGE);
+
+  atexit (close_stdout);
 
-  while ((c = getopt_long (argc, argv, "", long_options, (int *) 0)) != EOF)
+  parse_long_options (argc, argv, PROGRAM_NAME, GNU_PACKAGE, VERSION,
+                     WRITTEN_BY, usage);
+
+  while ((c = getopt_long (argc, argv, "", long_options, NULL)) != -1)
     {
       switch (c)
        {
@@ -82,31 +87,21 @@ main (argc, argv)
          break;
 
        default:
-         usage (1);
+         usage (EXIT_FAILURE);
        }
     }
 
-  if (show_version)
-    {
-      printf ("whoami - %s\n", version_string);
-      exit (0);
-    }
-
-  if (show_help)
-    usage (0);
-
-
   if (optind != argc)
-    usage (1);
+    usage (EXIT_FAILURE);
 
   uid = geteuid ();
   pw = getpwuid (uid);
   if (pw)
     {
       puts (pw->pw_name);
-      exit (0);
+      exit (EXIT_SUCCESS);
     }
-  fprintf (stderr, "%s: cannot find username for UID %u\n",
+  fprintf (stderr, _("%s: cannot find username for UID %u\n"),
           program_name, (unsigned) uid);
-  exit (1);
+  exit (EXIT_FAILURE);
 }