aboutsummaryrefslogtreecommitdiff
path: root/src/symtab.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/symtab.c')
-rw-r--r--src/symtab.c92
1 files changed, 46 insertions, 46 deletions
diff --git a/src/symtab.c b/src/symtab.c
index 540ea0f..43469a4 100644
--- a/src/symtab.c
+++ b/src/symtab.c
@@ -1,4 +1,4 @@
-/* grecs - Gray's Extensible Configuration System
+/* argot - Gray's Extensible Configuration System
Copyright (C) 2007-2016 Sergey Poznyakoff
Grecs is free software; you can redistribute it and/or modify it
@@ -17,7 +17,7 @@
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
-#include <grecs.h>
+#include <argot.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
@@ -33,11 +33,11 @@ static unsigned int hash_size[] = {
/* |max_rehash| keeps the number of entries in |hash_size| table. */
static unsigned int max_rehash = sizeof(hash_size) / sizeof(hash_size[0]);
-struct grecs_symtab {
+struct argot_symtab {
int flags;
unsigned int hash_num; /* Index to hash_size table */
size_t elsize; /* Size of an element */
- struct grecs_syment **tab;
+ struct argot_syment **tab;
unsigned (*hash_fun)(void *, unsigned long hash_num);
int (*cmp_fun)(const void *, const void *);
int (*copy_fun)(void *, void *);
@@ -46,7 +46,7 @@ struct grecs_symtab {
};
static void
-syment_free(struct grecs_symtab *st, void *ptr)
+syment_free(struct argot_symtab *st, void *ptr)
{
if (st->syment_free_fun)
st->syment_free_fun(ptr);
@@ -54,10 +54,10 @@ syment_free(struct grecs_symtab *st, void *ptr)
free(ptr);
}
-static struct grecs_syment *
-syment_alloc(struct grecs_symtab *st, void *key)
+static struct argot_syment *
+syment_alloc(struct argot_symtab *st, void *key)
{
- struct grecs_syment *ent;
+ struct argot_syment *ent;
ent = st->syment_alloc_fun ?
st->syment_alloc_fun(st->elsize) : malloc(st->elsize);
@@ -75,7 +75,7 @@ syment_alloc(struct grecs_symtab *st, void *key)
unsigned
-grecs_hash_string(const char *name, unsigned long hashsize)
+argot_hash_string(const char *name, unsigned long hashsize)
{
unsigned i;
@@ -87,7 +87,7 @@ grecs_hash_string(const char *name, unsigned long hashsize)
}
unsigned
-grecs_hash_string_ci(const char *name, unsigned long hashsize)
+argot_hash_string_ci(const char *name, unsigned long hashsize)
{
unsigned i;
@@ -101,15 +101,15 @@ grecs_hash_string_ci(const char *name, unsigned long hashsize)
static unsigned
def_hash(void *data, unsigned long hashsize)
{
- struct grecs_syment *sym = data;
- return grecs_hash_string(sym->name, hashsize);
+ struct argot_syment *sym = data;
+ return argot_hash_string(sym->name, hashsize);
}
static int
def_cmp(const void *a, const void *b)
{
- struct grecs_syment const *syma = a;
- struct grecs_syment const *symb = b;
+ struct argot_syment const *syma = a;
+ struct argot_syment const *symb = b;
return strcmp(syma->name, symb->name);
}
@@ -117,8 +117,8 @@ def_cmp(const void *a, const void *b)
static int
def_copy(void *a, void *b)
{
- struct grecs_syment *syma = a;
- struct grecs_syment *symb = b;
+ struct argot_syment *syma = a;
+ struct argot_syment *symb = b;
syma->name = strdup(symb->name);
return syma->name == NULL;
@@ -127,7 +127,7 @@ def_copy(void *a, void *b)
static void
def_free_fun(void *p)
{
- struct grecs_syment *sym = p;
+ struct argot_syment *sym = p;
free(sym->name);
free(sym);
}
@@ -135,7 +135,7 @@ def_free_fun(void *p)
static unsigned
-symtab_insert_pos(struct grecs_symtab *st, void *elt)
+symtab_insert_pos(struct argot_symtab *st, void *elt)
{
unsigned i;
unsigned pos = st->hash_fun(elt, hash_size[st->hash_num]);
@@ -151,9 +151,9 @@ symtab_insert_pos(struct grecs_symtab *st, void *elt)
}
int
-grecs_symtab_replace(struct grecs_symtab *st, void *ent, void **old_ent)
+argot_symtab_replace(struct argot_symtab *st, void *ent, void **old_ent)
{
- struct grecs_syment *entry;
+ struct argot_syment *entry;
unsigned i, pos = st->hash_fun(ent, hash_size[st->hash_num]);
for (i = pos; (entry = st->tab[i]);) {
if (st->cmp_fun(entry, ent) == 0)
@@ -170,10 +170,10 @@ grecs_symtab_replace(struct grecs_symtab *st, void *ent, void **old_ent)
}
static int
-symtab_rehash(struct grecs_symtab *st)
+symtab_rehash(struct argot_symtab *st)
{
- struct grecs_syment **old_tab = st->tab;
- struct grecs_syment **new_tab;
+ struct argot_syment **old_tab = st->tab;
+ struct argot_syment **new_tab;
unsigned int i;
unsigned int hash_num = st->hash_num + 1;
@@ -187,7 +187,7 @@ symtab_rehash(struct grecs_symtab *st)
if (old_tab) {
st->hash_num = hash_num;
for (i = 0; i < hash_size[hash_num-1]; i++) {
- struct grecs_syment *elt = old_tab[i];
+ struct argot_syment *elt = old_tab[i];
if (elt->name) {
unsigned n = symtab_insert_pos(st, elt);
new_tab[n] = elt;
@@ -199,7 +199,7 @@ symtab_rehash(struct grecs_symtab *st)
}
const char *
-grecs_symtab_strerror(int rc)
+argot_symtab_strerror(int rc)
{
switch (rc) {
case ENOENT:
@@ -213,10 +213,10 @@ grecs_symtab_strerror(int rc)
}
int
-grecs_symtab_remove(struct grecs_symtab *st, void *elt)
+argot_symtab_remove(struct argot_symtab *st, void *elt)
{
unsigned int pos, i, j, r;
- struct grecs_syment *entry;
+ struct argot_syment *entry;
pos = st->hash_fun(elt, hash_size[st->hash_num]);
for (i = pos; (entry = st->tab[i]);) {
@@ -252,12 +252,12 @@ grecs_symtab_remove(struct grecs_symtab *st, void *elt)
}
int
-grecs_symtab_get_index(unsigned *idx, struct grecs_symtab *st,
+argot_symtab_get_index(unsigned *idx, struct argot_symtab *st,
void *key, int *install)
{
int rc;
unsigned i, pos;
- struct grecs_syment *elem;
+ struct argot_syment *elem;
if (!st->tab) {
if (install) {
@@ -296,18 +296,18 @@ grecs_symtab_get_index(unsigned *idx, struct grecs_symtab *st,
if ((rc = symtab_rehash(st)) != 0)
return rc;
- return grecs_symtab_get_index(idx, st, key, install);
+ return argot_symtab_get_index(idx, st, key, install);
}
void *
-grecs_symtab_lookup_or_install(struct grecs_symtab *st, void *key,
+argot_symtab_lookup_or_install(struct argot_symtab *st, void *key,
int *install)
{
unsigned i;
- int rc = grecs_symtab_get_index(&i, st, key, install);
+ int rc = argot_symtab_get_index(&i, st, key, install);
if (rc == 0) {
if (install && *install == 1) {
- struct grecs_syment *ent = syment_alloc(st, key);
+ struct argot_syment *ent = syment_alloc(st, key);
if (!ent) {
errno = ENOMEM;
return NULL;
@@ -322,7 +322,7 @@ grecs_symtab_lookup_or_install(struct grecs_symtab *st, void *key,
}
void
-grecs_symtab_clear(struct grecs_symtab *st)
+argot_symtab_clear(struct argot_symtab *st)
{
unsigned i, hs;
@@ -331,7 +331,7 @@ grecs_symtab_clear(struct grecs_symtab *st)
hs = hash_size[st->hash_num];
for (i = 0; i < hs; i++) {
- struct grecs_syment *elem = st->tab[i];
+ struct argot_syment *elem = st->tab[i];
if (elem) {
syment_free(st, elem);
st->tab[i] = NULL;
@@ -339,14 +339,14 @@ grecs_symtab_clear(struct grecs_symtab *st)
}
}
-struct grecs_symtab *
-grecs_symtab_create(size_t elsize,
+struct argot_symtab *
+argot_symtab_create(size_t elsize,
unsigned (*hash_fun)(void *, unsigned long),
int (*cmp_fun)(const void *, const void *),
int (*copy_fun)(void *, void *),
void *(*alloc_fun)(size_t), void (*free_fun)(void *))
{
- struct grecs_symtab *st = malloc(sizeof(*st));
+ struct argot_symtab *st = malloc(sizeof(*st));
if (st) {
memset(st, 0, sizeof(*st));
st->elsize = elsize;
@@ -369,25 +369,25 @@ grecs_symtab_create(size_t elsize,
return st;
}
-struct grecs_symtab *
-grecs_symtab_create_default(size_t elsize)
+struct argot_symtab *
+argot_symtab_create_default(size_t elsize)
{
- return grecs_symtab_create(elsize,
+ return argot_symtab_create(elsize,
NULL, NULL, NULL, NULL, NULL);
}
void
-grecs_symtab_free(struct grecs_symtab *st)
+argot_symtab_free(struct argot_symtab *st)
{
if (st) {
- grecs_symtab_clear(st);
+ argot_symtab_clear(st);
free(st->tab);
free(st);
}
}
size_t
-grecs_symtab_count_entries(struct grecs_symtab *st)
+argot_symtab_count_entries(struct argot_symtab *st)
{
unsigned i;
size_t count = 0;
@@ -399,7 +399,7 @@ grecs_symtab_count_entries(struct grecs_symtab *st)
}
int
-grecs_symtab_enumerate(struct grecs_symtab *st, grecs_symtab_enumerator_t fun,
+argot_symtab_enumerate(struct argot_symtab *st, argot_symtab_enumerator_t fun,
void *data)
{
unsigned i;
@@ -407,7 +407,7 @@ grecs_symtab_enumerate(struct grecs_symtab *st, grecs_symtab_enumerator_t fun,
if (!st)
return 0;
for (i = 0; i < hash_size[st->hash_num]; i++) {
- struct grecs_syment *ep = st->tab[i];
+ struct argot_syment *ep = st->tab[i];
if (ep) {
int rc = fun(ep, data);
if (rc)

Return to:

Send suggestions and report system problems to the System administrator.