From c7e4f5f2596bc7812b0569eabeea557686b43bb1 Mon Sep 17 00:00:00 2001 From: Jens Arnold Date: Wed, 24 Aug 2005 06:48:39 +0000 Subject: Keyboard code cleanup & optimisation. Corrected potential overflow problem. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@7397 a1c6a512-1295-4272-9138-f99709370657 --- apps/player/keyboard.c | 31 +++++++++---------------------- 1 file changed, 9 insertions(+), 22 deletions(-) (limited to 'apps/player') diff --git a/apps/player/keyboard.c b/apps/player/keyboard.c index 6467ed60f1..fb06a0dc7b 100644 --- a/apps/player/keyboard.c +++ b/apps/player/keyboard.c @@ -102,7 +102,6 @@ int kbd_input(char* text, int buflen) int editpos, curpos, leftpos; unsigned short* line = kbd_setupkeys(page, &linelen); unsigned char temptext[12]; - char c; int button, lastbutton = 0; @@ -130,11 +129,11 @@ int kbd_input(char* text, int buflen) /* Draw insert chars */ temptext[0] = KEYBOARD_INSERT_LEFT; - temptext[1] = line[x%linelen]; + temptext[1] = line[x]; temptext[2] = KEYBOARD_INSERT_RIGHT; for (i = 1; i < 8; i++) { - temptext[i+2] = line[(i+x)%linelen]; + temptext[i+2] = line[(x+i)%linelen]; } temptext[i+2] = 0; lcd_puts(1, 0, temptext); @@ -194,9 +193,7 @@ int kbd_input(char* text, int buflen) } else { - if (x < linelen - 1) - x++; - else + if (++x >= linelen) x = 0; kbd_spellchar(line[x]); } @@ -214,9 +211,7 @@ int kbd_input(char* text, int buflen) } else { - if (x) - x--; - else + if (--x < 0) x = linelen - 1; kbd_spellchar(line[x]); } @@ -242,20 +237,12 @@ int kbd_input(char* text, int buflen) } else /* inserts the selected char */ { - if (len < buflen) + if (len + 1 < buflen) { - c = line[x]; - if (editpos == len) - { - text[len] = c; - text[len+1] = 0; - } - else - { - for (i = len ; i >= editpos; i--) - text[i+1] = text[i]; - text[editpos] = c; - } + for (i = len ; i > editpos; i--) + text[i] = text[i-1]; + text[len+1] = 0; + text[editpos] = line[x]; editpos++; } } -- cgit v1.2.3