do_remove.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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 <stdio.h>
  10. #include <string.h>
  11. #include <grass/gis.h>
  12. #include <grass/vector.h>
  13. #include <grass/glocale.h>
  14. #include <grass/raster3d.h>
  15. #include "manage_local_proto.h"
  16. /*!
  17. \brief Remove elements from data base
  18. \param n element id
  19. \param old name of element to be removed
  20. \return 0 on success
  21. \return 1 on error
  22. */
  23. int M_do_remove(int n, const char *old)
  24. {
  25. int i, ret;
  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. M__hold_signals(1);
  32. if (G_name_is_fully_qualified(old, xname, xmapset)) {
  33. if (strcmp(xmapset, G_mapset()) != 0)
  34. G_fatal_error("%s is not in the current mapset (%s)", old,
  35. G_mapset());
  36. old = xname;
  37. }
  38. if (G_strcasecmp(list[n].alias, "vector") == 0) {
  39. if ((mapset = G_find_vector2(old, "")) == NULL) {
  40. G_warning(_("Vector map <%s> not found"), old);
  41. }
  42. else {
  43. ret = Vect_delete(old);
  44. if (ret != -1) {
  45. removed = 1;
  46. }
  47. else {
  48. G_warning(_("Unable to delete vector map"));
  49. result = 1;
  50. }
  51. }
  52. }
  53. else {
  54. if (G_strcasecmp(list[n].alias, "raster") == 0) {
  55. if ((mapset = G_find_raster2(old, "")) == NULL)
  56. G_warning(_("Raster map <%s> not found"), old);
  57. }
  58. if (G_strcasecmp(list[n].alias, "raster_3d") == 0) {
  59. if ((mapset = G_find_raster3d(old, "")) == NULL)
  60. G_warning(_("3D raster map <%s> not found"), old);
  61. }
  62. for (i = 0; i < list[n].nelem; i++) {
  63. switch (G_remove(list[n].element[i], old)) {
  64. case -1:
  65. G_warning(_("Unable to remove %s element"), list[n].desc[i]);
  66. result = 1;
  67. break;
  68. case 0:
  69. G_verbose_message(_("%s is missing"), list[n].desc[i]);
  70. break;
  71. case 1:
  72. G_verbose_message(_("%s removed"), list[n].desc[i]);
  73. removed = 1;
  74. break;
  75. }
  76. }
  77. }
  78. if (G_strcasecmp(list[n].element[0], "cell") == 0) {
  79. char colr2[6 + GMAPSET_MAX];
  80. if (snprintf(colr2, 6 + GMAPSET_MAX, "colr2/%s", G_mapset()) >=
  81. 6 + GMAPSET_MAX)
  82. G_warning(_("String for secondary color table has been truncated"));
  83. switch (G_remove(colr2, old)) {
  84. case -1:
  85. G_warning(_("Unable to remove %s"), colr2);
  86. result = 1;
  87. break;
  88. case 0:
  89. G_verbose_message(_("%s is missing"), colr2);
  90. break;
  91. case 1:
  92. G_verbose_message(_("%s removed"), colr2);
  93. removed = 1;
  94. break;
  95. }
  96. }
  97. M__hold_signals(0);
  98. if (!removed)
  99. G_warning(_("<%s> nothing removed"), old);
  100. return result;
  101. }