mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
profile: redo eventname handling
The eventname handling code was splattered all over the place. Collect it in a single source file and use C++ idioms to avoid nasty memory management. Provide a C-only interface, however. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
ab7b9329c0
commit
0d3c9954f4
10 changed files with 94 additions and 70 deletions
35
core/event.c
35
core/event.c
|
@ -99,38 +99,3 @@ bool same_event(const struct event *a, const struct event *b)
|
|||
return 0;
|
||||
return !strcmp(a->name, b->name);
|
||||
}
|
||||
|
||||
/* collect all event names and whether we display them */
|
||||
struct ev_select *ev_namelist = NULL;
|
||||
int evn_used = 0;
|
||||
static int evn_allocated = 0;
|
||||
|
||||
void clear_events(void)
|
||||
{
|
||||
for (int i = 0; i < evn_used; i++)
|
||||
free(ev_namelist[i].ev_name);
|
||||
evn_used = 0;
|
||||
}
|
||||
|
||||
void remember_event(const char *eventname)
|
||||
{
|
||||
int i = 0, len;
|
||||
|
||||
if (!eventname || (len = strlen(eventname)) == 0)
|
||||
return;
|
||||
while (i < evn_used) {
|
||||
if (!strncmp(eventname, ev_namelist[i].ev_name, len))
|
||||
return;
|
||||
i++;
|
||||
}
|
||||
if (evn_used == evn_allocated) {
|
||||
evn_allocated += 10;
|
||||
ev_namelist = realloc(ev_namelist, evn_allocated * sizeof(struct ev_select));
|
||||
if (!ev_namelist)
|
||||
/* we are screwed, but let's just bail out */
|
||||
return;
|
||||
}
|
||||
ev_namelist[evn_used].ev_name = strdup(eventname);
|
||||
ev_namelist[evn_used].plot_ev = true;
|
||||
evn_used++;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue