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