|
Revision 4669, 0.8 KB
(checked in by khali, 6 years ago)
|
|
License fix.
|
| 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 | |
|---|
| 11 | #include <stdio.h> |
|---|
| 12 | #include "util.h" |
|---|
| 13 | |
|---|
| 14 | /* Return 1 if we should continue, 0 if we should abort */ |
|---|
| 15 | int user_ack(int def) |
|---|
| 16 | { |
|---|
| 17 | char s[2]; |
|---|
| 18 | int ret; |
|---|
| 19 | |
|---|
| 20 | if (!fgets(s, 2, stdin)) |
|---|
| 21 | return 0; /* Nack by default */ |
|---|
| 22 | |
|---|
| 23 | switch (s[0]) { |
|---|
| 24 | case 'y': |
|---|
| 25 | case 'Y': |
|---|
| 26 | ret = 1; |
|---|
| 27 | break; |
|---|
| 28 | case 'n': |
|---|
| 29 | case 'N': |
|---|
| 30 | ret = 0; |
|---|
| 31 | break; |
|---|
| 32 | default: |
|---|
| 33 | ret = def; |
|---|
| 34 | } |
|---|
| 35 | |
|---|
| 36 | /* Flush extra characters */ |
|---|
| 37 | while (s[0] != '\n') { |
|---|
| 38 | int c = fgetc(stdin); |
|---|
| 39 | if (c == EOF) { |
|---|
| 40 | ret = 0; |
|---|
| 41 | break; |
|---|
| 42 | } |
|---|
| 43 | s[0] = c; |
|---|
| 44 | } |
|---|
| 45 | |
|---|
| 46 | return ret; |
|---|
| 47 | } |
|---|
| 48 | |
|---|