main.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /****************************************************************************
  2. *
  3. * MODULE: g.filename
  4. * AUTHOR(S): Michael Shapiro CERL (original contributor)
  5. * Markus Neteler <neteler itc.it>,
  6. * Bernhard Reiter <bernhard intevation.de>,
  7. * Glynn Clements <glynn gclements.plus.com>,
  8. * Hamish Bowman <hamish_b yahoo.com>,
  9. * Jan-Oliver Wagner <jan intevation.de>
  10. * PURPOSE: Prints GRASS data base file names
  11. * COPYRIGHT: (C) 1999-2006 by the GRASS Development Team
  12. *
  13. * This program is free software under the GNU General Public
  14. * License (>=v2). Read the file COPYING that comes with GRASS
  15. * for details.
  16. *
  17. *****************************************************************************/
  18. #include <stdio.h>
  19. #include <string.h>
  20. #include <stdlib.h>
  21. #include <grass/gis.h>
  22. #include <grass/glocale.h>
  23. int main(int argc, char *argv[])
  24. {
  25. char path[1024];
  26. const char *element;
  27. const char *mapset;
  28. const char *name;
  29. struct GModule *module;
  30. struct Option *opt1;
  31. struct Option *opt2;
  32. struct Option *opt3;
  33. G_gisinit(argv[0]);
  34. module = G_define_module();
  35. G_add_keyword(_("general"));
  36. G_add_keyword(_("map management"));
  37. G_add_keyword(_("scripts"));
  38. module->description = _("Prints GRASS data base file names.");
  39. /* Define the different options */
  40. opt1 = G_define_option();
  41. opt1->key = "element";
  42. opt1->type = TYPE_STRING;
  43. opt1->required = YES;
  44. opt1->description = _("Name of an element");
  45. opt3 = G_define_option();
  46. opt3->key = "file";
  47. opt3->type = TYPE_STRING;
  48. opt3->required = YES;
  49. opt3->description = _("Name of a database file");
  50. opt2 = G_define_option();
  51. opt2->key = "mapset";
  52. opt2->type = TYPE_STRING;
  53. opt2->required = NO;
  54. opt2->description = _("Name of a mapset (default: current)");
  55. if (G_parser(argc, argv))
  56. exit(EXIT_FAILURE);
  57. element = opt1->answer;
  58. name = opt3->answer;
  59. if (opt2->answer)
  60. mapset = opt2->answer;
  61. else
  62. mapset = G_mapset();
  63. if (strcmp(mapset, ".") == 0 || strcmp(mapset, "") == 0)
  64. mapset = G_mapset();
  65. G_make_mapset_element(element);
  66. G_file_name(path, element, name, mapset);
  67. fprintf(stdout, "file='%s'\n", path);
  68. exit(EXIT_SUCCESS);
  69. }