GRASS 8 Programmer's Manual 8.6.0dev(2026)-b0a6d7703c
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 SPDX-FileCopyrightText: 2001-2008,2013 GRASS Development Team
7 SPDX-License-Identifier: GPL-2.0-or-later
8
9 \author USA CERL
10 */
11
12#include <string.h>
13#include <grass/imagery.h>
14#include <grass/glocale.h>
15
16char **list_subgroups(const char *group, const char *mapset, int *subgs_num)
17{
18 /* Unlike I_list_subgroup and I_list_subgroup_simple this function
19 returns array of subgroup names, it does not use fprintf.
20 This approach should make the function usable in more cases. */
21
22 char **subgs;
23 char path[GPATH_MAX];
24 char buf[GPATH_MAX];
25 struct stat sb;
26
27 *subgs_num = 0;
28
29 if (I_find_group2(group, mapset) == 0)
30 return NULL;
31
32 snprintf(buf, sizeof(buf), "group/%s/subgroup", group);
33 G_file_name(path, buf, "", mapset);
34
35 if (G_lstat(path, &sb) || !S_ISDIR(sb.st_mode))
36 return NULL;
37
39 return subgs;
40}
41
42/*!
43 * \brief Get list of subgroups which a group contains.
44 *
45 * \param group group name
46 * \param[out] subgs_num number of subgroups which the group contains
47 * \return array of subgroup names
48 */
49char **I_list_subgroups(const char *group, int *subgs_num)
50{
51
52 return list_subgroups(group, G_mapset(), subgs_num);
53}
54
55/*!
56 * \brief Get list of subgroups which a group contains.
57 *
58 * \param group group name
59 * \param mapset mapset name
60 * \param[out] subgs_num number of subgroups which the group contains
61 * \return array of subgroup names
62 */
63char **I_list_subgroups2(const char *group, const char *mapset, int *subgs_num)
64{
65 return list_subgroups(group, mapset, subgs_num);
66}
67
68/*!
69 * \brief Prints maps in a subgroup (fancy version)
70 *
71 * \param group group name
72 * \param subgroup subgroup name
73 * \param ref group reference (set with I_get_subgroup_ref())
74 * \param fd where to print (typically stdout)
75 * \return 0
76 */
77int I_list_subgroup(const char *group, const char *subgroup,
78 const struct Ref *ref, FILE *fd)
79{
80 char buf[80];
81 int i;
82 int len, tot_len;
83 int max;
84
85 if (ref->nfiles <= 0) {
86 fprintf(fd, _("subgroup <%s> of group <%s> is empty\n"), subgroup,
87 group);
88 return 0;
89 }
90 max = 0;
91 for (i = 0; i < ref->nfiles; i++) {
92 I__list_group_name_fit(buf, ref->file[i].name, ref->file[i].mapset);
93 len = strlen(buf) + 4;
94 if (len > max)
95 max = len;
96 }
97 fprintf(
98 fd,
99 _("subgroup <%s> of group <%s> references the following raster maps\n"),
100 subgroup, group);
101 fprintf(fd, "-------------\n");
102 tot_len = 0;
103 for (i = 0; i < ref->nfiles; i++) {
104 I__list_group_name_fit(buf, ref->file[i].name, ref->file[i].mapset);
105 tot_len += max;
106 if (tot_len > 78) {
107 fprintf(fd, "\n");
108 tot_len = max;
109 }
110 fprintf(fd, "%-*s", max, buf);
111 }
112 if (tot_len)
113 fprintf(fd, "\n");
114 fprintf(fd, "-------------\n");
115
116 return 0;
117}
118
119/*!
120 * \brief Prints maps in a subgroup (simple version)
121 *
122 * Same as I_list_subgroup(), but without all the fancy stuff.
123 * Prints one map per line in map@mapset form.
124 *
125 * \param ref group reference (set with I_get_subgroup_ref())
126 * \param fd where to print (typically stdout)
127 * \return 0
128 */
129/* same as above, but one map per line in map@mapset form */
130int I_list_subgroup_simple(const struct Ref *ref, FILE *fd)
131{
132 return I_list_group_simple(ref, fd);
133}
#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:59
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:91
const char * G_mapset(void)
Get current mapset name.
Definition gis/mapset.c:31
int I_list_group_simple(const struct Ref *, FILE *)
Prints maps in a group (simple version)
Definition list_gp.c:71
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:95
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:196
#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:130
char ** list_subgroups(const char *group, const char *mapset, int *subgs_num)
Definition list_subgp.c:16
char ** I_list_subgroups(const char *group, int *subgs_num)
Get list of subgroups which a group contains.
Definition list_subgp.c:49
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:63
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:77
#define S_ISDIR(mode)
Definition stat.h:6
Definition imagery.h:24
Definition path.h:15