GRASS GIS 8 Programmer's Manual  8.2.2dev(2023)-3d2c704037
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,
71  const char *file)
72 {
73  if (!I_find_group2(group, mapset))
74  return 0;
75  if (file == NULL || *file == 0)
76  return 0;
77 
78  return G_find_file2_misc("group", file, group, mapset) != NULL;
79 }
80 
81 /*!
82  * \brief Searches for a subgroup in the current mapset
83  *
84  * \param group
85  * \param subgroup
86  * \return int 1 if subgroup was found, 0 otherwise
87  */
88 int I_find_subgroup(const char *group, const char *subgroup)
89 {
90  char element[GNAME_MAX];
91 
92  if (!I_find_group(group))
93  return 0;
94  if (subgroup == NULL || *subgroup == 0)
95  return 0;
96 
97  sprintf(element, "subgroup%c%s", HOST_DIRSEP, subgroup);
98  G_debug(5, "I_find_subgroup() element: %s", element);
99 
100  return G_find_file2_misc("group", element, group, G_mapset()) != NULL;
101 }
102 
103 /*!
104  * \brief Searches for a subgroup in specified mapset or any mapset if mapset is not set
105  *
106  * \param group
107  * \param subgroup
108  * \param mapset
109  * \return int 1 if subrgoup was found, 0 otherwise
110  */
111 int I_find_subgroup2(const char *group, const char *subgroup,
112  const char *mapset)
113 {
114  char element[GNAME_MAX];
115 
116  if (!I_find_group2(group, mapset))
117  return 0;
118  if (subgroup == NULL || *subgroup == 0)
119  return 0;
120 
121  sprintf(element, "subgroup%c%s", HOST_DIRSEP, subgroup);
122  G_debug(5, "I_find_subgroup2() element: %s", element);
123 
124  return G_find_file2_misc("group", element, group, mapset) != NULL;
125 }
126 
127 /*!
128  * \brief Searches for a subgroup file in the current mapset
129  *
130  * \param group
131  * \param subgroup
132  * \param file
133  * \return int 1 if file was found, 0 otherwise
134  */
135 int I_find_subgroup_file(const char *group, const char *subgroup,
136  const char *file)
137 {
138  char element[GNAME_MAX * 2];
139 
140  if (!I_find_group(group))
141  return 0;
142  if (subgroup == NULL || *subgroup == 0)
143  return 0;
144  if (file == NULL || *file == 0)
145  return 0;
146 
147  sprintf(element, "subgroup%c%s%c%s", HOST_DIRSEP, subgroup, HOST_DIRSEP,
148  file);
149  G_debug(5, "I_find_subgroup_file() element: %s", element);
150 
151  return G_find_file2_misc("group", element, group, G_mapset()) != NULL;
152 }
153 
154 /*!
155  * \brief Searches for a subgroup file in the specified mapset
156  *
157  * \param group
158  * \param subgroup
159  * \param mapset
160  * \param file
161  * \return int 1 if file was found, 0 otherwise
162  */
163 int I_find_subgroup_file2(const char *group, const char *subgroup,
164  const char *mapset, const char *file)
165 {
166  char element[GNAME_MAX * 2];
167 
168  if (!I_find_group2(group, mapset))
169  return 0;
170  if (subgroup == NULL || *subgroup == 0)
171  return 0;
172  if (file == NULL || *file == 0)
173  return 0;
174 
175  sprintf(element, "subgroup%c%s%c%s", HOST_DIRSEP, subgroup, HOST_DIRSEP,
176  file);
177  G_debug(5, "I_find_subgroup_file2() element: %s", element);
178 
179  return G_find_file2_misc("group", element, group, mapset) != NULL;
180 }
181 
182 /*!
183  * \brief Find mapset containing signature file
184  *
185  * Looks for the signature <i>name</i> of type <i>type</i>
186  * in the database. The <i>mapset</i> parameter can either be
187  * the empty string "", which means search all the mapsets in
188  * the users current mapset search path
189  * (see \ref Mapset_Search_Path for more details about the search
190  * path) or it can be a specific mapset name, which means look for the
191  * signature only in this one mapset (for example, in the current
192  * mapset). If found, the mapset where the signature lives is
193  * returned. If not found, the NULL pointer is returned.
194  *
195  * Note: If the user specifies a fully qualified signature name which
196  * exists, then I_find_signature() modifies <i>name</i> by removing
197  * the "@<i>mapset</i>".
198  * Use I_find_signature2 if altering passed in name is not desired.
199  *
200  * \param type I_SIGFILE_TYPE
201  * \param name of signature
202  * \param mapset set NULL to search in all mapsets
203  * \return mapset or NULL
204  */
205 const char *I_find_signature(I_SIGFILE_TYPE type, char *name,
206  const char *mapset)
207 {
208  char sdir[GNAME_MAX]; /* 'signatures/type\0' */
209 
210  G_debug(1, "I_find_signature(): type=%d name=%s mapset=%s", type, name,
211  mapset);
212 
213  I_get_signatures_dir(sdir, type);
214 
215  /* We do not search for a specific file as file name is up to signature type */
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 }
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:249
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:111
#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:163
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:88
#define HOST_DIRSEP
Definition: gis.h:223
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 * I_find_signature2(I_SIGFILE_TYPE type, const char *name, const char *mapset)
Find mapset containing signature (look but don&#39;t touch)
Definition: imagery/find.c:240
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&#39;t touch)...
Definition: find_file.c:270
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:203
const char * G_mapset(void)
Get current mapset name.
Definition: gis/mapset.c:33
#define GNAME_MAX
Definition: gis.h:177
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
void I_get_signatures_dir(char *, I_SIGFILE_TYPE)
Get signature directory.
const char * I_find_signature(I_SIGFILE_TYPE type, char *name, const char *mapset)
Find mapset containing signature file.
Definition: imagery/find.c:205
const char * name
Definition: named_colr.c:7
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:135
int G_debug(int, const char *,...) __attribute__((format(printf
I_SIGFILE_TYPE
Definition: imagery.h:202