~ubuntu-branches/ubuntu/precise/grass/precise

« back to all changes in this revision

Viewing changes to imagery/i.ortho.photo/photo.2image/target.c

  • Committer: Bazaar Package Importer
  • Author(s): Francesco Paolo Lovergine
  • Date: 2011-04-13 17:08:41 UTC
  • mfrom: (8.1.7 sid)
  • Revision ID: james.westby@ubuntu.com-20110413170841-ss1t9bic0d0uq0gz
Tags: 6.4.1-1
* New upstream version.
* Now build-dep on libjpeg-dev and current libreadline6-dev.
* Removed patch swig: obsolete.
* Policy bumped to 3.9.2, without changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#include <unistd.h>
2
 
#include <string.h>
3
 
#include <grass/gis.h>
4
 
#include <grass/imagery.h>
5
 
#include "globals.h"
6
 
 
7
 
 
8
 
/* read the target for the group and cast it into the alternate GRASS env */
9
 
 
10
 
 
11
 
static int which_env;
12
 
static char buf[1024];
13
 
 
14
 
 
15
 
int get_target(void)
16
 
{
17
 
    char location[40];
18
 
    char mapset[40];
19
 
    int stat;
20
 
 
21
 
    if (!I_get_target(group.name, location, mapset)) {
22
 
        sprintf(buf, "Target information for group [%s] missing\n",
23
 
                group.name);
24
 
        goto error;
25
 
    }
26
 
 
27
 
    sprintf(buf, "%s/%s", G_gisdbase(), location);
28
 
    if (access(buf, 0) != 0) {
29
 
        sprintf(buf, "Target location [%s] not found\n", location);
30
 
        goto error;
31
 
    }
32
 
    G__create_alt_env();
33
 
    G__setenv("LOCATION_NAME", location);
34
 
    stat = G__mapset_permissions(mapset);
35
 
    if (stat > 0) {
36
 
        G__setenv("MAPSET", mapset);
37
 
        G__create_alt_search_path();
38
 
        G__switch_env();
39
 
        G__switch_search_path();
40
 
        which_env = 0;
41
 
        return 1;
42
 
    }
43
 
    sprintf(buf, "Mapset [%s] in target location [%s] - ", mapset, location);
44
 
    strcat(buf, stat == 0 ? "permission denied\n" : "not found\n");
45
 
 
46
 
  error:
47
 
    strcat(buf, "Please run i.target for group ");
48
 
    strcat(buf, group.name);
49
 
    G_fatal_error(buf);
50
 
 
51
 
    return -1;
52
 
}
53
 
 
54
 
int select_current_env(void)
55
 
{
56
 
    if (which_env != 0) {
57
 
        G__switch_env();
58
 
        G__switch_search_path();
59
 
        which_env = 0;
60
 
    }
61
 
 
62
 
    return 0;
63
 
}
64
 
 
65
 
int select_target_env(void)
66
 
{
67
 
    if (which_env != 1) {
68
 
        G__switch_env();
69
 
        G__switch_search_path();
70
 
        which_env = 1;
71
 
    }
72
 
 
73
 
    return 0;
74
 
}