DIRECTOR: LINGO: normalize xlib in openXLib call

In Director, the openXLib call loads an XLib from a file.
Resource forks on Mac, dlls on windows.

The XLib has it's own name. It looks like the filename,
most of the time.

ScummVM doesn't read these files, but reimplements them in C.
ScummVM's openXLib is a wrapper which loads the XLib in question.
A conversion is needed to go from filename to XLib.

The conversion is follows these steps:
    - on mac: strip leading path, i.e. ':',
    - on windows: strip '.dll' extension,
    - lowercase and
    - trimmed

The name in the XLibProto struct isn't normalized since that's the
variable name as it's know and found by the code.
This commit is contained in:
Roland van Laar 2020-08-10 18:42:20 +02:00
parent 43650c1a8a
commit 0b777c23a9

View File

@ -118,16 +118,27 @@ void Lingo::initXLibs() {
sym.maxArgs = 0;
sym.targetType = lib->type;
sym.u.bltin = lib->initializer;
_xlibInitializers[lib->name] = sym;
Common::String xlibName = lib->name;
xlibName.toLowercase();
_xlibInitializers[xlibName] = sym;
}
}
void Lingo::openXLib(Common::String name, ObjectType type) {
if (_vm->getPlatform() == Common::kPlatformMacintosh) {
Common::Platform platform = _vm->getPlatform();
if (platform == Common::kPlatformMacintosh) {
int pos = name.findLastOf(':');
name = name.substr(pos + 1, name.size());
} else if (platform == Common::kPlatformWindows) {
if (name.hasSuffixIgnoreCase(".dll"))
name = name.substr(0, name.size() - 4);
}
// normalize xlib name
name.toLowercase();
name.trim();
if (_xlibInitializers.contains(name)) {
Symbol sym = _xlibInitializers[name];
(*sym.u.bltin)(type);