Initial commit
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "engines/wintermute/debugger/listing_providers/basic_source_listing_provider.h"
|
||||
#include "engines/wintermute/base/base_file_manager.h"
|
||||
|
||||
namespace Wintermute {
|
||||
BasicSourceListingProvider::BasicSourceListingProvider() : _fsDirectory(nullptr) {
|
||||
}
|
||||
|
||||
BasicSourceListingProvider::~BasicSourceListingProvider() {
|
||||
}
|
||||
|
||||
SourceListing *BasicSourceListingProvider::getListing(const Common::Path &filename, ErrorCode &_err) {
|
||||
_err = OK;
|
||||
if (!_fsDirectory) {
|
||||
_err = SOURCE_PATH_NOT_SET;
|
||||
return nullptr;
|
||||
};
|
||||
|
||||
Common::SeekableReadStream *file = _fsDirectory->createReadStreamForMember(filename);
|
||||
Common::Array<Common::String> strings;
|
||||
|
||||
if (!file) {
|
||||
_err = NO_SUCH_SOURCE;
|
||||
} else {
|
||||
if (file->err()) {
|
||||
_err = UNKNOWN_ERROR;
|
||||
}
|
||||
while (!file->eos()) {
|
||||
strings.push_back(file->readLine());
|
||||
if (file->err()) {
|
||||
_err = UNKNOWN_ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (_err == OK) {
|
||||
return new SourceListing(strings);
|
||||
} else {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
ErrorCode BasicSourceListingProvider::setPath(const Common::Path &path) {
|
||||
if (path.empty())
|
||||
return ILLEGAL_PATH;
|
||||
delete _fsDirectory;
|
||||
Common::FSNode node(path);
|
||||
if (node.exists() && node.isDirectory()) {
|
||||
_fsDirectory = new Common::FSDirectory(node, 64);
|
||||
return OK;
|
||||
} else {
|
||||
return COULD_NOT_OPEN;
|
||||
}
|
||||
}
|
||||
|
||||
Common::Path BasicSourceListingProvider::getPath() const {
|
||||
if (!_fsDirectory) return Common::Path();
|
||||
return _fsDirectory->getFSNode().getPath();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef BASIC_SOURCE_LISTING_PROVIDER_H_
|
||||
#define BASIC_SOURCE_LISTING_PROVIDER_H_
|
||||
|
||||
#include "engines/wintermute/debugger/listing_provider.h"
|
||||
#include "engines/wintermute/debugger/listing_providers/source_listing_provider.h"
|
||||
#include "source_listing.h"
|
||||
#include "common/fs.h"
|
||||
|
||||
namespace Wintermute {
|
||||
|
||||
class BasicSourceListingProvider : public SourceListingProvider {
|
||||
Common::FSDirectory *_fsDirectory;
|
||||
public:
|
||||
BasicSourceListingProvider();
|
||||
~BasicSourceListingProvider() override;
|
||||
SourceListing *getListing(const Common::Path &filename, ErrorCode &err) override;
|
||||
ErrorCode setPath(const Common::Path &path) override;
|
||||
Common::Path getPath() const override;
|
||||
};
|
||||
|
||||
}
|
||||
#endif /* BASIC_SOURCE_LISTING_PROVIDER_H_ */
|
||||
@@ -0,0 +1,37 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "blank_listing.h"
|
||||
#include "engines/wintermute/wintermute.h"
|
||||
|
||||
namespace Wintermute {
|
||||
|
||||
BlankListing::BlankListing(const Common::Path &filename) : _filename(filename.toString(Common::Path::kNativeSeparator)) {}
|
||||
|
||||
uint BlankListing::getLength() const { return UINT_MAX_VALUE; }
|
||||
|
||||
Common::String BlankListing::getLine(uint n) {
|
||||
return "<no source for " + _filename + " ~~~ line: " + Common::String::format("%d", n) + ">";
|
||||
}
|
||||
BlankListing::~BlankListing() {}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef BLANK_LISTING_H_
|
||||
#define BLANK_LISTING_H_
|
||||
#include "engines/wintermute/debugger/listing.h"
|
||||
|
||||
#include "common/path.h"
|
||||
|
||||
namespace Wintermute {
|
||||
class BlankListing : public Listing {
|
||||
const Common::String _filename;
|
||||
public:
|
||||
BlankListing(const Common::Path &filename);
|
||||
~BlankListing() override;
|
||||
uint getLength() const override;
|
||||
Common::String getLine(uint n) override;
|
||||
};
|
||||
|
||||
} // End of namespace Wintermute
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,34 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "blank_listing_provider.h"
|
||||
#include "blank_listing.h"
|
||||
namespace Wintermute {
|
||||
BlankListingProvider::BlankListingProvider() {}
|
||||
|
||||
BlankListingProvider::~BlankListingProvider() {}
|
||||
|
||||
Listing *BlankListingProvider::getListing(const Common::Path &filename, ErrorCode &error) {
|
||||
Listing *l = new BlankListing(filename);
|
||||
error = OK;
|
||||
return l; // Delete this sometime please.
|
||||
}
|
||||
} // End of namespace Wintermute
|
||||
@@ -0,0 +1,37 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef BLANK_LISTING_PROVIDER_H_
|
||||
#define BLANK_LISTING_PROVIDER_H_
|
||||
|
||||
#include "engines/wintermute/debugger/listing.h"
|
||||
#include "engines/wintermute/debugger/listing_provider.h"
|
||||
#include "engines/wintermute/debugger/error.h"
|
||||
|
||||
namespace Wintermute {
|
||||
class BlankListingProvider : public ListingProvider {
|
||||
public:
|
||||
BlankListingProvider();
|
||||
~BlankListingProvider() override;
|
||||
Listing *getListing(const Common::Path &filename, ErrorCode &error) override;
|
||||
};
|
||||
} // End of namespace Wintermute
|
||||
#endif
|
||||
@@ -0,0 +1,79 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "engines/wintermute/debugger/listing_providers/cached_source_listing_provider.h"
|
||||
#include "engines/wintermute/debugger/listing_providers/basic_source_listing_provider.h"
|
||||
#include "engines/wintermute/debugger/listing_providers/blank_listing_provider.h"
|
||||
#include "engines/wintermute/debugger/listing_providers/source_listing.h"
|
||||
|
||||
namespace Wintermute {
|
||||
|
||||
CachedSourceListingProvider::CachedSourceListingProvider() {
|
||||
_sourceListingProvider = new BasicSourceListingProvider();
|
||||
_fallbackListingProvider = new BlankListingProvider();
|
||||
}
|
||||
|
||||
CachedSourceListingProvider::~CachedSourceListingProvider() {
|
||||
delete _sourceListingProvider;
|
||||
delete _fallbackListingProvider;
|
||||
for (CacheMap::iterator it = _cached.begin();
|
||||
it != _cached.end(); it++) {
|
||||
delete (it->_value);
|
||||
}
|
||||
}
|
||||
|
||||
Listing *CachedSourceListingProvider::getListing(const Common::Path &filename, Wintermute::ErrorCode &error) {
|
||||
if (_cached.contains(filename)) {
|
||||
error = OK;
|
||||
SourceListing *copy = new SourceListing(*_cached.getVal(filename));
|
||||
return copy;
|
||||
} else {
|
||||
ErrorCode inner;
|
||||
SourceListing *res = _sourceListingProvider->getListing(filename, inner);
|
||||
if (inner == OK) {
|
||||
SourceListing *copy = new SourceListing(*res);
|
||||
_cached.setVal(filename, copy); // The cached copy is deleted on destruction
|
||||
return res;
|
||||
} else {
|
||||
delete res;
|
||||
return _fallbackListingProvider->getListing(filename, error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CachedSourceListingProvider::invalidateCache() {
|
||||
for (CacheMap::iterator it = _cached.begin();
|
||||
it != _cached.end(); it++) {
|
||||
delete (it->_value);
|
||||
}
|
||||
_cached.clear();
|
||||
}
|
||||
|
||||
ErrorCode CachedSourceListingProvider::setPath(const Common::Path &path) {
|
||||
invalidateCache();
|
||||
return _sourceListingProvider->setPath(path);
|
||||
}
|
||||
|
||||
Common::Path CachedSourceListingProvider::getPath() const {
|
||||
return _sourceListingProvider->getPath();
|
||||
}
|
||||
|
||||
} // End of namespace Wintermute
|
||||
@@ -0,0 +1,52 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef CACHED_LISTING_PROVIDER_H_
|
||||
#define CACHED_LISTING_PROVIDER_H_
|
||||
|
||||
#include "common/hashmap.h"
|
||||
#include "common/hash-str.h"
|
||||
#include "engines/wintermute/debugger/error.h"
|
||||
#include "engines/wintermute/debugger/listing_providers/source_listing_provider.h"
|
||||
|
||||
namespace Wintermute {
|
||||
|
||||
class BasicSourceListingProvider;
|
||||
class BlankListingProvider;
|
||||
class Listing;
|
||||
|
||||
class CachedSourceListingProvider : public SourceListingProvider {
|
||||
BasicSourceListingProvider *_sourceListingProvider;
|
||||
BlankListingProvider *_fallbackListingProvider;
|
||||
typedef Common::HashMap<Common::Path, SourceListing *, Common::Path::IgnoreCaseAndMac_Hash, Common::Path::IgnoreCaseAndMac_EqualTo> CacheMap;
|
||||
CacheMap _cached;
|
||||
void invalidateCache();
|
||||
public:
|
||||
CachedSourceListingProvider();
|
||||
~CachedSourceListingProvider() override;
|
||||
ErrorCode setPath(const Common::Path &path) override;
|
||||
Common::Path getPath() const override;
|
||||
Listing *getListing(const Common::Path &filename, ErrorCode &err) override;
|
||||
};
|
||||
|
||||
} // End of namespace Wintermute
|
||||
|
||||
#endif /* CACHED_LISTING_PROVIDER_H_ */
|
||||
@@ -0,0 +1,56 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "source_listing.h"
|
||||
|
||||
namespace Wintermute {
|
||||
|
||||
SourceListing::SourceListing(const Common::Array<Common::String> &strings) : _strings(strings) {}
|
||||
|
||||
SourceListing::~SourceListing() {}
|
||||
|
||||
uint SourceListing::getLength() const {
|
||||
return _strings.size();
|
||||
}
|
||||
|
||||
Common::String SourceListing::getLine(uint n) {
|
||||
uint index = n - 1; // Line numbers start from 1, arrays from 0
|
||||
/*
|
||||
* Clients should not ask for a line number that
|
||||
* is not in the source file.
|
||||
* 0 is undefined, n - 1 is undefined.
|
||||
* It is easy for the client to check that n > 0
|
||||
* and n < getLength(), so it should just not happen.
|
||||
* We return '^', after vim, to misbehaving clients.
|
||||
*/
|
||||
if (n == 0) {
|
||||
return Common::String("^");
|
||||
}
|
||||
if (index < getLength()) {
|
||||
return _strings[index];
|
||||
} else {
|
||||
return Common::String("^");
|
||||
}
|
||||
}
|
||||
|
||||
} // End of namespace Wintermute
|
||||
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef SOURCE_LISTING_H_
|
||||
#define SOURCE_LISTING_H_
|
||||
#include "engines/wintermute/debugger/listing.h"
|
||||
|
||||
namespace Wintermute {
|
||||
class SourceListing : public Listing {
|
||||
const Common::Array<Common::String> _strings;
|
||||
public:
|
||||
SourceListing(const Common::Array<Common::String> &strings);
|
||||
~SourceListing() override;
|
||||
uint getLength() const override;
|
||||
Common::String getLine(uint n) override;
|
||||
};
|
||||
}
|
||||
#endif /* DUMMY_LISTING_H_ */
|
||||
@@ -0,0 +1,49 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef SOURCE_LISTING_PROVIDER_H_
|
||||
#define SOURCE_LISTING_PROVIDER_H_
|
||||
|
||||
#include "engines/wintermute/debugger/error.h"
|
||||
#include "engines/wintermute/debugger/listing_provider.h"
|
||||
#include "common/path.h"
|
||||
#include "common/str.h"
|
||||
|
||||
namespace Wintermute {
|
||||
|
||||
class SourceListing;
|
||||
class Listing;
|
||||
|
||||
class SourceListingProvider : ListingProvider {
|
||||
public:
|
||||
~SourceListingProvider() override {};
|
||||
/**
|
||||
* Get a listing. When implementing this, the result should be safe to delete for the caller.
|
||||
*/
|
||||
Listing *getListing(const Common::Path &filename, ErrorCode &err) override = 0;
|
||||
virtual ErrorCode setPath(const Common::Path &path) = 0;
|
||||
virtual Common::Path getPath() const = 0;
|
||||
|
||||
};
|
||||
|
||||
} // End of namespace Wintermute
|
||||
|
||||
#endif /* SOURCE_LISTING_PROVIDER_H_ */
|
||||
Reference in New Issue
Block a user