GRASS GIS 7 Programmer's Manual  7.5.svn(2017)-r71759
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
do_copy.c
Go to the documentation of this file.
1 /*!
2  \file lib/manage/do_copy.c
3 
4  \brief Manage Library - Copy element
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 <string.h>
16 #include <unistd.h>
17 
18 #include <grass/gis.h>
19 #include <grass/glocale.h>
20 #include <grass/vector.h>
21 
22 #include "manage_local_proto.h"
23 
24 /*!
25  \brief Copy element
26 
27  \param n element id
28  \param old source name
29  \param mapset name of source mapset
30  \param new destination name
31 
32  \return 0 on success
33  \return 1 on error
34 */
35 int M_do_copy(int n, const char *old, const char *mapset, const char *new)
36 {
37  int i, ret;
38  char path[GPATH_MAX], path2[GPATH_MAX];
39  int result = 0;
40 
41  G_debug(3, "Copy %s", list[n].alias);
42 
43  G_message(_("Copy %s <%s> to current mapset as <%s>"),
44  list[n].maindesc, G_fully_qualified_name(old, mapset), new);
45 
46  M__hold_signals(1);
47  if (G_strcasecmp(list[n].alias, "vector") == 0) {
48  ret = Vect_copy(old, mapset, new);
49  if (ret == -1) {
50  G_warning(_("Unable to copy <%s> to current mapset as <%s>"),
51  G_fully_qualified_name(old, mapset), new);
52  result = 1;
53  }
54  }
55  else {
56  for (i = 0; i < list[n].nelem; i++) {
58  G_file_name(path, list[n].element[i], old, mapset);
59  if (access(path, 0) != 0) {
60  G_remove(list[n].element[i], new);
61  G_verbose_message(_("%s is missing"), list[n].desc[i]);
62 
63  continue;
64  }
65  G_file_name(path2, list[n].element[i], new, G_mapset());
66  if (G_recursive_copy(path, path2) == 1) {
67  G_warning(_("Unable to copy <%s> to current mapset as <%s>"),
68  G_fully_qualified_name(old, mapset), new);
69  result = 1;
70  }
71  else {
72  G_verbose_message(_("%s copied"), list[n].desc[i]);
73  }
74  }
75  }
76 
77  /* special case: remove (yes, remove) the secondary color table, if it exists */
78  if (G_strcasecmp(list[n].element[0], "cell") == 0) {
79  char colr2[GNAME_MAX];
80 
81  sprintf(colr2, "colr2/%s", G_mapset());
82  G_remove(colr2, new);
83  }
84  M__hold_signals(0);
85 
86  return result;
87 }
int G_make_mapset_element(const char *p_element)
Create element in the current mapset.
Definition: mapset_msc.c:38
int G_strcasecmp(const char *x, const char *y)
String compare ignoring case (upper or lower)
Definition: strings.c:46
int M_do_copy(int n, const char *old, const char *mapset, const char *new)
Copy element.
Definition: do_copy.c:35
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
int G_recursive_copy(const char *src, const char *dst)
Copy recursively source directory to destination directory.
Definition: copy_dir.c:70
Definition: lidar.h:89
char * G_file_name(char *path, const char *element, const char *name, const char *mapset)
Builds full path names to GIS data files.
Definition: file_name.c:38
int G_debug(int level, const char *msg,...)
Print debugging message.
Definition: debug.c:65
#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 Vect_copy(const char *in, const char *mapset, const char *out)
Copy vector map including attribute tables.
Definition: map.c:123
Definition: manage.h:4
#define GNAME_MAX
Definition: gis.h:148
Definition: path.h:16
#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
char * G_fully_qualified_name(const char *name, const char *mapset)
Get fully qualified element name.
Definition: nme_in_mps.c:101
const char * G_mapset(void)
Get current mapset name.
Definition: gis/mapset.c:33
int nelem
Definition: manage.h:10
void G_warning(const char *msg,...)
Print a warning message to stderr.
Definition: gis/error.c:203