Skip to content
Snippets Groups Projects
Commit d4f5ab77 authored by Cédric Roux's avatar Cédric 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
No related branches found
No related tags found
No related merge requests found
...@@ -28,7 +28,7 @@ typedef struct { ...@@ -28,7 +28,7 @@ typedef struct {
int isize; int isize;
group *g; group *g;
int gsize; int gsize;
int *pos; int *id_to_pos;
} database; } database;
typedef struct { typedef struct {
...@@ -326,10 +326,11 @@ void *parse_database(char *filename) ...@@ -326,10 +326,11 @@ void *parse_database(char *filename)
free(p.name.data); free(p.name.data);
free(p.value.data); free(p.value.data);
/* setup pos */ /* setup id_to_pos */
r->pos = malloc(sizeof(int) * r->isize); if (r->pos == NULL) abort(); r->id_to_pos = malloc(sizeof(int) * r->isize);
if (r->id_to_pos == NULL) abort();
for (i = 0; i < r->isize; i++) 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; return r;
} }
...@@ -420,7 +421,7 @@ void on_off(void *_d, char *item, int *a, int onoff) ...@@ -420,7 +421,7 @@ void on_off(void *_d, char *item, int *a, int onoff)
char *event_name_from_id(void *_database, int id) char *event_name_from_id(void *_database, int id)
{ {
database *d = _database; 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) int event_id_from_name(void *_database, char *name)
...@@ -442,9 +443,9 @@ database_event_format get_format(void *_database, int event_id) ...@@ -442,9 +443,9 @@ database_event_format get_format(void *_database, int event_id)
abort(); abort();
} }
ret.type = d->i[d->pos[event_id]].arg_type; ret.type = d->i[d->id_to_pos[event_id]].arg_type;
ret.name = d->i[d->pos[event_id]].arg_name; ret.name = d->i[d->id_to_pos[event_id]].arg_name;
ret.count = d->i[d->pos[event_id]].asize; ret.count = d->i[d->id_to_pos[event_id]].asize;
return ret; return ret;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment