GRASS GIS 7 Programmer's Manual  7.5.svn(2018)-r72097
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 <string.h>
15 
16 #include <grass/gis.h>
17 #include <grass/vector.h>
18 #include <grass/glocale.h>
19 #include <grass/raster3d.h>
20 
21 #include "manage_local_proto.h"
22 
23 /*!
24  \brief Remove elements from data base
25 
26  \param n element id
27  \param old name of element to be removed
28 
29  \return 0 on success
30  \return 1 on error
31 */
32 int M_do_remove(int n, const char *old)
33 {
34  int i, ret;
35 
36  /* int len; */
37  const char *mapset;
38  int result = 0;
39  int removed = 0;
40  char xname[GNAME_MAX], xmapset[GMAPSET_MAX];
41 
42  G_message(_("Removing %s <%s>"), list[n].maindesc, old);
43 
44  /* len = get_description_len(n); */
45 
46  M__hold_signals(1);
47 
48  if (G_name_is_fully_qualified(old, xname, xmapset)) {
49  if (strcmp(xmapset, G_mapset()) != 0)
50  G_fatal_error("%s is not in the current mapset (%s)", old,
51  G_mapset());
52  old = xname;
53  }
54 
55  if (G_strcasecmp(list[n].alias, "vector") == 0) {
56  if ((mapset = G_find_vector2(old, "")) == NULL) {
57  G_warning(_("Vector map <%s> not found"), old);
58  }
59  else {
60  ret = Vect_delete(old);
61  if (ret != -1) {
62  removed = 1;
63  }
64  else {
65  G_warning(_("Unable to delete vector map"));
66  result = 1;
67  }
68  }
69  }
70  else {
71  if (G_strcasecmp(list[n].alias, "raster") == 0) {
72  if ((mapset = G_find_raster2(old, "")) == NULL)
73  G_warning(_("Raster map <%s> not found"), old);
74  }
75 
76  if (G_strcasecmp(list[n].alias, "raster_3d") == 0) {
77  if ((mapset = G_find_raster3d(old, "")) == NULL)
78  G_warning(_("3D raster map <%s> not found"), old);
79  }
80 
81  for (i = 0; i < list[n].nelem; i++) {
82 
83  switch (G_remove(list[n].element[i], old)) {
84  case -1:
85  G_warning(_("Unable to remove %s element"), list[n].desc[i]);
86  result = 1;
87  break;
88  case 0:
89  G_verbose_message(_("%s is missing"), list[n].desc[i]);
90  break;
91  case 1:
92  G_verbose_message(_("%s removed"), list[n].desc[i]);
93  removed = 1;
94  break;
95  }
96  }
97  }
98 
99  if (G_strcasecmp(list[n].element[0], "cell") == 0) {
100  char colr2[GPATH_MAX];
101 
102  G_snprintf(colr2, GPATH_MAX, "colr2/%s", G_mapset());
103  switch (G_remove(colr2, old)) {
104  case -1:
105  G_warning(_("Unable to remove %s"), colr2);
106  result = 1;
107  break;
108  case 0:
109  G_verbose_message(_("%s is missing"), colr2);
110  break;
111  case 1:
112  G_verbose_message(_("%s removed"), colr2);
113  removed = 1;
114  break;
115  }
116  }
117 
118  M__hold_signals(0);
119 
120  if (!removed)
121  G_warning(_("<%s> nothing removed"), old);
122 
123  return result;
124 }
int G_strcasecmp(const char *x, const char *y)
String compare ignoring case (upper or lower)
Definition: strings.c:46
#define GMAPSET_MAX
Definition: gis.h:149
void G_verbose_message(const char *msg,...)
Print a message to stderr but only if module is in verbose mode.
Definition: gis/error.c:108
int old
Definition: raster3d/cats.c:84
#define NULL
Definition: ccmath.h:32
void G_fatal_error(const char *msg,...)
Print a fatal error message to stderr.
Definition: gis/error.c:159
int G_snprintf(char *str, size_t size, const char *fmt,...)
snprintf() clone.
Definition: snprintf.c:43
Definition: lidar.h:89
const char * G_find_raster3d(const char *name, const char *mapset)
Search for a 3D raster map in current search path or in a specified mapset.
Definition: find_rast3d.c:28
int Vect_delete(const char *map)
Delete vector map including attribute tables.
Definition: map.c:369
#define GPATH_MAX
Definition: gis.h:151
int G_remove(const char *element, const char *name)
Remove a database file.
Definition: remove.c:44
int M_do_remove(int n, const char *old)
Remove elements from data base.
Definition: do_remove.c:32
Definition: manage.h:4
#define GNAME_MAX
Definition: gis.h:148
#define _(str)
Definition: glocale.h:13
int M__hold_signals(int hold)
Hold signals.
Definition: sighold.c:24
void G_message(const char *msg,...)
Print a message to stderr.
Definition: gis/error.c:89
const char * G_find_raster2(const char *name, const char *mapset)
Find a raster map (look but don&#39;t touch)
Definition: find_rast.c:76
int G_name_is_fully_qualified(const char *fullname, char *name, char *mapset)
Check if map name is fully qualified (map @ mapset)
Definition: nme_in_mps.c:36
const char * G_mapset(void)
Get current mapset name.
Definition: gis/mapset.c:33
const char * G_find_vector2(const char *name, const char *mapset)
Find a vector map (look but don&#39;t touch)
Definition: find_vect.c:62
int nelem
Definition: manage.h:10
void G_warning(const char *msg,...)
Print a warning message to stderr.
Definition: gis/error.c:203