cnlohr / esp82xx

Useful ESP8266 C Environment
Other
288 stars 107 forks source link

Improve mechanism for command parsing #5

Closed cnlohr closed 8 years ago

cnlohr commented 8 years ago

Right now, we are using things like:

char * des = nam ? (char *)ets_strstr( (char*)(nam+1), "\t" ) : 0;

which is just awful to be used so many places. We should write our own, perhaps where it also re-writes the byte to be a null and advances the pointer by reference?

i.e.

char * CaptureAndAdvance( char ** data );

Called in the following way:

    char * nam = CaptureAndAdvance( &pusrdata );
    char * des = CaptureAndAdvance( &pusrdata );

This will produce much smaller code and I think it's easier to read.

cnlohr commented 8 years ago

Maybe another parameter, "ERR" or something?

cnlohr commented 8 years ago

Ok. This is complete.

char * parameters;  <<set global variable before using parameter popping
uint8_t  paramcount; <<Set this to 0 before doing parameter popping
int MyNum = ParamCaptureAndAdvanceInt();
int MyVar = ParamCaptureAndAdvance();
con-f-use commented 8 years ago

/tmp/ccnbGE4K.o (symbol from plugin):(.text+0x0): first defined here esp82xx/fwsrc/esp82xxutil.c:281:40: error: 'memchr' has already been defined const ICACHE_FLASH_ATTR unsigned char memchr(const unsigned char s, int c, size_t n) ^ esp82xx/fwsrc/esp82xxutil.c:281:40: note: previously defined here const ICACHE_FLASH_ATTR unsigned char memchr(const unsigned char s, int c, size_t n) ^ esp82xx/fwsrc/esp82xxutil.c:217:26: error: 'strdup' has already been defined char * ICACHE_FLASH_ATTR strdup( const char * src ) ^ esp82xx/fwsrc/esp82xxutil.c:217:26: note: previously defined here char * ICACHE_FLASH_ATTR strdup( const char * src ) ^ lto1: fatal error: errors during merging of translation units compilation terminated.

You seem to have some multiply defined functions. Here is the full error message. Don't have time to look at it right now.

Edit: Nevermind, error went away. No idea why. Will leave this here for future reference if it resurfaces.