GRASS 8 Programmer's Manual
8.5.0(2026)-8d6ceba290
Toggle main menu visibility
Loading...
Searching...
No Matches
do_rename.c
Go to the documentation of this file.
1
/*!
2
\file lib/manage/do_rename.c
3
4
\brief Manage Library - Rename 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 <stdlib.h>
16
#include <string.h>
17
18
#include <grass/gis.h>
19
#include <grass/vector.h>
20
#include <grass/raster3d.h>
21
#include <grass/glocale.h>
22
23
#include "manage_local_proto.h"
24
25
/*!
26
\brief Rename element
27
28
\param n element id
29
\param old source name
30
\param new destination name
31
32
\return 0 on success
33
\return 1 on error
34
*/
35
int
M_do_rename
(
int
n,
const
char
*old,
const
char
*
new
)
36
{
37
int
i, ret;
38
const
char
*mapset;
39
int
result = 0;
40
int
renamed = 0;
41
42
G_message
(_(
"Rename %s <%s> to <%s>"
),
list
[n].maindesc, old,
new
);
43
44
if
(
G_strcasecmp
(old,
new
) == 0)
45
return
1;
46
47
M__hold_signals
(1);
48
49
if
(
G_strcasecmp
(
list
[n].alias,
"vector"
) == 0) {
50
if
((mapset =
G_find_vector2
(old,
""
)) ==
NULL
) {
51
G_warning
(_(
"Vector map <%s> not found"
), old);
52
}
53
else
{
54
ret = Vect_rename(old,
new
);
55
if
(ret != -1) {
56
renamed = 1;
57
}
58
else
{
59
G_warning
(_(
"Unable to rename vector map <%s> to <%s>"
), old,
60
new
);
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
G_remove
(
list
[n].
element
[i],
new
);
78
switch
(
G_rename
(
list
[n].
element
[i], old,
new
)) {
79
case
-1:
80
G_warning
(_(
"Unable to rename %s"
),
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 renamed"
),
list
[n].desc[i]);
88
renamed = 1;
89
break
;
90
}
91
}
92
93
if
(
G_strcasecmp
(
list
[n].
element
[0],
"cell"
) == 0) {
94
char
colr2[6 + GMAPSET_MAX];
95
96
if
(snprintf(colr2, 6 + GMAPSET_MAX,
"colr2/%s"
,
G_mapset
()) >=
97
6 + GMAPSET_MAX)
98
G_warning
(
99
_(
"String for secondary color table has been truncated"
));
100
G_remove
(colr2,
new
);
101
switch
(
G_rename
(colr2, old,
new
)) {
102
case
-1:
103
G_warning
(_(
"Unable to rename %s"
), colr2);
104
result = 1;
105
break
;
106
case
0:
107
G_verbose_message
(_(
"%s is missing"
), colr2);
108
break
;
109
case
1:
110
G_verbose_message
(_(
"%s renamed"
), colr2);
111
renamed = 1;
112
break
;
113
}
114
}
115
}
116
M__hold_signals
(0);
117
118
if
(!renamed)
119
G_warning
(_(
"<%s> nothing renamed"
), old);
120
121
return
result;
122
}
NULL
#define NULL
Definition
ccmath.h:32
M_do_rename
int M_do_rename(int n, const char *old, const char *new)
Rename element.
Definition
do_rename.c:35
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_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
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
G_rename
int G_rename(const char *element, const char *oldname, const char *newname)
Rename a database file.
Definition
rename.c:69
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
manage
do_rename.c
Generated on
for GRASS 8 Programmer's Manual by
1.17.0