diff options
author | Jens Arnold <amiconn@rockbox.org> | 2005-08-24 06:48:39 +0000 |
---|---|---|
committer | Jens Arnold <amiconn@rockbox.org> | 2005-08-24 06:48:39 +0000 |
commit | c7e4f5f2596bc7812b0569eabeea557686b43bb1 (patch) | |
tree | dc7d40e414ca81830a357cdc9bc1523fe5018e18 /apps/player | |
parent | 6c00e38665fbe7e4aa724667cf1105596a8495a6 (diff) |
Keyboard code cleanup & optimisation. Corrected potential overflow problem.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@7397 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/player')
-rw-r--r-- | apps/player/keyboard.c | 31 |
1 files changed, 9 insertions, 22 deletions
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++; } } |