Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

thecl: fix remaining r/r conflicts and warnings #65

Merged
merged 13 commits into from
Nov 8, 2019
43 changes: 43 additions & 0 deletions thecl/eclmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ eclmap_new()
map->gvar_types = seqmap_new();
map->timeline_ins_names = seqmap_new();
map->timeline_ins_signatures = seqmap_new();
map->mnem_set = NULL;
map->mnem_set_len = 0;
}
return map;
}
Expand All @@ -63,6 +65,7 @@ eclmap_free(
seqmap_free(map->gvar_types);
seqmap_free(map->timeline_ins_names);
seqmap_free(map->timeline_ins_signatures);
free(map->mnem_set);
free(map);
}
}
Expand Down Expand Up @@ -217,3 +220,43 @@ eclmap_load(
control(&state, 0, "!ins_names"); // default section
seqmap_load("!eclmap", &state, (seqmap_setfunc_t)set, (seqmap_controlfunc_t)control, f, fn);
}

int
strcmp_indirect(
const void *lhs,
const void *rhs)
{
return strcmp(*(const char **)lhs, *(const char **)rhs);
}

void
eclmap_rebuild(
eclmap_t *emap)
{
char **p;
size_t count = 0;
seqmap_entry_t *ent;
list_for_each(emap->ins_names, ent)
++count;
list_for_each(emap->timeline_ins_names, ent)
++count;

free(emap->mnem_set);
emap->mnem_set = p = malloc(count * sizeof(char*));
emap->mnem_set_len = count;

list_for_each(emap->ins_names, ent)
*p++ = ent->value;
list_for_each(emap->timeline_ins_names, ent)
*p++ = ent->value;

qsort(emap->mnem_set, emap->mnem_set_len, sizeof(char*), strcmp_indirect);
}

int
eclmap_is_mnemonic(
eclmap_t *emap,
const char *mnem)
{
return !!bsearch(&mnem, emap->mnem_set, emap->mnem_set_len, sizeof(char*), strcmp_indirect);
}
6 changes: 6 additions & 0 deletions thecl/eclmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ typedef struct eclmap_t {
seqmap_t *gvar_types;
seqmap_t *timeline_ins_names;
seqmap_t *timeline_ins_signatures;
char **mnem_set;
size_t mnem_set_len;
} eclmap_t;

/* Allocates and initalizes a new eclmap */
Expand All @@ -51,5 +53,9 @@ eclmap_t* eclmap_new();
void eclmap_free(eclmap_t* map);
/* Loads entries from eclmap file (thread unsafe) */
void eclmap_load(unsigned int version, eclmap_t* emap, FILE* f, const char* fn);
/* Rebuilds mnemonic set. Do this after adding entries to mnemonic maps. */
void eclmap_rebuild(eclmap_t *emap);
/* Returns whether identifier is a mnemonic */
int eclmap_is_mnemonic(eclmap_t *emap, const char *mnem);

#endif
Loading