GRASS GIS 7 Programmer's Manual  7.0.5(2016)-r00000
key_value4.c
Go to the documentation of this file.
1 
16 #include <grass/gis.h>
17 #include <string.h>
18 
26 void G_update_key_value_file(const char *file,
27  const char *key, const char *value)
28 {
29  struct Key_Value *kv;
30 
31  kv = G_read_key_value_file(file);
32  G_set_key_value(key, value, kv);
33  G_write_key_value_file(file, kv);
34  G_free_key_value(kv);
35 }
36 
49  const char *key, char value[], int n)
50 {
51  struct Key_Value *kv;
52  const char *v;
53 
54  *value = '\0';
55  kv = G_read_key_value_file(file);
56 
57  v = G_find_key_value(key, kv);
58 
59  if (v) {
60  strncpy(value, v, n);
61  value[n - 1] = '\0';
62  }
63 
64  G_free_key_value(kv);
65 
66  return v ? 1 : 0;
67 }
const char * G_find_key_value(const char *key, const struct Key_Value *kv)
Find given key (case sensitive)
Definition: key_value1.c:84
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
void G_free_key_value(struct Key_Value *kv)
Free allocated Key_Value structure.
Definition: key_value1.c:103
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
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
struct Key_Value * G_read_key_value_file(const char *file)
Read key/values pairs from file.
Definition: key_value3.c:53
#define file
void G_set_key_value(const char *key, const char *value, struct Key_Value *kv)
Set value for given key.
Definition: key_value1.c:38