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