GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
yes.c
Go to the documentation of this file.
1 
17 #include <stdio.h>
18 #include <grass/gis.h>
19 
20 
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 }
int G_gets(char *buf)
Definition: gets.c:39
int G_yes(const char *question, int dflt)
Ask a yes/no question.
Definition: yes.c:39
int G_strip(char *buf)
Removes all leading and trailing white space from string.
Definition: strings.c:389