[Scummvm-cvs-logs] scummvm-tools master -> 397ea18dfd9f3e4157fd92bfd7e889396fc0d618

criezy criezy at scummvm.org
Mon Nov 21 22:40:17 CET 2011


This automated email contains information about 3 new commits which have been
pushed to the 'scummvm-tools' repo located at https://github.com/scummvm/scummvm-tools .

Summary:
62af3658d8 TOOLS: Improve behavior of Filename for directories
ad4170337d TOOLS: Improve handling of input files and directories
397ea18dfd TOOLS: Fix compress_sword help string


Commit: 62af3658d85d323c0afd9d883761c7763208bfd2
    https://github.com/scummvm/scummvm-tools/commit/62af3658d85d323c0afd9d883761c7763208bfd2
Author: Thierry Crozat (criezy at scummvm.org)
Date: 2011-11-21T13:37:21-08:00

Commit Message:
TOOLS: Improve behavior of Filename for directories

When creating a Filename with a path corresponding to a directory
but without a '/' or '\\' at the end the last part is treated as the file
name and not a directory and setFullName() does not behaves as
expected. Now when setting the path in Filename if it corresponds to
an existing directory it makes sure it ends with a '/' or '\\'.

Changed paths:
    common/file.cpp



diff --git a/common/file.cpp b/common/file.cpp
index a1ca46b..c9c62a7 100644
--- a/common/file.cpp
+++ b/common/file.cpp
@@ -50,8 +50,14 @@ namespace Common {
 Filename::Filename() {
 }
 Filename::Filename(const char *path) : _path(path) {
+	// If this is a directory append '/' at the end if needed.
+	if (!_path.empty() && _path[_path.size() - 1] != '/' && _path[_path.size() - 1] != '\\' && isDirectory(_path.c_str()))
+		_path += '/';
 }
 Filename::Filename(std::string path) : _path(path) {
+	// If this is a directory append '/' at the end if needed.
+	if (!_path.empty() && _path[_path.size() - 1] != '/' && _path[_path.size() - 1] != '\\' && isDirectory(_path.c_str()))
+		_path += '/';
 }
 
 Filename::Filename(const Filename& filename) : _path(filename._path) {
@@ -64,6 +70,9 @@ Filename& Filename::operator=(const Filename& filename) {
 
 void Filename::setFullPath(const std::string &path) {
 	_path = path;
+	// If this is a directory append '/' at the end if needed.
+	if (!_path.empty() && _path[_path.size() - 1] != '/' && _path[_path.size() - 1] != '\\' && isDirectory(_path.c_str()))
+		_path += '/';
 }
 
 void Filename::setFullName(const std::string &newname) {


Commit: ad4170337d7d6c996c5cbf6cccf446bb941a8e6c
    https://github.com/scummvm/scummvm-tools/commit/ad4170337d7d6c996c5cbf6cccf446bb941a8e6c
Author: Thierry Crozat (criezy at scummvm.org)
Date: 2011-11-21T13:37:21-08:00

Commit Message:
TOOLS: Improve handling of input files and directories

There are three main changes:
Properly handle directory detection.
Improve inspectInput() when there is more than one input to the tool.
Rewrote input arguments parsing to match them with the expected inputs.

Changed paths:
    tool.cpp
    tool.h



diff --git a/tool.cpp b/tool.cpp
index aaf68ef..2feb3d9 100644
--- a/tool.cpp
+++ b/tool.cpp
@@ -90,24 +90,46 @@ int Tool::run(const std::deque<std::string> &args) {
 		return -2;
 	}
 
-	// Read input files from CLI
-	for (ToolInputs::iterator iter = _inputPaths.begin(); iter != _inputPaths.end(); ++iter) {
+	// Read input files from CLI and match them to expected input.
+	// First make sure the all the input paths are unset 
+	for (ToolInputs::iterator iter = _inputPaths.begin(); iter != _inputPaths.end(); ++iter)
+		iter->path.clear();
+	// Then match the remaining arguments with the input paths.
+	int nbExpectedInputs = _inputPaths.size();
+	for (int i = 0 ; i < nbExpectedInputs ; ++i) {
 		std::string in = _arguments.front();
 		_arguments.pop_front();
-		if (!iter->file) {
+		int bestMatchIndex = -1;
+		InspectionMatch bestMatch = IMATCH_AWFUL;
+		for (ToolInputs::iterator iter = _inputPaths.begin(); iter != _inputPaths.end(); ++iter) {
+			if (!iter->path.empty())
+				continue;
+			InspectionMatch match = inspectInput(in, iter->file ? iter->format : std::string("/"));
+			if (match == IMATCH_PERFECT) {
+				bestMatch = IMATCH_PERFECT;
+				bestMatchIndex = (iter - _inputPaths.begin());
+				break;
+			} else if (bestMatch == IMATCH_AWFUL && match == IMATCH_POSSIBLE) {
+				bestMatch = IMATCH_POSSIBLE;
+				bestMatchIndex = (iter - _inputPaths.begin());
+			}
+		}
+		if (bestMatch == IMATCH_AWFUL) {
+			print("Unexpected input file '%s'!\n", in.c_str());
+			return -2;
+		}
+		if (!_inputPaths[bestMatchIndex].file) {
 			// Append '/' to input if it's not already done
-			// TODO: We need a way to detect a proper directory here!
 			size_t s = in.size();
 			if (in[s-1] != '/' && in[s-1] != '\\') {
-				in.append("/");
+				in += '/';
 			}
 		}
-
-		iter->path = in;
+		_inputPaths[bestMatchIndex].path = in;
 	}
 
 	// We should have parsed all arguments by now
-	if (_inputPaths.size() < _arguments.size()) {
+	if (!_arguments.empty()) {
 		std::ostringstream os;
 		os << "Too many inputs files ( ";
 		while (!_arguments.empty()) {
@@ -156,36 +178,50 @@ void Tool::run() {
 }
 
 InspectionMatch Tool::inspectInput(const Common::Filename &filename) {
+	InspectionMatch bestMatch = IMATCH_AWFUL;
 	for (ToolInputs::iterator iter = _inputPaths.begin(); iter != _inputPaths.end(); ++iter) {
-		std::string p = iter->format;
-		if (p == "/") {
-			// TODO
-			// Directory, we don't handle this yet, don't display at all
-			return IMATCH_AWFUL;
-		}
+		InspectionMatch match = inspectInput(filename, iter->file ? iter->format : std::string("/"));
+		if (match == IMATCH_PERFECT)
+			return IMATCH_PERFECT;
+		else if (match == IMATCH_POSSIBLE)
+			bestMatch = match;
+	}
 
-		Common::Filename cmp_filename = p;
+	// Didn't match any of our inputs
+	return bestMatch;
+}
+
+InspectionMatch Tool::inspectInput(const Common::Filename &filename, const std::string& format) {
+	// Case were we expect a directory
+	if (format == "/") {
+		if (filename.directory())
+			return IMATCH_POSSIBLE;
+		return IMATCH_AWFUL;
+	}
 
-		if (cmp_filename.getName() == "*") {
+	// We expect a file.
+	// First check this is not a directory.
+	if (filename.directory())
+		return IMATCH_AWFUL;
+	
+	Common::Filename cmp_filename = format;
+	if (cmp_filename.getName() == "*") {
+		if (cmp_filename.getExtension() == "*")
+			// Match anything!
+			return IMATCH_POSSIBLE;
+		else if (scumm_stricmp(cmp_filename.getExtension().c_str(), filename.getExtension().c_str()) == 0)
+			// Extensions are the same
+			return IMATCH_PERFECT;
+	} else {
+		// Match on filename
+		if (cmp_filename.getName() == filename.getName()) {
 			if (cmp_filename.getExtension() == "*")
-				// Match anything!
-				return IMATCH_POSSIBLE;
+				return IMATCH_PERFECT;
 			else if (scumm_stricmp(cmp_filename.getExtension().c_str(), filename.getExtension().c_str()) == 0)
-				// Extensions are the same
+				// Filenames are identical
 				return IMATCH_PERFECT;
-		} else {
-			// Match on filename
-			if (cmp_filename.getName() == filename.getName()) {
-				if (cmp_filename.getExtension() == "*")
-					return IMATCH_PERFECT;
-				else if (scumm_stricmp(cmp_filename.getExtension().c_str(), filename.getExtension().c_str()) == 0)
-					// Filenames are identical
-					return IMATCH_PERFECT;
-			}
 		}
 	}
-
-	// Didn't match any of our inputs
 	return IMATCH_AWFUL;
 }
 
diff --git a/tool.h b/tool.h
index 9890156..42d77f7 100644
--- a/tool.h
+++ b/tool.h
@@ -200,6 +200,8 @@ protected:
 	virtual void parseAudioArguments();
 	virtual void setTempFileName();
 	void parseOutputArguments();
+	
+	InspectionMatch inspectInput(const Common::Filename &filename, const std::string& format);
 
 	/** Parses the arguments only this tool takes. */
 	virtual void parseExtraArguments();


Commit: 397ea18dfd9f3e4157fd92bfd7e889396fc0d618
    https://github.com/scummvm/scummvm-tools/commit/397ea18dfd9f3e4157fd92bfd7e889396fc0d618
Author: Thierry Crozat (criezy at scummvm.org)
Date: 2011-11-21T13:37:21-08:00

Commit Message:
TOOLS: Fix compress_sword help string

The tool is expecting an input file and not an input directory.

Changed paths:
    engines/sword1/compress_sword1.cpp



diff --git a/engines/sword1/compress_sword1.cpp b/engines/sword1/compress_sword1.cpp
index 0952154..065a0aa 100644
--- a/engines/sword1/compress_sword1.cpp
+++ b/engines/sword1/compress_sword1.cpp
@@ -741,10 +741,11 @@ CompressSword1::CompressSword1(const std::string &name) : CompressionTool(name,
 	_inputPaths.push_back(input);
 
 	_shorthelp = "Used to compress Broken Sword 1 data files.";
-	_helptext = "\nUsage: " + getName() + " [mode] [mode params] [-o outputdir] [only] <inputdir>\n"
+	_helptext = "\nUsage: " + getName() + " [mode] [mode params] [-o outputdir] [only] <inputfile>\n"
 		"only can be either:\n"
 		" --speech-only  only encode speech clusters\n"
-		" --music-only   only encode music files\n";
+		" --music-only   only encode music files\n\n"
+		"<inputfile> can match one of 'swordres.rif', *.clu or *.clm\n";
 }
 
 void CompressSword1::parseExtraArguments() {






More information about the Scummvm-git-logs mailing list