diff --git a/src/pgm_type.c b/src/pgm_type.c index 91400fea..70d3ec81 100644 --- a/src/pgm_type.c +++ b/src/pgm_type.c @@ -111,29 +111,17 @@ const PROGRAMMER_TYPE programmers_types[] = { // Name(s) the programmers call th {"xbee", xbee_initpgm, xbee_desc}, // "XBee" }; -const PROGRAMMER_TYPE * locate_programmer_type(const char * id) -{ - const PROGRAMMER_TYPE * p = NULL; - int i; - int found; - - found = 0; - - for (i = 0; i < sizeof(programmers_types)/sizeof(programmers_types[0]) && !found; i++) { - p = &(programmers_types[i]); - if (strcasecmp(id, p->id) == 0) - found = 1; - } - - if (found) - return p; +const PROGRAMMER_TYPE *locate_programmer_type(const char *id) { + for(size_t i = 0; i < sizeof programmers_types/sizeof*programmers_types; i++) + if(strcasecmp(id, programmers_types[i].id) == 0) + return programmers_types + i; return NULL; } // Return type id given the init function or "" if not found const char *locate_programmer_type_id(void (*initpgm)(PROGRAMMER *pgm)) { - for (int i=0; i < sizeof programmers_types/sizeof*programmers_types; i++) + for(size_t i=0; i < sizeof programmers_types/sizeof*programmers_types; i++) if(programmers_types[i].initpgm == initpgm) return programmers_types[i].id; @@ -142,35 +130,15 @@ const char *locate_programmer_type_id(void (*initpgm)(PROGRAMMER *pgm)) { /* - * Iterate over the list of programmers given as "programmers", and - * call the callback function cb for each entry found. cb is being + * Iterate over the list of programmer types given in the table above and + * call the callback function cb for each entry found. cb is being * passed the following arguments: - * . the name of the programmer (for -c) - * . the descriptive text given in the config file - * . the name of the config file this programmer has been defined in - * . the line number of the config file this programmer has been defined at - * . the "cookie" passed into walk_programmers() (opaque client data) + * - Name of the programmer + * - Descriptive text + * - "Cookie" passed into walk_programmer_types() for opaque client data */ - /* -void walk_programmer_types(LISTID programmer_types, walk_programmer_types_cb cb, void *cookie) -{ - LNODEID ln1; - PROGRAMMER * p; - for (ln1 = lfirst(programmers); ln1; ln1 = lnext(ln1)) { - p = ldata(ln1); - cb(p->id, p->desc, cookie); - } - } -}*/ - -void walk_programmer_types(walk_programmer_types_cb cb, void *cookie) -{ - const PROGRAMMER_TYPE * p; - int i; - - for (i = 0; i < sizeof(programmers_types)/sizeof(programmers_types[0]); i++) { - p = &(programmers_types[i]); - cb(p->id, p->desc, cookie); - } +void walk_programmer_types(walk_programmer_types_cb cb, void *cookie) { + for (size_t i = 0; i < sizeof(programmers_types)/sizeof(programmers_types[0]); i++) + cb(programmers_types[i].id, programmers_types[i].desc, cookie); }