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