10 |
/* Read a line from stdin. If the first non-whitespace char is 'y' or 'Y', |
/* Read a line from stdin. If the first non-whitespace char is 'y' or 'Y', |
11 |
* return 1. Otherwise return 0. |
* return 1. Otherwise return 0. |
12 |
*/ |
*/ |
|
|
|
13 |
#include "libbb.h" |
#include "libbb.h" |
14 |
|
|
15 |
int FAST_FUNC bb_ask_confirmation(void) |
int FAST_FUNC bb_ask_confirmation(void) |
16 |
{ |
{ |
17 |
int retval = 0; |
char first = 0; |
|
int first = 1; |
|
18 |
int c; |
int c; |
19 |
|
|
20 |
while (((c = getchar()) != EOF) && (c != '\n')) { |
while (((c = getchar()) != EOF) && (c != '\n')) { |
21 |
/* Make sure we get the actual function call for isspace, |
if (first == 0 && !isblank(c)) { |
22 |
* as speed is not critical here. */ |
first = c|0x20; |
|
if (first && !(isspace)(c)) { |
|
|
--first; |
|
|
if ((c == 'y') || (c == 'Y')) { |
|
|
++retval; |
|
|
} |
|
23 |
} |
} |
24 |
} |
} |
25 |
|
|
26 |
return retval; |
return first == 'y'; |
27 |
} |
} |