2013-12-19 17:10:14 +00:00
|
|
|
/*
|
|
|
|
Command line parsing
|
|
|
|
*/
|
|
|
|
|
2019-09-07 12:37:39 +00:00
|
|
|
#include <cstdio>
|
|
|
|
#include <cctype>
|
|
|
|
#include <cstring>
|
2018-08-21 03:31:37 +00:00
|
|
|
|
2013-12-19 17:10:14 +00:00
|
|
|
#include "cfg/cfg.h"
|
2021-10-10 15:24:17 +00:00
|
|
|
#include "stdclass.h"
|
2013-12-19 17:10:14 +00:00
|
|
|
|
2021-10-10 15:24:17 +00:00
|
|
|
static int setconfig(char *arg[], int cl)
|
2013-12-19 17:10:14 +00:00
|
|
|
{
|
|
|
|
int rv=0;
|
2022-12-15 17:25:41 +00:00
|
|
|
|
|
|
|
if (cl < 1)
|
2013-12-19 17:10:14 +00:00
|
|
|
{
|
2022-12-15 17:25:41 +00:00
|
|
|
WARN_LOG(COMMON, "-config : invalid number of parameters, format is section:key=value,section:key=value,...");
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string value(arg[1]);
|
|
|
|
for(;;)
|
|
|
|
{
|
2021-10-10 15:24:17 +00:00
|
|
|
auto seppos = value.find(':');
|
|
|
|
if (seppos == std::string::npos)
|
2013-12-19 17:10:14 +00:00
|
|
|
{
|
2022-12-15 17:25:41 +00:00
|
|
|
WARN_LOG(COMMON, "-config : invalid parameter %s, format is section:key=value,section:key=value,...", value.c_str());
|
2021-10-10 15:24:17 +00:00
|
|
|
break;
|
2013-12-19 17:10:14 +00:00
|
|
|
}
|
2021-10-10 15:24:17 +00:00
|
|
|
auto eqpos = value.find('=', seppos);
|
|
|
|
if (eqpos == std::string::npos)
|
2013-12-19 17:10:14 +00:00
|
|
|
{
|
2022-12-15 17:25:41 +00:00
|
|
|
WARN_LOG(COMMON, "-config : invalid parameter %s, format is section:key=value,section:key=value,...", value.c_str());
|
2021-10-10 15:24:17 +00:00
|
|
|
break;
|
2013-12-19 17:10:14 +00:00
|
|
|
}
|
|
|
|
|
2022-12-15 17:25:41 +00:00
|
|
|
auto commapos = value.find(',', eqpos);
|
|
|
|
|
2021-10-10 15:24:17 +00:00
|
|
|
std::string sect = trim_ws(value.substr(0, seppos));
|
|
|
|
std::string key = trim_ws(value.substr(seppos + 1, eqpos - seppos - 1));
|
2022-12-15 17:25:41 +00:00
|
|
|
auto endofcurrent = (commapos == std::string::npos) ? value.size() : commapos;
|
|
|
|
std::string next = (commapos == std::string::npos) ? "" : trim_ws(value.substr(endofcurrent + 1, value.size() - endofcurrent));
|
|
|
|
value = trim_ws(value.substr(eqpos + 1, endofcurrent - eqpos - 1));
|
2013-12-19 17:10:14 +00:00
|
|
|
|
2021-10-10 15:24:17 +00:00
|
|
|
if (sect.empty() || key.empty())
|
2013-12-19 17:10:14 +00:00
|
|
|
{
|
2022-12-15 17:25:41 +00:00
|
|
|
WARN_LOG(COMMON, "-config : invalid parameter, format is section:key=value,section:key=value,...");
|
2021-10-10 15:24:17 +00:00
|
|
|
break;
|
2013-12-19 17:10:14 +00:00
|
|
|
}
|
|
|
|
|
2021-10-10 15:24:17 +00:00
|
|
|
INFO_LOG(COMMON, "Virtual cfg %s:%s=%s", sect.c_str(), key.c_str(), value.c_str());
|
2013-12-19 17:10:14 +00:00
|
|
|
|
2021-10-10 15:24:17 +00:00
|
|
|
cfgSetVirtual(sect, key, value);
|
2013-12-19 17:10:14 +00:00
|
|
|
|
2022-12-15 17:25:41 +00:00
|
|
|
if (commapos == std::string::npos)
|
|
|
|
rv++;
|
|
|
|
|
|
|
|
if (commapos != std::string::npos)
|
|
|
|
{
|
|
|
|
value = next;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else if (cl>=3 && strcmp(arg[2],",")==0)
|
2013-12-19 17:10:14 +00:00
|
|
|
{
|
|
|
|
cl-=2;
|
|
|
|
arg+=2;
|
|
|
|
rv++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2020-03-27 14:25:47 +00:00
|
|
|
static int showhelp()
|
2013-12-19 17:10:14 +00:00
|
|
|
{
|
2020-03-27 14:25:47 +00:00
|
|
|
printf("Usage: flycast [OPTION]... [CONTENT]\n\n");
|
|
|
|
printf("Options:\n");
|
|
|
|
printf("-config section:key=value add a virtual config value;\n");
|
|
|
|
printf(" virtual config values won't be saved to the .cfg file\n");
|
|
|
|
printf(" unless a different value is written to them\n");
|
|
|
|
printf("-help display this help\n");
|
|
|
|
|
|
|
|
exit(0);
|
2018-08-21 03:31:37 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2013-12-19 17:10:14 +00:00
|
|
|
|
2020-01-31 22:51:12 +00:00
|
|
|
bool ParseCommandLine(int argc,char* argv[])
|
2018-08-21 03:31:37 +00:00
|
|
|
{
|
2021-09-30 12:24:17 +00:00
|
|
|
settings.content.path.clear();
|
2013-12-19 17:10:14 +00:00
|
|
|
int cl=argc-2;
|
2020-01-31 22:51:12 +00:00
|
|
|
char** arg=argv+1;
|
2013-12-19 17:10:14 +00:00
|
|
|
while(cl>=0)
|
|
|
|
{
|
2018-08-21 03:31:37 +00:00
|
|
|
if (stricmp(*arg,"-help")==0 || stricmp(*arg,"--help")==0)
|
2013-12-19 17:10:14 +00:00
|
|
|
{
|
2020-03-27 14:25:47 +00:00
|
|
|
showhelp();
|
2018-08-21 03:31:37 +00:00
|
|
|
}
|
|
|
|
else if (stricmp(*arg,"-config")==0 || stricmp(*arg,"--config")==0)
|
2013-12-19 17:10:14 +00:00
|
|
|
{
|
|
|
|
int as=setconfig(arg,cl);
|
|
|
|
cl-=as;
|
|
|
|
arg+=as;
|
|
|
|
}
|
2020-04-26 08:03:57 +00:00
|
|
|
#if defined(__APPLE__)
|
2020-04-23 09:46:34 +00:00
|
|
|
else if (!strncmp(*arg, "-NSDocumentRevisions", 20))
|
|
|
|
{
|
|
|
|
arg++;
|
|
|
|
cl--;
|
|
|
|
}
|
|
|
|
#endif
|
2021-11-19 22:18:45 +00:00
|
|
|
else if ((*arg)[0] == '-')
|
|
|
|
{
|
|
|
|
WARN_LOG(COMMON, "Ignoring unknown command line option '%s'", *arg);
|
|
|
|
}
|
2013-12-19 17:10:14 +00:00
|
|
|
else
|
|
|
|
{
|
2015-08-17 22:28:01 +00:00
|
|
|
char* extension = strrchr(*arg, '.');
|
|
|
|
|
|
|
|
if (extension
|
|
|
|
&& (stricmp(extension, ".cdi") == 0 || stricmp(extension, ".chd") == 0
|
2019-07-09 21:52:19 +00:00
|
|
|
|| stricmp(extension, ".gdi") == 0 || stricmp(extension, ".cue") == 0))
|
2015-08-17 22:28:01 +00:00
|
|
|
{
|
2019-07-01 16:23:10 +00:00
|
|
|
INFO_LOG(COMMON, "Using '%s' as cd image", *arg);
|
2021-09-30 12:24:17 +00:00
|
|
|
settings.content.path = *arg;
|
2015-08-17 22:28:01 +00:00
|
|
|
}
|
|
|
|
else if (extension && stricmp(extension, ".elf") == 0)
|
|
|
|
{
|
2019-07-01 16:23:10 +00:00
|
|
|
INFO_LOG(COMMON, "Using '%s' as reios elf file", *arg);
|
2019-07-30 17:04:51 +00:00
|
|
|
cfgSetVirtual("config", "bios.UseReios", "yes");
|
2021-09-30 12:24:17 +00:00
|
|
|
settings.content.path = *arg;
|
2015-08-17 22:28:01 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-07-01 16:23:10 +00:00
|
|
|
INFO_LOG(COMMON, "Using '%s' as rom", *arg);
|
2021-09-30 12:24:17 +00:00
|
|
|
settings.content.path = *arg;
|
2015-08-17 22:28:01 +00:00
|
|
|
}
|
2013-12-19 17:10:14 +00:00
|
|
|
}
|
|
|
|
arg++;
|
|
|
|
cl--;
|
|
|
|
}
|
|
|
|
return false;
|
2015-07-17 21:56:51 +00:00
|
|
|
}
|