do_remove.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #include <string.h>
  2. #include <grass/gis.h>
  3. #include <grass/vector.h>
  4. #include <grass/glocale.h>
  5. #include <grass/G3d.h>
  6. #include "list.h"
  7. /*
  8. * returns 0 - success
  9. * 1 - error
  10. */
  11. int do_remove(int n, const char *old)
  12. {
  13. int i, ret;
  14. /* int len; */
  15. const char *mapset;
  16. int result = 0;
  17. int removed = 0;
  18. char xname[GNAME_MAX], xmapset[GMAPSET_MAX];
  19. G_message(_("Removing %s <%s>"), list[n].maindesc, old);
  20. /* len = get_description_len(n); */
  21. hold_signals(1);
  22. if (G_name_is_fully_qualified(old, xname, xmapset)) {
  23. if (strcmp(xmapset, G_mapset()) != 0)
  24. G_fatal_error("%s is not in the current mapset (%s)", old,
  25. G_mapset());
  26. old = xname;
  27. }
  28. if (G_strcasecmp(list[n].alias, "vect") == 0) {
  29. if ((mapset = G_find_vector2(old, "")) == NULL) {
  30. G_warning(_("Vector map <%s> not found"), old);
  31. }
  32. else {
  33. ret = Vect_delete(old);
  34. if (ret != -1) {
  35. removed = 1;
  36. }
  37. else {
  38. G_warning(_("couldn't be removed"));
  39. result = 1;
  40. }
  41. }
  42. }
  43. else {
  44. if (G_strcasecmp(list[n].alias, "rast") == 0) {
  45. if ((mapset = G_find_raster2(old, "")) == NULL)
  46. G_warning(_("Raster map <%s> not found"), old);
  47. }
  48. if (G_strcasecmp(list[n].alias, "rast3d") == 0) {
  49. if ((mapset = G_find_grid3(old, "")) == NULL)
  50. G_warning(_("3D raster map <%s> not found"), old);
  51. }
  52. for (i = 0; i < list[n].nelem; i++) {
  53. switch (G_remove(list[n].element[i], old)) {
  54. case -1:
  55. G_warning(_("%s: couldn't be removed"), list[n].desc[i]);
  56. result = 1;
  57. break;
  58. case 0:
  59. if (G_verbose() == G_verbose_max())
  60. G_message(_("%s: missing"), list[n].desc[i]);
  61. break;
  62. case 1:
  63. if (G_verbose() == G_verbose_max())
  64. G_message(_("%s: removed"), list[n].desc[i]);
  65. removed = 1;
  66. break;
  67. }
  68. }
  69. }
  70. if (G_strcasecmp(list[n].element[0], "cell") == 0) {
  71. char colr2[50];
  72. sprintf(colr2, "colr2/%s", G_mapset());
  73. switch (G_remove(colr2, old)) {
  74. case -1:
  75. G_warning("%s: %s", colr2, _("couldn't be removed"));
  76. result = 1;
  77. break;
  78. case 0:
  79. if (G_verbose() == G_verbose_max())
  80. G_message(_("%s: missing"), colr2);
  81. break;
  82. case 1:
  83. if (G_verbose() == G_verbose_max())
  84. G_message(_("%s: removed"), colr2);
  85. removed = 1;
  86. break;
  87. }
  88. }
  89. hold_signals(0);
  90. if (!removed)
  91. G_warning(_("<%s> nothing removed"), old);
  92. return result;
  93. }