summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilliam Wilgus <wilgus.william@gmail.com>2020-10-03 22:45:27 -0400
committerWilliam Wilgus <wilgus.william@gmail.com>2020-10-04 04:00:54 -0400
commit1aa739e3c3d1ce25cdebe285847c3c493756d5d6 (patch)
tree554a5500c2483032fddb06bd5ff8589e942d86be
parentf3ae48f552e2d12e1d60e86198ff7ee26aabc2ec (diff)
downloadrockbox-1aa739e3c3d1ce25cdebe285847c3c493756d5d6.tar.gz
rockbox-1aa739e3c3d1ce25cdebe285847c3c493756d5d6.zip
lua misc tweaks and cleanup
checks button_status in rockev strpbrk_n custom implementation allows setting max search len in source string add some branch prediction where appropriate fix formatting in splash_scroller script Change-Id: Id5d8e9d83f4b3e361ccb67b403af8f9a8a31b8f0
-rw-r--r--apps/plugins/lua/rockaux.c8
-rw-r--r--apps/plugins/lua/rocklib_events.c13
-rw-r--r--apps/plugins/lua/strpbrk.c20
-rw-r--r--apps/plugins/lua/strtol.c4
-rw-r--r--apps/plugins/lua/strtoul.c2
-rw-r--r--apps/plugins/lua_scripts/splashscroller.lua2
6 files changed, 25 insertions, 24 deletions
diff --git a/apps/plugins/lua/rockaux.c b/apps/plugins/lua/rockaux.c
index 7ed82f616d..25bace3451 100644
--- a/apps/plugins/lua/rockaux.c
+++ b/apps/plugins/lua/rockaux.c
@@ -27,6 +27,7 @@
27#include "lib/pluginlib_actions.h" 27#include "lib/pluginlib_actions.h"
28 28
29extern long strtol(const char *nptr, char **endptr, int base); 29extern long strtol(const char *nptr, char **endptr, int base);
30extern const char *strpbrk_n(const char *s, int smax, const char *accept);
30 31
31#if (CONFIG_PLATFORM & PLATFORM_NATIVE) 32#if (CONFIG_PLATFORM & PLATFORM_NATIVE)
32int errno = 0; 33int errno = 0;
@@ -58,7 +59,7 @@ int splash_scroller(int timeout, const char* str)
58 const int max_lines = LCD_HEIGHT / ch_h - 1; 59 const int max_lines = LCD_HEIGHT / ch_h - 1;
59 const int wrap_thresh = (LCD_WIDTH / 3); 60 const int wrap_thresh = (LCD_WIDTH / 3);
60 const char *ch; 61 const char *ch;
61 char *brk; 62 const char *brk;
62 63
63 const int max_ch = (LCD_WIDTH / ch_w - 1) * 2; 64 const int max_ch = (LCD_WIDTH / ch_w - 1) * 2;
64 char line[max_ch + 2]; /* display buffer */ 65 char line[max_ch + 2]; /* display buffer */
@@ -98,9 +99,10 @@ int splash_scroller(int timeout, const char* str)
98 rb->lcd_getstringsize(line, &w, NULL); 99 rb->lcd_getstringsize(line, &w, NULL);
99 100
100 /* try to not split in middle of words */ 101 /* try to not split in middle of words */
101 if (w + wrap_thresh >= max_w && strpbrk (&line[linepos], break_chars)) 102 if (w + wrap_thresh >= max_w &&
103 strpbrk_n(ch, 1, break_chars))
102 { 104 {
103 brk = strpbrk(ch+1, break_chars); 105 brk = strpbrk_n(ch+1, max_ch, break_chars);
104 chars_next_break = (brk - ch); 106 chars_next_break = (brk - ch);
105 if (chars_next_break < 2 || w + (ch_w * chars_next_break) > max_w) 107 if (chars_next_break < 2 || w + (ch_w * chars_next_break) > max_w)
106 { 108 {
diff --git a/apps/plugins/lua/rocklib_events.c b/apps/plugins/lua/rocklib_events.c
index 91e217169e..dc15c363a4 100644
--- a/apps/plugins/lua/rocklib_events.c
+++ b/apps/plugins/lua/rocklib_events.c
@@ -272,7 +272,8 @@ static void rev_timer_isr(void)
272 { 272 {
273 evt = ev_data.cb[i]; 273 evt = ev_data.cb[i];
274 274
275 if ((i == ACTEVENT || i == BTNEVENT) && rb->button_queue_count()) 275 if ((i == ACTEVENT || i == BTNEVENT) &&
276 (rb->button_queue_count() || rb->button_status() || evt->id))
276 ev_flag |= event_flag(i); /* any buttons ready? */ 277 ev_flag |= event_flag(i); /* any buttons ready? */
277 else if(evt->ticks > 0 && TIME_AFTER(curr_tick, evt->next_tick)) 278 else if(evt->ticks > 0 && TIME_AFTER(curr_tick, evt->next_tick))
278 ev_flag |= event_flag(i); 279 ev_flag |= event_flag(i);
@@ -315,23 +316,15 @@ static void event_thread(void)
315 { 316 {
316 /* only send ACTION_NONE once */ 317 /* only send ACTION_NONE once */
317 if (evt->id == ACTION_NONE || rb->button_status() != 0) 318 if (evt->id == ACTION_NONE || rb->button_status() != 0)
318 {
319 evt->ticks = 0;
320 continue; /* check next event */ 319 continue; /* check next event */
321 }
322 } 320 }
323 evt->ticks = EV_TICKS; /* poll release event */
324 evt->id = action; 321 evt->id = action;
325 break; 322 break;
326 case BTNEVENT: 323 case BTNEVENT:
327 evt->id = rb->button_get(false); 324 evt->id = rb->button_get(false);
328 /* only send BUTTON_NONE once */ 325 /* only send BUTTON_NONE once */
329 if (evt->id == BUTTON_NONE) 326 if (evt->id == BUTTON_NONE)
330 {
331 evt->ticks = 0;
332 continue; /* check next event */ 327 continue; /* check next event */
333 }
334 evt->ticks = EV_TICKS; /* poll release event */
335 break; 328 break;
336 case CUSTOMEVENT: 329 case CUSTOMEVENT:
337 case PLAYBKEVENT: 330 case PLAYBKEVENT:
@@ -592,7 +585,7 @@ static int rockev_register(lua_State *L)
592 case ACTEVENT: 585 case ACTEVENT:
593 /* fall through */ 586 /* fall through */
594 case BTNEVENT: 587 case BTNEVENT:
595 event_ticks = 0; /* button events not triggered by timeout but release is*/ 588 event_ticks = 0; /* button events not triggered by timeout */
596 break; 589 break;
597 case CUSTOMEVENT: 590 case CUSTOMEVENT:
598 event_ticks = luaL_optinteger(L, 3, EV_TICKS); 591 event_ticks = luaL_optinteger(L, 3, EV_TICKS);
diff --git a/apps/plugins/lua/strpbrk.c b/apps/plugins/lua/strpbrk.c
index 1e0491f779..efa9cbd2bb 100644
--- a/apps/plugins/lua/strpbrk.c
+++ b/apps/plugins/lua/strpbrk.c
@@ -1,11 +1,17 @@
1#include "rocklibc.h" 1#include "rocklibc.h"
2 2
3#undef strpbrk 3#undef strpbrk
4char *strpbrk(const char *s, const char *accept) { 4/* custom strbbrk allowing you to define search len of s*/
5 register int i,l=strlen(accept); 5const char *strpbrk_n(const char *s, int smax, const char *accept) {
6 for (; *s; s++) 6 register int i;
7 for (i=0; i<l; i++) 7 register const char *a = accept;
8 if (*s == accept[i]) 8 for (i=0; __likely(s[i] && i < smax); i++, a=accept)
9 return (char*)s; 9 while(__likely(a++[0]))
10 return 0; 10 if ((s[i] == a[0]))
11 return &s[i];
12 return NULL;
13}
14
15inline char *strpbrk(const char *s, const char *accept) {
16 return (char*)strpbrk_n(s, INT_MAX, accept);
11} 17}
diff --git a/apps/plugins/lua/strtol.c b/apps/plugins/lua/strtol.c
index 3dd29b6b57..564494643d 100644
--- a/apps/plugins/lua/strtol.c
+++ b/apps/plugins/lua/strtol.c
@@ -9,12 +9,12 @@ long int strtol(const char *nptr, char **endptr, int base)
9 unsigned long int v; 9 unsigned long int v;
10 const char*orig=nptr; 10 const char*orig=nptr;
11 11
12 while(isspace(*nptr)) nptr++; 12 while(__unlikely(isspace(*nptr))) nptr++;
13 13
14 if (*nptr == '-' && isalnum(nptr[1])) { neg=-1; ++nptr; } 14 if (*nptr == '-' && isalnum(nptr[1])) { neg=-1; ++nptr; }
15 v=strtoul(nptr,endptr,base); 15 v=strtoul(nptr,endptr,base);
16 if (endptr && *endptr==nptr) *endptr=(char *)orig; 16 if (endptr && *endptr==nptr) *endptr=(char *)orig;
17 if (v>=ABS_LONG_MIN) { 17 if (__unlikely(v>=ABS_LONG_MIN)) {
18 if (v==ABS_LONG_MIN && neg) { 18 if (v==ABS_LONG_MIN && neg) {
19 errno=0; 19 errno=0;
20 return v; 20 return v;
diff --git a/apps/plugins/lua/strtoul.c b/apps/plugins/lua/strtoul.c
index 74d9b4bb09..834721f05b 100644
--- a/apps/plugins/lua/strtoul.c
+++ b/apps/plugins/lua/strtoul.c
@@ -7,7 +7,7 @@ unsigned long int strtoul(const char *ptr, char **endptr, int base)
7 const char* orig; 7 const char* orig;
8 const char* nptr=ptr; 8 const char* nptr=ptr;
9 9
10 while(isspace(*nptr)) ++nptr; 10 while(__unlikely(isspace(*nptr))) ++nptr;
11 11
12 if (*nptr == '-') { neg=1; nptr++; } 12 if (*nptr == '-') { neg=1; nptr++; }
13 else if (*nptr == '+') ++nptr; 13 else if (*nptr == '+') ++nptr;
diff --git a/apps/plugins/lua_scripts/splashscroller.lua b/apps/plugins/lua_scripts/splashscroller.lua
index 78a7266de8..4356d573ee 100644
--- a/apps/plugins/lua_scripts/splashscroller.lua
+++ b/apps/plugins/lua_scripts/splashscroller.lua
@@ -1 +1 @@
rb.splash_scroller(rb.HZ * 5, "This is a rb.splash_scroller test, it is meant to reflow text into a format easily digestable on small screen devices.\n\n it is not particularly adept at this as we strive for the bare minimum in order to leave room for YOUR code. :) \n\nHowever, it does recognize \t\\t \r\\r\n\\n\n\\b (bell)\b") rb.splash_scroller(rb.HZ * 5, "This is a rb.splash_scroller test, it is meant to reflow text into a format easily digestable on small screen devices.\n\n it is not particularly adept at this as we strive for the bare minimum in order to leave room for YOUR code. :) \n\nHowever, it does recognize \n\t\\t \r\\r\n\\n\n\\b (bell)\b")