* [PATCH] e2fsck/e2fsprogs: answer yes/no to a group of questions
@ 2007-08-01 12:57 Bernd Schubert
2007-08-01 22:28 ` Andreas Dilger
0 siblings, 1 reply; 4+ messages in thread
From: Bernd Schubert @ 2007-08-01 12:57 UTC (permalink / raw)
To: linux-ext4
[-- Attachment #1: Type: text/plain, Size: 171 bytes --]
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
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: yes_no_to_all.patch --]
[-- Type: text/x-diff; name="yes_no_to_all.patch", Size: 5218 bytes --]
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
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] e2fsck/e2fsprogs: answer yes/no to a group of questions
2007-08-01 12:57 [PATCH] e2fsck/e2fsprogs: answer yes/no to a group of questions Bernd Schubert
@ 2007-08-01 22:28 ` Andreas Dilger
2007-08-02 16:32 ` Bernd Schubert
2007-08-06 11:20 ` Bernd Schubert
0 siblings, 2 replies; 4+ messages in thread
From: Andreas Dilger @ 2007-08-01 22:28 UTC (permalink / raw)
To: Bernd Schubert; +Cc: linux-ext4
On Aug 01, 2007 14:57 +0200, Bernd Schubert wrote:
> 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.
I've wanted something like this for quite a while already.
What would be more useful, however, is having the yes-to-all or no-to-all
apply to a particular problem instead of being generic. Otherwise it
isn't really different from using -y or -n. The reason that is useful
is that often there is a particular problem that should all be fixed or
skipped, but you want to be prompted how to fix a different problem type.
I haven't investigated, but maybe this could be implemented in the
same way as a latch for every problem?
> + 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;
> + }
The "yes" and "no" here should be "_("yes")" and "_("no")" like in
ask() so they are translated.
Cheers, Andreas
--
Andreas Dilger
Principal Software Engineer
Cluster File Systems, Inc.
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] e2fsck/e2fsprogs: answer yes/no to a group of questions
2007-08-01 22:28 ` Andreas Dilger
@ 2007-08-02 16:32 ` Bernd Schubert
2007-08-06 11:20 ` Bernd Schubert
1 sibling, 0 replies; 4+ messages in thread
From: Bernd Schubert @ 2007-08-02 16:32 UTC (permalink / raw)
To: linux-ext4
Andreas Dilger wrote:
> On Aug 01, 2007 14:57 +0200, Bernd Schubert wrote:
>> 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.
>
> I've wanted something like this for quite a while already.
>
> What would be more useful, however, is having the yes-to-all or no-to-all
> apply to a particular problem instead of being generic. Otherwise it
> isn't really different from using -y or -n. The reason that is useful
> is that often there is a particular problem that should all be fixed or
> skipped, but you want to be prompted how to fix a different problem type.
But isn't that what the patch is going to do?
int fix_problem(e2fsck_t ctx, problem_t code, struct problem_context *pctx)
{
...
ptr = find_problem(code); // So ptr is problem specific
}
Actually there was already everything prepared, it seems someone just forgot
to add a patch like this.
>
> I haven't investigated, but maybe this could be implemented in the
> same way as a latch for every problem?
>
>> + 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;
>> + }
>
> The "yes" and "no" here should be "_("yes")" and "_("no")" like in
> ask() so they are translated.
Thanks, going to correct this.
Cheers,
Bernd
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] e2fsck/e2fsprogs: answer yes/no to a group of questions
2007-08-01 22:28 ` Andreas Dilger
2007-08-02 16:32 ` Bernd Schubert
@ 2007-08-06 11:20 ` Bernd Schubert
1 sibling, 0 replies; 4+ messages in thread
From: Bernd Schubert @ 2007-08-06 11:20 UTC (permalink / raw)
To: Andreas Dilger, Theodore Y. Ts'o; +Cc: Bernd Schubert, linux-ext4
[-- Attachment #1: Type: text/plain, Size: 291 bytes --]
On Thursday 02 August 2007 00:28:56 Andreas Dilger wrote:
> The "yes" and "no" here should be "_("yes")" and "_("no")" like in
> ask() so they are translated.
Corrected version attached.
Signed-off-by: Bernd Schubert <bs@q-leap.de>
Cheers,
Bernd
--
Bernd Schubert
Q-Leap Networks GmbH
[-- Attachment #2: yes_no_to_all.patch --]
[-- Type: text/x-diff, Size: 5238 bytes --]
diff -r 9a2f051a0a1d e2fsck/e2fsck.h
--- a/e2fsck/e2fsck.h Fri Jun 29 23:09:16 2007 -0400
+++ b/e2fsck/e2fsck.h Mon Aug 06 13:13:54 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 Mon Aug 06 13:13:54 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: %s\n", _(prompt[(int) ptr->prompt]), _("yes"));
+ return YES;
+ } else if (ptr->flags & PR_NO_TO_ALL) {
+ printf(_("%s: %s\n"), _(prompt[(int) ptr->prompt]), _("no"));
+ 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 Mon Aug 06 13:13:54 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 Mon Aug 06 13:13:54 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
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2007-08-06 11:20 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-08-01 12:57 [PATCH] e2fsck/e2fsprogs: answer yes/no to a group of questions Bernd Schubert
2007-08-01 22:28 ` Andreas Dilger
2007-08-02 16:32 ` Bernd Schubert
2007-08-06 11:20 ` Bernd Schubert
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).