Remove nested functions from videoinfo iterators.

This commit is contained in:
Vladimir 'phcoder' Serbinenko 2013-03-01 11:11:36 +01:00
parent e230377407
commit 3056d3e752
5 changed files with 39 additions and 28 deletions

View File

@ -1,3 +1,7 @@
2013-03-01 Vladimir Serbinenko <phcoder@gmail.com>
Remove nested functions from videoinfo iterators.
2013-03-01 Vladimir Serbinenko <phcoder@gmail.com>
* grub-core/loader/i386/pc/linux.c (grub_cmd_linux): Fix compilation

View File

@ -27,23 +27,28 @@
GRUB_MOD_LICENSE ("GPLv3+");
static unsigned height, width, depth;
static struct grub_video_mode_info *current_mode;
struct hook_ctx
{
unsigned height, width, depth;
struct grub_video_mode_info *current_mode;
};
static int
hook (const struct grub_video_mode_info *info)
hook (const struct grub_video_mode_info *info, void *hook_arg)
{
if (height && width && (info->width != width || info->height != height))
struct hook_ctx *ctx = hook_arg;
if (ctx->height && ctx->width && (info->width != ctx->width || info->height != ctx->height))
return 0;
if (depth && info->bpp != depth)
if (ctx->depth && info->bpp != ctx->depth)
return 0;
if (info->mode_number == GRUB_VIDEO_MODE_NUMBER_INVALID)
grub_printf (" ");
else
{
if (current_mode && info->mode_number == current_mode->mode_number)
if (ctx->current_mode && info->mode_number == ctx->current_mode->mode_number)
grub_printf ("*");
else
grub_printf (" ");
@ -126,13 +131,14 @@ grub_cmd_videoinfo (grub_command_t cmd __attribute__ ((unused)),
{
grub_video_adapter_t adapter;
grub_video_driver_id_t id;
struct hook_ctx ctx;
height = width = depth = 0;
ctx.height = ctx.width = ctx.depth = 0;
if (argc)
{
char *ptr;
ptr = args[0];
width = grub_strtoul (ptr, &ptr, 0);
ctx.width = grub_strtoul (ptr, &ptr, 0);
if (grub_errno)
return grub_errno;
if (*ptr != 'x')
@ -140,13 +146,13 @@ grub_cmd_videoinfo (grub_command_t cmd __attribute__ ((unused)),
N_("invalid video mode specification `%s'"),
args[0]);
ptr++;
height = grub_strtoul (ptr, &ptr, 0);
ctx.height = grub_strtoul (ptr, &ptr, 0);
if (grub_errno)
return grub_errno;
if (*ptr == 'x')
{
ptr++;
depth = grub_strtoul (ptr, &ptr, 0);
ctx.depth = grub_strtoul (ptr, &ptr, 0);
if (grub_errno)
return grub_errno;
}
@ -175,12 +181,12 @@ grub_cmd_videoinfo (grub_command_t cmd __attribute__ ((unused)),
continue;
}
current_mode = NULL;
ctx.current_mode = NULL;
if (adapter->id == id)
{
if (grub_video_get_info (&info) == GRUB_ERR_NONE)
current_mode = &info;
ctx.current_mode = &info;
else
/* Don't worry about errors. */
grub_errno = GRUB_ERR_NONE;
@ -198,14 +204,14 @@ grub_cmd_videoinfo (grub_command_t cmd __attribute__ ((unused)),
if (adapter->print_adapter_specific_info)
adapter->print_adapter_specific_info ();
adapter->iterate (hook);
adapter->iterate (hook, &ctx);
if (adapter->get_edid && adapter->get_edid (&edid_info) == GRUB_ERR_NONE)
print_edid (&edid_info);
else
grub_errno = GRUB_ERR_NONE;
current_mode = NULL;
ctx.current_mode = NULL;
if (adapter->id != id)
{

View File

@ -42,7 +42,7 @@ static int restore_needed;
static grub_efi_handle_t gop_handle;
static int
grub_video_gop_iterate (int (*hook) (const struct grub_video_mode_info *info));
grub_video_gop_iterate (int (*hook) (const struct grub_video_mode_info *info, void *hook_arg), void *hook_arg);
static struct
{
@ -52,6 +52,14 @@ static struct
grub_uint8_t *offscreen;
} framebuffer;
static int
check_protocol_hook (const struct grub_video_mode_info *info __attribute__ ((unused)), void *hook_arg)
{
int *have_usable_mode = hook_arg;
*have_usable_mode = 1;
return 1;
}
static int
check_protocol (void)
@ -60,13 +68,6 @@ check_protocol (void)
grub_efi_uintn_t num_handles, i;
int have_usable_mode = 0;
auto int hook (const struct grub_video_mode_info *info);
int hook (const struct grub_video_mode_info *info __attribute__ ((unused)))
{
have_usable_mode = 1;
return 1;
}
handles = grub_efi_locate_handle (GRUB_EFI_BY_PROTOCOL,
&graphics_output_guid, NULL, &num_handles);
if (!handles || num_handles == 0)
@ -77,7 +78,7 @@ check_protocol (void)
gop_handle = handles[i];
gop = grub_efi_open_protocol (gop_handle, &graphics_output_guid,
GRUB_EFI_OPEN_PROTOCOL_GET_PROTOCOL);
grub_video_gop_iterate (hook);
grub_video_gop_iterate (check_protocol_hook, &have_usable_mode);
if (have_usable_mode)
{
grub_free (handles);
@ -256,7 +257,7 @@ grub_video_gop_fill_mode_info (unsigned mode,
}
static int
grub_video_gop_iterate (int (*hook) (const struct grub_video_mode_info *info))
grub_video_gop_iterate (int (*hook) (const struct grub_video_mode_info *info, void *hook_arg), void *hook_arg)
{
unsigned mode;
@ -282,7 +283,7 @@ grub_video_gop_iterate (int (*hook) (const struct grub_video_mode_info *info))
grub_errno = GRUB_ERR_NONE;
continue;
}
if (hook (&mode_info))
if (hook (&mode_info, hook_arg))
return 1;
}
return 0;

View File

@ -952,7 +952,7 @@ vbe2videoinfo (grub_uint32_t mode,
}
static int
grub_video_vbe_iterate (int (*hook) (const struct grub_video_mode_info *info))
grub_video_vbe_iterate (int (*hook) (const struct grub_video_mode_info *info, void *hook_arg), void *hook_arg)
{
grub_uint16_t *p;
struct grub_vbe_mode_info_block vbe_mode_info;
@ -969,7 +969,7 @@ grub_video_vbe_iterate (int (*hook) (const struct grub_video_mode_info *info))
}
vbe2videoinfo (*p, &vbe_mode_info, &mode_info);
if (hook (&mode_info))
if (hook (&mode_info, hook_arg))
return 1;
}
return 0;

View File

@ -372,7 +372,7 @@ struct grub_video_adapter
grub_err_t (*get_active_render_target) (struct grub_video_render_target **target);
int (*iterate) (int (*hook) (const struct grub_video_mode_info *info));
int (*iterate) (int (*hook) (const struct grub_video_mode_info *info, void *hook_arg), void *hook_arg);
grub_err_t (*get_edid) (struct grub_video_edid_info *edid_info);