18 #include <grass/gis.h>
29 kv = (
struct Key_Value *)G_malloc(
sizeof(
struct Key_Value));
35 kv->key = (
char **)
NULL;
36 kv->value = (
char **)
NULL;
60 if (key ==
NULL || key == 0)
63 for (n = 0; n < kv->nitems; n++)
64 if (strcmp(key, kv->key[n]) == 0)
67 if (n == kv->nitems) {
68 if (n >= kv->nalloc) {
69 if (kv->nalloc <= 0) {
71 size = kv->nalloc *
sizeof(
char *);
72 kv->key = (
char **)G_malloc(size);
73 kv->value = (
char **)G_malloc(size);
77 size = kv->nalloc *
sizeof(
char *);
78 kv->key = (
char **)G_realloc(kv->key, size);
79 kv->value = (
char **)G_realloc(kv->value, size);
82 if (kv->key ==
NULL || kv->value ==
NULL) {
91 kv->nitems = kv->nalloc = 0;
96 kv->key[
n] = G_malloc(strlen(key) + 1);
97 if (kv->key[n] ==
NULL)
99 strcpy(kv->key[n], key);
105 size = strlen(value);
106 if (kv->value[n] !=
NULL)
109 kv->value[
n] = G_malloc(size + 1);
110 if (kv->value[n] ==
NULL)
112 strcpy(kv->value[n], value);
132 for (n = 0; n < kv->nitems; n++)
133 if (strcmp(key, kv->key[n]) == 0)
134 return kv->value[
n][0] ? kv->value[
n] :
NULL;
152 for (n = 0; n < kv->nitems; n++) {
char * G_find_key_value(const char *key, const struct Key_Value *kv)
Find given key.
void G_free(void *buf)
Free allocated memory.
int G_free_key_value(struct Key_Value *kv)
Free allocated Key_Value structure.
int G_set_key_value(const char *key, const char *value, struct Key_Value *kv)
Set value for given key.
struct Key_Value * G_create_key_value(void)
Allocate and initialize Key_Value structure.