1
1
/* normal_parser.h */
3
3
* GRUB -- GRand Unified Bootloader
4
* Copyright (C) 2005,2007,2009 Free Software Foundation, Inc.
4
* Copyright (C) 2005,2007,2009,2010 Free Software Foundation, Inc.
6
6
* GRUB is free software: you can redistribute it and/or modify
7
7
* it under the terms of the GNU General Public License as published by
42
44
struct grub_script_mem *mem;
43
45
struct grub_script_cmd *cmd;
47
/* grub_scripts from block arguments. */
48
struct grub_script *next_siblings;
49
struct grub_script *children;
48
GRUB_SCRIPT_ARG_TYPE_STR,
49
GRUB_SCRIPT_ARG_TYPE_VAR
54
GRUB_SCRIPT_ARG_TYPE_VAR,
55
GRUB_SCRIPT_ARG_TYPE_TEXT,
56
GRUB_SCRIPT_ARG_TYPE_DQVAR,
57
GRUB_SCRIPT_ARG_TYPE_DQSTR,
58
GRUB_SCRIPT_ARG_TYPE_SQSTR,
59
GRUB_SCRIPT_ARG_TYPE_BLOCK
50
60
} grub_script_arg_type_t;
52
62
/* A part of an argument. */
69
/* Parsed block argument. */
70
struct grub_script *script;
59
72
/* Next argument part. */
60
73
struct grub_script_arg *next;
76
/* An argument vector. */
77
struct grub_script_argv
81
struct grub_script *script;
84
/* Pluggable wildcard translator. */
85
struct grub_script_wildcard_translator
87
char *(*escape) (const char *str);
88
char *(*unescape) (const char *str);
89
grub_err_t (*expand) (const char *str, char ***expansions);
91
extern struct grub_script_wildcard_translator *grub_wildcard_translator;
92
extern struct grub_script_wildcard_translator grub_filename_translator;
63
94
/* A complete argument. It consists of a list of one or more `struct
64
95
grub_script_arg's. */
65
96
struct grub_script_arglist
79
110
struct grub_script_arglist *arglist;
82
/* A block of commands, this can be used to group commands. */
83
struct grub_script_cmdblock
85
struct grub_script_cmd cmd;
87
/* A chain of commands. */
88
struct grub_script_cmd *cmdlist;
91
113
/* An if statement. */
92
114
struct grub_script_cmdif
103
125
struct grub_script_cmd *exec_on_false;
106
/* A menu entry generate statement. */
107
struct grub_script_cmd_menuentry
109
struct grub_script_cmd cmd;
111
/* The arguments for this menu entry. */
112
struct grub_script_arglist *arglist;
114
/* The sourcecode the entry will be generated from. */
117
/* Options. XXX: Not used yet. */
128
/* A for statement. */
129
struct grub_script_cmdfor
131
struct grub_script_cmd cmd;
133
/* The name used as looping variable. */
134
struct grub_script_arg *name;
136
/* The words loop iterates over. */
137
struct grub_script_arglist *words;
139
/* The command list executed in each loop. */
140
struct grub_script_cmd *list;
143
/* A while/until command. */
144
struct grub_script_cmdwhile
146
struct grub_script_cmd cmd;
148
/* The command list used as condition. */
149
struct grub_script_cmd *cond;
151
/* The command list executed in each loop. */
152
struct grub_script_cmd *list;
154
/* The flag to indicate this as "until" loop. */
121
158
/* State of the lexer as passed to the lexer. */
122
159
struct grub_lexer_param
124
/* Set to 0 when the lexer is done. */
127
/* State of the state machine. */
128
grub_parser_state_t state;
130
161
/* Function used by the lexer to get a new line when more input is
131
162
expected, but not available. */
132
163
grub_reader_getline_t getline;
140
/* The character stream that has to be parsed. */
142
char *newscript; /* XXX */
144
171
/* While walking through the databuffer, `record' the characters to
145
172
this other buffer. It can be used to edit the menu entry at a
157
184
/* Size of RECORDING. */
160
/* The token that is already parsed but not yet returned. */
163
/* Was the last token a newline? */
187
/* End of file reached. */
190
/* Merge multiple word tokens. */
194
/* Part of a multi-part token. */
200
grub_script_arg_type_t type;
202
/* Flag to indicate resplit in progres. */
205
/* Text that is unput. */
211
/* Flex scanner buffer. */
215
#define GRUB_LEXER_INITIAL_TEXT_SIZE 32
216
#define GRUB_LEXER_INITIAL_RECORD_SIZE 256
167
218
/* State of the parser as passes to the parser. */
168
219
struct grub_parser_param
177
228
/* The memory that was used while parsing and scanning. */
178
229
struct grub_script_mem *memused;
231
/* The block argument scripts. */
232
struct grub_script *scripts;
180
234
/* The result of the parser. */
181
235
struct grub_script_cmd *parsed;
183
237
struct grub_lexer_param *lexerstate;
240
void grub_script_init (void);
241
void grub_script_fini (void);
243
void grub_script_mem_free (struct grub_script_mem *mem);
245
void grub_script_argv_free (struct grub_script_argv *argv);
246
int grub_script_argv_make (struct grub_script_argv *argv, int argc, char **args);
247
int grub_script_argv_next (struct grub_script_argv *argv);
248
int grub_script_argv_append (struct grub_script_argv *argv, const char *s);
249
int grub_script_argv_split_append (struct grub_script_argv *argv, char *s);
186
251
struct grub_script_arglist *
187
252
grub_script_create_arglist (struct grub_parser_param *state);
193
258
struct grub_script_cmd *
194
259
grub_script_create_cmdline (struct grub_parser_param *state,
195
260
struct grub_script_arglist *arglist);
196
struct grub_script_cmd *
197
grub_script_create_cmdblock (struct grub_parser_param *state);
199
262
struct grub_script_cmd *
200
263
grub_script_create_cmdif (struct grub_parser_param *state,
203
266
struct grub_script_cmd *exec_on_false);
205
268
struct grub_script_cmd *
206
grub_script_create_cmdmenu (struct grub_parser_param *state,
207
struct grub_script_arglist *arglist,
211
struct grub_script_cmd *
212
grub_script_add_cmd (struct grub_parser_param *state,
213
struct grub_script_cmdblock *cmdblock,
214
struct grub_script_cmd *cmd);
269
grub_script_create_cmdfor (struct grub_parser_param *state,
270
struct grub_script_arg *name,
271
struct grub_script_arglist *words,
272
struct grub_script_cmd *list);
274
struct grub_script_cmd *
275
grub_script_create_cmdwhile (struct grub_parser_param *state,
276
struct grub_script_cmd *cond,
277
struct grub_script_cmd *list,
278
int is_an_until_loop);
280
struct grub_script_cmd *
281
grub_script_append_cmd (struct grub_parser_param *state,
282
struct grub_script_cmd *list,
283
struct grub_script_cmd *last);
215
284
struct grub_script_arg *
216
285
grub_script_arg_add (struct grub_parser_param *state,
217
286
struct grub_script_arg *arg,
223
292
struct grub_script *grub_script_create (struct grub_script_cmd *cmd,
224
293
struct grub_script_mem *mem);
226
struct grub_lexer_param *grub_script_lexer_init (char *s,
295
struct grub_lexer_param *grub_script_lexer_init (struct grub_parser_param *parser,
227
297
grub_reader_getline_t getline);
298
void grub_script_lexer_fini (struct grub_lexer_param *);
228
299
void grub_script_lexer_ref (struct grub_lexer_param *);
229
300
void grub_script_lexer_deref (struct grub_lexer_param *);
230
void grub_script_lexer_record_start (struct grub_lexer_param *);
231
char *grub_script_lexer_record_stop (struct grub_lexer_param *);
301
unsigned grub_script_lexer_record_start (struct grub_parser_param *);
302
char *grub_script_lexer_record_stop (struct grub_parser_param *, unsigned);
303
int grub_script_lexer_yywrap (struct grub_parser_param *, const char *input);
304
void grub_script_lexer_record (struct grub_parser_param *, char *);
233
306
/* Functions to track allocated memory. */
234
307
struct grub_script_mem *grub_script_mem_record (struct grub_parser_param *state);
245
318
/* Commands to execute, don't use these directly. */
246
319
grub_err_t grub_script_execute_cmdline (struct grub_script_cmd *cmd);
247
grub_err_t grub_script_execute_cmdblock (struct grub_script_cmd *cmd);
320
grub_err_t grub_script_execute_cmdlist (struct grub_script_cmd *cmd);
248
321
grub_err_t grub_script_execute_cmdif (struct grub_script_cmd *cmd);
249
grub_err_t grub_script_execute_menuentry (struct grub_script_cmd *cmd);
322
grub_err_t grub_script_execute_cmdfor (struct grub_script_cmd *cmd);
323
grub_err_t grub_script_execute_cmdwhile (struct grub_script_cmd *cmd);
251
325
/* Execute any GRUB pre-parsed command or script. */
252
326
grub_err_t grub_script_execute (struct grub_script *script);
327
grub_err_t grub_script_execute_sourcecode (const char *source, int argc, char **args);
329
/* Break command for loops. */
330
grub_err_t grub_script_break (grub_command_t cmd, int argc, char *argv[]);
332
/* SHIFT command for GRUB script. */
333
grub_err_t grub_script_shift (grub_command_t cmd, int argc, char *argv[]);
335
/* SETPARAMS command for GRUB script functions. */
336
grub_err_t grub_script_setparams (grub_command_t cmd, int argc, char *argv[]);
338
/* RETURN command for functions. */
339
grub_err_t grub_script_return (grub_command_t cmd, int argc, char *argv[]);
254
341
/* This variable points to the parsed command. This is used to
255
342
communicate with the bison code. */
277
364
typedef struct grub_script_function *grub_script_function_t;
366
extern grub_script_function_t grub_script_function_list;
368
#define FOR_SCRIPT_FUNCTIONS(var) for((var) = grub_script_function_list; \
369
(var); (var) = (var)->next)
279
371
grub_script_function_t grub_script_function_create (struct grub_script_arg *functionname,
280
372
struct grub_script *cmd);
281
373
void grub_script_function_remove (const char *name);
282
374
grub_script_function_t grub_script_function_find (char *functionname);
283
int grub_script_function_iterate (int (*iterate) (grub_script_function_t));
284
int grub_script_function_call (grub_script_function_t func,
285
int argc, char **args);
288
grub_script_execute_argument_to_string (struct grub_script_arg *arg);
376
grub_err_t grub_script_function_call (grub_script_function_t func,
377
int argc, char **args);
380
grub_script_execute_arglist_to_argv (struct grub_script_arglist *arglist, int *count);
383
grub_normal_parse_line (char *line, grub_reader_getline_t getline);
385
static inline struct grub_script *
386
grub_script_ref (struct grub_script *script)
394
grub_script_unref (struct grub_script *script)
399
if (script->refcnt == 0)
400
grub_script_free (script);
290
405
#endif /* ! GRUB_NORMAL_PARSER_HEADER */