OSDN Git Service

Make clearfat accept --help and --version options.
authorJim Meyering <jim@meyering.net>
Mon, 5 Mar 2007 13:47:02 +0000 (14:47 +0100)
committerJim Meyering <jim@meyering.net>
Mon, 5 Mar 2007 13:47:02 +0000 (14:47 +0100)
* debug/clearfat/clearfat.c (AUTHORS, PROGRAM_NAME): Define.
Include gettext-related things.
Include closeout.h.
(usage): New function.
(main): Set up for translations, use close_stdout.
* bootstrap.conf: Add long-options, for clearfat.
* debug/clearfat/Makefile.am: Use gnulib.

bootstrap.conf
debug/clearfat/Makefile.am
debug/clearfat/clearfat.c
lib/.gitignore
po/POTFILES.in

index b874d93..93a8eb9 100644 (file)
@@ -46,6 +46,7 @@ gnulib_modules="
        gnupload
        inttypes
        lib-ignore
+       long-options
        malloc
        realloc
        rpmatch
index 0101ceb..7409f45 100644 (file)
@@ -2,11 +2,13 @@ noinst_PROGRAMS       = clearfat
 
 clearfat_SOURCES = clearfat.c
 
-clearfat_LDADD = $(LIBS) $(PARTED_LIBS) \
-               $(top_builddir)/libparted/libparted.la
+clearfat_LDADD = \
+  $(top_builddir)/lib/libparted.la \
+  $(top_builddir)/libparted/libparted.la \
+  $(INTLLIBS) $(LIBS) \
+  $(PARTED_LIBS)
 
-
-partedincludedir       = -I$(top_srcdir)/include
+partedincludedir       = -I$(top_srcdir)/lib -I$(top_srcdir)/include
 
 INCLUDES               = $(partedincludedir) $(INTLINCS)
 
index e27c32d..4aba739 100644 (file)
 
 #include <string.h>
 #include <stdio.h>
+#include <stdlib.h>
+#include <getopt.h>
+#include "closeout.h"
+#include "configmake.h"
+#include "error.h"
+#include "long-options.h"
+
+#include "../../libparted/fs/fat/fat.h"
+
+#include <locale.h>
+
+/* Take care of NLS matters.  */
+
+#include "gettext.h"
+#if ! ENABLE_NLS
+# undef textdomain
+# define textdomain(Domainname) /* empty */
+# undef bindtextdomain
+# define bindtextdomain(Domainname, Dirname) /* empty */
+#endif
+
+#undef _
+#define _(msgid) gettext (msgid)
 
 #ifndef DISCOVER_ONLY
 
-#include "../../libparted/fs/fat/fat.h"
+/* The official name of this program (e.g., no `g' prefix).  */
+#define PROGRAM_NAME "clearfat"
+
+#define AUTHORS \
+  "<http://parted.alioth.debian.org/cgi-bin/trac.cgi/browser/AUTHORS>"
 
-static char* help_msg =
-"Usage:  clearfat DEVICE MINOR\n"
-"\n"
-"This program is used to enhance the automated testing.  It is not useful for\n"
-"anything much else.\n";
+/* The name this program was run with. */
+char *program_name;
+
+void
+usage (int status)
+{
+  if (status != EXIT_SUCCESS)
+    fprintf (stderr, _("Try `%s --help' for more information.\n"),
+            program_name);
+  else
+    {
+      printf (_("\
+Usage: %s [OPTION]\n\
+  or:  %s DEVICE MINOR\n"), PROGRAM_NAME, PROGRAM_NAME);
+      fputs (_("\
+Clear unused space on a FAT partition (a GNU Parted testing tool).\n\
+\n\
+"), stdout);
+      fputs (_("      --help     display this help and exit\n"), stdout);
+      fputs (_("      --version  output version information and exit\n"),
+             stdout);
+      printf (_("\nReport bugs to <%s>.\n"), PACKAGE_BUGREPORT);
+    }
+  exit (status);
+}
 
 #define CLEAR_BUFFER_SIZE              (1024 * 1024)
 #define CLEAR_BUFFER_SECTORS           (CLEAR_BUFFER_SIZE/512)
 
 static char buffer [CLEAR_BUFFER_SIZE];
 
-static int
-_do_help ()
-{
-       fputs (help_msg, stdout);
-       exit (1);
-}
-
 /* generic clearing code ***************************************************/
 
 static int
@@ -228,8 +268,28 @@ main (int argc, char* argv[])
        PedPartition*           part;
        PedFileSystem*          fs;
 
-       if (argc < 3)
-               _do_help ();
+        program_name = argv[0];
+        setlocale (LC_ALL, "");
+        bindtextdomain (PACKAGE, LOCALEDIR);
+        textdomain (PACKAGE);
+
+       atexit (close_stdout);
+
+       parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE, VERSION,
+                            usage, AUTHORS, (char const *) NULL);
+       if (getopt_long (argc, argv, "", NULL, NULL) != -1)
+         usage (EXIT_FAILURE);
+
+       if (argc - optind < 2)
+          {
+            error (0, 0, _("too few arguments"));
+            usage (EXIT_FAILURE);
+          }
+       if (2 < argc - optind)
+          {
+            error (0, 0, _("too many arguments"));
+            usage (EXIT_FAILURE);
+          }
 
        dev = ped_device_get (argv [1]);
        if (!dev)
@@ -284,4 +344,3 @@ main()
 }
 
 #endif /* DISCOVER_ONLY */
-
index 37c2404..4b2978f 100644 (file)
@@ -31,6 +31,8 @@ inttypes.h
 inttypes_.h
 localcharset.c
 localcharset.h
+long-options.c
+long-options.h
 malloc.c
 memchr.c
 memcmp.c
index 6c50518..406ad36 100644 (file)
@@ -14,6 +14,8 @@ lib/version-etc.c
 lib/xalloc-die.c
 libparted/arch/beos.c
 
+debug/clearfat/clearfat.c
+
 # libparted
 libparted/arch/gnu.c
 libparted/arch/linux.c