My Project
|
Hardware link parsing and storage. More...
#include <shareLib.h>
#include <dbDefs.h>
#include <epicsTypes.h>
Go to the source code of this file.
Functions | |
epicsShareFunc int epicsShareAPI | linkOptionsStore (const linkOptionDef *opts, void *user, const char *str, int options) |
Parse a string a store the result. More... | |
epicsShareFunc const char *epicsShareAPI | linkOptionsEnumString (const linkOptionEnumType *Enums, int i, const char *def) |
Return the string associated with Enum 'i'. More... | |
Hardware link parsing and storage.
Utility to parse a macLib style string ('key=val, key2=val2') and store the results directly into a user supplied struture after appropriate type conversion.
Before calling linkOptionsStore() a linkOptionDef structure must be defined for the user structure.
For example:
typedef struct myStruct { ... other stuff epicsUInt32 ival; double dval; epicsUInt32 ival2; int enumval; char strval[20]; } myStruct;
static const linkOptionEnumType colorEnum[] = { {"Red",1}, {"Green",2}, {"Blue",3}, {NULL,0} };
static const linkOptionDef myStructDef[] = { linkInt32 (myStruct, ival, "Integer" , 0, 0), linkInt32 (myStruct, ival2, "Second" , 1, 0), linkDouble(myStruct, dval, "Double" , 1, 0), linkString(myStruct, strval , "String" , 1, 0), linkEnum (myStruct, enumval, "Color" , 1, 0, colorEnum), linkOptionEnd };
Note: The 4th argument is required (1) or optional (0), the 5th whether later definitions override previous ones (1), or are an error (0).
void someFunc(const char *arg) { myStruct mine;
memset(&mine, 0, sizeof(myStruct)); // set defaults
if (linkOptionsStore(myStructDef, &mine, arg, 0)) goto error;
printf("Second=%d\n",mine->ival2); }
Would parse the string 'Second=17, Color=Green, String=Hello world, Double=4.2' and assign ival2=17, dval=4.2, enumval=2, strval="Hello world". ival is not required and since 'Integer' was not specified would not remain unchanged.
epicsShareFunc int epicsShareAPI linkOptionsStore | ( | const linkOptionDef * | opts, |
void * | user, | ||
const char * | str, | ||
int | options | ||
) |
Parse a string a store the result.
Takes the string 'str', parses it according to 'opts', then sorts the result in 'user'.
opts | A null-terminated array of options. |
user | Pointer to a structure whos member offsets are given in 'opts' |
str | The string to parse |
options | Some modifiers for the parsing process or 0. The only option is LINKOPTIONDEBUG. |
epicsShareFunc const char* epicsShareAPI linkOptionsEnumString | ( | const linkOptionEnumType * | Enums, |
int | i, | ||
const char * | def | ||
) |
Return the string associated with Enum 'i'.
Enums | A null-terminated array of string/integer pairs |
i | An Enum index |
def | String to be returned in 'i' isn't a valid Enum index. |