Commit d4f5ab77 authored by Cedric Roux's avatar Cedric Roux
Browse files

clarify "pos" in database.c

the list of IDs is stored alphabetically so when accessing the database
with an ID one needs an indirection to get the correct record.
"pos" was not clear. "id_to_pos" is clearer.
parent e54f87a0
......@@ -28,7 +28,7 @@ typedef struct {
int isize;
group *g;
int gsize;
int *pos;
int *id_to_pos;
} database;
typedef struct {
......@@ -326,10 +326,11 @@ void *parse_database(char *filename)
free(p.name.data);
free(p.value.data);
/* setup pos */
r->pos = malloc(sizeof(int) * r->isize); if (r->pos == NULL) abort();
/* setup id_to_pos */
r->id_to_pos = malloc(sizeof(int) * r->isize);
if (r->id_to_pos == NULL) abort();
for (i = 0; i < r->isize; i++)
r->pos[r->i[i].id] = i;
r->id_to_pos[r->i[i].id] = i;
return r;
}
......@@ -420,7 +421,7 @@ void on_off(void *_d, char *item, int *a, int onoff)
char *event_name_from_id(void *_database, int id)
{
database *d = _database;
return d->i[d->pos[id]].name;
return d->i[d->id_to_pos[id]].name;
}
int event_id_from_name(void *_database, char *name)
......@@ -442,9 +443,9 @@ database_event_format get_format(void *_database, int event_id)
abort();
}
ret.type = d->i[d->pos[event_id]].arg_type;
ret.name = d->i[d->pos[event_id]].arg_name;
ret.count = d->i[d->pos[event_id]].asize;
ret.type = d->i[d->id_to_pos[event_id]].arg_type;
ret.name = d->i[d->id_to_pos[event_id]].arg_name;
ret.count = d->i[d->id_to_pos[event_id]].asize;
return ret;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment