| 1 |
#include "DiskImageCLI.hh" |
| 2 |
|
| 3 |
#include "CommandLineParser.hh" |
| 4 |
#include "Interpreter.hh" |
| 5 |
#include "MSXException.hh" |
| 6 |
#include "TclObject.hh" |
| 7 |
|
| 8 |
namespace openmsx { |
| 9 |
|
| 10 |
std::span<const std::string_view> DiskImageCLI::getExtensions() |
| 11 |
{ |
| 12 |
static constexpr std::array<std::string_view, 7> extensions = { |
| 13 |
"di1", "di2", "dmk", "dsk", "xsa", "fd1", "fd2" |
| 14 |
}; |
| 15 |
return extensions; |
| 16 |
} |
| 17 |
|
| 18 |
DiskImageCLI::DiskImageCLI(CommandLineParser& parser_) |
| 19 |
: parser(parser_) |
| 20 |
{ |
| 21 |
for (const auto* disk : {"-diska", "-diskb"}) { |
| 22 |
parser.registerOption(disk, *this); |
| 23 |
} |
| 24 |
parser.registerFileType(getExtensions(), *this); |
| 25 |
} |
| 26 |
|
| 27 |
void DiskImageCLI::parseOption(const std::string& option, std::span<std::string>& cmdLine) |
| 28 |
{ |
| 29 |
std::string filename = getArgument(option, cmdLine); |
| 30 |
parse(zstring_view(option).substr(1), filename, cmdLine); |
| 31 |
} |
| 32 |
std::string_view DiskImageCLI::optionHelp() const |
| 33 |
{ |
| 34 |
return "Insert the disk image specified in argument"; |
| 35 |
} |
| 36 |
|
| 37 |
void DiskImageCLI::parseFileType(const std::string& filename, std::span<std::string>& cmdLine) |
| 38 |
{ |
| 39 |
parse(tmpStrCat("disk", driveLetter), filename, cmdLine); |
| 40 |
++driveLetter; |
| 41 |
} |
| 42 |
|
| 43 |
std::string_view DiskImageCLI::fileTypeHelp() const |
| 44 |
{ |
| 45 |
return "Disk image"; |
| 46 |
} |
| 47 |
|
| 48 |
std::string_view DiskImageCLI::fileTypeCategoryName() const |
| 49 |
{ |
| 50 |
return "disk"; |
| 51 |
} |
| 52 |
|
| 53 |
void DiskImageCLI::parse(zstring_view drive, std::string_view image, |
| 54 |
std::span<std::string>& cmdLine) const |
| 55 |
{ |
| 56 |
if (!parser.getInterpreter().hasCommand(drive)) { |
| 57 |
throw MSXException("No disk drive ", char(::toupper(drive.back())), " present to put image '", image, "' in."); |
| 58 |
} |
| 59 |
TclObject command = makeTclList(drive, image); |
| 60 |
while (peekArgument(cmdLine) == "-ips") { |
| 61 |
cmdLine = cmdLine.subspan(1); |
| 62 |
command.addListElement(getArgument("-ips", cmdLine)); |
| 63 |
} |
| 64 |
command.executeCommand(parser.getInterpreter()); |
| 65 |
} |
| 66 |
|
| 67 |
} |