2009-08-17 Robert Millan <rmh.grub@aybabtu.com>
[grub2/phcoder/solaris.git] / kern / rescue_reader.c
blob2a06f3fc248920517e830689f41da8ef7879dfef
1 /* rescue_reader.c - rescue mode reader */
2 /*
3 * GRUB -- GRand Unified Bootloader
4 * Copyright (C) 2009 Free Software Foundation, Inc.
6 * GRUB is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * GRUB is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
20 #include <grub/types.h>
21 #include <grub/reader.h>
22 #include <grub/misc.h>
23 #include <grub/term.h>
25 #define GRUB_RESCUE_BUF_SIZE 256
27 static char linebuf[GRUB_RESCUE_BUF_SIZE];
29 static grub_err_t
30 grub_rescue_init (void)
32 grub_printf ("Entering rescue mode...\n");
33 return 0;
36 /* Prompt to input a command and read the line. */
37 static grub_err_t
38 grub_rescue_read_line (char **line, int cont)
40 int c;
41 int pos = 0;
43 grub_printf ((cont) ? "> " : "grub rescue> ");
44 grub_memset (linebuf, 0, GRUB_RESCUE_BUF_SIZE);
46 while ((c = GRUB_TERM_ASCII_CHAR (grub_getkey ())) != '\n' && c != '\r')
48 if (grub_isprint (c))
50 if (pos < GRUB_RESCUE_BUF_SIZE - 1)
52 linebuf[pos++] = c;
53 grub_putchar (c);
56 else if (c == '\b')
58 if (pos > 0)
60 linebuf[--pos] = 0;
61 grub_putchar (c);
62 grub_putchar (' ');
63 grub_putchar (c);
66 grub_refresh ();
69 grub_putchar ('\n');
70 grub_refresh ();
72 *line = grub_strdup (linebuf);
74 return 0;
77 static struct grub_reader grub_rescue_reader =
79 .name = "rescue",
80 .init = grub_rescue_init,
81 .read_line = grub_rescue_read_line
84 void
85 grub_register_rescue_reader (void)
87 grub_reader_register ("rescue", &grub_rescue_reader);