diff options
-rw-r--r-- | apps/plugins/lua/README | 2 | ||||
-rw-r--r-- | apps/plugins/lua/SOURCES | 2 | ||||
-rw-r--r-- | apps/plugins/lua/lobject.c | 66 | ||||
-rw-r--r-- | apps/plugins/lua/strcspn.c | 17 | ||||
-rw-r--r-- | apps/plugins/lua/strncat.c | 37 |
5 files changed, 39 insertions, 85 deletions
diff --git a/apps/plugins/lua/README b/apps/plugins/lua/README index 5b53eb354e..06cfd6f8f8 100644 --- a/apps/plugins/lua/README +++ b/apps/plugins/lua/README | |||
@@ -2,9 +2,7 @@ The following files are (with slight modifications for Rockbox) from dietlibc | |||
2 | version 0.31 which is licensed under the GPL version 2: | 2 | version 0.31 which is licensed under the GPL version 2: |
3 | 3 | ||
4 | gmtime.c | 4 | gmtime.c |
5 | strcspn.c | ||
6 | strftime.c | 5 | strftime.c |
7 | strncat.c | ||
8 | strpbrk.c | 6 | strpbrk.c |
9 | strtol.c | 7 | strtol.c |
10 | strtoul.c | 8 | strtoul.c |
diff --git a/apps/plugins/lua/SOURCES b/apps/plugins/lua/SOURCES index 3fea681a50..ff40046eb0 100644 --- a/apps/plugins/lua/SOURCES +++ b/apps/plugins/lua/SOURCES | |||
@@ -31,9 +31,7 @@ rocklib.c | |||
31 | rocklib_img.c | 31 | rocklib_img.c |
32 | tlsf_helper.c | 32 | tlsf_helper.c |
33 | fscanf.c | 33 | fscanf.c |
34 | strcspn.c | ||
35 | strftime.c | 34 | strftime.c |
36 | strncat.c | ||
37 | strpbrk.c | 35 | strpbrk.c |
38 | strtoul.c | 36 | strtoul.c |
39 | strtol.c | 37 | strtol.c |
diff --git a/apps/plugins/lua/lobject.c b/apps/plugins/lua/lobject.c index 62ad8e9359..a351ff41da 100644 --- a/apps/plugins/lua/lobject.c +++ b/apps/plugins/lua/lobject.c | |||
@@ -178,37 +178,49 @@ const char *luaO_pushfstring (lua_State *L, const char *fmt, ...) { | |||
178 | return msg; | 178 | return msg; |
179 | } | 179 | } |
180 | 180 | ||
181 | /* lua 5.2 lobject.c,v 2.58.1.1 2013/04/12 18:48:47 roberto Exp $ */ | ||
182 | /* number of chars of a literal string without the ending \0 */ | ||
183 | #define LL(x) (sizeof(x)/sizeof(char) - 1) | ||
184 | |||
185 | #define RETS "..." | ||
186 | #define PRE "[string \"" | ||
187 | #define POS "\"]" | ||
188 | |||
189 | #define addstr(a,b,l) ( memcpy(a,b,(l) * sizeof(char)), a += (l) ) | ||
181 | 190 | ||
182 | void luaO_chunkid (char *out, const char *source, size_t bufflen) { | 191 | void luaO_chunkid (char *out, const char *source, size_t bufflen) { |
183 | if (*source == '=') { | 192 | size_t l = strlen(source); |
184 | strncpy(out, source+1, bufflen); /* remove first char */ | 193 | if (*source == '=') { /* 'literal' source */ |
185 | out[bufflen-1] = '\0'; /* ensures null termination */ | 194 | if (l <= bufflen) /* small enough? */ |
195 | memcpy(out, source + 1, l * sizeof(char)); | ||
196 | else { /* truncate it */ | ||
197 | addstr(out, source + 1, bufflen - 1); | ||
198 | *out = '\0'; | ||
199 | } | ||
186 | } | 200 | } |
187 | else { /* out = "source", or "...source" */ | 201 | else if (*source == '@') { /* file name */ |
188 | if (*source == '@') { | 202 | if (l <= bufflen) /* small enough? */ |
189 | size_t l; | 203 | memcpy(out, source + 1, l * sizeof(char)); |
190 | source++; /* skip the `@' */ | 204 | else { /* add '...' before rest of name */ |
191 | bufflen -= sizeof(" '...' "); | 205 | addstr(out, RETS, LL(RETS)); |
192 | l = strlen(source); | 206 | bufflen -= LL(RETS); |
193 | strcpy(out, ""); | 207 | memcpy(out, source + 1 + l - bufflen, bufflen * sizeof(char)); |
194 | if (l > bufflen) { | ||
195 | source += (l-bufflen); /* get last part of file name */ | ||
196 | strcat(out, "..."); | ||
197 | } | ||
198 | strcat(out, source); | ||
199 | } | 208 | } |
200 | else { /* out = [string "string"] */ | 209 | } |
201 | size_t len = strcspn(source, "\n\r"); /* stop at first newline */ | 210 | else { /* string; format as [string "source"] */ |
202 | bufflen -= sizeof(" [string \"...\"] "); | 211 | const char *nl = strchr(source, '\n'); /* find first new line (if any) */ |
203 | if (len > bufflen) len = bufflen; | 212 | addstr(out, PRE, LL(PRE)); /* add prefix */ |
204 | strcpy(out, "[string \""); | 213 | bufflen -= LL(PRE RETS POS) + 1; /* save space for prefix+suffix+'\0' */ |
205 | if (source[len] != '\0') { /* must truncate? */ | 214 | if (l < bufflen && nl == NULL) { /* small one-line source? */ |
206 | strncat(out, source, len); | 215 | addstr(out, source, l); /* keep it */ |
207 | strcat(out, "..."); | ||
208 | } | ||
209 | else | ||
210 | strcat(out, source); | ||
211 | strcat(out, "\"]"); | ||
212 | } | 216 | } |
217 | else { | ||
218 | if (nl != NULL) l = nl - source; /* stop at first newline */ | ||
219 | if (l > bufflen) l = bufflen; | ||
220 | addstr(out, source, l); | ||
221 | addstr(out, RETS, LL(RETS)); | ||
222 | } | ||
223 | memcpy(out, POS, (LL(POS) + 1) * sizeof(char)); | ||
213 | } | 224 | } |
214 | } | 225 | } |
226 | |||
diff --git a/apps/plugins/lua/strcspn.c b/apps/plugins/lua/strcspn.c deleted file mode 100644 index 0a19eaebf2..0000000000 --- a/apps/plugins/lua/strcspn.c +++ /dev/null | |||
@@ -1,17 +0,0 @@ | |||
1 | #include "rocklibc.h" | ||
2 | |||
3 | #undef strcspn | ||
4 | size_t strcspn(const char *s, const char *reject) | ||
5 | { | ||
6 | size_t l=0; | ||
7 | int a=1,i,al=strlen(reject); | ||
8 | |||
9 | while((a)&&(*s)) | ||
10 | { | ||
11 | for(i=0;(a)&&(i<al);i++) | ||
12 | if (*s==reject[i]) a=0; | ||
13 | if (a) l++; | ||
14 | s++; | ||
15 | } | ||
16 | return l; | ||
17 | } | ||
diff --git a/apps/plugins/lua/strncat.c b/apps/plugins/lua/strncat.c deleted file mode 100644 index 147397440a..0000000000 --- a/apps/plugins/lua/strncat.c +++ /dev/null | |||
@@ -1,37 +0,0 @@ | |||
1 | #include "rocklibc.h" | ||
2 | |||
3 | /* gcc is broken and has a non-SUSv2 compliant internal prototype. | ||
4 | * This causes it to warn about a type mismatch here. Ignore it. */ | ||
5 | char *strncat(char *s, const char *t, size_t n) { | ||
6 | char *dest=s; | ||
7 | register char *max; | ||
8 | s+=strlen(s); | ||
9 | if (__unlikely((max=s+n)==s)) goto fini; | ||
10 | for (;;) { | ||
11 | if (__unlikely(!(*s = *t))) | ||
12 | break; | ||
13 | if (__unlikely(++s==max)) | ||
14 | break; | ||
15 | ++t; | ||
16 | #ifndef WANT_SMALL_STRING_ROUTINES | ||
17 | if (__unlikely(!(*s = *t))) | ||
18 | break; | ||
19 | if (__unlikely(++s==max)) | ||
20 | break; | ||
21 | ++t; | ||
22 | if (__unlikely(!(*s = *t))) | ||
23 | break; | ||
24 | if (__unlikely(++s==max)) | ||
25 | break; | ||
26 | ++t; | ||
27 | if (__unlikely(!(*s = *t))) | ||
28 | break; | ||
29 | if (__unlikely(++s==max)) | ||
30 | break; | ||
31 | ++t; | ||
32 | #endif | ||
33 | } | ||
34 | *s=0; | ||
35 | fini: | ||
36 | return dest; | ||
37 | } | ||