From: Vladimir Serbinenko Date: Mon, 28 Oct 2013 16:42:40 +0000 (+0100) Subject: Several fixes X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fheads%2Fphcoder%2Fbrltty;p=thirdparty%2Fgrub.git Several fixes --- diff --git a/configure.ac b/configure.ac index 209173a6c..98f281e11 100644 --- a/configure.ac +++ b/configure.ac @@ -85,7 +85,7 @@ HOST_CPPFLAGS="$HOST_CPPFLAGS -DLOCALEDIR=\\\"\$(localedir)\\\"" TARGET_CPPFLAGS="$TARGET_CPPFLAGS -Wall -W" TARGET_CPPFLAGS="$TARGET_CPPFLAGS -I\$(top_srcdir)/include" TARGET_CPPFLAGS="$TARGET_CPPFLAGS -I\$(top_builddir)/include" -TARGET_CPPFLAGS="$TARGET_CPPFLAGS -Dfloat=__float__bug__ -Ddouble=__double__bug__ -DGRUB_RUNTIME=1" +TARGET_CPPFLAGS="$TARGET_CPPFLAGS -DGRUB_RUNTIME=1" case "$target_cpu" in i[[3456]]86) target_cpu=i386 ;; diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index f45e90e58..c2f6ea5bf 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -642,8 +642,8 @@ module = { name = regexp; common = commands/regexp.c; common = commands/wildcard.c; - ldadd = libgnulib.a; - dependencies = libgnulib.a; + ldadd = libregexp.a; + dependencies = libregexp.a; cflags = '$(CFLAGS_POSIX) $(CFLAGS_GNULIB)'; cppflags = '$(CPPFLAGS_POSIX) $(CPPFLAGS_GNULIB)'; }; @@ -835,7 +835,7 @@ module = { name = verify; common = commands/verify.c; cflags = '$(CFLAGS_POSIX)'; - cppflags = '-I$(srcdir)/lib/posix_wrap'; + cppflags = '-I$(srcdir)/lib/posix_wrap/include'; }; module = { diff --git a/grub-core/commands/help.c b/grub-core/commands/help.c index a04489daa..f0be89baa 100644 --- a/grub-core/commands/help.c +++ b/grub-core/commands/help.c @@ -45,8 +45,8 @@ grub_cmd_help (grub_extcmd_context_t ctxt __attribute__ ((unused)), int argc, struct grub_term_output *term; const char *summary_translated = _(cmd->summary); char *command_help; - grub_wchar_t *unicode_command_help; - grub_wchar_t *unicode_last_position; + grub_uint32_t *unicode_command_help; + grub_uint32_t *unicode_last_position; command_help = grub_xasprintf ("%s %s", cmd->name, summary_translated); if (!command_help) @@ -58,7 +58,7 @@ grub_cmd_help (grub_extcmd_context_t ctxt __attribute__ ((unused)), int argc, FOR_ACTIVE_TERM_OUTPUTS(term) { unsigned stringwidth; - grub_wchar_t *unicode_last_screen_position; + grub_uint32_t *unicode_last_screen_position; unicode_last_screen_position = unicode_command_help; diff --git a/grub-core/gettext/gettext.c b/grub-core/gettext/gettext.c index 8e70185a1..dca33e9ed 100644 --- a/grub-core/gettext/gettext.c +++ b/grub-core/gettext/gettext.c @@ -554,7 +554,6 @@ GRUB_MOD_INIT (gettext) COMPILE_TIME_ASSERT (ARRAY_SIZE (domains) == CONTEXT_CNT); for (i = 0; i < ARRAY_SIZE (domains); i++) { - grub_err_t err; err = grub_gettext_init_ext (&main_context[i], lang, grub_env_get ("locale_dir"), grub_env_get ("prefix"), domains[i]); diff --git a/grub-core/gfxmenu/font.c b/grub-core/gfxmenu/font.c index b76f61f1e..64d52670b 100644 --- a/grub-core/gfxmenu/font.c +++ b/grub-core/gfxmenu/font.c @@ -42,7 +42,7 @@ grub_font_draw_string (const char *str, grub_font_t font, int left_x, int baseline_y) { int x; - grub_wchar_t *logical; + grub_uint32_t *logical; grub_ssize_t logical_len, visual_len; struct grub_unicode_glyph *visual, *ptr; @@ -83,9 +83,9 @@ int grub_font_get_string_width (grub_font_t font, const char *str) { int width = 0; - grub_wchar_t *ptr; + grub_uint32_t *ptr; grub_ssize_t logical_len; - grub_wchar_t *logical; + grub_uint32_t *logical; logical_len = grub_utf8_to_ucs4_alloc (str, &logical, 0); if (logical_len < 0) diff --git a/grub-core/lib/posix_wrap/assert.h b/grub-core/lib/posix_wrap/include/assert.h similarity index 100% rename from grub-core/lib/posix_wrap/assert.h rename to grub-core/lib/posix_wrap/include/assert.h diff --git a/grub-core/lib/posix_wrap/ctype.h b/grub-core/lib/posix_wrap/include/ctype.h similarity index 100% rename from grub-core/lib/posix_wrap/ctype.h rename to grub-core/lib/posix_wrap/include/ctype.h diff --git a/grub-core/lib/posix_wrap/errno.h b/grub-core/lib/posix_wrap/include/errno.h similarity index 95% rename from grub-core/lib/posix_wrap/errno.h rename to grub-core/lib/posix_wrap/include/errno.h index b40203df1..6015e92e9 100644 --- a/grub-core/lib/posix_wrap/errno.h +++ b/grub-core/lib/posix_wrap/include/errno.h @@ -25,14 +25,14 @@ #define errno grub_posix_errno #define EINVAL GRUB_ERR_BAD_NUMBER #define ENOMEM GRUB_ERR_OUT_OF_MEMORY -#define EAGAIN GRUB_ERR_AGAIN +#define EAGAIN GRUB_ERR_WAIT /* FIXME: Disambiguate this. */ #define ENODEV GRUB_ERR_IO #define ENOSYS GRUB_ERR_IO #define ENOENT GRUB_ERR_IO #define EIO GRUB_ERR_IO #define EROFS GRUB_ERR_POSIX_EROFS -#define EINTR GRUB_ERR_AGAIN +#define EINTR GRUB_ERR_WAIT #define EACCES GRUB_ERR_ACCESS_DENIED #define ERANGE GRUB_ERR_BAD_ARGUMENT #define EEXIST GRUB_ERR_POSIX_EEXIST diff --git a/grub-core/lib/posix_wrap/inttypes.h b/grub-core/lib/posix_wrap/include/inttypes.h similarity index 100% rename from grub-core/lib/posix_wrap/inttypes.h rename to grub-core/lib/posix_wrap/include/inttypes.h diff --git a/grub-core/lib/posix_wrap/langinfo.h b/grub-core/lib/posix_wrap/include/langinfo.h similarity index 100% rename from grub-core/lib/posix_wrap/langinfo.h rename to grub-core/lib/posix_wrap/include/langinfo.h diff --git a/grub-core/lib/posix_wrap/limits.h b/grub-core/lib/posix_wrap/include/limits.h similarity index 100% rename from grub-core/lib/posix_wrap/limits.h rename to grub-core/lib/posix_wrap/include/limits.h diff --git a/grub-core/lib/posix_wrap/localcharset.h b/grub-core/lib/posix_wrap/include/localcharset.h similarity index 100% rename from grub-core/lib/posix_wrap/localcharset.h rename to grub-core/lib/posix_wrap/include/localcharset.h diff --git a/grub-core/lib/posix_wrap/locale.h b/grub-core/lib/posix_wrap/include/locale.h similarity index 100% rename from grub-core/lib/posix_wrap/locale.h rename to grub-core/lib/posix_wrap/include/locale.h diff --git a/grub-core/lib/posix_wrap/stdint.h b/grub-core/lib/posix_wrap/include/stdint.h similarity index 100% rename from grub-core/lib/posix_wrap/stdint.h rename to grub-core/lib/posix_wrap/include/stdint.h diff --git a/grub-core/lib/posix_wrap/stdio.h b/grub-core/lib/posix_wrap/include/stdio.h similarity index 100% rename from grub-core/lib/posix_wrap/stdio.h rename to grub-core/lib/posix_wrap/include/stdio.h diff --git a/grub-core/lib/posix_wrap/stdlib.h b/grub-core/lib/posix_wrap/include/stdlib.h similarity index 92% rename from grub-core/lib/posix_wrap/stdlib.h rename to grub-core/lib/posix_wrap/include/stdlib.h index a8fdde43c..920e35db6 100644 --- a/grub-core/lib/posix_wrap/stdlib.h +++ b/grub-core/lib/posix_wrap/include/stdlib.h @@ -97,9 +97,11 @@ atol (const char *nptr) } static inline grub_size_t -mbstowcs (grub_wchar_t *dest, const char *src, grub_size_t n) +mbstowcs (wchar_t *dest, const char *src, grub_size_t n) { - grub_size_t ret = grub_utf8_to_ucs4 (dest, n, (const grub_uint8_t *) src, + COMPILE_TIME_ASSERT( sizeof (grub_uint32_t) == sizeof (wchar_t)); + grub_size_t ret = grub_utf8_to_ucs4 ((grub_uint32_t *) dest, + n, (const grub_uint8_t *) src, -1, NULL); if (ret < n) dest[ret] = 0; diff --git a/grub-core/lib/posix_wrap/string.h b/grub-core/lib/posix_wrap/include/string.h similarity index 97% rename from grub-core/lib/posix_wrap/string.h rename to grub-core/lib/posix_wrap/include/string.h index 748b1c662..ee7254d82 100644 --- a/grub-core/lib/posix_wrap/string.h +++ b/grub-core/lib/posix_wrap/include/string.h @@ -167,8 +167,8 @@ strdup (const char *s) return grub_strdup (s); } -static inline grub_wchar_t * -wmempcpy (grub_wchar_t *dest, const grub_wchar_t *src, grub_size_t n) +static inline wchar_t * +wmempcpy (wchar_t *dest, const wchar_t *src, grub_size_t n) { grub_memcpy (dest, src, sizeof (dest[0]) * n); return dest + n; @@ -215,7 +215,7 @@ static inline char * mbschr (const char *src, int c) { int count = 0; - grub_wchar_t code = 0; + grub_uint32_t code = 0; const char *last_start = src; while (1) @@ -233,7 +233,7 @@ mbschr (const char *src, int c) continue; if (code == 0) break; - if (code == c) + if ((int) code == c) return (char *) last_start; last_start = src; } diff --git a/grub-core/lib/posix_wrap/sys/types.h b/grub-core/lib/posix_wrap/include/sys/types.h similarity index 100% rename from grub-core/lib/posix_wrap/sys/types.h rename to grub-core/lib/posix_wrap/include/sys/types.h diff --git a/grub-core/lib/posix_wrap/unistd.h b/grub-core/lib/posix_wrap/include/unistd.h similarity index 100% rename from grub-core/lib/posix_wrap/unistd.h rename to grub-core/lib/posix_wrap/include/unistd.h diff --git a/grub-core/lib/posix_wrap/wchar.h b/grub-core/lib/posix_wrap/include/wchar.h similarity index 87% rename from grub-core/lib/posix_wrap/wchar.h rename to grub-core/lib/posix_wrap/include/wchar.h index beb45dfaa..ef3bed9ce 100644 --- a/grub-core/lib/posix_wrap/wchar.h +++ b/grub-core/lib/posix_wrap/include/wchar.h @@ -22,8 +22,8 @@ #include #include -#define wint_t grub_posix_wint_t -#define wchar_t grub_posix_wchar_t +#include + #define mbstate_t grub_posix_mbstate_t /* UCS-4. */ @@ -32,20 +32,21 @@ enum WEOF = -1 }; +typedef int wint_t; + typedef struct mbstate { - grub_wchar_t code; + grub_uint32_t code; int count; } mbstate_t; + /* UTF-8. */ #define MB_CUR_MAX 4 #define MB_LEN_MAX 4 static inline grub_size_t -mbrtowc (grub_wchar_t *pwc, const char *s, grub_size_t n, mbstate_t *ps) +mbrtowc (wchar_t *pwc, const char *s, grub_size_t n, mbstate_t *ps) { - COMPILE_TIME_ASSERT (sizeof (wchar_t) == sizeof (grub_wchar_t)); - COMPILE_TIME_ASSERT (GRUB_WCHAR_MAX == WCHAR_MAX); const char *ptr; if (!s) { @@ -149,22 +150,22 @@ wmemcmp (const wchar_t *s1, const wchar_t *s2, grub_size_t n) return 0; } -static inline grub_wchar_t * -wmemchr (const grub_wchar_t *s, grub_wchar_t c, grub_size_t n) +static inline wchar_t * +wmemchr (const wchar_t *s, wchar_t c, grub_size_t n) { for (; n--; s++) { if (*s == c) - return (grub_wchar_t *) s; + return (wchar_t *) s; } return 0; } static inline grub_size_t -wcslen (const grub_wchar_t *s) +wcslen (const wchar_t *s) { - const grub_wchar_t *ptr; + const wchar_t *ptr; for (ptr = s; *ptr; ptr++); return ptr - s; } @@ -196,7 +197,7 @@ mbslen (const char *src) { int count = 0; grub_size_t ret = 0; - grub_wchar_t code = 0; + grub_uint32_t code = 0; while (1) { diff --git a/grub-core/lib/posix_wrap/wctype.h b/grub-core/lib/posix_wrap/include/wctype.h similarity index 100% rename from grub-core/lib/posix_wrap/wctype.h rename to grub-core/lib/posix_wrap/include/wctype.h diff --git a/grub-core/normal/cmdline.c b/grub-core/normal/cmdline.c index c19a1dfdd..f7cd115d7 100644 --- a/grub-core/normal/cmdline.c +++ b/grub-core/normal/cmdline.c @@ -29,10 +29,10 @@ #include #include -static grub_wchar_t *kill_buf; +static grub_uint32_t *kill_buf; static int hist_size; -static grub_wchar_t **hist_lines = 0; +static grub_uint32_t **hist_lines = 0; static int hist_pos = 0; static int hist_end = 0; static int hist_used = 0; @@ -40,8 +40,8 @@ static int hist_used = 0; grub_err_t grub_set_history (int newsize) { - grub_wchar_t **old_hist_lines = hist_lines; - hist_lines = grub_malloc (sizeof (hist_lines[0]) * newsize); + grub_uint32_t **old_hist_lines = hist_lines; + hist_lines = grub_malloc (sizeof (grub_uint32_t *) * newsize); /* Copy the old lines into the new buffer. */ if (old_hist_lines) @@ -68,16 +68,16 @@ grub_set_history (int newsize) if (hist_pos < hist_end) grub_memmove (hist_lines, old_hist_lines + hist_pos, - (hist_end - hist_pos) * sizeof (grub_wchar_t *)); + (hist_end - hist_pos) * sizeof (grub_uint32_t *)); else if (hist_used) { /* Copy the older part. */ grub_memmove (hist_lines, old_hist_lines + hist_pos, - (hist_size - hist_pos) * sizeof (grub_wchar_t *)); + (hist_size - hist_pos) * sizeof (grub_uint32_t *)); /* Copy the newer part. */ grub_memmove (hist_lines + hist_size - hist_pos, old_hist_lines, - hist_end * sizeof (grub_wchar_t *)); + hist_end * sizeof (grub_uint32_t *)); } } @@ -91,7 +91,7 @@ grub_set_history (int newsize) /* Get the entry POS from the history where `0' is the newest entry. */ -static grub_wchar_t * +static grub_uint32_t * grub_history_get (unsigned pos) { pos = (hist_pos + pos) % hist_size; @@ -99,9 +99,9 @@ grub_history_get (unsigned pos) } static grub_size_t -strlen_ucs4 (const grub_wchar_t *s) +strlen_ucs4 (const grub_uint32_t *s) { - const grub_wchar_t *p = s; + const grub_uint32_t *p = s; while (*p) p++; @@ -111,23 +111,23 @@ strlen_ucs4 (const grub_wchar_t *s) /* Replace the history entry on position POS with the string S. */ static void -grub_history_set (int pos, grub_wchar_t *s, grub_size_t len) +grub_history_set (int pos, grub_uint32_t *s, grub_size_t len) { grub_free (hist_lines[pos]); - hist_lines[pos] = grub_malloc ((len + 1) * sizeof (grub_wchar_t)); + hist_lines[pos] = grub_malloc ((len + 1) * sizeof (grub_uint32_t)); if (!hist_lines[pos]) { grub_print_error (); grub_errno = GRUB_ERR_NONE; return ; } - grub_memcpy (hist_lines[pos], s, len * sizeof (grub_wchar_t)); + grub_memcpy (hist_lines[pos], s, len * sizeof (grub_uint32_t)); hist_lines[pos][len] = 0; } /* Insert a new history line S on the top of the history. */ static void -grub_history_add (grub_wchar_t *s, grub_size_t len) +grub_history_add (grub_uint32_t *s, grub_size_t len) { /* Remove the oldest entry in the history to make room for a new entry. */ @@ -154,7 +154,7 @@ grub_history_add (grub_wchar_t *s, grub_size_t len) /* Replace the history entry on position POS with the string S. */ static void -grub_history_replace (unsigned pos, grub_wchar_t *s, grub_size_t len) +grub_history_replace (unsigned pos, grub_uint32_t *s, grub_size_t len) { grub_history_set ((hist_pos + pos) % hist_size, s, len); } @@ -219,16 +219,16 @@ char * grub_cmdline_get (const char *prompt_translated) { grub_size_t lpos, llen; - grub_wchar_t *buf; + grub_uint32_t *buf; grub_size_t max_len = 256; int key; int histpos = 0; - auto void cl_insert (const grub_wchar_t *str); + auto void cl_insert (const grub_uint32_t *str); auto void cl_delete (unsigned len); auto inline void __attribute__ ((always_inline)) cl_print (struct cmdline_term *cl_term, int pos, - grub_wchar_t c); + grub_uint32_t c); auto void cl_set_pos (struct cmdline_term *cl_term); - auto void cl_print_all (int pos, grub_wchar_t c); + auto void cl_print_all (int pos, grub_uint32_t c); auto void cl_set_pos_all (void); auto void init_clterm (struct cmdline_term *cl_term_cur); auto void init_clterm_all (void); @@ -251,9 +251,9 @@ grub_cmdline_get (const char *prompt_translated) cl_set_pos (&cl_terms[i]); } - inline void __attribute__ ((always_inline)) cl_print (struct cmdline_term *cl_term, int pos, grub_wchar_t c) + inline void __attribute__ ((always_inline)) cl_print (struct cmdline_term *cl_term, int pos, grub_uint32_t c) { - grub_wchar_t *p; + grub_uint32_t *p; for (p = buf + pos; p < buf + llen; p++) { @@ -274,22 +274,22 @@ grub_cmdline_get (const char *prompt_translated) } } - void cl_print_all (int pos, grub_wchar_t c) + void cl_print_all (int pos, grub_uint32_t c) { unsigned i; for (i = 0; i < nterms; i++) cl_print (&cl_terms[i], pos, c); } - void cl_insert (const grub_wchar_t *str) + void cl_insert (const grub_uint32_t *str) { grub_size_t len = strlen_ucs4 (str); if (len + llen >= max_len) { - grub_wchar_t *nbuf; + grub_uint32_t *nbuf; max_len *= 2; - nbuf = grub_realloc (buf, sizeof (nbuf[0]) * max_len); + nbuf = grub_realloc (buf, sizeof (grub_uint32_t) * max_len); if (nbuf) buf = nbuf; else @@ -303,8 +303,8 @@ grub_cmdline_get (const char *prompt_translated) if (len + llen < max_len) { grub_memmove (buf + lpos + len, buf + lpos, - (llen - lpos + 1) * sizeof (grub_wchar_t)); - grub_memmove (buf + lpos, str, len * sizeof (grub_wchar_t)); + (llen - lpos + 1) * sizeof (grub_uint32_t)); + grub_memmove (buf + lpos, str, len * sizeof (grub_uint32_t)); llen += len; cl_set_pos_all (); @@ -327,7 +327,7 @@ grub_cmdline_get (const char *prompt_translated) cl_set_pos_all (); grub_memmove (buf + lpos, buf + lpos + len, - sizeof (grub_wchar_t) * (llen - lpos + 1)); + sizeof (grub_uint32_t) * (llen - lpos + 1)); llen -= len; cl_print_all (lpos, 0); cl_set_pos_all (); @@ -350,7 +350,7 @@ grub_cmdline_get (const char *prompt_translated) init_clterm (&cl_terms[i]); } - buf = grub_malloc (max_len * sizeof (grub_wchar_t)); + buf = grub_malloc (max_len * sizeof (grub_uint32_t)); if (!buf) return 0; @@ -371,7 +371,7 @@ grub_cmdline_get (const char *prompt_translated) { struct cmdline_term *cl_term_cur; struct grub_term_output *cur; - grub_wchar_t *unicode_msg; + grub_uint32_t *unicode_msg; grub_size_t msg_len = grub_strlen (prompt_translated) + 3; nterms = 0; @@ -383,7 +383,7 @@ grub_cmdline_get (const char *prompt_translated) return 0; cl_term_cur = cl_terms; - unicode_msg = grub_malloc (msg_len * sizeof (grub_wchar_t)); + unicode_msg = grub_malloc (msg_len * sizeof (grub_uint32_t)); if (!unicode_msg) return 0;; msg_len = grub_utf8_to_ucs4 (unicode_msg, msg_len - 1, @@ -447,7 +447,7 @@ grub_cmdline_get (const char *prompt_translated) int restore; char *insertu8; char *bufu8; - grub_wchar_t c; + grub_uint32_t c; c = buf[lpos]; buf[lpos] = '\0'; @@ -481,10 +481,10 @@ grub_cmdline_get (const char *prompt_translated) { grub_size_t insertlen; grub_ssize_t t; - grub_wchar_t *insert; + grub_uint32_t *insert; insertlen = grub_strlen (insertu8); - insert = grub_malloc ((insertlen + 1) * sizeof (insert[0])); + insert = grub_malloc ((insertlen + 1) * sizeof (grub_uint32_t)); if (!insert) { grub_free (insertu8); @@ -524,7 +524,7 @@ grub_cmdline_get (const char *prompt_translated) grub_free (kill_buf); kill_buf = grub_malloc ((llen - lpos + 1) - * sizeof (grub_wchar_t)); + * sizeof (grub_uint32_t)); if (grub_errno) { grub_print_error (); @@ -533,7 +533,7 @@ grub_cmdline_get (const char *prompt_translated) else { grub_memcpy (kill_buf, buf + lpos, - (llen - lpos + 1) * sizeof (grub_wchar_t)); + (llen - lpos + 1) * sizeof (grub_uint32_t)); kill_buf[llen - lpos] = 0; } @@ -544,7 +544,7 @@ grub_cmdline_get (const char *prompt_translated) case GRUB_TERM_CTRL | 'n': case GRUB_TERM_KEY_DOWN: { - grub_wchar_t *hist; + grub_uint32_t *hist; lpos = 0; @@ -564,7 +564,7 @@ grub_cmdline_get (const char *prompt_translated) case GRUB_TERM_KEY_UP: case GRUB_TERM_CTRL | 'p': { - grub_wchar_t *hist; + grub_uint32_t *hist; lpos = 0; @@ -588,7 +588,7 @@ grub_cmdline_get (const char *prompt_translated) grub_free (kill_buf); - kill_buf = grub_malloc ((n + 1) * sizeof(grub_wchar_t)); + kill_buf = grub_malloc ((n + 1) * sizeof(grub_uint32_t)); if (grub_errno) { grub_print_error (); @@ -596,7 +596,7 @@ grub_cmdline_get (const char *prompt_translated) } if (kill_buf) { - grub_memcpy (kill_buf, buf, n * sizeof(grub_wchar_t)); + grub_memcpy (kill_buf, buf, n * sizeof(grub_uint32_t)); kill_buf[n] = 0; } @@ -634,7 +634,7 @@ grub_cmdline_get (const char *prompt_translated) default: if (grub_isprint (key)) { - grub_wchar_t str[2]; + grub_uint32_t str[2]; str[0] = key; str[1] = '\0'; @@ -652,7 +652,7 @@ grub_cmdline_get (const char *prompt_translated) histpos = 0; if (strlen_ucs4 (buf) > 0) { - grub_wchar_t empty[] = { 0 }; + grub_uint32_t empty[] = { 0 }; grub_history_replace (histpos, buf, llen); grub_history_add (empty, 0); } diff --git a/grub-core/normal/main.c b/grub-core/normal/main.c index 88510ce24..ad3627351 100644 --- a/grub-core/normal/main.c +++ b/grub-core/normal/main.c @@ -247,36 +247,17 @@ grub_normal_init_page (struct grub_term_output *term, grub_term_cls (term); - if (!grub_term_is_tiny (term)) - { - int msg_len; - int posx; - const char *msg = _("GNU GRUB version %s"); - char *msg_formatted; - grub_wchar_t *unicode_msg; - grub_wchar_t *last_position; - - msg_formatted = grub_xasprintf (msg, PACKAGE_VERSION); - if (!msg_formatted) - return; + msg_formatted = grub_xasprintf (msg, PACKAGE_VERSION); + if (!msg_formatted) + return; - msg_len = grub_utf8_to_ucs4_alloc (msg_formatted, - &unicode_msg, &last_position); - grub_free (msg_formatted); + msg_len = grub_utf8_to_ucs4_alloc (msg_formatted, + &unicode_msg, &last_position); + grub_free (msg_formatted); - if (msg_len < 0) - { - return; - } - - posx = grub_getstringwidth (unicode_msg, last_position, term); - posx = (grub_term_width (term) - posx) / 2; - grub_term_gotoxy (term, posx, 1); - - grub_print_ucs4 (unicode_msg, last_position, 0, 0, term); - grub_putcode ('\n', term); - grub_putcode ('\n', term); - grub_free (unicode_msg); + if (msg_len < 0) + { + return; } posx = grub_getstringwidth (unicode_msg, last_position, term); @@ -426,19 +407,18 @@ grub_normal_reader_init (int nested) return grub_errno; FOR_ACTIVE_TERM_OUTPUTS(term) - if (!grub_term_is_tiny (term)) - { - grub_normal_init_page (term, 1); - grub_term_setcursor (term, 1); - - if (grub_term_width (term) > 3 + STANDARD_MARGIN + 20) - grub_print_message_indented (msg_formatted, 3, STANDARD_MARGIN, term); - else - grub_print_message_indented (msg_formatted, 0, 0, term); - grub_putcode ('\n', term); - grub_putcode ('\n', term); - grub_putcode ('\n', term); - } + { + grub_normal_init_page (term, 1); + grub_term_setcursor (term, 1); + + if (grub_term_width (term) > 3 + STANDARD_MARGIN + 20) + grub_print_message_indented (msg_formatted, 3, STANDARD_MARGIN, term); + else + grub_print_message_indented (msg_formatted, 0, 0, term); + grub_putcode ('\n', term); + grub_putcode ('\n', term); + grub_putcode ('\n', term); + } grub_free (msg_formatted); return 0; diff --git a/grub-core/normal/term.c b/grub-core/normal/term.c index 71f76fc4d..7b2b7bd33 100644 --- a/grub-core/normal/term.c +++ b/grub-core/normal/term.c @@ -29,8 +29,8 @@ struct term_state { struct term_state *next; - const struct grub_unicode_glyph *backlog_glyphs; - const grub_wchar_t *backlog_ucs4; + struct grub_unicode_glyph *backlog_glyphs; + const grub_uint32_t *backlog_ucs4; int backlog_fixed_tab; grub_size_t backlog_len; @@ -59,7 +59,7 @@ static struct term_state *term_states = NULL; static int grub_more; static void -putcode_real (grub_wchar_t code, struct grub_term_output *term, int fixed_tab); +putcode_real (grub_uint32_t code, struct grub_term_output *term, int fixed_tab); void grub_normal_reset_more (void) @@ -75,7 +75,7 @@ print_more (void) char key; struct grub_term_coordinate *pos; grub_term_output_t term; - grub_wchar_t *unicode_str, *unicode_last_position; + grub_uint32_t *unicode_str, *unicode_last_position; pos = grub_term_save_pos (); @@ -146,45 +146,10 @@ enum GRUB_CP437_CORNER_UL = 0xda, }; -char -grub_translit (grub_wchar_t in) +static grub_uint32_t +map_code (grub_uint32_t in, struct grub_term_output *term) { - if (!(in & ~0x7f)) - return in; - - switch (in) - { - case GRUB_UNICODE_LEFTARROW: - return '<'; - - case GRUB_UNICODE_UPARROW: - return '^'; - - case GRUB_UNICODE_RIGHTARROW: - return '>'; - - case GRUB_UNICODE_DOWNARROW: - return 'v'; - - case GRUB_UNICODE_HLINE: - return '-'; - - case GRUB_UNICODE_VLINE: - return '|'; - - case GRUB_UNICODE_CORNER_UL: - case GRUB_UNICODE_CORNER_UR: - case GRUB_UNICODE_CORNER_LL: - case GRUB_UNICODE_CORNER_LR: - return '+'; - } - return '?'; -} - -static grub_wchar_t -map_code (grub_wchar_t in, struct grub_term_output *term) -{ - if (!(in & ~0x7f)) + if (in <= 0x7f) return in; switch (term->flags & GRUB_TERM_CODE_TYPE_MASK) @@ -215,9 +180,37 @@ map_code (grub_wchar_t in, struct grub_term_output *term) case GRUB_UNICODE_CORNER_LR: return GRUB_CP437_CORNER_LR; } + return '?'; case GRUB_TERM_CODE_TYPE_ASCII: /* Better than nothing. */ - return grub_translit (in); + switch (in) + { + case GRUB_UNICODE_LEFTARROW: + return '<'; + + case GRUB_UNICODE_UPARROW: + return '^'; + + case GRUB_UNICODE_RIGHTARROW: + return '>'; + + case GRUB_UNICODE_DOWNARROW: + return 'v'; + + case GRUB_UNICODE_HLINE: + return '-'; + + case GRUB_UNICODE_VLINE: + return '|'; + + case GRUB_UNICODE_CORNER_UL: + case GRUB_UNICODE_CORNER_UR: + case GRUB_UNICODE_CORNER_LL: + case GRUB_UNICODE_CORNER_LR: + return '+'; + + } + return '?'; } return in; } @@ -225,7 +218,7 @@ map_code (grub_wchar_t in, struct grub_term_output *term) void grub_puts_terminal (const char *str, struct grub_term_output *term) { - grub_wchar_t *unicode_str, *unicode_last_position; + grub_uint32_t *unicode_str, *unicode_last_position; grub_error_push (); grub_utf8_to_ucs4_alloc (str, &unicode_str, &unicode_last_position); @@ -470,7 +463,7 @@ putglyph (const struct grub_unicode_glyph *c, struct grub_term_output *term, for (i = -1; i < (int) c->ncomb; i++) { grub_uint8_t u8[20], *ptr; - grub_wchar_t code; + grub_uint32_t code; if (i == -1) { @@ -508,7 +501,7 @@ putglyph (const struct grub_unicode_glyph *c, struct grub_term_output *term, } static void -putcode_real (grub_wchar_t code, struct grub_term_output *term, int fixed_tab) +putcode_real (grub_uint32_t code, struct grub_term_output *term, int fixed_tab) { struct grub_unicode_glyph c = { @@ -524,7 +517,7 @@ putcode_real (grub_wchar_t code, struct grub_term_output *term, int fixed_tab) /* Put a Unicode character. */ void -grub_putcode (grub_wchar_t code, struct grub_term_output *term) +grub_putcode (grub_uint32_t code, struct grub_term_output *term) { /* Combining character by itself? */ if (grub_unicode_get_comb_type (code) != GRUB_UNICODE_COMB_NONE) @@ -565,8 +558,8 @@ fill_margin (struct grub_term_output *term, int r) } static int -print_ucs4_terminal (const grub_wchar_t * str, - const grub_wchar_t * last_position, +print_ucs4_terminal (const grub_uint32_t * str, + const grub_uint32_t * last_position, int margin_left, int margin_right, struct grub_term_output *term, struct term_state *state, @@ -575,12 +568,12 @@ print_ucs4_terminal (const grub_wchar_t * str, grub_uint32_t contchar, int primitive_wrap, int fill_right, struct grub_term_pos *pos) { - const grub_wchar_t *ptr; + const grub_uint32_t *ptr; grub_ssize_t startwidth = dry_run ? 0 : get_startwidth (term, margin_left); grub_ssize_t line_width = startwidth; grub_ssize_t lastspacewidth = 0; grub_ssize_t max_width = get_maxwidth (term, margin_left, margin_right); - const grub_wchar_t *line_start = str, *last_space = str - 1; + const grub_uint32_t *line_start = str, *last_space = str - 1; int lines = 0; int i; struct term_state local_state; @@ -642,7 +635,7 @@ print_ucs4_terminal (const grub_wchar_t * str, if (line_width > max_width || *ptr == '\n') { - const grub_wchar_t *ptr2; + const grub_uint32_t *ptr2; int wasn = (*ptr == '\n'); if (wasn) @@ -740,7 +733,7 @@ print_ucs4_terminal (const grub_wchar_t * str, lines++; if (!dry_run && !skip_lines && max_lines) { - const grub_wchar_t *ptr2; + const grub_uint32_t *ptr2; for (ptr2 = line_start; ptr2 < last_position; ptr2++) { @@ -880,8 +873,8 @@ getcharwidth (const struct grub_unicode_glyph *c, void *term) } static int -print_ucs4_real (const grub_wchar_t * str, - const grub_wchar_t * last_position, +print_ucs4_real (const grub_uint32_t * str, + const grub_uint32_t * last_position, int margin_left, int margin_right, struct grub_term_output *term, int backlog, int dry_run, int fixed_tab, unsigned skip_lines, @@ -995,8 +988,8 @@ grub_print_ucs4_menu (const grub_uint32_t * str, } void -grub_print_ucs4 (const grub_wchar_t * str, - const grub_wchar_t * last_position, +grub_print_ucs4 (const grub_uint32_t * str, + const grub_uint32_t * last_position, int margin_left, int margin_right, struct grub_term_output *term) { @@ -1005,8 +998,8 @@ grub_print_ucs4 (const grub_wchar_t * str, } int -grub_ucs4_count_lines (const grub_wchar_t * str, - const grub_wchar_t * last_position, +grub_ucs4_count_lines (const grub_uint32_t * str, + const grub_uint32_t * last_position, int margin_left, int margin_right, struct grub_term_output *term) { @@ -1017,7 +1010,7 @@ grub_ucs4_count_lines (const grub_wchar_t * str, void grub_xnputs (const char *str, grub_size_t msg_len) { - grub_wchar_t *unicode_str = NULL, *unicode_last_position; + grub_uint32_t *unicode_str = NULL, *unicode_last_position; int backlog = 0; grub_term_output_t term; diff --git a/include/grub/misc.h b/include/grub/misc.h index 2be2af224..8950ecb95 100644 --- a/include/grub/misc.h +++ b/include/grub/misc.h @@ -59,9 +59,7 @@ #define ALIGN_UP_OVERHEAD(addr, align) ((-(addr)) & ((typeof (addr)) (align) - 1)) #define ALIGN_DOWN(addr, align) \ ((addr) & ~((typeof (addr)) align - 1)) -#ifndef GRUB_POSIX #define ARRAY_SIZE(array) (sizeof (array) / sizeof (array[0])) -#endif #define COMPILE_TIME_ASSERT(cond) switch (0) { case 1: case !(cond): ; } #define grub_dprintf(condition, fmt, args...) grub_real_dprintf(GRUB_FILE, __LINE__, condition, fmt, ## args)