command.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /* command.c - support basic command */
  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. #include <grub/mm.h>
  20. #include <grub/command.h>
  21. GRUB_EXPORT(grub_command_list);
  22. GRUB_EXPORT(grub_reg_cmd);
  23. GRUB_EXPORT(grub_unregister_command);
  24. grub_command_t grub_command_list;
  25. grub_command_t
  26. grub_reg_cmd (const char *name,
  27. grub_command_func_t func,
  28. const char *summary,
  29. const char *description,
  30. int prio)
  31. {
  32. grub_command_t cmd;
  33. cmd = (grub_command_t) grub_zalloc (sizeof (*cmd));
  34. if (! cmd)
  35. return 0;
  36. cmd->name = name;
  37. cmd->func = func;
  38. cmd->summary = (summary) ? summary : "";
  39. cmd->description = description;
  40. cmd->flags = GRUB_COMMAND_FLAG_BOTH;
  41. cmd->prio = prio;
  42. grub_prio_list_insert (GRUB_AS_PRIO_LIST_P (&grub_command_list),
  43. GRUB_AS_PRIO_LIST (cmd));
  44. return cmd;
  45. }
  46. void
  47. grub_unregister_command (grub_command_t cmd)
  48. {
  49. grub_prio_list_remove (GRUB_AS_PRIO_LIST_P (&grub_command_list),
  50. GRUB_AS_PRIO_LIST (cmd));
  51. grub_free (cmd);
  52. }