+2002-07-24 Theodore Ts'o <tytso@mit.edu>
+
+ * util.c (ask_yn, read_a_char): Note when the user has typed ^C,
+ and abort processing by longjmp'ing to ctx->abort_loc.
+
2002-07-23 Theodore Ts'o <tytso@mit.edu>
* pass1.c (e2fsck_pass1): If e2fsck is run with -n, don't create
#include <termios.h>
#endif
#include <stdio.h>
-#define read_a_char() getchar()
#endif
#ifdef HAVE_MALLOC_H
#include "e2fsck.h"
+e2fsck_t e2fsck_global_ctx; /* Try your very best not to use this! */
+
#include <sys/time.h>
#include <sys/resource.h>
return ret;
}
+#ifndef HAVE_CONIO_H
+int read_a_char(void)
+{
+ char c;
+ int r;
+ int fail = 0;
+
+ while(1) {
+ if (e2fsck_global_ctx &&
+ (e2fsck_global_ctx->flags & E2F_FLAG_CANCEL)) {
+ return 3;
+ }
+ r = read(0, &c, 1);
+ if (r == 1)
+ return c;
+ if (fail++ > 100)
+ break;
+ }
+ return EOF;
+}
+#endif
+
int ask_yn(const char * string, int def)
{
int c;
#endif
if (def == 1)
- defstr = _("<y>");
+ defstr = _(_("<y>"));
else if (def == 0)
- defstr = _("<n>");
+ defstr = _(_("<n>"));
else
defstr = _(" (y/n)");
printf("%s%s? ", string, defstr);
fflush (stdout);
if ((c = read_a_char()) == EOF)
break;
+ if (c == 3) {
+#ifdef HAVE_TERMIOS_H
+ tcsetattr (0, TCSANOW, &termios);
+#endif
+ if (e2fsck_global_ctx &&
+ e2fsck_global_ctx->flags & E2F_FLAG_SETJMP_OK) {
+ puts("\n");
+ longjmp(e2fsck_global_ctx->abort_loc, 1);
+ }
+ puts(_("cancelled!\n"));
+ return 0;
+ }
if (strchr(short_yes, (char) c)) {
def = 1;
break;
break;
}
if (def)
- printf ("yes\n\n");
+ puts(_("yes\n"));
else
- printf ("no\n\n");
+ puts (_("no\n"));
#ifdef HAVE_TERMIOS_H
tcsetattr (0, TCSANOW, &termios);
#endif