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