GRASS GIS 8 Programmer's Manual  8.2.1dev(2022)-f67d8e515
do_remove.c
Go to the documentation of this file.
1 /*!
2  \file lib/manage/do_remove.c
3 
4  \brief Manage Library - Remove elements
5 
6  (C) 2001-2011 by the GRASS Development Team
7 
8  This program is free software under the GNU General Public License
9  (>=v2). Read the file COPYING that comes with GRASS for details.
10 
11  \author Original author CERL
12 */
13 
14 #include <stdio.h>
15 #include <string.h>
16 
17 #include <grass/gis.h>
18 #include <grass/vector.h>
19 #include <grass/glocale.h>
20 #include <grass/raster3d.h>
21 
22 #include "manage_local_proto.h"
23 
24 /*!
25  \brief Remove elements from data base
26 
27  \param n element id
28  \param old name of element to be removed
29 
30  \return 0 on success
31  \return 1 on error
32 */
33 int M_do_remove(int n, const char *old)
34 {
35  int i, ret;
36  const char *mapset;
37  int result = 0;
38  int removed = 0;
39  char xname[GNAME_MAX], xmapset[GMAPSET_MAX];
40 
41  G_message(_("Removing %s <%s>"), list[n].maindesc, old);
42 
43  M__hold_signals(1);
44 
45  if (G_name_is_fully_qualified(old, xname, xmapset)) {
46  if (strcmp(xmapset, G_mapset()) != 0)
47  G_fatal_error("%s is not in the current mapset (%s)", old,
48  G_mapset());
49  old = xname;
50  }
51 
52  if (G_strcasecmp(list[n].alias, "vector") == 0) {
53  if ((mapset = G_find_vector2(old, "")) == NULL) {
54  G_warning(_("Vector map <%s> not found"), old);
55  }
56  else {
57  ret = Vect_delete(old);
58  if (ret != -1) {
59  removed = 1;
60  }
61  else {
62  G_warning(_("Unable to delete vector map"));
63  result = 1;
64  }
65  }
66  }
67  else {
68  if (G_strcasecmp(list[n].alias, "raster") == 0) {
69  if ((mapset = G_find_raster2(old, "")) == NULL)
70  G_warning(_("Raster map <%s> not found"), old);
71  }
72 
73  if (G_strcasecmp(list[n].alias, "raster_3d") == 0) {
74  if ((mapset = G_find_raster3d(old, "")) == NULL)
75  G_warning(_("3D raster map <%s> not found"), old);
76  }
77 
78  for (i = 0; i < list[n].nelem; i++) {
79 
80  switch (G_remove(list[n].element[i], old)) {
81  case -1:
82  G_warning(_("Unable to remove %s element"), list[n].desc[i]);
83  result = 1;
84  break;
85  case 0:
86  G_verbose_message(_("%s is missing"), list[n].desc[i]);
87  break;
88  case 1:
89  G_verbose_message(_("%s removed"), list[n].desc[i]);
90  removed = 1;
91  break;
92  }
93  }
94  }
95 
96  if (G_strcasecmp(list[n].element[0], "cell") == 0) {
97  char colr2[6 + GMAPSET_MAX];
98 
99  if (snprintf(colr2, 6 + GMAPSET_MAX, "colr2/%s", G_mapset()) >=
100  6 + GMAPSET_MAX)
101  G_warning(_("String for secondary color table has been truncated"));
102  switch (G_remove(colr2, old)) {
103  case -1:
104  G_warning(_("Unable to remove %s"), colr2);
105  result = 1;
106  break;
107  case 0:
108  G_verbose_message(_("%s is missing"), colr2);
109  break;
110  case 1:
111  G_verbose_message(_("%s removed"), colr2);
112  removed = 1;
113  break;
114  }
115  }
116 
117  M__hold_signals(0);
118 
119  if (!removed)
120  G_warning(_("<%s> nothing removed"), old);
121 
122  return result;
123 }
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
int G_remove(const char *, const char *)
Remove a database file.
Definition: remove.c:44
int Vect_delete(const char *)
Delete vector map including attribute tables.
Definition: map.c:368
#define GMAPSET_MAX
Definition: gis.h:178
int M__hold_signals(int)
Hold signals.
Definition: sighold.c:24
const char * G_find_vector2(const char *, const char *)
Find a vector map (look but don&#39;t touch)
Definition: find_vect.c:62
const char * G_find_raster3d(const char *, const char *)
Search for a 3D raster map in current search path or in a specified mapset.
Definition: find_rast3d.c:28
#define NULL
Definition: ccmath.h:32
Definition: lidar.h:86
void G_message(const char *,...) __attribute__((format(printf
int int G_strcasecmp(const char *, const char *)
String compare ignoring case (upper or lower)
Definition: strings.c:47
int M_do_remove(int n, const char *old)
Remove elements from data base.
Definition: do_remove.c:33
const char * G_mapset(void)
Get current mapset name.
Definition: gis/mapset.c:33
Definition: manage.h:4
#define GNAME_MAX
Definition: gis.h:177
void G_warning(const char *,...) __attribute__((format(printf
#define _(str)
Definition: glocale.h:10
const char * G_find_raster2(const char *, const char *)
Find a raster map (look but don&#39;t touch)
Definition: find_rast.c:76
int nelem
Definition: manage.h:10
int G_name_is_fully_qualified(const char *, char *, char *)
Check if map name is fully qualified (map @ mapset)
Definition: nme_in_mps.c:36
void void G_verbose_message(const char *,...) __attribute__((format(printf