main.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /****************************************************************************
  2. *
  3. * MODULE: cmd
  4. * AUTHOR(S): CERL (original contributor)
  5. * Radim Blazek <radim.blazek gmail.com>,
  6. * Cedric Shock <cedricgrass shockfamily.net>,
  7. * Huidae Cho <grass4u gmail.com>,
  8. * Glynn Clements <glynn gclements.plus.com>,
  9. * Markus Neteler <neteler itc.it>,
  10. * Martin Landa <landa.martin gmail.com>
  11. * PURPOSE: lets users copy database files
  12. * COPYRIGHT: (C) 2003-2007 by the GRASS Development Team
  13. *
  14. * This program is free software under the GNU General Public
  15. * License (>=v2). Read the file COPYING that comes with GRASS
  16. * for details.
  17. *
  18. *****************************************************************************/
  19. #include <stdlib.h>
  20. #include <string.h>
  21. #include <grass/gis.h>
  22. #include <grass/glocale.h>
  23. #include <grass/manage.h>
  24. int main(int argc, char *argv[])
  25. {
  26. int i, n, nlist;
  27. const char *mapset;
  28. struct GModule *module;
  29. struct Option **parm;
  30. char *from, *to;
  31. int result = EXIT_SUCCESS;
  32. G_gisinit(argv[0]);
  33. M_read_list(FALSE, &nlist);
  34. module = G_define_module();
  35. G_add_keyword(_("general"));
  36. G_add_keyword(_("map management"));
  37. G_add_keyword(_("copy"));
  38. module->description =
  39. _("Copies available data files in the current mapset "
  40. "search path to the user's current mapset.");
  41. module->overwrite = 1;
  42. parm = (struct Option **) G_calloc(nlist, sizeof(struct Option *));
  43. for (n = 0; n < nlist; n++) {
  44. parm[n] = M_define_option(n, _("copied"), NO);
  45. }
  46. if (G_parser(argc, argv))
  47. exit(EXIT_FAILURE);
  48. for (n = 0; n < nlist; n++) {
  49. if (parm[n]->answers == NULL)
  50. continue;
  51. i = 0;
  52. while (parm[n]->answers[i]) {
  53. from = parm[n]->answers[i++];
  54. to = parm[n]->answers[i++];
  55. mapset = M_find(n, from, "");
  56. if (!mapset) {
  57. G_warning(_("<%s> not found"), from);
  58. continue;
  59. }
  60. if (G_strcasecmp(mapset, G_mapset()) == 0 &&
  61. G_strcasecmp(from, to) == 0) {
  62. G_warning(_("%s=%s,%s: files are the same, no copy required"),
  63. parm[n]->key, from, to);
  64. continue;
  65. }
  66. if (M_find(n, to, G_mapset()) && !(module->overwrite)) {
  67. G_warning(_("<%s> already exists"), to);
  68. continue;
  69. }
  70. if (G_legal_filename(to) < 0) {
  71. G_warning(_("<%s> is an illegal file name"), to);
  72. continue;
  73. }
  74. if (M_do_copy(n, from, mapset, to) == 1) {
  75. result = EXIT_FAILURE;
  76. }
  77. G_remove_misc("cell_misc", "reclassed_to", to);
  78. }
  79. }
  80. exit(result);
  81. }