Loading...
Searching...
No Matches
key_value4.c
Go to the documentation of this file.
/*!
\file lib/gis/key_value4.c
\brief Key_Value management.
(C) 2001-2014 by the GRASS Development Team
This program is free software under the
GNU General Public License (>=v2).
Read the file COPYING that comes with GRASS
for details.
\author CERL
*/
#include <grass/gis.h>
#include <string.h>
/*!
\brief Update file, set up value for given key
\param[in] file filename to be updated
\param[in] key key value
\param[in] value value to be updated
*/
void G_update_key_value_file(const char *file, const char *key,
const char *value)
{
struct Key_Value *kv;
kv = G_read_key_value_file(file);
G_set_key_value(key, value, kv);
G_write_key_value_file(file, kv);
G_free_key_value(kv);
}
/*!
\brief Look up for key in file
\param[in] file filename
\param[in] key key to be found in file
\param[out] value value for key
\param[in] n number of characters to be copied
\return 0 not found
\return 1 ok
*/
int G_lookup_key_value_from_file(const char *file, const char *key,
char value[], int n)
{
struct Key_Value *kv;
const char *v;
*value = '\0';
kv = G_read_key_value_file(file);
v = G_find_key_value(key, kv);
if (v) {
strncpy(value, v, n);
value[n - 1] = '\0';
}
G_free_key_value(kv);
return v ? 1 : 0;
}
G_free_key_value
void G_free_key_value(struct Key_Value *kv)
Free allocated Key_Value structure.
Definition key_value1.c:104
G_set_key_value
void G_set_key_value(const char *key, const char *value, struct Key_Value *kv)
Set value for given key.
Definition key_value1.c:39
G_find_key_value
const char * G_find_key_value(const char *key, const struct Key_Value *kv)
Find given key (case sensitive).
Definition key_value1.c:85
G_write_key_value_file
void G_write_key_value_file(const char *file, const struct Key_Value *kv)
Write key/value pairs to file.
Definition key_value3.c:28
G_read_key_value_file
struct Key_Value * G_read_key_value_file(const char *file)
Read key/values pairs from file.
Definition key_value3.c:55
G_lookup_key_value_from_file
int G_lookup_key_value_from_file(const char *file, const char *key, char value[], int n)
Look up for key in file.
Definition key_value4.c:48
G_update_key_value_file
void G_update_key_value_file(const char *file, const char *key, const char *value)
Update file, set up value for given key.
Definition key_value4.c:26
file
#define file