merge mainline into bidi
This commit is contained in:
commit
a87add6d17
10 changed files with 501 additions and 278 deletions
30
ChangeLog
30
ChangeLog
|
@ -1,3 +1,33 @@
|
|||
2010-04-09 Vladimir Serbinenko <phcoder@gmail.com>
|
||||
|
||||
* font/font.c: Indented.
|
||||
|
||||
2010-04-09 BVK Chaitanya <bvk.groups@gmail.com>
|
||||
|
||||
Elif support to GRUB script (by Deepak Vankadaru).
|
||||
|
||||
* tests/grub_script_if.in: New testcase.
|
||||
* conf/tests.rmk: Rule for new testcase.
|
||||
* script/parser.y: Grammar rules for elif.
|
||||
|
||||
2010-04-09 BVK Chaitanya <bvk.groups@gmail.com>
|
||||
|
||||
While and until loops support to GRUB script.
|
||||
|
||||
* include/grub/script_sh.h (grub_script_cmdwhile): New struct.
|
||||
(grub_script_create_cmdwhile): New function prototype.
|
||||
(grub_script_execute_cmdwhile): New function prototype.
|
||||
* script/execute.c (grub_script_execute_cmdwhile): New function.
|
||||
* script/parser.y (command): New commands.
|
||||
(whilecmd): New grammar rule.
|
||||
(untilcmd): New grammar rule.
|
||||
* script/script.c (grub_script_create_cmdwhile): New function.
|
||||
* util/grub-script-check.c (grub_script_execute_cmdwhile): New
|
||||
function.
|
||||
|
||||
* tests/grub_script_while1.in: New testcase.
|
||||
* conf/tests.rmk: Rule for new testcase.
|
||||
|
||||
2010-04-09 Vladimir Serbinenko <phcoder@gmail.com>
|
||||
|
||||
* util/grub.d/00_header.in: Add few missing quotes. Recognise *.jpeg
|
||||
|
|
|
@ -53,6 +53,12 @@ grub_script_vars1_SOURCES = tests/grub_script_vars1.in
|
|||
check_SCRIPTS += grub_script_for1
|
||||
grub_script_for1_SOURCES = tests/grub_script_for1.in
|
||||
|
||||
check_SCRIPTS += grub_script_while1
|
||||
grub_script_while1_SOURCES = tests/grub_script_while1.in
|
||||
|
||||
check_SCRIPTS += grub_script_if
|
||||
grub_script_if_SOURCES = tests/grub_script_if.in
|
||||
|
||||
check_SCRIPTS += grub_script_blanklines
|
||||
grub_script_blanklines_SOURCES = tests/grub_script_blanklines.in
|
||||
|
||||
|
@ -69,9 +75,12 @@ SCRIPTED_TESTS = grub_script_echo1
|
|||
SCRIPTED_TESTS += grub_script_echo_keywords
|
||||
SCRIPTED_TESTS += grub_script_vars1
|
||||
SCRIPTED_TESTS += grub_script_for1
|
||||
SCRIPTED_TESTS += grub_script_while1
|
||||
SCRIPTED_TESTS += grub_script_if
|
||||
SCRIPTED_TESTS += grub_script_blanklines
|
||||
SCRIPTED_TESTS += grub_script_final_semicolon
|
||||
|
||||
|
||||
# dependencies between tests and testing-tools
|
||||
$(SCRIPTED_TESTS): grub-shell grub-shell-tester
|
||||
$(FUNCTIONAL_TESTS): functional_test.mod
|
||||
|
|
99
font/font.c
99
font/font.c
|
@ -93,8 +93,7 @@ struct font_file_section
|
|||
};
|
||||
|
||||
/* Replace unknown glyphs with a rounded question mark. */
|
||||
static grub_uint8_t unknown_glyph_bitmap[] =
|
||||
{
|
||||
static grub_uint8_t unknown_glyph_bitmap[] = {
|
||||
/* 76543210 */
|
||||
0x7C, /* ooooo */
|
||||
0x82, /* o o */
|
||||
|
@ -143,8 +142,8 @@ ascii_glyph_lookup (grub_uint32_t code)
|
|||
int current;
|
||||
for (current = 0; current < 0x80; current++)
|
||||
{
|
||||
ascii_font_glyph[current] = grub_malloc(sizeof(struct grub_font_glyph)
|
||||
+ ASCII_BITMAP_SIZE);
|
||||
ascii_font_glyph[current] =
|
||||
grub_malloc (sizeof (struct grub_font_glyph) + ASCII_BITMAP_SIZE);
|
||||
|
||||
ascii_font_glyph[current]->width = 8;
|
||||
ascii_font_glyph[current]->height = 16;
|
||||
|
@ -401,7 +400,8 @@ read_section_as_string (struct font_file_section *section)
|
|||
which is stored into *VALUE.
|
||||
Returns 0 upon success, nonzero upon failure. */
|
||||
static int
|
||||
read_section_as_short (struct font_file_section *section, grub_int16_t *value)
|
||||
read_section_as_short (struct font_file_section *section,
|
||||
grub_int16_t * value)
|
||||
{
|
||||
grub_uint16_t raw_value;
|
||||
|
||||
|
@ -411,8 +411,7 @@ read_section_as_short (struct font_file_section *section, grub_int16_t *value)
|
|||
"font file format error: section %c%c%c%c length "
|
||||
"is %d but should be 2",
|
||||
section->name[0], section->name[1],
|
||||
section->name[2], section->name[3],
|
||||
section->length);
|
||||
section->name[2], section->name[3], section->length);
|
||||
return 1;
|
||||
}
|
||||
if (grub_file_read (section->file, &raw_value, 2) != 2)
|
||||
|
@ -530,13 +529,15 @@ grub_font_load (const char *filename)
|
|||
}
|
||||
else if (grub_memcmp (section.name,
|
||||
FONT_FORMAT_SECTION_NAMES_POINT_SIZE,
|
||||
sizeof(FONT_FORMAT_SECTION_NAMES_POINT_SIZE) - 1) == 0)
|
||||
sizeof (FONT_FORMAT_SECTION_NAMES_POINT_SIZE) -
|
||||
1) == 0)
|
||||
{
|
||||
if (read_section_as_short (§ion, &font->point_size) != 0)
|
||||
goto fail;
|
||||
}
|
||||
else if (grub_memcmp (section.name, FONT_FORMAT_SECTION_NAMES_WEIGHT,
|
||||
sizeof(FONT_FORMAT_SECTION_NAMES_WEIGHT) - 1) == 0)
|
||||
sizeof (FONT_FORMAT_SECTION_NAMES_WEIGHT) - 1)
|
||||
== 0)
|
||||
{
|
||||
char *wt;
|
||||
wt = read_section_as_string (§ion);
|
||||
|
@ -551,34 +552,39 @@ grub_font_load (const char *filename)
|
|||
}
|
||||
else if (grub_memcmp (section.name,
|
||||
FONT_FORMAT_SECTION_NAMES_MAX_CHAR_WIDTH,
|
||||
sizeof(FONT_FORMAT_SECTION_NAMES_MAX_CHAR_WIDTH) - 1) == 0)
|
||||
sizeof (FONT_FORMAT_SECTION_NAMES_MAX_CHAR_WIDTH)
|
||||
- 1) == 0)
|
||||
{
|
||||
if (read_section_as_short (§ion, &font->max_char_width) != 0)
|
||||
goto fail;
|
||||
}
|
||||
else if (grub_memcmp (section.name,
|
||||
FONT_FORMAT_SECTION_NAMES_MAX_CHAR_HEIGHT,
|
||||
sizeof(FONT_FORMAT_SECTION_NAMES_MAX_CHAR_HEIGHT) - 1) == 0)
|
||||
sizeof (FONT_FORMAT_SECTION_NAMES_MAX_CHAR_HEIGHT)
|
||||
- 1) == 0)
|
||||
{
|
||||
if (read_section_as_short (§ion, &font->max_char_height) != 0)
|
||||
goto fail;
|
||||
}
|
||||
else if (grub_memcmp (section.name,
|
||||
FONT_FORMAT_SECTION_NAMES_ASCENT,
|
||||
sizeof(FONT_FORMAT_SECTION_NAMES_ASCENT) - 1) == 0)
|
||||
sizeof (FONT_FORMAT_SECTION_NAMES_ASCENT) - 1)
|
||||
== 0)
|
||||
{
|
||||
if (read_section_as_short (§ion, &font->ascent) != 0)
|
||||
goto fail;
|
||||
}
|
||||
else if (grub_memcmp (section.name, FONT_FORMAT_SECTION_NAMES_DESCENT,
|
||||
sizeof(FONT_FORMAT_SECTION_NAMES_DESCENT) - 1) == 0)
|
||||
sizeof (FONT_FORMAT_SECTION_NAMES_DESCENT) - 1)
|
||||
== 0)
|
||||
{
|
||||
if (read_section_as_short (§ion, &font->descent) != 0)
|
||||
goto fail;
|
||||
}
|
||||
else if (grub_memcmp (section.name,
|
||||
FONT_FORMAT_SECTION_NAMES_CHAR_INDEX,
|
||||
sizeof(FONT_FORMAT_SECTION_NAMES_CHAR_INDEX) - 1) == 0)
|
||||
sizeof (FONT_FORMAT_SECTION_NAMES_CHAR_INDEX) -
|
||||
1) == 0)
|
||||
{
|
||||
if (load_font_index (file, section.length, font) != 0)
|
||||
goto fail;
|
||||
|
@ -612,16 +618,13 @@ grub_font_load (const char *filename)
|
|||
"Ascent=%d Descent=%d MaxW=%d MaxH=%d Number of characters=%d.\n",
|
||||
font->name,
|
||||
font->ascent, font->descent,
|
||||
font->max_char_width, font->max_char_height,
|
||||
font->num_chars);
|
||||
font->max_char_width, font->max_char_height, font->num_chars);
|
||||
#endif
|
||||
|
||||
if (font->max_char_width == 0
|
||||
|| font->max_char_height == 0
|
||||
|| font->num_chars == 0
|
||||
|| font->char_index == 0
|
||||
|| font->ascent == 0
|
||||
|| font->descent == 0)
|
||||
|| font->char_index == 0 || font->ascent == 0 || font->descent == 0)
|
||||
{
|
||||
grub_error (GRUB_ERR_BAD_FONT,
|
||||
"invalid font file: missing some required data");
|
||||
|
@ -825,8 +828,7 @@ remove_font (grub_font_t font)
|
|||
struct grub_font_node **nextp, *cur;
|
||||
|
||||
for (nextp = &grub_font_list, cur = *nextp;
|
||||
cur;
|
||||
nextp = &cur->next, cur = cur->next)
|
||||
cur; nextp = &cur->next, cur = cur->next)
|
||||
{
|
||||
if (cur->value == font)
|
||||
{
|
||||
|
@ -1047,8 +1049,7 @@ grub_font_dup_glyph (struct grub_font_glyph *glyph)
|
|||
/* FIXME: suboptimal. */
|
||||
static void
|
||||
grub_font_blit_glyph (struct grub_font_glyph *target,
|
||||
struct grub_font_glyph *src,
|
||||
unsigned dx, unsigned dy)
|
||||
struct grub_font_glyph *src, unsigned dx, unsigned dy)
|
||||
{
|
||||
unsigned src_bit, tgt_bit, src_byte, tgt_byte;
|
||||
unsigned i, j;
|
||||
|
@ -1117,8 +1118,7 @@ blit_comb (const struct grub_unicode_glyph *glyph_id,
|
|||
struct grub_font_glyph *glyph,
|
||||
struct grub_video_signed_rect *bounds_out,
|
||||
struct grub_font_glyph *main_glyph,
|
||||
struct grub_font_glyph **combining_glyphs,
|
||||
int *device_width)
|
||||
struct grub_font_glyph **combining_glyphs, int *device_width)
|
||||
{
|
||||
struct grub_video_signed_rect bounds;
|
||||
unsigned i;
|
||||
|
@ -1186,10 +1186,10 @@ blit_comb (const struct grub_unicode_glyph *glyph_id,
|
|||
|
||||
if (!combining_glyphs[i])
|
||||
continue;
|
||||
targetx = (bounds.width - combining_glyphs[i]->width) / 2
|
||||
+ bounds.x;
|
||||
targetx = (bounds.width - combining_glyphs[i]->width) / 2 + bounds.x;
|
||||
/* CGJ is to avoid diacritics reordering. */
|
||||
if (glyph_id->combining[i].code == GRUB_UNICODE_COMBINING_GRAPHEME_JOINER)
|
||||
if (glyph_id->combining[i].code
|
||||
== GRUB_UNICODE_COMBINING_GRAPHEME_JOINER)
|
||||
continue;
|
||||
switch (glyph_id->combining[i].type)
|
||||
{
|
||||
|
@ -1220,14 +1220,15 @@ blit_comb (const struct grub_unicode_glyph *glyph_id,
|
|||
break;
|
||||
|
||||
case GRUB_UNICODE_COMB_BELOW_RIGHT:
|
||||
do_blit (combining_glyphs[i], below_rightx,
|
||||
below_righty);
|
||||
do_blit (combining_glyphs[i], below_rightx, below_righty);
|
||||
below_rightx += combining_glyphs[i]->width;
|
||||
break;
|
||||
|
||||
case GRUB_UNICODE_COMB_HEBREW_HOLAM:
|
||||
if (glyph_id->base != GRUB_UNICODE_HEBREW_WAW)
|
||||
targetx = main_glyph->offset_x - combining_glyphs[i]->width - (combining_glyphs[i]->width + 3) / 4;
|
||||
targetx =
|
||||
main_glyph->offset_x - combining_glyphs[i]->width -
|
||||
(combining_glyphs[i]->width + 3) / 4;
|
||||
goto above_on_main;
|
||||
|
||||
case GRUB_UNICODE_COMB_HEBREW_SIN_DOT:
|
||||
|
@ -1235,7 +1236,9 @@ blit_comb (const struct grub_unicode_glyph *glyph_id,
|
|||
goto above_on_main;
|
||||
|
||||
case GRUB_UNICODE_COMB_HEBREW_SHIN_DOT:
|
||||
targetx = main_glyph->width + main_glyph->offset_x - combining_glyphs[i]->width;
|
||||
targetx =
|
||||
main_glyph->width + main_glyph->offset_x -
|
||||
combining_glyphs[i]->width;
|
||||
above_on_main:
|
||||
space = combining_glyphs[i]->offset_y
|
||||
- grub_font_get_xheight (combining_glyphs[i]->font) - 1;
|
||||
|
@ -1299,8 +1302,7 @@ blit_comb (const struct grub_unicode_glyph *glyph_id,
|
|||
space = 1 + (grub_font_get_xheight (main_glyph->font)) / 8;
|
||||
|
||||
case GRUB_UNICODE_STACK_ATTACHED_BELOW:
|
||||
do_blit (combining_glyphs[i], targetx,
|
||||
-(bounds.y - space));
|
||||
do_blit (combining_glyphs[i], targetx, -(bounds.y - space));
|
||||
if (min_devwidth < combining_glyphs[i]->width)
|
||||
min_devwidth = combining_glyphs[i]->width;
|
||||
break;
|
||||
|
@ -1338,8 +1340,9 @@ blit_comb (const struct grub_unicode_glyph *glyph_id,
|
|||
}
|
||||
}
|
||||
}
|
||||
add_device_width ((above_rightx > below_rightx ? above_rightx : below_rightx)
|
||||
- (main_glyph->offset_x + main_glyph->width));
|
||||
add_device_width ((above_rightx >
|
||||
below_rightx ? above_rightx : below_rightx) -
|
||||
(main_glyph->offset_x + main_glyph->width));
|
||||
add_device_width (above_leftx - main_glyph->offset_x);
|
||||
if (glyph && glyph->device_width < min_devwidth)
|
||||
glyph->device_width = min_devwidth;
|
||||
|
@ -1407,7 +1410,8 @@ grub_font_construct_dry_run (grub_font_t hinted_font,
|
|||
glyph_id->combining[i].code);
|
||||
}
|
||||
|
||||
blit_comb (glyph_id, NULL, bounds, main_glyph, combining_glyphs, device_width);
|
||||
blit_comb (glyph_id, NULL, bounds, main_glyph, combining_glyphs,
|
||||
device_width);
|
||||
if (combining_glyphs_out)
|
||||
*combining_glyphs_out = combining_glyphs;
|
||||
else
|
||||
|
@ -1418,7 +1422,8 @@ grub_font_construct_dry_run (grub_font_t hinted_font,
|
|||
|
||||
int
|
||||
grub_font_get_constructed_device_width (grub_font_t hinted_font,
|
||||
const struct grub_unicode_glyph *glyph_id)
|
||||
const struct grub_unicode_glyph
|
||||
*glyph_id)
|
||||
{
|
||||
int ret;
|
||||
struct grub_font_glyph *main_glyph;
|
||||
|
@ -1447,7 +1452,8 @@ grub_font_construct_glyph (grub_font_t hinted_font,
|
|||
if (!combining_glyphs)
|
||||
return grub_font_dup_glyph (main_glyph);
|
||||
|
||||
glyph = grub_zalloc (sizeof (*glyph) + (bounds.width * bounds.height + 7) / 8);
|
||||
glyph =
|
||||
grub_zalloc (sizeof (*glyph) + (bounds.width * bounds.height + 7) / 8);
|
||||
if (!glyph)
|
||||
{
|
||||
grub_errno = GRUB_ERR_NONE;
|
||||
|
@ -1464,7 +1470,8 @@ grub_font_construct_glyph (grub_font_t hinted_font,
|
|||
grub_font_blit_glyph_mirror (glyph, main_glyph,
|
||||
main_glyph->offset_x - glyph->offset_x,
|
||||
(glyph->height + glyph->offset_y)
|
||||
- (main_glyph->height + main_glyph->offset_y));
|
||||
- (main_glyph->height +
|
||||
main_glyph->offset_y));
|
||||
else
|
||||
grub_font_blit_glyph (glyph, main_glyph,
|
||||
main_glyph->offset_x - glyph->offset_x,
|
||||
|
@ -1481,8 +1488,7 @@ grub_font_construct_glyph (grub_font_t hinted_font,
|
|||
side location of the character. */
|
||||
grub_err_t
|
||||
grub_font_draw_glyph (struct grub_font_glyph * glyph,
|
||||
grub_video_color_t color,
|
||||
int left_x, int baseline_y)
|
||||
grub_video_color_t color, int left_x, int baseline_y)
|
||||
{
|
||||
struct grub_video_bitmap glyph_bitmap;
|
||||
|
||||
|
@ -1492,9 +1498,8 @@ grub_font_draw_glyph (struct grub_font_glyph *glyph,
|
|||
|
||||
glyph_bitmap.mode_info.width = glyph->width;
|
||||
glyph_bitmap.mode_info.height = glyph->height;
|
||||
glyph_bitmap.mode_info.mode_type =
|
||||
(1 << GRUB_VIDEO_MODE_TYPE_DEPTH_POS)
|
||||
| GRUB_VIDEO_MODE_TYPE_1BIT_BITMAP;
|
||||
glyph_bitmap.mode_info.mode_type
|
||||
= (1 << GRUB_VIDEO_MODE_TYPE_DEPTH_POS) | GRUB_VIDEO_MODE_TYPE_1BIT_BITMAP;
|
||||
glyph_bitmap.mode_info.blit_format = GRUB_VIDEO_BLIT_FORMAT_1BIT_PACKED;
|
||||
glyph_bitmap.mode_info.bpp = 1;
|
||||
|
||||
|
@ -1522,7 +1527,5 @@ grub_font_draw_glyph (struct grub_font_glyph *glyph,
|
|||
|
||||
return grub_video_blit_bitmap (&glyph_bitmap, GRUB_VIDEO_BLIT_BLEND,
|
||||
bitmap_left, bitmap_top,
|
||||
0, 0,
|
||||
glyph->width, glyph->height);
|
||||
0, 0, glyph->width, glyph->height);
|
||||
}
|
||||
|
||||
|
|
|
@ -121,6 +121,21 @@ struct grub_script_cmdfor
|
|||
struct grub_script_cmd *list;
|
||||
};
|
||||
|
||||
/* A while/until command. */
|
||||
struct grub_script_cmdwhile
|
||||
{
|
||||
struct grub_script_cmd cmd;
|
||||
|
||||
/* The command list used as condition. */
|
||||
struct grub_script_cmd *cond;
|
||||
|
||||
/* The command list executed in each loop. */
|
||||
struct grub_script_cmd *list;
|
||||
|
||||
/* The flag to indicate this as "until" loop. */
|
||||
int until;
|
||||
};
|
||||
|
||||
/* A menu entry generate statement. */
|
||||
struct grub_script_cmd_menuentry
|
||||
{
|
||||
|
@ -234,6 +249,12 @@ grub_script_create_cmdfor (struct grub_parser_param *state,
|
|||
struct grub_script_arglist *words,
|
||||
struct grub_script_cmd *list);
|
||||
|
||||
struct grub_script_cmd *
|
||||
grub_script_create_cmdwhile (struct grub_parser_param *state,
|
||||
struct grub_script_cmd *cond,
|
||||
struct grub_script_cmd *list,
|
||||
int is_an_until_loop);
|
||||
|
||||
struct grub_script_cmd *
|
||||
grub_script_create_cmdmenu (struct grub_parser_param *state,
|
||||
struct grub_script_arglist *arglist,
|
||||
|
@ -283,6 +304,7 @@ grub_err_t grub_script_execute_cmdline (struct grub_script_cmd *cmd);
|
|||
grub_err_t grub_script_execute_cmdblock (struct grub_script_cmd *cmd);
|
||||
grub_err_t grub_script_execute_cmdif (struct grub_script_cmd *cmd);
|
||||
grub_err_t grub_script_execute_cmdfor (struct grub_script_cmd *cmd);
|
||||
grub_err_t grub_script_execute_cmdwhile (struct grub_script_cmd *cmd);
|
||||
grub_err_t grub_script_execute_menuentry (struct grub_script_cmd *cmd);
|
||||
|
||||
/* Execute any GRUB pre-parsed command or script. */
|
||||
|
|
|
@ -26,13 +26,24 @@
|
|||
#include <grub/lib/arg.h>
|
||||
#include <grub/normal.h>
|
||||
|
||||
/* Max digits for a char is 3 (0xFF is 255), similarly for an int it
|
||||
is sizeof (int) * 3, and one extra for a possible -ve sign. */
|
||||
#define ERRNO_DIGITS_MAX (sizeof (int) * 3 + 1)
|
||||
|
||||
static grub_err_t
|
||||
grub_script_execute_cmd (struct grub_script_cmd *cmd)
|
||||
{
|
||||
int ret;
|
||||
char errnobuf[ERRNO_DIGITS_MAX + 1];
|
||||
|
||||
if (cmd == 0)
|
||||
return 0;
|
||||
|
||||
return cmd->exec (cmd);
|
||||
ret = cmd->exec (cmd);
|
||||
|
||||
grub_snprintf (errnobuf, sizeof (errnobuf), "%d", ret);
|
||||
grub_env_set ("?", errnobuf);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#define ARG_ALLOCATION_UNIT (32 * sizeof (char))
|
||||
|
@ -260,13 +271,14 @@ grub_script_execute_cmdline (struct grub_script_cmd *cmd)
|
|||
grub_err_t
|
||||
grub_script_execute_cmdblock (struct grub_script_cmd *cmd)
|
||||
{
|
||||
int ret = 0;
|
||||
struct grub_script_cmdblock *cmdblock = (struct grub_script_cmdblock *) cmd;
|
||||
|
||||
/* Loop over every command and execute it. */
|
||||
for (cmd = cmdblock->cmdlist; cmd; cmd = cmd->next)
|
||||
grub_script_execute_cmd (cmd);
|
||||
ret = grub_script_execute_cmd (cmd);
|
||||
|
||||
return 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Execute an if statement. */
|
||||
|
@ -317,6 +329,26 @@ grub_script_execute_cmdfor (struct grub_script_cmd *cmd)
|
|||
return result;
|
||||
}
|
||||
|
||||
/* Execute a "while" or "until" command. */
|
||||
grub_err_t
|
||||
grub_script_execute_cmdwhile (struct grub_script_cmd *cmd)
|
||||
{
|
||||
int cond;
|
||||
int result;
|
||||
struct grub_script_cmdwhile *cmdwhile = (struct grub_script_cmdwhile *) cmd;
|
||||
|
||||
result = 0;
|
||||
do {
|
||||
cond = grub_script_execute_cmd (cmdwhile->cond);
|
||||
if (cmdwhile->until ? !cond : cond)
|
||||
break;
|
||||
|
||||
result = grub_script_execute_cmd (cmdwhile->list);
|
||||
} while (1); /* XXX Put a check for ^C here */
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/* Execute the menu entry generate statement. */
|
||||
grub_err_t
|
||||
grub_script_execute_menuentry (struct grub_script_cmd *cmd)
|
||||
|
|
|
@ -74,8 +74,10 @@
|
|||
%token <arg> GRUB_PARSER_TOKEN_WORD "word"
|
||||
|
||||
%type <arglist> word argument arguments0 arguments1
|
||||
%type <cmd> script_init script grubcmd ifcmd forcmd command
|
||||
%type <cmd> commands1 menuentry statement
|
||||
|
||||
%type <cmd> script_init script
|
||||
%type <cmd> grubcmd ifclause ifcmd forcmd whilecmd untilcmd
|
||||
%type <cmd> command commands1 menuentry statement
|
||||
|
||||
%pure-parser
|
||||
%lex-param { struct grub_parser_param *state };
|
||||
|
@ -174,6 +176,8 @@ grubcmd: word arguments0
|
|||
command: grubcmd { $$ = $1; }
|
||||
| ifcmd { $$ = $1; }
|
||||
| forcmd { $$ = $1; }
|
||||
| whilecmd { $$ = $1; }
|
||||
| untilcmd { $$ = $1; }
|
||||
;
|
||||
|
||||
/* A list of commands. */
|
||||
|
@ -224,17 +228,27 @@ menuentry: "menuentry"
|
|||
}
|
||||
;
|
||||
|
||||
if: "if" { grub_script_lexer_ref (state->lexerstate); }
|
||||
;
|
||||
ifcmd: if commands1 delimiters1 "then" commands1 delimiters1 "fi"
|
||||
ifcmd: "if"
|
||||
{
|
||||
$$ = grub_script_create_cmdif (state, $2, $5, 0);
|
||||
grub_script_lexer_ref (state->lexerstate);
|
||||
}
|
||||
ifclause "fi"
|
||||
{
|
||||
$$ = $3;
|
||||
grub_script_lexer_deref (state->lexerstate);
|
||||
}
|
||||
| if commands1 delimiters1 "then" commands1 delimiters1 "else" commands1 delimiters1 "fi"
|
||||
;
|
||||
ifclause: commands1 delimiters1 "then" commands1 delimiters1
|
||||
{
|
||||
$$ = grub_script_create_cmdif (state, $2, $5, $8);
|
||||
grub_script_lexer_deref (state->lexerstate);
|
||||
$$ = grub_script_create_cmdif (state, $1, $4, 0);
|
||||
}
|
||||
| commands1 delimiters1 "then" commands1 delimiters1 "else" commands1 delimiters1
|
||||
{
|
||||
$$ = grub_script_create_cmdif (state, $1, $4, $7);
|
||||
}
|
||||
| commands1 delimiters1 "then" commands1 delimiters1 "elif" ifclause
|
||||
{
|
||||
$$ = grub_script_create_cmdif (state, $1, $4, $7);
|
||||
}
|
||||
;
|
||||
|
||||
|
@ -248,3 +262,25 @@ forcmd: "for" "name"
|
|||
grub_script_lexer_deref (state->lexerstate);
|
||||
}
|
||||
;
|
||||
|
||||
whilecmd: "while"
|
||||
{
|
||||
grub_script_lexer_ref (state->lexerstate);
|
||||
}
|
||||
commands1 delimiters1 "do" commands1 delimiters1 "done"
|
||||
{
|
||||
$$ = grub_script_create_cmdwhile (state, $3, $6, 0);
|
||||
grub_script_lexer_deref (state->lexerstate);
|
||||
}
|
||||
;
|
||||
|
||||
untilcmd: "until"
|
||||
{
|
||||
grub_script_lexer_ref (state->lexerstate);
|
||||
}
|
||||
commands1 delimiters1 "do" commands1 delimiters1 "done"
|
||||
{
|
||||
$$ = grub_script_create_cmdwhile (state, $3, $6, 1);
|
||||
grub_script_lexer_deref (state->lexerstate);
|
||||
}
|
||||
;
|
||||
|
|
|
@ -245,6 +245,28 @@ grub_script_create_cmdfor (struct grub_parser_param *state,
|
|||
return (struct grub_script_cmd *) cmd;
|
||||
}
|
||||
|
||||
/* Create a "while" or "until" command. */
|
||||
struct grub_script_cmd *
|
||||
grub_script_create_cmdwhile (struct grub_parser_param *state,
|
||||
struct grub_script_cmd *cond,
|
||||
struct grub_script_cmd *list,
|
||||
int is_an_until_loop)
|
||||
{
|
||||
struct grub_script_cmdwhile *cmd;
|
||||
|
||||
cmd = grub_script_malloc (state, sizeof (*cmd));
|
||||
if (! cmd)
|
||||
return 0;
|
||||
|
||||
cmd->cmd.exec = grub_script_execute_cmdwhile;
|
||||
cmd->cmd.next = 0;
|
||||
cmd->cond = cond;
|
||||
cmd->list = list;
|
||||
cmd->until = is_an_until_loop;
|
||||
|
||||
return (struct grub_script_cmd *) cmd;
|
||||
}
|
||||
|
||||
/* Create a command that adds a menu entry to the menu. Title is an
|
||||
argument that is parsed to generate a string that can be used as
|
||||
the title. The sourcecode for this entry is passed in SOURCECODE.
|
||||
|
|
31
tests/grub_script_if.in
Normal file
31
tests/grub_script_if.in
Normal file
|
@ -0,0 +1,31 @@
|
|||
#! @builddir@/grub-shell-tester
|
||||
|
||||
#basic if, execute
|
||||
if true; then echo yes; fi
|
||||
|
||||
#basic if, no execution
|
||||
if false; then echo no; fi
|
||||
|
||||
#if else, execute if path
|
||||
if true; then echo yes; else echo no; fi
|
||||
|
||||
#if else, execute else path
|
||||
if false; then echo no; else echo yes; fi
|
||||
|
||||
#if elif, execute elif
|
||||
if false; then echo no; elif true; then echo yes; fi
|
||||
|
||||
#if elif else, execute else
|
||||
if false; then echo no; elif false; then echo no; else echo yes; fi
|
||||
|
||||
#if elif(1) elif(2), execute elif(2)
|
||||
if false; then echo no; elif false; then echo no; elif true; then echo yes; fi
|
||||
|
||||
#if elif(1) elif(2) else, execute else
|
||||
if false; then echo no; elif false; then echo no; elif false; then echo no; else echo yes; fi
|
||||
|
||||
#if {if elif else}, execute elif
|
||||
if true; then if false; then echo no; elif true; then echo yes; else echo no; fi; fi
|
||||
|
||||
#if {if elif} else, execute elif. ofcourse no dangling-else problem due to "fi"
|
||||
if true; then if false; then echo no; elif true; then echo yes; fi; else echo no; fi
|
32
tests/grub_script_while1.in
Normal file
32
tests/grub_script_while1.in
Normal file
|
@ -0,0 +1,32 @@
|
|||
#! @builddir@/grub-shell-tester
|
||||
|
||||
echo one
|
||||
foo=""
|
||||
while test "$foo" != "1111"; do foo="${foo}1"; echo "$foo"; done
|
||||
|
||||
echo two
|
||||
foo=""
|
||||
while test "$foo" != "aaaa"
|
||||
do
|
||||
foo="${foo}a"
|
||||
echo $foo
|
||||
done
|
||||
|
||||
foo=""
|
||||
until test "$foo" = "1111"; do foo="${foo}1"; echo $foo; done
|
||||
foo=""
|
||||
until test "$foo" = "aaaa"
|
||||
do
|
||||
foo="${foo}a"
|
||||
echo $foo
|
||||
done
|
||||
|
||||
# check "$?" in condition gets its value from while body commands
|
||||
foo=""
|
||||
false
|
||||
while test "$?" != "0"
|
||||
do
|
||||
echo $foo
|
||||
foo="${foo}1"
|
||||
test "$foo" = "111111"
|
||||
done
|
|
@ -89,6 +89,12 @@ grub_script_execute_cmdfor (struct grub_script_cmd *cmd __attribute__ ((unused))
|
|||
return 0;
|
||||
}
|
||||
|
||||
grub_err_t
|
||||
grub_script_execute_cmdwhile (struct grub_script_cmd *cmd __attribute__ ((unused)))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
grub_err_t
|
||||
grub_script_execute_menuentry (struct grub_script_cmd *cmd __attribute__ ((unused)))
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue