~ubuntu-branches/ubuntu/vivid/grass/vivid-proposed

« back to all changes in this revision

Viewing changes to lib/gis/location.c

  • Committer: Package Import Robot
  • Author(s): Bas Couwenberg
  • Date: 2015-02-20 23:12:08 UTC
  • mfrom: (8.2.6 experimental)
  • Revision ID: package-import@ubuntu.com-20150220231208-1u6qvqm84v430b10
Tags: 7.0.0-1~exp1
* New upstream release.
* Update python-ctypes-ternary.patch to use if/else instead of and/or.
* Drop check4dev patch, rely on upstream check.
* Add build dependency on libpq-dev to grass-dev for libpq-fe.h.
* Drop patches applied upstream, refresh remaining patches.
* Update symlinks for images switched from jpg to png.

Show diffs side-by-side

added added

removed removed

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