returned *arrIdx will be the real index in the data structure, i.e. named index - arrNameOffset
| 203 | |
| 204 | // returned *arrIdx will be the real index in the data structure, i.e. named index - arrNameOffset |
| 205 | int FrameMetaInfo::findField(const char*fieldName, int *arrIdx, int *more) const |
| 206 | { |
| 207 | if (fieldName == NULL) |
| 208 | return -1; |
| 209 | // check for [] in _fieldName => array field |
| 210 | long ai = 0; |
| 211 | char *fn = strdup(fieldName); |
| 212 | char *a = strchr(fn, '['); |
| 213 | if (a != NULL) { // yes, array |
| 214 | a[0] = 0; |
| 215 | a++; |
| 216 | char *b = strchr(a, ']'); |
| 217 | if (b == NULL) { |
| 218 | COMP_ERR("findField: invalid array field name " |
| 219 | "'%s', expected ']' at the end!", fieldName); |
| 220 | } |
| 221 | b[0] = 0; |
| 222 | char *eptr = NULL; |
| 223 | ai = strtol(a, &eptr, 10); |
| 224 | if ((ai == 0) && (eptr == a)) { |
| 225 | COMP_ERR("findField: error parsing array index in " |
| 226 | "name '%s', index is not a number!",fieldName); |
| 227 | } |
| 228 | } |
| 229 | if (arrIdx != NULL) |
| 230 | *arrIdx = ai; |
| 231 | |
| 232 | int i; |
| 233 | int idx = -1; |
| 234 | int start = 0; |
| 235 | if ((more != NULL) && (*more>0)) { |
| 236 | start = *more; |
| 237 | *more = 0; |
| 238 | } |
| 239 | int foundFlag = 0; |
| 240 | for (i=start; i<N; i++) { |
| 241 | int myAi; |
| 242 | if (!foundFlag) { |
| 243 | if (a != NULL) // array name |
| 244 | myAi = ai - field[i].arrNameOffset; |
| 245 | else // non array name (first field of array, always index 0 in data structure) |
| 246 | myAi = 0; |
| 247 | } |
| 248 | if (!strcmp(fn,field[i].name)) { |
| 249 | if (!foundFlag) { |
| 250 | idx = i; |
| 251 | if (myAi < field[i].N) { |
| 252 | //idx = field[i].Nstart + myAi; |
| 253 | if (arrIdx != NULL) *arrIdx = myAi; // update *arrIdx with correct index (real index in data structure, not 'named' index) |
| 254 | if (more == NULL) break; |
| 255 | else foundFlag=1; |
| 256 | } else { |
| 257 | COMP_ERR("array index out of bounds (field '%s') %i > %i (must from %i - %i) (NOTE: first index is 0, not 1!)",fieldName,ai,field[i].N-1+field[N].arrNameOffset,field[N].arrNameOffset,field[i].N-1+field[N].arrNameOffset); |
| 258 | } |
| 259 | } else { |
| 260 | if (more != NULL) (*more)++; |
| 261 | } |
| 262 | } |