GRASS Programmer's Manual  6.4.2(2012)
yes.c
Go to the documentation of this file.
00001 
00017 #include <stdio.h>
00018 #include <grass/gis.h>
00019 
00020 
00039 int G_yes(const char *question, int dflt)
00040 {
00041     fflush(stdout);
00042 
00043     while (1) {
00044         char answer[100];
00045 
00046         fprintf(stderr, "%s", question);
00047 
00048         while (1) {
00049             fprintf(stderr, "(y/n) ");
00050             if (dflt >= 0)
00051                 fprintf(stderr, dflt == 0 ? "[n] " : "[y] ");
00052 
00053             fflush(stderr);
00054             if (!G_gets(answer))
00055                 break;
00056             G_strip(answer);
00057 
00058             switch (*answer) {
00059             case 'y':
00060             case 'Y':
00061                 return (1);
00062             case 'n':
00063             case 'N':
00064                 return (0);
00065             case 0:
00066                 if (dflt >= 0)
00067                     return (dflt);
00068             }
00069         }
00070     }
00071 }
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines