Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
| 2 | /* |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 3 | * bb_ask_confirmation implementation for busybox |
Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 4 | * |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 5 | * Copyright (C) 2003 Manuel Novoa III <mjn3@codepoet.org> |
Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 6 | * |
"Robert P. J. Day" | 5d8843e | 2006-07-10 11:41:19 +0000 | [diff] [blame^] | 7 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | /* Read a line from stdin. If the first non-whitespace char is 'y' or 'Y', |
| 11 | * return 1. Otherwise return 0. |
Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 12 | */ |
| 13 | |
| 14 | #include <stdio.h> |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 15 | #include <ctype.h> |
Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 16 | #include "libbb.h" |
| 17 | |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 18 | int bb_ask_confirmation(void) |
Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 19 | { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 20 | int retval = 0; |
| 21 | int first = 1; |
| 22 | int c; |
Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 23 | |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 24 | while (((c = getchar()) != EOF) && (c != '\n')) { |
| 25 | /* Make sure we get the actual function call for isspace, |
| 26 | * as speed is not critical here. */ |
| 27 | if (first && !(isspace)(c)) { |
| 28 | --first; |
| 29 | if ((c == 'y') || (c == 'Y')) { |
| 30 | ++retval; |
| 31 | } |
Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 32 | } |
| 33 | } |
Eric Andersen | aad1a88 | 2001-03-16 22:47:14 +0000 | [diff] [blame] | 34 | |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 35 | return retval; |
| 36 | } |