]> git.proxmox.com Git - grub2.git/commitdiff
Remove nested functions from videoinfo iterators.
authorVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Fri, 1 Mar 2013 10:11:36 +0000 (11:11 +0100)
committerVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Fri, 1 Mar 2013 10:11:36 +0000 (11:11 +0100)
ChangeLog
grub-core/commands/videoinfo.c
grub-core/video/efi_gop.c
grub-core/video/i386/pc/vbe.c
include/grub/video.h

index 3ca1fed349dd242a4da85e8922d08f0b5d4a1690..7f5bcfab3ff0b692deb3b348c98a3adba9cc30c6 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -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
index 4a11576154d996f6ecc8ee34d6562f6a14d94164..7a75c9d5a92b543184647f2176dbe14461cb52af 100644 (file)
 
 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)
       {
index 37a0015c2fa72450befbc1e5e096a5d9e96bf625..f73a278b70a1c01f6a36a73f3d5cb51e54a166c3 100644 (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;
index 81e5a8e94618c99870166870d25895ee75bf94a4..e8a8c7aa8b1bf574609691a3429c7a134185915f 100644 (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;
index 08f730091da50a051f13f250054bb69aaa8fc878..9fe4783162670eb733208d42cf801a079e0cc845 100644 (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);