cluster-devel.redhat.com archive mirror
 help / color / mirror / Atom feed
* [Cluster-devel] [PATCH 1/3] mkfs: Use rpmatch() to yes/no questions
@ 2011-09-27 16:08 Carlos Maiolino
  2011-09-27 16:08 ` [Cluster-devel] [PATCH 2/3] mkfs: Remove unneeded open/close fd test from are_you_sure() Carlos Maiolino
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Carlos Maiolino @ 2011-09-27 16:08 UTC (permalink / raw)
  To: cluster-devel.redhat.com

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.\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



^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2011-09-28  9:20 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-09-27 16:08 [Cluster-devel] [PATCH 1/3] mkfs: Use rpmatch() to yes/no questions Carlos Maiolino
2011-09-27 16:08 ` [Cluster-devel] [PATCH 2/3] mkfs: Remove unneeded open/close fd test from are_you_sure() Carlos Maiolino
2011-09-27 16:08   ` [Cluster-devel] [PATCH 3/3] mkfs: remove duplicated code to ask yes/no question Carlos Maiolino
2011-09-27 16:35     ` Bob Peterson
2011-09-28  9:20     ` Steven Whitehouse
2011-09-27 16:37   ` [Cluster-devel] [PATCH 2/3] mkfs: Remove unneeded open/close fd test from are_you_sure() Bob Peterson
2011-09-27 17:37     ` Carlos Maiolino
2011-09-27 18:01       ` Bob Peterson
2011-09-27 16:34 ` [Cluster-devel] [PATCH 1/3] mkfs: Use rpmatch() to yes/no questions Bob Peterson
2011-09-28  9:18 ` 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 NNTP newsgroup(s).