GRASS GIS 7 Programmer's Manual  7.9.dev(2021)-e5379bbd7
cell_title.c
Go to the documentation of this file.
1 
2 /**************************************************************
3  * char *Rast_get_cell_title (name, mapset)
4  * char *name name of map file
5  * char *mapset mapset containing name
6  *
7  * returns pointer to string containing cell title. (from cats file)
8  *************************************************************/
9 
10 #include <grass/gis.h>
11 
12 
13 /*!
14  * \brief get raster map title
15  *
16  * If only the map layer title is needed, it is not necessary to read the
17  * entire category file into memory. This routine gets the title for raster map
18  * <b>name</b> in <b>mapset</b> directly from the category file, and returns
19  * a pointer to the title. A legal pointer is always returned. If the map layer
20  * does not have a title, then a pointer to the empty string "" is returned.
21  *
22  * \param name
23  * \param mapset
24  * \return char *
25  */
26 
27 char *Rast_get_cell_title(const char *name, const char *mapset)
28 {
29  FILE *fd;
30  int stat;
31  char title[1024];
32 
33  stat = -1;
34  fd = G_fopen_old("cats", name, mapset);
35  if (fd) {
36  stat = 1;
37  if (!fgets(title, sizeof title, fd)) /* skip number of cats */
38  stat = -1;
39  else if (!G_getl(title, sizeof title, fd)) /* read title */
40  stat = -1;
41 
42  fclose(fd);
43  }
44 
45  if (stat < 0)
46  *title = 0;
47  else
48  G_strip(title);
49  return G_store(title);
50 }
int G_getl(char *, int, FILE *)
Gets a line of text from a file.
Definition: getl.c:31
void G_strip(char *)
Removes all leading and trailing white space from string.
Definition: strings.c:300
char * Rast_get_cell_title(const char *name, const char *mapset)
get raster map title
Definition: cell_title.c:27
FILE * G_fopen_old(const char *, const char *, const char *)
Open a database file for reading.
Definition: gis/open.c:253
char * G_store(const char *)
Copy string to allocated memory.
Definition: strings.c:87
const char * name
Definition: named_colr.c:7