| 329 | } |
| 330 | |
| 331 | static char ** get_fields(char * line, int last) |
| 332 | { |
| 333 | int count = 0, ii; |
| 334 | char * pos; |
| 335 | |
| 336 | if (line == NULL || *line == 0) |
| 337 | { |
| 338 | return NULL; |
| 339 | } |
| 340 | |
| 341 | // count number of fields |
| 342 | count = 1; |
| 343 | pos = line; |
| 344 | while ((pos = strchr(pos, ',')) != NULL) |
| 345 | { |
| 346 | count++; |
| 347 | pos++; |
| 348 | } |
| 349 | if (last > 0 && count > last) |
| 350 | { |
| 351 | count = last; |
| 352 | } |
| 353 | char ** result = calloc(count + 1, sizeof(char*)); |
| 354 | pos = line; |
| 355 | for (ii = 0; ii < count - 1; ii++) |
| 356 | { |
| 357 | result[ii] = get_field(&pos); |
| 358 | } |
| 359 | result[ii] = pos != NULL ? strdup(pos) : NULL; |
| 360 | |
| 361 | return result; |
| 362 | } |
| 363 | |
| 364 | static int field_index(char ** fields, char * name) |
| 365 | { |
no test coverage detected