GRASS GIS 7 Programmer's Manual  7.0.2(2015)-r00000
nme_in_mps.c
Go to the documentation of this file.
1 
14 #include <string.h>
15 #include <grass/gis.h>
16 
36 int G_name_is_fully_qualified(const char *fullname, char *name, char *mapset)
37 {
38  const char *p;
39  char *q;
40 
41  /* search for name@mapset */
42 
43  *name = *mapset = 0;
44 
45  for (p = fullname; *p; p++)
46  if (*p == '@')
47  break;
48 
49  if (*p == 0)
50  return 0;
51 
52  /* copy the name part */
53  q = name;
54  while (fullname != p)
55  *q++ = *fullname++;
56  *q = 0;
57 
58  /* copy the mapset part */
59  p++; /* skip the @ */
60  q = mapset;
61  while ((*q++ = *p++)) ;
62 
63  return (*name && *mapset);
64 }
65 
66 
101 char *G_fully_qualified_name(const char *name, const char *mapset)
102 {
103  char fullname[GNAME_MAX + GMAPSET_MAX];
104 
105  if (strchr(name, '@') || strlen(mapset) < 1) {
106  sprintf(fullname, "%s", name);
107  }
108  else {
109  sprintf(fullname, "%s@%s", name, mapset);
110  }
111 
112  return G_store(fullname);
113 }
114 
134 int G_unqualified_name(const char *name, const char *mapset,
135  char *xname, char *xmapset)
136 {
137  if (G_name_is_fully_qualified(name, xname, xmapset)) {
138  /* name is fully qualified */
139  if (mapset && *mapset && strcmp(mapset, xmapset) != 0)
140  return -1;
141  return 1;
142  }
143 
144  /* name is not fully qualified */
145  strcpy(xname, name);
146  if (mapset)
147  strcpy(xmapset, mapset);
148  else
149  xmapset[0] = '\0';
150 
151  return 0;
152 }
char * G_store(const char *s)
Copy string to allocated memory.
Definition: strings.c:86
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:134
char * G_fully_qualified_name(const char *name, const char *mapset)
Get fully qualified element name.
Definition: nme_in_mps.c:101
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:36
const char * name
Definition: named_colr.c:7