My Project
Functions
linkoptions.h File Reference

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...
 

Detailed Description

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.

Function Documentation

◆ linkOptionsStore()

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'.

Parameters
optsA null-terminated array of options.
userPointer to a structure whos member offsets are given in 'opts'
strThe string to parse
optionsSome modifiers for the parsing process or 0. The only option is LINKOPTIONDEBUG.
Returns
0 Ok
-1 Fail ('user' may be partially modified)

◆ linkOptionsEnumString()

epicsShareFunc const char* epicsShareAPI linkOptionsEnumString ( const linkOptionEnumType *  Enums,
int  i,
const char *  def 
)

Return the string associated with Enum 'i'.

Parameters
EnumsA null-terminated array of string/integer pairs
iAn Enum index
defString to be returned in 'i' isn't a valid Enum index.
Returns
A constant string