2009-11-21 Samuel Thibault <samuel.thibault@ens-lyon.org>
[grub2.git] / include / grub / parser.h
blob4ee0e83898ec7f9b3dc365846ecff5335d546af2
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.
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.
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.
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/>.
20 #ifndef GRUB_PARSER_HEADER
21 #define GRUB_PARSER_HEADER 1
23 #include <grub/types.h>
24 #include <grub/err.h>
25 #include <grub/reader.h>
27 /* All the states for the command line. */
28 typedef enum
30 GRUB_PARSER_STATE_TEXT = 1,
31 GRUB_PARSER_STATE_ESC,
32 GRUB_PARSER_STATE_QUOTE,
33 GRUB_PARSER_STATE_DQUOTE,
34 GRUB_PARSER_STATE_VAR,
35 GRUB_PARSER_STATE_VARNAME,
36 GRUB_PARSER_STATE_VARNAME2,
37 GRUB_PARSER_STATE_QVAR,
38 GRUB_PARSER_STATE_QVARNAME,
39 GRUB_PARSER_STATE_QVARNAME2
40 } grub_parser_state_t;
42 /* A single state transition. */
43 struct grub_parser_state_transition
45 /* The state that is looked up. */
46 grub_parser_state_t from_state;
48 /* The next state, determined by FROM_STATE and INPUT. */
49 grub_parser_state_t to_state;
51 /* The input that will determine the next state from FROM_STATE. */
52 char input;
54 /* If set to 1, the input is valid and should be used. */
55 int keep_value;
58 /* Determines the state following STATE, determined by C. */
59 grub_parser_state_t
60 EXPORT_FUNC (grub_parser_cmdline_state) (grub_parser_state_t state,
61 char c, char *result);
63 grub_err_t
64 EXPORT_FUNC (grub_parser_split_cmdline) (const char *cmdline,
65 grub_reader_getline_t getline,
66 int *argc, char ***argv);
68 struct grub_parser
70 /* The next parser. */
71 struct grub_parser *next;
73 /* The parser name. */
74 const char *name;
76 /* Initialize the parser. */
77 grub_err_t (*init) (void);
79 /* Clean up the parser. */
80 grub_err_t (*fini) (void);
82 grub_err_t (*parse_line) (char *line, grub_reader_getline_t getline);
84 typedef struct grub_parser *grub_parser_t;
86 extern struct grub_handler_class EXPORT_VAR(grub_parser_class);
87 grub_err_t EXPORT_FUNC(grub_parser_execute) (char *source);
89 static inline void
90 grub_parser_register (const char *name __attribute__ ((unused)),
91 grub_parser_t parser)
93 grub_handler_register (&grub_parser_class, GRUB_AS_HANDLER (parser));
96 static inline void
97 grub_parser_unregister (grub_parser_t parser)
99 grub_handler_unregister (&grub_parser_class, GRUB_AS_HANDLER (parser));
102 static inline grub_parser_t
103 grub_parser_get_current (void)
105 return (grub_parser_t) grub_parser_class.cur_handler;
108 static inline grub_err_t
109 grub_parser_set_current (grub_parser_t parser)
111 return grub_handler_set_current (&grub_parser_class,
112 GRUB_AS_HANDLER (parser));
115 void grub_register_rescue_parser (void);
117 #endif /* ! GRUB_PARSER_HEADER */