GRASS 8 Programmer's Manual 8.6.0dev(2026)-ddeab64dbf
Loading...
Searching...
No Matches
list_gp.c
Go to the documentation of this file.
1/*!
2 \file list_gp.c
3
4 \brief Imagery Library - List group
5
6 (C) 2001-2008 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
18/*!
19 * \brief Prints maps in a group (fancy version)
20 *
21 * \param group group name
22 * \param ref group reference (set with I_get_group_ref())
23 * \param fd where to print (typically stdout)
24 * \return 0
25 */
26int I_list_group(const char *group, const struct Ref *ref, FILE *fd)
27{
28 char buf[80];
29 int i;
30 int len, tot_len;
31 int max;
32
33 if (ref->nfiles <= 0) {
34 fprintf(fd, _("group <%s> is empty\n"), group);
35 return 0;
36 }
37 max = 0;
38 for (i = 0; i < ref->nfiles; i++) {
39 I__list_group_name_fit(buf, ref->file[i].name, ref->file[i].mapset);
40 len = strlen(buf) + 4;
41 if (len > max)
42 max = len;
43 }
44 fprintf(fd, _("group <%s> references the following raster maps\n"), group);
45 fprintf(fd, "-------------\n");
46 tot_len = 0;
47 for (i = 0; i < ref->nfiles; i++) {
48 I__list_group_name_fit(buf, ref->file[i].name, ref->file[i].mapset);
49 tot_len += max;
50 if (tot_len > 78) {
51 fprintf(fd, "\n");
52 tot_len = max;
53 }
54 fprintf(fd, "%-*s", max, buf);
55 }
56 if (tot_len)
57 fprintf(fd, "\n");
58 fprintf(fd, "-------------\n");
59
60 return 0;
61}
62
63/*!
64 * \brief Prints maps in a group (simple version)
65 *
66 * Same as I_list_group(), but without all the fancy stuff.
67 * Prints one map per line in map\@mapset form.
68 *
69 * \param ref group reference (set with I_get_group_ref())
70 * \param fd where to print (typically stdout)
71 * \return 0
72 */
73int I_list_group_simple(const struct Ref *ref, FILE *fd)
74{
75 int i;
76
77 if (ref->nfiles <= 0)
78 return 0;
79
80 for (i = 0; i < ref->nfiles; i++)
81 fprintf(fd, "%s@%s\n", ref->file[i].name, ref->file[i].mapset);
82
83 return 0;
84}
85
86/*!
87 * \brief Formats map name to fit in a 80 column layout
88 *
89 * Results in a map name in the "<map@mapset>" form.
90 * If necessary truncates relevant part(s) and denotes
91 * with ellipsis, e.g. "<verylongmapname...@mapset>".
92 *
93 * \param[out] buf formatted map name
94 * \param name map name
95 * \param mapset mapset name
96 */
97void I__list_group_name_fit(char *buf, const char *name, const char *mapset)
98{
99 char *frmt;
100 char fr[32];
101 int name_length = (int)strlen(name);
102 int mapset_length = (int)strlen(mapset);
103
104 if (name_length + mapset_length + 3 < 75) {
105 frmt = "<%s@%s>";
106 }
107 else if (name_length > 35 && mapset_length > 35) {
108 frmt = "<%.33s...@%.32s...>";
109 }
110 else if (name_length > 35) {
111 snprintf(fr, sizeof(fr), "<%%.%ds...@%%s>", 68 - mapset_length);
112 frmt = fr;
113 }
114 else {
115 snprintf(fr, sizeof(fr), "<%%s@%%.%ds...>", 68 - name_length);
116 frmt = fr;
117 }
118 snprintf(buf, 75, frmt, name, mapset);
119}
AMI_err name(char **stream_name)
Definition ami_stream.h:426
#define max(x, y)
Definition draw2.c:30
#define _(str)
Definition glocale.h:10
void I__list_group_name_fit(char *buf, const char *name, const char *mapset)
Formats map name to fit in a 80 column layout.
Definition list_gp.c:97
int I_list_group(const char *group, const struct Ref *ref, FILE *fd)
Prints maps in a group (fancy version)
Definition list_gp.c:26
int I_list_group_simple(const struct Ref *ref, FILE *fd)
Prints maps in a group (simple version)
Definition list_gp.c:73
const char * name
Definition named_colr.c:6
Definition imagery.h:24