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

« back to all changes in this revision

Viewing changes to display/d.menu/main.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
 
 
2
 
/****************************************************************
3
 
 *
4
 
 * MODULE:       d.menu
5
 
 *
6
 
 * AUTHOR(S):    James Westervelt, U.S. Army CERL
7
 
 *
8
 
 * PURPOSE:      Creates an interactive menu on the display monitor using
9
 
 *               lines from stdin as options. Returns selected entry.
10
 
 *               
11
 
 * COPYRIGHT:    (c) 1999, 2006 by the GRASS Development Team
12
 
 *
13
 
 *               This program is free software under the 
14
 
 *               GNU General Public License (>=v2). 
15
 
 *               Read the file COPYING that comes with GRASS
16
 
 *               for details.
17
 
 *
18
 
 ****************************************************************
19
 
 *
20
 
 *   Lines beginning with:
21
 
 *    #      are comments and ignored
22
 
 *    .B     contains the background color
23
 
 *    .C     contains the text color
24
 
 *    .D     contains the line divider color
25
 
 *    .F     contains the font name
26
 
 *    .S     contains the text size (in pixels)
27
 
 *    .T     contains the panel's top edge
28
 
 *    .L     contains the panel's left edge
29
 
 *
30
 
 *   Of the remaining lines, the first is the menu name; the rest
31
 
 *   are the menu options.
32
 
 *
33
 
 *   Returns option number chosen.
34
 
 *
35
 
 ****************************************************************/
36
 
 
37
 
#include <stdio.h>
38
 
#include <stdlib.h>
39
 
#include <string.h>
40
 
#include "grass/gis.h"
41
 
#include "grass/display.h"
42
 
#include "grass/raster.h"
43
 
#include "grass/glocale.h"
44
 
 
45
 
int main(int argc, char **argv)
46
 
{
47
 
    int backcolor;
48
 
    int textcolor;
49
 
    int dividercolor;
50
 
    int size;
51
 
    int left;
52
 
    int top;
53
 
    char buff[128];
54
 
    char *cmd_ptr;
55
 
    char *tmp;
56
 
    char *options[128];
57
 
    int i;
58
 
    int len;
59
 
    struct GModule *module;
60
 
    struct Option *opt1, *opt2, *opt3, *opt4;
61
 
 
62
 
    /* Initialize the GIS calls */
63
 
    G_gisinit(argv[0]);
64
 
 
65
 
    module = G_define_module();
66
 
    module->keywords = _("display, menu");
67
 
    module->description =
68
 
        _("Creates and displays a menu within the active "
69
 
          "frame on the graphics monitor.");
70
 
 
71
 
    opt1 = G_define_option();
72
 
    opt1->key = "bcolor";
73
 
    opt1->type = TYPE_STRING;
74
 
    opt1->answer = DEFAULT_BG_COLOR;
75
 
    opt1->required = NO;
76
 
    opt1->options = D_color_list();
77
 
    opt1->description = _("Sets the color of the menu background");
78
 
 
79
 
    opt2 = G_define_option();
80
 
    opt2->key = "tcolor";
81
 
    opt2->type = TYPE_STRING;
82
 
    opt2->answer = DEFAULT_FG_COLOR;
83
 
    opt2->required = NO;
84
 
    opt2->options = D_color_list();
85
 
    opt2->description = _("Sets the color of the menu text");
86
 
 
87
 
    opt3 = G_define_option();
88
 
    opt3->key = "dcolor";
89
 
    opt3->type = TYPE_STRING;
90
 
    opt3->answer = DEFAULT_FG_COLOR;
91
 
    opt3->required = NO;
92
 
    opt3->options = D_color_list();
93
 
    opt3->description = _("Sets the color dividing lines of text");
94
 
 
95
 
    opt4 = G_define_option();
96
 
    opt4->key = "size";
97
 
    opt4->type = TYPE_INTEGER;
98
 
    opt4->answer = "3";
99
 
    opt4->required = NO;
100
 
    opt4->options = "1-100";
101
 
    opt4->description = _("Sets the menu text size (in percent)");
102
 
 
103
 
    /* Check command line */
104
 
    if (G_parser(argc, argv))
105
 
        exit(EXIT_FAILURE);
106
 
 
107
 
    if (R_open_driver() != 0)
108
 
        G_fatal_error(_("No graphics device selected"));
109
 
 
110
 
    backcolor = D_translate_color(opt1->answer);
111
 
    if (backcolor == 0) {
112
 
        R_close_driver();
113
 
        G_fatal_error(_("Don't know the color %s"), opt1->answer);
114
 
    }
115
 
 
116
 
    textcolor = D_translate_color(opt2->answer);
117
 
    if (textcolor == 0) {
118
 
        R_close_driver();
119
 
        G_fatal_error(_("Don't know the color %s"), opt2->answer);
120
 
    }
121
 
 
122
 
    dividercolor = D_translate_color(opt3->answer);
123
 
    if (dividercolor == 0) {
124
 
        R_close_driver();
125
 
        G_fatal_error(_("Don't know the color %s"), opt3->answer);
126
 
    }
127
 
 
128
 
 
129
 
    sscanf(opt4->answer, "%d", &size);
130
 
 
131
 
    /* Read the options */
132
 
    i = 0;
133
 
    while (fgets(buff, 128, stdin) != NULL) {
134
 
        /* un-fgets it  */
135
 
        tmp = buff;
136
 
        while (*tmp) {
137
 
            if (*tmp == '\n')
138
 
                *tmp = '\0';
139
 
            tmp++;
140
 
        }
141
 
        if (*buff == '#')
142
 
            continue;
143
 
        if (*buff == '.') {
144
 
            for (cmd_ptr = buff + 2; *cmd_ptr == ' ' && *cmd_ptr != '\0';
145
 
                 cmd_ptr++) ;
146
 
            switch (buff[1] & 0x7F) {
147
 
 
148
 
            case 'B':           /* background color */
149
 
                backcolor = D_translate_color(cmd_ptr);
150
 
                break;
151
 
            case 'C':           /* text color */
152
 
                textcolor = D_translate_color(cmd_ptr);
153
 
                break;
154
 
            case 'D':           /* divider color */
155
 
                dividercolor = D_translate_color(cmd_ptr);
156
 
                break;
157
 
            case 'F':           /* font */
158
 
                R_font(cmd_ptr);
159
 
                break;
160
 
            case 'S':           /* size */
161
 
                sscanf(cmd_ptr, "%d", &size);
162
 
                break;
163
 
            case 'T':           /* top edge */
164
 
                sscanf(cmd_ptr, "%d", &top);
165
 
                top = 100 - top;
166
 
                break;
167
 
            case 'L':           /* left edge */
168
 
                sscanf(cmd_ptr, "%d", &left);
169
 
                break;
170
 
 
171
 
            default:
172
 
                break;
173
 
            }
174
 
        }
175
 
        else {
176
 
            len = strlen(buff);
177
 
            tmp = malloc(len + 1);
178
 
            strcpy(tmp, buff);
179
 
            options[i++] = tmp;
180
 
        }
181
 
    }
182
 
 
183
 
    options[i] = NULL;
184
 
    if (i < 2) {
185
 
        R_close_driver();
186
 
        G_fatal_error(_("Menu must contain a title and at least one option"));
187
 
    }
188
 
 
189
 
    i = D_popup(backcolor, textcolor, dividercolor,
190
 
                top,            /* The col of the top left corner */
191
 
                left,           /* The row of the top left corner */
192
 
                size,           /* The size of the characters in pixels */
193
 
                options);       /* The text */
194
 
 
195
 
    R_close_driver();
196
 
 
197
 
    /* Provide the result to standard output */
198
 
    fprintf(stdout, "%d\n", i);
199
 
 
200
 
    return 0;
201
 
}