font_cmd.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /* font_cmd.c - Font command definition. */
  2. /*
  3. * GRUB -- GRand Unified Bootloader
  4. * Copyright (C) 2003,2005,2006,2007,2008,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/font.h>
  20. #include <grub/dl.h>
  21. #include <grub/misc.h>
  22. #include <grub/command.h>
  23. #include <grub/i18n.h>
  24. static grub_err_t
  25. loadfont_command (grub_command_t cmd __attribute__ ((unused)),
  26. int argc,
  27. char **args)
  28. {
  29. if (argc == 0)
  30. return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected"));
  31. while (argc--)
  32. if (grub_font_load (*args++) == 0)
  33. {
  34. if (!grub_errno)
  35. return grub_error (GRUB_ERR_BAD_FONT, "invalid font");
  36. return grub_errno;
  37. }
  38. return GRUB_ERR_NONE;
  39. }
  40. static grub_err_t
  41. lsfonts_command (grub_command_t cmd __attribute__ ((unused)),
  42. int argc __attribute__ ((unused)),
  43. char **args __attribute__ ((unused)))
  44. {
  45. struct grub_font_node *node;
  46. grub_puts_ (N_("Loaded fonts:"));
  47. for (node = grub_font_list; node; node = node->next)
  48. {
  49. grub_font_t font = node->value;
  50. grub_printf ("%s\n", grub_font_get_name (font));
  51. }
  52. return GRUB_ERR_NONE;
  53. }
  54. static grub_command_t cmd_loadfont, cmd_lsfonts;
  55. #if defined (GRUB_MACHINE_MIPS_LOONGSON) || defined (GRUB_MACHINE_COREBOOT)
  56. void grub_font_init (void)
  57. #else
  58. GRUB_MOD_INIT(font)
  59. #endif
  60. {
  61. grub_font_loader_init ();
  62. cmd_loadfont =
  63. grub_register_command ("loadfont", loadfont_command,
  64. N_("FILE..."),
  65. N_("Specify one or more font files to load."));
  66. cmd_lsfonts =
  67. grub_register_command ("lsfonts", lsfonts_command,
  68. 0, N_("List the loaded fonts."));
  69. }
  70. #if defined (GRUB_MACHINE_MIPS_LOONGSON) || defined (GRUB_MACHINE_COREBOOT)
  71. void grub_font_fini (void)
  72. #else
  73. GRUB_MOD_FINI(font)
  74. #endif
  75. {
  76. /* TODO: Determine way to free allocated resources.
  77. Warning: possible pointer references could be in use. */
  78. grub_unregister_command (cmd_loadfont);
  79. grub_unregister_command (cmd_lsfonts);
  80. }