• Main Page
  • Related Pages
  • Data Structures
  • Files
  • File List
  • Globals

key_value4.c

Go to the documentation of this file.
00001 
00016 #include <grass/gis.h>
00017 #include <string.h>
00018 
00031 int G_update_key_value_file(const char *file, const char *key,
00032                             const char *value)
00033 {
00034     struct Key_Value *kv;
00035     int stat;
00036 
00037     kv = G_read_key_value_file(file, &stat);
00038     if (stat != 0)
00039         return stat;
00040 
00041     if (!G_set_key_value(key, value, kv)) {
00042         G_free_key_value(kv);
00043         return -2;
00044     }
00045 
00046     G_write_key_value_file(file, kv, &stat);
00047     G_free_key_value(kv);
00048 
00049     return stat;
00050 }
00051 
00064 int G_lookup_key_value_from_file(const char *file,
00065                                  const char *key, char value[], int n)
00066 {
00067     struct Key_Value *kv;
00068     int stat;
00069     char *v;
00070 
00071     *value = 0;
00072     kv = G_read_key_value_file(file, &stat);
00073     if (stat != 0)
00074         return stat;
00075 
00076     v = G_find_key_value(key, kv);
00077     if (v) {
00078         strncpy(value, v, n);
00079         value[n - 1] = 0;
00080         stat = 1;
00081     }
00082     else
00083         stat = 0;
00084     G_free_key_value(kv);
00085     return stat;
00086 }

Generated on Thu Dec 9 2010 20:46:05 for GRASS Programmer's Manual by  doxygen 1.7.2