summaryrefslogtreecommitdiff
path: root/debug
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2007-03-05 14:47:02 +0100
committerJim Meyering <jim@meyering.net>2007-03-05 14:47:02 +0100
commit3389f62ba35ca2f0c5ba87ae29af5ef807ecf985 (patch)
tree2bae1be3782935ec977f11adb22b60df65ff4c9b /debug
parenta3f971d08ff676bd515da2830acfddd3753d5b6e (diff)
downloadparted-3389f62ba35ca2f0c5ba87ae29af5ef807ecf985.tar.gz
Make clearfat accept --help and --version options.
* 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.
Diffstat (limited to 'debug')
-rw-r--r--debug/clearfat/Makefile.am10
-rw-r--r--debug/clearfat/clearfat.c91
2 files changed, 81 insertions, 20 deletions
diff --git a/debug/clearfat/Makefile.am b/debug/clearfat/Makefile.am
index 0101ceb..7409f45 100644
--- a/debug/clearfat/Makefile.am
+++ b/debug/clearfat/Makefile.am
@@ -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)
diff --git a/debug/clearfat/clearfat.c b/debug/clearfat/clearfat.c
index e27c32d..4aba739 100644
--- a/debug/clearfat/clearfat.c
+++ b/debug/clearfat/clearfat.c
@@ -21,29 +21,69 @@
#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 */
-