>From 770f813b787ce5c3ae2cbf56cd16d6ad824e04da Mon Sep 17 00:00:00 2001
From: Steven Whitehouse <[email protected]>
Date: Mon, 23 Mar 2009 17:04:13 +0000
Subject: [PATCH] mkfs.gfs2: Add gettext support

Same as for gfs2_tool. I hope that by adding the markup for
gettext it will encourage better English by making people think
a bit about how the message would need to be translated as well
as paving the way for later translations.

Signed-off-by: Steven Whitehouse <[email protected]>
---
 gfs2/mkfs/main.c      |    9 ++-
 gfs2/mkfs/main_grow.c |   46 ++++++++-------
 gfs2/mkfs/main_jadd.c |  135 ++++++++++++++++++++----------------------
 gfs2/mkfs/main_mkfs.c |  157 ++++++++++++++++++++++++-------------------------
 4 files changed, 172 insertions(+), 175 deletions(-)

diff --git a/gfs2/mkfs/main.c b/gfs2/mkfs/main.c
index 9471c6f..1e9d225 100644
--- a/gfs2/mkfs/main.c
+++ b/gfs2/mkfs/main.c
@@ -10,6 +10,8 @@
 #include <time.h>
 #include <errno.h>
 #include <libgen.h>
+#include <libintl.h>
+#define _(String) gettext(String)
 
 #include <linux/types.h>
 #include "libgfs2.h"
@@ -30,6 +32,9 @@ main(int argc, char *argv[])
 {
        char *p, *whoami;
 
+       setlocale(LC_ALL, "");
+       textdomain("mkfs.gfs2");
+
        prog_name = argv[0];
        srandom(time(NULL) ^ getpid());
 
@@ -43,9 +48,9 @@ main(int argc, char *argv[])
        else if (!strcmp(whoami, "gfs2_grow"))
                main_grow(argc, argv);
        else
-               die("I don't know who I am!\n");
+               die( _("I don't know who I am!\n"));
 
        free(p);
 
-       return EXIT_SUCCESS;
+       return 0;
 }
diff --git a/gfs2/mkfs/main_grow.c b/gfs2/mkfs/main_grow.c
index 0e18d1a..e87623a 100644
--- a/gfs2/mkfs/main_grow.c
+++ b/gfs2/mkfs/main_grow.c
@@ -16,6 +16,8 @@
 #include <errno.h>
 #include <stdarg.h>
 #include <linux/types.h>
+#include <libintl.h>
+#define _(String) gettext(String)
 
 #include "libgfs2.h"
 #include "gfs2_mkfs.h"
@@ -44,7 +46,7 @@ extern int rename2system(struct gfs2_sbd *sdp, char *new_dir, 
char *new_name);
 static void usage(void)
 {
        fprintf(stdout,
-               "Usage:\n"
+               _("Usage:\n"
                "\n"
                "gfs2_grow [options] /path/to/filesystem\n"
                "\n"
@@ -53,7 +55,7 @@ static void usage(void)
                "  -q               Quiet, reduce verbosity\n"
                "  -T               Test, do everything except update FS\n"
                "  -V               Version information\n"
-               "  -v               Verbose, increase verbosity\n");
+               "  -v               Verbose, increase verbosity\n"));
 }
 
 void decode_arguments(int argc, char *argv[], struct gfs2_sbd *sdp)
@@ -69,7 +71,7 @@ void decode_arguments(int argc, char *argv[], struct gfs2_sbd 
*sdp)
                case 'V':
                        printf("%s %s (built %s %s)\n", argv[0],
                               RELEASE_VERSION, __DATE__, __TIME__);
-                       printf("%s\n", REDHAT_COPYRIGHT);
+                       printf( _(REDHAT_COPYRIGHT "\n"));
                        exit(0);
                case 'h':
                        usage();
@@ -78,8 +80,8 @@ void decode_arguments(int argc, char *argv[], struct gfs2_sbd 
*sdp)
                        decrease_verbosity();
                        break;
                case 'T':
-                       printf("(Test mode--File system will not "
-                              "be changed)\n");
+                       printf( _("(Test mode--File system will not "
+                              "be changed)\n"));
                        test = 1;
                        break;
                case 'v':
@@ -88,11 +90,11 @@ void decode_arguments(int argc, char *argv[], struct 
gfs2_sbd *sdp)
                case ':':
                case '?':
                        /* Unknown flag */
-                       fprintf(stderr, "Please use '-h' for usage.\n");
+                       fprintf(stderr, _("Please use '-h' for usage.\n"));
                        exit(EXIT_FAILURE);
                default:
-                       fprintf(stderr, "Bad programmer! You forgot"
-                               " to catch the %c flag\n", opt);
+                       fprintf(stderr, _("Bad programmer! You forgot"
+                               " to catch the %c flag\n"), opt);
                        exit(EXIT_FAILURE);
                        break;
                }
@@ -191,11 +193,11 @@ void fix_rindex(struct gfs2_sbd *sdp, int rindex_fd, int 
old_rg_count)
        rg = 0;
        osi_list_foreach(tmp, &sdp->rglist)
                rg++;
-       log_info("%d new rindex entries.\n", rg);
+       log_info( _("%d new rindex entries.\n"), rg);
        writelen = rg * sizeof(struct gfs2_rindex);
        buf = calloc(1, writelen);
        if (buf == NULL) {
-               fprintf(stderr, "Out of memory in %s\n", __FUNCTION__);
+               fprintf(stderr, _("Out of memory in %s\n"), __FUNCTION__);
                exit(-1);
        }
        /* Now add the new rg entries to the rg index.  Here we     */
@@ -268,7 +270,7 @@ main_grow(int argc, char *argv[])
                if (check_for_gfs2(sdp)) {
                        if (errno == EINVAL)
                                fprintf(stderr,
-                                       "Not a valid GFS2 mount point: %s\n",
+                                       _("Not a valid GFS2 mount point: %s\n"),
                                        sdp->path_name);
                        else
                                fprintf(stderr, "%s\n", strerror(errno));
@@ -277,13 +279,13 @@ main_grow(int argc, char *argv[])
                sdp->device_fd = open(sdp->device_name,
                                      (test ? O_RDONLY : O_RDWR));
                if (sdp->device_fd < 0)
-                       die("can't open device %s: %s\n",
+                       die( _("can't open device %s: %s\n"),
                            sdp->device_name, strerror(errno));
                if (device_geometry(sdp)) {
-                       fprintf(stderr, "Geometry error\n");
+                       fprintf(stderr, _("Geometry error\n"));
                        exit(-1);
                }
-               log_info("Initializing lists...\n");
+               log_info( _("Initializing lists...\n"));
                osi_list_init(&sdp->rglist);
                init_buf_list(sdp, &sdp->buf_list, 128 << 20);
                init_buf_list(sdp, &sdp->nvbuf_list, 0xffffffff);
@@ -292,11 +294,11 @@ main_grow(int argc, char *argv[])
                sdp->bsize = sdp->sd_sb.sb_bsize;
                compute_constants(sdp);
                if(read_sb(sdp) < 0)
-                       die("gfs: Error reading superblock.\n");
+                       die( _("gfs: Error reading superblock.\n"));
 
                fix_device_geometry(sdp);
                if (mount_gfs2_meta(sdp)) {
-                       fprintf(stderr, "Error mounting GFS2 metafs: %s\n",
+                       fprintf(stderr, _("Error mounting GFS2 metafs: %s\n"),
                                        strerror(errno));
                        exit(-1);
                }
@@ -305,7 +307,7 @@ main_grow(int argc, char *argv[])
                rindex_fd = open(rindex_name, (test ? O_RDONLY : O_RDWR));
                if (rindex_fd < 0) {
                        cleanup_metafs(sdp);
-                       die("GFS2 rindex not found.  Please run gfs2_fsck.\n");
+                       die( _("GFS2 rindex not found.  Please run 
gfs2_fsck.\n"));
                }
                /* Get master dinode */
                sdp->master_dir =
@@ -321,11 +323,11 @@ main_grow(int argc, char *argv[])
                figure_out_rgsize(sdp, &rgsize);
                fsgrowth = ((sdp->device.length - fssize) * sdp->bsize);
                if (fsgrowth < rgsize * sdp->bsize) {
-                       log_err("Error: The device has grown by less than "
-                               "one Resource Group (RG).\n");
-                       log_err("The device grew by %" PRIu64 "MB.  ",
+                       log_err( _("Error: The device has grown by less than "
+                               "one Resource Group (RG).\n"));
+                       log_err( _("The device grew by %" PRIu64 "MB.  "),
                                fsgrowth / MB);
-                       log_err("One RG is %uMB for this file system.\n",
+                       log_err( _("One RG is %uMB for this file system.\n"),
                                (rgsize * sdp->bsize) / MB);
                }
                else {
@@ -345,5 +347,5 @@ main_grow(int argc, char *argv[])
        }
        close(sdp->path_fd);
        sync();
-       log_notice("gfs2_grow complete.\n");
+       log_notice( _("gfs2_grow complete.\n"));
 }
diff --git a/gfs2/mkfs/main_jadd.c b/gfs2/mkfs/main_jadd.c
index 3f574de..5f9e461 100644
--- a/gfs2/mkfs/main_jadd.c
+++ b/gfs2/mkfs/main_jadd.c
@@ -15,6 +15,8 @@
 #include <time.h>
 #include <errno.h>
 #include <stdarg.h>
+#include <libintl.h>
+#define _(String) gettext(String)
 
 #include <linux/types.h>
 #include "libgfs2.h"
@@ -23,38 +25,36 @@
 #define BUF_SIZE 4096
 #define RANDOM(values) ((values) * (random() / (RAND_MAX + 1.0)))
 
-void
-make_jdata(int fd, char *value)
+void make_jdata(int fd, char *value)
 {
         int err;
         uint32_t val;
 
         err = ioctl(fd, FS_IOC_GETFLAGS, &val);
         if (err)
-                die("error doing get flags (%d): %s\n", err, strerror(errno));
+                die( _("error doing get flags (%d): %s\n"), err, 
strerror(errno));
         if (strcmp(value, "set") == 0)
                 val |= FS_JOURNAL_DATA_FL;
         if (strcmp(value, "clear") == 0)
                 val &= ~FS_JOURNAL_DATA_FL;
         err = ioctl(fd, FS_IOC_SETFLAGS, &val);
         if (err)
-                die("error doing set flags (%d): %s\n", err, strerror(errno));
+                die( _("error doing set flags (%d): %s\n"), err, 
strerror(errno));
 }
 
-int 
-rename2system(struct gfs2_sbd *sdp, char *new_dir, char *new_name)
+int rename2system(struct gfs2_sbd *sdp, char *new_dir, char *new_name)
 {
        char oldpath[PATH_MAX], newpath[PATH_MAX];
        int error = 0;
        error = snprintf(oldpath, PATH_MAX, "%s/new_inode", 
                         sdp->metafs_path);
        if (error >= PATH_MAX)
-               die("rename2system (1)\n");
+               die( _("rename2system (1)\n"));
 
        error = snprintf(newpath, PATH_MAX, "%s/%s/%s",
                         sdp->metafs_path, new_dir, new_name);
        if (error >= PATH_MAX)
-               die("rename2system (2)\n");
+               die( _("rename2system (2)\n"));
        
        return rename(oldpath, newpath);
 }
@@ -64,22 +64,18 @@ rename2system(struct gfs2_sbd *sdp, char *new_dir, char 
*new_name)
  *
  */
 
-static void 
-print_usage(void)
+static void print_usage(void)
 {
-       printf("Usage:\n");
-       printf("\n");
-       printf("%s [options] /path/to/filesystem\n", prog_name);
-       printf("\n");
-       printf("Options:\n");
-       printf("\n");
-       printf("  -c <MB>           Size of quota change file\n");
-       printf("  -D                Enable debugging code\n");
-       printf("  -h                Print this help, then exit\n");
-       printf("  -J <MB>           Size of journals\n");
-       printf("  -j <num>          Number of journals\n");
-       printf("  -q                Don't print anything\n");
-       printf("  -V                Print program version information, then 
exit\n");
+       printf( _("Usage:\n\n"
+               "%s [options] /path/to/filesystem\n\n"
+               "Options:\n\n"
+               "  -c <MB>           Size of quota change file\n"
+               "  -D                Enable debugging code\n"
+               "  -h                Print this help, then exit\n"
+               "  -J <MB>           Size of journals\n"
+               "  -j <num>          Number of journals\n"
+               "  -q                Don't print anything\n"
+               "  -V                Print program version information, then 
exit\n"), prog_name);
 }
 
 /**
@@ -90,8 +86,7 @@ print_usage(void)
  *
  */
 
-static void
-decode_arguments(int argc, char *argv[], struct gfs2_sbd *sdp)
+static void decode_arguments(int argc, char *argv[], struct gfs2_sbd *sdp)
 {
        int cont = TRUE;
        int optchar;
@@ -108,7 +103,7 @@ decode_arguments(int argc, char *argv[], struct gfs2_sbd 
*sdp)
                        break;
                case 'h':
                        print_usage();
-                       exit(EXIT_SUCCESS);
+                       exit(0);
                        break;
                case 'J':
                        sdp->jsize = atoi(optarg);
@@ -122,22 +117,22 @@ decode_arguments(int argc, char *argv[], struct gfs2_sbd 
*sdp)
                case 'V':
                        printf("gfs2_jadd %s (built %s %s)\n", RELEASE_VERSION,
                               __DATE__, __TIME__);
-                       printf("%s\n", REDHAT_COPYRIGHT);
-                       exit(EXIT_SUCCESS);
+                       printf( _(REDHAT_COPYRIGHT "\n"));
+                       exit(0);
                        break;
                case 'X':
                        sdp->expert = TRUE;
                        break;
                case ':':
                case '?':
-                       fprintf(stderr, "Please use '-h' for usage.\n");
+                       fprintf(stderr, _("Please use '-h' for usage.\n"));
                        exit(EXIT_FAILURE);
                        break;
                case EOF:
                        cont = FALSE;
                        break;
                default:
-                       die("unknown option: %c\n", optchar);
+                       die( _("unknown option: %c\n"), optchar);
                        break;
                };
        }
@@ -146,13 +141,13 @@ decode_arguments(int argc, char *argv[], struct gfs2_sbd 
*sdp)
                sdp->path_name = argv[optind];
                optind++;
        } else
-               die("no path specified (try -h for help)\n");
+               die( _("no path specified (try -h for help)\n"));
        
        if (optind < argc)
-               die("Unrecognized option: %s\n", argv[optind]);
+               die( _("Unrecognized option: %s\n"), argv[optind]);
 
        if (sdp->debug) {
-               printf("Command Line Arguments:\n");
+               printf( _("Command Line Arguments:\n"));
                printf("  qcsize = %u\n", sdp->qcsize);
                printf("  jsize = %u\n", sdp->jsize);
                printf("  journals = %u\n", sdp->md.journals);
@@ -165,11 +160,11 @@ static void
 verify_arguments(struct gfs2_sbd *sdp)
 {
        if (!sdp->md.journals)
-               die("no journals specified\n");
+               die( _("no journals specified\n"));
        if (sdp->jsize < 32 || sdp->jsize > 1024)
-               die("bad journal size\n");
+               die( _("bad journal size\n"));
        if (!sdp->qcsize || sdp->qcsize > 64)
-               die("bad quota change size\n");
+               die( _("bad quota change size\n"));
 }
 
 /**
@@ -189,9 +184,9 @@ print_results(struct gfs2_sbd *sdp)
        if (sdp->expert)
                printf("Expert mode:            on\n");
 
-       printf("Filesystem:            %s\n", sdp->path_name);
-       printf("Old Journals           %u\n", sdp->orig_journals);
-       printf("New Journals           %u\n", sdp->md.journals);
+       printf( _("Filesystem:            %s\n"), sdp->path_name);
+       printf( _("Old Journals           %u\n"), sdp->orig_journals);
+       printf( _("New Journals           %u\n"), sdp->md.journals);
 
 }
 
@@ -213,17 +208,16 @@ create_new_inode(struct gfs2_sbd *sdp)
                if (errno == EEXIST) {
                        error = unlink(name);
                        if (error)
-                               die("can't unlink %s: %s\n",
+                               die( _("can't unlink %s: %s\n"),
                                    name, strerror(errno));
                } else
-                       die("can't create %s: %s\n", name, strerror(errno));
+                       die( _("can't create %s: %s\n"), name, strerror(errno));
        }
        
        return fd;
 }
 
-void 
-add_ir(struct gfs2_sbd *sdp)
+void add_ir(struct gfs2_sbd *sdp)
 {
        int fd;
        char new_name[256];
@@ -237,8 +231,8 @@ add_ir(struct gfs2_sbd *sdp)
                memset(&ir, 0, sizeof(struct gfs2_inum_range));
                if (write(fd, (void*)&ir, sizeof(struct gfs2_inum_range)) !=
                    sizeof(struct gfs2_inum_range)) {
-                       fprintf(stderr, "write error: %s from %s:%d: "
-                               "offset 0\n", strerror(errno),
+                       fprintf(stderr, _( "write error: %s from %s:%d: "
+                               "offset 0\n"), strerror(errno),
                                __FUNCTION__, __LINE__);
                        exit(-1);
                }
@@ -249,7 +243,7 @@ add_ir(struct gfs2_sbd *sdp)
        sprintf(new_name, "inum_range%u", sdp->md.journals);
        error = rename2system(sdp, "per_node", new_name);
        if (error < 0 && errno != EEXIST)
-               die("can't rename2system %s (%d): %s\n", 
+               die( _("can't rename2system %s (%d): %s\n"), 
                new_name, error, strerror(errno));
 }
 
@@ -269,8 +263,8 @@ add_sc(struct gfs2_sbd *sdp)
                memset(&sc, 0, sizeof(struct gfs2_statfs_change));
                if (write(fd, (void*)&sc, sizeof(struct gfs2_statfs_change)) !=
                    sizeof(struct gfs2_statfs_change)) {
-                       fprintf(stderr, "write error: %s from %s:%d: "
-                               "offset 0\n", strerror(errno),
+                       fprintf(stderr, _("write error: %s from %s:%d: "
+                               "offset 0\n"), strerror(errno),
                                __FUNCTION__, __LINE__);
                        exit(-1);
                }
@@ -281,7 +275,7 @@ add_sc(struct gfs2_sbd *sdp)
        sprintf(new_name, "statfs_change%u", sdp->md.journals);
        error = rename2system(sdp, "per_node", new_name);
        if (error < 0 && errno != EEXIST)
-               die("can't rename2system %s (%d): %s\n",
+               die( _("can't rename2system %s (%d): %s\n"),
                    new_name, error, strerror(errno));
 }
 
@@ -306,8 +300,8 @@ add_qc(struct gfs2_sbd *sdp)
 
                for (x=0; x<blocks; x++) {
                        if (write(fd, buf, sdp->bsize) != sdp->bsize) {
-                               fprintf(stderr, "write error: %s from %s:%d: "
-                                       "block %lld (0x%llx)\n",
+                               fprintf(stderr, _("write error: %s from %s:%d: "
+                                       "block %lld (0x%llx)\n"),
                                        strerror(errno),
                                        __FUNCTION__, __LINE__,
                                        (unsigned long long)x,
@@ -326,8 +320,8 @@ add_qc(struct gfs2_sbd *sdp)
 
                for (x=0; x<blocks; x++) {
                        if (write(fd, buf, sdp->bsize) != sdp->bsize) {
-                               fprintf(stderr, "write error: %s from %s:%d: "
-                                       "block %lld (0x%llx)\n",
+                               fprintf(stderr, _("write error: %s from %s:%d: "
+                                       "block %lld (0x%llx)\n"),
                                        strerror(errno),
                                        __FUNCTION__, __LINE__,
                                        (unsigned long long)x,
@@ -338,7 +332,7 @@ add_qc(struct gfs2_sbd *sdp)
 
                error = fsync(fd);
                if (error)
-                       die("can't fsync: %s\n",
+                       die( _("can't fsync: %s\n"),
                            strerror(errno));
        }
 
@@ -347,7 +341,7 @@ add_qc(struct gfs2_sbd *sdp)
        sprintf(new_name, "quota_change%u", sdp->md.journals);
        error = rename2system(sdp, "per_node", new_name);
        if (error < 0 && errno != EEXIST)
-               die("can't rename2system %s (%d): %s\n",
+               die( _("can't rename2system %s (%d): %s\n"),
                    new_name, error, strerror(errno));
 }
 
@@ -356,7 +350,7 @@ gather_info(struct gfs2_sbd *sdp)
 {
        struct statfs statbuf;
        if (statfs(sdp->path_name, &statbuf) < 0) {
-               die("Could not statfs the filesystem %s: %s\n",
+               die( _("Could not statfs the filesystem %s: %s\n"),
                    sdp->path_name, strerror(errno));
        }
        sdp->bsize = statbuf.f_bsize;
@@ -373,8 +367,8 @@ find_current_journals(struct gfs2_sbd *sdp)
        sprintf(jindex, "%s/jindex", sdp->metafs_path);
        dirp = opendir(jindex);
        if (!dirp) {
-               die("Could not find the jindex directory "
-                   "in gfs2meta mount! error: %s\n", strerror(errno));
+               die( _("Could not find the jindex directory "
+                   "in gfs2meta mount! error: %s\n"), strerror(errno));
        }
        while (dirp) {
                if ((dp = readdir(dirp)) != NULL) {
@@ -386,8 +380,8 @@ find_current_journals(struct gfs2_sbd *sdp)
 close:
        closedir(dirp);
        if (existing_journals <= 0) {
-               die("There are no journals for this "
-                   "gfs2 fs! Did you mkfs.gfs2 correctly?\n");
+               die( _("There are no journals for this "
+                   "gfs2 fs! Did you mkfs.gfs2 correctly?\n"));
        }
 
        sdp->orig_journals = existing_journals;
@@ -414,8 +408,8 @@ add_j(struct gfs2_sbd *sdp)
                memset(buf, 0, sdp->bsize);
                for (x=0; x<blocks; x++) {
                        if (write(fd, buf, sdp->bsize) != sdp->bsize) {
-                               fprintf(stderr, "write error: %s from %s:%d: "
-                                       "block %lld (0x%llx)\n",
+                               fprintf(stderr, _("write error: %s from %s:%d: "
+                                       "block %lld (0x%llx)\n"),
                                        strerror(errno),
                                        __FUNCTION__, __LINE__,
                                        (unsigned long long)x,
@@ -442,8 +436,8 @@ add_j(struct gfs2_sbd *sdp)
                        ((struct gfs2_log_header *)buf)->lh_hash = 
cpu_to_be32(hash);
 
                        if (write(fd, buf, sdp->bsize) != sdp->bsize) {
-                               fprintf(stderr, "write error: %s from %s:%d: "
-                                       "block %lld (0x%llx)\n",
+                               fprintf(stderr, _("write error: %s from %s:%d: "
+                                       "block %lld (0x%llx)\n"),
                                        strerror(errno),
                                        __FUNCTION__, __LINE__,
                                        (unsigned long long)x,
@@ -457,7 +451,7 @@ add_j(struct gfs2_sbd *sdp)
 
                error = fsync(fd);
                if (error)
-                       die("can't fsync: %s\n",
+                       die( _("can't fsync: %s\n"),
                            strerror(errno));
        }
 
@@ -466,7 +460,7 @@ add_j(struct gfs2_sbd *sdp)
        sprintf(new_name, "journal%u", sdp->md.journals);
        error = rename2system(sdp, "jindex", new_name);
        if (error < 0 && errno != EEXIST)
-               die("can't rename2system %s (%d): %s\n",
+               die( _("can't rename2system %s (%d): %s\n"),
                    new_name, error, strerror(errno));
 }
 
@@ -477,8 +471,7 @@ add_j(struct gfs2_sbd *sdp)
  *
  */
 
-void 
-main_jadd(int argc, char *argv[])
+void main_jadd(int argc, char *argv[])
 {
        struct gfs2_sbd sbd, *sdp = &sbd;
        unsigned int total;
@@ -493,12 +486,12 @@ main_jadd(int argc, char *argv[])
        
        sdp->path_fd = open(sdp->path_name, O_RDONLY);
        if (sdp->path_fd < 0)
-               die("can't open root directory %s: %s\n",
+               die( _("can't open root directory %s: %s\n"),
                    sdp->path_name, strerror(errno));
 
        if (check_for_gfs2(sdp)) {
                if (errno == EINVAL)
-                       fprintf(stderr, "Not a valid GFS2 mount point: %s\n",
+                       fprintf(stderr, _("Not a valid GFS2 mount point: %s\n"),
                                        sdp->path_name);
                else
                        fprintf(stderr, "%s\n", strerror(errno));
@@ -508,7 +501,7 @@ main_jadd(int argc, char *argv[])
        gather_info(sdp);
 
        if (mount_gfs2_meta(sdp)) {
-               fprintf(stderr, "Error mounting GFS2 metafs: %s\n",
+               fprintf(stderr, _("Error mounting GFS2 metafs: %s\n"),
                                strerror(errno));
                exit(-1);
        }
diff --git a/gfs2/mkfs/main_mkfs.c b/gfs2/mkfs/main_mkfs.c
index cdc0068..edda1d0 100644
--- a/gfs2/mkfs/main_mkfs.c
+++ b/gfs2/mkfs/main_mkfs.c
@@ -13,6 +13,8 @@
 #include <mntent.h>
 #include <ctype.h>
 #include <sys/time.h>
+#include <libintl.h>
+#define _(String) gettext(String)
 
 #include <linux/types.h>
 #include "libgfs2.h"
@@ -42,25 +44,22 @@ void print_it(const char *label, const char *fmt, const 
char *fmt2, ...)
 static void
 print_usage(void)
 {
-       printf("Usage:\n");
-       printf("\n");
-       printf("%s [options] <device> [ block-count ]\n", prog_name);
-       printf("\n");
-       printf("Options:\n");
-       printf("\n");
-       printf("  -b <bytes>       Filesystem block size\n");
-       printf("  -c <MB>          Size of quota change file\n");
-       printf("  -D               Enable debugging code\n");
-       printf("  -h               Print this help, then exit\n");
-       printf("  -J <MB>          Size of journals\n");
-       printf("  -j <num>         Number of journals\n");
-       printf("  -O               Don't ask for confirmation\n");
-       printf("  -p <name>        Name of the locking protocol\n");
-       printf("  -q               Don't print anything\n");
-       printf("  -r <MB>          Resource Group Size\n");
-       printf("  -t <name>        Name of the lock table\n");
-       printf("  -u <MB>          Size of unlinked file\n");
-       printf("  -V               Print program version information, then 
exit\n");
+       printf( _("Usage:\n\n"
+               "%s [options] <device> [ block-count ]\n\n"
+               "Options:\n\n"
+               "  -b <bytes>       Filesystem block size\n"
+               "  -c <MB>          Size of quota change file\n"
+               "  -D               Enable debugging code\n"
+               "  -h               Print this help, then exit\n"
+               "  -J <MB>          Size of journals\n"
+               "  -j <num>         Number of journals\n"
+               "  -O               Don't ask for confirmation\n"
+               "  -p <name>        Name of the locking protocol\n"
+               "  -q               Don't print anything\n"
+               "  -r <MB>          Resource Group Size\n"
+               "  -t <name>        Name of the lock table\n"
+               "  -u <MB>          Size of unlinked file\n"
+               "  -V               Print program version information, then 
exit\n"), prog_name);
 }
 
 /**
@@ -71,8 +70,7 @@ print_usage(void)
  *
  */
 
-static void
-decode_arguments(int argc, char *argv[], struct gfs2_sbd *sdp)
+static void decode_arguments(int argc, char *argv[], struct gfs2_sbd *sdp)
 {
        int cont = TRUE;
        int optchar;
@@ -99,7 +97,7 @@ decode_arguments(int argc, char *argv[], struct gfs2_sbd *sdp)
 
                case 'h':
                        print_usage();
-                       exit(EXIT_SUCCESS);
+                       exit(0);
                        break;
 
                case 'J':
@@ -116,7 +114,7 @@ decode_arguments(int argc, char *argv[], struct gfs2_sbd 
*sdp)
 
                case 'p':
                        if (strlen(optarg) >= GFS2_LOCKNAME_LEN)
-                               die("lock protocol name %s is too long\n",
+                               die( _("lock protocol name %s is too long\n"),
                                    optarg);
                        strcpy(sdp->lockproto, optarg);
                        break;
@@ -131,7 +129,7 @@ decode_arguments(int argc, char *argv[], struct gfs2_sbd 
*sdp)
 
                case 't':
                        if (strlen(optarg) >= GFS2_LOCKNAME_LEN)
-                               die("lock table name %s is too long\n", optarg);
+                               die( _("lock table name %s is too long\n"), 
optarg);
                        strcpy(sdp->locktable, optarg);
                        break;
 
@@ -142,7 +140,7 @@ decode_arguments(int argc, char *argv[], struct gfs2_sbd 
*sdp)
                case 'V':
                        printf("gfs2_mkfs %s (built %s %s)\n", RELEASE_VERSION,
                               __DATE__, __TIME__);
-                       printf("%s\n", REDHAT_COPYRIGHT);
+                       printf( _(REDHAT_COPYRIGHT "\n"));
                        exit(EXIT_SUCCESS);
                        break;
 
@@ -152,7 +150,7 @@ decode_arguments(int argc, char *argv[], struct gfs2_sbd 
*sdp)
 
                case ':':
                case '?':
-                       fprintf(stderr, "Please use '-h' for usage.\n");
+                       fprintf(stderr, _("Please use '-h' for usage.\n"));
                        exit(EXIT_FAILURE);
                        break;
 
@@ -169,11 +167,11 @@ decode_arguments(int argc, char *argv[], struct gfs2_sbd 
*sdp)
                                 isdigit(optarg[0]))
                                sdp->orig_fssize = atol(optarg);
                        else
-                               die("More than one device specified (try -h for 
help)\n");
+                               die( _("More than one device specified (try -h 
for help)\n"));
                        break;
 
                default:
-                       die("unknown option: %c\n", optchar);
+                       die( _("unknown option: %c\n"), optchar);
                        break;
                };
        }
@@ -182,16 +180,16 @@ decode_arguments(int argc, char *argv[], struct gfs2_sbd 
*sdp)
                strcpy(sdp->device_name, argv[optind++]);
 
        if (sdp->device_name[0] == '\0')
-               die("no device specified (try -h for help)\n");
+               die( _("no device specified (try -h for help)\n"));
 
        if (optind < argc)
                sdp->orig_fssize = atol(argv[optind++]);
 
        if (optind < argc)
-               die("Unrecognized argument: %s\n", argv[optind]);
+               die( _("Unrecognized argument: %s\n"), argv[optind]);
 
        if (sdp->debug) {
-               printf("Command Line Arguments:\n");
+               printf( _("Command Line Arguments:\n"));
                printf("  bsize = %u\n", sdp->bsize);
                printf("  qcsize = %u\n", sdp->qcsize);
                printf("  jsize = %u\n", sdp->jsize);
@@ -200,7 +198,7 @@ decode_arguments(int argc, char *argv[], struct gfs2_sbd 
*sdp)
                printf("  proto = %s\n", sdp->lockproto);
                printf("  quiet = %d\n", sdp->quiet);
                if (sdp->rgsize==-1)
-                       printf("  rgsize = optimize for best performance\n");
+                       printf( _("  rgsize = optimize for best 
performance\n"));
                else
                        printf("  rgsize = %u\n", sdp->rgsize);
                printf("  table = %s\n", sdp->locktable);
@@ -229,33 +227,33 @@ static void test_locking(char *lockproto, char *locktable)
                   strcmp(lockproto, "lock_dlm") == 0) {
                for (c = locktable; *c; c++) {
                        if (isspace(*c))
-                               die("locktable error: contains space 
characters\n");
+                               die( _("locktable error: contains space 
characters\n"));
                        if (!isprint(*c))
-                               die("locktable error: contains unprintable 
characters\n");
+                               die( _("locktable error: contains unprintable 
characters\n"));
                }
 
                c = strstr(locktable, ":");
                if (!c)
-                       die("locktable error: missing colon in the 
locktable\n");
+                       die( _("locktable error: missing colon in the 
locktable\n"));
 
                if (c == locktable)
-                       die("locktable error: missing cluster name\n");
+                       die( _("locktable error: missing cluster name\n"));
                if (c - locktable > 16)
-                       die("locktable error: cluster name too long\n");
+                       die( _("locktable error: cluster name too long\n"));
 
                c++;
                if (!c)
-                       die("locktable error: missing filesystem name\n");
+                       die( _("locktable error: missing filesystem name\n"));
 
                if (strstr(c, ":"))
-                       die("locktable error: more than one colon present\n");
+                       die( _("locktable error: more than one colon 
present\n"));
 
                if (!strlen(c))
-                       die("locktable error: missing filesystem name\n");
+                       die( _("locktable error: missing filesystem name\n"));
                if (strlen(c) > 16)
-                       die("locktable error: filesystem name too long\n");
+                       die( _("locktable error: filesystem name too long\n"));
        } else {
-               die("lockproto error: %s unknown\n", lockproto);
+               die( _("lockproto error: %s unknown\n"), lockproto);
        }
 }
 
@@ -273,28 +271,28 @@ static void verify_arguments(struct gfs2_sbd *sdp)
                        break;
 
        if (!x || sdp->bsize > 65536)
-               die("block size must be a power of two between 512 and 
65536\n");
+               die( _("block size must be a power of two between 512 and 
65536\n"));
 
        /* Look at this!  Why can't we go bigger than 2GB? */
        if (sdp->expert) {
                if (1 > sdp->rgsize || sdp->rgsize > 2048)
-                       die("bad resource group size\n");
+                       die( _("bad resource group size\n"));
        } else {
                if (32 > sdp->rgsize || sdp->rgsize > 2048)
-                       die("bad resource group size\n");
+                       die( _("bad resource group size\n"));
        }
 
        if (!sdp->md.journals)
-               die("no journals specified\n");
+               die( _("no journals specified\n"));
 
        if (sdp->jsize < 8 || sdp->jsize > 1024)
-               die("bad journal size\n");
+               die( _("bad journal size\n"));
 
        if (!sdp->utsize || sdp->utsize > 64)
-               die("bad unlinked size\n");
+               die( _("bad unlinked size\n"));
 
        if (!sdp->qcsize || sdp->qcsize > 64)
-               die("bad quota change size\n");
+               die( _("bad quota change size\n"));
 }
 
 /**
@@ -311,14 +309,14 @@ static void are_you_sure(struct gfs2_sbd *sdp)
 
        fd = open(sdp->device_name, O_RDONLY);
        if (fd < 0)
-               die("Error: device %s not found.\n", sdp->device_name);
+               die( _("Error: device %s not found.\n"), sdp->device_name);
        vid = volume_id_open_fd(fd);
        if (vid == NULL) {
                close(fd);
-               die("error identifying the contents of %s: %s\n",
+               die( _("error identifying the contents of %s: %s\n"),
                    sdp->device_name, strerror(errno));
        }
-       printf("This will destroy any data on %s.\n", sdp->device_name);
+       printf( _("This will destroy any data on %s.\n"), sdp->device_name);
        if (volume_id_probe_all(vid, 0, sdp->device_size) == 0) {
                const char *fstype, *fsusage;
                int rc;
@@ -328,18 +326,18 @@ static void are_you_sure(struct gfs2_sbd *sdp)
                        rc = volume_id_get_usage(vid, &fsusage);
                        if (!rc || strncmp(fsusage, "other", 5) == 0)
                                fsusage = "partition";
-                       printf("  It appears to contain a %s %s.\n", fstype,
+                       printf( _("  It appears to contain a %s %s.\n"), fstype,
                               fsusage);
                }
        }
        volume_id_close(vid);
        close(fd);
-       printf("\nAre you sure you want to proceed? [y/n] ");
+       printf( _("\nAre you sure you want to proceed? [y/n] "));
        if(!fgets(input, 32, 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"));
        else
                printf("\n");
 }
@@ -356,15 +354,15 @@ void check_mount(char *device)
        int fd;
 
        if (stat(device, &st_buf) < 0)
-               die("could not stat device %s\n", device);
+               die( _("could not stat device %s\n"), device);
        if (!S_ISBLK(st_buf.st_mode))
-               die("%s is not a block device\n", device);
+               die( _("%s is not a block device\n"), device);
 
        fd = open(device, O_RDONLY | O_NONBLOCK | O_EXCL);
 
        if (fd < 0) {
                if (errno == EBUSY) {
-                       die("device %s is busy\n", device);
+                       die( _("device %s is busy\n"), device);
                }
        }
        else {
@@ -434,31 +432,31 @@ print_results(struct gfs2_sbd *sdp, uint64_t 
real_device_size,
                return;
 
        if (sdp->expert)
-               printf("Expert mode:               on\n");
+               printf( _("Expert mode:               on\n"));
 
-       printf("Device:                    %s\n", sdp->device_name);
+       printf( _("Device:                    %s\n"), sdp->device_name);
 
-       printf("Blocksize:                 %u\n", sdp->bsize);
-       printf("Device Size                %.2f GB (%"PRIu64" blocks)\n",
+       printf( _("Blocksize:                 %u\n"), sdp->bsize);
+       printf( _("Device Size                %.2f GB (%"PRIu64" blocks)\n"),
               real_device_size / ((float)(1 << 30)),
               real_device_size / sdp->bsize);
-       printf("Filesystem Size:           %.2f GB (%"PRIu64" blocks)\n",
+       printf( _("Filesystem Size:           %.2f GB (%"PRIu64" blocks)\n"),
               sdp->fssize / ((float)(1 << 30)) * sdp->bsize, sdp->fssize);
 
-       printf("Journals:                  %u\n", sdp->md.journals);
-       printf("Resource Groups:           %"PRIu64"\n", sdp->rgrps);
+       printf( _("Journals:                  %u\n"), sdp->md.journals);
+       printf( _("Resource Groups:           %"PRIu64"\n"), sdp->rgrps);
 
-       printf("Locking Protocol:          \"%s\"\n", sdp->lockproto);
-       printf("Lock Table:                \"%s\"\n", sdp->locktable);
+       printf( _("Locking Protocol:          \"%s\"\n"), sdp->lockproto);
+       printf( _("Lock Table:                \"%s\"\n"), sdp->locktable);
 
        if (sdp->debug) {
                printf("\n");
-               printf("Spills:                    %u\n",
+               printf( _("Spills:                    %u\n"),
                       sdp->buf_list.spills);
-               printf("Writes:                    %u\n", sdp->writes);
+               printf( _("Writes:                    %u\n"), sdp->writes);
        }
 
-       printf("UUID:                      %s\n", str_uuid(uuid));
+       printf( _("UUID:                      %s\n"), str_uuid(uuid));
        printf("\n");
 }
 
@@ -469,8 +467,7 @@ print_results(struct gfs2_sbd *sdp, uint64_t 
real_device_size,
  *
  */
 
-void
-main_mkfs(int argc, char *argv[])
+void main_mkfs(int argc, char *argv[])
 {
        struct gfs2_sbd sbd, *sdp = &sbd;
        int error;
@@ -502,7 +499,7 @@ main_mkfs(int argc, char *argv[])
 
        sdp->device_fd = open(sdp->device_name, O_RDWR);
        if (sdp->device_fd < 0)
-               die("can't open device %s: %s\n",
+               die( _("can't open device %s: %s\n"),
                    sdp->device_name, strerror(errno));
 
        if (!sdp->override)
@@ -514,7 +511,7 @@ main_mkfs(int argc, char *argv[])
 
        device_size(sdp->device_fd, &real_device_size);
        if (device_geometry(sdp)) {
-               fprintf(stderr, "Geometry error\n");
+               fprintf(stderr, _("Geometry error\n"));
                exit(-1);
        }
        /* Convert optional block-count to basic blocks */
@@ -522,9 +519,9 @@ main_mkfs(int argc, char *argv[])
                sdp->orig_fssize *= sdp->bsize;
                sdp->orig_fssize >>= GFS2_BASIC_BLOCK_SHIFT;
                if (sdp->orig_fssize > sdp->device.length) {
-                       fprintf(stderr, "%s: Specified block count is bigger "
-                               "than the actual device.\n", prog_name);
-                       die("Device Size is %.2f GB (%"PRIu64" blocks)\n",
+                       fprintf(stderr, _("%s: Specified block count is bigger "
+                               "than the actual device.\n"), prog_name);
+                       die( _("Device Size is %.2f GB (%"PRIu64" blocks)\n"),
                               real_device_size / ((float)(1 << 30)),
                               real_device_size / sdp->bsize);
                }
@@ -565,11 +562,11 @@ main_mkfs(int argc, char *argv[])
 
        error = fsync(sdp->device_fd);
        if (error)
-               die("can't fsync device (%d): %s\n",
+               die( _("can't fsync device (%d): %s\n"),
                    error, strerror(errno));
        error = close(sdp->device_fd);
        if (error)
-               die("error closing device (%d): %s\n",
+               die( _("error closing device (%d): %s\n"),
                    error, strerror(errno));
 
        print_results(sdp, real_device_size, uuid);
-- 
1.6.0.6



Reply via email to