[Scummvm-git-logs] scummvm master -> 4213888dbfe164b3a6c8a8a915bec421e433e9dc

sev- sev at scummvm.org
Mon Feb 24 23:55:29 UTC 2020


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

Summary:
4213888dbf DIRECTOR: Added code for converting Mac filenames to Win


Commit: 4213888dbfe164b3a6c8a8a915bec421e433e9dc
    https://github.com/scummvm/scummvm/commit/4213888dbfe164b3a6c8a8a915bec421e433e9dc
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2020-02-25T00:54:57+01:00

Commit Message:
DIRECTOR: Added code for converting Mac filenames to Win

Changed paths:
    engines/director/util.cpp
    engines/director/util.h


diff --git a/engines/director/util.cpp b/engines/director/util.cpp
index 3e3256abce..b3c1d4cd9c 100644
--- a/engines/director/util.cpp
+++ b/engines/director/util.cpp
@@ -181,4 +181,100 @@ Common::String pathMakeRelative(Common::String path) {
 	return convPath;
 }
 
+//////////////////
+////// Mac --> Windows filename conversion
+//////////////////
+static byte myToUpper(byte c) {
+	if (c >= 'a' && c <= 'z')
+		c -= ('a' - 'A');
+	return c;
+}
+
+static bool myIsVowel(byte c) {
+	switch (myToUpper(c)) {
+	case 'A':
+	case 'E':
+	case 'I':
+	case 'O':
+	case 'U':
+		return true;
+	default:
+		return false;
+	}
+}
+
+static bool myIsAlpha(byte c) {
+	return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'));
+}
+
+static bool myIsDigit(byte c) {
+	return (c >= '0' && c <= '9');
+}
+
+static bool myIsAlnum(byte c) {
+	return (myIsAlpha(c) || myIsDigit(c));
+}
+
+static bool myIsSpace(byte c) {
+	return c ==' ';
+}
+
+Common::String convertMacFilename(const char *name) {
+	Common::String res;
+
+	int origlen = strlen(name);
+
+	// Remove trailing spaces
+	const char *ptr = &name[origlen - 1];
+	while (myIsSpace(*ptr))
+		ptr--;
+
+	/* Count suffix digits (up to whole filename less a character). */
+	int numDigits = 0;
+	char digits[10];
+
+	while (myIsDigit(*ptr) && (numDigits < (8 - 1)))
+		digits[++numDigits] = *ptr--;
+
+	ptr = name;
+	int cnt = 0;
+	while (cnt < (8 - numDigits) && ptr < &name[origlen]) {
+		char c = toupper(*ptr++);
+
+		if ((myIsVowel(c) && (cnt != 0)) || myIsSpace(c) || myIsDigit(c))
+			continue;
+
+		if ((c != '_') && !myIsAlnum(c))
+			continue;
+
+		cnt++;
+	}
+
+	int numVowels = 8 - (numDigits + cnt);
+	ptr = name;
+	for (cnt = 0; cnt < (8 - numDigits) && ptr < &name[origlen];) {
+		char c = toupper(*ptr++);
+
+		if (myIsVowel(c) && (cnt != 0)) {
+			if (numVowels > 0)
+				numVowels--;
+			else
+				continue;
+		}
+
+		if (myIsSpace(c) || myIsDigit(c) || ((c != '_') && !myIsAlnum(c)))
+			continue;
+
+		res += c;
+
+		cnt++;
+	}
+
+
+	while (numDigits)
+		res += digits[numDigits--];
+
+	return res + ".MMM";
+}
+
 } // End of namespace Director
diff --git a/engines/director/util.h b/engines/director/util.h
index fad016ec1d..b8c25a7158 100644
--- a/engines/director/util.h
+++ b/engines/director/util.h
@@ -40,6 +40,8 @@ Common::String getPath(Common::String path, Common::String cwd);
 
 Common::String pathMakeRelative(Common::String path);
 
+Common::String convertMacFilename(const char *name);
+
 void processQuitEvent(); // events.cpp
 
 } // End of namespace Director




More information about the Scummvm-git-logs mailing list