Commit dca2143b authored by Cedric Roux's avatar Cedric Roux

add some functions in database.c

parent 7dbb2b8c
...@@ -422,6 +422,15 @@ char *event_name_from_id(void *_database, int id) ...@@ -422,6 +422,15 @@ char *event_name_from_id(void *_database, int id)
return d->i[d->pos[id]].name; return d->i[d->pos[id]].name;
} }
int event_id_from_name(void *_database, char *name)
{
database *d = _database;
id *i = (id*)bsearch(&(id){name:name}, d->i, d->isize, sizeof(id), id_cmp);
if (i == NULL)
{ printf("%s:%d: '%s' not found\n", __FILE__, __LINE__, name); abort(); }
return i->id;
}
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;
...@@ -438,3 +447,9 @@ database_event_format get_format(void *_database, int event_id) ...@@ -438,3 +447,9 @@ database_event_format get_format(void *_database, int event_id)
return ret; return ret;
} }
int number_of_ids(void *_d)
{
database *d = _d;
return d->isize;
}
...@@ -8,6 +8,8 @@ void list_ids(void *database); ...@@ -8,6 +8,8 @@ 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); char *event_name_from_id(void *database, int id);
int event_id_from_name(void *database, char *name);
int number_of_ids(void *database);
/****************************************************************************/ /****************************************************************************/
/* 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