const char *st_valueFor(strtbl *st, const char *key) { int index; index = st_findKey(st, key); return (index != -1) ? st->head[index].value : NULL; }
/* * we don't compact the table, rather we just nullify the entry */ void st_removeKey(strtbl *st, const char *key) { int index; strtblelem *el; index = st_findKey(st, key); if (index != -1) { el = &st->head[index]; if (el->flags & STR_FREEKEY) WOFREE((void *)el->key); if (el->flags & STR_FREEVALUE) WOFREE((void *)el->value); #ifndef _MSC_VER // SWK clear the element changed *el = STRTBL_NULLELEM; /* clear the element */ #else el->key = NULL; /* clear the element */ el->value = NULL; /* clear the element */ el->flags = 0; /* clear the element */ #endif if (st->firstNull > index) st->firstNull = index; st->count--; } return; }
/* * we don't compact the table, rather we just nullify the entry */ void st_removeKey(strtbl *st, const char *key) { int index; strtblelem *el; index = st_findKey(st, key); if (index != -1) { el = &st->head[index]; if (el->flags & STR_FREEKEY) WOFREE((void *)el->key); if (el->flags & STR_FREEVALUE) WOFREE((void *)el->value); *el = STRTBL_NULLELEM; /* clear the element */ if (st->firstNull > index) st->firstNull = index; st->count--; } return; }
void st_setValueForKey(strtbl *st, const char *key, const char *value, int flags) { int index; strtblelem *el; index = st_findKey(st, key); if (index == -1) { st_add(st, key, value, flags); } else { el = &st->head[index]; if (el->flags & STR_FREEVALUE) WOFREE((void *)el->value); /* keep the old key flags, but take the new value flags */ el->flags = (el->flags & (STR_COPYKEY|STR_FREEKEY)) | (flags & (STR_COPYVALUE | STR_FREEVALUE)); if (flags & STR_COPYVALUE) { el->value = WOSTRDUP(value); el->flags |= STR_FREEVALUE; } else el->value = value; } return; }