2009-11-01 Felix Zielcke <fzielcke@z-51.de>
[grub2/phcoder/solaris.git] / kern / rescue_parser.c
blob1e0841e49d2fd7fd0784cf51fe85f4a258730ad9
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>
27 static grub_err_t
28 grub_rescue_parse_line (char *line, grub_reader_getline_t getline)
30 char *name;
31 int n;
32 grub_command_t cmd;
33 char **args;
35 if (grub_parser_split_cmdline (line, getline, &n, &args) || n < 0)
36 return grub_errno;
38 /* In case of an assignment set the environment accordingly
39 instead of calling a function. */
40 if (n == 0 && grub_strchr (line, '='))
42 char *val = grub_strchr (args[0], '=');
43 val[0] = 0;
44 grub_env_set (args[0], val + 1);
45 val[0] = '=';
46 goto quit;
49 /* Get the command name. */
50 name = args[0];
52 /* If nothing is specified, restart. */
53 if (*name == '\0')
54 goto quit;
56 cmd = grub_command_find (name);
57 if (cmd)
59 (cmd->func) (cmd, n, &args[1]);
61 else
63 grub_printf ("Unknown command `%s'\n", name);
64 if (grub_command_find ("help"))
65 grub_printf ("Try `help' for usage\n");
68 quit:
69 grub_free (args[0]);
70 grub_free (args);
72 return grub_errno;
75 static struct grub_parser grub_rescue_parser =
77 .name = "rescue",
78 .parse_line = grub_rescue_parse_line
81 void
82 grub_register_rescue_parser (void)
84 grub_parser_register ("rescue", &grub_rescue_parser);