parser.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /* parser.h - prototypes for the command line parser. */
  2. /*
  3. * GRUB -- GRand Unified Bootloader
  4. * Copyright (C) 2005,2007,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. #ifndef GRUB_PARSER_HEADER
  20. #define GRUB_PARSER_HEADER 1
  21. #include <grub/types.h>
  22. #include <grub/err.h>
  23. #include <grub/reader.h>
  24. /* All the states for the command line. */
  25. typedef enum
  26. {
  27. GRUB_PARSER_STATE_TEXT = 1,
  28. GRUB_PARSER_STATE_ESC,
  29. GRUB_PARSER_STATE_QUOTE,
  30. GRUB_PARSER_STATE_DQUOTE,
  31. GRUB_PARSER_STATE_VAR,
  32. GRUB_PARSER_STATE_VARNAME,
  33. GRUB_PARSER_STATE_VARNAME2,
  34. GRUB_PARSER_STATE_QVAR,
  35. GRUB_PARSER_STATE_QVARNAME,
  36. GRUB_PARSER_STATE_QVARNAME2
  37. } grub_parser_state_t;
  38. /* A single state transition. */
  39. struct grub_parser_state_transition
  40. {
  41. /* The state that is looked up. */
  42. grub_parser_state_t from_state;
  43. /* The next state, determined by FROM_STATE and INPUT. */
  44. grub_parser_state_t to_state;
  45. /* The input that will determine the next state from FROM_STATE. */
  46. char input;
  47. /* If set to 1, the input is valid and should be used. */
  48. int keep_value;
  49. };
  50. /* Determines the state following STATE, determined by C. */
  51. grub_parser_state_t
  52. EXPORT_FUNC (grub_parser_cmdline_state) (grub_parser_state_t state,
  53. char c, char *result);
  54. grub_err_t
  55. EXPORT_FUNC (grub_parser_split_cmdline) (const char *cmdline,
  56. grub_reader_getline_t getline_func,
  57. void *getline_func_data,
  58. int *argc, char ***argv);
  59. struct grub_parser
  60. {
  61. /* The next parser. */
  62. struct grub_parser *next;
  63. /* The parser name. */
  64. const char *name;
  65. /* Initialize the parser. */
  66. grub_err_t (*init) (void);
  67. /* Clean up the parser. */
  68. grub_err_t (*fini) (void);
  69. grub_err_t (*parse_line) (char *line,
  70. grub_reader_getline_t getline_func,
  71. void *getline_func_data);
  72. };
  73. typedef struct grub_parser *grub_parser_t;
  74. grub_err_t grub_parser_execute (char *source);
  75. grub_err_t
  76. grub_rescue_parse_line (char *line,
  77. grub_reader_getline_t getline_func,
  78. void *getline_func_data);
  79. #endif /* ! GRUB_PARSER_HEADER */