From mboxrd@z Thu Jan 1 00:00:00 1970 From: Carlos Maiolino Date: Tue, 27 Sep 2011 13:08:21 -0300 Subject: [Cluster-devel] [PATCH 1/3] mkfs: Use rpmatch() to yes/no questions Message-ID: <1317139703-2755-1-git-send-email-cmaiolino@redhat.com> List-Id: To: cluster-devel.redhat.com MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit This patch changes the are_you_sure() function to make use of rpmatch() to identify the user's answer in the language set in the i18n Also add 2 another translatable strings Signed-off-by: Carlos Maiolino --- gfs2/mkfs/main_mkfs.c | 34 ++++++++++++++++++++++++---------- 1 files changed, 24 insertions(+), 10 deletions(-) diff --git a/gfs2/mkfs/main_mkfs.c b/gfs2/mkfs/main_mkfs.c index 4751f19..cc678fe 100644 --- a/gfs2/mkfs/main_mkfs.c +++ b/gfs2/mkfs/main_mkfs.c @@ -78,7 +78,7 @@ static int discard_blocks(struct gfs2_sbd *sdp) range[0] = 0; range[1] = sdp->device.length * sdp->bsize; if (sdp->debug) - printf("Issuing discard ioctl: range: %llu - %llu...", + printf(_("Issuing discard ioctl: range: %llu - %llu..."), (unsigned long long)range[0], (unsigned long long)range[1]); if (ioctl(sdp->device_fd, BLKDISCARD, &range) < 0) { @@ -87,7 +87,7 @@ static int discard_blocks(struct gfs2_sbd *sdp) return errno; } if (sdp->debug) - printf("Successful.\n"); + printf(_("Successful.\n")); return 0; } @@ -456,8 +456,11 @@ fail: static void are_you_sure(struct gfs2_sbd *sdp) { - char input[32]; + char *line = NULL; + size_t len = 0; int fd; + int ret = -1; + int res = 0; fd = open(sdp->device_name, O_RDONLY|O_CLOEXEC); if (fd < 0) @@ -465,14 +468,25 @@ static void are_you_sure(struct gfs2_sbd *sdp) printf( _("This will destroy any data on %s.\n"), sdp->device_name); check_dev_content(sdp->device_name); close(fd); - printf( _("\nAre you sure you want to proceed? [y/n] ")); - if(!fgets(input, 32, stdin)) - die( _("unable to read from stdin\n")); + + do{ + printf( _("Are you sure you want to proceed? [y/n]")); + ret = getline(&line, &len, stdin); + res = rpmatch(line); + + if (res > 0){ + free(line); + return; + } + if (!res){ + printf("\n"); + die( _("aborted\n")); + } + + }while(ret >= 0); - if (input[0] != 'y') - die( _("aborted\n")); - else - printf("\n"); + if(line) + free(line); } /** -- 1.7.6