[Scummvm-cvs-logs] SF.net SVN: scummvm:[47296] tools/trunk/engines/mohawk
tdhs at users.sourceforge.net
tdhs at users.sourceforge.net
Thu Jan 14 01:16:17 CET 2010
Revision: 47296
http://scummvm.svn.sourceforge.net/scummvm/?rev=47296&view=rev
Author: tdhs
Date: 2010-01-14 00:15:57 +0000 (Thu, 14 Jan 2010)
Log Message:
-----------
Fixed Mohawk tools to be buildable, prior to cleanup and integration.
This required adding the files from the tools.diff patch, which was not imported initially.
Most of these files are duplicated in "common" and "sound", but these have minor changes which will need merging and one major change i.e. wrapping of file accesses in a SeekableReadStream implementation.
Added Paths:
-----------
tools/trunk/engines/mohawk/Makefile
tools/trunk/engines/mohawk/util.cpp
tools/trunk/engines/mohawk/util.h
tools/trunk/engines/mohawk/utils/
tools/trunk/engines/mohawk/utils/adpcm.cpp
tools/trunk/engines/mohawk/utils/adpcm.h
tools/trunk/engines/mohawk/utils/algorithm.h
tools/trunk/engines/mohawk/utils/array.h
tools/trunk/engines/mohawk/utils/audiostream.cpp
tools/trunk/engines/mohawk/utils/audiostream.h
tools/trunk/engines/mohawk/utils/file.cpp
tools/trunk/engines/mohawk/utils/file.h
tools/trunk/engines/mohawk/utils/md5.cpp
tools/trunk/engines/mohawk/utils/md5.h
tools/trunk/engines/mohawk/utils/pack-end.h
tools/trunk/engines/mohawk/utils/pack-start.h
tools/trunk/engines/mohawk/utils/str.cpp
tools/trunk/engines/mohawk/utils/str.h
tools/trunk/engines/mohawk/utils/stream.h
tools/trunk/engines/mohawk/utils/util.h
tools/trunk/engines/mohawk/utils/voc.cpp
tools/trunk/engines/mohawk/utils/voc.h
tools/trunk/engines/mohawk/utils/wave.cpp
tools/trunk/engines/mohawk/utils/wave.h
Property Changed:
----------------
tools/trunk/engines/mohawk/
Property changes on: tools/trunk/engines/mohawk
___________________________________________________________________
Added: svn:ignore
+ .deps
Added: tools/trunk/engines/mohawk/Makefile
===================================================================
--- tools/trunk/engines/mohawk/Makefile (rev 0)
+++ tools/trunk/engines/mohawk/Makefile 2010-01-14 00:15:57 UTC (rev 47296)
@@ -0,0 +1,106 @@
+# $URL: https://scummvm.svn.sourceforge.net/svnroot/scummvm/tools/branches/gsoc2009-gui/Makefile $
+# $Id: Makefile 41455 2009-06-11 21:42:48Z fingolfin $
+
+#######################################################################
+# Default compilation parameters. Normally don't edit these #
+#######################################################################
+
+srcdir ?= .
+
+DEFINES := -DUNIX
+LDFLAGS := $(LDFLAGS)
+INCLUDES := -I. -I$(srcdir)
+LIBS :=
+OBJS :=
+DEPDIR := .deps
+
+# Load the make rules generated by configure
+# HACK: We don't yet support configure in the tools SVN module, but at least one can
+# manually create a config.mk files with overrides, if needed.
+-include config.mk
+
+CXXFLAGS += -g -O -Wuninitialized
+
+# Additional warnings
+CXXFLAGS:= -Wall $(CXXFLAGS)
+# Turn off some annoying and not-so-useful warnings
+CXXFLAGS+= -Wno-long-long -Wno-multichar -Wno-unknown-pragmas -Wno-reorder
+# Enable even more warnings...
+#CXXFLAGS+= -pedantic # -pedantic is too pedantic, at least on Mac OS X
+CXXFLAGS+= -Wpointer-arith -Wcast-qual -Wconversion
+CXXFLAGS+= -Wshadow -Wimplicit -Wundef -Wnon-virtual-dtor -Wwrite-strings
+
+# Disable exceptions, and enabled checking of pointers returned by "new"
+CXXFLAGS+= -fno-exceptions -fcheck-new
+
+#######################################################################
+# Default commands - put the necessary replacements in config.mk #
+#######################################################################
+
+CAT ?= cat
+CP ?= cp
+ECHO ?= printf
+INSTALL ?= install
+MKDIR ?= mkdir -p
+RM ?= rm -f
+RM_REC ?= $(RM) -r
+ZIP ?= zip -q
+
+CC := gcc
+CXX := g++
+
+#######################################################################
+
+# HACK: Until we get proper module support, add these "module dirs" to
+# get the dependency tracking code working.
+MODULE_DIRS := ./ utils/
+
+#######################################################################
+
+TARGETS := \
+ deriven$(EXEEXT) \
+ extract_mohawk$(EXEEXT)
+
+UTILS := \
+ utils/adpcm.o \
+ utils/audiostream.o \
+ utils/file.o \
+ utils/md5.o \
+ utils/str.o \
+ utils/voc.o \
+ utils/wave.o
+
+all: $(TARGETS)
+
+install: $(TARGETS)
+ for i in $^ ; do install -p -m 0755 $$i $(DESTDIR) ; done
+
+deriven$(EXEEXT): deriven.o mohawk_file.o util.o $(UTILS)
+ $(CXX) $(LDFLAGS) -o $@ $+
+
+extract_mohawk$(EXEEXT): extract_mohawk.o mohawk_file.o util.o $(UTILS)
+ $(CXX) $(LDFLAGS) -o $@ $+
+clean:
+ rm -f *.o utils/*.o $(TARGETS)
+
+######################################################################
+# The build rules follow - normally you should have no need to
+# touch whatever comes after here.
+######################################################################
+
+# Concat DEFINES and INCLUDES to form the CPPFLAGS
+CPPFLAGS := $(DEFINES) $(INCLUDES)
+
+# Include the build instructions for all modules
+#-include $(addprefix $(srcdir)/, $(addsuffix /module.mk,$(MODULES)))
+
+# Depdir information
+DEPDIRS = $(addsuffix $(DEPDIR),$(MODULE_DIRS))
+DEPFILES =
+
+%.o: %.cpp
+ $(MKDIR) $(*D)/$(DEPDIR)
+ $(CXX) -Wp,-MMD,"$(*D)/$(DEPDIR)/$(*F).d",-MQ,"$@",-MP $(CXXFLAGS) $(CPPFLAGS) -c $(<) -o $*.o
+
+# Include the dependency tracking files.
+-include $(wildcard $(addsuffix /*.d,$(DEPDIRS)))
Property changes on: tools/trunk/engines/mohawk/Makefile
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:svn-keywords
+ Date Rev Author URL Id
Added: svn:eol-style
+ native
Added: tools/trunk/engines/mohawk/util.cpp
===================================================================
--- tools/trunk/engines/mohawk/util.cpp (rev 0)
+++ tools/trunk/engines/mohawk/util.cpp 2010-01-14 00:15:57 UTC (rev 47296)
@@ -0,0 +1,316 @@
+/* Scumm Tools
+ * Copyright (C) 2003-2006 The ScummVM Team
+ *
+ * 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 2
+ * 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL: https://scummvm.svn.sourceforge.net/svnroot/scummvm/tools/branches/gsoc2009-gui/util.cpp $
+ * $Id: util.cpp 41547 2009-06-15 14:24:36Z Remere $
+ *
+ */
+
+#include "util.h"
+#include <stdarg.h>
+
+#ifdef _MSC_VER
+ #define vsnprintf _vsnprintf
+#endif
+
+void error(const char *s, ...) {
+ char buf[1024];
+ va_list va;
+
+ va_start(va, s);
+ vsnprintf(buf, 1024, s, va);
+ va_end(va);
+
+ fprintf(stderr, "ERROR: %s!\n", buf);
+
+ exit(1);
+}
+
+void warning(const char *s, ...) {
+ char buf[1024];
+ va_list va;
+
+ va_start(va, s);
+ vsnprintf(buf, 1024, s, va);
+ va_end(va);
+
+ fprintf(stderr, "WARNING: %s!\n", buf);
+}
+
+void debug(int level, const char *s, ...) {
+ char buf[1024];
+ va_list va;
+
+ va_start(va, s);
+ vsnprintf(buf, 1024, s, va);
+ va_end(va);
+
+ fprintf(stderr, "DEBUG: %s!\n", buf);
+}
+
+void notice(const char *s, ...) {
+ char buf[1024];
+ va_list va;
+
+ va_start(va, s);
+ vsnprintf(buf, 1024, s, va);
+ va_end(va);
+
+ fprintf(stdout, "%s\n", buf);
+}
+
+uint8 readByte(FILE *fp) {
+ return fgetc(fp);
+}
+
+uint16 readUint16BE(FILE *fp) {
+ uint16 ret = 0;
+ ret |= fgetc(fp) << 8;
+ ret |= fgetc(fp);
+ return ret;
+}
+
+uint16 readUint16LE(FILE *fp) {
+ uint16 ret = 0;
+ ret |= fgetc(fp);
+ ret |= fgetc(fp) << 8;
+ return ret;
+}
+
+uint32 readUint32BE(FILE *fp) {
+ uint32 ret = 0;
+ ret |= fgetc(fp) << 24;
+ ret |= fgetc(fp) << 16;
+ ret |= fgetc(fp) << 8;
+ ret |= fgetc(fp);
+ return ret;
+}
+
+uint32 readUint32LE(FILE *fp) {
+ uint32 ret = 0;
+ ret |= fgetc(fp);
+ ret |= fgetc(fp) << 8;
+ ret |= fgetc(fp) << 16;
+ ret |= fgetc(fp) << 24;
+ return ret;
+}
+
+void writeByte(FILE *fp, uint8 b) {
+ fwrite(&b, 1, 1, fp);
+}
+
+void writeUint16BE(FILE *fp, uint16 value) {
+ writeByte(fp, (uint8)(value >> 8));
+ writeByte(fp, (uint8)(value));
+}
+
+void writeUint16LE(FILE *fp, uint16 value) {
+ writeByte(fp, (uint8)(value));
+ writeByte(fp, (uint8)(value >> 8));
+}
+
+void writeUint32BE(FILE *fp, uint32 value) {
+ writeByte(fp, (uint8)(value >> 24));
+ writeByte(fp, (uint8)(value >> 16));
+ writeByte(fp, (uint8)(value >> 8));
+ writeByte(fp, (uint8)(value));
+}
+
+void writeUint32LE(FILE *fp, uint32 value) {
+ writeByte(fp, (uint8)(value));
+ writeByte(fp, (uint8)(value >> 8));
+ writeByte(fp, (uint8)(value >> 16));
+ writeByte(fp, (uint8)(value >> 24));
+}
+
+uint32 fileSize(FILE *fp) {
+ uint32 sz;
+ uint32 pos = ftell(fp);
+ fseek(fp, 0, SEEK_END);
+ sz = ftell(fp);
+ fseek(fp, pos, SEEK_SET);
+ return sz;
+}
+
+Filename::Filename(const char *path) {
+ strcpy(_path, path);
+}
+
+Filename::Filename(const Filename& filename) {
+ strcpy(_path, filename._path);
+}
+
+Filename& Filename::operator=(const Filename& filename) {
+ strcpy(_path, filename._path);
+ return *this;
+}
+
+void Filename::setFullPath(const char *path) {
+ strcpy(_path, path);
+}
+
+Filename *Filename::setFullName(const char *newname) {
+ char p[1024];
+ if (getPath(p)) {
+ strcat(p, newname);
+ strcpy(_path, p);
+ return this;
+ }
+ return NULL;
+}
+
+void Filename::addExtension(const char *ext) {
+ strcat(_path, ext);
+}
+
+void Filename::setExtension(const char *ext) {
+ char *dot = strrchr(_path, '.');
+ if(!dot)
+ dot = _path + strlen(_path) - 1;
+ // Don't copy the dot
+ if(*ext == '.')
+ ext++;
+ strcpy(dot+1, ext);
+}
+
+bool Filename::equals(const Filename *other) const {
+#ifdef _WIN32
+ // On Windows paths are case-insensitive
+ return scumm_stricmp(_path, other->_path) == 0;
+#else
+ return strcmp(_path, other->_path) == 0;
+#endif
+}
+
+bool Filename::empty() const {
+ return *_path == 0;
+}
+
+bool Filename::hasExtension(const char *suffix) const {
+ const char *dot = strrchr(_path, '.');
+ if(!dot)
+ dot = _path + strlen(_path);
+
+ // Check that dot position is less than /, since some
+ // directories contain ., like /home/.data/file
+ const char *slash = strrchr(_path, '/');
+ if(slash && slash > dot)
+ return false;
+
+ slash = strrchr(_path, '\\');
+ if(slash && slash > dot)
+ return false;
+
+ // We compare extensions, skip any dots
+ if(*dot == '.')
+ dot++;
+ if(*suffix == '.')
+ suffix++;
+
+#ifdef _WIN32
+ // On Windows paths are case-insensitive
+ return scumm_stricmp(dot, suffix) == 0;
+#else
+ return strcmp(dot, suffix) == 0;
+#endif
+}
+
+const char *Filename::getFullPath() const {
+ return _path;
+}
+
+const char *Filename::getFullName(char *out) const {
+ const char *slash;
+ if ((slash = strrchr(_path, '/')) || (slash = strrchr(_path, '\\'))) {
+ strcpy(out, slash + 1);
+ return out;
+ }
+ strcpy(out, _path);
+ return out;
+}
+
+const char *Filename::getFullName() const {
+ const char *slash;
+ if ((slash = strrchr(_path, '/')) || (slash = strrchr(_path, '\\'))) {
+ return slash + 1;
+ }
+ return _path;
+}
+
+const char *Filename::getPath(char *out) const {
+ const char *slash;
+ if ((slash = strrchr(_path, '/')) || (slash = strrchr(_path, '\\'))) {
+ int end = strlen(_path) - strlen(slash) + 1;
+ strncpy(out, _path, end);
+ out[end] = '\0';
+ return out;
+ }
+ // If there was no '/', this was a local path
+ out[0] = '\0';
+ return out;
+}
+
+void displayHelp(const char *msg, const char *exename) {
+ if (!msg) {
+ printf("\nUsage: %s [-o <output dir> = out/] <file 1> ... <file n>\n", exename);
+ }
+ else {
+ printf(msg, exename);
+ }
+ exit(2);
+}
+
+void parseHelpArguments(const char * const argv[], int argc, const char *msg) {
+ if (argc < 2 || strcmp(argv[1], "--help") == 0 || scumm_stricmp(argv[1], "-h") == 0) {
+ displayHelp(msg, argv[0]);
+ }
+}
+
+bool parseOutputArguments(Filename *outputname, bool output_directory, const char * const argv[], int argc, int start_arg) {
+ if (start_arg >= 0 && (strcmp(argv[start_arg], "-o") == 0 || strcmp(argv[start_arg], "--output") == 0)) {
+ /* It's a -o argument, can we check next arg? */
+
+ if (start_arg + 1 < argc) {
+ outputname->setFullPath(argv[start_arg + 1]);
+
+ if (output_directory) {
+ /* Ensure last character is a /, this way we force directory output */
+ char lastchr = outputname->getFullPath()[strlen(outputname->getFullPath()) - 1];
+ if (lastchr != '/' && lastchr != '\\') {
+ strcat(outputname->_path, "/");
+ }
+ } else {
+ char* lastchr = outputname->_path + strlen(outputname->getFullPath()) - 1;
+ if (*lastchr == '/' && *lastchr == '\\') {
+ *lastchr = '\0';
+ }
+ }
+ return true;
+ } else {
+ error("Expected directory path after '-o' or '--output'.");
+ }
+ }
+ return false;
+}
+
+bool parseOutputFileArguments(Filename *outputname, const char * const argv[], int argc, int start_arg) {
+ return parseOutputArguments(outputname, false, argv, argc, start_arg);
+}
+
+bool parseOutputDirectoryArguments(Filename *outputname, const char * const argv[], int argc, int start_arg) {
+ return parseOutputArguments(outputname, true, argv, argc, start_arg);
+}
Property changes on: tools/trunk/engines/mohawk/util.cpp
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:svn-keywords
+ Date Rev Author URL Id
Added: svn:eol-style
+ native
Added: tools/trunk/engines/mohawk/util.h
===================================================================
--- tools/trunk/engines/mohawk/util.h (rev 0)
+++ tools/trunk/engines/mohawk/util.h 2010-01-14 00:15:57 UTC (rev 47296)
@@ -0,0 +1,245 @@
+/* Scumm Tools
+ * Copyright (C) 2002-2006 The ScummVM project
+ *
+ * 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 2
+ * 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL: https://scummvm.svn.sourceforge.net/svnroot/scummvm/tools/branches/gsoc2009-gui/util.h $
+ * $Id: util.h 41441 2009-06-10 23:55:21Z Remere $
+ *
+ */
+
+#ifndef UTIL_H
+#define UTIL_H
+
+#include <assert.h>
+#include <ctype.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+
+#if !defined(_MSC_VER)
+#include <unistd.h>
+#endif
+
+#ifdef WIN32
+#include <io.h>
+#include <process.h>
+#endif
+
+
+/*
+ * Some useful types
+ */
+
+typedef unsigned char byte;
+typedef unsigned char uint8;
+typedef unsigned short uint16;
+typedef signed char int8;
+typedef signed short int16;
+#ifdef __amigaos4__
+#include <exec/types.h>
+#include <stdlib.h>
+#else
+typedef unsigned int uint32;
+typedef signed int int32;
+#endif
+
+typedef uint32 uint;
+
+/*
+ * Various utility macros
+ */
+
+#if defined(_MSC_VER)
+
+ #define scumm_stricmp stricmp
+ #define scumm_strnicmp _strnicmp
+ #define snprintf _snprintf
+
+ #define SCUMM_LITTLE_ENDIAN
+ #pragma once
+ #pragma warning( disable : 4068 ) /* turn off "unknown pragma" warning */
+ #pragma warning( disable : 4996 ) /* turn off warnings about unsafe functions */
+
+#elif defined(__MINGW32__)
+
+ #define scumm_stricmp stricmp
+ #define scumm_strnicmp strnicmp
+
+ #define SCUMM_LITTLE_ENDIAN
+
+#elif defined(UNIX)
+
+ #define scumm_stricmp strcasecmp
+ #define scumm_strnicmp strncasecmp
+
+ #if defined(__DECCXX) /* Assume alpha architecture */
+ #define INVERSE_MKID
+ #define SCUMM_NEED_ALIGNMENT
+ #endif
+
+#else
+
+ #error No system type defined
+
+#endif
+
+
+/*
+ * GCC specific stuff
+ */
+#if defined(__GNUC__)
+ #define GCC_PACK __attribute__((packed))
+ #define NORETURN __attribute__((__noreturn__))
+ #define GCC_PRINTF(x,y) __attribute__((format(printf, x, y)))
+#else
+ #define GCC_PACK
+ #define GCC_PRINTF(x,y)
+#endif
+
+#define ARRAYSIZE(x) ((int)(sizeof(x) / sizeof(x[0])))
+
+#if defined(INVERSE_MKID)
+#define MKID_BE(a) ((uint32) \
+ (((a) >> 24) & 0x000000FF) | \
+ (((a) >> 8) & 0x0000FF00) | \
+ (((a) << 8) & 0x00FF0000) | \
+ (((a) << 24) & 0xFF000000))
+
+#else
+# define MKID_BE(a) ((uint32)(a))
+#endif
+
+static inline uint32 SWAP_32(uint32 a) {
+ return ((a >> 24) & 0xFF) | ((a >> 8) & 0xFF00) | ((a << 8) & 0xFF0000) |
+ ((a << 24) & 0xFF000000);
+}
+
+static inline uint16 SWAP_16(uint16 a) {
+ return ((a >> 8) & 0xFF) | ((a << 8) & 0xFF00);
+}
+
+#define FORCEINLINE static inline
+
+FORCEINLINE uint16 READ_LE_UINT16(const void *ptr) {
+ const byte *b = (const byte *)ptr;
+ return (b[1] << 8) + b[0];
+}
+FORCEINLINE uint32 READ_LE_UINT32(const void *ptr) {
+ const byte *b = (const byte *)ptr;
+ return (b[3] << 24) + (b[2] << 16) + (b[1] << 8) + (b[0]);
+}
+FORCEINLINE void WRITE_LE_UINT16(void *ptr, uint16 value) {
+ byte *b = (byte *)ptr;
+ b[0] = (byte)(value >> 0);
+ b[1] = (byte)(value >> 8);
+}
+FORCEINLINE void WRITE_LE_UINT32(void *ptr, uint32 value) {
+ byte *b = (byte *)ptr;
+ b[0] = (byte)(value >> 0);
+ b[1] = (byte)(value >> 8);
+ b[2] = (byte)(value >> 16);
+ b[3] = (byte)(value >> 24);
+}
+
+FORCEINLINE uint16 READ_BE_UINT16(const void *ptr) {
+ const byte *b = (const byte *)ptr;
+ return (b[0] << 8) + b[1];
+}
+FORCEINLINE uint32 READ_BE_UINT32(const void *ptr) {
+ const byte *b = (const byte *)ptr;
+ return (b[0] << 24) + (b[1] << 16) + (b[2] << 8) + (b[3]);
+}
+FORCEINLINE void WRITE_BE_UINT16(void *ptr, uint16 value) {
+ byte *b = (byte *)ptr;
+ b[0] = (byte)(value >> 8);
+ b[1] = (byte)(value >> 0);
+}
+FORCEINLINE void WRITE_BE_UINT32(void *ptr, uint32 value) {
+ byte *b = (byte *)ptr;
+ b[0] = (byte)(value >> 24);
+ b[1] = (byte)(value >> 16);
+ b[2] = (byte)(value >> 8);
+ b[3] = (byte)(value >> 0);
+}
+
+#if defined(__GNUC__)
+#define NORETURN_PRE
+#define NORETURN_POST __attribute__((__noreturn__))
+#elif defined(_MSC_VER)
+#define NORETURN_PRE _declspec(noreturn)
+#define NORETURN_POST
+#else
+#define NORETURN_PRE
+#define NORETURN_POST
+#endif
+
+
+/* File I/O */
+uint8 readByte(FILE *fp);
+uint16 readUint16BE(FILE *fp);
+uint16 readUint16LE(FILE *fp);
+uint32 readUint32BE(FILE *fp);
+uint32 readUint32LE(FILE *fp);
+void writeByte(FILE *fp, uint8 b);
+void writeUint16BE(FILE *fp, uint16 value);
+void writeUint16LE(FILE *fp, uint16 value);
+void writeUint32BE(FILE *fp, uint32 value);
+void writeUint32LE(FILE *fp, uint32 value);
+uint32 fileSize(FILE *fp);
+
+/* Misc stuff */
+void NORETURN_PRE error(const char *s, ...) NORETURN_POST;
+void warning(const char *s, ...);
+void debug(int level, const char *s, ...);
+void notice(const char *s, ...);
+
+struct Filename {
+ char _path[1024];
+
+ Filename(const char *path = "");
+ Filename(const Filename &path);
+ Filename& operator=(const Filename &fn);
+
+ void setFullPath(const char *path);
+ Filename *setFullName(const char *name);
+ void addExtension(const char *ext);
+ void setExtension(const char *ext);
+
+ bool hasExtension(const char *suffix) const;
+ bool empty() const;
+ bool equals(const Filename* other) const;
+
+ // Doesn't work
+ bool mkdir(int permission = 077);
+
+ const char *getFullPath() const;
+ const char *getFullName() const;
+ const char *getFullName(char *out) const;
+ const char *getPath(char *out) const;
+};
+
+inline bool operator==(const Filename &f1, const Filename &f2){
+ return f1.equals(&f2);
+}
+
+void displayHelp(const char *msg = NULL, const char *exename = NULL);
+void parseHelpArguments(const char * const argv[], int argc, const char *msg = NULL);
+bool parseOutputFileArguments(Filename *outputname, const char * const argv[], int argc, int start_arg);
+bool parseOutputDirectoryArguments(Filename *outputname, const char * const argv[], int argc, int start_arg);
+
+
+#endif
Property changes on: tools/trunk/engines/mohawk/util.h
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:svn-keywords
+ Date Rev Author URL Id
Added: svn:eol-style
+ native
Property changes on: tools/trunk/engines/mohawk/utils
___________________________________________________________________
Added: svn:ignore
+ .deps
Added: tools/trunk/engines/mohawk/utils/adpcm.cpp
===================================================================
--- tools/trunk/engines/mohawk/utils/adpcm.cpp (rev 0)
+++ tools/trunk/engines/mohawk/utils/adpcm.cpp 2010-01-14 00:15:57 UTC (rev 47296)
@@ -0,0 +1,354 @@
+/* Scumm Tools
+ * Copyright (C) 2004-2006 The ScummVM Team
+ *
+ * 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 2
+ * 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL: https://scummvm.svn.sourceforge.net/svnroot/scummvm/tools/branches/gsoc2009-gui/utils/adpcm.cpp $
+ * $Id: adpcm.cpp 40868 2009-05-24 15:19:28Z lordhoto $
+ *
+ */
+
+#include "adpcm.h"
+#include "util.h"
+
+namespace Audio {
+
+// TODO: Switch from a SeekableReadStream to a plain ReadStream. This requires
+// some internal refactoring but is definitely possible and will increase the
+// flexibility of this code.
+class ADPCMInputStream : public AudioStream {
+private:
+ Common::SeekableReadStream *_stream;
+ uint32 _endpos;
+ int _channels;
+ typesADPCM _type;
+ uint32 _blockAlign;
+ uint32 _blockPos;
+ int _blockLen;
+ int _rate;
+
+ struct ADPCMChannelStatus {
+ byte predictor;
+ int16 delta;
+ int16 coeff1;
+ int16 coeff2;
+ int16 sample1;
+ int16 sample2;
+ };
+
+ struct adpcmStatus {
+ // IMA
+ int32 last;
+ int32 stepIndex;
+
+ // MS ADPCM
+ ADPCMChannelStatus ch[2];
+ } _status;
+
+ int16 stepAdjust(byte);
+ int16 decodeOKI(byte);
+ int16 decodeMSIMA(byte);
+ int16 decodeMS(ADPCMChannelStatus *c, byte);
+
+public:
+ ADPCMInputStream(Common::SeekableReadStream *stream, uint32 size, typesADPCM type, int rate, int channels = 2, uint32 blockAlign = 0);
+ ~ADPCMInputStream() {};
+
+ int readBuffer(int16 *buffer, const int numSamples);
+ int readBufferOKI(int16 *buffer, const int numSamples);
+ int readBufferMSIMA1(int16 *buffer, const int numSamples);
+ int readBufferMSIMA2(int16 *buffer, const int numSamples);
+ int readBufferMS(int channels, int16 *buffer, const int numSamples);
+
+ bool endOfData() const { return (_stream->eos() || _stream->pos() >= _endpos); }
+ bool isStereo() const { return false; }
+ int getRate() const { return _rate; }
+};
+
+// Routines to convert 12 bit linear samples to the
+// Dialogic or Oki ADPCM coding format aka VOX.
+// See also <http://www.comptek.ru/telephony/tnotes/tt1-13.html>
+//
+// In addition, also MS IMA ADPCM is supported. See
+// <http://wiki.multimedia.cx/index.php?title=Microsoft_IMA_ADPCM>.
+
+ADPCMInputStream::ADPCMInputStream(Common::SeekableReadStream *stream, uint32 size, typesADPCM type, int rate, int channels, uint32 blockAlign)
+ : _stream(stream), _channels(channels), _type(type), _blockAlign(blockAlign), _rate(rate) {
+
+ _status.last = 0;
+ _status.stepIndex = 0;
+ memset(_status.ch, 0, sizeof(_status.ch));
+ _endpos = stream->pos() + size;
+ _blockPos = _blockLen = 0;
+
+ if (type == kADPCMMSIma && blockAlign == 0)
+ error("ADPCMInputStream(): blockAlign isn't specifiled for MS IMA ADPCM");
+ if (type == kADPCMMS && blockAlign == 0)
+ error("ADPCMInputStream(): blockAlign isn't specifiled for MS ADPCM");
+}
+
+int ADPCMInputStream::readBuffer(int16 *buffer, const int numSamples) {
+ switch (_type) {
+ case kADPCMOki:
+ return readBufferOKI(buffer, numSamples);
+ break;
+ case kADPCMMSIma:
+ if (_channels == 1)
+ return readBufferMSIMA1(buffer, numSamples);
+ else
+ return readBufferMSIMA2(buffer, numSamples);
+ break;
+ case kADPCMMS:
+ return readBufferMS(_channels, buffer, numSamples);
+ break;
+ default:
+ error("Unsupported ADPCM encoding");
+ break;
+ }
+ return 0;
+}
+
+int ADPCMInputStream::readBufferOKI(int16 *buffer, const int numSamples) {
+ int samples;
+ byte data;
+
+ assert(numSamples % 2 == 0);
+
+ for (samples = 0; samples < numSamples && !_stream->eos() && _stream->pos() < _endpos; samples += 2) {
+ data = _stream->readByte();
+ WRITE_LE_UINT16(buffer + samples, decodeOKI((data >> 4) & 0x0f));
+ WRITE_LE_UINT16(buffer + samples + 1, decodeOKI(data & 0x0f));
+ }
+ return samples;
+}
+
+
+int ADPCMInputStream::readBufferMSIMA1(int16 *buffer, const int numSamples) {
+ int samples;
+ byte data;
+
+ assert(numSamples % 2 == 0);
+
+ samples = 0;
+
+ while (samples < numSamples && !_stream->eos() && _stream->pos() < _endpos) {
+ if (_blockPos == _blockAlign) {
+ // read block header
+ _status.last = _stream->readSint16LE();
+ _status.stepIndex = _stream->readSint16LE();
+ _blockPos = 4;
+ }
+
+ for (; samples < numSamples && _blockPos < _blockAlign && !_stream->eos() && _stream->pos() < _endpos; samples += 2) {
+ data = _stream->readByte();
+ _blockPos++;
+ WRITE_LE_UINT16(buffer + samples, decodeMSIMA(data & 0x0f));
+ WRITE_LE_UINT16(buffer + samples + 1, decodeMSIMA((data >> 4) & 0x0f));
+ }
+ }
+ return samples;
+}
+
+
+// Microsoft as usual tries to implement it differently. This method
+// is used for stereo data.
+int ADPCMInputStream::readBufferMSIMA2(int16 *buffer, const int numSamples) {
+ int samples;
+ uint32 data;
+ int nibble;
+
+ for (samples = 0; samples < numSamples && !_stream->eos() && _stream->pos() < _endpos;) {
+ for (int channel = 0; channel < 2; channel++) {
+ data = _stream->readUint32LE();
+
+ for (nibble = 0; nibble < 8; nibble++) {
+ byte k = ((data & 0xf0000000) >> 28);
+ WRITE_LE_UINT16(buffer + samples + channel + nibble * 2, decodeMSIMA(k));
+ data <<= 4;
+ }
+ }
+ samples += 16;
+ }
+ return samples;
+}
+
+static const int MSADPCMAdaptCoeff1[] = {
+ 256, 512, 0, 192, 240, 460, 392
+};
+
+static const int MSADPCMAdaptCoeff2[] = {
+ 0, -256, 0, 64, 0, -208, -232
+};
+
+int ADPCMInputStream::readBufferMS(int channels, int16 *buffer, const int numSamples) {
+ int samples;
+ byte data;
+ int stereo = channels - 1; // We use it in index
+
+ samples = 0;
+
+ while (samples < numSamples && !_stream->eos() && _stream->pos() < _endpos) {
+ if (_blockPos == _blockAlign) {
+ // read block header
+ _status.ch[0].predictor = Common::CLIP(_stream->readByte(), (byte)0, (byte)6);
+ _status.ch[0].coeff1 = MSADPCMAdaptCoeff1[_status.ch[0].predictor];
+ _status.ch[0].coeff2 = MSADPCMAdaptCoeff2[_status.ch[0].predictor];
+ if (stereo) {
+ _status.ch[1].predictor = Common::CLIP(_stream->readByte(), (byte)0, (byte)6);
+ _status.ch[1].coeff1 = MSADPCMAdaptCoeff1[_status.ch[1].predictor];
+ _status.ch[1].coeff2 = MSADPCMAdaptCoeff2[_status.ch[1].predictor];
+ }
+
+ _status.ch[0].delta = _stream->readSint16LE();
+ if (stereo)
+ _status.ch[1].delta = _stream->readSint16LE();
+
+ buffer[samples++] = _status.ch[0].sample1 = _stream->readSint16LE();
+ if (stereo)
+ buffer[samples++] = _status.ch[1].sample1 = _stream->readSint16LE();
+
+ buffer[samples++] = _status.ch[0].sample2 = _stream->readSint16LE();
+ if (stereo)
+ buffer[samples++] = _status.ch[1].sample2 = _stream->readSint16LE();
+
+ _blockPos = channels * 7;
+ }
+
+
+ for (; samples < numSamples && _blockPos < _blockAlign && !_stream->eos() && _stream->pos() < _endpos; samples += 2) {
+ data = _stream->readByte();
+ _blockPos++;
+ WRITE_LE_UINT16(buffer + samples, decodeMS(&_status.ch[0], (data >> 4) & 0x0f));
+ WRITE_LE_UINT16(buffer + samples + 1, decodeMS(&_status.ch[stereo], data & 0x0f));
+ }
+ }
+
+ return samples;
+}
+
+
+// adjust the step for use on the next sample.
+int16 ADPCMInputStream::stepAdjust(byte code) {
+ static const int16 adjusts[] = {-1, -1, -1, -1, 2, 4, 6, 8};
+
+ return adjusts[code & 0x07];
+}
+
+static const int16 okiStepSize[49] = {
+ 16, 17, 19, 21, 23, 25, 28, 31,
+ 34, 37, 41, 45, 50, 55, 60, 66,
+ 73, 80, 88, 97, 107, 118, 130, 143,
+ 157, 173, 190, 209, 230, 253, 279, 307,
+ 337, 371, 408, 449, 494, 544, 598, 658,
+ 724, 796, 876, 963, 1060, 1166, 1282, 1411,
+ 1552
+};
+
+// Decode Linear to ADPCM
+int16 ADPCMInputStream::decodeOKI(byte code) {
+ int16 diff, E, samp;
+
+ E = (2 * (code & 0x7) + 1) * okiStepSize[_status.stepIndex] / 8;
+ diff = (code & 0x08) ? -E : E;
+ samp = _status.last + diff;
+
+ // Clip the values to +/- 2^11 (supposed to be 12 bits)
+ if (samp > 2048)
+ samp = 2048;
+ if (samp < -2048)
+ samp = -2048;
+
+ _status.last = samp;
+ _status.stepIndex += stepAdjust(code);
+ if (_status.stepIndex < 0)
+ _status.stepIndex = 0;
+ if (_status.stepIndex > ARRAYSIZE(okiStepSize) - 1)
+ _status.stepIndex = ARRAYSIZE(okiStepSize) - 1;
+
+ // * 16 effectively converts 12-bit input to 16-bit output
+ return samp * 16;
+}
+
+
+static const uint16 imaStepTable[89] = {
+ 7, 8, 9, 10, 11, 12, 13, 14,
+ 16, 17, 19, 21, 23, 25, 28, 31,
+ 34, 37, 41, 45, 50, 55, 60, 66,
+ 73, 80, 88, 97, 107, 118, 130, 143,
+ 157, 173, 190, 209, 230, 253, 279, 307,
+ 337, 371, 408, 449, 494, 544, 598, 658,
+ 724, 796, 876, 963, 1060, 1166, 1282, 1411,
+ 1552, 1707, 1878, 2066, 2272, 2499, 2749, 3024,
+ 3327, 3660, 4026, 4428, 4871, 5358, 5894, 6484,
+ 7132, 7845, 8630, 9493,10442,11487,12635,13899,
+ 15289,16818,18500,20350,22385,24623,27086,29794,
+ 32767
+};
+
+int16 ADPCMInputStream::decodeMSIMA(byte code) {
+ int32 diff, E, samp;
+
+ E = (2 * (code & 0x7) + 1) * imaStepTable[_status.stepIndex] / 8;
+ diff = (code & 0x08) ? -E : E;
+ samp = _status.last + diff;
+
+ if (samp < -0x8000)
+ samp = -0x8000;
+ else if (samp > 0x7fff)
+ samp = 0x7fff;
+
+ _status.last = samp;
+
+ _status.stepIndex += stepAdjust(code);
+ if (_status.stepIndex < 0)
+ _status.stepIndex = 0;
+ if (_status.stepIndex > ARRAYSIZE(imaStepTable) - 1)
+ _status.stepIndex = ARRAYSIZE(imaStepTable) - 1;
+
+ return samp;
+}
+
+static const int MSADPCMAdaptationTable[] = {
+ 230, 230, 230, 230, 307, 409, 512, 614,
+ 768, 614, 512, 409, 307, 230, 230, 230
+};
+
+
+int16 ADPCMInputStream::decodeMS(ADPCMChannelStatus *c, byte code) {
+ int32 predictor;
+
+ predictor = (((c->sample1) * (c->coeff1)) + ((c->sample2) * (c->coeff2))) / 256;
+ predictor += (signed)((code & 0x08) ? (code - 0x10) : (code)) * c->delta;
+
+ if (predictor < -0x8000)
+ predictor = -0x8000;
+ else if (predictor > 0x7fff)
+ predictor = 0x7fff;
+
+ c->sample2 = c->sample1;
+ c->sample1 = predictor;
+ c->delta = (MSADPCMAdaptationTable[(int)code] * c->delta) >> 8;
+
+ if (c->delta < 16)
+ c->delta = 16;
+
+ return (int16)predictor;
+}
+
+AudioStream *makeADPCMStream(Common::SeekableReadStream *stream, uint32 size, typesADPCM type, int rate, int channels, uint32 blockAlign) {
+ return new ADPCMInputStream(stream, size, type, rate, channels, blockAlign);
+}
+
+} // End of namespace Audio
Property changes on: tools/trunk/engines/mohawk/utils/adpcm.cpp
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:svn-keywords
+ Date Rev Author URL Id
Added: svn:eol-style
+ native
Added: tools/trunk/engines/mohawk/utils/adpcm.h
===================================================================
--- tools/trunk/engines/mohawk/utils/adpcm.h (rev 0)
+++ tools/trunk/engines/mohawk/utils/adpcm.h 2010-01-14 00:15:57 UTC (rev 47296)
@@ -0,0 +1,43 @@
+/* Scumm Tools
+ * Copyright (C) 2004-2006 The ScummVM Team
+ *
+ * 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 2
+ * 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL: https://scummvm.svn.sourceforge.net/svnroot/scummvm/tools/branches/gsoc2009-gui/utils/adpcm.h $
+ * $Id: adpcm.h 23138 2006-06-15 15:44:06Z h00ligan $
+ *
+ */
+
+#ifndef SOUND_ADPCM_H
+#define SOUND_ADPCM_H
+
+#include "audiostream.h"
+#include "stream.h"
+
+namespace Audio {
+
+class AudioStream;
+
+enum typesADPCM {
+ kADPCMOki,
+ kADPCMMSIma,
+ kADPCMMS
+};
+
+AudioStream *makeADPCMStream(Common::SeekableReadStream *stream, uint32 size, typesADPCM type, int rate = 22050, int channels = 2, uint32 blockAlign = 0);
+
+} // End of namespace Audio
+
+#endif
Property changes on: tools/trunk/engines/mohawk/utils/adpcm.h
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:svn-keywords
+ Date Rev Author URL Id
Added: svn:eol-style
+ native
Added: tools/trunk/engines/mohawk/utils/algorithm.h
===================================================================
--- tools/trunk/engines/mohawk/utils/algorithm.h (rev 0)
+++ tools/trunk/engines/mohawk/utils/algorithm.h 2010-01-14 00:15:57 UTC (rev 47296)
@@ -0,0 +1,201 @@
+/* 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 2
+ * 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ */
+
+#ifndef COMMON_ALGORITHM_H
+#define COMMON_ALGORITHM_H
+
+#include "../util.h"
+
+namespace Common {
+
+/**
+ * Copies data from the range [first, last) to [dst, dst + (last - first)).
+ * It requires the range [dst, dst + (last - first)) to be valid.
+ * It also requires dst not to be in the range [first, last).
+ */
+template<class In, class Out>
+Out copy(In first, In last, Out dst) {
+ while (first != last)
+ *dst++ = *first++;
+ return dst;
+}
+
+/**
+ * Copies data from the range [first, last) to [dst - (last - first), dst).
+ * It requires the range [dst - (last - first), dst) to be valid.
+ * It also requires dst not to be in the range [first, last).
+ *
+ * Unlike copy copy_backward copies the data from the end to the beginning.
+ */
+template<class In, class Out>
+Out copy_backward(In first, In last, Out dst) {
+ while (first != last)
+ *--dst = *--last;
+ return dst;
+}
+
+/**
+ * Copies data from the range [first, last) to [dst, dst + (last - first)).
+ * It requires the range [dst, dst + (last - first)) to be valid.
+ * It also requires dst not to be in the range [first, last).
+ *
+ * Unlike copy or copy_backward it does not copy all data. It only copies
+ * a data element when operator() of the op parameter returns true for the
+ * passed data element.
+ */
+template<class In, class Out, class Op>
+Out copy_if(In first, In last, Out dst, Op op) {
+ while (first != last) {
+ if (op(*first))
+ *dst++ = *first;
+ ++first;
+ }
+ return dst;
+}
+
+// Our 'specialized' 'set_to' template for char, signed char and unsigned char arrays.
+// Since C++ doesn't support partial specialized template functions (currently) we
+// are going this way...
+// With this we assure the usage of memset for those, which should be
+// faster than a simple loop like for the generic 'set_to'.
+template<class Value>
+signed char *set_to(signed char *first, signed char *last, Value val) {
+ memset(first, (val & 0xFF), last - first);
+ return last;
+}
+
+template<class Value>
+unsigned char *set_to(unsigned char *first, unsigned char *last, Value val) {
+ memset(first, (val & 0xFF), last - first);
+ return last;
+}
+
+template<class Value>
+char *set_to(char *first, char *last, Value val) {
+ memset(first, (val & 0xFF), last - first);
+ return last;
+}
+
+/**
+ * Sets all elements in the range [first, last) to val.
+ */
+template<class In, class Value>
+In set_to(In first, In last, Value val) {
+ while (first != last)
+ *first++ = val;
+ return first;
+}
+
+/**
+ * Finds the first data value in the range [first, last) matching v.
+ * For data comperance it uses operator == of the data elements.
+ */
+template<class In, class T>
+In find(In first, In last, const T &v) {
+ while (first != last) {
+ if (*first == v)
+ return first;
+ ++first;
+ }
+ return last;
+}
+
+/**
+ * Finds the first data value in the range [first, last) for which
+ * the specified predicate p returns true.
+ */
+template<class In, class Pred>
+In find_if(In first, In last, Pred p) {
+ while (first != last) {
+ if (p(*first))
+ return first;
+ ++first;
+ }
+ return last;
+}
+
+/**
+ * Applies the function f on all elements of the range [first, last).
+ * The processing order is from beginning to end.
+ */
+template<class In, class Op>
+Op for_each(In first, In last, Op f) {
+ while (first != last) f(*first++);
+ return f;
+}
+
+/**
+ * Simple sort function, modeled after std::sort.
+ * Use it like this: sort(container.begin(), container.end()).
+ * Also works on plain old i.e. int arrays etc. For comperance
+ * operator < is used.
+ */
+template<class T>
+void sort(T first, T last) {
+ if (first == last)
+ return;
+
+ // Simple selection sort
+ T i(first);
+ for (; i != last; ++i) {
+ T minElem(i);
+ T j(i);
+ ++j;
+ for (; j != last; ++j)
+ if (*j < *minElem)
+ minElem = j;
+ if (minElem != i)
+ SWAP(*minElem, *i);
+ }
+}
+
+/**
+ * Simple sort function, modeled after std::sort.
+ * It compares data with the given comparator object comp.
+ *
+ * Note: Using this with: Common::Less from common/func.h
+ * will give the same results as the plain sort function.
+ */
+template<class T, class StrictWeakOrdering>
+void sort(T first, T last, StrictWeakOrdering comp) {
+ if (first == last)
+ return;
+
+ // Simple selection sort
+ T i(first);
+ for (; i != last; ++i) {
+ T minElem(i);
+ T j(i);
+ ++j;
+ for (; j != last; ++j)
+ if (comp(*j, *minElem))
+ minElem = j;
+ if (minElem != i)
+ SWAP(*minElem, *i);
+ }
+}
+
+} // End of namespace Common
+
+#endif
Property changes on: tools/trunk/engines/mohawk/utils/algorithm.h
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:svn-keywords
+ Date Rev Author URL Id
Added: svn:eol-style
+ native
Added: tools/trunk/engines/mohawk/utils/array.h
===================================================================
--- tools/trunk/engines/mohawk/utils/array.h (rev 0)
+++ tools/trunk/engines/mohawk/utils/array.h 2010-01-14 00:15:57 UTC (rev 47296)
@@ -0,0 +1,182 @@
+/* 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 2
+ * 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ */
+
+#ifndef COMMON_ARRAY_H
+#define COMMON_ARRAY_H
+
+#include "utils/algorithm.h"
+
+namespace Common {
+
+template<class T>
+class Array {
+protected:
+ uint _capacity;
+ uint _size;
+ T *_storage;
+
+public:
+ typedef T *iterator;
+ typedef const T *const_iterator;
+
+ typedef T value_type;
+
+public:
+ Array() : _capacity(0), _size(0), _storage(0) {}
+ Array(const Array<T> &array) : _capacity(0), _size(0), _storage(0) {
+ _size = array._size;
+ _capacity = _size + 32;
+ _storage = new T[_capacity];
+ copy(array._storage, array._storage + _size, _storage);
+ }
+
+ ~Array() {
+ delete[] _storage;
+ }
+
+ void push_back(const T &element) {
+ ensureCapacity(_size + 1);
+ _storage[_size++] = element;
+ }
+
+ void push_back(const Array<T> &array) {
+ ensureCapacity(_size + array._size);
+ copy(array._storage, array._storage + array._size, _storage + _size);
+ _size += array._size;
+ }
+
+ void insert_at(int idx, const T &element) {
+ assert(idx >= 0 && (uint)idx <= _size);
+ ensureCapacity(_size + 1);
+ copy_backward(_storage + idx, _storage + _size, _storage + _size + 1);
+ _storage[idx] = element;
+ _size++;
+ }
+
+ T remove_at(int idx) {
+ assert(idx >= 0 && (uint)idx < _size);
+ T tmp = _storage[idx];
+ copy(_storage + idx + 1, _storage + _size, _storage + idx);
+ _size--;
+ return tmp;
+ }
+
+ // TODO: insert, remove, ...
+
+ T& operator[](int idx) {
+ assert(idx >= 0 && (uint)idx < _size);
+ return _storage[idx];
+ }
+
+ const T& operator[](int idx) const {
+ assert(idx >= 0 && (uint)idx < _size);
+ return _storage[idx];
+ }
+
+ Array<T>& operator=(const Array<T> &array) {
+ if (this == &array)
+ return *this;
+
+ delete[] _storage;
+ _size = array._size;
+ _capacity = _size + 32;
+ _storage = new T[_capacity];
+ copy(array._storage, array._storage + _size, _storage);
+
+ return *this;
+ }
+
+ uint size() const {
+ return _size;
+ }
+
+ void clear() {
+ delete[] _storage;
+ _storage = 0;
+ _size = 0;
+ _capacity = 0;
+ }
+
+ bool empty() const {
+ return (_size == 0);
+ }
+
+
+ iterator begin() {
+ return _storage;
+ }
+
+ iterator end() {
+ return _storage + _size;
+ }
+
+ const_iterator begin() const {
+ return _storage;
+ }
+
+ const_iterator end() const {
+ return _storage + _size;
+ }
+
+ void reserve(uint newCapacity) {
+ if (newCapacity <= _capacity)
+ return;
+
+ T *old_storage = _storage;
+ _capacity = newCapacity;
+ _storage = new T[newCapacity];
+
+ if (old_storage) {
+ // Copy old data
+ copy(old_storage, old_storage + _size, _storage);
+ delete[] old_storage;
+ }
+ }
+
+ void resize(uint newSize) {
+ if (newSize == _size)
+ return;
+
+ T *old_storage = _storage;
+ _capacity = newSize;
+ _storage = new T[newSize];
+ if (old_storage) {
+ // Copy old data
+ int cnt = (_size < newSize ? _size : newSize);
+ copy(old_storage, old_storage + cnt, _storage);
+ delete[] old_storage;
+ }
+ _size = newSize;
+ }
+
+protected:
+ void ensureCapacity(uint len) {
+ if (len >= _capacity)
+ reserve(len + 32);
+ }
+};
+
+} // End of namespace Common
+
+#endif
Property changes on: tools/trunk/engines/mohawk/utils/array.h
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:svn-keywords
+ Date Rev Author URL Id
Added: svn:eol-style
+ native
Added: tools/trunk/engines/mohawk/utils/audiostream.cpp
===================================================================
--- tools/trunk/engines/mohawk/utils/audiostream.cpp (rev 0)
+++ tools/trunk/engines/mohawk/utils/audiostream.cpp 2010-01-14 00:15:57 UTC (rev 47296)
@@ -0,0 +1,162 @@
+/* Scumm Tools
+ * Copyright (C) 2004-2006 The ScummVM Team
+ *
+ * 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 2
+ * 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL: https://scummvm.svn.sourceforge.net/svnroot/scummvm/tools/branches/gsoc2009-gui/utils/audiostream.cpp $
+ * $Id: audiostream.cpp 23138 2006-06-15 15:44:06Z h00ligan $
+ *
+ */
+
+#include "audiostream.h"
+
+
+namespace Audio {
+
+struct StreamFileFormat {
+ /** Decodername */
+ const char* decoderName;
+ const char* fileExtension;
+ /**
+ * Pointer to a function which tries to open a file of type StreamFormat.
+ * Return NULL in case of an error (invalid/nonexisting file).
+ */
+ AudioStream* (*openStreamFile)(FILE *file, uint32 size);
+};
+
+
+#pragma mark -
+#pragma mark --- LinearMemoryStream ---
+#pragma mark -
+
+
+/**
+ * A simple raw audio stream, purely memory based. It operates on a single
+ * block of data, which is passed to it upon creation.
+ * Optionally supports looping the sound.
+ *
+ * Design note: This code tries to be as optimized as possible (without
+ * resorting to assembly, that is). To this end, it is written as a template
+ * class. This way the compiler can actually create optimized code for each
+ * special code. This results in a total of 12 versions of the code being
+ * generated.
+ */
+template<bool stereo, bool is16Bit, bool isUnsigned, bool isLE>
+class LinearMemoryStream : public AudioStream {
+protected:
+ const byte *_ptr;
+ const byte *_end;
+ const byte *_loopPtr;
+ const byte *_loopEnd;
+ const int _rate;
+ const byte *_origPtr;
+
+ inline bool eosIntern() const { return _ptr >= _end; };
+public:
+ LinearMemoryStream(int rate, const byte *ptr, uint32 len, uint32 loopOffset, uint32 loopLen, bool autoFreeMemory)
+ : _ptr(ptr), _end(ptr+len), _loopPtr(0), _loopEnd(0), _rate(rate) {
+
+ // Verify the buffer sizes are sane
+ if (is16Bit && stereo)
+ assert((len & 3) == 0 && (loopLen & 3) == 0);
+ else if (is16Bit || stereo)
+ assert((len & 1) == 0 && (loopLen & 1) == 0);
+
+ if (loopLen) {
+ _loopPtr = _ptr + loopOffset;
+ _loopEnd = _loopPtr + loopLen;
+ }
+ if (stereo) // Stereo requires even sized data
+ assert(len % 2 == 0);
+
+ _origPtr = autoFreeMemory ? ptr : 0;
+ }
+ ~LinearMemoryStream() {
+ free(const_cast<byte *>(_origPtr));
+ }
+ int readBuffer(int16 *buffer, const int numSamples);
+
+ bool isStereo() const { return stereo; }
+ bool endOfData() const { return eosIntern(); }
+
+ int getRate() const { return _rate; }
+};
+
+template<bool stereo, bool is16Bit, bool isUnsigned, bool isLE>
+int LinearMemoryStream<stereo, is16Bit, isUnsigned, isLE>::readBuffer(int16 *buffer, const int numSamples) {
+ int samples = 0;
+ while (samples < numSamples && !eosIntern()) {
+ const int len = Common::MIN(numSamples, samples + (int)(_end - _ptr) / (is16Bit ? 2 : 1));
+ while (samples < len) {
+ *buffer++ = READ_ENDIAN_SAMPLE(is16Bit, isUnsigned, _ptr, isLE);
+ _ptr += (is16Bit ? 2 : 1);
+ samples++;
+ }
+ // Loop, if looping was specified
+ if (_loopPtr && eosIntern()) {
+ _ptr = _loopPtr;
+ _end = _loopEnd;
+ }
+ }
+ return samples;
+}
+
+
+#pragma mark -
+#pragma mark --- Input stream factory ---
+#pragma mark -
+
+/* In the following, we use preprocessor / macro tricks to simplify the code
+ * which instantiates the input streams. We used to use template functions for
+ * this, but MSVC6 / EVC 3-4 (used for WinCE builds) are extremely buggy when it
+ * comes to this feature of C++... so as a compromise we use macros to cut down
+ * on the (source) code duplication a bit.
+ * So while normally macro tricks are said to make maintenance harder, in this
+ * particular case it should actually help it :-)
+ */
+
+#define MAKE_LINEAR(STEREO, UNSIGNED) \
+ if (is16Bit) { \
+ if (isLE) \
+ return new LinearMemoryStream<STEREO, true, UNSIGNED, true>(rate, ptr, len, loopOffset, loopLen, autoFree); \
+ else \
+ return new LinearMemoryStream<STEREO, true, UNSIGNED, false>(rate, ptr, len, loopOffset, loopLen, autoFree); \
+ } else \
+ return new LinearMemoryStream<STEREO, false, UNSIGNED, false>(rate, ptr, len, loopOffset, loopLen, autoFree)
+
+AudioStream *makeLinearInputStream(int rate, byte flags, const byte *ptr, uint32 len, uint32 loopOffset, uint32 loopLen) {
+ const bool isStereo = (flags & Audio::Mixer::FLAG_STEREO) != 0;
+ const bool is16Bit = (flags & Audio::Mixer::FLAG_16BITS) != 0;
+ const bool isUnsigned = (flags & Audio::Mixer::FLAG_UNSIGNED) != 0;
+ const bool isLE = (flags & Audio::Mixer::FLAG_LITTLE_ENDIAN) != 0;
+ const bool autoFree = (flags & Audio::Mixer::FLAG_AUTOFREE) != 0;
+
+ if (isStereo) {
+ if (isUnsigned) {
+ MAKE_LINEAR(true, true);
+ } else {
+ MAKE_LINEAR(true, false);
+ }
+ } else {
+ if (isUnsigned) {
+ MAKE_LINEAR(false, true);
+ } else {
+ MAKE_LINEAR(false, false);
+ }
+ }
+}
+
+
+} // End of namespace Audio
Property changes on: tools/trunk/engines/mohawk/utils/audiostream.cpp
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:svn-keywords
+ Date Rev Author URL Id
Added: svn:eol-style
+ native
Added: tools/trunk/engines/mohawk/utils/audiostream.h
===================================================================
--- tools/trunk/engines/mohawk/utils/audiostream.h (rev 0)
+++ tools/trunk/engines/mohawk/utils/audiostream.h 2010-01-14 00:15:57 UTC (rev 47296)
@@ -0,0 +1,153 @@
+/* Scumm Tools
+ * Copyright (C) 2004-2006 The ScummVM Team
+ *
+ * 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 2
+ * 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL: https://scummvm.svn.sourceforge.net/svnroot/scummvm/tools/branches/gsoc2009-gui/utils/audiostream.h $
+ * $Id: audiostream.h 23138 2006-06-15 15:44:06Z h00ligan $
+ *
+ */
+
+#ifndef SOUND_AUDIOSTREAM_H
+#define SOUND_AUDIOSTREAM_H
+
+#include "../util.h"
+#include "util.h"
+
+namespace Audio {
+
+class Mixer {
+public:
+ enum {
+ /** unsigned samples (default: signed) */
+ FLAG_UNSIGNED = 1 << 0,
+
+ /** sound is 16 bits wide (default: 8bit) */
+ FLAG_16BITS = 1 << 1,
+
+ /** sample is little endian (default: big endian) */
+ FLAG_LITTLE_ENDIAN = 1 << 2,
+
+ /** sound is in stereo (default: mono) */
+ FLAG_STEREO = 1 << 3,
+
+ /** reverse the left and right stereo channel */
+ FLAG_REVERSE_STEREO = 1 << 4,
+
+ /** sound buffer is freed automagically at the end of playing */
+ FLAG_AUTOFREE = 1 << 5,
+
+ /** loop the audio */
+ FLAG_LOOP = 1 << 6
+ };
+};
+
+/**
+ * Generic input stream for the resampling code.
+ */
+class AudioStream {
+public:
+ virtual ~AudioStream() {}
+
+ /**
+ * Fill the given buffer with up to numSamples samples.
+ * Returns the actual number of samples read, or -1 if
+ * a critical error occured (note: you *must* check if
+ * this value is less than what you requested, this can
+ * happen when the stream is fully used up).
+ *
+ * Data has to be in native endianess, 16 bit per sample, signed.
+ * For stereo stream, buffer will be filled with interleaved
+ * left and right channel samples, starting with a left sample.
+ * Furthermore, the samples in the left and right are summed up.
+ * So if you request 4 samples from a stereo stream, you will get
+ * a total of two left channel and two right channel samples.
+ */
+ virtual int readBuffer(int16 *buffer, const int numSamples) = 0;
+
+ /** Is this a stereo stream? */
+ virtual bool isStereo() const = 0;
+
+ /**
+ * End of data reached? If this returns true, it means that at this
+ * time there is no data available in the stream. However there may be
+ * more data in the future.
+ * This is used by e.g. a rate converter to decide whether to keep on
+ * converting data or stop.
+ */
+ virtual bool endOfData() const = 0;
+
+ /**
+ * End of stream reached? If this returns true, it means that all data
+ * in this stream is used up and no additional data will appear in it
+ * in the future.
+ * This is used by the mixer to decide whether a given stream shall be
+ * removed from the list of active streams (and thus be destroyed).
+ * By default this maps to endOfData()
+ */
+ virtual bool endOfStream() const { return endOfData(); }
+
+ /** Sample rate of the stream. */
+ virtual int getRate() const = 0;
+};
+
+/**
+ * A simple AudioStream which represents a 'silent' stream,
+ * containing the specified number of zero samples.
+ */
+class ZeroInputStream : public AudioStream {
+private:
+ int _len;
+public:
+ ZeroInputStream(uint32 len) : _len(len) { }
+ int readBuffer(int16 *buffer, const int numSamples) {
+ int samples = Common::MIN(_len, numSamples);
+ memset(buffer, 0, samples * 2);
+ _len -= samples;
+ return samples;
+ }
+ bool isStereo() const { return false; }
+ bool eos() const { return _len <= 0; }
+
+ int getRate() const { return -1; }
+};
+
+AudioStream *makeLinearInputStream(int rate, byte flags, const byte *ptr, uint32 len, uint32 loopOffset, uint32 loopLen);
+
+/**
+ * An audio stream to which additional data can be appended on-the-fly.
+ * Used by SMUSH, iMuseDigital, and the Kyrandia 3 VQA player.
+ */
+class AppendableAudioStream : public Audio::AudioStream {
+public:
+ virtual void append(const byte *data, uint32 len) = 0;
+ virtual void finish() = 0;
+};
+
+AppendableAudioStream *makeAppendableAudioStream(int rate, byte _flags, uint32 len);
+
+
+// This used to be an inline template function, but
+// buggy template function handling in MSVC6 forced
+// us to go with the macro approach. So far this is
+// the only template function that MSVC6 seemed to
+// compile incorrectly. Knock on wood.
+#define READ_ENDIAN_SAMPLE(is16Bit, isUnsigned, ptr, isLE) \
+ ((is16Bit ? (isLE ? READ_LE_UINT16(ptr) : READ_BE_UINT16(ptr)) : (*ptr << 8)) ^ (isUnsigned ? 0x8000 : 0))
+
+
+} // End of namespace Audio
+
+#endif
Property changes on: tools/trunk/engines/mohawk/utils/audiostream.h
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:svn-keywords
+ Date Rev Author URL Id
Added: svn:eol-style
+ native
Added: tools/trunk/engines/mohawk/utils/file.cpp
===================================================================
--- tools/trunk/engines/mohawk/utils/file.cpp (rev 0)
+++ tools/trunk/engines/mohawk/utils/file.cpp 2010-01-14 00:15:57 UTC (rev 47296)
@@ -0,0 +1,116 @@
+/* Scumm Tools
+ * Copyright (C) 2004-2006 The ScummVM Team
+ *
+ * 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 2
+ * 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL: https://scummvm.svn.sourceforge.net/svnroot/scummvm/tools/branches/gsoc2009-gui/utils/file.cpp $
+ * $Id: file.cpp 23138 2006-06-15 15:44:06Z h00ligan $
+ *
+ */
+
+#include "file.h"
+
+
+namespace Common {
+
+
+File::File(FILE*file)
+ : _handle(file), _ioFailed(false) {
+}
+
+
+File::~File() {
+ close();
+}
+
+void File::close() {
+ _handle = NULL;
+}
+
+bool File::isOpen() const {
+ return _handle != NULL;
+}
+
+bool File::ioFailed() const {
+ return _ioFailed != 0;
+}
+
+void File::clearIOFailed() {
+ _ioFailed = false;
+}
+
+bool File::eof() const {
+ if (_handle == NULL) {
+ error("File::eof: File is not open!");
+ return false;
+ }
+
+ return feof(_handle) != 0;
+}
+
+uint32 File::pos() const {
+ if (_handle == NULL) {
+ error("File::pos: File is not open!");
+ return 0;
+ }
+
+ return ftell(_handle);
+}
+
+uint32 File::size() const {
+ if (_handle == NULL) {
+ error("File::size: File is not open!");
+ return 0;
+ }
+
+ uint32 oldPos = ftell(_handle);
+ fseek(_handle, 0, SEEK_END);
+ uint32 length = ftell(_handle);
+ fseek(_handle, oldPos, SEEK_SET);
+
+ return length;
+}
+
+void File::seek(int32 offs, int whence) {
+ if (_handle == NULL) {
+ error("File::seek: File is not open!");
+ return;
+ }
+
+ if (fseek(_handle, offs, whence) != 0)
+ clearerr(_handle);
+}
+
+uint32 File::read(void *ptr, uint32 len) {
+ byte *ptr2 = (byte *)ptr;
+ size_t real_len;
+
+ if (_handle == NULL) {
+ error("File::read: File is not open!");
+ return 0;
+ }
+
+ if (len == 0)
+ return 0;
+
+ real_len = fread(ptr2, 1, len, _handle);
+ if (real_len < len) {
+ _ioFailed = true;
+ }
+
+ return (uint32)real_len;
+}
+
+} // End of namespace Common
Property changes on: tools/trunk/engines/mohawk/utils/file.cpp
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:svn-keywords
+ Date Rev Author URL Id
Added: svn:eol-style
+ native
Added: tools/trunk/engines/mohawk/utils/file.h
===================================================================
--- tools/trunk/engines/mohawk/utils/file.h (rev 0)
+++ tools/trunk/engines/mohawk/utils/file.h 2010-01-14 00:15:57 UTC (rev 47296)
@@ -0,0 +1,65 @@
+/* Scumm Tools
+ * Copyright (C) 2004-2006 The ScummVM Team
+ *
+ * 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 2
+ * 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL: https://scummvm.svn.sourceforge.net/svnroot/scummvm/tools/branches/gsoc2009-gui/utils/file.h $
+ * $Id: file.h 23138 2006-06-15 15:44:06Z h00ligan $
+ *
+ */
+
+#ifndef COMMON_FILE_H
+#define COMMON_FILE_H
+
+#include "stream.h"
+
+namespace Common {
+
+class File : public SeekableReadStream {
+protected:
+ /** POSIX file handle to the actual file; 0 if no file is open. */
+ FILE *_handle;
+
+ /** Status flag which tells about recent I/O failures. */
+ bool _ioFailed;
+
+private:
+ // Disallow copying File objects. There is not strict reason for this,
+ // except that so far we never had real need for such a feature, and
+ // code that accidentally copied File objects tended to break in strange
+ // ways.
+ File(const File &f);
+ File &operator =(const File &f);
+
+public:
+
+ File(FILE*file);
+ virtual ~File();
+
+ virtual void close();
+ bool isOpen() const;
+ bool ioFailed() const;
+ void clearIOFailed();
+ bool eos() const { return eof(); }
+ bool eof() const;
+ uint32 pos() const;
+ uint32 size() const;
+ void seek(int32 offs, int whence = SEEK_SET);
+ uint32 read(void *dataPtr, uint32 dataSize);
+};
+
+} // End of namespace Common
+
+#endif
Property changes on: tools/trunk/engines/mohawk/utils/file.h
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:svn-keywords
+ Date Rev Author URL Id
Added: svn:eol-style
+ native
Added: tools/trunk/engines/mohawk/utils/md5.cpp
===================================================================
--- tools/trunk/engines/mohawk/utils/md5.cpp (rev 0)
+++ tools/trunk/engines/mohawk/utils/md5.cpp 2010-01-14 00:15:57 UTC (rev 47296)
@@ -0,0 +1,265 @@
+/* Scumm Tools
+ * Copyright (C) 2004-2006 The ScummVM Team
+ *
+ * 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 2
+ * 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL: https://scummvm.svn.sourceforge.net/svnroot/scummvm/tools/branches/gsoc2009-gui/utils/md5.cpp $
+ * $Id: md5.cpp 40868 2009-05-24 15:19:28Z lordhoto $
+ *
+ */
+
+#include "md5.h"
+
+namespace Common {
+
+#define GET_UINT32(n, b, i) (n) = READ_LE_UINT32(b + i)
+#define PUT_UINT32(n, b, i) WRITE_LE_UINT32(b + i, n)
+
+void md5_starts(md5_context *ctx) {
+ ctx->total[0] = 0;
+ ctx->total[1] = 0;
+
+ ctx->state[0] = 0x67452301;
+ ctx->state[1] = 0xEFCDAB89;
+ ctx->state[2] = 0x98BADCFE;
+ ctx->state[3] = 0x10325476;
+}
+
+static void md5_process(md5_context *ctx, const uint8 data[64]) {
+ uint32 X[16], A, B, C, D;
+
+ GET_UINT32(X[0], data, 0);
+ GET_UINT32(X[1], data, 4);
+ GET_UINT32(X[2], data, 8);
+ GET_UINT32(X[3], data, 12);
+ GET_UINT32(X[4], data, 16);
+ GET_UINT32(X[5], data, 20);
+ GET_UINT32(X[6], data, 24);
+ GET_UINT32(X[7], data, 28);
+ GET_UINT32(X[8], data, 32);
+ GET_UINT32(X[9], data, 36);
+ GET_UINT32(X[10], data, 40);
+ GET_UINT32(X[11], data, 44);
+ GET_UINT32(X[12], data, 48);
+ GET_UINT32(X[13], data, 52);
+ GET_UINT32(X[14], data, 56);
+ GET_UINT32(X[15], data, 60);
+
+#define S(x, n) ((x << n) | ((x & 0xFFFFFFFF) >> (32 - n)))
+
+#define P(a, b, c, d, k, s, t) \
+{ \
+ a += F(b,c,d) + X[k] + t; a = S(a,s) + b; \
+}
+
+ A = ctx->state[0];
+ B = ctx->state[1];
+ C = ctx->state[2];
+ D = ctx->state[3];
+
+#define F(x, y, z) (z ^ (x & (y ^ z)))
+
+ P(A, B, C, D, 0, 7, 0xD76AA478);
+ P(D, A, B, C, 1, 12, 0xE8C7B756);
+ P(C, D, A, B, 2, 17, 0x242070DB);
+ P(B, C, D, A, 3, 22, 0xC1BDCEEE);
+ P(A, B, C, D, 4, 7, 0xF57C0FAF);
+ P(D, A, B, C, 5, 12, 0x4787C62A);
+ P(C, D, A, B, 6, 17, 0xA8304613);
+ P(B, C, D, A, 7, 22, 0xFD469501);
+ P(A, B, C, D, 8, 7, 0x698098D8);
+ P(D, A, B, C, 9, 12, 0x8B44F7AF);
+ P(C, D, A, B, 10, 17, 0xFFFF5BB1);
+ P(B, C, D, A, 11, 22, 0x895CD7BE);
+ P(A, B, C, D, 12, 7, 0x6B901122);
+ P(D, A, B, C, 13, 12, 0xFD987193);
+ P(C, D, A, B, 14, 17, 0xA679438E);
+ P(B, C, D, A, 15, 22, 0x49B40821);
+
+#undef F
+
+#define F(x, y, z) (y ^ (z & (x ^ y)))
+
+ P(A, B, C, D, 1, 5, 0xF61E2562);
+ P(D, A, B, C, 6, 9, 0xC040B340);
+ P(C, D, A, B, 11, 14, 0x265E5A51);
+ P(B, C, D, A, 0, 20, 0xE9B6C7AA);
+ P(A, B, C, D, 5, 5, 0xD62F105D);
+ P(D, A, B, C, 10, 9, 0x02441453);
+ P(C, D, A, B, 15, 14, 0xD8A1E681);
+ P(B, C, D, A, 4, 20, 0xE7D3FBC8);
+ P(A, B, C, D, 9, 5, 0x21E1CDE6);
+ P(D, A, B, C, 14, 9, 0xC33707D6);
+ P(C, D, A, B, 3, 14, 0xF4D50D87);
+ P(B, C, D, A, 8, 20, 0x455A14ED);
+ P(A, B, C, D, 13, 5, 0xA9E3E905);
+ P(D, A, B, C, 2, 9, 0xFCEFA3F8);
+ P(C, D, A, B, 7, 14, 0x676F02D9);
+ P(B, C, D, A, 12, 20, 0x8D2A4C8A);
+
+#undef F
+
+#define F(x, y, z) (x ^ y ^ z)
+
+ P(A, B, C, D, 5, 4, 0xFFFA3942);
+ P(D, A, B, C, 8, 11, 0x8771F681);
+ P(C, D, A, B, 11, 16, 0x6D9D6122);
+ P(B, C, D, A, 14, 23, 0xFDE5380C);
+ P(A, B, C, D, 1, 4, 0xA4BEEA44);
+ P(D, A, B, C, 4, 11, 0x4BDECFA9);
+ P(C, D, A, B, 7, 16, 0xF6BB4B60);
+ P(B, C, D, A, 10, 23, 0xBEBFBC70);
+ P(A, B, C, D, 13, 4, 0x289B7EC6);
+ P(D, A, B, C, 0, 11, 0xEAA127FA);
+ P(C, D, A, B, 3, 16, 0xD4EF3085);
+ P(B, C, D, A, 6, 23, 0x04881D05);
+ P(A, B, C, D, 9, 4, 0xD9D4D039);
+ P(D, A, B, C, 12, 11, 0xE6DB99E5);
+ P(C, D, A, B, 15, 16, 0x1FA27CF8);
+ P(B, C, D, A, 2, 23, 0xC4AC5665);
+
+#undef F
+
+#define F(x, y, z) (y ^ (x | ~z))
+
+ P(A, B, C, D, 0, 6, 0xF4292244);
+ P(D, A, B, C, 7, 10, 0x432AFF97);
+ P(C, D, A, B, 14, 15, 0xAB9423A7);
+ P(B, C, D, A, 5, 21, 0xFC93A039);
+ P(A, B, C, D, 12, 6, 0x655B59C3);
+ P(D, A, B, C, 3, 10, 0x8F0CCC92);
+ P(C, D, A, B, 10, 15, 0xFFEFF47D);
+ P(B, C, D, A, 1, 21, 0x85845DD1);
+ P(A, B, C, D, 8, 6, 0x6FA87E4F);
+ P(D, A, B, C, 15, 10, 0xFE2CE6E0);
+ P(C, D, A, B, 6, 15, 0xA3014314);
+ P(B, C, D, A, 13, 21, 0x4E0811A1);
+ P(A, B, C, D, 4, 6, 0xF7537E82);
+ P(D, A, B, C, 11, 10, 0xBD3AF235);
+ P(C, D, A, B, 2, 15, 0x2AD7D2BB);
+ P(B, C, D, A, 9, 21, 0xEB86D391);
+
+#undef F
+
+ ctx->state[0] += A;
+ ctx->state[1] += B;
+ ctx->state[2] += C;
+ ctx->state[3] += D;
+}
+
+void md5_update(md5_context *ctx, const uint8 *input, uint32 length) {
+ uint32 left, fill;
+
+ if (!length)
+ return;
+
+ left = ctx->total[0] & 0x3F;
+ fill = 64 - left;
+
+ ctx->total[0] += length;
+ ctx->total[0] &= 0xFFFFFFFF;
+
+ if (ctx->total[0] < length)
+ ctx->total[1]++;
+
+ if (left && length >= fill) {
+ memcpy((void *)(ctx->buffer + left), (const void *)input, fill);
+ md5_process(ctx, ctx->buffer);
+ length -= fill;
+ input += fill;
+ left = 0;
+ }
+
+ while (length >= 64) {
+ md5_process(ctx, input);
+ length -= 64;
+ input += 64;
+ }
+
+ if (length) {
+ memcpy((void *)(ctx->buffer + left), (const void *)input, length);
+ }
+}
+
+static const uint8 md5_padding[64] = {
+ 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
+};
+
+void md5_finish(md5_context *ctx, uint8 digest[16]) {
+ uint32 last, padn;
+ uint32 high, low;
+ uint8 msglen[8];
+
+ high = (ctx->total[0] >> 29) | (ctx->total[1] << 3);
+ low = (ctx->total[0] << 3);
+
+ PUT_UINT32(low, msglen, 0);
+ PUT_UINT32(high, msglen, 4);
+
+ last = ctx->total[0] & 0x3F;
+ padn = (last < 56) ? (56 - last) : (120 - last);
+
+ md5_update(ctx, md5_padding, padn);
+ md5_update(ctx, msglen, 8);
+
+ PUT_UINT32(ctx->state[0], digest, 0);
+ PUT_UINT32(ctx->state[1], digest, 4);
+ PUT_UINT32(ctx->state[2], digest, 8);
+ PUT_UINT32(ctx->state[3], digest, 12);
+}
+
+bool md5_file(const char *name, uint8 digest[16], uint32 length) {
+ FILE *f;
+
+ f = fopen(name, "rb");
+ if (f == NULL) {
+ printf("md5_file couldn't open '%s'", name);
+ return false;
+ }
+
+ md5_context ctx;
+ uint32 i;
+ unsigned char buf[1000];
+ bool restricted = (length != 0);
+ int readlen;
+
+ if (!restricted || sizeof(buf) <= length)
+ readlen = sizeof(buf);
+ else
+ readlen = length;
+
+ md5_starts(&ctx);
+
+
+ while ((i = (uint32)fread(buf, 1, readlen, f)) > 0) {
+ md5_update(&ctx, buf, i);
+
+ length -= i;
+ if (restricted && length == 0)
+ break;
+
+ if (restricted && sizeof(buf) > length)
+ readlen = length;
+ }
+
+ md5_finish(&ctx, digest);
+ fclose(f);
+ return true;
+}
+
+}
Property changes on: tools/trunk/engines/mohawk/utils/md5.cpp
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:svn-keywords
+ Date Rev Author URL Id
Added: svn:eol-style
+ native
Added: tools/trunk/engines/mohawk/utils/md5.h
===================================================================
--- tools/trunk/engines/mohawk/utils/md5.h (rev 0)
+++ tools/trunk/engines/mohawk/utils/md5.h 2010-01-14 00:15:57 UTC (rev 47296)
@@ -0,0 +1,44 @@
+/* Scumm Tools
+ * Copyright (C) 2004-2006 The ScummVM Team
+ *
+ * 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 2
+ * 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL: https://scummvm.svn.sourceforge.net/svnroot/scummvm/tools/branches/gsoc2009-gui/utils/md5.h $
+ * $Id: md5.h 23138 2006-06-15 15:44:06Z h00ligan $
+ *
+ */
+
+#ifndef COMMON_MD5_H
+#define COMMON_MD5_H
+
+#include "../util.h"
+
+namespace Common {
+
+typedef struct {
+ uint32 total[2];
+ uint32 state[4];
+ uint8 buffer[64];
+} md5_context;
+
+void md5_starts(md5_context *ctx);
+void md5_update(md5_context *ctx, const uint8 *input, uint32 length);
+void md5_finish(md5_context *ctx, uint8 digest[16]);
+
+bool md5_file(const char *name, uint8 digest[16], uint32 length = 0);
+
+} // End of namespace Common
+
+#endif
Property changes on: tools/trunk/engines/mohawk/utils/md5.h
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:svn-keywords
+ Date Rev Author URL Id
Added: svn:eol-style
+ native
Added: tools/trunk/engines/mohawk/utils/pack-end.h
===================================================================
--- tools/trunk/engines/mohawk/utils/pack-end.h (rev 0)
+++ tools/trunk/engines/mohawk/utils/pack-end.h 2010-01-14 00:15:57 UTC (rev 47296)
@@ -0,0 +1,25 @@
+/* ScummVM Tools
+ * Copyright (C) 2002-2009 The ScummVM project
+ *
+ * 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 2
+ * 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL: https://scummvm.svn.sourceforge.net/svnroot/scummvm/tools/trunk/common/pack-end.h $
+ * $Id: pack-end.h 46360 2009-12-13 20:09:16Z fingolfin $
+ *
+ */
+
+#if defined(SCUMMVM_USE_PRAGMA_PACK)
+ #pragma pack()
+#endif
Property changes on: tools/trunk/engines/mohawk/utils/pack-end.h
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:svn-keywords
+ Date Rev Author URL Id
Added: svn:eol-style
+ native
Added: tools/trunk/engines/mohawk/utils/pack-start.h
===================================================================
--- tools/trunk/engines/mohawk/utils/pack-start.h (rev 0)
+++ tools/trunk/engines/mohawk/utils/pack-start.h 2010-01-14 00:15:57 UTC (rev 47296)
@@ -0,0 +1,25 @@
+/* ScummVM Tools
+ * Copyright (C) 2002-2009 The ScummVM project
+ *
+ * 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 2
+ * 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL: https://scummvm.svn.sourceforge.net/svnroot/scummvm/tools/trunk/common/pack-start.h $
+ * $Id: pack-start.h 46360 2009-12-13 20:09:16Z fingolfin $
+ *
+ */
+
+#if defined(SCUMMVM_USE_PRAGMA_PACK)
+ #pragma pack(1)
+#endif
Property changes on: tools/trunk/engines/mohawk/utils/pack-start.h
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:svn-keywords
+ Date Rev Author URL Id
Added: svn:eol-style
+ native
Added: tools/trunk/engines/mohawk/utils/str.cpp
===================================================================
--- tools/trunk/engines/mohawk/utils/str.cpp (rev 0)
+++ tools/trunk/engines/mohawk/utils/str.cpp 2010-01-14 00:15:57 UTC (rev 47296)
@@ -0,0 +1,618 @@
+/* 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 2
+ * 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ */
+
+#include "utils/str.h"
+#include "utils/util.h"
+
+#if !defined(__SYMBIAN32__)
+#include <new>
+#endif
+
+
+namespace Common {
+
+#if !(defined(PALMOS_ARM) || defined(PALMOS_DEBUG) || defined(__GP32__))
+const String String::emptyString;
+#else
+const char *String::emptyString = "";
+#endif
+
+static uint32 computeCapacity(uint32 len) {
+ // By default, for the capacity we use the next multiple of 32
+ return ((len + 32 - 1) & ~0x1F);
+}
+
+String::String(const char *str) : _size(0), _str(_storage) {
+ if (str == 0) {
+ _storage[0] = 0;
+ _size = 0;
+ } else
+ initWithCStr(str, strlen(str));
+}
+
+String::String(const char *str, uint32 len) : _size(0), _str(_storage) {
+ initWithCStr(str, len);
+}
+
+String::String(const char *beginP, const char *endP) : _size(0), _str(_storage) {
+ assert(endP >= beginP);
+ initWithCStr(beginP, endP - beginP);
+}
+
+void String::initWithCStr(const char *str, uint32 len) {
+ assert(str);
+
+ // Init _storage member explicitly (ie. without calling its constructor)
+ // for GCC 2.95.x compatibility (see also tracker item #1602879).
+ _storage[0] = 0;
+
+ _size = len;
+
+ if (len >= _builtinCapacity) {
+ // Not enough internal storage, so allocate more
+ _extern._capacity = computeCapacity(len+1);
+ _str = (char *)malloc(_extern._capacity);
+ assert(_str != 0);
+ }
+
+ // Copy the string into the storage area
+ memmove(_str, str, len);
+ _str[len] = 0;
+}
+
+String::String(const String &str)
+ : _size(str._size) {
+ if (str.isStorageIntern()) {
+ // String in internal storage: just copy it
+ memcpy(_storage, str._storage, _builtinCapacity);
+ _str = _storage;
+ } else {
+ // String in external storage
+ _extern._capacity = str._extern._capacity;
+ _str = str._str;
+ }
+ assert(_str != 0);
+}
+
+String::String(char c)
+: _size(0), _str(_storage) {
+
+ _storage[0] = c;
+ _storage[1] = 0;
+
+ // TODO/FIXME: There is no reason for the following check -- we *do*
+ // allow strings to contain 0 bytes!
+ _size = (c == 0) ? 0 : 1;
+}
+
+String::~String() {
+}
+
+void String::makeUnique() {
+ ensureCapacity(_size, true);
+}
+
+/**
+ * Ensure that enough storage is available to store at least new_size
+ * characters plus a null byte. In addition, if we currently share
+ * the storage with another string, unshare it, so that we can safely
+ * write to the storage.
+ */
+void String::ensureCapacity(uint32 new_size, bool keep_old) {
+ bool isShared = false;
+ uint32 curCapacity, newCapacity;
+ char *newStorage;
+
+ if (isStorageIntern()) {
+ isShared = false;
+ curCapacity = _builtinCapacity;
+ } else {
+ curCapacity = _extern._capacity;
+ }
+
+ // Special case: If there is enough space, and we do not share
+ // the storage, then there is nothing to do.
+ if (!isShared && new_size < curCapacity)
+ return;
+
+ if (isShared && new_size < _builtinCapacity) {
+ // We share the storage, but there is enough internal storage: Use that.
+ newStorage = _storage;
+ newCapacity = _builtinCapacity;
+ } else {
+ // We need to allocate storage on the heap!
+
+ // Compute a suitable new capacity limit
+ newCapacity = MAX(curCapacity * 2, computeCapacity(new_size+1));
+
+ // Allocate new storage
+ newStorage = (char *)malloc(newCapacity);
+ assert(newStorage);
+ }
+
+ // Copy old data if needed, elsewise reset the new storage.
+ if (keep_old) {
+ assert(_size < newCapacity);
+ memcpy(newStorage, _str, _size + 1);
+ } else {
+ _size = 0;
+ newStorage[0] = 0;
+ }
+
+ // ... in favor of the new storage
+ _str = newStorage;
+
+ if (!isStorageIntern()) {
+ // Set the ref count & capacity if we use an external storage.
+ // It is important to do this *after* copying any old content,
+ // else we would override data that has not yet been copied!
+ _extern._capacity = newCapacity;
+ }
+}
+
+String& String::operator =(const char *str) {
+ uint32 len = strlen(str);
+ ensureCapacity(len, false);
+ _size = len;
+ memmove(_str, str, len + 1);
+ return *this;
+}
+
+String &String::operator =(const String &str) {
+ if (&str == this)
+ return *this;
+
+ if (str.isStorageIntern()) {
+ _size = str._size;
+ _str = _storage;
+ memcpy(_str, str._str, _size + 1);
+ } else {
+ _extern._capacity = str._extern._capacity;
+ _size = str._size;
+ _str = str._str;
+ }
+
+ return *this;
+}
+
+String& String::operator =(char c) {
+ _str = _storage;
+ _size = 1;
+ _str[0] = c;
+ _str[1] = 0;
+ return *this;
+}
+
+String &String::operator +=(const char *str) {
+ int len = strlen(str);
+ if (len > 0) {
+ ensureCapacity(_size + len, true);
+
+ memcpy(_str + _size, str, len + 1);
+ _size += len;
+ }
+ return *this;
+}
+
+String &String::operator +=(const String &str) {
+ int len = str._size;
+ if (len > 0) {
+ ensureCapacity(_size + len, true);
+
+ memcpy(_str + _size, str._str, len + 1);
+ _size += len;
+ }
+ return *this;
+}
+
+String &String::operator +=(char c) {
+ ensureCapacity(_size + 1, true);
+
+ _str[_size++] = c;
+ _str[_size] = 0;
+
+ return *this;
+}
+
+bool String::hasPrefix(const char *x) const {
+ assert(x != 0);
+ // Compare x with the start of _str.
+ const char *y = c_str();
+ while (*x && *x == *y) {
+ ++x;
+ ++y;
+ }
+ // It's a prefix, if and only if all letters in x are 'used up' before
+ // _str ends.
+ return *x == 0;
+}
+
+bool String::hasSuffix(const char *x) const {
+ assert(x != 0);
+ // Compare x with the end of _str.
+ const uint32 x_size = strlen(x);
+ if (x_size > _size)
+ return false;
+ const char *y = c_str() + _size - x_size;
+ while (*x && *x == *y) {
+ ++x;
+ ++y;
+ }
+ // It's a suffix, if and only if all letters in x are 'used up' before
+ // _str ends.
+ return *x == 0;
+}
+
+bool String::contains(const char *x) const {
+ assert(x != 0);
+ return strstr(c_str(), x) != NULL;
+}
+
+bool String::contains(char x) const {
+ return strchr(c_str(), x) != NULL;
+}
+
+bool String::matchString(const char *pat, bool pathMode) const {
+ return Common::matchString(c_str(), pat, pathMode);
+}
+
+bool String::matchString(const String &pat, bool pathMode) const {
+ return Common::matchString(c_str(), pat.c_str(), pathMode);
+}
+
+void String::deleteLastChar() {
+ if (_size > 0)
+ deleteChar(_size - 1);
+}
+
+void String::deleteChar(uint32 p) {
+ assert(p < _size);
+
+ makeUnique();
+ while (p++ < _size)
+ _str[p-1] = _str[p];
+ _size--;
+}
+
+void String::clear() {
+ _size = 0;
+ _str = _storage;
+ _storage[0] = 0;
+}
+
+void String::setChar(char c, uint32 p) {
+ assert(p <= _size);
+
+ makeUnique();
+ _str[p] = c;
+}
+
+void String::insertChar(char c, uint32 p) {
+ assert(p <= _size);
+
+ ensureCapacity(_size + 1, true);
+ _size++;
+ for (uint32 i = _size; i > p; --i)
+ _str[i] = _str[i-1];
+ _str[p] = c;
+}
+
+void String::toLowercase() {
+ makeUnique();
+ for (uint32 i = 0; i < _size; ++i)
+ _str[i] = tolower(_str[i]);
+}
+
+void String::toUppercase() {
+ makeUnique();
+ for (uint32 i = 0; i < _size; ++i)
+ _str[i] = toupper(_str[i]);
+}
+
+void String::trim() {
+ if (_size == 0)
+ return;
+
+ makeUnique();
+
+ // Trim trailing whitespace
+ while (_size >= 1 && isspace(_str[_size-1]))
+ _size--;
+ _str[_size] = 0;
+
+ // Trim leading whitespace
+ char *t = _str;
+ while (isspace(*t))
+ t++;
+
+ if (t != _str) {
+ _size -= t - _str;
+ memmove(_str, t, _size + 1);
+ }
+}
+
+#pragma mark -
+
+bool String::operator ==(const String &x) const {
+ return equals(x);
+}
+
+bool String::operator ==(const char *x) const {
+ assert(x != 0);
+ return equals(x);
+}
+
+bool String::operator !=(const String &x) const {
+ return !equals(x);
+}
+
+bool String::operator !=(const char *x) const {
+ assert(x != 0);
+ return !equals(x);
+}
+
+bool String::operator < (const String &x) const {
+ return compareTo(x) < 0;
+}
+
+bool String::operator <= (const String &x) const {
+ return compareTo(x) <= 0;
+}
+
+bool String::operator > (const String &x) const {
+ return compareTo(x) > 0;
+}
+
+bool String::operator >= (const String &x) const {
+ return compareTo(x) >= 0;
+}
+
+#pragma mark -
+
+bool operator == (const char* y, const String &x) {
+ return (x == y);
+}
+
+bool operator != (const char* y, const String &x) {
+ return x != y;
+}
+
+#pragma mark -
+
+bool String::equals(const String &x) const {
+ return (0 == compareTo(x));
+}
+
+bool String::equals(const char *x) const {
+ assert(x != 0);
+ return (0 == compareTo(x));
+}
+
+bool String::equalsIgnoreCase(const String &x) const {
+ return (0 == compareToIgnoreCase(x));
+}
+
+bool String::equalsIgnoreCase(const char *x) const {
+ assert(x != 0);
+ return (0 == compareToIgnoreCase(x));
+}
+
+int String::compareTo(const String &x) const {
+ return compareTo(x.c_str());
+}
+
+int String::compareTo(const char *x) const {
+ assert(x != 0);
+ return strcmp(c_str(), x);
+}
+
+int String::compareToIgnoreCase(const String &x) const {
+ return compareToIgnoreCase(x.c_str());
+}
+
+int String::compareToIgnoreCase(const char *x) const {
+ assert(x != 0);
+ return scumm_stricmp(c_str(), x);
+}
+
+#pragma mark -
+
+String operator +(const String &x, const String &y) {
+ String temp(x);
+ temp += y;
+ return temp;
+}
+
+String operator +(const char *x, const String &y) {
+ String temp(x);
+ temp += y;
+ return temp;
+}
+
+String operator +(const String &x, const char *y) {
+ String temp(x);
+ temp += y;
+ return temp;
+}
+
+String operator +(char x, const String &y) {
+ String temp(x);
+ temp += y;
+ return temp;
+}
+
+String operator +(const String &x, char y) {
+ String temp(x);
+ temp += y;
+ return temp;
+}
+
+char *ltrim(char *t) {
+ while (isspace(*t))
+ t++;
+ return t;
+}
+
+char *rtrim(char *t) {
+ int l = strlen(t) - 1;
+ while (l >= 0 && isspace(t[l]))
+ t[l--] = 0;
+ return t;
+}
+
+char *trim(char *t) {
+ return rtrim(ltrim(t));
+}
+
+Common::String lastPathComponent(const Common::String &path, const char sep) {
+ const char *str = path.c_str();
+ const char *last = str + path.size();
+
+ // Skip over trailing slashes
+ while (last > str && *(last-1) == sep)
+ --last;
+
+ // Path consisted of only slashes -> return empty string
+ if (last == str)
+ return Common::String();
+
+ // Now scan the whole component
+ const char *first = last - 1;
+ while (first >= str && *first != sep)
+ --first;
+
+ if (*first == sep)
+ first++;
+
+ return Common::String(first, last);
+}
+
+Common::String normalizePath(const Common::String &path, const char sep) {
+ if (path.empty())
+ return path;
+
+ const char *cur = path.c_str();
+ Common::String result;
+
+ // If there is a leading slash, preserve that:
+ if (*cur == sep) {
+ result += sep;
+ while (*cur == sep)
+ ++cur;
+ }
+
+ // Scan till the end of the String
+ while (*cur != 0) {
+ const char *start = cur;
+
+ // Scan till the next path separator resp. the end of the string
+ while (*cur != sep && *cur != 0)
+ cur++;
+
+ const Common::String component(start, cur);
+
+ // Skip empty components and dot components, add all others
+ if (!component.empty() && component != ".") {
+ // Add a separator before the component, unless the result
+ // string already ends with one (which happens only if the
+ // path *starts* with a separator).
+ if (!result.empty() && result.lastChar() != sep)
+ result += sep;
+
+ // Add the component
+ result += component;
+ }
+
+ // Skip over separator chars
+ while (*cur == sep)
+ cur++;
+ }
+
+ return result;
+}
+
+bool matchString(const char *str, const char *pat, bool pathMode) {
+ assert(str);
+ assert(pat);
+
+ const char *p = 0;
+ const char *q = 0;
+
+ for (;;) {
+ if (pathMode && *str == '/') {
+ p = 0;
+ q = 0;
+ if (*pat == '?')
+ return false;
+ }
+
+ switch (*pat) {
+ case '*':
+ // Record pattern / string possition for backtracking
+ p = ++pat;
+ q = str;
+ // If pattern ended with * -> match
+ if (!*pat)
+ return true;
+ break;
+
+ default:
+ if (*pat != *str) {
+ if (p) {
+ // No match, oops -> try to backtrack
+ pat = p;
+ str = ++q;
+ if (!*str)
+ return !*pat;
+ break;
+ }
+ else
+ return false;
+ }
+ // fallthrough
+ case '?':
+ if (!*str)
+ return !*pat;
+ pat++;
+ str++;
+ }
+ }
+}
+
+String tag2string(uint32 tag) {
+ char str[5];
+ str[0] = (char)(tag >> 24);
+ str[1] = (char)(tag >> 16);
+ str[2] = (char)(tag >> 8);
+ str[3] = (char)tag;
+ str[4] = '\0';
+ // Replace non-printable chars by dot
+ for (int i = 0; i < 4; ++i) {
+ if (!isprint(str[i]))
+ str[i] = '.';
+ }
+ return Common::String(str);
+}
+
+} // End of namespace Common
Property changes on: tools/trunk/engines/mohawk/utils/str.cpp
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:svn-keywords
+ Date Rev Author URL Id
Added: svn:eol-style
+ native
Added: tools/trunk/engines/mohawk/utils/str.h
===================================================================
--- tools/trunk/engines/mohawk/utils/str.h (rev 0)
+++ tools/trunk/engines/mohawk/utils/str.h 2010-01-14 00:15:57 UTC (rev 47296)
@@ -0,0 +1,332 @@
+/* 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 2
+ * 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ */
+
+#ifndef COMMON_STRING_H
+#define COMMON_STRING_H
+
+#include "utils/array.h"
+
+namespace Common {
+
+/**
+ * Simple string class for ScummVM. Provides automatic storage managment,
+ * and overloads several operators in a 'natural' fashion, mimicking
+ * the std::string class. Even provides simple iterators.
+ *
+ * This class tries to avoid allocating lots of small blocks on the heap,
+ * since that is inefficient on several platforms supported by ScummVM.
+ * Instead, small strings are stored 'inside' the string object (i.e. on
+ * the stack, for stack allocated objects), and only for strings exceeding
+ * a certain length do we allocate a buffer on the heap.
+ */
+class String {
+protected:
+ /**
+ * The size of the internal storage. Increasing this means less heap
+ * allocations are needed, at the cost of more stack memory usage,
+ * and of course lots of wasted memory. Empirically, 90% or more of
+ * all String instances are less than 32 chars long. If a platform
+ * is very short on stack space, it would be possible to lower this.
+ * A value of 24 still seems acceptable, though considerably worse,
+ * while 16 seems to be the lowest you want to go... Anything lower
+ * than 8 makes no sense, since that's the size of member _extern
+ * (on 32 bit machines; 12 bytes on systems with 64bit pointers).
+ */
+ static const uint32 _builtinCapacity = 32 - sizeof(uint32) - sizeof(char*);
+
+ /**
+ * Length of the string. Stored to avoid having to call strlen
+ * a lot. Yes, we limit ourselves to strings shorter than 4GB --
+ * on purpose :-).
+ */
+ uint32 _size;
+
+ /**
+ * Pointer to the actual string storage. Either points to _storage,
+ * or to a block allocated on the heap via malloc.
+ */
+ char *_str;
+
+
+ union {
+ /**
+ * Internal string storage.
+ */
+ char _storage[_builtinCapacity];
+ /**
+ * External string storage data -- the capacity of the string
+ * _str points to.
+ */
+ struct {
+ uint32 _capacity;
+ } _extern;
+ };
+
+ inline bool isStorageIntern() const {
+ return _str == _storage;
+ }
+
+public:
+#if !(defined(PALMOS_ARM) || defined(PALMOS_DEBUG) || defined(__GP32__))
+ static const String emptyString;
+#else
+ static const char *emptyString;
+#endif
+
+ /** Construct a new empty string. */
+ String() : _size(0), _str(_storage) { _storage[0] = 0; }
+
+ /** Construct a new string from the given NULL-terminated C string. */
+ String(const char *str);
+
+ /** Construct a new string containing exactly len characters read from address str. */
+ String(const char *str, uint32 len);
+
+ /** Construct a new string containing the characters between beginP (including) and endP (excluding). */
+ String(const char *beginP, const char *endP);
+
+ /** Construct a copy of the given string. */
+ String(const String &str);
+
+ /** Construct a string consisting of the given character. */
+ explicit String(char c);
+
+ ~String();
+
+ String &operator =(const char *str);
+ String &operator =(const String &str);
+ String &operator =(char c);
+ String &operator +=(const char *str);
+ String &operator +=(const String &str);
+ String &operator +=(char c);
+
+ bool operator ==(const String &x) const;
+ bool operator ==(const char *x) const;
+ bool operator !=(const String &x) const;
+ bool operator !=(const char *x) const;
+
+ bool operator <(const String &x) const;
+ bool operator <=(const String &x) const;
+ bool operator >(const String &x) const;
+ bool operator >=(const String &x) const;
+
+ bool equals(const String &x) const;
+ bool equalsIgnoreCase(const String &x) const;
+ int compareTo(const String &x) const; // strcmp clone
+ int compareToIgnoreCase(const String &x) const; // stricmp clone
+
+ bool equals(const char *x) const;
+ bool equalsIgnoreCase(const char *x) const;
+ int compareTo(const char *x) const; // strcmp clone
+ int compareToIgnoreCase(const char *x) const; // stricmp clone
+
+ bool hasSuffix(const char *x) const;
+ bool hasPrefix(const char *x) const;
+
+ bool contains(const char *x) const;
+ bool contains(char x) const;
+
+ /**
+ * Simple DOS-style pattern matching function (understands * and ? like used in DOS).
+ * Taken from exult/files/listfiles.cc
+ *
+ * Token meaning:
+ * "*": any character, any amount of times.
+ * "?": any character, only once.
+ *
+ * Example strings/patterns:
+ * String: monkey.s01 Pattern: monkey.s?? => true
+ * String: monkey.s101 Pattern: monkey.s?? => false
+ * String: monkey.s99 Pattern: monkey.s?1 => false
+ * String: monkey.s101 Pattern: monkey.s* => true
+ * String: monkey.s99 Pattern: monkey.s*1 => false
+ *
+ * @param str Text to be matched against the given pattern.
+ * @param pat Glob pattern.
+ * @param pathMode Whether to use path mode, i.e., whether slashes must be matched explicitly.
+ *
+ * @return true if str matches the pattern, false otherwise.
+ */
+ bool matchString(const char *pat, bool pathMode = false) const;
+ bool matchString(const String &pat, bool pathMode = false) const;
+
+
+ inline const char *c_str() const { return _str; }
+ inline uint size() const { return _size; }
+
+ inline bool empty() const { return (_size == 0); }
+ char lastChar() const { return (_size > 0) ? _str[_size-1] : 0; }
+
+ char operator[](int idx) const {
+ assert(_str && idx >= 0 && idx < (int)_size);
+ return _str[idx];
+ }
+
+ /** Remove the last character from the string. */
+ void deleteLastChar();
+
+ /** Remove the character at position p from the string. */
+ void deleteChar(uint32 p);
+
+ /** Set character c at position p, replacing the previous character there. */
+ void setChar(char c, uint32 p);
+
+ /** Set character c at position p. */
+ void insertChar(char c, uint32 p);
+
+ /** Clears the string, making it empty. */
+ void clear();
+
+ /** Convert all characters in the string to lowercase. */
+ void toLowercase();
+
+ /** Convert all characters in the string to uppercase. */
+ void toUppercase();
+
+ /**
+ * Removes trailing and leading whitespaces. Uses isspace() to decide
+ * what is whitespace and what not.
+ */
+ void trim();
+
+public:
+ typedef char * iterator;
+ typedef const char * const_iterator;
+
+ iterator begin() {
+ return _str;
+ }
+
+ iterator end() {
+ return begin() + size();
+ }
+
+ const_iterator begin() const {
+ return _str;
+ }
+
+ const_iterator end() const {
+ return begin() + size();
+ }
+
+protected:
+ void makeUnique();
+ void ensureCapacity(uint32 new_size, bool keep_old);
+ void initWithCStr(const char *str, uint32 len);
+};
+
+// Append two strings to form a new (temp) string
+String operator +(const String &x, const String &y);
+
+String operator +(const char *x, const String &y);
+String operator +(const String &x, const char *y);
+
+String operator +(const String &x, char y);
+String operator +(char x, const String &y);
+
+// Some useful additional comparison operators for Strings
+bool operator == (const char *x, const String &y);
+bool operator != (const char *x, const String &y);
+
+// Utility functions to remove leading and trailing whitespaces
+extern char *ltrim(char *t);
+extern char *rtrim(char *t);
+extern char *trim(char *t);
+
+
+/**
+ * Returns the last component of a given path.
+ *
+ * Examples:
+ * /foo/bar.txt would return 'bar.txt'
+ * /foo/bar/ would return 'bar'
+ * /foo/./bar// would return 'bar'
+ *
+ * @param path the path of which we want to know the last component
+ * @param sep character used to separate path components
+ * @return The last component of the path.
+ */
+Common::String lastPathComponent(const Common::String &path, const char sep);
+
+/**
+ * Normalize a gien path to a canonical form. In particular:
+ * - trailing separators are removed: /foo/bar/ -> /foo/bar
+ * - double separators (= empty components) are removed: /foo//bar -> /foo/bar
+ * - dot components are removed: /foo/./bar -> /foo/bar
+ *
+ * @todo remove double dot components: /foo/baz/../bar -> /foo/bar
+ *
+ * @param path the path to normalize
+ * @param sep the separator token (usually '/' on Unix-style systems, or '\\' on Windows based stuff)
+ * @return the normalized path
+ */
+Common::String normalizePath(const Common::String &path, const char sep);
+
+
+/**
+ * Simple DOS-style pattern matching function (understands * and ? like used in DOS).
+ * Taken from exult/files/listfiles.cc
+ *
+ * Token meaning:
+ * "*": any character, any amount of times.
+ * "?": any character, only once.
+ *
+ * Example strings/patterns:
+ * String: monkey.s01 Pattern: monkey.s?? => true
+ * String: monkey.s101 Pattern: monkey.s?? => false
+ * String: monkey.s99 Pattern: monkey.s?1 => false
+ * String: monkey.s101 Pattern: monkey.s* => true
+ * String: monkey.s99 Pattern: monkey.s*1 => false
+ *
+ * @param str Text to be matched against the given pattern.
+ * @param pat Glob pattern.
+ * @param pathMode Whether to use path mode, i.e., whether slashes must be matched explicitly.
+ *
+ * @return true if str matches the pattern, false otherwise.
+ */
+bool matchString(const char *str, const char *pat, bool pathMode = false);
+
+/**
+ * Take a 32 bit value and turn it into a four character string, where each of
+ * the four bytes is turned into one character. Most significant byte is printed
+ * first.
+ */
+String tag2string(uint32 tag);
+#define tag2str(x) Common::tag2string(x).c_str()
+
+
+class StringList : public Array<String> {
+public:
+ void push_back(const char *str) {
+ Array<String>::push_back(str);
+ }
+
+ void push_back(const String &str) {
+ Array<String>::push_back(str);
+ }
+};
+
+} // End of namespace Common
+
+#endif
Property changes on: tools/trunk/engines/mohawk/utils/str.h
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:svn-keywords
+ Date Rev Author URL Id
Added: svn:eol-style
+ native
Added: tools/trunk/engines/mohawk/utils/stream.h
===================================================================
--- tools/trunk/engines/mohawk/utils/stream.h (rev 0)
+++ tools/trunk/engines/mohawk/utils/stream.h 2010-01-14 00:15:57 UTC (rev 47296)
@@ -0,0 +1,246 @@
+/* Scumm Tools
+ * Copyright (C) 2004-2006 The ScummVM Team
+ *
+ * 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 2
+ * 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL: https://scummvm.svn.sourceforge.net/svnroot/scummvm/tools/branches/gsoc2009-gui/utils/stream.h $
+ * $Id: stream.h 40868 2009-05-24 15:19:28Z lordhoto $
+ *
+ */
+
+#ifndef COMMON_STREAM_H
+#define COMMON_STREAM_H
+
+#include "../util.h"
+
+namespace Common {
+
+/**
+ * Virtual base class for both ReadStream and WriteStream.
+ */
+class Stream {
+public:
+ virtual ~Stream() {}
+
+ /**
+ * Returns true if any I/O failure occured.
+ * This flag is never cleared automatically. In order to clear it,
+ * client code has to call clearIOFailed() explicitly.
+ *
+ * @todo Instead of returning a plain bool, maybe we should define
+ * a list of error codes which can be returned here.
+ */
+ virtual bool ioFailed() const { return false; }
+
+ /**
+ * Reset the I/O error status.
+ */
+ virtual void clearIOFailed() {}
+};
+
+
+/**
+ * Generic interface for a readable data stream.
+ */
+class ReadStream : virtual public Stream {
+public:
+ /**
+ * Returns true if the end of the stream has been reached.
+ */
+ virtual bool eos() const = 0;
+
+ /**
+ * Read data from the stream. Subclasses must implement this
+ * method; all other read methods are implemented using it.
+ *
+ * @param dataPtr pointer to a buffer into which the data is read
+ * @param dataSize number of bytes to be read
+ * @return the number of bytes which were actually read.
+ */
+ virtual uint32 read(void *dataPtr, uint32 dataSize) = 0;
+
+
+ // The remaining methods all have default implementations; subclasses
+ // need not (and should not) overload them.
+
+ byte readByte() {
+ byte b = 0;
+ read(&b, 1);
+ return b;
+ }
+
+ int8 readSByte() {
+ int8 b = 0;
+ read(&b, 1);
+ return b;
+ }
+
+ uint16 readUint16LE() {
+ uint16 a = readByte();
+ uint16 b = readByte();
+ return a | (b << 8);
+ }
+
+ uint32 readUint32LE() {
+ uint32 a = readUint16LE();
+ uint32 b = readUint16LE();
+ return (b << 16) | a;
+ }
+
+ uint16 readUint16BE() {
+ uint16 b = readByte();
+ uint16 a = readByte();
+ return a | (b << 8);
+ }
+
+ uint32 readUint32BE() {
+ uint32 b = readUint16BE();
+ uint32 a = readUint16BE();
+ return (b << 16) | a;
+ }
+
+ int16 readSint16LE() {
+ return (int16)readUint16LE();
+ }
+
+ int32 readSint32LE() {
+ return (int32)readUint32LE();
+ }
+
+ int16 readSint16BE() {
+ return (int16)readUint16BE();
+ }
+
+ int32 readSint32BE() {
+ return (int32)readUint32BE();
+ }
+};
+
+
+/**
+ * Interface for a seekable & readable data stream.
+ *
+ * @todo We really need better error handling here!
+ * Like seek should somehow indicate whether it failed.
+ */
+class SeekableReadStream : virtual public ReadStream {
+public:
+
+ virtual uint32 pos() const = 0;
+ virtual uint32 size() const = 0;
+
+ virtual void seek(int32 offset, int whence = SEEK_SET) = 0;
+
+ void skip(uint32 offset) { seek(offset, SEEK_CUR); }
+};
+
+/**
+ * SubReadStream provides access to a ReadStream restricted to the range
+ * [currentPosition, currentPosition+end).
+ * Manipulating the parent stream directly /will/ mess up a substream.
+ * Likewise, manipulating two substreams of a parent stream will cause them to
+ * step on each others toes.
+ */
+class SubReadStream : virtual public ReadStream {
+protected:
+ ReadStream *_parentStream;
+ bool _disposeParentStream;
+ uint32 _pos;
+ uint32 _end;
+ bool _eos;
+public:
+ SubReadStream(ReadStream *parentStream, uint32 end, bool disposeParentStream = false)
+ : _parentStream(parentStream),
+ _disposeParentStream(disposeParentStream),
+ _pos(0),
+ _end(end),
+ _eos(false) {
+ assert(parentStream);
+ }
+
+ ~SubReadStream() {
+ if (_disposeParentStream) delete _parentStream;
+ }
+
+ virtual bool eos() const { return _eos; }
+
+ virtual uint32 read(void *dataPtr, uint32 dataSize) {
+ if (dataSize > _end - _pos) {
+ dataSize = _end - _pos;
+ _eos = true;
+ }
+
+ dataSize = _parentStream->read(dataPtr, dataSize);
@@ Diff output truncated at 100000 characters. @@
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list