123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- /****************************************************************************
- *
- * MODULE: cmd
- * AUTHOR(S): CERL (original contributor)
- * Radim Blazek <radim.blazek gmail.com>,
- * Cedric Shock <cedricgrass shockfamily.net>,
- * Huidae Cho <grass4u gmail.com>,
- * Glynn Clements <glynn gclements.plus.com>,
- * Markus Neteler <neteler itc.it>,
- * Martin Landa <landa.martin gmail.com>
- * PURPOSE: lets users copy database files
- * COPYRIGHT: (C) 2003-2007 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.
- *
- *****************************************************************************/
- #include <stdlib.h>
- #include <string.h>
- #include <grass/glocale.h>
- #include <grass/list.h>
- int main(int argc, char *argv[])
- {
- int i, n;
- const char *mapset;
- struct GModule *module;
- struct Option **parm, *p;
- char *from, *to;
- int result = EXIT_SUCCESS;
- G_gisinit(argv[0]);
- read_list(0);
- module = G_define_module();
- G_add_keyword(_("general"));
- G_add_keyword(_("map management"));
- module->description =
- _("Copies available data files in the user's current mapset "
- "search path and location to the appropriate element "
- "directories under the user's current mapset.");
- parm = (struct Option **)G_calloc(nlist, sizeof(struct Option *));
- for (n = 0; n < nlist; n++) {
- char *str;
- p = parm[n] = G_define_option();
- p->key = list[n].alias;
- p->key_desc = "from,to";
- p->type = TYPE_STRING;
- p->required = NO;
- p->multiple = NO;
- G_asprintf(&str, "old,%s,%s", list[n].mainelem, list[n].maindesc);
- p->gisprompt = str;
- G_asprintf(&str, _("%s file(s) to be copied"), list[n].alias);
- p->description = str;
- }
- if (G_parser(argc, argv))
- exit(EXIT_FAILURE);
- for (n = 0; n < nlist; n++) {
- if (parm[n]->answers == NULL)
- continue;
- i = 0;
- while (parm[n]->answers[i]) {
- from = parm[n]->answers[i++];
- to = parm[n]->answers[i++];
- mapset = find(n, from, "");
- if (!mapset) {
- G_warning(_("<%s> not found"), from);
- continue;
- }
- if (G_strcasecmp(mapset, G_mapset()) == 0 &&
- G_strcasecmp(from, to) == 0) {
- G_warning(_("%s=%s,%s: files are the same, no copy required"),
- parm[n]->key, from, to);
- continue;
- }
- if (find(n, to, G_mapset()) && !(module->overwrite)) {
- G_warning(_("<%s> already exists"), to);
- continue;
- }
- if (G_legal_filename(to) < 0) {
- G_warning(_("<%s> is an illegal file name"), to);
- continue;
- }
- if (do_copy(n, from, mapset, to) == 1) {
- result = EXIT_FAILURE;
- }
- G_remove_misc("cell_misc", "reclassed_to", to);
- }
- }
- exit(result);
- }
|