19 #include <epicsTypes.h> 20 #include <epicsString.h> 23 #define epicsExportSharedSymbols 27 # define HUGE_VALF HUGE_VAL 30 # define HUGE_VALL (-(HUGE_VAL)) 39 store_value(
const linkOptionDef* opt,
void* user,
const char* val,
int options)
42 unsigned long int lival;
53 if (opt->
size<
sizeof(epicsUInt32)) {
54 fprintf(stderr,
"Provide storage (%u bytes) is too small for Int32 (%lu)\n",
55 opt->
size, (
unsigned long)
sizeof(epicsUInt32));
58 ival=(epicsUInt32*)( (
char*)user + opt->
offset );
60 lival = strtoul(val, &end, 0);
62 if ( lival==ULONG_MAX || end==val )
64 fprintf(stderr,
"value %s can't be converted for integer key %s\n",val,opt->
name);
68 *ival = (epicsUInt32)lival;
72 if (opt->
size<
sizeof(
double)) {
73 fprintf(stderr,
"Provide storage (%u bytes) is too small for double (%lu)\n",
74 opt->
size, (
unsigned long)
sizeof(
double));
77 dval=(
double*)( (
char*)user + opt->
offset );
79 *dval = strtod(val, &end);
83 fprintf(stderr,
"value %s can't be converted for double key %s\n",val,opt->
name);
88 if (opt->
size<
sizeof(
int)) {
89 fprintf(stderr,
"Provide storage (%u bytes) is too small for enum (%lu)\n",
90 opt->
size, (
unsigned long)
sizeof(
int));
93 eval=(
int*)( (
char*)user + opt->
offset );
95 for(emap=opt->
Enums; emap && emap->
name; emap++) {
96 if ( strcmp(emap->
name, val)==0 ) {
102 if( !emap || !emap->
name ) {
103 fprintf(stderr,
"%s is not a valid value for the Enum %s\n",
110 if (opt->
size<
sizeof(
char*)) {
114 fprintf(stderr,
"Provide storage (%u bytes) is too small for string (>= %lu)\n",
115 opt->
size, (
unsigned long)
sizeof(
char*));
118 sval=( (
char*)user + opt->
offset );
120 strncpy(sval, val, opt->
size-1);
121 sval[opt->
size-1]=
'\0';
124 fprintf(stderr,
"Can't store \'%s\' for %s as the storage type is not defined\n",
143 char **pairs=NULL, **arg;
145 for(i=0, cur=opts; cur && cur->
name; i++, cur++) {}
148 found=calloc( (i/32)+1,
sizeof(epicsUInt32) );
150 fprintf(stderr,
"store_options: calloc failed\n");
155 memset((
void*)&handle, 0,
sizeof(handle));
168 if (macParseDefns(&handle, str, &pairs)<0) {
173 for (arg=pairs; arg && arg[0]; arg+=2) {
176 if (options&LINKOPTIONDEBUG)
177 printf(
"key %s\n",arg[0]);
179 for (i=0, cur=opts; !match && cur && cur->
name; i++, cur++) {
181 if (options&LINKOPTIONDEBUG)
182 fprintf(stderr,
"For option: %s\n",cur->
name);
184 if( strcmp(arg[0], cur->
name)!=0 )
188 if (found[i/32]&(1<<(i%32)) && !cur->
overwrite) {
189 fprintf(stderr,
"Option %s was already given\n",cur->
name);
194 found[i/32] |= 1<<(i%32);
196 status=store_value(cur, user, arg[1], options);
202 printf(
"Warning: ignoring unknown INP/OUT option %s=\n", arg[0]);
206 for (i=0, cur=opts; cur && cur->
name; i++, cur++) {
208 if ( !(found[i/32]&(1<<(i%32))) && cur->
required ) {
209 fprintf(stderr,
"Missing required option %s\n",cur->
name);
228 for(; emap && emap->
name; emap++) {
229 if ( i == emap->
value ) {
epicsShareFunc const char *epicsShareAPI linkOptionsEnumString(const linkOptionEnumType *emap, int i, const char *def)
Return the string associated with Enum 'i'.
int epicsShareAPI linkOptionsStore(const linkOptionDef *opts, void *user, const char *str, int options)
Parse a string a store the result.
const linkOptionEnumType * Enums
Hardware link parsing and storage.