mirror of
https://github.com/mariusgreuel/avrdude.git
synced 2025-09-27 14:35:27 +00:00
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/avrdude@724 81a1dc3b-b13d-400b-aceb-764788c761c2
This commit is contained in:
46
main.c
46
main.c
@@ -64,6 +64,12 @@ char progbuf[PATH_MAX]; /* temporary buffer of spaces the same
|
||||
length as progname; used for lining up
|
||||
multiline messages */
|
||||
|
||||
struct list_walk_cookie
|
||||
{
|
||||
FILE *f;
|
||||
const char *prefix;
|
||||
};
|
||||
|
||||
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. */
|
||||
}
|
||||
|
||||
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
|
||||
*/
|
||||
|
Reference in New Issue
Block a user