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

« back to all changes in this revision

Viewing changes to lib/gis/yes.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
 
 * \file yes.c
4
 
 *
5
 
 * \brief GIS Library - Yes/No functions.
6
 
 *
7
 
 * (C) 2001-2008 by the GRASS Development Team
8
 
 *
9
 
 * This program is free software under the GNU General Public License
10
 
 * (>=v2). Read the file COPYING that comes with GRASS for details.
11
 
 *
12
 
 * \author GRASS GIS Development Team
13
 
 *
14
 
 * \date 1999-2008
15
 
 */
16
 
 
17
 
#include <stdio.h>
18
 
#include <grass/gis.h>
19
 
 
20
 
 
21
 
/**
22
 
 * \brief Ask a yes/no question.
23
 
 *
24
 
 * This routine prints a <b>question</b> to the user, and expects the user to
25
 
 * respond either yes or no. (Invalid responses are rejected and the process is
26
 
 * repeated until the user answers yes or no.)<br>
27
 
 * The <b>default</b> indicates what the RETURN key alone should mean. A
28
 
 * <b>default</b> of 1 indicates that RETURN means yes, 0 indicates that RETURN
29
 
 * means no. The <b>question</b> will be appended with ''(y/n) '', and, 
30
 
 * if <b>default</b> is not -1, with ''[y] '' or ''[n] '', depending on 
31
 
 * the <b>default.</b><br>
32
 
 *
33
 
 * \param[in] question
34
 
 * \param[in] dflt
35
 
 * \return 0 for No
36
 
 * \return 1 for Yes
37
 
 */
38
 
 
39
 
int G_yes(const char *question, int dflt)
40
 
{
41
 
    fflush(stdout);
42
 
 
43
 
    while (1) {
44
 
        char answer[100];
45
 
 
46
 
        fprintf(stderr, "%s", question);
47
 
 
48
 
        while (1) {
49
 
            fprintf(stderr, "(y/n) ");
50
 
            if (dflt >= 0)
51
 
                fprintf(stderr, dflt == 0 ? "[n] " : "[y] ");
52
 
 
53
 
            fflush(stderr);
54
 
            if (!G_gets(answer))
55
 
                break;
56
 
            G_strip(answer);
57
 
 
58
 
            switch (*answer) {
59
 
            case 'y':
60
 
            case 'Y':
61
 
                return (1);
62
 
            case 'n':
63
 
            case 'N':
64
 
                return (0);
65
 
            case 0:
66
 
                if (dflt >= 0)
67
 
                    return (dflt);
68
 
            }
69
 
        }
70
 
    }
71
 
}