From d230e0759c299db8968d85ad2642e20b5a83d67d Mon Sep 17 00:00:00 2001 From: Patryk Obara Date: Mon, 27 Apr 2020 18:48:02 +0200 Subject: [PATCH] Cleanup PrintConfigLocation function Do not exit inside function, return error code instead. Print error to stderr, and not stdout, to make life easier for users invoking dosbox from within scripts. Include double-dash GNU-style parameter: '--printconf'. --- src/gui/sdlmain.cpp | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/gui/sdlmain.cpp b/src/gui/sdlmain.cpp index 6e66209d..793a77bd 100644 --- a/src/gui/sdlmain.cpp +++ b/src/gui/sdlmain.cpp @@ -3012,20 +3012,22 @@ static void launchcaptures(std::string const& edit) { exit(1); } -static void printconfiglocation() { - std::string path,file; +static int PrintConfigLocation() +{ + std::string path, file; Cross::CreatePlatformConfigDir(path); Cross::GetPlatformConfigName(file); path += file; - FILE* f = fopen(path.c_str(),"r"); + FILE *f = fopen(path.c_str(), "r"); if (!f && !control->PrintConfig(path)) { - printf("tried creating %s. but failed", path.c_str()); - exit(1); + fprintf(stderr, "Tried creating '%s', but failed.\n", path.c_str()); + return 1; } - if(f) fclose(f); - printf("%s\n",path.c_str()); - exit(0); + if (f) + fclose(f); + printf("%s\n", path.c_str()); + return 0; } static void eraseconfigfile() { @@ -3135,8 +3137,11 @@ int main(int argc, char* argv[]) { return 0; } - if (control->cmdline->FindExist("-printconf")) - printconfiglocation(); + if (control->cmdline->FindExist("--printconf") || + control->cmdline->FindExist("-printconf")) { + const int err = PrintConfigLocation(); + return err; + } #if C_DEBUG DEBUG_SetupConsole();