[GRASS-SVN] r39824 - grass/trunk/lib/gis
svn_grass at osgeo.org
svn_grass at osgeo.org
Fri Nov 27 10:55:55 EST 2009
Author: martinl
Date: 2009-11-27 10:55:54 -0500 (Fri, 27 Nov 2009)
New Revision: 39824
Modified:
grass/trunk/lib/gis/nme_in_mps.c
Log:
libgis: G_fully_qualified_name() don't report mapset if empty string
Modified: grass/trunk/lib/gis/nme_in_mps.c
===================================================================
--- grass/trunk/lib/gis/nme_in_mps.c 2009-11-27 13:14:12 UTC (rev 39823)
+++ grass/trunk/lib/gis/nme_in_mps.c 2009-11-27 15:55:54 UTC (rev 39824)
@@ -65,43 +65,49 @@
/*!
- \brief fully qualified file name
+ \brief Get fully qualified element name
- Returns a fully qualified name for the file <b>name</b> in
- <b>mapset.</b> 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.
- The following example shows how an interactive version of <i>d.rast</i>
- interfaces with the command-line version of <i>d.rast</i>:
+ Returns a fully qualified name for GIS element <i>name</i> in
+ <i>mapset</i>. Currently this string is in the form
+ <b>name at 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 "gis.h"
+ #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_ask_cell_old ("", name, "");
- if (mapset == NULL) exit(EXIT_SUCCESS);
- fqn = G_fully_qualified_name (name, mapset);
- sprintf (command, "d.rast map='%s'", fqn);
- system(command);
+ 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 map name
+ \param name element name
\param mapset mapset name
- \return pointer to full map name (map @ mapset)
+ \return pointer to full element name (map at mapset)
*/
char *G_fully_qualified_name(const char *name, const char *mapset)
{
char fullname[GNAME_MAX + GMAPSET_MAX];
- if (strchr(name, '@'))
+ if (strchr(name, '@') || strlen(mapset) < 1) {
sprintf(fullname, "%s", name);
- else
+ }
+ else {
sprintf(fullname, "%s@%s", name, mapset);
+ }
return G_store(fullname);
}
More information about the grass-commit
mailing list