[PATCH] e2fsck/e2fsprogs: answer yes/no to a group of questions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

saying yes or no to all e2fsck questions can be rather annoying (yes I
know -p and -y), so here's a patch to answer yes or no to a group of
questions.

Cheers,
Bernd
diff -r 9a2f051a0a1d e2fsck/e2fsck.h
--- a/e2fsck/e2fsck.h	Fri Jun 29 23:09:16 2007 -0400
+++ b/e2fsck/e2fsck.h	Fri Jul 27 16:08:50 2007 +0200
@@ -349,6 +349,14 @@ extern int e2fsck_strnlen(const char * s
 extern int e2fsck_strnlen(const char * s, int count);
 #endif
 
+typedef enum answer {
+	NO         = 0,
+	YES        = 1,
+	YES_TO_ALL = 2,
+	NO_TO_ALL  = 3
+} answer_t;
+
+
 /*
  * Procedure declarations
  */
diff -r 9a2f051a0a1d e2fsck/problem.c
--- a/e2fsck/problem.c	Fri Jun 29 23:09:16 2007 -0400
+++ b/e2fsck/problem.c	Fri Jul 27 16:08:50 2007 +0200
@@ -1608,7 +1608,8 @@ int fix_problem(e2fsck_t ctx, problem_t 
 	struct e2fsck_problem *ptr;
 	struct latch_descr *ldesc = 0;
 	const char *message;
-	int 		def_yn, answer, ans;
+	int 		def_yn, ans;
+	answer_t	answer;
 	int		print_answer = 0;
 	int		suppress = 0;
 
@@ -1617,6 +1618,15 @@ int fix_problem(e2fsck_t ctx, problem_t 
 		printf(_("Unhandled error code (0x%x)!\n"), code);
 		return 0;
 	}
+
+	if (ptr->flags & PR_YES_TO_ALL) {
+		printf("%s: yes\n", _(prompt[(int) ptr->prompt]));
+		return YES;
+	} else if (ptr->flags & PR_NO_TO_ALL) {
+		printf("%s: no\n", _(prompt[(int) ptr->prompt]));
+		return NO;
+	}
+
 	if (!(ptr->flags & PR_CONFIG)) {
 		char	key[9], *new_desc;
 
@@ -1638,11 +1648,11 @@ int fix_problem(e2fsck_t ctx, problem_t 
 
 		ptr->flags |= PR_CONFIG;
 	}
-	def_yn = 1;
+	def_yn = YES;
 	if ((ptr->flags & PR_NO_DEFAULT) ||
 	    ((ptr->flags & PR_PREEN_NO) && (ctx->options & E2F_OPT_PREEN)) ||
 	    (ctx->options & E2F_OPT_NO))
-		def_yn= 0;
+		def_yn= NO;
 
 	/*
 	 * Do special latch processing.  This is where we ask the
@@ -1652,9 +1662,9 @@ int fix_problem(e2fsck_t ctx, problem_t 
 		ldesc = find_latch(ptr->flags & PR_LATCH_MASK);
 		if (ldesc->question && !(ldesc->flags & PRL_LATCHED)) {
 			ans = fix_problem(ctx, ldesc->question, pctx);
-			if (ans == 1)
+			if (ans == YES)
 				ldesc->flags |= PRL_YES;
-			if (ans == 0)
+			if (ans == NO)
 				ldesc->flags |= PRL_NO;
 			ldesc->flags |= PRL_LATCHED;
 		}
@@ -1698,9 +1708,9 @@ int fix_problem(e2fsck_t ctx, problem_t 
 			if (!suppress)
 				print_answer = 1;
 			if (ldesc->flags & PRL_YES)
-				answer = 1;
+				answer = YES;
 			else
-				answer = 0;
+				answer = NO;
 		} else
 			answer = ask(ctx, _(prompt[(int) ptr->prompt]), def_yn);
 		if (!answer && !(ptr->flags & PR_NO_OK))
@@ -1709,7 +1719,14 @@ int fix_problem(e2fsck_t ctx, problem_t 
 		if (print_answer)
 			printf("%s.\n", answer ?
 			       _(preen_msg[(int) ptr->prompt]) : _("IGNORED"));
-	
+
+		if (answer == YES_TO_ALL) {
+			ptr->flags |= PR_YES_TO_ALL;
+			answer = YES;
+		} else if (answer == NO_TO_ALL) {
+			ptr->flags |= PR_NO_TO_ALL;
+			answer = YES;
+		}
 	}
 
 	if ((ptr->prompt == PROMPT_ABORT) && answer)
diff -r 9a2f051a0a1d e2fsck/problemP.h
--- a/e2fsck/problemP.h	Fri Jun 29 23:09:16 2007 -0400
+++ b/e2fsck/problemP.h	Fri Jul 27 16:08:50 2007 +0200
@@ -41,3 +41,5 @@ struct latch_descr {
 #define PR_PREEN_NOHDR	0x040000 /* Don't print the preen header */
 #define PR_CONFIG	0x080000 /* This problem has been customized 
 				    from the config file */
+#define PR_NO_TO_ALL    0x100000 /* Yes to all questions of this type */
+#define PR_YES_TO_ALL   0x200000 /* Yes to all questions of this type */
diff -r 9a2f051a0a1d e2fsck/util.c
--- a/e2fsck/util.c	Fri Jun 29 23:09:16 2007 -0400
+++ b/e2fsck/util.c	Fri Jul 27 16:08:50 2007 +0200
@@ -129,7 +129,10 @@ int ask_yn(const char * string, int def)
 	int		c;
 	const char	*defstr;
 	const char	*short_yes = _("yY");
-	const char	*short_no = _("nN");
+	const char	*short_no  = _("nN");
+	const char	*yes_all   = _("aA");
+	const char      *no_all    = _("oO");
+	const char	*help      = _("y = yes, n = no, a = yes to all, o = no to all");
 
 #ifdef HAVE_TERMIOS_H
 	struct termios	termios, tmp;
@@ -143,12 +146,12 @@ int ask_yn(const char * string, int def)
 #endif
 
 	if (def == 1)
-		defstr = _(_("<y>"));
+		defstr = _(_("Ynao"));
 	else if (def == 0)
-		defstr = _(_("<n>"));
+		defstr = _(_("yNao"));
 	else
-		defstr = _(" (y/n)");
-	printf("%s%s? ", string, defstr);
+		defstr = _("ynao");
+	printf("%s (%s?)? ", string, defstr);
 	while (1) {
 		fflush (stdout);
 		if ((c = read_a_char()) == EOF)
@@ -163,23 +166,42 @@ int ask_yn(const char * string, int def)
 				longjmp(e2fsck_global_ctx->abort_loc, 1);
 			}
 			puts(_("cancelled!\n"));
-			return 0;
+			return NO;
 		}
 		if (strchr(short_yes, (char) c)) {
-			def = 1;
+			def = YES;
 			break;
 		}
 		else if (strchr(short_no, (char) c)) {
-			def = 0;
-			break;
-		}
-		else if ((c == ' ' || c == '\n') && (def != -1))
-			break;
-	}
-	if (def)
+			def = NO;
+			break;
+		} else if (strchr(yes_all, (char) c)){
+			def = YES_TO_ALL;
+			break;
+		} else if (strchr(no_all, (char) c)){
+			def = NO_TO_ALL;
+			break;
+		} else if (c == '?') {
+			printf("\n%s\n", help);
+		} else if ((c == ' ' || c == '\n') && (def != -1))
+			break;
+	}
+
+	switch (def) {
+	case YES:
 		puts(_("yes\n"));
-	else
+		break;
+	case YES_TO_ALL:
+		puts(_("Yes to all\n"));
+		break;
+	case NO_TO_ALL:
+		puts(_("Yes to all\n"));
+		break;
+	case NO:
+	default:
 		puts (_("no\n"));
+	}
+
 #ifdef HAVE_TERMIOS_H
 	tcsetattr (0, TCSANOW, &termios);
 #endif


[Index of Archives]     [Reiser Filesystem Development]     [Ceph FS]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Linux FS]     [Yosemite National Park]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Device Mapper]     [Linux Media]

  Powered by Linux