GRASS 8 Programmer's Manual 8.6.0dev(2026)-c83afef6d3
Loading...
Searching...
No Matches
nme_in_mps.c
Go to the documentation of this file.
1/*!
2 \file lib/gis/nme_in_mps.c
3
4 \brief GIS Library - check map name
5
6 SPDX-FileCopyrightText: 2001-2009, 2013 GRASS Development Team
7 SPDX-License-Identifier: GPL-2.0-or-later
8
9 \author Original author CERL
10 */
11
12#include <string.h>
13#include <grass/gis.h>
14
15/*!
16 \brief Check if map name is fully qualified (map @ mapset)
17
18 Returns a fully qualified name for the file <i>name</i> in
19 <i>mapset</i>. Currently this string is in the form
20 <i>name\@mapset</i>, but the programmer should pretend not to know this
21 and always call this routine to get the fully qualified name.
22
23 Note:
24 - <i>name</i> is char array of size GNAME_MAX
25 - <i>mapset</i> is char array of size GMAPSET_MAX
26
27 \param fullname full map name
28 \param[out] name map name
29 \param[out] mapset mapset name
30
31 \return 1 if input map name is fully qualified
32 \return 0 if input map name is not fully qualified
33 */
34int G_name_is_fully_qualified(const char *fullname, char *name, char *mapset)
35{
36 const char *p;
37 char *q;
38
39 /* search for name@mapset */
40
41 *name = *mapset = 0;
42
43 for (p = fullname; *p; p++)
44 if (*p == '@')
45 break;
46
47 if (*p == 0)
48 return 0;
49
50 /* copy the name part */
51 q = name;
52 while (fullname != p)
53 *q++ = *fullname++;
54 *q = 0;
55
56 /* copy the mapset part */
57 p++; /* skip the @ */
58 q = mapset;
59 while ((*q++ = *p++))
60 ;
61
62 return (*name && *mapset);
63}
64
65/*!
66 \brief Get fully qualified element name
67
68 Returns a fully qualified name for GIS element <i>name</i> in
69 <i>mapset</i>. Currently this string is in the form
70 <b>name\@mapset</b>, but the programmer should pretend not to know
71 this and always call this routine to get the fully qualified name.
72
73 String is allocated by G_store().
74
75 \code
76 #include <grass/gis.h>
77 int main(char *argc, char **argv)
78 {
79 char name[GNAME_MAX], *mapset, *fqn;
80 char command[1024];
81
82 G_gisinit(argv[0]);
83 mapset = G_find_rast(name, "");
84 if (mapset == NULL)
85 exit(EXIT_SUCCESS);
86
87 fqn = G_fully_qualified_name (name, mapset);
88 printf (stdout, "map='%s'", fqn);
89
90 exit(EXIT_SUCCESS);
91 }
92 \endcode
93
94 \param name element name
95 \param mapset mapset name
96
97 \return pointer to full element name (map\@mapset)
98 */
99char *G_fully_qualified_name(const char *name, const char *mapset)
100{
102
103 if (strchr(name, '@') || strlen(mapset) < 1) {
104 snprintf(fullname, sizeof(fullname), "%s", name);
105 }
106 else {
107 snprintf(fullname, sizeof(fullname), "%s@%s", name, mapset);
108 }
109
110 return G_store(fullname);
111}
112
113/*!
114 \brief Returns unqualified map name (without @ mapset)
115
116 Returns an unqualified name for the file <i>name</i> in
117 <i>mapset</i>.
118
119 Note:
120 - <i>name, xname</i> are char array of size GNAME_MAX
121 - <i>mapset, xmapset</i> are char array of size GMAPSET_MAX
122
123 \param name map name
124 \param mapset mapset to check or NULL
125 \param[out] xname map name
126 \param[out] xmapset mapset name
127
128 \return 1 if input map name is fully qualified
129 \return 0 if name is not fully qualified
130 \return -1 if input mapset invalid (mapset != xmapset)
131 */
132int G_unqualified_name(const char *name, const char *mapset, char *xname,
133 char *xmapset)
134{
136 /* name is fully qualified */
137 if (mapset && *mapset && strcmp(mapset, xmapset) != 0)
138 return -1;
139 return 1;
140 }
141
142 /* name is not fully qualified */
143 strcpy(xname, name);
144 if (mapset)
145 strcpy(xmapset, mapset);
146 else
147 xmapset[0] = '\0';
148
149 return 0;
150}
char * G_store(const char *)
Copy string to allocated memory.
Definition strings.c:85
#define GMAPSET_MAX
Definition gis.h:194
#define GNAME_MAX
Definition gis.h:193
const char * name
Definition named_colr.c:6
char * G_fully_qualified_name(const char *name, const char *mapset)
Get fully qualified element name.
Definition nme_in_mps.c:99
int G_name_is_fully_qualified(const char *fullname, char *name, char *mapset)
Check if map name is fully qualified (map @ mapset)
Definition nme_in_mps.c:34
int G_unqualified_name(const char *name, const char *mapset, char *xname, char *xmapset)
Returns unqualified map name (without @ mapset)
Definition nme_in_mps.c:132
#define strcpy
Definition parson.c:66