FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Redhat > Cluster Development

 
 
LinkBack Thread Tools
 
Old 09-27-2011, 04:08 PM
Carlos Maiolino
 
Default mkfs: Use rpmatch() to yes/no questions

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 <cmaiolino@redhat.com>
---
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.
");
+ printf(_("Successful.
"));
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.
"), sdp->device_name);
check_dev_content(sdp->device_name);
close(fd);
- printf( _("
Are you sure you want to proceed? [y/n] "));
- if(!fgets(input, 32, stdin))
- die( _("unable to read from stdin
"));
+
+ 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("
");
+ die( _("aborted
"));
+ }
+
+ }while(ret >= 0);

- if (input[0] != 'y')
- die( _("aborted
"));
- else
- printf("
");
+ if(line)
+ free(line);
}

/**
--
1.7.6
 
Old 09-28-2011, 09:18 AM
Steven Whitehouse
 
Default mkfs: Use rpmatch() to yes/no questions

Hi,

On Tue, 2011-09-27 at 13:08 -0300, Carlos Maiolino wrote:
> 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 <cmaiolino@redhat.com>
> ---
> 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.
");
> + printf(_("Successful.
"));
Maybe just say "Success" here? Can this be made to match other similar
strings?

> 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.
"), sdp->device_name);
> check_dev_content(sdp->device_name);
> close(fd);
> - printf( _("
Are you sure you want to proceed? [y/n] "));
> - if(!fgets(input, 32, stdin))
> - die( _("unable to read from stdin
"));
> +
> + 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("
");
> + die( _("aborted
"));
Please don't add more die() calls. Could we replace this with another
message? Don't be afraid to do:

errno = ESOMETHING;
perror();

or to use strerror() when required,

Steve.
 

Thread Tools




All times are GMT. The time now is 04:47 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org