main.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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/glocale.h>
  22. #include <grass/list.h>
  23. int main(int argc, char *argv[])
  24. {
  25. int i, n;
  26. const char *mapset;
  27. struct GModule *module;
  28. struct Option **parm, *p;
  29. char *from, *to;
  30. int result = EXIT_SUCCESS;
  31. G_gisinit(argv[0]);
  32. read_list(0);
  33. module = G_define_module();
  34. G_add_keyword(_("general"));
  35. G_add_keyword(_("map management"));
  36. module->description =
  37. _("Copies available data files in the user's current mapset "
  38. "search path and location to the appropriate element "
  39. "directories under the user's current mapset.");
  40. parm = (struct Option **)G_calloc(nlist, sizeof(struct Option *));
  41. for (n = 0; n < nlist; n++) {
  42. char *str;
  43. p = parm[n] = G_define_option();
  44. p->key = list[n].alias;
  45. p->key_desc = "from,to";
  46. p->type = TYPE_STRING;
  47. p->required = NO;
  48. p->multiple = NO;
  49. G_asprintf(&str, "old,%s,%s", list[n].mainelem, list[n].maindesc);
  50. p->gisprompt = str;
  51. G_asprintf(&str, _("%s file(s) to be copied"), list[n].alias);
  52. p->description = str;
  53. }
  54. if (G_parser(argc, argv))
  55. exit(EXIT_FAILURE);
  56. for (n = 0; n < nlist; n++) {
  57. if (parm[n]->answers == NULL)
  58. continue;
  59. i = 0;
  60. while (parm[n]->answers[i]) {
  61. from = parm[n]->answers[i++];
  62. to = parm[n]->answers[i++];
  63. mapset = find(n, from, "");
  64. if (!mapset) {
  65. G_warning(_("<%s> not found"), from);
  66. continue;
  67. }
  68. if (G_strcasecmp(mapset, G_mapset()) == 0 &&
  69. G_strcasecmp(from, to) == 0) {
  70. G_warning(_("%s=%s,%s: files are the same, no copy required"),
  71. parm[n]->key, from, to);
  72. continue;
  73. }
  74. if (find(n, to, G_mapset()) && !(module->overwrite)) {
  75. G_warning(_("<%s> already exists"), to);
  76. continue;
  77. }
  78. if (G_legal_filename(to) < 0) {
  79. G_warning(_("<%s> is an illegal file name"), to);
  80. continue;
  81. }
  82. if (do_copy(n, from, mapset, to) == 1) {
  83. result = EXIT_FAILURE;
  84. }
  85. G_remove_misc("cell_misc", "reclassed_to", to);
  86. }
  87. }
  88. exit(result);
  89. }