From 8feb31e5329da705e7fc99f7b28a261af8c9e493 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Wed, 5 Jan 2011 16:50:47 +0100 Subject: [PATCH] fdisk: re-print prompt after maybe_exit() after Do you really want to quit? n the read_chars() has to re-print the original prompt and ask again for new input. For example: Partition number (1-4, default 3): <-- CTRL-D Do you really want to quit? n Partition number (1-4, default 3): 3 <-- ask again First sector (411648-1023999, default 411648): Signed-off-by: Karel Zak --- fdisk/fdisk.c | 26 +++++++++++++++++++------- fdisk/fdisk.h | 2 +- fdisk/fdiskbsdlabel.c | 4 ++-- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/fdisk/fdisk.c b/fdisk/fdisk.c index 57e645d7..177fb14c 100644 --- a/fdisk/fdisk.c +++ b/fdisk/fdisk.c @@ -1327,30 +1327,36 @@ static int is_partition_table_changed(void) return 0; } -static void maybe_exit(int rc) +static void maybe_exit(int rc, int *asked) { char line[LINE_LENGTH]; putchar('\n'); + if (asked) + *asked = 0; if (is_partition_table_changed() || MBRbuffer_changed) { fprintf(stderr, _("Do you really want to quit? ")); if (!fgets(line, LINE_LENGTH, stdin) || rpmatch(line) == 1) exit(rc); + if (asked) + *asked = 1; } else exit(rc); } /* read line; return 0 or first char */ int -read_line(void) +read_line(int *asked) { line_ptr = line_buffer; if (!fgets(line_buffer, LINE_LENGTH, stdin)) { - maybe_exit(1); + maybe_exit(1, asked); return 0; } + if (asked) + *asked = 0; while (*line_ptr && !isgraph(*line_ptr)) line_ptr++; return *line_ptr; @@ -1362,16 +1368,22 @@ read_char(char *mesg) do { fputs(mesg, stdout); fflush (stdout); /* requested by niles@scyld.com */ - } while (!read_line()); + } while (!read_line(NULL)); return *line_ptr; } char read_chars(char *mesg) { - fputs(mesg, stdout); - fflush (stdout); /* niles@scyld.com */ - if (!read_line()) { + int rc, asked = 0; + + do { + fputs(mesg, stdout); + fflush (stdout); /* niles@scyld.com */ + rc = read_line(&asked); + } while (asked); + + if (!rc) { *line_ptr = '\n'; line_ptr[1] = 0; } diff --git a/fdisk/fdisk.h b/fdisk/fdisk.h index 56230d68..612ab86b 100644 --- a/fdisk/fdisk.h +++ b/fdisk/fdisk.h @@ -67,7 +67,7 @@ extern void get_geometry(int fd, struct geom *); extern int get_boot(enum action what); extern int get_partition(int warn, int max); extern void list_types(struct systypes *sys); -extern int read_line (void); +extern int read_line (int *asked); extern char read_char(char *mesg); extern int read_hex(struct systypes *sys); extern void reread_partition_table(int leave); diff --git a/fdisk/fdiskbsdlabel.c b/fdisk/fdiskbsdlabel.c index 9c092524..0c3810d4 100644 --- a/fdisk/fdiskbsdlabel.c +++ b/fdisk/fdiskbsdlabel.c @@ -448,7 +448,7 @@ edit_int (int def, char *mesg) do { fputs (mesg, stdout); printf (" (%d): ", def); - if (!read_line ()) + if (!read_line (NULL)) return def; } while (!isdigit (*line_ptr)); @@ -527,7 +527,7 @@ xbsd_write_bootstrap (void) printf (_("Bootstrap: %sboot -> boot%s (%s): "), dkbasename, dkbasename, dkbasename); - if (read_line ()) { + if (read_line (NULL)) { line_ptr[strlen (line_ptr)-1] = '\0'; dkbasename = line_ptr; } -- 2.39.5