avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [avr-gcc-list] Strings and structures in program memory


From: Trampas
Subject: RE: [avr-gcc-list] Strings and structures in program memory
Date: Fri, 1 Dec 2006 13:58:44 -0500

Thanks for the information. Is there anyway to do this without declaring
each string external from the array? 

Trampas

-----Original Message-----
From: Eric Weddington [mailto:address@hidden 
Sent: Friday, December 01, 2006 11:55 AM
To: 'Trampas'; 'AVR GCC List'
Subject: RE: [avr-gcc-list] Strings and structures in program memory


Avr-libc FAQ #14:
<http://www.nongnu.org/avr-libc/user-manual/FAQ.html#faq_rom_array> 


> -----Original Message-----
> From: 
> address@hidden 
> [mailto:address@hidden
> org] On Behalf Of Trampas
> Sent: Friday, December 01, 2006 9:43 AM
> To: 'AVR GCC List'
> Subject: [avr-gcc-list] Strings and structures in program memory
> 
> I am trying to create a simple command processor and was 
> trying to figure out how to get strings and even the commands 
> structure to live and operate from program memory. Can anyone 
> show me how to do this?
> 
>  
> 
> #define COMMAND(NAME, help)  { PSTR( #NAME ), NAME ## _cmd, 
> PSTR( help ) }
> 
>  
> 
> //Command structure
> 
> struct Command
> 
> {
> 
>             PSTR name;
> 
>             int (*function) (int, char **);
> 
>             PSTR help;
> 
> };
> 
>  
> 
> //Prototypes
> 
> int help_cmd(int, char **);
> 
> int exit_cmd(int, char **);
> 
>  
> 
> //List of supported commands
> 
> struct Command commands[] =
> 
> {
> 
>             {PSTR("help"), help_cmd, PSTR("help")}, //COMMAND 
> (help, "Prints this message"),
> 
>             {PSTR("exit"), exit_cmd, PSTR("exit")},//COMMAND 
> (exit, "Exits command mode"),           
> 
>             {PSTR(""),0,PSTR("")}, //End of list signal
> 
> };
> 
>  
> 
> Then to parse commands I was trying:
> 
>  
> 
>             //now let's parse the command
> 
>             i=0;
> 
>             while(strlen_P(commands[i].name)!=0)
> 
>             {
> 
>                         if (strcmp_P(buff,commands[i].name)==0)
> 
>                                     return 
> (*commands[i].function)(numArgs,ptrArgv);
> 
>                         i=i+1;
> 
>             }
> 
>  
> 
> However this does not seem to work. 
> 
>  
> 
> Thanks 
> 
> Trampas
> 
>  
> 
>  
> 
> 





reply via email to

[Prev in Thread] Current Thread [Next in Thread]