~ubuntu-branches/debian/stretch/grub2/stretch

« back to all changes in this revision

Viewing changes to commands/handler.c

  • Committer: Bazaar Package Importer
  • Author(s): Colin Watson
  • Date: 2010-06-15 12:45:35 UTC
  • mto: (1.14.1 upstream) (17.3.18 experimental)
  • mto: This revision was merged to the branch mainline in revision 36.
  • Revision ID: james.westby@ubuntu.com-20100615124535-9vfbis4kzv0h5bgy
Tags: upstream-1.98+20100614
ImportĀ upstreamĀ versionĀ 1.98+20100614

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* handler.c - commands to list or select handlers */
2
 
/*
3
 
 *  GRUB  --  GRand Unified Bootloader
4
 
 *  Copyright (C) 2009  Free Software Foundation, Inc.
5
 
 *
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.
10
 
 *
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.
15
 
 *
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/>.
18
 
 */
19
 
 
20
 
#include <grub/dl.h>
21
 
#include <grub/err.h>
22
 
#include <grub/misc.h>
23
 
#include <grub/term.h>
24
 
#include <grub/handler.h>
25
 
#include <grub/command.h>
26
 
#include <grub/i18n.h>
27
 
 
28
 
static grub_err_t
29
 
grub_cmd_handler (struct grub_command *cmd __attribute__ ((unused)),
30
 
                  int argc, char **args)
31
 
{
32
 
  void *curr_item = 0;
33
 
  grub_handler_class_t head;
34
 
 
35
 
  auto int list_item (grub_named_list_t item);
36
 
  int list_item (grub_named_list_t item)
37
 
    {
38
 
      if (item == curr_item)
39
 
        grub_putchar ('*');
40
 
 
41
 
      grub_printf ("%s\n", item->name);
42
 
 
43
 
      return 0;
44
 
    }
45
 
 
46
 
  head = grub_handler_class_list;
47
 
  if (argc == 0)
48
 
    {
49
 
      grub_list_iterate (GRUB_AS_LIST (head), (grub_list_hook_t) list_item);
50
 
    }
51
 
  else
52
 
    {
53
 
      char *class_name;
54
 
      grub_handler_class_t class;
55
 
 
56
 
      class_name = args[0];
57
 
      argc--;
58
 
      args++;
59
 
 
60
 
      class = grub_named_list_find (GRUB_AS_NAMED_LIST (head), class_name);
61
 
      if (! class)
62
 
        return grub_error (GRUB_ERR_FILE_NOT_FOUND, "class not found");
63
 
 
64
 
      if (argc == 0)
65
 
        {
66
 
          curr_item = class->cur_handler;
67
 
          grub_list_iterate (GRUB_AS_LIST (class->handler_list),
68
 
                             (grub_list_hook_t) list_item);
69
 
        }
70
 
      else
71
 
        {
72
 
          grub_handler_t handler;
73
 
 
74
 
          handler =
75
 
            grub_named_list_find (GRUB_AS_NAMED_LIST (class->handler_list),
76
 
                                  args[0]);
77
 
 
78
 
          if (! handler)
79
 
            return grub_error (GRUB_ERR_FILE_NOT_FOUND, "handler not found");
80
 
 
81
 
          grub_handler_set_current (class, handler);
82
 
        }
83
 
    }
84
 
 
85
 
  return 0;
86
 
}
87
 
 
88
 
static grub_command_t cmd_handler;
89
 
 
90
 
GRUB_MOD_INIT(handler)
91
 
{
92
 
  cmd_handler =
93
 
    grub_register_command ("handler", grub_cmd_handler,
94
 
                           N_("[class [handler]]"),
95
 
                           N_("List or select a handler."));
96
 
}
97
 
 
98
 
GRUB_MOD_FINI(handler)
99
 
{
100
 
  grub_unregister_command (cmd_handler);
101
 
}