main.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * GRUB -- GRand Unified Bootloader
  3. * Copyright (C) 2009 Free Software Foundation, Inc.
  4. *
  5. * GRUB is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * GRUB is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include <grub/dl.h>
  19. #include <grub/i18n.h>
  20. #include <grub/parser.h>
  21. #include <grub/script_sh.h>
  22. grub_err_t
  23. grub_normal_parse_line (char *line,
  24. grub_reader_getline_t getline, void *getline_data)
  25. {
  26. struct grub_script *parsed_script;
  27. /* Parse the script. */
  28. parsed_script = grub_script_parse (line, getline, getline_data);
  29. if (parsed_script)
  30. {
  31. /* Execute the command(s). */
  32. grub_script_execute (parsed_script);
  33. /* The parsed script was executed, throw it away. */
  34. grub_script_unref (parsed_script);
  35. }
  36. return grub_errno;
  37. }
  38. static grub_command_t cmd_break;
  39. static grub_command_t cmd_continue;
  40. static grub_command_t cmd_shift;
  41. static grub_command_t cmd_setparams;
  42. static grub_command_t cmd_return;
  43. void
  44. grub_script_init (void)
  45. {
  46. cmd_break = grub_register_command ("break", grub_script_break,
  47. N_("[NUM]"), N_("Exit from loops"));
  48. cmd_continue = grub_register_command ("continue", grub_script_break,
  49. N_("[NUM]"), N_("Continue loops"));
  50. cmd_shift = grub_register_command ("shift", grub_script_shift,
  51. N_("[NUM]"),
  52. /* TRANSLATORS: Positional arguments are
  53. arguments $0, $1, $2, ... */
  54. N_("Shift positional parameters."));
  55. cmd_setparams = grub_register_command ("setparams", grub_script_setparams,
  56. N_("[VALUE]..."),
  57. N_("Set positional parameters."));
  58. cmd_return = grub_register_command ("return", grub_script_return,
  59. N_("[NUM]"),
  60. /* TRANSLATORS: It's a command description
  61. and "Return" is a verb, not a noun. The
  62. command in question is "return" and
  63. has exactly the same semanics as bash
  64. equivalent. */
  65. N_("Return from a function."));
  66. }
  67. void
  68. grub_script_fini (void)
  69. {
  70. if (cmd_break)
  71. grub_unregister_command (cmd_break);
  72. cmd_break = 0;
  73. if (cmd_continue)
  74. grub_unregister_command (cmd_continue);
  75. cmd_continue = 0;
  76. if (cmd_shift)
  77. grub_unregister_command (cmd_shift);
  78. cmd_shift = 0;
  79. if (cmd_setparams)
  80. grub_unregister_command (cmd_setparams);
  81. cmd_setparams = 0;
  82. if (cmd_return)
  83. grub_unregister_command (cmd_return);
  84. cmd_return = 0;
  85. }