GRASS 8 Programmer's Manual  8.5.0dev(2025)-c070206eb1
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 char *Rast_get_cell_title(const char *name, const char *mapset)
25 {
26  FILE *fd;
27  int stat;
28  char title[1024];
29 
30  stat = -1;
31  fd = G_fopen_old("cats", name, mapset);
32  if (fd) {
33  stat = 1;
34  if (!fgets(title, sizeof title, fd)) /* skip number of cats */
35  stat = -1;
36  else if (!G_getl(title, sizeof title, fd)) /* read title */
37  stat = -1;
38 
39  fclose(fd);
40  }
41 
42  if (stat < 0)
43  *title = 0;
44  else
45  G_strip(title);
46  return G_store(title);
47 }
char * Rast_get_cell_title(const char *name, const char *mapset)
get raster map title
Definition: cell_title.c:24
FILE * G_fopen_old(const char *, const char *, const char *)
Open a database file for reading.
Definition: gis/open.c:248
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