GRASS 8 Programmer's Manual  8.5.0dev(2025)-c070206eb1
imagery/find.c
Go to the documentation of this file.
1 /**************************************************************
2  * I_find_group (group)
3  *
4  * Find the a group in the current mapset
5  **************************************************************/
6 
7 #include <grass/imagery.h>
8 #include <grass/gis.h>
9 
10 /*!
11  * \brief does group exist?
12  *
13  * Returns 1 if the
14  * specified <b>group</b> exists in the current mapset; 0 otherwise.
15  * Use I_find_group2 to search in all or a specific mapset.
16  *
17  * \param group
18  * \return int 1 if group was found, 0 otherwise
19  */
20 int I_find_group(const char *group)
21 {
22  if (group == NULL || *group == 0)
23  return 0;
24 
25  return G_find_file2("group", group, G_mapset()) != NULL;
26 }
27 
28 /*!
29  * \brief Does the group exists?
30  *
31  * Finds a group in specified mapset or any mapset if mapset is not set.
32  * Internally uses G_find_file2().
33  *
34  * \param group
35  * \param mapset
36  * \return int 1 if group was found, 0 otherwise
37  */
38 int I_find_group2(const char *group, const char *mapset)
39 {
40  return G_find_file2("group", group, mapset) != NULL;
41 }
42 
43 /*!
44  * \brief Searches for a group file in the current mapset
45  *
46  * \param group
47  * \param file
48  * \return int 1 if file was found, 0 otherwise
49  */
50 int I_find_group_file(const char *group, const char *file)
51 {
52  if (!I_find_group(group))
53  return 0;
54  if (file == NULL || *file == 0)
55  return 0;
56 
57  return G_find_file2_misc("group", file, group, G_mapset()) != NULL;
58 }
59 
60 /*!
61  * \brief Searches for a group file in the specified mapset
62  *
63  * \param group
64  * \param mapset
65  * \param file
66  * \return int 1 if file was found, 0 otherwise
67  */
68 int I_find_group_file2(const char *group, const char *mapset, const char *file)
69 {
70  if (!I_find_group2(group, mapset))
71  return 0;
72  if (file == NULL || *file == 0)
73  return 0;
74 
75  return G_find_file2_misc("group", file, group, mapset) != NULL;
76 }
77 
78 /*!
79  * \brief Searches for a subgroup in the current mapset
80  *
81  * \param group
82  * \param subgroup
83  * \return int 1 if subgroup was found, 0 otherwise
84  */
85 int I_find_subgroup(const char *group, const char *subgroup)
86 {
87  char element[GNAME_MAX];
88 
89  if (!I_find_group(group))
90  return 0;
91  if (subgroup == NULL || *subgroup == 0)
92  return 0;
93 
94  snprintf(element, sizeof(element), "subgroup%c%s", HOST_DIRSEP, subgroup);
95  G_debug(5, "I_find_subgroup() element: %s", element);
96 
97  return G_find_file2_misc("group", element, group, G_mapset()) != NULL;
98 }
99 
100 /*!
101  * \brief Searches for a subgroup in specified mapset or any mapset if mapset is
102  * not set
103  *
104  * \param group
105  * \param subgroup
106  * \param mapset
107  * \return int 1 if subrgoup was found, 0 otherwise
108  */
109 int I_find_subgroup2(const char *group, const char *subgroup,
110  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  snprintf(element, sizeof(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  snprintf(element, sizeof(element), "subgroup%c%s%c%s", HOST_DIRSEP,
146  subgroup, HOST_DIRSEP, file);
147  G_debug(5, "I_find_subgroup_file() element: %s", element);
148 
149  return G_find_file2_misc("group", element, group, G_mapset()) != NULL;
150 }
151 
152 /*!
153  * \brief Searches for a subgroup file in the specified mapset
154  *
155  * \param group
156  * \param subgroup
157  * \param mapset
158  * \param file
159  * \return int 1 if file was found, 0 otherwise
160  */
161 int I_find_subgroup_file2(const char *group, const char *subgroup,
162  const char *mapset, const char *file)
163 {
164  char element[GNAME_MAX * 2];
165 
166  if (!I_find_group2(group, mapset))
167  return 0;
168  if (subgroup == NULL || *subgroup == 0)
169  return 0;
170  if (file == NULL || *file == 0)
171  return 0;
172 
173  snprintf(element, sizeof(element), "subgroup%c%s%c%s", HOST_DIRSEP,
174  subgroup, HOST_DIRSEP, file);
175  G_debug(5, "I_find_subgroup_file2() element: %s", element);
176 
177  return G_find_file2_misc("group", element, group, mapset) != NULL;
178 }
179 
180 /*!
181  * \brief Find mapset containing signature file
182  *
183  * Looks for the signature <i>name</i> of type <i>type</i>
184  * in the database. The <i>mapset</i> parameter can either be
185  * the empty string "", which means search all the mapsets in
186  * the users current mapset search path
187  * (see \ref Mapset_Search_Path for more details about the search
188  * path) or it can be a specific mapset name, which means look for the
189  * signature only in this one mapset (for example, in the current
190  * mapset). If found, the mapset where the signature lives is
191  * returned. If not found, the NULL pointer is returned.
192  *
193  * Note: If the user specifies a fully qualified signature name which
194  * exists, then I_find_signature() modifies <i>name</i> by removing
195  * the "@<i>mapset</i>".
196  * Use I_find_signature2 if altering passed in name is not desired.
197  *
198  * \param type I_SIGFILE_TYPE
199  * \param name of signature
200  * \param mapset set NULL to search in all mapsets
201  * \return mapset or NULL
202  */
203 const char *I_find_signature(I_SIGFILE_TYPE type, char *name,
204  const char *mapset)
205 {
206  char sdir[GNAME_MAX]; /* 'signatures/type\0' */
207 
208  G_debug(1, "I_find_signature(): type=%d name=%s mapset=%s", type, name,
209  mapset);
210 
211  I_get_signatures_dir(sdir, type);
212 
213  /* We do not search for a specific file as file name is up to signature type
214  */
215  return G_find_file(sdir, name, mapset);
216 }
217 
218 /*!
219  * \brief Find mapset containing signature (look but don't touch)
220  *
221  * Looks for the signature <i>name</i> of type <i>type</i>
222  * in the database. The <i>mapset</i> parameter can either be
223  * the empty string "", which means search all the mapsets in
224  * the users current mapset search path
225  * (see \ref Mapset_Search_Path for more details about the search
226  * path) or it can be a specific mapset name, which means look for the
227  * signature only in this one mapset (for example, in the current
228  * mapset). If found, the mapset where the signature lives is
229  * returned. If not found, the NULL pointer is returned.
230  *
231  * Note: The passed name argument is not altered.
232  * Use I_find_signature if stripping mapset part from the name is desired.
233  *
234  * \param type I_SIGFILE_TYPE
235  * \param name of signature
236  * \param mapset set NULL to search in all mapsets
237  * \return mapset or NULL
238  */
239 const char *I_find_signature2(I_SIGFILE_TYPE type, const char *name,
240  const char *mapset)
241 {
242  char sdir[GNAME_MAX]; /* 'signatures/type\0' */
243 
244  G_debug(1, "I_find_signature2(): type=%d name=%s mapset=%s", type, name,
245  mapset);
246 
247  I_get_signatures_dir(sdir, type);
248 
249  return G_find_file2(sdir, name, mapset);
250 }
#define NULL
Definition: ccmath.h:32
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't touch)
Definition: find_file.c:234
const char * G_mapset(void)
Get current mapset name.
Definition: gis/mapset.c:33
const char * G_find_file2_misc(const char *, const char *, const char *, const char *)
Searches for a misc file from the mapset search list or in a specified mapset. (look but don't touch)
Definition: find_file.c:257
int G_debug(int, const char *,...) __attribute__((format(printf
const char * G_find_file(const char *, char *, const char *)
Searches for a file from the mapset search list or in a specified mapset.
Definition: find_file.c:186
void I_get_signatures_dir(char *, I_SIGFILE_TYPE)
Get signature directory.
#define GNAME_MAX
Definition: gis.h:196
#define HOST_DIRSEP
Definition: gis.h:240
const char * I_find_signature2(I_SIGFILE_TYPE type, const char *name, const char *mapset)
Find mapset containing signature (look but don't touch)
Definition: imagery/find.c:239
int I_find_subgroup(const char *group, const char *subgroup)
Searches for a subgroup in the current mapset.
Definition: imagery/find.c:85
int I_find_group2(const char *group, const char *mapset)
Does the group exists?
Definition: imagery/find.c:38
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:109
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:161
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
const char * I_find_signature(I_SIGFILE_TYPE type, char *name, const char *mapset)
Find mapset containing signature file.
Definition: imagery/find.c:203
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:68
int I_find_group(const char *group)
does group exist?
Definition: imagery/find.c:20
int I_find_group_file(const char *group, const char *file)
Searches for a group file in the current mapset.
Definition: imagery/find.c:50
I_SIGFILE_TYPE
Definition: imagery.h:193
#define file
const char * name
Definition: named_colr.c:6
Definition: lidar.h:85