GRASS GIS 8 Programmer's Manual  8.5.0dev(2024)-f622271e7a
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, const char *key,
27  const char *value)
28 {
29  struct Key_Value *kv;
30 
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  */
48 int G_lookup_key_value_from_file(const char *file, const char *key,
49  char value[], int n)
50 {
51  struct Key_Value *kv;
52  const char *v;
53 
54  *value = '\0';
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 *, const struct Key_Value *)
Find given key (case sensitive)
Definition: key_value1.c:85
void G_free_key_value(struct Key_Value *)
Free allocated Key_Value structure.
Definition: key_value1.c:104
void G_set_key_value(const char *, const char *, struct Key_Value *)
Set value for given key.
Definition: key_value1.c:39
struct Key_Value * G_read_key_value_file(const char *)
Read key/values pairs from file.
Definition: key_value3.c:55
void G_write_key_value_file(const char *, const struct Key_Value *)
Write key/value pairs to file.
Definition: key_value3.c:28
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_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
#define file
Definition: gis.h:528
char ** value
Definition: gis.h:532
char ** key
Definition: gis.h:531