GRASS GIS 7 Programmer's Manual  7.9.dev(2021)-e5379bbd7
imagery/find.c
Go to the documentation of this file.
1 
2 /**************************************************************
3 * I_find_group (group)
4 *
5 * Find the a group in the current mapset
6 **************************************************************/
7 #include <grass/imagery.h>
8 #include <grass/gis.h>
9 
10 
11 /*!
12  * \brief does group exist?
13  *
14  * Returns 1 if the
15  * specified <b>group</b> exists in the current mapset; 0 otherwise.
16  * Use I_find_group2 to search in all or a specific mapset.
17  *
18  * \param group
19  * \return int 1 if group was found, 0 otherwise
20  */
21 
22 int I_find_group(const char *group)
23 {
24  if (group == NULL || *group == 0)
25  return 0;
26 
27  return G_find_file2("group", group, G_mapset()) != NULL;
28 }
29 
30 /*!
31  * \brief Does the group exists?
32  *
33  * Finds a group in specified mapset or any mapset if mapset is not set.
34  * Internally uses G_find_file2().
35  *
36  * \param group
37  * \param mapset
38  * \return int 1 if group was found, 0 otherwise
39  */
40 
41 int I_find_group2(const char *group, const char *mapset)
42 {
43  return G_find_file2("group", group, mapset) != NULL;
44 }
45 
46 /*!
47  * \brief Searches for a group file in the current mapset
48  *
49  * \param group
50  * \param file
51  * \return int 1 if file was found, 0 otherwise
52  */
53 int I_find_group_file(const char *group, const char *file)
54 {
55  if (!I_find_group(group))
56  return 0;
57  if (file == NULL || *file == 0)
58  return 0;
59 
60  return G_find_file2_misc("group", file, group, G_mapset()) != NULL;
61 }
62 
63 /*!
64  * \brief Searches for a group file in the specified mapset
65  *
66  * \param group
67  * \param file
68  * \return int 1 if file was found, 0 otherwise
69  */
70 int I_find_group_file2(const char *group, const char *mapset, const char *file)
71 {
72  if (!I_find_group2(group, mapset))
73  return 0;
74  if (file == NULL || *file == 0)
75  return 0;
76 
77  return G_find_file2_misc("group", file, group, mapset) != NULL;
78 }
79 
80 /*!
81  * \brief Searches for a subgroup in the current mapset
82  *
83  * \param group
84  * \param subgroup
85  * \return int 1 if subgroup was found, 0 otherwise
86  */
87 int I_find_subgroup(const char *group, const char *subgroup)
88 {
89  char element[GNAME_MAX];
90 
91  if (!I_find_group(group))
92  return 0;
93  if (subgroup == NULL || *subgroup == 0)
94  return 0;
95 
96  sprintf(element, "subgroup%c%s", HOST_DIRSEP, subgroup);
97  G_debug(5, "I_find_subgroup() element: %s", element);
98 
99  return G_find_file2_misc("group", element, group, G_mapset()) != NULL;
100 }
101 
102 /*!
103  * \brief Searches for a subgroup in specified mapset or any mapset if mapset is not set
104  *
105  * \param group
106  * \param subgroup
107  * \param mapset
108  * \return int 1 if subrgoup was found, 0 otherwise
109  */
110 int I_find_subgroup2(const char *group, const char *subgroup, const char *mapset)
111 {
112  char element[GNAME_MAX];
113 
114  if (!I_find_group2(group, mapset))
115  return 0;
116  if (subgroup == NULL || *subgroup == 0)
117  return 0;
118 
119  sprintf(element, "subgroup%c%s", HOST_DIRSEP, subgroup);
120  G_debug(5, "I_find_subgroup2() element: %s", element);
121 
122  return G_find_file2_misc("group", element, group, mapset) != NULL;
123 }
124 
125 /*!
126  * \brief Searches for a subgroup file in the current mapset
127  *
128  * \param group
129  * \param subgroup
130  * \param file
131  * \return int 1 if file was found, 0 otherwise
132  */
133 int I_find_subgroup_file(const char *group, const char *subgroup,
134  const char *file)
135 {
136  char element[GNAME_MAX * 2];
137 
138  if (!I_find_group(group))
139  return 0;
140  if (subgroup == NULL || *subgroup == 0)
141  return 0;
142  if (file == NULL || *file == 0)
143  return 0;
144 
145  sprintf(element, "subgroup%c%s%c%s", HOST_DIRSEP, subgroup, HOST_DIRSEP, file);
146  G_debug(5, "I_find_subgroup_file() element: %s", element);
147 
148  return G_find_file2_misc("group", element, group, G_mapset()) != NULL;
149 }
150 
151 /*!
152  * \brief Searches for a subgroup file in the specified mapset
153  *
154  * \param group
155  * \param subgroup
156  * \param mapset
157  * \param file
158  * \return int 1 if file was found, 0 otherwise
159  */
160 int I_find_subgroup_file2(const char *group, const char *subgroup,
161  const char *mapset, const char *file)
162 {
163  char element[GNAME_MAX * 2];
164 
165  if (!I_find_group2(group, mapset))
166  return 0;
167  if (subgroup == NULL || *subgroup == 0)
168  return 0;
169  if (file == NULL || *file == 0)
170  return 0;
171 
172  sprintf(element, "subgroup%c%s%c%s", HOST_DIRSEP, subgroup, HOST_DIRSEP, file);
173  G_debug(5, "I_find_subgroup_file2() element: %s", element);
174 
175  return G_find_file2_misc("group", element, group, mapset) != NULL;
176 }
177 
178 /*!
179  * \brief does signature file exists?
180  *
181  * Returns 1 if the
182  * specified <b>signature</b> exists in the specified subgroup; 0 otherwise.
183  *
184  * Should be used to check if signature file exists after G_parser run
185  * when generating new signature file.
186  *
187  * \param group - group where to search
188  * \param subgroup - subgroup containing signatures
189  * \param type - type of signature ("sig" or "sigset")
190  * \param file - name of signature file
191  * \return int
192  */
193 int I_find_signature_file(const char *group, const char *subgroup,
194  const char *type, const char *file)
195 {
196  char element[GNAME_MAX * 2];
197 
198  if (!I_find_group(group))
199  return 0;
200  if (subgroup == NULL || *subgroup == 0)
201  return 0;
202  if (type == NULL || *type == 0)
203  return 0;
204  if (file == NULL || *file == 0)
205  return 0;
206 
207  sprintf(element, "subgroup%c%s%c%s%c%s", HOST_DIRSEP, subgroup, HOST_DIRSEP, type, HOST_DIRSEP, file);
208  G_debug(5, "I_find_signature_file() element: %s", element);
209 
210  return G_find_file2_misc("group", element, group, G_mapset()) != NULL;
211 }
const char * G_find_file2(const char *, const char *, const char *)
Searches for a file from the mapset search list or in a specified mapset. (look but don&#39;t touch) ...
Definition: find_file.c:247
int I_find_subgroup2(const char *group, const char *subgroup, const char *mapset)
Searches for a subgroup in specified mapset or any mapset if mapset is not set.
Definition: imagery/find.c:110
#define NULL
Definition: ccmath.h:32
int I_find_subgroup_file2(const char *group, const char *subgroup, const char *mapset, const char *file)
Searches for a subgroup file in the specified mapset.
Definition: imagery/find.c:160
Definition: lidar.h:86
int I_find_subgroup(const char *group, const char *subgroup)
Searches for a subgroup in the current mapset.
Definition: imagery/find.c:87
#define HOST_DIRSEP
Definition: gis.h:213
int I_find_group(const char *group)
does group exist?
Definition: imagery/find.c:22
int I_find_group2(const char *group, const char *mapset)
Does the group exists?
Definition: imagery/find.c:41
int I_find_group_file(const char *group, const char *file)
Searches for a group file in the current mapset.
Definition: imagery/find.c:53
const char * G_find_file2_misc(const char *, const char *, const char *, const char *)
Searches for a file from the mapset search list or in a specified mapset. (look but don&#39;t touch) ...
Definition: find_file.c:267
const char * G_mapset(void)
Get current mapset name.
Definition: gis/mapset.c:33
#define GNAME_MAX
Definition: gis.h:167
int I_find_group_file2(const char *group, const char *mapset, const char *file)
Searches for a group file in the specified mapset.
Definition: imagery/find.c:70
#define file
int I_find_signature_file(const char *group, const char *subgroup, const char *type, const char *file)
does signature file exists?
Definition: imagery/find.c:193
int I_find_subgroup_file(const char *group, const char *subgroup, const char *file)
Searches for a subgroup file in the current mapset.
Definition: imagery/find.c:133
int G_debug(int, const char *,...) __attribute__((format(printf