]> git.proxmox.com Git - grub2.git/commitdiff
FORALL_ACTIVE_TERM_OUTPUTS macro
authorVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Thu, 24 Dec 2009 16:51:43 +0000 (17:51 +0100)
committerVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Thu, 24 Dec 2009 16:51:43 +0000 (17:51 +0100)
commands/help.c
include/grub/term.h
kern/term.c
normal/cmdline.c
normal/color.c
normal/main.c
normal/menu_text.c
normal/term.c

index 5e8f0b27a8e8c4cbb02655b5bbda06ca0a772cd0..bfca5e0cc1070b92a016a7312c258fff5ff1c92f 100644 (file)
@@ -39,22 +39,20 @@ grub_cmd_help (grub_extcmd_t ext __attribute__ ((unused)), int argc,
        {
          struct grub_term_output *cur;
          int desclen = grub_strlen (cmd->summary);
-         for (cur = grub_term_outputs; cur; cur = cur->next)
-           {
-             if (!grub_term_is_active (cur))
-               continue;
-             int width = grub_term_width(cur);
-             char description[width / 2];
+         FOR_ACTIVE_TERM_OUTPUTS(cur)
+         {
+           int width = grub_term_width(cur);
+           char description[width / 2];
 
-         /* Make a string with a length of GRUB_TERM_WIDTH / 2 - 1 filled
-            with the description followed by spaces.  */
-             grub_memset (description, ' ', width / 2 - 1);
-             description[width / 2 - 1] = '\0';
-             grub_memcpy (description, cmd->summary,
-                          (desclen < width / 2 - 1
-                           ? desclen : width / 2 - 1));
-             grub_puts_terminal (description, cur);
-           }
+           /* Make a string with a length of GRUB_TERM_WIDTH / 2 - 1 filled
+              with the description followed by spaces.  */
+           grub_memset (description, ' ', width / 2 - 1);
+           description[width / 2 - 1] = '\0';
+           grub_memcpy (description, cmd->summary,
+                        (desclen < width / 2 - 1
+                         ? desclen : width / 2 - 1));
+           grub_puts_terminal (description, cur);
+         }
          if ((cnt++) % 2)
            grub_printf ("\n");
          else
@@ -83,7 +81,11 @@ grub_cmd_help (grub_extcmd_t ext __attribute__ ((unused)), int argc,
     }
 
   if (argc == 0)
-    grub_command_iterate (print_command_info);
+    {
+      grub_command_iterate (print_command_info);
+      if (!(cnt % 2))
+       grub_printf ("\n");
+    }
   else
     {
       int i;
index fb9ed6f0c4d889d4654ec0ee0d5124ec44797f9c..bf6766af68e1b45634879a797652326cacf06a79 100644 (file)
@@ -227,6 +227,7 @@ grub_term_unregister_output (grub_term_output_t term)
 }
 
 #define FOR_ACTIVE_TERM_INPUTS(var) for (var = grub_term_inputs; var; var = var->next)
+#define FOR_ACTIVE_TERM_OUTPUTS(var) for (var = grub_term_outputs; var; var = var->next) if (grub_term_is_active (var))
 
 void EXPORT_FUNC(grub_putchar) (int c);
 void EXPORT_FUNC(grub_putcode) (grub_uint32_t code,
index 9ce906719277e0c4292b8f73b85f63e9d7cdef7c..dbcac1b1977f6fcb82116ee295b14d4355d2d4be 100644 (file)
@@ -69,9 +69,8 @@ grub_putchar (int c)
     {
       struct grub_term_output *term;
       size = 0;
-      for (term = grub_term_outputs; term; term = term->next)
-       if (grub_term_is_active (term))
-         grub_putcode (code, term);
+      FOR_ACTIVE_TERM_OUTPUTS(term)
+       grub_putcode (code, term);
     }
   if (ret == '\n' && grub_newline_hook)
     grub_newline_hook ();
@@ -129,20 +128,17 @@ void
 grub_cls (void)
 {
   struct grub_term_output *term;
-  
-  for (term = grub_term_outputs; term; term = term->next)
-    {
-      if (! grub_term_is_active (term))
-       continue;
-
-      if ((term->flags & GRUB_TERM_DUMB) || (grub_env_get ("debug")))
-       {
-         grub_putcode ('\n', term);
-         grub_refresh ();
-       }
-      else
-       (term->cls) ();
-    }
+
+  FOR_ACTIVE_TERM_OUTPUTS(term)  
+  {
+    if ((term->flags & GRUB_TERM_DUMB) || (grub_env_get ("debug")))
+      {
+       grub_putcode ('\n', term);
+       grub_refresh ();
+      }
+    else
+      (term->cls) ();
+  }
 }
 
 void
@@ -150,9 +146,8 @@ grub_setcolorstate (grub_term_color_state state)
 {
   struct grub_term_output *term;
   
-  for (term = grub_term_outputs; term; term = term->next)
-    if (grub_term_is_active (term))
-      grub_term_setcolorstate (term, state);
+  FOR_ACTIVE_TERM_OUTPUTS(term)
+    grub_term_setcolorstate (term, state);
 }
 
 void
@@ -160,7 +155,6 @@ grub_refresh (void)
 {
   struct grub_term_output *term;
 
-  for (term = grub_term_outputs; term; term = term->next)
-    if (grub_term_is_active (term))
-      grub_term_refresh (term);
+  FOR_ACTIVE_TERM_OUTPUTS(term)
+    grub_term_refresh (term);
 }
index 1412a6d6a64fccff6f8d586a6c06910ccd80a8e1..0f90fc2fe0cee2ef431a9c880f305b3e64331c1e 100644 (file)
@@ -363,21 +363,19 @@ grub_cmdline_get (const char *prompt)
     struct cmdline_term *cl_term_cur;
     struct grub_term_output *cur;
     nterms = 0;
-    for (cur = grub_term_outputs; cur; cur = cur->next)
-      if (grub_term_is_active (cur))
-       nterms++;
+    FOR_ACTIVE_TERM_OUTPUTS(cur)
+      nterms++;
 
     cl_terms = grub_malloc (sizeof (cl_terms[0]) * nterms);
     if (!cl_terms)
       return 0;
     cl_term_cur = cl_terms;
-    for (cur = grub_term_outputs; cur; cur = cur->next)
-      if (grub_term_is_active (cur))
-       {
-         cl_term_cur->term = cur;
-         init_clterm (cl_term_cur);
-         cl_term_cur++;
-       }
+    FOR_ACTIVE_TERM_OUTPUTS(cur)
+    {
+      cl_term_cur->term = cur;
+      init_clterm (cl_term_cur);
+      cl_term_cur++;
+    }
   }
 
   if (hist_used == 0)
index 80a285787e56739ffd05ec8236100e241c0a0941..bae082911603ca7e54255d122faacecc178afdda 100644 (file)
@@ -110,17 +110,14 @@ set_colors (void)
 {
   struct grub_term_output *term;
 
-  for (term = grub_term_outputs; term; term = term->next)
-    {
-      if (! grub_term_is_active (term))
-       continue;
-
-      /* Reloads terminal `normal' and `highlight' colors.  */
-      grub_term_setcolor (term, color_normal, color_highlight);
-
-      /* Propagates `normal' color to terminal current color.  */
-      grub_term_setcolorstate (term, GRUB_TERM_COLOR_NORMAL);
-    }
+  FOR_ACTIVE_TERM_OUTPUTS(term)
+  {
+    /* Reloads terminal `normal' and `highlight' colors.  */
+    grub_term_setcolor (term, color_normal, color_highlight);
+
+    /* Propagates `normal' color to terminal current color.  */
+    grub_term_setcolorstate (term, GRUB_TERM_COLOR_NORMAL);
+  }
 }
 
 /* Replace default `normal' colors with the ones specified by user (if any).  */
index b490f49e58670dffccfbb4736e41e80bc8333b3e..e1ffddae7e343afc70f495a69c19cacaa631eaa7 100644 (file)
@@ -520,16 +520,14 @@ grub_normal_reader_init (void)
 
   grub_sprintf (msg_formatted, msg, reader_nested ? msg_esc : "");
 
-  for (term = grub_term_outputs; term; term = term->next)
-    {
-      if (! (term->flags & GRUB_TERM_ACTIVE))
-       continue;
-      grub_normal_init_page (term);
-      grub_term_setcursor (term, 1);
-      
-      grub_print_message_indented (msg_formatted, 3, STANDARD_MARGIN, term);
-      grub_puts ("\n");
-    }
+  FOR_ACTIVE_TERM_OUTPUTS(term)
+  {
+    grub_normal_init_page (term);
+    grub_term_setcursor (term, 1);
+    
+    grub_print_message_indented (msg_formatted, 3, STANDARD_MARGIN, term);
+    grub_puts ("\n");
+  }
   grub_free (msg_formatted);
  
   return 0;
index edb315524545321a5a39989829cd68f74259a1ac..991a9ba4d85f276592888cab40130d1ed9f9bb08 100644 (file)
@@ -439,45 +439,43 @@ grub_menu_text_register_instances (int entry, grub_menu_t menu, int nested)
   struct grub_menu_viewer *instance;
   struct grub_term_output *term;
 
-  for (term = grub_term_outputs; term; term = term->next)
-    {
-      if (!grub_term_is_active (term))
+  FOR_ACTIVE_TERM_OUTPUTS(term)
+  {
+    instance = grub_zalloc (sizeof (*instance));
+    if (!instance)
+      {
+       grub_print_error ();
+       grub_errno = GRUB_ERR_NONE;
        continue;
-      instance = grub_zalloc (sizeof (*instance));
-      if (!instance)
-       {
-         grub_print_error ();
-         grub_errno = GRUB_ERR_NONE;
-         continue;
-       }
-      data = grub_zalloc (sizeof (*data));
-      if (!data)
-       {
-         grub_free (instance);
-         grub_print_error ();
-         grub_errno = GRUB_ERR_NONE;
-         continue;
-       }
-      data->term = term;
-      instance->data = data;
-      instance->set_chosen_entry = menu_text_set_chosen_entry;
-      instance->print_timeout = menu_text_print_timeout;
-      instance->clear_timeout = menu_text_clear_timeout;
-      instance->fini = menu_text_fini;
-
-      data->menu = menu;
-
-      data->offset = entry;
-      data->first = 0;
-      if (data->offset > grub_term_num_entries (data->term) - 1)
-       {
-         data->first = data->offset - (grub_term_num_entries (data->term) - 1);
-         data->offset = grub_term_num_entries (data->term) - 1;
-       }
-
-      grub_term_setcursor (data->term, 0);
-      grub_menu_init_page (nested, 0, data->term);
-      print_entries (menu, data->first, data->offset, data->term);
-      grub_term_refresh (data->term);
-    }
+      }
+    data = grub_zalloc (sizeof (*data));
+    if (!data)
+      {
+       grub_free (instance);
+       grub_print_error ();
+       grub_errno = GRUB_ERR_NONE;
+       continue;
+      }
+    data->term = term;
+    instance->data = data;
+    instance->set_chosen_entry = menu_text_set_chosen_entry;
+    instance->print_timeout = menu_text_print_timeout;
+    instance->clear_timeout = menu_text_clear_timeout;
+    instance->fini = menu_text_fini;
+    
+    data->menu = menu;
+    
+    data->offset = entry;
+    data->first = 0;
+    if (data->offset > grub_term_num_entries (data->term) - 1)
+      {
+       data->first = data->offset - (grub_term_num_entries (data->term) - 1);
+       data->offset = grub_term_num_entries (data->term) - 1;
+      }
+
+    grub_term_setcursor (data->term, 0);
+    grub_menu_init_page (nested, 0, data->term);
+    print_entries (menu, data->first, data->offset, data->term);
+    grub_term_refresh (data->term);
+  }
 }
index ff5120d48e54ddd1a2c338de72b1db215e70441b..eb8f8e8440d73e3416a930e707e13d2f56c8b73a 100644 (file)
@@ -32,8 +32,8 @@ process_newline (void)
   struct grub_term_output *cur;
   unsigned height = -1;
 
-  for (cur = grub_term_outputs; cur; cur = cur->next)
-    if (grub_term_is_active(cur) && grub_term_height (cur) < height)
+  FOR_ACTIVE_TERM_OUTPUTS(cur)
+    if (grub_term_height (cur) < height)
       height = grub_term_height (cur);
   grub_more_lines++;
 
@@ -98,18 +98,16 @@ grub_term_save_pos (void)
   unsigned cnt = 0;
   grub_uint16_t *ret, *ptr;
   
-  for (cur = grub_term_outputs; cur; cur = cur->next)
-    if (grub_term_is_active (cur))
-      cnt++;
+  FOR_ACTIVE_TERM_OUTPUTS(cur)
+    cnt++;
 
   ret = grub_malloc (cnt * sizeof (ret[0]));
   if (!ret)
     return NULL;
 
   ptr = ret;
-  for (cur = grub_term_outputs; cur; cur = cur->next)
-    if (grub_term_is_active (cur))
-      *ptr++ = grub_term_getxy (cur);
+  FOR_ACTIVE_TERM_OUTPUTS(cur)
+    *ptr++ = grub_term_getxy (cur);
 
   return ret;
 }
@@ -123,10 +121,9 @@ grub_term_restore_pos (grub_uint16_t *pos)
   if (!pos)
     return;
 
-  for (cur = grub_term_outputs; cur; cur = cur->next)
-    if (grub_term_is_active (cur))
-      {
-       grub_term_gotoxy (cur, (*ptr & 0xff00) >> 8, *ptr & 0xff);
-       ptr++;
-      }
+  FOR_ACTIVE_TERM_OUTPUTS(cur)
+  {
+    grub_term_gotoxy (cur, (*ptr & 0xff00) >> 8, *ptr & 0xff);
+    ptr++;
+  }
 }