00001 #include <grass/gis.h>
00002 #include <string.h>
00003
00004
00005
00006
00007
00008
00009 int G_update_key_value_file (char *file,char *key,char *value)
00010 {
00011 struct Key_Value *kv;
00012 int stat;
00013
00014 kv = G_read_key_value_file (file, &stat);
00015 if (stat != 0)
00016 return stat;
00017
00018 if(!G_set_key_value (key, value, kv))
00019 {
00020 G_free_key_value(kv);
00021 return -2;
00022 }
00023
00024 G_write_key_value_file (file, kv, &stat);
00025 G_free_key_value(kv);
00026
00027 return stat;
00028 }
00029
00030
00031
00032
00033
00034 int G_lookup_key_value_from_file(
00035 char *file,
00036 char *key,
00037 char value[],
00038 int n)
00039 {
00040 struct Key_Value *kv;
00041 int stat;
00042 char *v;
00043
00044 *value = 0;
00045 kv = G_read_key_value_file (file, &stat);
00046 if (stat != 0)
00047 return stat;
00048
00049 v = G_find_key_value (key, kv);
00050 if (v)
00051 {
00052 strncpy (value, v, n);
00053 value[n-1] = 0;
00054 stat = 1;
00055 }
00056 else
00057 stat = 0;
00058 G_free_key_value (kv);
00059 return stat;
00060 }