2 * Copyright 2011, Oliver Tappe <zooey@hirschkaefer.de>
3 * Distributed under the terms of the MIT License.
10 #include "DecisionProvider.h"
13 DecisionProvider::DecisionProvider(bool interactive
)
15 fInteractive(interactive
)
21 DecisionProvider::YesNoDecisionNeeded(const BString
& description
,
22 const BString
& question
, const BString
& yes
, const BString
& no
,
23 const BString
& defaultChoice
)
25 if (description
.Length() > 0)
26 printf("%s\n", description
.String());
28 bool haveDefault
= defaultChoice
.Length() > 0;
31 printf("%s [%s/%s]%s: ", question
.String(), yes
.String(), no
.String(),
33 ? (BString(" (") << defaultChoice
<< ") ").String() : "");
36 printf("%s\n", yes
.String());
41 if (fgets(buffer
, 32, stdin
)) {
42 if (haveDefault
&& (buffer
[0] == '\n' || buffer
[0] == '\0'))
43 return defaultChoice
== yes
;
44 int length
= strlen(buffer
);
45 for (int i
= 1; i
<= length
; ++i
) {
46 if (yes
.ICompare(buffer
, i
) == 0) {
47 if (no
.ICompare(buffer
, i
) != 0)
49 } else if (no
.Compare(buffer
, i
) == 0) {
50 if (yes
.ICompare(buffer
, i
) != 0)
55 fprintf(stderr
, "*** please enter '%s' or '%s'\n", yes
.String(),