More backend/library abstraction and generalization: turn the
list_parts() and list_programmers() functions into general list iteration functions that call a caller-supplied callback for each element. Implement list_parts() and list_programmers() as private functions in main.c based on that approach. git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk@724 81a1dc3b-b13d-400b-aceb-764788c761c2
This commit is contained in:
parent
a3349385d6
commit
2a7aeaa742
|
@ -1,3 +1,16 @@
|
||||||
|
2007-01-29 Joerg Wunsch <j@uriah.heep.sax.de>
|
||||||
|
|
||||||
|
* avrpart.c: More backend/library abstraction and generalization:
|
||||||
|
turn the list_parts() and list_programmers() functions into
|
||||||
|
general list iteration functions that call a caller-supplied
|
||||||
|
callback for each element. Implement list_parts() and
|
||||||
|
list_programmers() as private functions in main.c based on that
|
||||||
|
approach.
|
||||||
|
* avrpart.h: (Ditto.)
|
||||||
|
* main.c: (Ditto.)
|
||||||
|
* pgm.c: (Ditto.)
|
||||||
|
* pgm.h: (Ditto.)
|
||||||
|
|
||||||
2007-01-25 Joerg Wunsch <j@uriah.heep.sax.de>
|
2007-01-25 Joerg Wunsch <j@uriah.heep.sax.de>
|
||||||
|
|
||||||
* Makefile.am: Rearrange everything so it is now built into a
|
* Makefile.am: Rearrange everything so it is now built into a
|
||||||
|
|
|
@ -434,21 +434,29 @@ AVRPART * locate_part_by_avr910_devcode(LISTID parts, int devcode)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void list_parts(FILE * f, char * prefix, LISTID parts)
|
/*
|
||||||
|
* Iterate over the list of avrparts given as "avrparts", and
|
||||||
|
* call the callback function cb for each entry found. cb is being
|
||||||
|
* passed the following arguments:
|
||||||
|
* . the name of the avrpart (for -p)
|
||||||
|
* . the descriptive text given in the config file
|
||||||
|
* . the name of the config file this avrpart has been defined in
|
||||||
|
* . the line number of the config file this avrpart has been defined at
|
||||||
|
* . the "cookie" passed into walk_avrparts() (opaque client data)
|
||||||
|
*/
|
||||||
|
void walk_avrparts(LISTID avrparts, walk_avrparts_cb cb, void *cookie)
|
||||||
{
|
{
|
||||||
LNODEID ln1;
|
LNODEID ln1;
|
||||||
AVRPART * p;
|
AVRPART * p;
|
||||||
|
|
||||||
for (ln1=lfirst(parts); ln1; ln1=lnext(ln1)) {
|
for (ln1 = lfirst(avrparts); ln1; ln1 = lnext(ln1)) {
|
||||||
p = ldata(ln1);
|
p = ldata(ln1);
|
||||||
fprintf(f, "%s%-4s = %-15s [%s:%d]\n",
|
cb(p->id, p->desc, p->config_file, p->lineno, cookie);
|
||||||
prefix, p->id, p->desc, p->config_file, p->lineno);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static char * reset_disp_str(int r)
|
static char * reset_disp_str(int r)
|
||||||
{
|
{
|
||||||
switch (r) {
|
switch (r) {
|
||||||
|
|
|
@ -204,9 +204,13 @@ AVRPART * avr_new_part(void);
|
||||||
AVRPART * avr_dup_part(AVRPART * d);
|
AVRPART * avr_dup_part(AVRPART * d);
|
||||||
AVRPART * locate_part(LISTID parts, char * partdesc);
|
AVRPART * locate_part(LISTID parts, char * partdesc);
|
||||||
AVRPART * locate_part_by_avr910_devcode(LISTID parts, int devcode);
|
AVRPART * locate_part_by_avr910_devcode(LISTID parts, int devcode);
|
||||||
void list_parts(FILE * f, char * prefix, LISTID parts);
|
|
||||||
void avr_display(FILE * f, AVRPART * p, char * prefix, int verbose);
|
void avr_display(FILE * f, AVRPART * p, char * prefix, int verbose);
|
||||||
|
|
||||||
|
typedef void (*walk_avrparts_cb)(const char *name, const char *desc,
|
||||||
|
const char *cfgname, int cfglineno,
|
||||||
|
void *cookie);
|
||||||
|
void walk_avrparts(LISTID programmers, walk_avrparts_cb cb, void *cookie);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -64,6 +64,12 @@ char progbuf[PATH_MAX]; /* temporary buffer of spaces the same
|
||||||
length as progname; used for lining up
|
length as progname; used for lining up
|
||||||
multiline messages */
|
multiline messages */
|
||||||
|
|
||||||
|
struct list_walk_cookie
|
||||||
|
{
|
||||||
|
FILE *f;
|
||||||
|
const char *prefix;
|
||||||
|
};
|
||||||
|
|
||||||
static LISTID updates;
|
static LISTID updates;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -173,6 +179,46 @@ static void update_progress_no_tty (int percent, double etime, char *hdr)
|
||||||
last = (percent>>1)*2; /* Make last a multiple of 2. */
|
last = (percent>>1)*2; /* Make last a multiple of 2. */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void list_programmers_callback(const char *name, const char *desc,
|
||||||
|
const char *cfgname, int cfglineno,
|
||||||
|
void *cookie)
|
||||||
|
{
|
||||||
|
struct list_walk_cookie *c = (struct list_walk_cookie *)cookie;
|
||||||
|
|
||||||
|
fprintf(c->f, "%s%-8s = %-30s [%s:%d]\n",
|
||||||
|
c->prefix, name, desc, cfgname, cfglineno);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void list_programmers(FILE * f, const char *prefix, LISTID programmers)
|
||||||
|
{
|
||||||
|
struct list_walk_cookie c;
|
||||||
|
|
||||||
|
c.f = f;
|
||||||
|
c.prefix = prefix;
|
||||||
|
|
||||||
|
walk_programmers(programmers, list_programmers_callback, &c);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void list_avrparts_callback(const char *name, const char *desc,
|
||||||
|
const char *cfgname, int cfglineno,
|
||||||
|
void *cookie)
|
||||||
|
{
|
||||||
|
struct list_walk_cookie *c = (struct list_walk_cookie *)cookie;
|
||||||
|
|
||||||
|
fprintf(c->f, "%s%-4s = %-15s [%s:%d]\n",
|
||||||
|
c->prefix, name, desc, cfgname, cfglineno);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void list_parts(FILE * f, const char *prefix, LISTID avrparts)
|
||||||
|
{
|
||||||
|
struct list_walk_cookie c;
|
||||||
|
|
||||||
|
c.f = f;
|
||||||
|
c.prefix = prefix;
|
||||||
|
|
||||||
|
walk_avrparts(avrparts, list_avrparts_callback, &c);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* main routine
|
* main routine
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -199,17 +199,24 @@ PROGRAMMER * locate_programmer(LISTID programmers, char * configid)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void list_programmers(FILE * f, char * prefix, LISTID programmers)
|
/*
|
||||||
|
* Iterate over the list of programmers given as "programmers", 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)
|
||||||
|
*/
|
||||||
|
void walk_programmers(LISTID programmers, walk_programmers_cb cb, void *cookie)
|
||||||
{
|
{
|
||||||
LNODEID ln1;
|
LNODEID ln1;
|
||||||
PROGRAMMER * p;
|
PROGRAMMER * p;
|
||||||
|
|
||||||
for (ln1=lfirst(programmers); ln1; ln1=lnext(ln1)) {
|
for (ln1 = lfirst(programmers); ln1; ln1 = lnext(ln1)) {
|
||||||
p = ldata(ln1);
|
p = ldata(ln1);
|
||||||
fprintf(f, "%s%-8s = %-30s [%s:%d]\n",
|
cb((char *)ldata(lfirst(p->id)), p->desc, p->config_file, p->lineno, cookie);
|
||||||
prefix, (char *)ldata(lfirst(p->id)), p->desc,
|
|
||||||
p->config_file, p->lineno);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -112,7 +112,11 @@ PROGRAMMER * pgm_new(void);
|
||||||
|
|
||||||
void programmer_display(PROGRAMMER * pgm, char * p);
|
void programmer_display(PROGRAMMER * pgm, char * p);
|
||||||
PROGRAMMER * locate_programmer(LISTID programmers, char * configid);
|
PROGRAMMER * locate_programmer(LISTID programmers, char * configid);
|
||||||
void list_programmers(FILE * f, char * prefix, LISTID programmers);
|
|
||||||
|
typedef void (*walk_programmers_cb)(const char *name, const char *desc,
|
||||||
|
const char *cfgname, int cfglineno,
|
||||||
|
void *cookie);
|
||||||
|
void walk_programmers(LISTID programmers, walk_programmers_cb cb, void *cookie);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue