Added default values for GetInput() and GetBoolInput()

git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@204 726aef4b-f618-498e-8847-2d620e286838
This commit is contained in:
prozacx
2005-04-29 00:27:45 +00:00
parent 79aaf3d527
commit c6eea2aec1
2 changed files with 24 additions and 9 deletions
+21 -7
View File
@@ -223,9 +223,19 @@ char* CUtils::GetPass(const string& sPrompt) {
return getpass("");
}
bool CUtils::GetBoolInput(const string& sPrompt) {
string sRet;
GetInput(sPrompt + " [yes/no]", sRet);
bool CUtils::GetBoolInput(const string& sPrompt, bool bDefault) {
return CUtils::GetBoolInput(sPrompt, &bDefault);
}
bool CUtils::GetBoolInput(const string& sPrompt, bool *pbDefault) {
string sRet, sDefault;
string sExtra = " (yes/no)";
if (pbDefault) {
sDefault = (*pbDefault) ? "yes" : "no";
}
GetInput(sPrompt + sExtra, sRet, sDefault);
if (strcasecmp(sRet.c_str(), "yes") == 0) {
return true;
@@ -233,21 +243,25 @@ bool CUtils::GetBoolInput(const string& sPrompt) {
return false;
}
return GetBoolInput(sPrompt);
return GetBoolInput(sPrompt, pbDefault);
}
bool CUtils::GetInput(const string& sPrompt, string& sRet) {
PrintPrompt(sPrompt);
bool CUtils::GetInput(const string& sPrompt, string& sRet, const string& sDefault) {
string sExtra = (!sDefault.empty()) ? (" [" + sDefault + "]") : "";
PrintPrompt(sPrompt + sExtra);
char szBuf[1024];
memset(szBuf, 0, 1024);
fgets(szBuf, 1024, stdin);
sRet = szBuf;
if (CUtils::Right(sRet, 1) == "\n") {
CUtils::RightChomp(sRet);
}
if (sRet.empty()) {
sRet = sDefault;
}
return !sRet.empty();
}