~ubuntu-branches/ubuntu/vivid/grass/vivid-proposed

« back to all changes in this revision

Viewing changes to lib/manage/do_rename.c

  • Committer: Package Import Robot
  • Author(s): Bas Couwenberg
  • Date: 2015-02-20 23:12:08 UTC
  • mfrom: (8.2.6 experimental)
  • Revision ID: package-import@ubuntu.com-20150220231208-1u6qvqm84v430b10
Tags: 7.0.0-1~exp1
* New upstream release.
* Update python-ctypes-ternary.patch to use if/else instead of and/or.
* Drop check4dev patch, rely on upstream check.
* Add build dependency on libpq-dev to grass-dev for libpq-fe.h.
* Drop patches applied upstream, refresh remaining patches.
* Update symlinks for images switched from jpg to png.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 <stdlib.h>
 
15
#include <string.h>
 
16
 
 
17
#include <grass/gis.h>
 
18
#include <grass/vector.h>
 
19
#include <grass/raster3d.h>
 
20
#include <grass/glocale.h>
 
21
 
 
22
#include "manage_local_proto.h"
 
23
 
 
24
/*!
 
25
  \brief Rename element
 
26
 
 
27
  \param n element id
 
28
  \param old source name
 
29
  \param new destination name
 
30
 
 
31
  \return 0 on success
 
32
  \return 1 on error
 
33
*/
 
34
int M_do_rename(int n, const char *old, const char *new)
 
35
{
 
36
    int i, ret;
 
37
    int len;
 
38
    const char *mapset;
 
39
    int result = 0;
 
40
    int renamed = 0;
 
41
 
 
42
    G_message(_("Rename %s <%s> to <%s>"),
 
43
              list[n].maindesc, old, new);
 
44
    
 
45
    if (G_strcasecmp(old, new) == 0)
 
46
        return 1;
 
47
 
 
48
    len = M__get_description_len(n);
 
49
 
 
50
    M__hold_signals(1);
 
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_rename(old, new);
 
58
            if (ret != -1) {
 
59
                renamed = 1;
 
60
            }
 
61
            else {
 
62
                G_warning(_("Unable to rename vector map <%s> to <%s>"),
 
63
                          old, new);
 
64
                result = 1;
 
65
            }
 
66
        }
 
67
    }
 
68
    else {
 
69
        if (G_strcasecmp(list[n].alias, "raster") == 0) {
 
70
            if ((mapset = G_find_raster2(old, "")) == NULL)
 
71
                G_warning(_("Raster map <%s> not found"), old);
 
72
        }
 
73
 
 
74
        if (G_strcasecmp(list[n].alias, "raster_3d") == 0) {
 
75
            if ((mapset = G_find_raster3d(old, "")) == NULL)
 
76
                G_warning(_("3D raster map <%s> not found"), old);
 
77
        }
 
78
 
 
79
        for (i = 0; i < list[n].nelem; i++) {
 
80
            G_remove(list[n].element[i], new);
 
81
            switch (G_rename(list[n].element[i], old, new)) {
 
82
            case -1:
 
83
                G_warning(_("Unable to rename %s"), list[n].desc[i]);
 
84
                result = 1;
 
85
                break;
 
86
            case 0:
 
87
                G_verbose_message(_("%s is missing"), list[n].desc[i]);
 
88
                break;
 
89
            case 1:
 
90
                G_verbose_message(_("%s renamed"), list[n].desc[i]);
 
91
                renamed = 1;
 
92
                break;
 
93
            }
 
94
        }
 
95
 
 
96
        if (G_strcasecmp(list[n].element[0], "cell") == 0) {
 
97
            char colr2[50];
 
98
 
 
99
            sprintf(colr2, "colr2/%s", G_mapset());
 
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
}