GRASS GIS 7 Programmer's Manual  7.5.svn(2017)-r71769
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
key_value4.c
Go to the documentation of this file.
1 /*!
2  \file lib/gis/key_value4.c
3 
4  \brief Key_Value management.
5 
6  (C) 2001-2014 by the GRASS Development Team
7 
8  This program is free software under the
9  GNU General Public License (>=v2).
10  Read the file COPYING that comes with GRASS
11  for details.
12 
13  \author CERL
14  */
15 
16 #include <grass/gis.h>
17 #include <string.h>
18 
19 /*!
20  \brief Update file, set up value for given key
21 
22  \param[in] file filename to be updated
23  \param[in] key key value
24  \param[in] value value to be updated
25  */
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 
37 /*!
38  \brief Look up for key in file
39 
40  \param[in] file filename
41  \param[in] key key to be found in file
42  \param[out] value value for key
43  \param[in] n number of characters to be copied
44 
45  \return 0 not found
46  \return 1 ok
47  */
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
char ** value
Definition: gis.h:484
char ** key
Definition: gis.h:483
Definition: gis.h:479
#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