FORALL_ACTIVE_TERM_OUTPUTS macro

This commit is contained in:
Vladimir 'phcoder' Serbinenko 2009-12-24 17:51:43 +01:00
parent 8eca55a6eb
commit 3be7f8de12
8 changed files with 106 additions and 121 deletions

View file

@ -39,10 +39,8 @@ 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)
FOR_ACTIVE_TERM_OUTPUTS(cur)
{
if (!grub_term_is_active (cur))
continue;
int width = grub_term_width(cur);
char description[width / 2];
@ -83,7 +81,11 @@ grub_cmd_help (grub_extcmd_t ext __attribute__ ((unused)), int argc,
}
if (argc == 0)
{
grub_command_iterate (print_command_info);
if (!(cnt % 2))
grub_printf ("\n");
}
else
{
int i;

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

View file

@ -69,8 +69,7 @@ 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))
FOR_ACTIVE_TERM_OUTPUTS(term)
grub_putcode (code, term);
}
if (ret == '\n' && grub_newline_hook)
@ -130,11 +129,8 @@ grub_cls (void)
{
struct grub_term_output *term;
for (term = grub_term_outputs; term; term = term->next)
FOR_ACTIVE_TERM_OUTPUTS(term)
{
if (! grub_term_is_active (term))
continue;
if ((term->flags & GRUB_TERM_DUMB) || (grub_env_get ("debug")))
{
grub_putcode ('\n', term);
@ -150,8 +146,7 @@ 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))
FOR_ACTIVE_TERM_OUTPUTS(term)
grub_term_setcolorstate (term, state);
}
@ -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))
FOR_ACTIVE_TERM_OUTPUTS(term)
grub_term_refresh (term);
}

View file

@ -363,16 +363,14 @@ 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))
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))
FOR_ACTIVE_TERM_OUTPUTS(cur)
{
cl_term_cur->term = cur;
init_clterm (cl_term_cur);

View file

@ -110,11 +110,8 @@ set_colors (void)
{
struct grub_term_output *term;
for (term = grub_term_outputs; term; term = term->next)
FOR_ACTIVE_TERM_OUTPUTS(term)
{
if (! grub_term_is_active (term))
continue;
/* Reloads terminal `normal' and `highlight' colors. */
grub_term_setcolor (term, color_normal, color_highlight);

View file

@ -520,10 +520,8 @@ grub_normal_reader_init (void)
grub_sprintf (msg_formatted, msg, reader_nested ? msg_esc : "");
for (term = grub_term_outputs; term; term = term->next)
FOR_ACTIVE_TERM_OUTPUTS(term)
{
if (! (term->flags & GRUB_TERM_ACTIVE))
continue;
grub_normal_init_page (term);
grub_term_setcursor (term, 1);

View file

@ -439,10 +439,8 @@ 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)
FOR_ACTIVE_TERM_OUTPUTS(term)
{
if (!grub_term_is_active (term))
continue;
instance = grub_zalloc (sizeof (*instance));
if (!instance)
{

View 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,8 +98,7 @@ 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))
FOR_ACTIVE_TERM_OUTPUTS(cur)
cnt++;
ret = grub_malloc (cnt * sizeof (ret[0]));
@ -107,8 +106,7 @@ grub_term_save_pos (void)
return NULL;
ptr = ret;
for (cur = grub_term_outputs; cur; cur = cur->next)
if (grub_term_is_active (cur))
FOR_ACTIVE_TERM_OUTPUTS(cur)
*ptr++ = grub_term_getxy (cur);
return ret;
@ -123,8 +121,7 @@ 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))
FOR_ACTIVE_TERM_OUTPUTS(cur)
{
grub_term_gotoxy (cur, (*ptr & 0xff00) >> 8, *ptr & 0xff);
ptr++;