correct usage of strtok_r on non-AVR archs

This commit is contained in:
Christian Kroll 2009-08-01 22:56:32 +00:00
parent d90b187a2f
commit a8596768d9
1 changed files with 82 additions and 67 deletions

View File

@ -18,10 +18,6 @@
font fonts[MAX_FONTS]; font fonts[MAX_FONTS];
#define MAX_SPECIALCOLORS 3 #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, 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, 1, 1, 2, 3, 3,
3, 3, 2, 2, 3, 3, 2, 2 3, 3, 2, 2, 3, 3, 2, 2
@ -284,7 +280,18 @@ unsigned char blobNextCommand(blob_t * blob){
blob_t * setupBlob(char * str){ 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 unsigned char chop_cnt;
static char *last; static char delim[] = "#"; static char *last; static char delim[] = "#";
static char *lastcommands; static char *lastcommands;
@ -298,6 +305,7 @@ blob_t * setupBlob(char * str){
if(!chop_cnt){ if(!chop_cnt){
blob->commands = strtok_r (str, delim, &last); blob->commands = strtok_r (str, delim, &last);
if( blob->commands == 0) goto fail; if( blob->commands == 0) goto fail;
if((tmp = getnum(blob)) != 0xFFFF){ if((tmp = getnum(blob)) != 0xFFFF){
@ -361,6 +369,13 @@ blob_t * setupBlob(char * str){
fail: fail:
free(blob); free(blob);
#ifndef AVR
if (scrolltext != NULL) {
free(scrolltext);
}
#endif
return 0;//no more blobs to parse return 0;//no more blobs to parse
} }