Skip to contentSkip to conversation

grub_cmdline_get() i18n problem

DISCUSSION Oleg Strikov 3 participants 3 messages Feb 1, 2008 – Feb 2, 2008

lore
Share & tools
lore
#0 lore raw

Good day!

Let's look at grub_cmdline_get() func code:

/* normal/cmdline.c - line 300 */
plen = grub_utf8_strlen (prompt);
lpos = llen = 0;
buf[0] = '\0';

  if ((grub_getxy () >> 8) != 0)
    grub_putchar ('\n');

  grub_printf (prompt);

  xpos = plen;

Idea is very simple - we move cursor plen times.
All is OK when promt contains only ASCII symblos. If we use UTF8 strings - we get incorrect cursor moving (grub_strlen returns incorrect length due to UTF-8 symbol floating byte size).
There are two ways:
* encode smth like grub_utf8_strlen ()
* modify grub_strlen () func and add this feature

I do my best to solve this problem, but what way do you recommend?

Thanks

#1 lore raw
Quoted 5 lines · Oleg Strikov

There are two ways:
* encode smth like grub_utf8_strlen ()
* modify grub_strlen () func and add this feature

I do my best to solve this problem, but what way do you recommend?

The convention is to match the posix equivalents, then grub_strlen() for counting bytes, so I'd suggest the first.

But, are you sure we don't have this already?

Signature · 5 lines
Robert Millan

<GPLv2> I know my rights; I want my phone call!
<DRM> What use is a phone call… if you are unable to speak?
(as seen on /.)
#2 lore raw
In reply to Oleg Strikov
Quoted 24 lines · Oleg Strikov

Good day!

Let's look at grub_cmdline_get() func code:

/* normal/cmdline.c - line 300 */
plen = grub_utf8_strlen (prompt);
lpos = llen = 0;
buf[0] = '\0';

  if ((grub_getxy () >> 8) != 0)
    grub_putchar ('\n');

  grub_printf (prompt);

  xpos = plen;

Idea is very simple - we move cursor plen times.
All is OK when promt contains only ASCII symblos. If we use UTF8 strings
- we get incorrect cursor moving (grub_strlen returns incorrect length due to UTF-8 symbol floating byte size).
There are two ways:
* encode smth like grub_utf8_strlen ()
* modify grub_strlen () func and add this feature

Quoted 1 line

I do my best to solve this problem, but what way do you recommend?

PROMPT is always in ASCII. This was my assumption. Is it bad?

Okuji