merge mainline into bidi

This commit is contained in:
Vladimir 'phcoder' Serbinenko 2010-04-09 19:40:31 +02:00
commit a87add6d17
10 changed files with 501 additions and 278 deletions

View file

@ -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

View file

@ -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

View file

@ -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;
@ -176,9 +175,9 @@ grub_font_loader_init (void)
return;
/* Make glyph for unknown glyph. */
unknown_glyph = grub_malloc(sizeof(struct grub_font_glyph)
+ sizeof(unknown_glyph_bitmap));
if (! unknown_glyph)
unknown_glyph = grub_malloc (sizeof (struct grub_font_glyph)
+ sizeof (unknown_glyph_bitmap));
if (!unknown_glyph)
return;
unknown_glyph->width = 8;
@ -186,13 +185,13 @@ grub_font_loader_init (void)
unknown_glyph->offset_x = 0;
unknown_glyph->offset_y = -3;
unknown_glyph->device_width = 8;
grub_memcpy(unknown_glyph->bitmap,
unknown_glyph_bitmap, sizeof(unknown_glyph_bitmap));
grub_memcpy (unknown_glyph->bitmap,
unknown_glyph_bitmap, sizeof (unknown_glyph_bitmap));
/* Initialize the null font. */
font_init (&null_font);
null_font.name = "<No Font>";
null_font.ascent = unknown_glyph->height-3;
null_font.ascent = unknown_glyph->height - 3;
null_font.descent = 3;
null_font.max_char_width = unknown_glyph->width;
null_font.max_char_height = unknown_glyph->height;
@ -292,7 +291,7 @@ load_font_index (grub_file_t file, grub_uint32_t sect_length, struct
grub_uint32_t last_code;
#if FONT_DEBUG >= 2
grub_printf("load_font_index(sect_length=%d)\n", sect_length);
grub_printf ("load_font_index(sect_length=%d)\n", sect_length);
#endif
/* Sanity check: ensure section length is divisible by the entry size. */
@ -311,10 +310,10 @@ load_font_index (grub_file_t file, grub_uint32_t sect_length, struct
/* Allocate the character index array. */
font->char_index = grub_malloc (font->num_chars
* sizeof (struct char_index_entry));
if (! font->char_index)
if (!font->char_index)
return 1;
font->bmp_idx = grub_malloc (0x10000 * sizeof (grub_uint16_t));
if (! font->bmp_idx)
if (!font->bmp_idx)
{
grub_free (font->char_index);
return 1;
@ -323,7 +322,7 @@ load_font_index (grub_file_t file, grub_uint32_t sect_length, struct
#if FONT_DEBUG >= 2
grub_printf("num_chars=%d)\n", font->num_chars);
grub_printf ("num_chars=%d)\n", font->num_chars);
#endif
last_code = 0;
@ -367,7 +366,7 @@ load_font_index (grub_file_t file, grub_uint32_t sect_length, struct
#if FONT_DEBUG >= 5
/* Print the 1st 10 characters. */
if (i < 10)
grub_printf("c=%d o=%d\n", entry->code, entry->offset);
grub_printf ("c=%d o=%d\n", entry->code, entry->offset);
#endif
}
@ -383,7 +382,7 @@ read_section_as_string (struct font_file_section *section)
grub_ssize_t ret;
str = grub_malloc (section->length + 1);
if (! str)
if (!str)
return 0;
ret = grub_file_read (section->file, str, section->length);
@ -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)
@ -433,7 +432,7 @@ grub_font_load (const char *filename)
grub_font_t font = 0;
#if FONT_DEBUG >= 1
grub_printf("add_font(%s)\n", filename);
grub_printf ("add_font(%s)\n", filename);
#endif
file = grub_buffile_open (filename, 1024);
@ -441,7 +440,7 @@ grub_font_load (const char *filename)
goto fail;
#if FONT_DEBUG >= 3
grub_printf("file opened\n");
grub_printf ("file opened\n");
#endif
/* Read the FILE section. It indicates the file format. */
@ -449,10 +448,10 @@ grub_font_load (const char *filename)
goto fail;
#if FONT_DEBUG >= 3
grub_printf("opened FILE section\n");
grub_printf ("opened FILE section\n");
#endif
if (grub_memcmp (section.name, FONT_FORMAT_SECTION_NAMES_FILE,
sizeof(FONT_FORMAT_SECTION_NAMES_FILE) - 1) != 0)
sizeof (FONT_FORMAT_SECTION_NAMES_FILE) - 1) != 0)
{
grub_error (GRUB_ERR_BAD_FONT,
"font file format error: 1st section must be FILE");
@ -460,7 +459,7 @@ grub_font_load (const char *filename)
}
#if FONT_DEBUG >= 3
grub_printf("section name ok\n");
grub_printf ("section name ok\n");
#endif
if (section.length != 4)
{
@ -471,14 +470,14 @@ grub_font_load (const char *filename)
}
#if FONT_DEBUG >= 3
grub_printf("section length ok\n");
grub_printf ("section length ok\n");
#endif
/* Check the file format type code. */
if (grub_file_read (file, magic, 4) != 4)
goto fail;
#if FONT_DEBUG >= 3
grub_printf("read magic ok\n");
grub_printf ("read magic ok\n");
#endif
if (grub_memcmp (magic, FONT_FORMAT_PFF2_MAGIC, 4) != 0)
@ -489,19 +488,19 @@ grub_font_load (const char *filename)
}
#if FONT_DEBUG >= 3
grub_printf("compare magic ok\n");
grub_printf ("compare magic ok\n");
#endif
/* Allocate the font object. */
font = (grub_font_t) grub_malloc (sizeof (struct grub_font));
if (! font)
if (!font)
goto fail;
font_init (font);
font->file = file;
#if FONT_DEBUG >= 3
grub_printf("allocate font ok; loading font info\n");
grub_printf ("allocate font ok; loading font info\n");
#endif
/* Load the font information. */
@ -516,13 +515,13 @@ grub_font_load (const char *filename)
}
#if FONT_DEBUG >= 2
grub_printf("opened section %c%c%c%c ok\n",
grub_printf ("opened section %c%c%c%c ok\n",
section.name[0], section.name[1],
section.name[2], section.name[3]);
#endif
if (grub_memcmp (section.name, FONT_FORMAT_SECTION_NAMES_FONT_NAME,
sizeof(FONT_FORMAT_SECTION_NAMES_FONT_NAME) - 1) == 0)
sizeof (FONT_FORMAT_SECTION_NAMES_FONT_NAME) - 1) == 0)
{
font->name = read_section_as_string (&section);
if (!font->name)
@ -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 (&section, &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 (&section);
@ -551,40 +552,45 @@ 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 (&section, &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 (&section, &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 (&section, &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 (&section, &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;
}
else if (grub_memcmp (section.name, FONT_FORMAT_SECTION_NAMES_DATA,
sizeof(FONT_FORMAT_SECTION_NAMES_DATA) - 1) == 0)
sizeof (FONT_FORMAT_SECTION_NAMES_DATA) - 1) == 0)
{
/* When the DATA section marker is reached, we stop reading. */
break;
@ -593,7 +599,7 @@ grub_font_load (const char *filename)
{
/* Unhandled section type, simply skip past it. */
#if FONT_DEBUG >= 3
grub_printf("Unhandled section type, skipping.\n");
grub_printf ("Unhandled section type, skipping.\n");
#endif
grub_off_t section_end = grub_file_tell (file) + section.length;
if ((int) grub_file_seek (file, section_end) == -1)
@ -601,7 +607,7 @@ grub_font_load (const char *filename)
}
}
if (! font->name)
if (!font->name)
{
grub_printf ("Note: Font has no name.\n");
font->name = grub_strdup ("Unknown");
@ -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");
@ -682,7 +685,7 @@ find_glyph (const grub_font_t font, grub_uint32_t code)
lo = 0;
hi = font->num_chars - 1;
if (! table)
if (!table)
return 0;
while (lo <= hi)
@ -722,7 +725,7 @@ grub_font_get_glyph_internal (grub_font_t font, grub_uint32_t code)
/* Return cached glyph. */
return index_entry->glyph;
if (! font->file)
if (!font->file)
/* No open file, can't load any glyphs. */
return 0;
@ -733,11 +736,11 @@ grub_font_get_glyph_internal (grub_font_t font, grub_uint32_t code)
grub_file_seek (font->file, index_entry->offset);
/* Read the glyph width, height, and baseline. */
if (read_be_uint16(font->file, &width) != 0
|| read_be_uint16(font->file, &height) != 0
|| read_be_int16(font->file, &xoff) != 0
|| read_be_int16(font->file, &yoff) != 0
|| read_be_int16(font->file, &dwidth) != 0)
if (read_be_uint16 (font->file, &width) != 0
|| read_be_uint16 (font->file, &height) != 0
|| read_be_int16 (font->file, &xoff) != 0
|| read_be_int16 (font->file, &yoff) != 0
|| read_be_int16 (font->file, &dwidth) != 0)
{
remove_font (font);
return 0;
@ -745,7 +748,7 @@ grub_font_get_glyph_internal (grub_font_t font, grub_uint32_t code)
len = (width * height + 7) / 8;
glyph = grub_malloc (sizeof (struct grub_font_glyph) + len);
if (! glyph)
if (!glyph)
{
remove_font (font);
return 0;
@ -807,7 +810,7 @@ register_font (grub_font_t font)
struct grub_font_node *node = 0;
node = grub_malloc (sizeof (struct grub_font_node));
if (! node)
if (!node)
return 1;
node->value = font;
@ -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)
{
@ -950,7 +952,7 @@ grub_font_get_glyph (grub_font_t font, grub_uint32_t code)
sizes are used so that tiny 8 point glyphs are not mixed into a string
of 24 point text unless there is no other choice. */
static int
get_font_diversity(grub_font_t a, grub_font_t b)
get_font_diversity (grub_font_t a, grub_font_t b)
{
int d;
@ -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)
{
@ -1197,7 +1197,7 @@ blit_comb (const struct grub_unicode_glyph *glyph_id,
do_blit (combining_glyphs[i],
targetx,
(bounds.height - combining_glyphs[i]->height) / 2
-(bounds.height + bounds.y));
- (bounds.height + bounds.y));
if (min_devwidth < combining_glyphs[i]->width)
min_devwidth = combining_glyphs[i]->width;
break;
@ -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;
@ -1332,14 +1334,15 @@ blit_comb (const struct grub_unicode_glyph *glyph_id,
do_blit (combining_glyphs[i],
main_glyph->device_width
+ combining_glyphs[i]->offset_x,
- (combining_glyphs[i]->height
-(combining_glyphs[i]->height
+ combining_glyphs[i]->offset_y));
add_device_width (combining_glyphs[i]->device_width);
}
}
}
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,
@ -1480,9 +1487,8 @@ grub_font_construct_glyph (grub_font_t hinted_font,
baseline of the character, while the x coordinate designates the left
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_font_draw_glyph (struct grub_font_glyph * glyph,
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;
@ -1509,7 +1514,7 @@ grub_font_draw_glyph (struct grub_font_glyph *glyph,
glyph_bitmap.mode_info.bg_green = 0;
glyph_bitmap.mode_info.bg_blue = 0;
glyph_bitmap.mode_info.bg_alpha = 0;
grub_video_unmap_color(color,
grub_video_unmap_color (color,
&glyph_bitmap.mode_info.fg_red,
&glyph_bitmap.mode_info.fg_green,
&glyph_bitmap.mode_info.fg_blue,
@ -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);
}

View file

@ -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. */

View file

@ -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)

View file

@ -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);
}
;

View file

@ -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
View 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

View 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

View file

@ -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)))
{