GRASS GIS 7 Programmer's Manual  7.5.svn(2018)-r72105
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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  sprintf(buf, "<%s@%s>", 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  sprintf(buf, "<%s@%s>", 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  */
73 int 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 }
char name[INAME_LEN]
Definition: imagery.h:22
Definition: imagery.h:26
#define max(x, y)
Definition: draw2.c:32
fd
Definition: d/range.c:69
int I_list_group_simple(const struct Ref *ref, FILE *fd)
Prints maps in a group (simple version)
Definition: list_gp.c:73
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
#define _(str)
Definition: glocale.h:13