GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
key_value4.c
Go to the documentation of this file.
1 
16 #include <grass/gis.h>
17 #include <string.h>
18 
31 int G_update_key_value_file(const char *file, const char *key,
32  const char *value)
33 {
34  struct Key_Value *kv;
35  int stat;
36 
37  kv = G_read_key_value_file(file, &stat);
38  if (stat != 0)
39  return stat;
40 
41  if (!G_set_key_value(key, value, kv)) {
42  G_free_key_value(kv);
43  return -2;
44  }
45 
46  G_write_key_value_file(file, kv, &stat);
47  G_free_key_value(kv);
48 
49  return stat;
50 }
51 
65  const char *key, char value[], int n)
66 {
67  struct Key_Value *kv;
68  int stat;
69  char *v;
70 
71  *value = 0;
72  kv = G_read_key_value_file(file, &stat);
73  if (stat != 0)
74  return stat;
75 
76  v = G_find_key_value(key, kv);
77  if (v) {
78  strncpy(value, v, n);
79  value[n - 1] = 0;
80  stat = 1;
81  }
82  else
83  stat = 0;
84  G_free_key_value(kv);
85  return stat;
86 }
char * G_find_key_value(const char *key, const struct Key_Value *kv)
Find given key.
Definition: key_value1.c:128
int G_free_key_value(struct Key_Value *kv)
Free allocated Key_Value structure.
Definition: key_value1.c:145
int 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:31
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:64
int stat
Definition: g3dcolor.c:369
struct Key_Value * G_read_key_value_file(const char *file, int *stat)
Read key/values pairs from file.
Definition: key_value3.c:54
char * value
Definition: env.c:30
int G_write_key_value_file(const char *file, const struct Key_Value *kv, int *stat)
Write key/value pairs to file.
Definition: key_value3.c:29
#define file
int n
Definition: dataquad.c:291
int G_set_key_value(const char *key, const char *value, struct Key_Value *kv)
Set value for given key.
Definition: key_value1.c:55