Loading...
Searching...
No Matches
do_remove.c
Go to the documentation of this file.
/*!
\file lib/manage/do_remove.c
\brief Manage Library - Remove elements
(C) 2001-2011 by the GRASS Development Team
This program is free software under the GNU General Public License
(>=v2). Read the file COPYING that comes with GRASS for details.
\author Original author CERL
*/
#include <stdio.h>
#include <string.h>
#include <grass/gis.h>
#include <grass/vector.h>
#include <grass/glocale.h>
#include <grass/raster3d.h>
#include "manage_local_proto.h"
/*!
\brief Remove elements from data base
\param n element id
\param old name of element to be removed
\return 0 on success
\return 1 on error
*/
int M_do_remove(int n, const char *old)
{
int i, ret;
const char *mapset;
int result = 0;
int removed = 0;
char xname[GNAME_MAX], xmapset[GMAPSET_MAX];
G_message(_("Removing %s <%s>"), list[n].maindesc, old);
M__hold_signals(1);
if (G_name_is_fully_qualified(old, xname, xmapset)) {
if (strcmp(xmapset, G_mapset()) != 0)
G_fatal_error("%s is not in the current mapset (%s)", old,
G_mapset());
old = xname;
}
if (G_strcasecmp(list[n].alias, "vector") == 0) {
if ((mapset = G_find_vector2(old, "")) == NULL) {
G_warning(_("Vector map <%s> not found"), old);
}
else {
ret = Vect_delete(old);
if (ret != -1) {
removed = 1;
}
else {
G_warning(_("Unable to delete vector map"));
result = 1;
}
}
}
else {
if (G_strcasecmp(list[n].alias, "raster") == 0) {
if ((mapset = G_find_raster2(old, "")) == NULL)
G_warning(_("Raster map <%s> not found"), old);
}
if (G_strcasecmp(list[n].alias, "raster_3d") == 0) {
if ((mapset = G_find_raster3d(old, "")) == NULL)
G_warning(_("3D raster map <%s> not found"), old);
}
for (i = 0; i < list[n].nelem; i++) {
switch (G_remove(list[n].element[i], old)) {
case -1:
G_warning(_("Unable to remove %s element"), list[n].desc[i]);
result = 1;
break;
case 0:
G_verbose_message(_("%s is missing"), list[n].desc[i]);
break;
case 1:
G_verbose_message(_("%s removed"), list[n].desc[i]);
removed = 1;
break;
}
}
}
if (G_strcasecmp(list[n].element[0], "cell") == 0) {
char colr2[6 + GMAPSET_MAX];
if (snprintf(colr2, 6 + GMAPSET_MAX, "colr2/%s", G_mapset()) >=
6 + GMAPSET_MAX)
G_warning(_("String for secondary color table has been truncated"));
switch (G_remove(colr2, old)) {
case -1:
G_warning(_("Unable to remove %s"), colr2);
result = 1;
break;
case 0:
G_verbose_message(_("%s is missing"), colr2);
break;
case 1:
G_verbose_message(_("%s removed"), colr2);
removed = 1;
break;
}
}
M__hold_signals(0);
if (!removed)
G_warning(_("<%s> nothing removed"), old);
return result;
}
NULL
#define NULL
Definition ccmath.h:32
M_do_remove
int M_do_remove(int n, const char *old)
Remove elements from data base.
Definition do_remove.c:33
G_find_raster3d
const char * G_find_raster3d(const char *name, const char *mapset)
Definition find_rast3d.c:28
G_find_raster2
const char * G_find_raster2(const char *name, const char *mapset)
Find a raster map (look but don't touch).
Definition find_rast.c:76
G_find_vector2
const char * G_find_vector2(const char *name, const char *mapset)
Find a vector map (look but don't touch).
Definition find_vect.c:62
G_verbose_message
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
G_fatal_error
void G_fatal_error(const char *msg,...)
Print a fatal error message to stderr.
Definition gis/error.c:159
G_message
void G_message(const char *msg,...)
Print a message to stderr.
Definition gis/error.c:89
G_warning
void G_warning(const char *msg,...)
Print a warning message to stderr.
Definition gis/error.c:203
G_mapset
const char * G_mapset(void)
Get current mapset name.
Definition mapset.c:33
G_name_is_fully_qualified
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
list
struct list * list
Definition read_list.c:24
G_remove
int G_remove(const char *element, const char *name)
Remove a database file.
Definition remove.c:43
M__hold_signals
int M__hold_signals(int hold)
Hold signals.
Definition sighold.c:24
G_strcasecmp
int G_strcasecmp(const char *x, const char *y)
String compare ignoring case (upper or lower).
Definition strings.c:47
element
Definition lidar.h:85