Mercurial > hg > octave-kai > gnulib-hg
annotate lib/yesno.c @ 7114:5b8becde9879
.
author | Karl Berry <karl@freefriends.org> |
---|---|
date | Fri, 11 Aug 2006 08:19:37 +0000 |
parents | 96c32553b4c6 |
children | 8a1a9361108c |
rev | line source |
---|---|
5 | 1 /* yesno.c -- read a yes/no response from stdin |
5851 | 2 |
3 Copyright (C) 1990, 1998, 2001, 2003, 2004, 2005 Free Software | |
4 Foundation, Inc. | |
5 | 5 |
6 This program is free software; you can redistribute it and/or modify | |
7 it under the terms of the GNU General Public License as published by | |
8 the Free Software Foundation; either version 2, or (at your option) | |
9 any later version. | |
10 | |
11 This program is distributed in the hope that it will be useful, | |
12 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 GNU General Public License for more details. | |
15 | |
16 You should have received a copy of the GNU General Public License | |
650
b4ef1c1a0171
update FSF address in copyright
Jim Meyering <jim@meyering.net>
parents:
5
diff
changeset
|
17 along with this program; if not, write to the Free Software Foundation, |
5848
a48fb0e98c8c
*** empty log message ***
Paul Eggert <eggert@cs.ucla.edu>
parents:
5318
diff
changeset
|
18 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ |
650
b4ef1c1a0171
update FSF address in copyright
Jim Meyering <jim@meyering.net>
parents:
5
diff
changeset
|
19 |
6259
96c32553b4c6
Use a consistent style for including <config.h>.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5851
diff
changeset
|
20 #ifdef HAVE_CONFIG_H |
1278
9ad625a30b7d
Use #if, not #ifdef with HAVE_ macros
Jim Meyering <jim@meyering.net>
parents:
666
diff
changeset
|
21 # include <config.h> |
650
b4ef1c1a0171
update FSF address in copyright
Jim Meyering <jim@meyering.net>
parents:
5
diff
changeset
|
22 #endif |
5 | 23 |
5149 | 24 #include "yesno.h" |
25 | |
4684 | 26 #include <stdlib.h> |
5 | 27 #include <stdio.h> |
5318
7c24a825b51d
Remove dependencies on unlocked-io.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5149
diff
changeset
|
28 |
5851 | 29 #include "getline.h" |
5 | 30 |
5851 | 31 /* Return true if we read an affirmative line from standard input. */ |
5 | 32 |
4684 | 33 extern int rpmatch (char const *response); |
666
969996bb277b
(yesno) [!HAVE_RPMATCH]: Remove function since we'll
Jim Meyering <jim@meyering.net>
parents:
661
diff
changeset
|
34 |
5149 | 35 bool |
4686
70bf7ce55a75
(main): Define with a prototype.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4684
diff
changeset
|
36 yesno (void) |
661
b76c0d01af51
(yesno) [HAVE_RPMATCH]: New rpmatch-based version of the function.
Jim Meyering <jim@meyering.net>
parents:
650
diff
changeset
|
37 { |
5851 | 38 char *response = NULL; |
39 size_t response_size = 0; | |
40 ssize_t response_len = getline (&response, &response_size, stdin); | |
41 bool yes; | |
661
b76c0d01af51
(yesno) [HAVE_RPMATCH]: New rpmatch-based version of the function.
Jim Meyering <jim@meyering.net>
parents:
650
diff
changeset
|
42 |
5851 | 43 if (response_len <= 0) |
44 yes = false; | |
45 else | |
46 { | |
47 response[response_len - 1] = '\0'; | |
48 yes = (0 < rpmatch (response)); | |
49 } | |
661
b76c0d01af51
(yesno) [HAVE_RPMATCH]: New rpmatch-based version of the function.
Jim Meyering <jim@meyering.net>
parents:
650
diff
changeset
|
50 |
5851 | 51 free (response); |
52 return yes; | |
661
b76c0d01af51
(yesno) [HAVE_RPMATCH]: New rpmatch-based version of the function.
Jim Meyering <jim@meyering.net>
parents:
650
diff
changeset
|
53 } |