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