nme_in_mps.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*!
  2. \file nme_in_mps.c
  3. \brief GIS Library - check map name
  4. (C) 2001-2008 by the GRASS Development Team
  5. This program is free software under the
  6. GNU General Public License (>=v2).
  7. Read the file COPYING that comes with GRASS
  8. for details.
  9. \author Original author CERL
  10. */
  11. #include <string.h>
  12. #include <grass/gis.h>
  13. /*!
  14. \brief Checks to see if 'name_in' is in the format: <name> in <mapset>
  15. \param name_in full map name
  16. \param[out] name_out map name
  17. \param[out] mapset mapset name
  18. \return 1 name_in is in this format.
  19. name_out will contain the simple <name>
  20. mapset will contain <mapset>
  21. \return 0 name_in is not in this format
  22. name_out and mapset are undefined (changed)
  23. */
  24. #ifndef COMMENTED_OUT
  25. int G__name_in_mapset(const char *name_in, char *name_out, char *mapset)
  26. {
  27. char in[1024];
  28. *in = 0;
  29. return (sscanf(name_in, "%s %s %s", name_out, in, mapset) == 3 &&
  30. strcmp(in, "in") == 0);
  31. }
  32. #endif
  33. /*!
  34. \brief Check if map name is fully qualified (map @ mapset)
  35. Note:
  36. - <b>name</b> is char array of size GNAME_MAX
  37. - <b>mapset</b> is char array of size GMAPSET_MAX
  38. \param fullname full map name
  39. \param[out] name map name
  40. \param[out] mapset mapset name
  41. \return 1 if input map name is fully qualified
  42. \return 0 if input map name is not fully qualified
  43. */
  44. int G__name_is_fully_qualified(const char *fullname, char *name, char *mapset)
  45. {
  46. const char *p;
  47. char *q;
  48. /* search for name@mapset */
  49. *name = *mapset = 0;
  50. for (p = fullname; *p; p++)
  51. if (*p == '@')
  52. break;
  53. if (*p == 0)
  54. return 0;
  55. /* copy the name part */
  56. q = name;
  57. while (fullname != p)
  58. *q++ = *fullname++;
  59. *q = 0;
  60. /* copy the mapset part */
  61. p++; /* skip the @ */
  62. q = mapset;
  63. while ((*q++ = *p++)) ;
  64. return (*name && *mapset);
  65. }
  66. /*!
  67. \brief fully qualified file name
  68. Returns a fully qualified name for the file <b>name</b> in
  69. <b>mapset.</b> Currently this string is in the form <i>name @ mapset</i>,
  70. but the programmer should pretend not to know this and always call this
  71. routine to get the fully qualified name.
  72. The following example shows how an interactive version of <i>d.rast</i>
  73. interfaces with the command-line version of <i>d.rast</i>:
  74. \code
  75. #include "gis.h"
  76. int main(char *argc, char **argv)
  77. {
  78. char name[GNAME_MAX], *mapset, *fqn;
  79. char command[1024];
  80. G_gisinit(argv[0]);
  81. mapset = G_ask_cell_old ("", name, "");
  82. if (mapset == NULL) exit(EXIT_SUCCESS);
  83. fqn = G_fully_qualified_name (name, mapset);
  84. sprintf (command, "d.rast map='%s'", fqn);
  85. system(command);
  86. }
  87. \endcode
  88. \param name map name
  89. \param mapset mapset name
  90. \return pointer to full map name (map @ mapset)
  91. */
  92. char *G_fully_qualified_name(const char *name, const char *mapset)
  93. {
  94. char fullname[GNAME_MAX + GMAPSET_MAX];
  95. if (strchr(name, '@'))
  96. sprintf(fullname, "%s", name);
  97. else
  98. sprintf(fullname, "%s@%s", name, mapset);
  99. return G_store(fullname);
  100. }