don't return 1 on -help and -version

fixes #385
This commit is contained in:
tildearrow 2022-04-25 15:54:31 -05:00
parent f3f92b8035
commit 5821135b38
2 changed files with 46 additions and 31 deletions

View File

@ -60,7 +60,7 @@ bool displayEngineFailError=false;
std::vector<TAParam> params; std::vector<TAParam> params;
bool pHelp(String) { TAParamResult pHelp(String) {
printf("usage: furnace [params] [filename]\n" printf("usage: furnace [params] [filename]\n"
"you may specify the following parameters:\n"); "you may specify the following parameters:\n");
for (auto& i: params) { for (auto& i: params) {
@ -70,13 +70,13 @@ bool pHelp(String) {
printf(" -%s: %s\n",i.name.c_str(),i.desc.c_str()); printf(" -%s: %s\n",i.name.c_str(),i.desc.c_str());
} }
} }
return false; return TA_PARAM_QUIT;
} }
bool pAudio(String val) { TAParamResult pAudio(String val) {
if (outName!="") { if (outName!="") {
logE("can't use -audio and -output at the same time."); logE("can't use -audio and -output at the same time.");
return false; return TA_PARAM_ERROR;
} }
if (val=="jack") { if (val=="jack") {
e.setAudio(DIV_AUDIO_JACK); e.setAudio(DIV_AUDIO_JACK);
@ -84,12 +84,12 @@ bool pAudio(String val) {
e.setAudio(DIV_AUDIO_SDL); e.setAudio(DIV_AUDIO_SDL);
} else { } else {
logE("invalid value for audio engine! valid values are: jack, sdl."); logE("invalid value for audio engine! valid values are: jack, sdl.");
return false; return TA_PARAM_ERROR;
} }
return true; return TA_PARAM_SUCCESS;
} }
bool pView(String val) { TAParamResult pView(String val) {
if (val=="pattern") { if (val=="pattern") {
e.setView(DIV_STATUS_PATTERN); e.setView(DIV_STATUS_PATTERN);
} else if (val=="commands") { } else if (val=="commands") {
@ -98,17 +98,17 @@ bool pView(String val) {
e.setView(DIV_STATUS_NOTHING); e.setView(DIV_STATUS_NOTHING);
} else { } else {
logE("invalid value for view type! valid values are: pattern, commands, nothing."); logE("invalid value for view type! valid values are: pattern, commands, nothing.");
return false; return TA_PARAM_ERROR;
} }
return true; return TA_PARAM_SUCCESS;
} }
bool pConsole(String val) { TAParamResult pConsole(String val) {
consoleMode=true; consoleMode=true;
return true; return TA_PARAM_SUCCESS;
} }
bool pLogLevel(String val) { TAParamResult pLogLevel(String val) {
if (val=="trace") { if (val=="trace") {
logLevel=LOGLEVEL_TRACE; logLevel=LOGLEVEL_TRACE;
} else if (val=="debug") { } else if (val=="debug") {
@ -121,12 +121,12 @@ bool pLogLevel(String val) {
logLevel=LOGLEVEL_ERROR; logLevel=LOGLEVEL_ERROR;
} else { } else {
logE("invalid value for loglevel! valid values are: trace, debug, info, warning, error."); logE("invalid value for loglevel! valid values are: trace, debug, info, warning, error.");
return false; return TA_PARAM_ERROR;
} }
return true; return TA_PARAM_SUCCESS;
} }
bool pVersion(String) { TAParamResult pVersion(String) {
printf("Furnace version " DIV_VERSION ".\n\n"); printf("Furnace version " DIV_VERSION ".\n\n");
printf("copyright (C) 2021-2022 tildearrow and contributors.\n"); printf("copyright (C) 2021-2022 tildearrow and contributors.\n");
printf("licensed under the GNU General Public License version 2 or later\n"); printf("licensed under the GNU General Public License version 2 or later\n");
@ -152,10 +152,10 @@ bool pVersion(String) {
printf("- puNES by FHorse (GPLv2)\n"); printf("- puNES by FHorse (GPLv2)\n");
printf("- reSID by Dag Lem (GPLv2)\n"); printf("- reSID by Dag Lem (GPLv2)\n");
printf("- Stella by Stella Team (GPLv2)\n"); printf("- Stella by Stella Team (GPLv2)\n");
return false; return TA_PARAM_QUIT;
} }
bool pWarranty(String) { TAParamResult pWarranty(String) {
printf("This program is free software; you can redistribute it and/or\n" printf("This program is free software; you can redistribute it and/or\n"
"modify it under the terms of the GNU General Public License\n" "modify it under the terms of the GNU General Public License\n"
"as published by the Free Software Foundation; either version 2\n" "as published by the Free Software Foundation; either version 2\n"
@ -169,10 +169,10 @@ bool pWarranty(String) {
"You should have received a copy of the GNU General Public License\n" "You should have received a copy of the GNU General Public License\n"
"along with this program; if not, write to the Free Software\n" "along with this program; if not, write to the Free Software\n"
"Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.\n"); "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.\n");
return false; return TA_PARAM_QUIT;
} }
bool pLoops(String val) { TAParamResult pLoops(String val) {
try { try {
int count=std::stoi(val); int count=std::stoi(val);
if (count<0) { if (count<0) {
@ -182,12 +182,12 @@ bool pLoops(String val) {
} }
} catch (std::exception& e) { } catch (std::exception& e) {
logE("loop count shall be a number."); logE("loop count shall be a number.");
return false; return TA_PARAM_ERROR;
} }
return true; return TA_PARAM_SUCCESS;
} }
bool pOutMode(String val) { TAParamResult pOutMode(String val) {
if (val=="one") { if (val=="one") {
outMode=DIV_EXPORT_MODE_ONE; outMode=DIV_EXPORT_MODE_ONE;
} else if (val=="persys") { } else if (val=="persys") {
@ -196,21 +196,21 @@ bool pOutMode(String val) {
outMode=DIV_EXPORT_MODE_MANY_CHAN; outMode=DIV_EXPORT_MODE_MANY_CHAN;
} else { } else {
logE("invalid value for outmode! valid values are: one, persys and perchan."); logE("invalid value for outmode! valid values are: one, persys and perchan.");
return false; return TA_PARAM_ERROR;
} }
return true; return TA_PARAM_SUCCESS;
} }
bool pOutput(String val) { TAParamResult pOutput(String val) {
outName=val; outName=val;
e.setAudio(DIV_AUDIO_DUMMY); e.setAudio(DIV_AUDIO_DUMMY);
return true; return TA_PARAM_SUCCESS;
} }
bool pVGMOut(String val) { TAParamResult pVGMOut(String val) {
vgmOutName=val; vgmOutName=val;
e.setAudio(DIV_AUDIO_DUMMY); e.setAudio(DIV_AUDIO_DUMMY);
return true; return TA_PARAM_SUCCESS;
} }
bool needsValue(String param) { bool needsValue(String param) {
@ -283,7 +283,16 @@ int main(int argc, char** argv) {
} }
for (size_t j=0; j<params.size(); j++) { for (size_t j=0; j<params.size(); j++) {
if (params[j].name==arg || params[j].shortName==arg) { if (params[j].name==arg || params[j].shortName==arg) {
if (!params[j].func(val)) return 1; switch (params[j].func(val)) {
case TA_PARAM_ERROR:
return 1;
break;
case TA_PARAM_SUCCESS:
break;
case TA_PARAM_QUIT:
return 0;
break;
}
break; break;
} }
} }

View File

@ -43,14 +43,20 @@ typedef std::string String;
typedef std::wstring WString; typedef std::wstring WString;
enum TAParamResult {
TA_PARAM_ERROR=0,
TA_PARAM_SUCCESS,
TA_PARAM_QUIT
};
struct TAParam { struct TAParam {
String shortName; String shortName;
String name; String name;
String valName; String valName;
String desc; String desc;
bool value; bool value;
bool (*func)(String); TAParamResult (*func)(String);
TAParam(const String& sn, const String& n, bool v, bool (*f)(String), const String& vn, const String& d): TAParam(const String& sn, const String& n, bool v, TAParamResult (*f)(String), const String& vn, const String& d):
shortName(sn), shortName(sn),
name(n), name(n),
valName(vn), valName(vn),