main.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. module->description = _("Prints GRASS data base file names.");
  38. /* Define the different options */
  39. opt1 = G_define_option();
  40. opt1->key = "element";
  41. opt1->type = TYPE_STRING;
  42. opt1->required = YES;
  43. opt1->description = _("Name of an element");
  44. opt3 = G_define_option();
  45. opt3->key = "file";
  46. opt3->type = TYPE_STRING;
  47. opt3->required = YES;
  48. opt3->description = _("Name of a database file");
  49. opt2 = G_define_option();
  50. opt2->key = "mapset";
  51. opt2->type = TYPE_STRING;
  52. opt2->required = NO;
  53. opt2->description = _("Name of a mapset (default: current)");
  54. if (G_parser(argc, argv))
  55. exit(EXIT_FAILURE);
  56. element = opt1->answer;
  57. name = opt3->answer;
  58. if (opt2->answer)
  59. mapset = opt2->answer;
  60. else
  61. mapset = G_mapset();
  62. if (strcmp(mapset, ".") == 0 || strcmp(mapset, "") == 0)
  63. mapset = G_mapset();
  64. G__make_mapset_element(element);
  65. G_file_name(path, element, name, mapset);
  66. fprintf(stdout, "file='%s'\n", path);
  67. exit(EXIT_SUCCESS);
  68. }