186d7f5d3SJohn Marino /* yesno.c -- read a yes/no response from stdin
286d7f5d3SJohn Marino
386d7f5d3SJohn Marino Copyright (C) 1990, 1998, 2001, 2003, 2004, 2005 Free Software
486d7f5d3SJohn Marino Foundation, Inc.
586d7f5d3SJohn Marino
686d7f5d3SJohn Marino This program is free software; you can redistribute it and/or modify
786d7f5d3SJohn Marino it under the terms of the GNU General Public License as published by
886d7f5d3SJohn Marino the Free Software Foundation; either version 2, or (at your option)
986d7f5d3SJohn Marino any later version.
1086d7f5d3SJohn Marino
1186d7f5d3SJohn Marino This program is distributed in the hope that it will be useful,
1286d7f5d3SJohn Marino but WITHOUT ANY WARRANTY; without even the implied warranty of
1386d7f5d3SJohn Marino MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1486d7f5d3SJohn Marino GNU General Public License for more details.
1586d7f5d3SJohn Marino
1686d7f5d3SJohn Marino You should have received a copy of the GNU General Public License
1786d7f5d3SJohn Marino along with this program; if not, write to the Free Software Foundation,
1886d7f5d3SJohn Marino Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
1986d7f5d3SJohn Marino
2086d7f5d3SJohn Marino #ifdef HAVE_CONFIG_H
2186d7f5d3SJohn Marino # include <config.h>
2286d7f5d3SJohn Marino #endif
2386d7f5d3SJohn Marino
2486d7f5d3SJohn Marino #include "yesno.h"
2586d7f5d3SJohn Marino
2686d7f5d3SJohn Marino #include <stdlib.h>
2786d7f5d3SJohn Marino #include <stdio.h>
2886d7f5d3SJohn Marino
2986d7f5d3SJohn Marino #include "getline.h"
3086d7f5d3SJohn Marino
3186d7f5d3SJohn Marino /* Return true if we read an affirmative line from standard input. */
3286d7f5d3SJohn Marino
3386d7f5d3SJohn Marino extern int rpmatch (char const *response);
3486d7f5d3SJohn Marino
3586d7f5d3SJohn Marino bool
yesno(void)3686d7f5d3SJohn Marino yesno (void)
3786d7f5d3SJohn Marino {
3886d7f5d3SJohn Marino char *response = NULL;
3986d7f5d3SJohn Marino size_t response_size = 0;
4086d7f5d3SJohn Marino ssize_t response_len = getline (&response, &response_size, stdin);
4186d7f5d3SJohn Marino bool yes;
4286d7f5d3SJohn Marino
4386d7f5d3SJohn Marino if (response_len <= 0)
4486d7f5d3SJohn Marino yes = false;
4586d7f5d3SJohn Marino else
4686d7f5d3SJohn Marino {
4786d7f5d3SJohn Marino response[response_len - 1] = '\0';
4886d7f5d3SJohn Marino yes = (0 < rpmatch (response));
4986d7f5d3SJohn Marino }
5086d7f5d3SJohn Marino
5186d7f5d3SJohn Marino free (response);
5286d7f5d3SJohn Marino return yes;
5386d7f5d3SJohn Marino }
54