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

« back to all changes in this revision

Viewing changes to imagery/i.points/digit.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
 
#include "globals.h"
2
 
#include "local_proto.h"
3
 
#include <unistd.h>
4
 
#include <stdlib.h>
5
 
 
6
 
static int setup(void);
7
 
static int oops(void);
8
 
static int yes(void);
9
 
static int no(void);
10
 
 
11
 
int setup_digitizer(void)
12
 
{
13
 
    static int use = 1;
14
 
    static Objects objects[] = {
15
 
        INFO("Do you wish to use the digitizer?  ", &use),
16
 
        MENU("YES", yes, &use),
17
 
        MENU("NO", no, &use),
18
 
        {0}
19
 
    };
20
 
    char command[1024];
21
 
 
22
 
    use_digitizer = 0;
23
 
    /*
24
 
     * test to see if we have a digitizer (geo.quest)
25
 
     * make sure this program has execute permission first.
26
 
     * then run the program and check its exit status
27
 
     *  0 means can use digitizer, other means can't
28
 
     */
29
 
    sprintf(command, "%s/etc/geo.quest", G_gisbase());
30
 
    if (access(command, 1) != 0)
31
 
        return 0;
32
 
    if (system(command))
33
 
        return 0;
34
 
 
35
 
 
36
 
    /*
37
 
     * ask the user if he/she wishes to use it
38
 
     */
39
 
    Start_mouse_in_menu();
40
 
    Input_pointer(objects);
41
 
    if (use_digitizer)
42
 
        Input_other(setup, "Keyboard");
43
 
 
44
 
    return 0;
45
 
}
46
 
 
47
 
static int setup(void)
48
 
{
49
 
    char command[1024];
50
 
 
51
 
    /*
52
 
     * setup the digitizer. system() call must exit with 0 to indicate
53
 
     * everything went fine
54
 
     */
55
 
    sprintf(command, "%s/etc/geo.reg %s %d",
56
 
            G_gisbase(), digit_points, getpid());
57
 
    Suspend_curses();
58
 
    if (system(command)) {
59
 
        use_digitizer = 0;
60
 
        G_sleep(3);
61
 
    }
62
 
    Resume_curses();
63
 
 
64
 
    return 0;
65
 
}
66
 
 
67
 
int digitizer_point(double *east, double *north)
68
 
{
69
 
    char command[1024];
70
 
    FILE *fd;
71
 
    int stat;
72
 
 
73
 
    /* make sure digitzer is to be used */
74
 
    if (!use_digitizer)
75
 
        return 0;
76
 
 
77
 
    sprintf(command, "%s/etc/geo.point %s %s",
78
 
            G_gisbase(), digit_points, digit_results);
79
 
 
80
 
    Suspend_curses();
81
 
    if (system(command)) {
82
 
        G_sleep(3);
83
 
        Resume_curses();
84
 
        oops();
85
 
        return 0;
86
 
    }
87
 
    Resume_curses();
88
 
    fd = fopen(digit_results, "r");
89
 
    if (fd == NULL) {
90
 
        oops();
91
 
        return 0;
92
 
    }
93
 
    stat = (fscanf(fd, "%lf %lf", east, north) == 2);
94
 
    fclose(fd);
95
 
 
96
 
    if (stat == 0)
97
 
        oops();
98
 
    return stat;
99
 
}
100
 
 
101
 
static int oops(void)
102
 
{
103
 
    Curses_clear_window(MENU_WINDOW);
104
 
    Curses_write_window(MENU_WINDOW, 3, 2, "Can't get data from digitizer");
105
 
 
106
 
    return 0;
107
 
}
108
 
 
109
 
static int no(void)
110
 
{
111
 
    use_digitizer = 0;
112
 
    return 1;
113
 
}
114
 
 
115
 
static int yes(void)
116
 
{
117
 
    use_digitizer = 1;
118
 
    return 1;
119
 
}