Upgraded GRUB2 to 2.00 release.
[AROS.git] / arch / all-pc / boot / grub2-aros / grub-core / kern / rescue_reader.c
blob4587b944f73b904bb03e8468847f2676fa2b14cc
1 /* rescue_reader.c - rescue mode reader */
2 /*
3 * GRUB -- GRand Unified Bootloader
4 * Copyright (C) 2009,2010 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/parser.h>
23 #include <grub/misc.h>
24 #include <grub/term.h>
25 #include <grub/mm.h>
27 #define GRUB_RESCUE_BUF_SIZE 256
29 static char linebuf[GRUB_RESCUE_BUF_SIZE];
31 /* Prompt to input a command and read the line. */
32 static grub_err_t
33 grub_rescue_read_line (char **line, int cont)
35 int c;
36 int pos = 0;
37 char str[4];
39 grub_printf ((cont) ? "> " : "grub rescue> ");
40 grub_memset (linebuf, 0, GRUB_RESCUE_BUF_SIZE);
42 while ((c = grub_getkey ()) != '\n' && c != '\r')
44 if (grub_isprint (c))
46 if (pos < GRUB_RESCUE_BUF_SIZE - 1)
48 str[0] = c;
49 str[1] = 0;
50 linebuf[pos++] = c;
51 grub_xputs (str);
54 else if (c == '\b')
56 if (pos > 0)
58 str[0] = c;
59 str[1] = ' ';
60 str[2] = c;
61 str[3] = 0;
62 linebuf[--pos] = 0;
63 grub_xputs (str);
66 grub_refresh ();
69 grub_xputs ("\n");
70 grub_refresh ();
72 *line = grub_strdup (linebuf);
74 return 0;
77 void __attribute__ ((noreturn))
78 grub_rescue_run (void)
80 grub_printf ("Entering rescue mode...\n");
82 while (1)
84 char *line;
86 /* Print an error, if any. */
87 grub_print_error ();
88 grub_errno = GRUB_ERR_NONE;
90 grub_rescue_read_line (&line, 0);
91 if (! line || line[0] == '\0')
92 continue;
94 grub_rescue_parse_line (line, grub_rescue_read_line);
95 grub_free (line);