Skip to contentSkip to conversation

gfs2_tool: gettext support

Cluster-devel Steven Whitehouse 1 participant 1 message Mar 23, 2009

lore
Share & tools
lore
#0 lore raw

From 611960af035b1296e610a6f977bc836a7fbadd7f Mon Sep 17 00:00:00 2001
From: Steven Whitehouse <[email protected]>
Date: Mon, 23 Mar 2009 16:29:55 +0000
Subject: [PATCH] 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.

---
 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(-)
gfs2/tool/df.c +30 -28
index 8b6d9b4..53c645d 100644
@@ -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)
gfs2/tool/main.c +58 -79

209 lines not on this page · raw message

gfs2/tool/misc.c +33 -32

234 lines not on this page · raw message

gfs2/tool/sb.c +31 -29

166 lines not on this page · raw message

gfs2/tool/tune.c +14 -12
index 277d2dd..4666291 100644
@@ -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);
 	}
Signature · 1 line
1.6.0.6