Commit 7dbb2b8c authored by Cedric Roux's avatar Cedric Roux

id management / bug fixes in database

parent f0a70414
...@@ -27,6 +27,7 @@ typedef struct { ...@@ -27,6 +27,7 @@ typedef struct {
int isize; int isize;
group *g; group *g;
int gsize; int gsize;
int *pos;
} database; } database;
typedef struct { typedef struct {
...@@ -324,6 +325,11 @@ void *parse_database(char *filename) ...@@ -324,6 +325,11 @@ void *parse_database(char *filename)
free(p.name.data); free(p.name.data);
free(p.value.data); free(p.value.data);
/* setup pos */
r->pos = malloc(sizeof(int) * r->isize); if (r->pos == NULL) abort();
for (i = 0; i < r->isize; i++)
r->pos[r->i[i].id] = i;
return r; return r;
} }
...@@ -410,6 +416,12 @@ void on_off(void *_d, char *item, int *a, int onoff) ...@@ -410,6 +416,12 @@ 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;
}
database_event_format get_format(void *_database, int event_id) database_event_format get_format(void *_database, int event_id)
{ {
database *d = _database; database *d = _database;
...@@ -420,9 +432,9 @@ database_event_format get_format(void *_database, int event_id) ...@@ -420,9 +432,9 @@ database_event_format get_format(void *_database, int event_id)
abort(); abort();
} }
ret.type = d->i[event_id].arg_type; ret.type = d->i[d->pos[event_id]].arg_type;
ret.name = d->i[event_id].arg_name; ret.name = d->i[d->pos[event_id]].arg_name;
ret.count = d->i[event_id].asize; ret.count = d->i[d->pos[event_id]].asize;
return ret; return ret;
} }
...@@ -7,6 +7,7 @@ void dump_database(void *database); ...@@ -7,6 +7,7 @@ void dump_database(void *database);
void list_ids(void *database); void list_ids(void *database);
void list_groups(void *database); void list_groups(void *database);
void on_off(void *d, char *item, int *a, int onoff); void on_off(void *d, char *item, int *a, int onoff);
char *event_name_from_id(void *database, int id);
/****************************************************************************/ /****************************************************************************/
/* get format of an event */ /* get format of an event */
......
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