Removed grub_putchar

This commit is contained in:
Vladimir 'phcoder' Serbinenko 2010-03-15 11:49:27 +01:00
parent 53f312c1cf
commit dfed5c6bb4
31 changed files with 241 additions and 219 deletions

View file

@ -53,7 +53,7 @@ grub_cmd_cat (grub_command_t cmd __attribute__ ((unused)),
unsigned char c = buf[i];
if ((grub_isprint (c) || grub_isspace (c)) && c != '\r')
grub_putchar (c);
grub_printf ("%c", c);
else
{
grub_setcolorstate (GRUB_TERM_COLOR_HIGHLIGHT);
@ -67,7 +67,7 @@ grub_cmd_cat (grub_command_t cmd __attribute__ ((unused)),
;
}
grub_putchar ('\n');
grub_xputs ("\n");
grub_refresh ();
grub_file_close (file);

View file

@ -36,7 +36,7 @@ grub_cmd_handler (struct grub_command *cmd __attribute__ ((unused)),
int list_item (grub_named_list_t item)
{
if (item == curr_item)
grub_putchar ('*');
grub_xputs ("*");
grub_printf ("%s\n", item->name);

View file

@ -57,7 +57,7 @@ grub_ls_list_devices (int longlist)
}
grub_device_iterate (grub_ls_print_devices);
grub_putchar ('\n');
grub_xputs ("\n");
grub_refresh ();
return 0;
@ -233,7 +233,7 @@ grub_ls_list_files (char *dirname, int longlist, int all, int human)
}
if (grub_errno == GRUB_ERR_NONE)
grub_putchar ('\n');
grub_xputs ("\n");
grub_refresh ();
}

View file

@ -54,7 +54,7 @@ grub_mini_cmd_cat (struct grub_command *cmd __attribute__ ((unused)),
unsigned char c = buf[i];
if ((grub_isprint (c) || grub_isspace (c)) && c != '\r')
grub_putchar (c);
grub_printf ("%c", c);
else
{
grub_setcolorstate (GRUB_TERM_COLOR_HIGHLIGHT);
@ -64,7 +64,7 @@ grub_mini_cmd_cat (struct grub_command *cmd __attribute__ ((unused)),
}
}
grub_putchar ('\n');
grub_xputs ("\n");
grub_refresh ();
grub_file_close (file);
@ -311,11 +311,11 @@ grub_mini_cmd_lsmod (struct grub_command *cmd __attribute__ ((unused)),
for (dep = mod->dep; dep; dep = dep->next)
{
if (dep != mod->dep)
grub_putchar (',');
grub_xputs (",");
grub_printf ("%s", dep->mod->name);
}
grub_putchar ('\n');
grub_xputs ("\n");
return 0;
}

View file

@ -47,7 +47,7 @@ grub_getline (void)
line[i] = c;
if (grub_isprint (c))
grub_putchar (c);
grub_printf ("%c", c);
i++;
tmp = grub_realloc (line, 1 + i + sizeof('\0'));
if (! tmp)

View file

@ -1315,7 +1315,7 @@ grub_font_construct_glyph (grub_font_t hinted_font,
/* Glyph not available in any font. Use ASCII fallback. */
if (!main_glyph)
main_glyph = ascii_glyph_lookup (code);
main_glyph = ascii_glyph_lookup (glyph_id->base);
/* Glyph not available in any font. Return unknown glyph. */
if (!main_glyph)

View file

@ -118,4 +118,10 @@ grub_is_valid_utf8 (const grub_uint8_t *src, grub_size_t srcsize);
int grub_utf8_to_ucs4_alloc (const char *msg, grub_uint32_t **unicode_msg,
grub_uint32_t **last_position);
grub_size_t grub_utf8_to_ucs4 (grub_uint32_t *dest,
grub_size_t destsize,
const grub_uint8_t *src,
grub_size_t srcsize,
const grub_uint8_t **srcend);
#endif

View file

@ -237,7 +237,19 @@ void *EXPORT_FUNC(grub_memset) (void *s, int c, grub_size_t n);
grub_size_t EXPORT_FUNC(grub_strlen) (const char *s);
int EXPORT_FUNC(grub_printf) (const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
int EXPORT_FUNC(grub_printf_) (const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
int EXPORT_FUNC(grub_puts) (const char *s);
extern void (*EXPORT_VAR (grub_xputs)) (const char *str);
static inline int
grub_puts (const char *s)
{
const char nl[2] = "\n";
grub_xputs (s);
grub_xputs (nl);
return 1; /* Cannot fail. */
}
int EXPORT_FUNC(grub_puts_) (const char *s);
void EXPORT_FUNC(grub_real_dprintf) (const char *file,
const int line,
@ -253,11 +265,6 @@ char *EXPORT_FUNC(grub_xasprintf) (const char *fmt, ...)
char *EXPORT_FUNC(grub_xvasprintf) (const char *fmt, va_list args);
void EXPORT_FUNC(grub_exit) (void) __attribute__ ((noreturn));
void EXPORT_FUNC(grub_abort) (void) __attribute__ ((noreturn));
grub_size_t EXPORT_FUNC(grub_utf8_to_ucs4) (grub_uint32_t *dest,
grub_size_t destsize,
const grub_uint8_t *src,
grub_size_t srcsize,
const grub_uint8_t **srcend);
grub_uint64_t EXPORT_FUNC(grub_divmod64) (grub_uint64_t n,
grub_uint32_t d, grub_uint32_t *r);

View file

@ -68,6 +68,17 @@ grub_term_color_state;
#define GRUB_TERM_NO_EDIT (1 << 1)
/* Set when the terminal cannot do fancy things. */
#define GRUB_TERM_DUMB (1 << 2)
/* Which encoding does terminal expect stream to be. */
#define GRUB_TERM_CODE_TYPE_MASK ((1 << 5) | (1 << 4) | (1 << 3))
/* Only ASCII characters accepted. */
#define GRUB_TERM_CODE_TYPE_ASCII 0
/* Expects VGA characters (ASCII + pseudographics). */
#define GRUB_TERM_CODE_TYPE_VGA (1 << 3)
/* UTF-8 stream in logical order. Usually used for terminals
which just forward the stream to another computer. */
#define GRUB_TERM_CODE_TYPE_UTF8_LOGICAL (1 << 4)
/* UCS-4 in visual order. */
#define GRUB_TERM_CODE_TYPE_UCS4_VISUAL ((1 << 4) | (1 << 3))
/* Bitmasks for modifier keys returned by grub_getkeystatus. */
@ -250,7 +261,6 @@ grub_term_unregister_output (grub_term_output_t term)
#define FOR_ACTIVE_TERM_OUTPUTS(var) for (var = grub_term_outputs; var; var = var->next)
#define FOR_DISABLED_TERM_OUTPUTS(var) for (var = grub_term_outputs_disabled; var; var = var->next)
void EXPORT_FUNC(grub_putchar) (int c);
void EXPORT_FUNC(grub_putcode) (grub_uint32_t code,
struct grub_term_output *term);
int EXPORT_FUNC(grub_getkey) (void);

View file

@ -121,7 +121,7 @@ grub_core_cmd_ls (struct grub_command *cmd __attribute__ ((unused)),
if (argc < 1)
{
grub_device_iterate (grub_mini_print_devices);
grub_putchar ('\n');
grub_xputs ("\n");
grub_refresh ();
}
else
@ -160,7 +160,7 @@ grub_core_cmd_ls (struct grub_command *cmd __attribute__ ((unused)),
else if (fs)
{
(fs->dir) (dev, path, grub_mini_print_files);
grub_putchar ('\n');
grub_xputs ("\n");
grub_refresh ();
}

View file

@ -142,19 +142,6 @@ grub_printf_ (const char *fmt, ...)
return ret;
}
int
grub_puts (const char *s)
{
while (*s)
{
grub_putchar (*s);
s++;
}
grub_putchar ('\n');
return 1; /* Cannot fail. */
}
int
grub_puts_ (const char *s)
{
@ -200,13 +187,37 @@ grub_real_dprintf (const char *file, const int line, const char *condition,
}
}
#define PREALLOC_SIZE 255
int
grub_vprintf (const char *fmt, va_list args)
{
int ret;
grub_size_t s;
static char buf[PREALLOC_SIZE + 1];
char *curbuf = buf;
ret = grub_vsnprintf_real (0, 0, fmt, args);
return ret;
s = grub_vsnprintf_real (buf, PREALLOC_SIZE, fmt, args);
if (s > PREALLOC_SIZE)
{
curbuf = grub_malloc (s + 1);
if (!curbuf)
{
grub_errno = GRUB_ERR_NONE;
buf[PREALLOC_SIZE - 3] = '.';
buf[PREALLOC_SIZE - 2] = '.';
buf[PREALLOC_SIZE - 1] = '.';
buf[PREALLOC_SIZE] = 0;
}
else
s = grub_vsnprintf_real (curbuf, s, fmt, args);
}
grub_xputs (curbuf);
if (curbuf != buf)
grub_free (curbuf);
return s;
}
int
@ -648,14 +659,9 @@ grub_vsnprintf_real (char *str, grub_size_t max_len, const char *fmt, va_list ar
auto void write_fill (const char ch, int n);
void write_char (unsigned char ch)
{
if (str)
{
if (count < max_len)
*str++ = ch;
}
else
grub_putchar (ch);
count++;
}
@ -872,7 +878,6 @@ grub_vsnprintf_real (char *str, grub_size_t max_len, const char *fmt, va_list ar
}
}
if (str)
*str = '\0';
return count;
@ -906,8 +911,6 @@ grub_snprintf (char *str, grub_size_t n, const char *fmt, ...)
return ret;
}
#define PREALLOC_SIZE 255
char *
grub_xvasprintf (const char *fmt, va_list ap)
{
@ -942,100 +945,6 @@ grub_xasprintf (const char *fmt, ...)
return ret;
}
/* Convert a (possibly null-terminated) UTF-8 string of at most SRCSIZE
bytes (if SRCSIZE is -1, it is ignored) in length to a UCS-4 string.
Return the number of characters converted. DEST must be able to hold
at least DESTSIZE characters.
If SRCEND is not NULL, then *SRCEND is set to the next byte after the
last byte used in SRC. */
grub_size_t
grub_utf8_to_ucs4 (grub_uint32_t *dest, grub_size_t destsize,
const grub_uint8_t *src, grub_size_t srcsize,
const grub_uint8_t **srcend)
{
grub_uint32_t *p = dest;
int count = 0;
grub_uint32_t code = 0;
if (srcend)
*srcend = src;
while (srcsize && destsize)
{
grub_uint32_t c = *src++;
if (srcsize != (grub_size_t)-1)
srcsize--;
if (count)
{
if ((c & 0xc0) != 0x80)
{
/* invalid */
code = '?';
/* Character c may be valid, don't eat it. */
src--;
if (srcsize != (grub_size_t)-1)
srcsize++;
count = 0;
}
else
{
code <<= 6;
code |= (c & 0x3f);
count--;
}
}
else
{
if (c == 0)
break;
if ((c & 0x80) == 0x00)
code = c;
else if ((c & 0xe0) == 0xc0)
{
count = 1;
code = c & 0x1f;
}
else if ((c & 0xf0) == 0xe0)
{
count = 2;
code = c & 0x0f;
}
else if ((c & 0xf8) == 0xf0)
{
count = 3;
code = c & 0x07;
}
else if ((c & 0xfc) == 0xf8)
{
count = 4;
code = c & 0x03;
}
else if ((c & 0xfe) == 0xfc)
{
count = 5;
code = c & 0x01;
}
else
{
/* invalid */
code = '?';
count = 0;
}
}
if (count == 0)
{
*p++ = code;
destsize--;
}
}
if (srcend)
*srcend = src;
return p - dest;
}
/* Abort GRUB. This function does not return. */
void
grub_abort (void)

View file

@ -34,6 +34,7 @@ grub_rescue_read_line (char **line, int cont)
{
int c;
int pos = 0;
char str[4];
grub_printf ((cont) ? "> " : "grub rescue> ");
grub_memset (linebuf, 0, GRUB_RESCUE_BUF_SIZE);
@ -44,24 +45,28 @@ grub_rescue_read_line (char **line, int cont)
{
if (pos < GRUB_RESCUE_BUF_SIZE - 1)
{
str[0] = c;
str[1] = 0;
linebuf[pos++] = c;
grub_putchar (c);
grub_xputs (str);
}
}
else if (c == '\b')
{
if (pos > 0)
{
str[0] = c;
str[1] = ' ';
str[2] = c;
str[3] = 0;
linebuf[--pos] = 0;
grub_putchar (c);
grub_putchar (' ');
grub_putchar (c);
grub_xputs (str);
}
}
grub_refresh ();
}
grub_putchar ('\n');
grub_xputs ("\n");
grub_refresh ();
*line = grub_strdup (linebuf);

View file

@ -50,31 +50,23 @@ grub_putcode (grub_uint32_t code, struct grub_term_output *term)
(term->putchar) ('\r');
}
/* Put a character. C is one byte of a UTF-8 stream.
This function gathers bytes until a valid Unicode character is found. */
void
grub_putchar (int c)
static void
grub_xputs_dumb (const char *str)
{
static grub_size_t size = 0;
static grub_uint8_t buf[6];
grub_uint8_t *rest;
grub_uint32_t code;
buf[size++] = c;
while (grub_utf8_to_ucs4 (&code, 1, buf, size, (const grub_uint8_t **) &rest)
!= 0)
for (; *str; str++)
{
struct grub_term_output *term;
size -= rest - buf;
grub_memmove (buf, rest, size);
grub_term_output_t term;
char c = *str;
if ((unsigned char) c > 0x7f)
c = '?';
FOR_ACTIVE_TERM_OUTPUTS(term)
grub_putcode (code, term);
if (code == '\n' && grub_newline_hook)
grub_newline_hook ();
grub_putcode (c, term);
}
}
void (*grub_xputs) (const char *str) = grub_xputs_dumb;
int
grub_getkey (void)
{

View file

@ -144,21 +144,8 @@ grub_arg_show_help (grub_extcmd_t cmd)
}
}
const char *doc = _(opt->doc);
for (;;)
{
while (spacing-- > 0)
grub_putchar (' ');
while (*doc && *doc != '\n')
grub_putchar (*doc++);
grub_putchar ('\n');
if (! *doc)
break;
doc++;
spacing = 4 + 20;
}
/* FIXME: add spacing back. */
grub_xputs (_(opt->doc));
switch (opt->shortarg)
{

View file

@ -267,3 +267,97 @@ grub_utf8_to_ucs4_alloc (const char *msg, grub_uint32_t **unicode_msg,
return msg_len;
}
/* Convert a (possibly null-terminated) UTF-8 string of at most SRCSIZE
bytes (if SRCSIZE is -1, it is ignored) in length to a UCS-4 string.
Return the number of characters converted. DEST must be able to hold
at least DESTSIZE characters.
If SRCEND is not NULL, then *SRCEND is set to the next byte after the
last byte used in SRC. */
grub_size_t
grub_utf8_to_ucs4 (grub_uint32_t *dest, grub_size_t destsize,
const grub_uint8_t *src, grub_size_t srcsize,
const grub_uint8_t **srcend)
{
grub_uint32_t *p = dest;
int count = 0;
grub_uint32_t code = 0;
if (srcend)
*srcend = src;
while (srcsize && destsize)
{
grub_uint32_t c = *src++;
if (srcsize != (grub_size_t)-1)
srcsize--;
if (count)
{
if ((c & 0xc0) != 0x80)
{
/* invalid */
code = '?';
/* Character c may be valid, don't eat it. */
src--;
if (srcsize != (grub_size_t)-1)
srcsize++;
count = 0;
}
else
{
code <<= 6;
code |= (c & 0x3f);
count--;
}
}
else
{
if (c == 0)
break;
if ((c & 0x80) == 0x00)
code = c;
else if ((c & 0xe0) == 0xc0)
{
count = 1;
code = c & 0x1f;
}
else if ((c & 0xf0) == 0xe0)
{
count = 2;
code = c & 0x0f;
}
else if ((c & 0xf8) == 0xf0)
{
count = 3;
code = c & 0x07;
}
else if ((c & 0xfc) == 0xf8)
{
count = 4;
code = c & 0x03;
}
else if ((c & 0xfe) == 0xfc)
{
count = 5;
code = c & 0x01;
}
else
{
/* invalid */
code = '?';
count = 0;
}
}
if (count == 0)
{
*p++ = code;
destsize--;
}
}
if (srcend)
*srcend = src;
return p - dest;
}

View file

@ -445,7 +445,7 @@ grub_password_get (char buf[], unsigned buf_size)
grub_memset (buf + cur_len, 0, buf_size - cur_len);
grub_putchar ('\n');
grub_xputs ("\n");
grub_refresh ();
return (key != '\e');

View file

@ -185,13 +185,13 @@ grub_username_get (char buf[], unsigned buf_size)
if (cur_len + 2 < buf_size)
{
buf[cur_len++] = key;
grub_putchar (key);
grub_printf ("%c", key);
}
}
grub_memset (buf + cur_len, 0, buf_size - cur_len);
grub_putchar ('\n');
grub_xputs ("\n");
grub_refresh ();
return (key != '\e');

View file

@ -614,7 +614,7 @@ grub_cmdline_get (const char *prompt)
grub_refresh ();
}
grub_putchar ('\n');
grub_xputs ("\n");
grub_refresh ();
/* Remove leading spaces. */

View file

@ -42,10 +42,10 @@ grub_err_t (*grub_gfxmenu_try_hook) (int entry, grub_menu_t menu,
void
grub_wait_after_message (void)
{
grub_putchar ('\n');
grub_xputs ("\n");
grub_printf_ (N_("Press any key to continue..."));
(void) grub_getkey ();
grub_putchar ('\n');
grub_xputs ("\n");
}
/* Get a menu entry by its index in the entry list. */

View file

@ -25,6 +25,7 @@
#include <grub/parser.h>
#include <grub/auth.h>
#include <grub/i18n.h>
#include <grub/charset.h>
enum update_mode
{
@ -1393,7 +1394,7 @@ grub_menu_entry_run (grub_menu_entry_t entry)
grub_cls ();
grub_print_error ();
grub_errno = GRUB_ERR_NONE;
grub_putchar ('\n');
grub_xputs ("\n");
grub_printf_ (N_("Press any key to continue..."));
(void) grub_getkey ();
}

View file

@ -191,7 +191,7 @@ command-line or ESC to return menu."), STANDARD_MARGIN, STANDARD_MARGIN,
(grub_uint32_t) GRUB_TERM_DISP_DOWN);
if (!msg_translated)
return;
grub_putchar ('\n');
grub_xputs ("\n");
grub_print_message_indented (msg_translated, STANDARD_MARGIN,
STANDARD_MARGIN, term);

View file

@ -37,14 +37,14 @@ grub_normal_print_device_info (const char *name)
p = grub_strchr (name, ',');
if (p)
{
grub_putchar ('\t');
grub_xputs ("\t");
grub_printf_ (N_("Partition %s:"), name);
grub_putchar (' ');
grub_xputs (" ");
}
else
{
grub_printf_ (N_("Device %s:"), name);
grub_putchar (' ');
grub_xputs (" ");
}
dev = grub_device_open (name);
@ -69,7 +69,7 @@ grub_normal_print_device_info (const char *name)
{
if (label && grub_strlen (label))
{
grub_putchar (' ');
grub_xputs (" ");
grub_printf_ (N_("- Label \"%s\""), label);
}
grub_free (label);
@ -84,7 +84,7 @@ grub_normal_print_device_info (const char *name)
if (grub_errno == GRUB_ERR_NONE)
{
grub_unixtime2datetime (tm, &datetime);
grub_putchar (' ');
grub_xputs (" ");
grub_printf_ (N_("- Last modification time %d-%02d-%02d "
"%02d:%02d:%02d %s"),
datetime.year, datetime.month, datetime.day,
@ -115,6 +115,6 @@ grub_normal_print_device_info (const char *name)
grub_device_close (dev);
}
grub_putchar ('\n');
grub_xputs ("\n");
return grub_errno;
}

View file

@ -23,6 +23,7 @@
#include <grub/dl.h>
#include <grub/env.h>
#include <grub/normal.h>
#include <grub/charset.h>
/* The amount of lines counted by the pager. */
static unsigned grub_more_lines;

View file

@ -840,7 +840,7 @@ grub_gfxterm_putchar (grub_uint32_t c)
/* If we are about to exceed line length, wrap to next line. */
if (virtual_screen.cursor_x + char_width > virtual_screen.columns)
grub_putchar ('\n');
grub_gfxterm_putchar ('\n');
/* Find position on virtual screen, and fill information. */
p = (virtual_screen.text_buffer +

View file

@ -334,7 +334,7 @@ grub_vga_putchar (grub_uint32_t c)
glyph = grub_font_get_glyph(font, c);
if (xpos + char_width > TEXT_WIDTH)
grub_putchar ('\n');
grub_vga_putchar ('\n');
p = text_buf + xpos + ypos * TEXT_WIDTH;
p->code = c;

View file

@ -388,8 +388,8 @@ grub_serial_putchar (grub_uint32_t c)
default:
if (xpos >= TEXT_WIDTH)
{
grub_putchar ('\r');
grub_putchar ('\n');
grub_serial_putchar ('\r');
grub_serial_putchar ('\n');
}
xpos++;
break;

View file

@ -34,12 +34,6 @@
#define DEFAULT_ENVBLK_SIZE 1024
void
grub_putchar (int c)
{
putchar (c);
}
void
grub_refresh (void)
{
@ -52,6 +46,14 @@ grub_getkey (void)
return 0;
}
void
grub_xputs_real (const char *str)
{
fputs (str, stdout);
}
void (*grub_xputs) (const char *str) = grub_xputs_real;
char *
grub_env_get (const char *name __attribute__ ((unused)))
{

View file

@ -44,11 +44,13 @@
#include "progname.h"
void
grub_putchar (int c)
grub_xputs_real (const char *str)
{
putchar (c);
fputs (str, stdout);
}
void (*grub_xputs) (const char *str) = grub_xputs_real;
int
grub_getkey (void)
{

View file

@ -59,11 +59,13 @@ int print = PRINT_FS;
static unsigned int argument_is_device = 0;
void
grub_putchar (int c)
grub_xputs_real (const char *str)
{
putchar (c);
fputs (str, stdout);
}
void (*grub_xputs) (const char *str) = grub_xputs_real;
int
grub_getkey (void)
{

View file

@ -40,11 +40,13 @@
#include "progname.h"
void
grub_putchar (int c)
grub_xputs_real (const char *str)
{
putchar (c);
fputs (str, stdout);
}
void (*grub_xputs) (const char *str) = grub_xputs_real;
int
grub_getkey (void)
{

View file

@ -58,11 +58,13 @@ static const grub_gpt_part_type_t grub_gpt_partition_type_bios_boot = GRUB_GPT_P
#define DEFAULT_CORE_FILE "core.img"
void
grub_putchar (int c)
grub_xputs_real (const char *str)
{
putchar (c);
fputs (str, stdout);
}
void (*grub_xputs) (const char *str) = grub_xputs_real;
int
grub_getkey (void)
{