GRASS GIS 8 Programmer's Manual  8.2.2dev(2023)-3d2c704037
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  */
26 int 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"),
45  group);
46  fprintf(fd, "-------------\n");
47  tot_len = 0;
48  for (i = 0; i < ref->nfiles; i++) {
49  I__list_group_name_fit(buf, ref->file[i].name, ref->file[i].mapset);
50  tot_len += max;
51  if (tot_len > 78) {
52  fprintf(fd, "\n");
53  tot_len = max;
54  }
55  fprintf(fd, "%-*s", max, buf);
56  }
57  if (tot_len)
58  fprintf(fd, "\n");
59  fprintf(fd, "-------------\n");
60 
61  return 0;
62 }
63 
64 /*!
65  * \brief Prints maps in a group (simple version)
66  *
67  * Same as I_list_group(), but without all the fancy stuff.
68  * Prints one map per line in map@mapset form.
69  *
70  * \param ref group reference (set with I_get_group_ref())
71  * \param fd where to print (typically stdout)
72  * \return 0
73  */
74 int I_list_group_simple(const struct Ref *ref, FILE * fd)
75 {
76  int i;
77 
78  if (ref->nfiles <= 0)
79  return 0;
80 
81  for (i = 0; i < ref->nfiles; i++)
82  fprintf(fd, "%s@%s\n", ref->file[i].name, ref->file[i].mapset);
83 
84  return 0;
85 }
86 
87 /*!
88  * \brief Formats map name to fit in a 80 column layout
89  *
90  * Results in a map name in the "<map@mapset>" form.
91  * If necessary truncates relevant part(s) and denotes
92  * with ellipsis, e.g. "<verylongmapname...@mapset>".
93  *
94  * \param[out] buf formatted map name
95  * \param name map name
96  * \param mapset mapset name
97  */
98 void I__list_group_name_fit(char *buf, const char *name, const char *mapset)
99 {
100  char *frmt;
101  char fr[32];
102  int name_length = (int)strlen(name);
103  int mapset_length = (int)strlen(mapset);
104 
105  if (name_length + mapset_length + 3 < 75) {
106  frmt = "<%s@%s>";
107  }
108  else if (name_length > 35 && mapset_length > 35) {
109  frmt = "<%.33s...@%.32s...>";
110  }
111  else if (name_length > 35) {
112  sprintf(fr, "<%%.%ds...@%%s>", 68 - mapset_length);
113  frmt = fr;
114  }
115  else {
116  sprintf(fr, "<%%s@%%.%ds...>", 68 - name_length);
117  frmt = fr;
118  }
119  snprintf(buf, 75, frmt, name, mapset);
120 }
char name[INAME_LEN]
Definition: imagery.h:22
Definition: imagery.h:26
#define max(x, y)
Definition: draw2.c:32
int I_list_group_simple(const struct Ref *ref, FILE *fd)
Prints maps in a group (simple version)
Definition: list_gp.c:74
char mapset[INAME_LEN]
Definition: imagery.h:23
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 nfiles
Definition: imagery.h:28
struct Ref_Files * file
Definition: imagery.h:29
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:98
#define _(str)
Definition: glocale.h:10
const char * name
Definition: named_colr.c:7