31 #include <grass/imagery.h>
33 static int get_ref(
const char *,
const char *,
struct Ref *);
34 static int set_color(
const char *,
const char *,
const char *,
struct Ref *);
35 static int put_ref(
const char *,
const char *,
const struct Ref *);
49 stat = (fscanf(fd,
"%s", group) == 1);
62 fprintf(fd,
"%s\n", group);
81 stat = (fscanf(fd,
"%s", subgroup) == 1);
96 fprintf(fd,
"%s\n", subgroup);
116 return get_ref(group,
"", ref);
135 const char *subgroup,
struct Ref *ref)
137 return get_ref(group, subgroup, ref);
140 static int get_ref(
const char *group,
const char *subgroup,
struct Ref *ref)
144 char name[INAME_LEN], mapset[INAME_LEN];
159 while (
G_getl2(buf,
sizeof buf, fd)) {
160 n = sscanf(buf,
"%255s %255s %15s", name, mapset, color);
161 if (n == 2 || n == 3) {
164 set_color(name, mapset, color, ref);
174 static int set_color(
const char *name,
const char *mapset,
const char *color,
179 for (n = 0; n < ref->nfiles; n++) {
180 if (strcmp(ref->file[n].name, name) == 0
181 && strcmp(ref->file[n].mapset, mapset) == 0)
212 ref->red.table =
NULL;
213 ref->grn.table =
NULL;
214 ref->blu.table =
NULL;
216 ref->red.index =
NULL;
217 ref->grn.index =
NULL;
218 ref->blu.index =
NULL;
220 if (ref->nfiles <= 0 || ref->red.n >= 0 || ref->blu.n >= 0 ||
223 switch (ref->nfiles) {
270 return put_ref(group,
"", ref);
291 const struct Ref *ref)
293 return put_ref(group, subgroup, ref);
296 static int put_ref(
const char *group,
const char *subgroup,
297 const struct Ref *ref)
309 for (n = 0; n < ref->nfiles; n++) {
310 fprintf(fd,
"%s %s", ref->file[n].name, ref->file[n].mapset);
311 if (n == ref->red.n || n == ref->grn.n || n == ref->blu.n) {
351 for (n = 0; n < ref->nfiles; n++) {
352 if (strcmp(ref->file[n].name, name) == 0
353 && strcmp(ref->file[n].mapset, mapset) == 0)
357 if ((n = ref->nfiles++))
359 (
struct Ref_Files *)G_realloc(ref->file,
361 sizeof(
struct Ref_Files));
364 (
struct Ref_Files *)G_malloc(ref->nfiles *
365 sizeof(
struct Ref_Files));
366 strcpy(ref->file[n].name, name);
367 strcpy(ref->file[n].mapset, mapset);
407 if (n == ref2->red.n)
409 if (n == ref2->grn.n)
411 if (n == ref2->blu.n)
436 ref->red.n = ref->grn.n = ref->blu.n = -1;
437 ref->red.table = ref->grn.table = ref->blu.table =
NULL;
char * G_mapset(void)
current mapset name
int I_add_file_to_group_ref(const char *name, const char *mapset, struct Ref *ref)
add file name to Ref structure
int I_put_subgroup(const char *group, const char *subgroup)
int I_put_group_ref(const char *group, const struct Ref *ref)
write group REF file
int I_init_group_ref(struct Ref *ref)
initialize Ref structure
int I_get_subgroup(const char *group, char *subgroup)
int I_init_ref_color_nums(struct Ref *ref)
int G_suppress_warnings(int flag)
Suppress printing a warning message to stderr.
int I_get_group(char *group)
int I_find_group(const char *group)
does group exist?
int G_getl2(char *buf, int n, FILE *fd)
gets a line of text from a file of any pedigree
int I_put_subgroup_ref(const char *group, const char *subgroup, const struct Ref *ref)
write subgroup REF file
FILE * I_fopen_subgroup_ref_new(const char *group, const char *subgroup)
FILE * I_fopen_group_file_old(const char *group, const char *file)
FILE * I_fopen_group_file_new(const char *group, const char *file)
FILE * I_fopen_group_ref_old(const char *group)
int I_transfer_group_ref_file(const struct Ref *ref2, int n, struct Ref *ref1)
copy Ref lists
char buf[GNAME_MAX+sizeof(G3D_DIRECTORY)+2]
FILE * G_fopen_new(const char *element, const char *name)
Open a new database file.
int I_put_group(const char *group)
int I_get_group_ref(const char *group, struct Ref *ref)
read group REF file
int I_free_group_ref(struct Ref *ref)
free Ref structure
int I_get_subgroup_ref(const char *group, const char *subgroup, struct Ref *ref)
read subgroup REF file
FILE * G_fopen_old(const char *element, const char *name, const char *mapset)
Open a database file for reading.
FILE * I_fopen_group_ref_new(const char *group)
FILE * I_fopen_subgroup_ref_old(const char *group, const char *subgroup)