GRASS 8 Programmer's Manual 8.6.0dev(2026)-ddeab64dbf
Loading...
Searching...
No Matches
list_subgp.c
Go to the documentation of this file.
1/*!
2 \file list_subgp.c
3
4 \brief Imagery Library - List subgroup
5
6 (C) 2001-2008,2013 by the GRASS Development Team
7
8 This program is free software under the GNU General Public License
9 (>=v2). Read the file COPYING that comes with GRASS for details.
10
11 \author USA CERL
12 */
13
14#include <string.h>
15#include <grass/imagery.h>
16#include <grass/glocale.h>
17
18char **list_subgroups(const char *group, const char *mapset, int *subgs_num)
19{
20 /* Unlike I_list_subgroup and I_list_subgroup_simple this function
21 returns array of subgroup names, it does not use fprintf.
22 This approach should make the function usable in more cases. */
23
24 char **subgs;
25 char path[GPATH_MAX];
26 char buf[GPATH_MAX];
27 struct stat sb;
28
29 *subgs_num = 0;
30
31 if (I_find_group2(group, mapset) == 0)
32 return NULL;
33
34 snprintf(buf, sizeof(buf), "group/%s/subgroup", group);
35 G_file_name(path, buf, "", mapset);
36
37 if (G_lstat(path, &sb) || !S_ISDIR(sb.st_mode))
38 return NULL;
39
41 return subgs;
42}
43
44/*!
45 * \brief Get list of subgroups which a group contains.
46 *
47 * \param group group name
48 * \param[out] subgs_num number of subgroups which the group contains
49 * \return array of subgroup names
50 */
51char **I_list_subgroups(const char *group, int *subgs_num)
52{
53
54 return list_subgroups(group, G_mapset(), subgs_num);
55}
56
57/*!
58 * \brief Get list of subgroups which a group contains.
59 *
60 * \param group group name
61 * \param mapset mapset name
62 * \param[out] subgs_num number of subgroups which the group contains
63 * \return array of subgroup names
64 */
65char **I_list_subgroups2(const char *group, const char *mapset, int *subgs_num)
66{
67 return list_subgroups(group, mapset, subgs_num);
68}
69
70/*!
71 * \brief Prints maps in a subgroup (fancy version)
72 *
73 * \param group group name
74 * \param subgroup subgroup name
75 * \param ref group reference (set with I_get_subgroup_ref())
76 * \param fd where to print (typically stdout)
77 * \return 0
78 */
79int I_list_subgroup(const char *group, const char *subgroup,
80 const struct Ref *ref, FILE *fd)
81{
82 char buf[80];
83 int i;
84 int len, tot_len;
85 int max;
86
87 if (ref->nfiles <= 0) {
88 fprintf(fd, _("subgroup <%s> of group <%s> is empty\n"), subgroup,
89 group);
90 return 0;
91 }
92 max = 0;
93 for (i = 0; i < ref->nfiles; i++) {
94 I__list_group_name_fit(buf, ref->file[i].name, ref->file[i].mapset);
95 len = strlen(buf) + 4;
96 if (len > max)
97 max = len;
98 }
99 fprintf(
100 fd,
101 _("subgroup <%s> of group <%s> references the following raster maps\n"),
102 subgroup, group);
103 fprintf(fd, "-------------\n");
104 tot_len = 0;
105 for (i = 0; i < ref->nfiles; i++) {
106 I__list_group_name_fit(buf, ref->file[i].name, ref->file[i].mapset);
107 tot_len += max;
108 if (tot_len > 78) {
109 fprintf(fd, "\n");
110 tot_len = max;
111 }
112 fprintf(fd, "%-*s", max, buf);
113 }
114 if (tot_len)
115 fprintf(fd, "\n");
116 fprintf(fd, "-------------\n");
117
118 return 0;
119}
120
121/*!
122 * \brief Prints maps in a subgroup (simple version)
123 *
124 * Same as I_list_subgroup(), but without all the fancy stuff.
125 * Prints one map per line in map@mapset form.
126 *
127 * \param ref group reference (set with I_get_subgroup_ref())
128 * \param fd where to print (typically stdout)
129 * \return 0
130 */
131/* same as above, but one map per line in map@mapset form */
132int I_list_subgroup_simple(const struct Ref *ref, FILE *fd)
133{
134 return I_list_group_simple(ref, fd);
135}
#define NULL
Definition ccmath.h:32
AMI_err name(char **stream_name)
Definition ami_stream.h:426
char * G_file_name(char *, const char *, const char *, const char *)
Builds full path names to GIS data files.
Definition file_name.c:61
int G_lstat(const char *, struct stat *)
Get file status.
Definition paths.c:145
char ** G_ls2(const char *, int *)
Stores a sorted directory listing in an array.
Definition ls.c:94
const char * G_mapset(void)
Get current mapset name.
Definition gis/mapset.c:33
int I_list_group_simple(const struct Ref *, FILE *)
Prints maps in a group (simple version)
Definition list_gp.c:73
void I__list_group_name_fit(char *, const char *, const char *)
Formats map name to fit in a 80 column layout.
Definition list_gp.c:97
int I_find_group2(const char *, const char *)
Does the group exists?
#define max(x, y)
Definition draw2.c:30
#define GPATH_MAX
Definition gis.h:199
#define _(str)
Definition glocale.h:10
int I_list_subgroup_simple(const struct Ref *ref, FILE *fd)
Prints maps in a subgroup (simple version)
Definition list_subgp.c:132
char ** list_subgroups(const char *group, const char *mapset, int *subgs_num)
Definition list_subgp.c:18
char ** I_list_subgroups(const char *group, int *subgs_num)
Get list of subgroups which a group contains.
Definition list_subgp.c:51
char ** I_list_subgroups2(const char *group, const char *mapset, int *subgs_num)
Get list of subgroups which a group contains.
Definition list_subgp.c:65
int I_list_subgroup(const char *group, const char *subgroup, const struct Ref *ref, FILE *fd)
Prints maps in a subgroup (fancy version)
Definition list_subgp.c:79
#define S_ISDIR(mode)
Definition stat.h:6
Definition imagery.h:24
Definition path.h:15