~hamo/ubuntu/precise/grub2/grub2.hi_res

« back to all changes in this revision

Viewing changes to include/grub/script_sh.h

  • Committer: Bazaar Package Importer
  • Author(s): Colin Watson, Colin Watson, Robert Millan, Updated translations
  • Date: 2010-11-22 12:24:56 UTC
  • mfrom: (1.26.4 upstream) (17.3.36 sid)
  • mto: (17.3.43 sid)
  • mto: This revision was merged to the branch mainline in revision 89.
  • Revision ID: james.westby@ubuntu.com-20101122122456-y82z3sfb7k4zfdcc
Tags: 1.99~20101122-1
[ Colin Watson ]
* New Bazaar snapshot.  Too many changes to list in full, but some of the
  more user-visible ones are as follows:
  - GRUB script:
    + Function parameters, "break", "continue", "shift", "setparams",
      "return", and "!".
    + "export" command supports multiple variable names.
    + Multi-line quoted strings support.
    + Wildcard expansion.
  - sendkey support.
  - USB hotunplugging and USB serial support.
  - Rename CD-ROM to cd on BIOS.
  - Add new --boot-directory option to grub-install, grub-reboot, and
    grub-set-default; the old --root-directory option is still accepted
    but was often confusing.
  - Basic btrfs detection/UUID support (but no file reading yet).
  - bash-completion for utilities.
  - If a device is listed in device.map, always assume that it is
    BIOS-visible rather than using extra layers such as LVM or RAID.
  - Add grub-mknetdir script (closes: #550658).
  - Remove deprecated "root" command.
  - Handle RAID devices containing virtio components.
  - GRUB Legacy configuration file support (via grub-menulst2cfg).
  - Keyboard layout support (via grub-mklayout and grub-kbdcomp).
  - Check generated grub.cfg for syntax errors before saving.
  - Pause execution for at most ten seconds if any errors are displayed,
    so that the user has a chance to see them.
  - Support submenus.
  - Write embedding zone using Reed-Solomon, so that it's robust against
    being partially overwritten (closes: #550702, #591416, #593347).
  - GRUB_DISABLE_LINUX_RECOVERY and GRUB_DISABLE_NETBSD_RECOVERY merged
    into a single GRUB_DISABLE_RECOVERY variable.
  - Fix loader memory allocation failure (closes: #551627).
  - Don't call savedefault on recovery entries (closes: #589325).
  - Support triple-indirect blocks on ext2 (closes: #543924).
  - Recognise DDF1 fake RAID (closes: #603354).

[ Robert Millan ]
* Use dpkg architecture wildcards.

[ Updated translations ]
* Slovenian (Vanja Cvelbar).  Closes: #604003
* Dzongkha (dawa pemo via Tenzin Dendup).  Closes: #604102

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* normal_parser.h  */
2
2
/*
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.
5
5
 *
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
23
23
#include <grub/types.h>
24
24
#include <grub/err.h>
25
25
#include <grub/parser.h>
 
26
#include <grub/command.h>
26
27
 
27
28
struct grub_script_mem;
28
29
 
39
40
 
40
41
struct grub_script
41
42
{
 
43
  unsigned refcnt;
42
44
  struct grub_script_mem *mem;
43
45
  struct grub_script_cmd *cmd;
 
46
 
 
47
  /* grub_scripts from block arguments.  */
 
48
  struct grub_script *next_siblings;
 
49
  struct grub_script *children;
44
50
};
45
51
 
46
52
typedef enum
47
53
{
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;
51
61
 
52
62
/* A part of an argument.  */
56
66
 
57
67
  char *str;
58
68
 
 
69
  /* Parsed block argument.  */
 
70
  struct grub_script *script;
 
71
 
59
72
  /* Next argument part.  */
60
73
  struct grub_script_arg *next;
61
74
};
62
75
 
 
76
/* An argument vector.  */
 
77
struct grub_script_argv
 
78
{
 
79
  unsigned argc;
 
80
  char **args;
 
81
  struct grub_script *script;
 
82
};
 
83
 
 
84
/* Pluggable wildcard translator.  */
 
85
struct grub_script_wildcard_translator
 
86
{
 
87
  char *(*escape) (const char *str);
 
88
  char *(*unescape) (const char *str);
 
89
  grub_err_t (*expand) (const char *str, char ***expansions);
 
90
};
 
91
extern struct grub_script_wildcard_translator *grub_wildcard_translator;
 
92
extern struct grub_script_wildcard_translator grub_filename_translator;
 
93
 
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;
80
111
};
81
112
 
82
 
/* A block of commands, this can be used to group commands.  */
83
 
struct grub_script_cmdblock
84
 
{
85
 
  struct grub_script_cmd cmd;
86
 
 
87
 
  /* A chain of commands.  */
88
 
  struct grub_script_cmd *cmdlist;
89
 
};
90
 
 
91
113
/* An if statement.  */
92
114
struct grub_script_cmdif
93
115
{
103
125
  struct grub_script_cmd *exec_on_false;
104
126
};
105
127
 
106
 
/* A menu entry generate statement.  */
107
 
struct grub_script_cmd_menuentry
108
 
{
109
 
  struct grub_script_cmd cmd;
110
 
 
111
 
  /* The arguments for this menu entry.  */
112
 
  struct grub_script_arglist *arglist;
113
 
 
114
 
  /* The sourcecode the entry will be generated from.  */
115
 
  char *sourcecode;
116
 
 
117
 
  /* Options.  XXX: Not used yet.  */
118
 
  int options;
 
128
/* A for statement.  */
 
129
struct grub_script_cmdfor
 
130
{
 
131
  struct grub_script_cmd cmd;
 
132
 
 
133
  /* The name used as looping variable.  */
 
134
  struct grub_script_arg *name;
 
135
 
 
136
  /* The words loop iterates over.  */
 
137
  struct grub_script_arglist *words;
 
138
 
 
139
  /* The command list executed in each loop.  */
 
140
  struct grub_script_cmd *list;
 
141
};
 
142
 
 
143
/* A while/until command.  */
 
144
struct grub_script_cmdwhile
 
145
{
 
146
  struct grub_script_cmd cmd;
 
147
 
 
148
  /* The command list used as condition.  */
 
149
  struct grub_script_cmd *cond;
 
150
 
 
151
  /* The command list executed in each loop.  */
 
152
  struct grub_script_cmd *list;
 
153
 
 
154
  /* The flag to indicate this as "until" loop.  */
 
155
  int until;
119
156
};
120
157
 
121
158
/* State of the lexer as passed to the lexer.  */
122
159
struct grub_lexer_param
123
160
{
124
 
  /* Set to 0 when the lexer is done.  */
125
 
  int done;
126
 
 
127
 
  /* State of the state machine.  */
128
 
  grub_parser_state_t state;
129
 
 
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;
137
168
     depleted.  */
138
169
  int refs;
139
170
 
140
 
  /* The character stream that has to be parsed.  */
141
 
  char *script;
142
 
  char *newscript; /* XXX */
143
 
 
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
146
173
     later moment.  */
157
184
  /* Size of RECORDING.  */
158
185
  int recordlen;
159
186
 
160
 
  /* The token that is already parsed but not yet returned. */
161
 
  int tokenonhold;
162
 
 
163
 
  /* Was the last token a newline? */
164
 
  int was_newline;
 
187
  /* End of file reached.  */
 
188
  int eof;
 
189
 
 
190
  /* Merge multiple word tokens.  */
 
191
  int merge_start;
 
192
  int merge_end;
 
193
 
 
194
  /* Part of a multi-part token.  */
 
195
  char *text;
 
196
  unsigned used;
 
197
  unsigned size;
 
198
 
 
199
  /* Type of text.  */
 
200
  grub_script_arg_type_t type;
 
201
 
 
202
  /* Flag to indicate resplit in progres.  */
 
203
  unsigned resplit;
 
204
 
 
205
  /* Text that is unput.  */
 
206
  char *prefix;
 
207
 
 
208
  /* Flex scanner.  */
 
209
  void *yyscanner;
 
210
 
 
211
  /* Flex scanner buffer.  */
 
212
  void *buffer;
165
213
};
166
214
 
 
215
#define GRUB_LEXER_INITIAL_TEXT_SIZE   32
 
216
#define GRUB_LEXER_INITIAL_RECORD_SIZE 256
 
217
 
167
218
/* State of the parser as passes to the parser.  */
168
219
struct grub_parser_param
169
220
{
177
228
  /* The memory that was used while parsing and scanning.  */
178
229
  struct grub_script_mem *memused;
179
230
 
 
231
  /* The block argument scripts.  */
 
232
  struct grub_script *scripts;
 
233
 
180
234
  /* The result of the parser.  */
181
235
  struct grub_script_cmd *parsed;
182
236
 
183
237
  struct grub_lexer_param *lexerstate;
184
238
};
185
239
 
 
240
void grub_script_init (void);
 
241
void grub_script_fini (void);
 
242
 
 
243
void grub_script_mem_free (struct grub_script_mem *mem);
 
244
 
 
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);
 
250
 
186
251
struct grub_script_arglist *
187
252
grub_script_create_arglist (struct grub_parser_param *state);
188
253
 
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);
198
261
 
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);
204
267
 
205
268
struct grub_script_cmd *
206
 
grub_script_create_cmdmenu (struct grub_parser_param *state,
207
 
                            struct grub_script_arglist *arglist,
208
 
                            char *sourcecode,
209
 
                            int options);
210
 
 
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);
 
273
 
 
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);
 
279
 
 
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);
225
294
 
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,
 
296
                                                 char *script,
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 *);
232
305
 
233
306
/* Functions to track allocated memory.  */
234
307
struct grub_script_mem *grub_script_mem_record (struct grub_parser_param *state);
244
317
 
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);
250
324
 
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);
 
328
 
 
329
/* Break command for loops.  */
 
330
grub_err_t grub_script_break (grub_command_t cmd, int argc, char *argv[]);
 
331
 
 
332
/* SHIFT command for GRUB script.  */
 
333
grub_err_t grub_script_shift (grub_command_t cmd, int argc, char *argv[]);
 
334
 
 
335
/* SETPARAMS command for GRUB script functions.  */
 
336
grub_err_t grub_script_setparams (grub_command_t cmd, int argc, char *argv[]);
 
337
 
 
338
/* RETURN command for functions.  */
 
339
grub_err_t grub_script_return (grub_command_t cmd, int argc, char *argv[]);
253
340
 
254
341
/* This variable points to the parsed command.  This is used to
255
342
   communicate with the bison code.  */
276
363
};
277
364
typedef struct grub_script_function *grub_script_function_t;
278
365
 
 
366
extern grub_script_function_t grub_script_function_list;
 
367
 
 
368
#define FOR_SCRIPT_FUNCTIONS(var) for((var) = grub_script_function_list; \
 
369
                                      (var); (var) = (var)->next)
 
370
 
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);
286
 
 
287
 
char *
288
 
grub_script_execute_argument_to_string (struct grub_script_arg *arg);
 
375
 
 
376
grub_err_t grub_script_function_call (grub_script_function_t func,
 
377
                                      int argc, char **args);
 
378
 
 
379
char **
 
380
grub_script_execute_arglist_to_argv (struct grub_script_arglist *arglist, int *count);
 
381
 
 
382
grub_err_t
 
383
grub_normal_parse_line (char *line, grub_reader_getline_t getline);
 
384
 
 
385
static inline struct grub_script *
 
386
grub_script_ref (struct grub_script *script)
 
387
{
 
388
  if (script)
 
389
    script->refcnt++;
 
390
  return script;
 
391
}
 
392
 
 
393
static inline void
 
394
grub_script_unref (struct grub_script *script)
 
395
{
 
396
  if (! script)
 
397
    return;
 
398
 
 
399
  if (script->refcnt == 0)
 
400
    grub_script_free (script);
 
401
  else
 
402
    script->refcnt--;
 
403
}
289
404
 
290
405
#endif /* ! GRUB_NORMAL_PARSER_HEADER */