do_remove.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*!
  2. \file lib/manage/do_remove.c
  3. \brief Manage Library - Remove elements
  4. (C) 2001-2011 by the GRASS Development Team
  5. This program is free software under the GNU General Public License
  6. (>=v2). Read the file COPYING that comes with GRASS for details.
  7. \author Original author CERL
  8. */
  9. #include <string.h>
  10. #include <grass/gis.h>
  11. #include <grass/vector.h>
  12. #include <grass/glocale.h>
  13. #include <grass/raster3d.h>
  14. #include "manage_local_proto.h"
  15. /*!
  16. \brief Remove elements from data base
  17. \param n element id
  18. \param old name of element to be removed
  19. \return 0 on success
  20. \return 1 on error
  21. */
  22. int M_do_remove(int n, const char *old)
  23. {
  24. int i, ret;
  25. /* int len; */
  26. const char *mapset;
  27. int result = 0;
  28. int removed = 0;
  29. char xname[GNAME_MAX], xmapset[GMAPSET_MAX];
  30. G_message(_("Removing %s <%s>"), list[n].maindesc, old);
  31. /* len = get_description_len(n); */
  32. M__hold_signals(1);
  33. if (G_name_is_fully_qualified(old, xname, xmapset)) {
  34. if (strcmp(xmapset, G_mapset()) != 0)
  35. G_fatal_error("%s is not in the current mapset (%s)", old,
  36. G_mapset());
  37. old = xname;
  38. }
  39. if (G_strcasecmp(list[n].alias, "vector") == 0) {
  40. if ((mapset = G_find_vector2(old, "")) == NULL) {
  41. G_warning(_("Vector map <%s> not found"), old);
  42. }
  43. else {
  44. ret = Vect_delete(old);
  45. if (ret != -1) {
  46. removed = 1;
  47. }
  48. else {
  49. G_warning(_("Unable to delete vector map"));
  50. result = 1;
  51. }
  52. }
  53. }
  54. else {
  55. if (G_strcasecmp(list[n].alias, "raster") == 0) {
  56. if ((mapset = G_find_raster2(old, "")) == NULL)
  57. G_warning(_("Raster map <%s> not found"), old);
  58. }
  59. if (G_strcasecmp(list[n].alias, "raster_3d") == 0) {
  60. if ((mapset = G_find_raster3d(old, "")) == NULL)
  61. G_warning(_("3D raster map <%s> not found"), old);
  62. }
  63. for (i = 0; i < list[n].nelem; i++) {
  64. switch (G_remove(list[n].element[i], old)) {
  65. case -1:
  66. G_warning(_("Unable to remove %s element"), list[n].desc[i]);
  67. result = 1;
  68. break;
  69. case 0:
  70. G_verbose_message(_("%s is missing"), list[n].desc[i]);
  71. break;
  72. case 1:
  73. G_verbose_message(_("%s removed"), list[n].desc[i]);
  74. removed = 1;
  75. break;
  76. }
  77. }
  78. }
  79. if (G_strcasecmp(list[n].element[0], "cell") == 0) {
  80. char colr2[GPATH_MAX];
  81. G_snprintf(colr2, GPATH_MAX, "colr2/%s", G_mapset());
  82. switch (G_remove(colr2, old)) {
  83. case -1:
  84. G_warning(_("Unable to remove %s"), colr2);
  85. result = 1;
  86. break;
  87. case 0:
  88. G_verbose_message(_("%s is missing"), colr2);
  89. break;
  90. case 1:
  91. G_verbose_message(_("%s removed"), colr2);
  92. removed = 1;
  93. break;
  94. }
  95. }
  96. M__hold_signals(0);
  97. if (!removed)
  98. G_warning(_("<%s> nothing removed"), old);
  99. return result;
  100. }