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,22 +39,20 @@ grub_cmd_help (grub_extcmd_t ext __attribute__ ((unused)), int argc,
{ {
struct grub_term_output *cur; struct grub_term_output *cur;
int desclen = grub_strlen (cmd->summary); 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)) int width = grub_term_width(cur);
continue; char description[width / 2];
int width = grub_term_width(cur);
char description[width / 2];
/* Make a string with a length of GRUB_TERM_WIDTH / 2 - 1 filled /* Make a string with a length of GRUB_TERM_WIDTH / 2 - 1 filled
with the description followed by spaces. */ with the description followed by spaces. */
grub_memset (description, ' ', width / 2 - 1); grub_memset (description, ' ', width / 2 - 1);
description[width / 2 - 1] = '\0'; description[width / 2 - 1] = '\0';
grub_memcpy (description, cmd->summary, grub_memcpy (description, cmd->summary,
(desclen < width / 2 - 1 (desclen < width / 2 - 1
? desclen : width / 2 - 1)); ? desclen : width / 2 - 1));
grub_puts_terminal (description, cur); grub_puts_terminal (description, cur);
} }
if ((cnt++) % 2) if ((cnt++) % 2)
grub_printf ("\n"); grub_printf ("\n");
else else
@ -83,7 +81,11 @@ grub_cmd_help (grub_extcmd_t ext __attribute__ ((unused)), int argc,
} }
if (argc == 0) if (argc == 0)
grub_command_iterate (print_command_info); {
grub_command_iterate (print_command_info);
if (!(cnt % 2))
grub_printf ("\n");
}
else else
{ {
int i; 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_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_putchar) (int c);
void EXPORT_FUNC(grub_putcode) (grub_uint32_t code, void EXPORT_FUNC(grub_putcode) (grub_uint32_t code,

View file

@ -69,9 +69,8 @@ grub_putchar (int c)
{ {
struct grub_term_output *term; struct grub_term_output *term;
size = 0; size = 0;
for (term = grub_term_outputs; term; term = term->next) FOR_ACTIVE_TERM_OUTPUTS(term)
if (grub_term_is_active (term)) grub_putcode (code, term);
grub_putcode (code, term);
} }
if (ret == '\n' && grub_newline_hook) if (ret == '\n' && grub_newline_hook)
grub_newline_hook (); grub_newline_hook ();
@ -129,20 +128,17 @@ void
grub_cls (void) grub_cls (void)
{ {
struct grub_term_output *term; 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"))) FOR_ACTIVE_TERM_OUTPUTS(term)
{ {
grub_putcode ('\n', term); if ((term->flags & GRUB_TERM_DUMB) || (grub_env_get ("debug")))
grub_refresh (); {
} grub_putcode ('\n', term);
else grub_refresh ();
(term->cls) (); }
} else
(term->cls) ();
}
} }
void void
@ -150,9 +146,8 @@ grub_setcolorstate (grub_term_color_state state)
{ {
struct grub_term_output *term; 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)) grub_term_setcolorstate (term, state);
grub_term_setcolorstate (term, state);
} }
void void
@ -160,7 +155,6 @@ grub_refresh (void)
{ {
struct grub_term_output *term; 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)) grub_term_refresh (term);
grub_term_refresh (term);
} }

View file

@ -363,21 +363,19 @@ grub_cmdline_get (const char *prompt)
struct cmdline_term *cl_term_cur; struct cmdline_term *cl_term_cur;
struct grub_term_output *cur; struct grub_term_output *cur;
nterms = 0; nterms = 0;
for (cur = grub_term_outputs; cur; cur = cur->next) FOR_ACTIVE_TERM_OUTPUTS(cur)
if (grub_term_is_active (cur)) nterms++;
nterms++;
cl_terms = grub_malloc (sizeof (cl_terms[0]) * nterms); cl_terms = grub_malloc (sizeof (cl_terms[0]) * nterms);
if (!cl_terms) if (!cl_terms)
return 0; return 0;
cl_term_cur = cl_terms; cl_term_cur = cl_terms;
for (cur = grub_term_outputs; cur; cur = cur->next) FOR_ACTIVE_TERM_OUTPUTS(cur)
if (grub_term_is_active (cur)) {
{ cl_term_cur->term = cur;
cl_term_cur->term = cur; init_clterm (cl_term_cur);
init_clterm (cl_term_cur); cl_term_cur++;
cl_term_cur++; }
}
} }
if (hist_used == 0) if (hist_used == 0)

View file

@ -110,17 +110,14 @@ set_colors (void)
{ {
struct grub_term_output *term; 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)) /* Reloads terminal `normal' and `highlight' colors. */
continue; grub_term_setcolor (term, color_normal, color_highlight);
/* Reloads terminal `normal' and `highlight' colors. */ /* Propagates `normal' color to terminal current color. */
grub_term_setcolor (term, color_normal, color_highlight); grub_term_setcolorstate (term, GRUB_TERM_COLOR_NORMAL);
}
/* 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). */ /* Replace default `normal' colors with the ones specified by user (if any). */

View file

@ -520,16 +520,14 @@ grub_normal_reader_init (void)
grub_sprintf (msg_formatted, msg, reader_nested ? msg_esc : ""); 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)) grub_normal_init_page (term);
continue; grub_term_setcursor (term, 1);
grub_normal_init_page (term);
grub_term_setcursor (term, 1); grub_print_message_indented (msg_formatted, 3, STANDARD_MARGIN, term);
grub_puts ("\n");
grub_print_message_indented (msg_formatted, 3, STANDARD_MARGIN, term); }
grub_puts ("\n");
}
grub_free (msg_formatted); grub_free (msg_formatted);
return 0; return 0;

View 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_menu_viewer *instance;
struct grub_term_output *term; 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)) instance = grub_zalloc (sizeof (*instance));
if (!instance)
{
grub_print_error ();
grub_errno = GRUB_ERR_NONE;
continue; continue;
instance = grub_zalloc (sizeof (*instance)); }
if (!instance) data = grub_zalloc (sizeof (*data));
{ if (!data)
grub_print_error (); {
grub_errno = GRUB_ERR_NONE; grub_free (instance);
continue; grub_print_error ();
} grub_errno = GRUB_ERR_NONE;
data = grub_zalloc (sizeof (*data)); continue;
if (!data) }
{ data->term = term;
grub_free (instance); instance->data = data;
grub_print_error (); instance->set_chosen_entry = menu_text_set_chosen_entry;
grub_errno = GRUB_ERR_NONE; instance->print_timeout = menu_text_print_timeout;
continue; instance->clear_timeout = menu_text_clear_timeout;
} instance->fini = menu_text_fini;
data->term = term;
instance->data = data; data->menu = menu;
instance->set_chosen_entry = menu_text_set_chosen_entry;
instance->print_timeout = menu_text_print_timeout; data->offset = entry;
instance->clear_timeout = menu_text_clear_timeout; data->first = 0;
instance->fini = menu_text_fini; 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;
}
data->menu = menu; grub_term_setcursor (data->term, 0);
grub_menu_init_page (nested, 0, data->term);
data->offset = entry; print_entries (menu, data->first, data->offset, data->term);
data->first = 0; grub_term_refresh (data->term);
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);
}
} }

View file

@ -32,8 +32,8 @@ process_newline (void)
struct grub_term_output *cur; struct grub_term_output *cur;
unsigned height = -1; unsigned height = -1;
for (cur = grub_term_outputs; cur; cur = cur->next) FOR_ACTIVE_TERM_OUTPUTS(cur)
if (grub_term_is_active(cur) && grub_term_height (cur) < height) if (grub_term_height (cur) < height)
height = grub_term_height (cur); height = grub_term_height (cur);
grub_more_lines++; grub_more_lines++;
@ -98,18 +98,16 @@ grub_term_save_pos (void)
unsigned cnt = 0; unsigned cnt = 0;
grub_uint16_t *ret, *ptr; grub_uint16_t *ret, *ptr;
for (cur = grub_term_outputs; cur; cur = cur->next) FOR_ACTIVE_TERM_OUTPUTS(cur)
if (grub_term_is_active (cur)) cnt++;
cnt++;
ret = grub_malloc (cnt * sizeof (ret[0])); ret = grub_malloc (cnt * sizeof (ret[0]));
if (!ret) if (!ret)
return NULL; return NULL;
ptr = ret; ptr = ret;
for (cur = grub_term_outputs; cur; cur = cur->next) FOR_ACTIVE_TERM_OUTPUTS(cur)
if (grub_term_is_active (cur)) *ptr++ = grub_term_getxy (cur);
*ptr++ = grub_term_getxy (cur);
return ret; return ret;
} }
@ -123,10 +121,9 @@ grub_term_restore_pos (grub_uint16_t *pos)
if (!pos) if (!pos)
return; return;
for (cur = grub_term_outputs; cur; cur = cur->next) FOR_ACTIVE_TERM_OUTPUTS(cur)
if (grub_term_is_active (cur)) {
{ grub_term_gotoxy (cur, (*ptr & 0xff00) >> 8, *ptr & 0xff);
grub_term_gotoxy (cur, (*ptr & 0xff00) >> 8, *ptr & 0xff); ptr++;
ptr++; }
}
} }