Browse Source

correct usage of strtok_r on non-AVR archs

feature/2015
Christian Kroll 16 years ago
parent
commit
a8596768d9
  1. 25
      scrolltext/scrolltext3.c

25
scrolltext/scrolltext3.c

@ -18,10 +18,6 @@
font fonts[MAX_FONTS];
#define MAX_SPECIALCOLORS 3
#ifndef AVR
#define strtok_r(s,d,l) strtok(s,d)
#endif
unsigned char PROGMEM colorTable[MAX_SPECIALCOLORS*NUM_ROWS] = {1, 1, 2, 3, 3, 2, 1, 1,
3, 3, 2, 1, 1, 2, 3, 3,
3, 3, 2, 2, 3, 3, 2, 2
@ -284,7 +280,18 @@ unsigned char blobNextCommand(blob_t * blob){
blob_t * setupBlob(char * str){
/*char * strtok_r ( char * string, const char * delim, char ** last)*/
#ifndef AVR
// strtok_r must not be used on string literals so we copy the string to
// the heap (at least on non-AVR based processors)
int n;
char *scrolltext = NULL;
if ((str != NULL) && ((n = (strlen(str))) != 0)) {
scrolltext = malloc(n + 1);
strcpy(scrolltext, str);
str = scrolltext;
}
#endif
static unsigned char chop_cnt;
static char *last; static char delim[] = "#";
static char *lastcommands;
@ -298,6 +305,7 @@ blob_t * setupBlob(char * str){
if(!chop_cnt){
blob->commands = strtok_r (str, delim, &last);
if( blob->commands == 0) goto fail;
if((tmp = getnum(blob)) != 0xFFFF){
@ -361,6 +369,13 @@ blob_t * setupBlob(char * str){
fail:
free(blob);
#ifndef AVR
if (scrolltext != NULL) {
free(scrolltext);
}
#endif
return 0;//no more blobs to parse
}

Loading…
Cancel
Save