public inbox for cluster-cvs@sourceware.org
help / color / mirror / Atom feed
* gfs2-utils: master - gfs2_tool: gettext support
@ 2009-03-23 17:26 Steven Whitehouse
  0 siblings, 0 replies; only message in thread
From: Steven Whitehouse @ 2009-03-23 17:26 UTC (permalink / raw)
  To: cluster-cvs-relay

Gitweb:        http://git.fedorahosted.org/git/gfs2-utils.git?p=gfs2-utils.git;a=commitdiff;h=611960af035b1296e610a6f977bc836a7fbadd7f
Commit:        611960af035b1296e610a6f977bc836a7fbadd7f
Parent:        8514279411a96f7b8f690c08eccad4c9f306737d
Author:        Steven Whitehouse <steve@dolmen.chygwyn.com>
AuthorDate:    Mon Mar 23 16:29:55 2009 +0000
Committer:     Steven Whitehouse <steve@dolmen.chygwyn.com>
CommitterDate: Mon Mar 23 16:29:55 2009 +0000

gfs2_tool: gettext support

This is only the basics. Message catalog generation will come
later.

My plan is to add gettext support to all the programs, but not
to libgfs2. My intended solution for libgfs2 is to simply avoid
the generation of printable strings and move all interaction with
the user into the programs.

Signed-off-by: Steven Whitehouse <swhiteho@redhat.com>
---
 gfs2/tool/df.c   |   58 ++++++++++++-----------
 gfs2/tool/main.c |  137 +++++++++++++++++++++++-------------------------------
 gfs2/tool/misc.c |   65 +++++++++++++-------------
 gfs2/tool/sb.c   |   60 ++++++++++++-----------
 gfs2/tool/tune.c |   26 ++++++-----
 5 files changed, 166 insertions(+), 180 deletions(-)

diff --git a/gfs2/tool/df.c b/gfs2/tool/df.c
index 8b6d9b4..53c645d 100644
--- a/gfs2/tool/df.c
+++ b/gfs2/tool/df.c
@@ -11,6 +11,8 @@
 #include <sys/ioctl.h>
 #include <limits.h>
 #include <errno.h>
+#include <libintl.h>
+#define _(String) gettext(String)
 
 #define __user
 #include <linux/gfs2_ondisk.h>
@@ -88,7 +90,7 @@ do_df_one(char *path)
 	sbd.path_name = path;
 	if (check_for_gfs2(&sbd)) {
 		if (errno == EINVAL)
-			fprintf(stderr, "Not a valid GFS2 mount point: %s\n",
+			fprintf(stderr, _("Not a valid GFS2 mount point: %s\n"),
 					sbd.path_name);
 		else
 			fprintf(stderr, "%s\n", strerror(errno));
@@ -96,14 +98,14 @@ do_df_one(char *path)
 	}
 	fs = mp2fsname(sbd.path_name);
 	if (!fs) {
-		fprintf(stderr, "Couldn't find GFS2 filesystem mounted at %s\n",
+		fprintf(stderr, _("Couldn't find GFS2 filesystem mounted at %s\n"),
 				sbd.path_name);
 		exit(-1);
 	}
 
 	sbd.device_fd = open(sbd.device_name, O_RDONLY);
 	if (sbd.device_fd < 0)
-		die("can't open %s: %s\n", path, strerror(errno));
+		die( _("can't open %s: %s\n"), path, strerror(errno));
 
 	sbd.bsize = GFS2_DEFAULT_BSIZE;
 	sbd.jsize = GFS2_DEFAULT_JSIZE;
@@ -116,12 +118,12 @@ do_df_one(char *path)
 
 	if (lseek(sbd.device_fd, 0x10 * sbd.bsize, SEEK_SET) !=
 	    0x10 * sbd.bsize) {
-		fprintf(stderr, "bad seek: %s from %s:%d: superblock\n",
+		fprintf(stderr, _("bad seek: %s from %s:%d: superblock\n"),
 			strerror(errno), __FUNCTION__, __LINE__);
 		exit(-1);
 	}
 	if (read(sbd.device_fd, buf, sbd.bsize) != sbd.bsize) {
-		fprintf(stderr, "bad read: %s from %s:%d: superblock\n",
+		fprintf(stderr, _("bad read: %s from %s:%d: superblock\n"),
 			strerror(errno), __FUNCTION__, __LINE__);
 		exit(-1);
 	}
@@ -145,51 +147,51 @@ do_df_one(char *path)
 	rgrps /= sizeof(struct gfs2_rindex);
 
 	printf("%s:\n", path);
-	printf("  SB lock proto = \"%s\"\n", sbd.sd_sb.sb_lockproto);
-	printf("  SB lock table = \"%s\"\n", sbd.sd_sb.sb_locktable);
-	printf("  SB ondisk format = %u\n", sbd.sd_sb.sb_fs_format);
-	printf("  SB multihost format = %u\n", sbd.sd_sb.sb_multihost_format);
-	printf("  Block size = %u\n", sbd.sd_sb.sb_bsize);
-	printf("  Journals = %u\n", journals);
-	printf("  Resource Groups = %"PRIu64"\n", rgrps);
+	printf( _("  SB lock proto = \"%s\"\n"), sbd.sd_sb.sb_lockproto);
+	printf( _("  SB lock table = \"%s\"\n"), sbd.sd_sb.sb_locktable);
+	printf( _("  SB ondisk format = %u\n"), sbd.sd_sb.sb_fs_format);
+	printf( _("  SB multihost format = %u\n"), sbd.sd_sb.sb_multihost_format);
+	printf( _("  Block size = %u\n"), sbd.sd_sb.sb_bsize);
+	printf( _("  Journals = %u\n"), journals);
+	printf( _("  Resource Groups = %"PRIu64"\n"), rgrps);
 	value = get_sysfs(fs, "args/lockproto");
 	if (value)
-		printf("  Mounted lock proto = \"%s\"\n",
+		printf( _("  Mounted lock proto = \"%s\"\n"),
 			value[0] ? value : sbd.sd_sb.sb_lockproto);
 	else
-		printf("  Mounted lock proto = (Not found: %s)\n",
+		printf( _("  Mounted lock proto = (Not found: %s)\n"),
 				strerror(errno));
 
 	value = get_sysfs(fs, "args/locktable");
 	if (value)
-		printf("  Mounted lock table = \"%s\"\n",
+		printf( _("  Mounted lock table = \"%s\"\n"),
 			value[0] ? value : sbd.sd_sb.sb_locktable);
 	else
-		printf("  Mounted lock table = (Not found: %s)\n",
+		printf( _("  Mounted lock table = (Not found: %s)\n"),
 				strerror(errno));
 
-	printf("  Mounted host data = \"%s\"\n",
+	printf( _("  Mounted host data = \"%s\"\n"),
 	       get_sysfs(fs, "args/hostdata"));
-	printf("  Journal number = %s\n", get_sysfs(fs, "lockstruct/jid"));
+	printf( _("  Journal number = %s\n"), get_sysfs(fs, "lockstruct/jid"));
 
 	if (get_sysfs_uint(fs, "lockstruct/flags", &flags))
-		printf("  Lock module flags = (Not found: %s)\n", strerror(errno));
+		printf( _("  Lock module flags = (Not found: %s)\n"), strerror(errno));
 	else
-		printf("  Lock module flags = %x\n", flags);
+		printf( _("  Lock module flags = %x\n"), flags);
 
 	if (get_sysfs_uint(fs, "args/localflocks", &flags))
-		printf("  Lock flocks = (Not found: %s)\n", strerror(errno));
+		printf( _("  Lock flocks = (Not found: %s)\n"), strerror(errno));
 	else
-		printf("  Local flocks = %s\n", flags ? "TRUE" : "FALSE");
+		printf( _("  Local flocks = %s\n"), flags ? "TRUE" : "FALSE");
 
 	if (get_sysfs_uint(fs, "args/localcaching", &flags))
-		printf("  Lock caching = (Not found: %s)\n", strerror(errno));
+		printf( _("  Lock caching = (Not found: %s)\n"), strerror(errno));
 	else
-		printf("  Local caching = %s\n", flags ? "TRUE" : "FALSE");
+		printf( _("  Local caching = %s\n"), flags ? "TRUE" : "FALSE");
 
 	/* Read the master statfs file */
 	if (mount_gfs2_meta(&sbd)) {
-		fprintf(stderr, "Error mounting GFS2 metafs: %s\n",
+		fprintf(stderr, _("Error mounting GFS2 metafs: %s\n"),
 			strerror(errno));
 		exit(-1);
 	}
@@ -198,7 +200,7 @@ do_df_one(char *path)
 	statfs_fd = open(statfs_fn, O_RDONLY);
 	if (read(statfs_fd, buf, sizeof(struct gfs2_statfs_change)) !=
 	    sizeof(struct gfs2_statfs_change)) {
-		fprintf(stderr, "bad read: %s from %s:%d: superblock\n",
+		fprintf(stderr, _("bad read: %s from %s:%d: superblock\n"),
 			strerror(errno), __FUNCTION__, __LINE__);
 		exit(-1);
 	}
@@ -252,7 +254,7 @@ print_df(int argc, char **argv)
 		char buf[PATH_MAX];
 
 		if (!realpath(argv[optind], buf))
-			die("can't determine real path: %s\n", strerror(errno));
+			die( _("can't determine real path: %s\n"), strerror(errno));
 
 		do_df_one(buf);
 
@@ -266,7 +268,7 @@ print_df(int argc, char **argv)
 
 		file = fopen("/proc/mounts", "r");
 		if (!file)
-			die("can't open /proc/mounts: %s\n", strerror(errno));
+			die( _("can't open /proc/mounts: %s\n"), strerror(errno));
 
 		while (fgets(buf, 256, file)) {
 			if (sscanf(buf, "%s %s %s", device, path, type) != 3)
diff --git a/gfs2/tool/main.c b/gfs2/tool/main.c
index b80ca9d..aa872c3 100644
--- a/gfs2/tool/main.c
+++ b/gfs2/tool/main.c
@@ -11,6 +11,8 @@
 #include <limits.h>
 #include <errno.h>
 #include <linux/types.h>
+#include <libintl.h>
+#define _(String) gettext(String)
 
 #include "copyright.cf"
 
@@ -26,59 +28,43 @@ int continuous = FALSE;
 int interval = 1;
 int output_type = OUTPUT_BLOCKS;
 
-static const char *usage[] = {
-	"Clear a flag on a inode\n",
-	"  gfs2_tool clearflag flag <filenames>\n",
-	"\n",
-	"Do a GFS2 specific \"df\":\n",
-	"  gfs2_tool df <mountpoint>\n",
-	"\n",
-	"Freeze a GFS2 cluster:\n",
-	"  gfs2_tool freeze <mountpoint>\n",
-	"\n",
-	"Print the current mount arguments of a mounted filesystem:\n",
-	"  gfs2_tool getargs <mountpoint>\n",
-	"\n",
-	"Get tuneable parameters for a filesystem\n",
-	"  gfs2_tool gettune <mountpoint>\n",
-	"\n",
-	"List the file system's journals:\n",
-	"  gfs2_tool journals <mountpoint>\n",
-	"\n",
-	"List filesystems:\n",
-	"  gfs2_tool list\n",
-	"\n",
-	"Have GFS2 dump its lock state:\n",
-	"  gfs2_tool lockdump <mountpoint> [buffersize]\n",
-	"\n",
-	"Provide arguments for next mount:\n",
-	"  gfs2_tool margs <mountarguments>\n",
-	"\n",
-	"Tune a GFS2 superblock\n",
-	"  gfs2_tool sb <device> proto [newval]\n",
-	"  gfs2_tool sb <device> table [newval]\n",
-	"  gfs2_tool sb <device> ondisk [newval]\n",
-	"  gfs2_tool sb <device> multihost [newval]\n",
-	"  gfs2_tool sb <device> all\n",
-	"\n",
-	"Set a flag on a inode\n",
-	"  gfs2_tool setflag flag <filenames>\n",
-	"\n",
-	"Tune a running filesystem\n",
-	"  gfs2_tool settune <mountpoint> <parameter> <value>\n",
-	"\n",
-	"Shrink a filesystem's inode cache:\n",
-	"  gfs2_tool shrink <mountpoint>\n",
-	"\n",
-	"Unfreeze a GFS2 cluster:\n",
-	"  gfs2_tool unfreeze <mountpoint>\n",
-	"\n",
-	"Print tool version information\n",
-	"  gfs2_tool version\n",
-	"\n",
-	"Withdraw this machine from participating in a filesystem:\n",
-	"  gfs2_tool withdraw <mountpoint>\n",
-	"",
+static const char *usage = {
+	"Clear a flag on a inode\n"
+	"  gfs2_tool clearflag flag <filenames>\n"
+	"Do a GFS2 specific \"df\":\n"
+	"  gfs2_tool df <mountpoint>\n"
+	"Freeze a GFS2 cluster:\n"
+	"  gfs2_tool freeze <mountpoint>\n"
+	"Print the current mount arguments of a mounted filesystem:\n"
+	"  gfs2_tool getargs <mountpoint>\n"
+	"Get tuneable parameters for a filesystem\n"
+	"  gfs2_tool gettune <mountpoint>\n"
+	"List the file system's journals:\n"
+	"  gfs2_tool journals <mountpoint>\n"
+	"List filesystems:\n"
+	"  gfs2_tool list\n"
+	"Have GFS2 dump its lock state:\n"
+	"  gfs2_tool lockdump <mountpoint> [buffersize]\n"
+	"Provide arguments for next mount:\n"
+	"  gfs2_tool margs <mountarguments>\n"
+	"Tune a GFS2 superblock\n"
+	"  gfs2_tool sb <device> proto [newval]\n"
+	"  gfs2_tool sb <device> table [newval]\n"
+	"  gfs2_tool sb <device> ondisk [newval]\n"
+	"  gfs2_tool sb <device> multihost [newval]\n"
+	"  gfs2_tool sb <device> all\n"
+	"Set a flag on a inode\n"
+	"  gfs2_tool setflag flag <filenames>\n"
+	"Tune a running filesystem\n"
+	"  gfs2_tool settune <mountpoint> <parameter> <value>\n"
+	"Shrink a filesystem's inode cache:\n"
+	"  gfs2_tool shrink <mountpoint>\n"
+	"Unfreeze a GFS2 cluster:\n"
+	"  gfs2_tool unfreeze <mountpoint>\n"
+	"Print tool version information\n"
+	"  gfs2_tool version\n"
+	"Withdraw this machine from participating in a filesystem:\n"
+	"  gfs2_tool withdraw <mountpoint>\n"
 };
 
 /**
@@ -86,13 +72,9 @@ static const char *usage[] = {
  *
  */
 
-void
-print_usage(void)
+void print_usage(void)
 {
-	int x;
-
-	for (x = 0; usage[x][0]; x++)
-		printf("%s", usage[x]);
+	puts( _(usage) );
 }
 
 /**
@@ -100,14 +82,10 @@ print_usage(void)
  *
  */
 
-static void
-print_version(void)
+static void print_version(void)
 {
-	printf("gfs2_tool %s (built %s %s)\n",
-	       RELEASE_VERSION,
-	       __DATE__, __TIME__);
-	printf("%s\n",
-	       REDHAT_COPYRIGHT);
+	printf( _("gfs2_tool " RELEASE_VERSION " (built " __DATE__ " " __TIME__ ")\n"));
+	puts( _(REDHAT_COPYRIGHT "\n") );
 }
 
 /**
@@ -117,8 +95,7 @@ print_version(void)
  *
  */
 
-static void
-decode_arguments(int argc, char *argv[])
+static void decode_arguments(int argc, char *argv[])
 {
 	int cont = TRUE;
 	int optchar;
@@ -138,7 +115,7 @@ decode_arguments(int argc, char *argv[])
 
 		case 'h':
 			print_usage();
-			exit(EXIT_SUCCESS);
+			exit(0);
 
 		case 'H':
 			output_type = OUTPUT_HUMAN;
@@ -158,7 +135,7 @@ decode_arguments(int argc, char *argv[])
 
 		case 'V':
 			print_version();
-			exit(EXIT_SUCCESS);
+			exit(0);
 
 		case 'X':
 			expert = TRUE;
@@ -169,15 +146,16 @@ decode_arguments(int argc, char *argv[])
 			break;
 
 		default:
-			die("unknown option: %c\n", optchar);
+			die( _("unknown option: %c\n"), optchar);
 		};
 	}
 
 	if (optind < argc) {
 		action = argv[optind];
 		optind++;
-	} else
-		die("no action specified\n");
+	} else {
+		die( _("no action specified\n"));
+	}
 }
 
 /**
@@ -187,14 +165,16 @@ decode_arguments(int argc, char *argv[])
  *
  */
 
-int
-main(int argc, char *argv[])
+int main(int argc, char *argv[])
 {
 	prog_name = argv[0];
 
+	setlocale(LC_ALL, "");
+	textdomain("gfs2_tool");
+
 	if (argc < 2) {
 		print_usage();
-		exit(EXIT_SUCCESS);
+		return 0;
 	}
 
 	decode_arguments(argc, argv);
@@ -232,8 +212,7 @@ main(int argc, char *argv[])
 	else if (strcmp(action, "withdraw") == 0)
 		do_withdraw(argc, argv);
 	else
-		die("unknown action: %s\n",
-		    action);
+		die( _("unknown action: %s\n"), action);
 
-	exit(EXIT_SUCCESS);
+	return 0;
 }
diff --git a/gfs2/tool/misc.c b/gfs2/tool/misc.c
index 3315e6e..df422bd 100644
--- a/gfs2/tool/misc.c
+++ b/gfs2/tool/misc.c
@@ -12,6 +12,8 @@
 #include <limits.h>
 #include <errno.h>
 #include <dirent.h>
+#include <libintl.h>
+#define _(String) gettext(String)
 
 #define __user
 #include <linux/gfs2_ondisk.h>
@@ -41,20 +43,20 @@ do_freeze(int argc, char **argv)
 
 	name = mp2fsname2(argv[optind]);
 	if (!name) {
-		fprintf(stderr, "Couldn't find a GFS2 filesystem mounted at %s\n",
+		fprintf(stderr, _("Couldn't find a GFS2 filesystem mounted at %s\n"),
 				argv[optind]);
 		exit(-1);
 	}
 
 	if (strcmp(command, "freeze") == 0) {
 		if (set_sysfs(name, "freeze", "1")) {
-			fprintf(stderr, "Error writing to sysfs freeze file: %s\n",
+			fprintf(stderr, _("Error writing to sysfs freeze file: %s\n"),
 					strerror(errno));
 			exit(-1);
 		}
 	} else if (strcmp(command, "unfreeze") == 0) {
 		if (set_sysfs(name, "freeze", "0")) {
-			fprintf(stderr, "Error writing to sysfs freeze file: %s\n",
+			fprintf(stderr, _("Error writing to sysfs freeze file: %s\n"),
 					strerror(errno));
 			exit(-1);
 		}
@@ -90,8 +92,7 @@ print_lockdump(int argc, char **argv)
 		sprintf(debugfs, "/tmp/debugfs.XXXXXX");
 
 		if (!mkdtemp(debugfs)) {
-			fprintf(stderr,
-				"Can't create %s mount point.\n",
+			fprintf(stderr,_("Can't create %s mount point.\n"),
 				debugfs);
 			free(debugfs);
 			exit(-1);
@@ -100,8 +101,8 @@ print_lockdump(int argc, char **argv)
 		rc = mount("none", debugfs, "debugfs", 0, NULL);
 		if (rc) {
 			fprintf(stderr,
-				"Can't mount debugfs.  "
-				"Maybe your kernel doesn't support it.\n");
+				_("Can't mount debugfs. "
+				"Maybe your kernel doesn't support it.\n"));
 				free(debugfs);
 				exit(-1);
 		}
@@ -117,11 +118,11 @@ print_lockdump(int argc, char **argv)
 			}
 			fclose(file);
 		} else {
-			fprintf(stderr, "Can't open %s: %s\n", path,
+			fprintf(stderr, _("Can't open %s: %s\n"), path,
 				strerror(errno));
 		}
 	} else {
-		fprintf(stderr, "Unable to locate sysfs for mount point %s.\n",
+		fprintf(stderr, _("Unable to locate sysfs for mount point %s.\n"),
 			argv[optind]);
 	}
 	/* Check if we mounted the debugfs and if so, unmount it. */
@@ -142,7 +143,7 @@ print_lockdump(int argc, char **argv)
 void
 margs(int argc, char **argv)
 {
-	die("margs not implemented\n");
+	die( _("margs not implemented\n"));
 }
 
 /**
@@ -155,7 +156,7 @@ static void
 print_flags(struct gfs2_dinode *di)
 {
 	if (di->di_flags) {
-		printf("Flags:\n");
+		printf( _("Flags:\n"));
 		if (di->di_flags & GFS2_DIF_JDATA)
 			printf("  jdata\n");
 		if (di->di_flags & GFS2_DIF_EXHASH)
@@ -167,7 +168,7 @@ print_flags(struct gfs2_dinode *di)
 		if (di->di_flags & GFS2_DIF_APPENDONLY)
 			printf("  appendonly\n");
 		if (di->di_flags & GFS2_DIF_NOATIME)
-			printf("  noatime\n");
+			printf( _("  noatime\n"));
 		if (di->di_flags & GFS2_DIF_SYNC)
 			printf("  sync\n");
 		if (di->di_flags & GFS2_DIF_TRUNC_IN_PROG)
@@ -221,22 +222,22 @@ set_flag(int argc, char **argv)
 	set = (strcmp(argv[optind -1], "setflag") == 0) ? 1 : 0;
 	flstr = argv[optind++];
 	if (!(flag = get_flag_from_name(flstr)))
-		die("unrecognized flag %s\n", argv[optind -1]);
+		die( _("unrecognized flag %s\n"), argv[optind -1]);
 	
 	for (; optind < argc; optind++) {
 		fd = open(argv[optind], O_RDONLY);
 		if (fd < 0)
-			die("can't open %s: %s\n", argv[optind], strerror(errno));
+			die( _("can't open %s: %s\n"), argv[optind], strerror(errno));
 		/* first get the existing flags on the file */
 		error = ioctl(fd, FS_IOC_GETFLAGS, &newflags);
 		if (error)
-			die("can't get flags on %s: %s\n", 
+			die( _("can't get flags on %s: %s\n"), 
 			    argv[optind], strerror(errno));
 		newflags = set ? newflags | flag : newflags & ~flag;
 		/* new flags */
 		error = ioctl(fd, FS_IOC_SETFLAGS, &newflags);
 		if (error)
-			die("can't set flags on %s: %s\n", 
+			die( _("can't set flags on %s: %s\n"), 
 			    argv[optind], strerror(errno));
 		close(fd);
 	}
@@ -260,12 +261,12 @@ print_args(int argc, char **argv)
 	struct gfs2_sbd sbd;
 
 	if (optind == argc)
-		die("Usage: gfs2_tool getargs <mountpoint>\n");
+		die( _("Usage: gfs2_tool getargs <mountpoint>\n"));
 
 	sbd.path_name = argv[optind];
 	if (check_for_gfs2(&sbd)) {
 		if (errno == EINVAL)
-			fprintf(stderr, "Not a valid GFS2 mount point: %s\n",
+			fprintf(stderr, _("Not a valid GFS2 mount point: %s\n"),
 					sbd.path_name);
 		else
 			fprintf(stderr, "%s\n", strerror(errno));
@@ -273,7 +274,7 @@ print_args(int argc, char **argv)
 	}
 	fs = mp2fsname(argv[optind]);
 	if (!fs) {
-		fprintf(stderr, "Couldn't find GFS2 filesystem mounted at %s\n",
+		fprintf(stderr, _("Couldn't find GFS2 filesystem mounted at %s\n"),
 				argv[optind]);
 		exit(-1);
 	}
@@ -283,7 +284,7 @@ print_args(int argc, char **argv)
 
 	d = opendir(path);
 	if (!d)
-		die("can't open %s: %s\n", path, strerror(errno));
+		die( _("can't open %s: %s\n"), path, strerror(errno));
 
 	while((de = readdir(d))) {
 		if (de->d_name[0] == '.')
@@ -328,7 +329,7 @@ print_journals(int argc, char **argv)
 		    sbd.path_name, strerror(errno));
 	if (check_for_gfs2(&sbd)) {
 		if (errno == EINVAL)
-			fprintf(stderr, "Not a valid GFS2 mount point: %s\n",
+			fprintf(stderr, _("Not a valid GFS2 mount point: %s\n"),
 					sbd.path_name);
 		else
 			fprintf(stderr, "%s\n", strerror(errno));
@@ -336,11 +337,11 @@ print_journals(int argc, char **argv)
 	}
 	sbd.device_fd = open(sbd.device_name, O_RDONLY);
 	if (sbd.device_fd < 0)
-		die("can't open device %s: %s\n",
+		die( _("can't open device %s: %s\n"),
 		    sbd.device_name, strerror(errno));
 
 	if (mount_gfs2_meta(&sbd)) {
-		fprintf(stderr, "Error mounting GFS2 metafs: %s\n",
+		fprintf(stderr, _("Error mounting GFS2 metafs: %s\n"),
 			strerror(errno));
 		exit(-1);
 	}
@@ -348,7 +349,7 @@ print_journals(int argc, char **argv)
 	sprintf(jindex_name, "%s/jindex", sbd.metafs_path);
 	jindex = opendir(jindex_name);
 	if (!jindex) {
-		die("Can't open %s\n", jindex_name);
+		die( _("Can't open %s\n"), jindex_name);
 	} else {
 		jcount = 0;
 		while ((journal = readdir(jindex))) {
@@ -364,7 +365,7 @@ print_journals(int argc, char **argv)
 			       (unsigned long long)statbuf.st_size / 1048576);
 		}
 
-		printf("%d journal(s) found.\n", jcount);
+		printf( _("%d journal(s) found.\n"), jcount);
 		closedir(jindex);
 	}
 	cleanup_metafs(&sbd);
@@ -398,7 +399,7 @@ print_list(void)
 
 	d = opendir(path);
 	if (!d)
-		die("can't open %s: %s\n", SYS_BASE, strerror(errno));
+		die( _("can't open %s: %s\n"), SYS_BASE, strerror(errno));
 
 	while ((de = readdir(d))) {
 		if (de->d_name[0] == '.')
@@ -455,7 +456,7 @@ do_shrink(int argc, char **argv)
 	sbd.path_name = argv[optind];
 	if (check_for_gfs2(&sbd)) {
 		if (errno == EINVAL)
-			fprintf(stderr, "Not a valid GFS2 mount point: %s\n",
+			fprintf(stderr, _("Not a valid GFS2 mount point: %s\n"),
 					sbd.path_name);
 		else
 			fprintf(stderr, "%s\n", strerror(errno));
@@ -463,13 +464,13 @@ do_shrink(int argc, char **argv)
 	}
 	fs = mp2fsname(argv[optind]);
 	if (!fs) {
-		fprintf(stderr, "Couldn't find GFS2 filesystem mounted at %s\n",
+		fprintf(stderr, _("Couldn't find GFS2 filesystem mounted at %s\n"),
 				argv[optind]);
 		exit(-1);
 	}
 	
 	if (set_sysfs(fs, "shrink", "1")) {
-		fprintf(stderr, "Error writing to sysfs shrink file: %s\n",
+		fprintf(stderr, _("Error writing to sysfs shrink file: %s\n"),
 				strerror(errno));
 		exit(-1);
 	}
@@ -494,7 +495,7 @@ do_withdraw(int argc, char **argv)
 	sbd.path_name = argv[optind];
 	if (check_for_gfs2(&sbd)) {
 		if (errno == EINVAL)
-			fprintf(stderr, "Not a valid GFS2 mount point: %s\n",
+			fprintf(stderr, _("Not a valid GFS2 mount point: %s\n"),
 					sbd.path_name);
 		else
 			fprintf(stderr, "%s\n", strerror(errno));
@@ -502,13 +503,13 @@ do_withdraw(int argc, char **argv)
 	}
 	name = mp2fsname(argv[optind]);
 	if (!name) {
-		fprintf(stderr, "Couldn't find GFS2 filesystem mounted at %s\n",
+		fprintf(stderr, _("Couldn't find GFS2 filesystem mounted at %s\n"),
 				argv[optind]);
 		exit(-1);
 	}
 
 	if (set_sysfs(name, "withdraw", "1")) {
-		fprintf(stderr, "Error writing to sysfs withdraw file: %s\n",
+		fprintf(stderr, _("Error writing to sysfs withdraw file: %s\n"),
 				strerror(errno));
 		exit(-1);
 	}
diff --git a/gfs2/tool/sb.c b/gfs2/tool/sb.c
index d6296c8..7757470 100644
--- a/gfs2/tool/sb.c
+++ b/gfs2/tool/sb.c
@@ -13,6 +13,8 @@
 #include <limits.h>
 #include <errno.h>
 #include <ctype.h>
+#include <libintl.h>
+#define _(String) gettext(String)
 
 #include <linux/gfs2_ondisk.h>
 
@@ -92,25 +94,25 @@ do_sb(int argc, char **argv)
 		die("can't open %s: %s\n", device, strerror(errno));
 
 	if (newval && !override) {
-		printf("You shouldn't change any of these values if the filesystem is mounted.\n");
-		printf("\nAre you sure? [y/n] ");
+		printf( _("You shouldn't change any of these values if the filesystem is mounted.\n"));
+		printf( _("\nAre you sure? [y/n] "));
 		if(!fgets((char*)input, 255, stdin))
-			die("unable to read from stdin\n");
+			die( _("unable to read from stdin\n"));
 
 		if (input[0] != 'y')
-			die("aborted\n");
+			die( _("aborted\n"));
 
 		printf("\n");
 	}
 
 	if (lseek(fd, GFS2_SB_ADDR * GFS2_BASIC_BLOCK, SEEK_SET) !=
 	    GFS2_SB_ADDR * GFS2_BASIC_BLOCK) {
-		fprintf(stderr, "bad seek: %s from %s:%d: superblock\n",
+		fprintf(stderr, _("bad seek: %s from %s:%d: superblock\n"),
 			strerror(errno), __FUNCTION__, __LINE__);
 		exit(-1);
 	}
 	if (read(fd, buf, GFS2_BASIC_BLOCK) != GFS2_BASIC_BLOCK) {
-		fprintf(stderr, "bad read: %s from %s:%d: superblock\n",
+		fprintf(stderr, _("bad read: %s from %s:%d: superblock\n"),
 			strerror(errno), __FUNCTION__, __LINE__);
 		exit(-1);
 	}
@@ -119,104 +121,104 @@ do_sb(int argc, char **argv)
 
 	if (sb.sb_header.mh_magic != GFS2_MAGIC ||
 	    sb.sb_header.mh_type != GFS2_METATYPE_SB)
-		die("there isn't a GFS2 filesystem on %s\n", device);
+		die( _("there isn't a GFS2 filesystem on %s\n"), device);
 
 	if (strcmp(field, "proto") == 0) {
-		printf("current lock protocol name = \"%s\"\n",
+		printf( _("current lock protocol name = \"%s\"\n"),
 		       sb.sb_lockproto);
 
 		if (newval) {
 			if (strlen(newval) >= GFS2_LOCKNAME_LEN)
-				die("new lockproto name is too long\n");
+				die( _("new lockproto name is too long\n"));
 			strcpy(sb.sb_lockproto, newval);
-			printf("new lock protocol name = \"%s\"\n",
+			printf( _("new lock protocol name = \"%s\"\n"),
 			       sb.sb_lockproto);
 		}
 	} else if (strcmp(field, "table") == 0) {
-		printf("current lock table name = \"%s\"\n",
+		printf( _("current lock table name = \"%s\"\n"),
 		       sb.sb_locktable);
 
 		if (newval) {
 			if (strlen(newval) >= GFS2_LOCKNAME_LEN)
-				die("new locktable name is too long\n");
+				die( _("new locktable name is too long\n"));
 			strcpy(sb.sb_locktable, newval);
-			printf("new lock table name = \"%s\"\n",
+			printf( _("new lock table name = \"%s\"\n"),
 			       sb.sb_locktable);
 		}
 	} else if (strcmp(field, "ondisk") == 0) {
-		printf("current ondisk format = %u\n",
+		printf( _("current ondisk format = %u\n"),
 		       sb.sb_fs_format);
 
 		if (newval) {
 			sb.sb_fs_format = atoi(newval);
-			printf("new ondisk format = %u\n",
+			printf( _("new ondisk format = %u\n"),
 			       sb.sb_fs_format);
 		}
 	} else if (strcmp(field, "multihost") == 0) {
-		printf("current multihost format = %u\n",
+		printf( _("current multihost format = %u\n"),
 		       sb.sb_multihost_format);
 
 		if (newval) {
 			sb.sb_multihost_format = atoi(newval);
-			printf("new multihost format = %u\n",
+			printf( _("new multihost format = %u\n"),
 			       sb.sb_multihost_format);
 		}
 #ifdef GFS2_HAS_UUID
 	} else if (strcmp(field, "uuid") == 0) {
-		printf("current uuid = %s\n", str_uuid(sb.sb_uuid));
+		printf( _("current uuid = %s\n"), str_uuid(sb.sb_uuid));
 
 		if (newval) {
 			int i;
 			unsigned char uuid[16], *cp;
 
 			if (strlen(newval) != 36)
-				die("uuid %s is the wrong length; must be 36 "
-				    "hex characters long.\n", newval);
+				die( _("uuid %s is the wrong length; must be 36 "
+				    "hex characters long.\n"), newval);
 			cp = uuid;
 			for (i = 0; i < 36; i++) {
 				if ((i == 8) || (i == 13) ||
 				    (i == 18) || (i == 23)) {
 					if (newval[i] == '-')
 						continue;
-					die("uuid %s has an invalid format.",
+					die( _("uuid %s has an invalid format."),
 					    newval);
 				}
 				if (!isxdigit(newval[i]))
-					die("uuid %s has an invalid hex "
-					    "digit '%c' at offset %d.\n",
+					die( _("uuid %s has an invalid hex "
+					    "digit '%c' at offset %d.\n"),
 					    newval, newval[i], i + 1);
 				*cp = str_to_hexchar(&newval[i++]);
 				cp++;
 			}
 			memcpy(sb.sb_uuid, uuid, 16);
-			printf("new uuid = %s\n", str_uuid(sb.sb_uuid));
+			printf( _("new uuid = %s\n", str_uuid(sb.sb_uuid)));
 		}
 #endif
 	} else if (strcmp(field, "all") == 0) {
 		gfs2_sb_print(&sb);
 		newval = FALSE;
 	} else
-		die("unknown field %s\n", field);
+		die( _("unknown field %s\n"), field);
 
 	if (newval) {
 		gfs2_sb_out(&sb,(char*) buf);
 
 		if (lseek(fd, GFS2_SB_ADDR * GFS2_BASIC_BLOCK, SEEK_SET) !=
 		    GFS2_SB_ADDR * GFS2_BASIC_BLOCK) {
-			fprintf(stderr, "bad seek: %s from %s:%d: superblock\n",
+			fprintf(stderr, _("bad seek: %s from %s:%d: superblock\n"),
 				strerror(errno), __FUNCTION__, __LINE__);
 			exit(-1);
 		}
 		if (write(fd, buf, GFS2_BASIC_BLOCK) != GFS2_BASIC_BLOCK) {
-			fprintf(stderr, "write error: %s from %s:%d: "
-				"superblock\n", strerror(errno),
+			fprintf(stderr, _("write error: %s from %s:%d: "
+				"superblock\n"), strerror(errno),
 				__FUNCTION__, __LINE__);
 			exit(-1);
 		}
 
 		fsync(fd);
 
-		printf("Done\n");
+		printf( _("Done\n"));
 	}
 
 	close(fd);
diff --git a/gfs2/tool/tune.c b/gfs2/tool/tune.c
index 277d2dd..4666291 100644
--- a/gfs2/tool/tune.c
+++ b/gfs2/tool/tune.c
@@ -12,6 +12,8 @@
 #include <limits.h>
 #include <errno.h>
 #include <dirent.h>
+#include <libintl.h>
+#define _(String) gettext(String)
 
 #define __user
 
@@ -42,12 +44,12 @@ get_tune(int argc, char **argv)
 	char *value;
 
 	if (optind == argc)
-		die("Usage: gfs2_tool gettune <mountpoint>\n");
+		die( _("Usage: gfs2_tool gettune <mountpoint>\n"));
 
 	sbd.path_name = argv[optind];
 	if (check_for_gfs2(&sbd)) {
 		if (errno == EINVAL)
-			fprintf(stderr, "Not a valid GFS2 mount point: %s\n",
+			fprintf(stderr, _("Not a valid GFS2 mount point: %s\n"),
 					sbd.path_name);
 		else
 			fprintf(stderr, "%s\n", strerror(errno));
@@ -55,7 +57,7 @@ get_tune(int argc, char **argv)
 	}
 	fs = mp2fsname(argv[optind]);
 	if (!fs) {
-		fprintf(stderr, "Couldn't find GFS2 filesystem mounted at %s\n",
+		fprintf(stderr, _("Couldn't find GFS2 filesystem mounted at %s\n"),
 				argv[optind]);
 		exit(-1);
 	}
@@ -64,7 +66,7 @@ get_tune(int argc, char **argv)
 
 	d = opendir(path);
 	if (!d)
-		die("can't open %s: %s\n", path, strerror(errno));
+		die( _("can't open %s: %s\n"), path, strerror(errno));
 
 	while((de = readdir(d))) {
 		if (de->d_name[0] == '.')
@@ -73,13 +75,13 @@ get_tune(int argc, char **argv)
 		if (strcmp(de->d_name, "quota_scale") == 0) {
 			value = get_sysfs(fs, "tune/quota_scale");
 			if (!value) {
-				printf("quota_scale = (Not found: %s)\n",
+				printf( _("quota_scale = (Not found: %s)\n"),
 						strerror(errno));
 				continue;
 			}
 			sscanf(value, "%u %u", &num, &den);
 			ratio = (double)num / den;
-			printf("quota_scale = %.4f   (%u, %u)\n", ratio, num,
+			printf( _("quota_scale = %.4f   (%u, %u)\n"), ratio, num,
 			       den);
 		} else
 			printf("%s = %s\n", de->d_name, get_sysfs(fs, path));
@@ -104,18 +106,18 @@ set_tune(int argc, char **argv)
 	struct gfs2_sbd sbd;
 
 	if (optind == argc)
-		die("Usage: gfs2_tool settune <mountpoint> <parameter> <value>\n");
+		die( _("Usage: gfs2_tool settune <mountpoint> <parameter> <value>\n"));
 	sbd.path_name = argv[optind++];
 	if (optind == argc)
-		die("Usage: gfs2_tool settune <mountpoint> <parameter> <value>\n");
+		die( _("Usage: gfs2_tool settune <mountpoint> <parameter> <value>\n"));
 	param = argv[optind++];
 	if (optind == argc)
-		die("Usage: gfs2_tool settune <mountpoint> <parameter> <value>\n");
+		die( _("Usage: gfs2_tool settune <mountpoint> <parameter> <value>\n"));
 	value = argv[optind++];
 
 	if (check_for_gfs2(&sbd)) {
 		if (errno == EINVAL)
-			fprintf(stderr, "Not a valid GFS2 mount point: %s\n",
+			fprintf(stderr, _("Not a valid GFS2 mount point: %s\n"),
 					sbd.path_name);
 		else
 			fprintf(stderr, "%s\n", strerror(errno));
@@ -123,7 +125,7 @@ set_tune(int argc, char **argv)
 	}
 	fs = mp2fsname(sbd.path_name);
 	if (!fs) {
-		fprintf(stderr, "Couldn't find GFS2 filesystem mounted at %s\n",
+		fprintf(stderr, _("Couldn't find GFS2 filesystem mounted at %s\n"),
 				sbd.path_name);
 		exit(-1);
 	}
@@ -135,7 +137,7 @@ set_tune(int argc, char **argv)
 		value = buf;
 	}
 	if (set_sysfs(fs, strcat(tune_base, param), value)) {
-		fprintf(stderr, "Error writing to sysfs %s tune file: %s\n",
+		fprintf(stderr, _("Error writing to sysfs %s tune file: %s\n"),
 				param, strerror(errno));
 		exit(-1);
 	}


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2009-03-23 17:26 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-03-23 17:26 gfs2-utils: master - gfs2_tool: gettext support Steven Whitehouse

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).