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

« back to all changes in this revision

Viewing changes to script/yylex.l

  • Committer: Bazaar Package Importer
  • Author(s): Colin Watson, Colin Watson, Evan Broder, Mario Limonciello
  • Date: 2010-11-24 13:59:55 UTC
  • mfrom: (1.17.6 upstream) (17.6.15 experimental)
  • Revision ID: james.westby@ubuntu.com-20101124135955-r6ii5sepayr7jt53
Tags: 1.99~20101124-1ubuntu1
[ Colin Watson ]
* Resynchronise with Debian experimental.  Remaining changes:
  - Adjust for default Ubuntu boot options ("quiet splash").
  - Default to hiding the menu; holding down Shift at boot will show it.
  - Set a monochromatic theme for Ubuntu.
  - Apply Ubuntu GRUB Legacy changes to legacy update-grub script: title,
    recovery mode, quiet option, tweak how memtest86+ is displayed, and
    use UUIDs where appropriate.
  - Fix backslash-escaping in merge_debconf_into_conf.
  - Remove "GNU/Linux" from default distributor string.
  - Add crashkernel= options if kdump and makedumpfile are available.
  - If other operating systems are installed, then automatically unhide
    the menu.  Otherwise, if GRUB_HIDDEN_TIMEOUT is 0, then use keystatus
    if available to check whether Shift is pressed.  If it is, show the
    menu, otherwise boot immediately.  If keystatus is not available, then
    fall back to a short delay interruptible with Escape.
  - Allow Shift to interrupt 'sleep --interruptible'.
  - Don't display introductory message about line editing unless we're
    actually offering a shell prompt.  Don't clear the screen just before
    booting if we never drew the menu in the first place.
  - Remove some verbose messages printed before reading the configuration
    file.
  - Suppress progress messages as the kernel and initrd load for
    non-recovery kernel menu entries.
  - Change prepare_grub_to_access_device to handle filesystems
    loop-mounted on file images.
  - Ignore devices loop-mounted from files in 10_linux.
  - Show the boot menu if the previous boot failed, that is if it failed
    to get to the end of one of the normal runlevels.
  - Don't generate /boot/grub/device.map during grub-install or
    grub-mkconfig by default.
  - Adjust upgrade version checks for Ubuntu.
  - Don't display "GRUB loading" unless Shift is held down.
  - Adjust versions of grub-doc and grub-legacy-doc conflicts to tolerate
    our backport of the grub-doc split.
  - Fix LVM/RAID probing in the absence of /boot/grub/device.map.
  - Look for .mo files in /usr/share/locale-langpack as well, in
    preference.
  - Make sure GRUB_TIMEOUT isn't quoted unnecessarily.
  - Probe all devices in 'grub-probe --target=drive' if
    /boot/grub/device.map is missing.
  - Build-depend on qemu-kvm rather than qemu-system for grub-pc tests.
  - Use qemu rather than qemu-system-i386.
  - Program vesafb on BIOS systems rather than efifb.
  - Add a grub-rescue-efi-amd64 package containing a rescue CD-ROM image
    for EFI-AMD64.
  - On Wubi, don't ask for an install device, but just update wubildr
    using the diverted grub-install.
  - When embedding the core image in a post-MBR gap, check for and avoid
    sectors matching any of a list of known signatures.
  - Disable video_bochs and video_cirrus on PC BIOS systems, as probing
    PCI space seems to break on some systems.
* Downgrade "ACPI shutdown failed" error to a debug message, since it can
  cause spurious test failures.

[ Evan Broder ]
* Enable lua from grub-extras.
* Incorporate the bitop library into lua.
* Add enum_pci function to grub module in lua.
* Switch back to gfxpayload=keep by default, unless the video hardware
  is known to not support it.

[ Mario Limonciello ]
* Built part_msdos and vfat into bootx64.efi (LP: #677758)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
%{
2
 
/* yylex.l  The scripting lexer.  */
3
 
/*
4
 
 *  GRUB  --  GRand Unified Bootloader
5
 
 *  Copyright (C) 2009,2010  Free Software Foundation, Inc.
6
 
 *
7
 
 *  GRUB is free software: you can redistribute it and/or modify
8
 
 *  it under the terms of the GNU General Public License as published by
9
 
 *  the Free Software Foundation, either version 3 of the License, or
10
 
 *  (at your option) any later version.
11
 
 *
12
 
 *  GRUB is distributed in the hope that it will be useful,
13
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 
 *  GNU General Public License for more details.
16
 
 *
17
 
 *  You should have received a copy of the GNU General Public License
18
 
 *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
19
 
 */
20
 
 
21
 
#include <grub/parser.h>
22
 
#include <grub/misc.h>
23
 
#include <grub/mm.h>
24
 
#include <grub/script_sh.h>
25
 
#include "grub_script.tab.h"
26
 
 
27
 
#define yyfree    grub_lexer_yyfree
28
 
#define yyalloc   grub_lexer_yyalloc
29
 
#define yyrealloc grub_lexer_yyrealloc
30
 
 
31
 
/* 
32
 
 * As we don't have access to yyscanner, we cannot do much except to
33
 
 * print the fatal error.
34
 
 */
35
 
#define YY_FATAL_ERROR(msg)                     \
36
 
  do {                                          \
37
 
    grub_printf ("fatal error: %s\n", msg);     \
38
 
  } while (0)
39
 
 
40
 
#define COPY(str, hint)                         \
41
 
  do {                                          \
42
 
    copy_string (yyextra, str, hint);           \
43
 
  } while (0)
44
 
 
45
 
 
46
 
#define RECORD                                  \
47
 
  do {                                          \
48
 
    grub_script_lexer_record (yyextra, yytext); \
49
 
  } while (0)
50
 
 
51
 
#define ARG(t)                        \
52
 
  do {                                \
53
 
    yyextra->lexerstate->type = t;    \
54
 
    return GRUB_PARSER_TOKEN_WORD;    \
55
 
  } while (0)
56
 
 
57
 
/* We don't need YY_INPUT, as we rely on yy_scan_strings */
58
 
#define YY_INPUT(buf,res,max) do { res = 0; } while (0)
59
 
 
60
 
/* forward declarations */
61
 
static void  grub_lexer_yyfree (void *, yyscan_t yyscanner);
62
 
static void* grub_lexer_yyalloc (yy_size_t, yyscan_t yyscanner);
63
 
static void* grub_lexer_yyrealloc (void*, yy_size_t, yyscan_t yyscanner);
64
 
static void  copy_string (struct grub_parser_param *, const char *,
65
 
                          unsigned hint);
66
 
 
67
 
%}
68
 
 
69
 
%top{
70
 
 
71
 
#include <sys/types.h>
72
 
 
73
 
typedef size_t yy_size_t;
74
 
#define YY_TYPEDEF_YY_SIZE_T 1
75
 
 
76
 
/* 
77
 
 * Some flex hacks for -nostdinc; XXX We need to fix these when libc
78
 
 * support becomes availble in GRUB.
79
 
 */
80
 
 
81
 
#ifndef GRUB_UTIL
82
 
#define stdin  0
83
 
#define stdout 0
84
 
 
85
 
#define fprintf(...) 0
86
 
#define exit(...)
87
 
#endif
88
 
 
89
 
}
90
 
 
91
 
%option ecs
92
 
%option meta-ecs
93
 
 
94
 
%option warn
95
 
%option array
96
 
%option stack
97
 
%option reentrant
98
 
%option bison-bridge
99
 
%option never-interactive
100
 
 
101
 
%option noyyfree noyyalloc noyyrealloc
102
 
%option nounistd nostdinit nodefault noyylineno noyywrap
103
 
 
104
 
/* Reduce lexer size, by not defining these.  */
105
 
%option noyy_top_state
106
 
%option noinput nounput
107
 
%option noyyget_in noyyset_in
108
 
%option noyyget_out noyyset_out
109
 
%option noyyget_debug noyyset_debug
110
 
%option noyyget_lineno noyyset_lineno
111
 
 
112
 
%option extra-type="struct grub_parser_param*"
113
 
 
114
 
BLANK           [ \t]
115
 
COMMENT         #.*$
116
 
 
117
 
CHAR            [^{}|&$;<> \t\n\'\"\\]
118
 
DIGITS          [[:digit:]]+
119
 
NAME            [[:alpha:]_][[:alnum:]_]*
120
 
 
121
 
ESC             \\.
122
 
VARIABLE        ${NAME}|$\{{NAME}\}|${DIGITS}|$\{{DIGITS}\}|$\?|$\{\?\}
123
 
DQSTR           \"([^\\\"]|{ESC})*\"
124
 
SQSTR           \'[^\']*\'
125
 
WORD            ({CHAR}|{DQSTR}|{SQSTR}|{ESC}|{VARIABLE})+
126
 
 
127
 
%x              SPLIT
128
 
%x              DQUOTE
129
 
%x              SQUOTE
130
 
%x              VAR
131
 
 
132
 
%%
133
 
 
134
 
 /* White spaces */
135
 
{BLANK}+        { RECORD; }
136
 
{COMMENT}       { RECORD; }
137
 
 
138
 
 /* Special symbols */
139
 
"\n"            { RECORD; return GRUB_PARSER_TOKEN_NEWLINE; }
140
 
"||"            { RECORD; return GRUB_PARSER_TOKEN_OR;      }
141
 
"&&"            { RECORD; return GRUB_PARSER_TOKEN_AND;     }
142
 
";;"            { RECORD; return GRUB_PARSER_TOKEN_SEMI2;   }
143
 
"|"             { RECORD; return GRUB_PARSER_TOKEN_PIPE;    }
144
 
"&"             { RECORD; return GRUB_PARSER_TOKEN_AMP;     }
145
 
";"             { RECORD; return GRUB_PARSER_TOKEN_SEMI;    }
146
 
"<"             { RECORD; return GRUB_PARSER_TOKEN_LT;      }
147
 
">"             { RECORD; return GRUB_PARSER_TOKEN_GT;      }
148
 
 
149
 
 /* Reserved words */
150
 
"!"             { RECORD; return GRUB_PARSER_TOKEN_NOT;       }
151
 
"{"             { RECORD; return GRUB_PARSER_TOKEN_LBR;       }
152
 
"}"             { RECORD; return GRUB_PARSER_TOKEN_RBR;       }
153
 
"[["            { RECORD; return GRUB_PARSER_TOKEN_RSQBR2;    }
154
 
"]]"            { RECORD; return GRUB_PARSER_TOKEN_LSQBR2;    }
155
 
"time"          { RECORD; return GRUB_PARSER_TOKEN_TIME;      }
156
 
"case"          { RECORD; return GRUB_PARSER_TOKEN_CASE;      }
157
 
"do"            { RECORD; return GRUB_PARSER_TOKEN_DO;        }
158
 
"done"          { RECORD; return GRUB_PARSER_TOKEN_DONE;      }
159
 
"elif"          { RECORD; return GRUB_PARSER_TOKEN_ELIF;      }
160
 
"else"          { RECORD; return GRUB_PARSER_TOKEN_ELSE;      }
161
 
"esac"          { RECORD; return GRUB_PARSER_TOKEN_ESAC;      }
162
 
"fi"            { RECORD; return GRUB_PARSER_TOKEN_FI;        }
163
 
"for"           { RECORD; return GRUB_PARSER_TOKEN_FOR;       }
164
 
"if"            { RECORD; return GRUB_PARSER_TOKEN_IF;        }
165
 
"in"            { RECORD; return GRUB_PARSER_TOKEN_IN;        }
166
 
"select"        { RECORD; return GRUB_PARSER_TOKEN_SELECT;    }
167
 
"then"          { RECORD; return GRUB_PARSER_TOKEN_THEN;      }
168
 
"until"         { RECORD; return GRUB_PARSER_TOKEN_UNTIL;     }
169
 
"while"         { RECORD; return GRUB_PARSER_TOKEN_WHILE;     }
170
 
"function"      { RECORD; return GRUB_PARSER_TOKEN_FUNCTION;  }
171
 
"menuentry"     { RECORD; return GRUB_PARSER_TOKEN_MENUENTRY; }
172
 
 
173
 
{NAME}          { RECORD; return GRUB_PARSER_TOKEN_NAME; }
174
 
{WORD}          {
175
 
                  RECORD;
176
 
                  /* resplit yytext */
177
 
                  grub_dprintf ("lexer", "word: [%s]\n", yytext);
178
 
                  yypush_buffer_state (YY_CURRENT_BUFFER, yyscanner);
179
 
                  if (yy_scan_string (yytext, yyscanner))
180
 
                    {
181
 
                      yyextra->lexerstate->merge_start = 1;
182
 
                      yy_push_state (SPLIT, yyscanner);
183
 
                    }
184
 
                  else
185
 
                    {
186
 
                      grub_script_yyerror (yyextra, 0);
187
 
                      yypop_buffer_state (yyscanner);
188
 
                      return GRUB_PARSER_TOKEN_WORD;
189
 
                    }
190
 
                }
191
 
 
192
 
.|\n            {
193
 
                  grub_script_yyerror (yyextra, "unrecognized token");
194
 
                  return GRUB_PARSER_TOKEN_BAD;
195
 
                }
196
 
 
197
 
 /* Split word into multiple args */
198
 
 
199
 
<SPLIT>{
200
 
  \\.           { COPY (yytext + 1, yyleng - 1); }
201
 
  \"            {
202
 
                  yy_push_state (DQUOTE, yyscanner);
203
 
                  ARG (GRUB_SCRIPT_ARG_TYPE_TEXT);
204
 
                }
205
 
  \'            {
206
 
                  yy_push_state (SQUOTE, yyscanner);
207
 
                  ARG (GRUB_SCRIPT_ARG_TYPE_TEXT);
208
 
                }
209
 
  \$            {
210
 
                  yy_push_state (VAR, yyscanner);
211
 
                  ARG (GRUB_SCRIPT_ARG_TYPE_TEXT);
212
 
                }
213
 
  \\            |
214
 
  [^\"\'\$\\]+  { COPY (yytext, yyleng); }
215
 
  <<EOF>>       {
216
 
                  yy_pop_state (yyscanner);
217
 
                  yypop_buffer_state (yyscanner);
218
 
                  yyextra->lexerstate->merge_end = 1;
219
 
                  ARG (GRUB_SCRIPT_ARG_TYPE_TEXT);
220
 
                }
221
 
}
222
 
 
223
 
<VAR>{
224
 
  \?            |
225
 
  {DIGITS}      |
226
 
  {NAME}        {
227
 
                  COPY (yytext, yyleng);
228
 
                  yy_pop_state (yyscanner);
229
 
                  if (YY_START == SPLIT)
230
 
                    ARG (GRUB_SCRIPT_ARG_TYPE_VAR);
231
 
                  else
232
 
                    ARG (GRUB_SCRIPT_ARG_TYPE_DQVAR);
233
 
                }
234
 
  \{\?\}        |
235
 
  \{{DIGITS}\}  |
236
 
  \{{NAME}\}    {
237
 
                  yytext[yyleng - 1] = '\0';
238
 
                  COPY (yytext + 1, yyleng - 2);
239
 
                  yy_pop_state (yyscanner);
240
 
                  if (YY_START == SPLIT)
241
 
                    ARG (GRUB_SCRIPT_ARG_TYPE_VAR);
242
 
                  else
243
 
                    ARG (GRUB_SCRIPT_ARG_TYPE_DQVAR);
244
 
                }
245
 
  .|\n          { return GRUB_PARSER_TOKEN_BAD; }
246
 
}
247
 
 
248
 
<SQUOTE>{
249
 
  \'            {
250
 
                  yy_pop_state (yyscanner);
251
 
                  ARG (GRUB_SCRIPT_ARG_TYPE_SQSTR);
252
 
                }
253
 
  [^\']+        { COPY (yytext, yyleng); }
254
 
}
255
 
 
256
 
<DQUOTE>{
257
 
  \\\$          { COPY ("$", 1); }
258
 
  \\\\          { COPY ("\\", 1); }
259
 
  \\\"          { COPY ("\"", 1); }
260
 
  \\\n          { /* ignore */ }
261
 
  [^\"\$\\\n]+  { COPY (yytext, yyleng); }
262
 
  \"            {
263
 
                  yy_pop_state (yyscanner);
264
 
                  ARG (GRUB_SCRIPT_ARG_TYPE_DQSTR);
265
 
                }
266
 
  \$            {
267
 
                  yy_push_state (VAR, yyscanner);
268
 
                  ARG (GRUB_SCRIPT_ARG_TYPE_DQSTR);
269
 
                }
270
 
  (.|\n)        { COPY (yytext, yyleng); }
271
 
}
272
 
 
273
 
<<EOF>>         {
274
 
                  yypop_buffer_state (yyscanner);
275
 
                  if (! grub_script_lexer_yywrap (yyextra))
276
 
                    {
277
 
                      yyextra->lexerstate->eof = 1;
278
 
                      return GRUB_PARSER_TOKEN_EOF;
279
 
                    }
280
 
                }
281
 
 
282
 
%%
283
 
 
284
 
static void
285
 
grub_lexer_yyfree (void *ptr, yyscan_t yyscanner __attribute__ ((unused)))
286
 
{
287
 
  grub_free(ptr);
288
 
}
289
 
 
290
 
static void*
291
 
grub_lexer_yyalloc (yy_size_t size, yyscan_t yyscanner __attribute__ ((unused)))
292
 
{
293
 
  return grub_malloc (size);
294
 
}
295
 
 
296
 
static void*
297
 
grub_lexer_yyrealloc (void *ptr, yy_size_t size,
298
 
                      yyscan_t yyscanner __attribute__ ((unused)))
299
 
{
300
 
  return grub_realloc (ptr, size);
301
 
}
302
 
 
303
 
#define MAX(a,b) ((a) < (b) ? (b) : (a))
304
 
 
305
 
static void copy_string (struct grub_parser_param *parser, const char *str, unsigned hint)
306
 
{
307
 
  int size;
308
 
  char *ptr;
309
 
  unsigned len;
310
 
 
311
 
  len = hint ? hint : grub_strlen (str);
312
 
  if (parser->lexerstate->used + len >= parser->lexerstate->size)
313
 
    {
314
 
      size = MAX (len, parser->lexerstate->size) * 2;
315
 
      ptr = grub_realloc (parser->lexerstate->text, size);
316
 
      if (!ptr)
317
 
        {
318
 
          grub_script_yyerror (parser, 0);
319
 
          return;
320
 
        }
321
 
 
322
 
      parser->lexerstate->text = ptr;
323
 
      parser->lexerstate->size = size;
324
 
    }
325
 
  grub_strcpy (parser->lexerstate->text + parser->lexerstate->used - 1, str);
326
 
  parser->lexerstate->used += len;
327
 
}