Upgraded GRUB2 to 2.00 release.
[AROS.git] / arch / all-pc / boot / grub2-aros / grub-core / kern / rescue_parser.c
blob656342d273d99f91fa0abef3fa0b85d7dbb5bdd8
1 /* rescue_parser.c - rescue mode parser */
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/mm.h>
22 #include <grub/env.h>
23 #include <grub/parser.h>
24 #include <grub/misc.h>
25 #include <grub/command.h>
26 #include <grub/i18n.h>
28 grub_err_t
29 grub_rescue_parse_line (char *line, grub_reader_getline_t getline)
31 char *name;
32 int n;
33 grub_command_t cmd;
34 char **args;
36 if (grub_parser_split_cmdline (line, getline, &n, &args) || n < 0)
37 return grub_errno;
39 if (n == 0)
40 return GRUB_ERR_NONE;
42 /* In case of an assignment set the environment accordingly
43 instead of calling a function. */
44 if (n == 1 && grub_strchr (line, '='))
46 char *val = grub_strchr (args[0], '=');
47 val[0] = 0;
48 grub_env_set (args[0], val + 1);
49 val[0] = '=';
50 goto quit;
53 /* Get the command name. */
54 name = args[0];
56 /* If nothing is specified, restart. */
57 if (*name == '\0')
58 goto quit;
60 cmd = grub_command_find (name);
61 if (cmd)
63 (cmd->func) (cmd, n - 1, &args[1]);
65 else
67 grub_printf_ (N_("Unknown command `%s'.\n"), name);
68 if (grub_command_find ("help"))
69 grub_printf ("Try `help' for usage\n");
72 quit:
73 grub_free (args[0]);
74 grub_free (args);
76 return grub_errno;