diff options
Diffstat (limited to 'firmware')
-rw-r--r-- | firmware/SOURCES | 64 | ||||
-rw-r--r-- | firmware/common/strptokspn.c | 88 | ||||
-rw-r--r-- | firmware/export/font.h | 2 | ||||
-rw-r--r-- | firmware/font.c | 24 | ||||
-rw-r--r-- | firmware/include/strptokspn_r.h | 26 |
5 files changed, 166 insertions, 38 deletions
diff --git a/firmware/SOURCES b/firmware/SOURCES index bbd67631a9..4aa7c38daf 100644 --- a/firmware/SOURCES +++ b/firmware/SOURCES | |||
@@ -205,39 +205,10 @@ target/hosted/samsungypr/ypr1/wmcodec-ypr1.c | |||
205 | target/hosted/maemo/maemo-thread.c | 205 | target/hosted/maemo/maemo-thread.c |
206 | #endif | 206 | #endif |
207 | 207 | ||
208 | /* Standard library */ | ||
209 | #if (CONFIG_PLATFORM & PLATFORM_NATIVE) || defined(__MINGW32__) || defined(__CYGWIN__) | ||
210 | libc/strtok.c | ||
211 | #endif /* PLATFORM_NATIVE || __MINGW32__ || __CYGWIN__ */ | ||
212 | #if (CONFIG_PLATFORM & PLATFORM_NATIVE) || defined(HAVE_ROCKBOX_C_LIBRARY) | ||
213 | libc/atoi.c | ||
214 | libc/errno.c | ||
215 | #if (CONFIG_PLATFORM & PLATFORM_NATIVE) | ||
216 | /* our ctype.[ch] comes from newlib and is incompitble with most desktop's ctype */ | ||
217 | libc/ctype.c | ||
218 | /* alsa on linux requires a more advanced sprintf, i.e. not ours */ | ||
219 | libc/sprintf.c | ||
220 | #endif | ||
221 | |||
222 | libc/memchr.c | ||
223 | libc/memcmp.c | ||
224 | |||
225 | libc/qsort.c | ||
226 | libc/random.c | ||
227 | libc/strcat.c | ||
228 | libc/strchr.c | ||
229 | libc/strcmp.c | ||
230 | libc/strcpy.c | ||
231 | |||
232 | libc/strncmp.c | ||
233 | libc/strrchr.c | ||
234 | libc/strstr.c | ||
235 | libc/mktime.c | ||
236 | libc/gmtime.c | ||
237 | #endif /* CONFIG_PLATFORM || HAVE_ROCKBOX_C_LIBRARY */ | ||
238 | |||
239 | /* Common */ | 208 | /* Common */ |
240 | #ifndef BOOTLOADER | 209 | #ifndef BOOTLOADER |
210 | common/strptokspn.c | ||
211 | #define HAVE_STRTOK_R | ||
241 | common/ap_int.c | 212 | common/ap_int.c |
242 | #endif | 213 | #endif |
243 | common/version.c | 214 | common/version.c |
@@ -277,6 +248,37 @@ common/zip.c | |||
277 | common/adler32.c | 248 | common/adler32.c |
278 | common/inflate.c | 249 | common/inflate.c |
279 | 250 | ||
251 | /* Standard library */ | ||
252 | #if (CONFIG_PLATFORM & PLATFORM_NATIVE) || defined(__MINGW32__) || defined(__CYGWIN__) | ||
253 | libc/strtok.c | ||
254 | #endif /* PLATFORM_NATIVE || __MINGW32__ || __CYGWIN__ */ | ||
255 | #if (CONFIG_PLATFORM & PLATFORM_NATIVE) || defined(HAVE_ROCKBOX_C_LIBRARY) | ||
256 | libc/atoi.c | ||
257 | libc/errno.c | ||
258 | #if (CONFIG_PLATFORM & PLATFORM_NATIVE) | ||
259 | /* our ctype.[ch] comes from newlib and is incompitble with most desktop's ctype */ | ||
260 | libc/ctype.c | ||
261 | /* alsa on linux requires a more advanced sprintf, i.e. not ours */ | ||
262 | libc/sprintf.c | ||
263 | #endif | ||
264 | |||
265 | libc/memchr.c | ||
266 | libc/memcmp.c | ||
267 | |||
268 | libc/qsort.c | ||
269 | libc/random.c | ||
270 | libc/strcat.c | ||
271 | libc/strchr.c | ||
272 | libc/strcmp.c | ||
273 | libc/strcpy.c | ||
274 | |||
275 | libc/strncmp.c | ||
276 | libc/strrchr.c | ||
277 | libc/strstr.c | ||
278 | libc/mktime.c | ||
279 | libc/gmtime.c | ||
280 | #endif /* CONFIG_PLATFORM || HAVE_ROCKBOX_C_LIBRARY */ | ||
281 | |||
280 | /* Display */ | 282 | /* Display */ |
281 | scroll_engine.c | 283 | scroll_engine.c |
282 | 284 | ||
diff --git a/firmware/common/strptokspn.c b/firmware/common/strptokspn.c new file mode 100644 index 0000000000..f4b92c0712 --- /dev/null +++ b/firmware/common/strptokspn.c | |||
@@ -0,0 +1,88 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2022 by William WIlgus | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. * | ||
19 | ****************************************************************************/ | ||
20 | |||
21 | #include "config.h" | ||
22 | |||
23 | #include <stddef.h> | ||
24 | #include <string.h> | ||
25 | #include "strtok_r.h" | ||
26 | /* strptokspn_r is a custom implementation of strtok_r that does NOT modify | ||
27 | * the source string. | ||
28 | * | ||
29 | * strptokspn_r reads ptr as a series of zero or more tokens, | ||
30 | * and sep as delimiters of the tokens | ||
31 | * The tokens can be separated by one or more of the delimiters | ||
32 | * first call searches for the first token skipping over any leading delimiters. | ||
33 | * Returns pointer to first token | ||
34 | * Pointer *len contains the span to the first delimeter | ||
35 | * (this would be the resulting strlen had token actually been NULL terminated) | ||
36 | * Pointer **end contains pointer to first character after the last delimeter | ||
37 | * | ||
38 | * When strptokspn_r is called with a ptr == NULL, the next token is read from | ||
39 | * Pointer **end | ||
40 | * | ||
41 | * Note the returned token is NOT NULL terminated by the function as in strtok_r | ||
42 | * However the caller can use ret[len+1] = '\0'; to emulate a call to strtok_r | ||
43 | */ | ||
44 | |||
45 | const char *strptokspn_r(const char *ptr, const char *sep, size_t *len, const char **end) | ||
46 | { | ||
47 | *len = 0; | ||
48 | if (!ptr) | ||
49 | /* we got NULL input so then we get our last position instead */ | ||
50 | ptr = *end; | ||
51 | |||
52 | /* pass all letters that are including in the separator string */ | ||
53 | while (*ptr && strchr(sep, *ptr)) | ||
54 | ++ptr; | ||
55 | |||
56 | if (*ptr) { | ||
57 | /* so this is where the next piece of string starts */ | ||
58 | const char *start = ptr; | ||
59 | |||
60 | /* set the end pointer to the first byte after the start */ | ||
61 | *end = start + 1; | ||
62 | |||
63 | /* scan through the string to find where it ends, it ends on a | ||
64 | null byte or a character that exists in the separator string */ | ||
65 | while (**end && !strchr(sep, **end)) | ||
66 | ++*end; | ||
67 | *len = (*end - start) - 1; /* this would be the string len if there actually was a NULL */ | ||
68 | if (**end) { /* the end is not a null byte */ | ||
69 | ++*end; /* advance last pointer to beyond the match */ | ||
70 | } | ||
71 | |||
72 | return start; /* return the position where the string starts */ | ||
73 | } | ||
74 | |||
75 | /* we ended up on a null byte, there are no more strings to find! */ | ||
76 | return NULL; | ||
77 | } | ||
78 | |||
79 | #if !defined(HAVE_STRTOK_R) | ||
80 | char * strtok_r(char *ptr, const char *sep, char **end) | ||
81 | { | ||
82 | size_t len; | ||
83 | char * ret = (char*) strptokspn_r((const char*)ptr, sep, &len, (const char**) end); | ||
84 | if (ret) | ||
85 | ret[len + 1] = '\0'; | ||
86 | return ret; | ||
87 | } | ||
88 | #endif | ||
diff --git a/firmware/export/font.h b/firmware/export/font.h index 067c67e43d..38e30187b3 100644 --- a/firmware/export/font.h +++ b/firmware/export/font.h | |||
@@ -132,7 +132,7 @@ void font_disable_all(void); | |||
132 | void font_enable_all(void); | 132 | void font_enable_all(void); |
133 | 133 | ||
134 | struct font* font_get(int font); | 134 | struct font* font_get(int font); |
135 | 135 | int font_getstringnsize(const unsigned char *str, size_t maxbytes, int *w, int *h, int fontnumber); | |
136 | int font_getstringsize(const unsigned char *str, int *w, int *h, int fontnumber); | 136 | int font_getstringsize(const unsigned char *str, int *w, int *h, int fontnumber); |
137 | int font_get_width(struct font* ft, unsigned short ch); | 137 | int font_get_width(struct font* ft, unsigned short ch); |
138 | const unsigned char * font_get_bits(struct font* ft, unsigned short ch); | 138 | const unsigned char * font_get_bits(struct font* ft, unsigned short ch); |
diff --git a/firmware/font.c b/firmware/font.c index 7ce64ed47d..97a15221fc 100644 --- a/firmware/font.c +++ b/firmware/font.c | |||
@@ -1046,16 +1046,20 @@ const unsigned char* font_get_bits(struct font* pf, unsigned short char_code) | |||
1046 | #endif /* BOOTLOADER */ | 1046 | #endif /* BOOTLOADER */ |
1047 | 1047 | ||
1048 | /* | 1048 | /* |
1049 | * Returns the stringsize of a given string. | 1049 | * Returns the stringsize of a given NULL terminated string |
1050 | * stops after maxbytes or NULL (\0) whichever occurs first. | ||
1051 | * maxbytes = -1 ignores maxbytes and relies on NULL terminator (\0) | ||
1052 | * to terminate the string | ||
1050 | */ | 1053 | */ |
1051 | int font_getstringsize(const unsigned char *str, int *w, int *h, int fontnumber) | 1054 | int font_getstringnsize(const unsigned char *str, size_t maxbytes, int *w, int *h, int fontnum) |
1052 | { | 1055 | { |
1053 | struct font* pf = font_get(fontnumber); | 1056 | struct font* pf = font_get(fontnum); |
1057 | font_lock( fontnum, true ); | ||
1054 | unsigned short ch; | 1058 | unsigned short ch; |
1055 | int width = 0; | 1059 | int width = 0; |
1060 | size_t b = maxbytes - 1; | ||
1056 | 1061 | ||
1057 | font_lock( fontnumber, true ); | 1062 | for (str = utf8decode(str, &ch); ch != 0 && b < maxbytes; str = utf8decode(str, &ch), b--) |
1058 | for (str = utf8decode(str, &ch); ch != 0 ; str = utf8decode(str, &ch)) | ||
1059 | { | 1063 | { |
1060 | if (is_diacritic(ch, NULL)) | 1064 | if (is_diacritic(ch, NULL)) |
1061 | continue; | 1065 | continue; |
@@ -1067,10 +1071,18 @@ int font_getstringsize(const unsigned char *str, int *w, int *h, int fontnumber) | |||
1067 | *w = width; | 1071 | *w = width; |
1068 | if ( h ) | 1072 | if ( h ) |
1069 | *h = pf->height; | 1073 | *h = pf->height; |
1070 | font_lock( fontnumber, false ); | 1074 | font_lock( fontnum, false ); |
1071 | return width; | 1075 | return width; |
1072 | } | 1076 | } |
1073 | 1077 | ||
1078 | /* | ||
1079 | * Returns the stringsize of a given NULL terminated string. | ||
1080 | */ | ||
1081 | int font_getstringsize(const unsigned char *str, int *w, int *h, int fontnumber) | ||
1082 | { | ||
1083 | return font_getstringnsize(str, -1, w, h, fontnumber); | ||
1084 | } | ||
1085 | |||
1074 | /* ----------------------------------------------------------------- | 1086 | /* ----------------------------------------------------------------- |
1075 | * vim: et sw=4 ts=8 sts=4 tw=78 | 1087 | * vim: et sw=4 ts=8 sts=4 tw=78 |
1076 | */ | 1088 | */ |
diff --git a/firmware/include/strptokspn_r.h b/firmware/include/strptokspn_r.h new file mode 100644 index 0000000000..d565118190 --- /dev/null +++ b/firmware/include/strptokspn_r.h | |||
@@ -0,0 +1,26 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2022 William Wilgus | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | |||
23 | #ifndef __STRPTOKSPN_R_H__ | ||
24 | #define __STRPTOKSPN_R_H__ | ||
25 | const char *strptokspn_r(const char *ptr, const char *sep, size_t *len, const char **end); | ||
26 | #endif | ||