|
Revision 5596, 1.3 KB
(checked in by khali, 4 years ago)
|
|
Complete GPL header.
|
| Line | |
|---|
| 1 | /* |
|---|
| 2 | util.c - helper functions |
|---|
| 3 | Copyright (C) 2006 Jean Delvare <khali@linux-fr.org> |
|---|
| 4 | |
|---|
| 5 | This program is free software; you can redistribute it and/or modify |
|---|
| 6 | it under the terms of the GNU General Public License as published by |
|---|
| 7 | the Free Software Foundation; either version 2 of the License, or |
|---|
| 8 | (at your option) any later version. |
|---|
| 9 | |
|---|
| 10 | This program is distributed in the hope that it will be useful, |
|---|
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 13 | GNU General Public License for more details. |
|---|
| 14 | |
|---|
| 15 | You should have received a copy of the GNU General Public License |
|---|
| 16 | along with this program; if not, write to the Free Software |
|---|
| 17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|---|
| 18 | MA 02110-1301 USA. |
|---|
| 19 | */ |
|---|
| 20 | |
|---|
| 21 | #include <stdio.h> |
|---|
| 22 | #include "util.h" |
|---|
| 23 | |
|---|
| 24 | /* Return 1 if we should continue, 0 if we should abort */ |
|---|
| 25 | int user_ack(int def) |
|---|
| 26 | { |
|---|
| 27 | char s[2]; |
|---|
| 28 | int ret; |
|---|
| 29 | |
|---|
| 30 | if (!fgets(s, 2, stdin)) |
|---|
| 31 | return 0; /* Nack by default */ |
|---|
| 32 | |
|---|
| 33 | switch (s[0]) { |
|---|
| 34 | case 'y': |
|---|
| 35 | case 'Y': |
|---|
| 36 | ret = 1; |
|---|
| 37 | break; |
|---|
| 38 | case 'n': |
|---|
| 39 | case 'N': |
|---|
| 40 | ret = 0; |
|---|
| 41 | break; |
|---|
| 42 | default: |
|---|
| 43 | ret = def; |
|---|
| 44 | } |
|---|
| 45 | |
|---|
| 46 | /* Flush extra characters */ |
|---|
| 47 | while (s[0] != '\n') { |
|---|
| 48 | int c = fgetc(stdin); |
|---|
| 49 | if (c == EOF) { |
|---|
| 50 | ret = 0; |
|---|
| 51 | break; |
|---|
| 52 | } |
|---|
| 53 | s[0] = c; |
|---|
| 54 | } |
|---|
| 55 | |
|---|
| 56 | return ret; |
|---|
| 57 | } |
|---|
| 58 | |
|---|