main.c 2.2 KB

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