location.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*!
  2. \file location.c
  3. \brief GIS library - environment routines (location)
  4. (C) 2001-2008 by the GRASS Development Team
  5. This program is free software under the
  6. GNU General Public License (>=v2).
  7. Read the file COPYING that comes with GRASS
  8. for details.
  9. \author Original author CERL
  10. */
  11. #include <stdio.h>
  12. #include <string.h>
  13. #include <unistd.h>
  14. #include <sys/types.h>
  15. #include <grass/gis.h>
  16. #include <grass/glocale.h>
  17. /*!
  18. * \brief Get current location directory
  19. *
  20. * Returns the full UNIX path name of the current database
  21. * location. For example, if the user is working in location
  22. * <i>spearfish</i> in the <i>/home/user/grassdata</i> database
  23. * directory, this routine will return a string which looks like
  24. * <i>/home/user/grassdata/spearfish</i>.
  25. *
  26. * \param
  27. * \return char *
  28. */
  29. char *G_location_path(void)
  30. {
  31. char *location;
  32. location = G__location_path();
  33. if (access(location, 0) != 0) {
  34. perror("access");
  35. G_fatal_error(_("LOCATION << %s >> not available"), location);
  36. }
  37. return location;
  38. }
  39. /*!
  40. * \brief Get current location name
  41. *
  42. * Returns the name of the current database location. This routine
  43. * should be used by modules that need to display the current location
  44. * to the user. See Locations for an explanation of locations.
  45. *
  46. * \param
  47. * \return char* tolocation name
  48. */
  49. char *G_location(void)
  50. {
  51. return G_getenv("LOCATION_NAME");
  52. }
  53. /*!
  54. * \brief Get current location path
  55. *
  56. * \param
  57. * \return char* to location path
  58. */
  59. char *G__location_path(void)
  60. {
  61. char *location = 0;
  62. char *base;
  63. char *name;
  64. name = G_location();
  65. base = G_gisdbase();
  66. location = G_malloc(strlen(base) + strlen(name) + 2);
  67. sprintf(location, "%s/%s", base, name);
  68. return location;
  69. }