[Scummvm-cvs-logs] SF.net SVN: scummvm: [30690] tools/trunk

knakos at users.sourceforge.net knakos at users.sourceforge.net
Mon Jan 28 21:41:00 CET 2008


Revision: 30690
          http://scummvm.svn.sourceforge.net/scummvm/?rev=30690&view=rev
Author:   knakos
Date:     2008-01-28 12:41:00 -0800 (Mon, 28 Jan 2008)

Log Message:
-----------
Merge the tools gui branch into the trunk (GSoC 2007 task - student lightcast

Modified Paths:
--------------
    tools/trunk/Makefile
    tools/trunk/Makefile.mingw
    tools/trunk/README
    tools/trunk/compress.c
    tools/trunk/compress.h
    tools/trunk/compress_agos.c
    tools/trunk/compress_kyra.cpp
    tools/trunk/compress_queen.c
    tools/trunk/compress_saga.cpp
    tools/trunk/compress_scumm_bun.cpp
    tools/trunk/compress_scumm_san.cpp
    tools/trunk/compress_scumm_sou.c
    tools/trunk/compress_sword1.c
    tools/trunk/compress_sword2.c
    tools/trunk/compress_touche.c
    tools/trunk/dekyra.cpp
    tools/trunk/dekyra.h
    tools/trunk/dekyra_v1.cpp
    tools/trunk/descumm-common.cpp
    tools/trunk/descumm-tool.cpp
    tools/trunk/descumm.cpp
    tools/trunk/descumm.h
    tools/trunk/descumm6.cpp
    tools/trunk/encode_dxa.cpp
    tools/trunk/extract_agos.c
    tools/trunk/extract_kyra.cpp
    tools/trunk/extract_loom_tg16.c
    tools/trunk/extract_mm_apple.c
    tools/trunk/extract_mm_c64.c
    tools/trunk/extract_mm_nes.c
    tools/trunk/extract_parallaction.cpp
    tools/trunk/extract_scumm_mac.c
    tools/trunk/extract_zak_c64.c
    tools/trunk/kyra_pak.cpp
    tools/trunk/kyra_pak.h
    tools/trunk/util.c
    tools/trunk/util.h

Added Paths:
-----------
    tools/trunk/TODO
    tools/trunk/dist/macosx/
    tools/trunk/dist/macosx/Info.plist
    tools/trunk/tools_gui.cpp
    tools/trunk/tools_gui.h

Removed Paths:
-------------
    tools/trunk/dist/macosx/Info.plist

Modified: tools/trunk/Makefile
===================================================================
--- tools/trunk/Makefile	2008-01-28 20:40:05 UTC (rev 30689)
+++ tools/trunk/Makefile	2008-01-28 20:41:00 UTC (rev 30690)
@@ -10,7 +10,7 @@
 
 # Additional warnings
 CFLAGS+= -Wshadow
-CFLAGS+= -pedantic
+#CFLAGS+= -pedantic
 CFLAGS+= -Wpointer-arith -Wcast-qual -Wcast-align
 # -Wconversion
 CFLAGS+= -Wshadow -Wimplicit -Wundef -Wwrite-strings
@@ -38,7 +38,8 @@
 	extract_mm_nes$(EXEEXT) \
 	extract_parallaction$(EXEEXT) \
 	extract_scumm_mac$(EXEEXT) \
-	extract_zak_c64$(EXEEXT)
+	extract_zak_c64$(EXEEXT) \
+	tools_gui$(EXEEXT)
 
 UTILS := \
 	utils/adpcm.o \
@@ -50,35 +51,46 @@
 
 all: $(TARGETS)
 
+bundle_name = ScummVM\ Tools\ GUI.app
+bundle: $(TARGETS)
+	mkdir -p $(bundle_name)
+	mkdir -p $(bundle_name)/Contents
+	mkdir -p $(bundle_name)/Contents/MacOS
+	mkdir -p $(bundle_name)/Contents/Resources
+	echo "APPL????" > $(bundle_name)/Contents/PkgInfo
+	cp $(SRC)/dist/macosx/Info.plist $(bundle_name)/Contents/
+	cp $(TARGETS) $(bundle_name)/Contents/Resources/
+	mv $(bundle_name)/Contents/Resources/tools_gui $(bundle_name)/Contents/MacOS/
+
 compress_agos$(EXEEXT): compress_agos.o compress.o util.o
-	$(CC) $(LDFLAGS) -o $@ $+
+	$(CC) $(LDFLAGS) -o $@ $+ -lvorbis -logg -lvorbisenc -lFLAC
 
 compress_kyra$(EXEEXT): compress_kyra.o kyra_pak.o compress.o util.o
-	$(CXX) $(LDFLAGS) -o $@ $+
+	$(CXX) $(LDFLAGS) -o $@ $+ -lvorbis -logg -lvorbisenc -lFLAC
 
-compress_queen$(EXEEXT): compress_queen.o util.o
-	$(CC) $(LDFLAGS) -o $@ $+
+compress_queen$(EXEEXT): compress_queen.o compress.o util.o
+	$(CC) $(LDFLAGS) -o $@ $+ -lvorbis -logg -lvorbisenc -lFLAC
 
 compress_saga$(EXEEXT): compress_saga.o compress.o util.o $(UTILS)
-	$(CXX) $(LDFLAGS) -o $@ $+
+	$(CXX) $(LDFLAGS) -o $@ $+ -lvorbis -logg -lvorbisenc -lFLAC
 
 compress_scumm_bun$(EXEEXT): compress_scumm_bun.o compress.o util.o
-	$(CXX) $(LDFLAGS) -o $@ $+
+	$(CXX) $(LDFLAGS) -o $@ $+ -lvorbis -logg -lvorbisenc -lFLAC
 
 compress_scumm_san$(EXEEXT): compress_scumm_san.o compress.o util.o
-	$(CXX) $(LDFLAGS) -o $@ $+ -lz
+	$(CXX) $(LDFLAGS) -o $@ $+ -lz -lvorbis -logg -lvorbisenc -lFLAC
 
 compress_scumm_sou$(EXEEXT): compress_scumm_sou.o compress.o util.o
-	$(CC) $(LDFLAGS) -o $@ $+
+	$(CC) $(LDFLAGS) -o $@ $+ -lvorbis -logg -lvorbisenc -lFLAC
 
 compress_sword1$(EXEEXT): compress_sword1.o compress.o util.o
-	$(CC) $(LDFLAGS) -o $@ $+
+	$(CC) $(LDFLAGS) -o $@ $+ -lvorbis -logg -lvorbisenc -lFLAC
 
 compress_sword2$(EXEEXT): compress_sword2.o compress.o util.o
-	$(CC) $(LDFLAGS) -o $@ $+
+	$(CC) $(LDFLAGS) -o $@ $+ -lvorbis -logg -lvorbisenc -lFLAC
 
 compress_touche$(EXEEXT): compress_touche.o compress.o util.o
-	$(CC) $(LDFLAGS) -o $@ $+
+	$(CC) $(LDFLAGS) -o $@ $+ -lvorbis -logg -lvorbisenc -lFLAC
 
 dekyra$(EXEEXT): dekyra.o dekyra_v1.o util.o
 	$(CXX) $(LDFLAGS) -o $@ $+
@@ -90,7 +102,7 @@
 	$(CXX) $(LDFLAGS) -o $@ $+
 
 encode_dxa$(EXEEXT): encode_dxa.o compress.o util.o
-	$(CXX) $(LDFLAGS) -o $@ $+ -lpng -lz
+	$(CXX) $(LDFLAGS) -o $@ $+ -lpng -lz -lvorbis -logg -lvorbisenc -lFLAC
 
 extract_agos$(EXEEXT): extract_agos.o
 	$(CC) $(LDFLAGS) -o $@ $+
@@ -119,13 +131,16 @@
 extract_zak_c64$(EXEEXT): extract_zak_c64.o util.o
 	$(CC) $(LDFLAGS) -o $@ $+
 
+tools_gui$(EXEEXT): tools_gui.o
+	$(CXX) $(LDFLAGS) -o $@ $+ `wx-config --libs`
 
+
 descumm.o descumm6.o descumm-common.o descumm-tool.o: descumm.h
 
-# Most compress_* tools (except for compress_queen) use compress.h
+# All compress_* tools use compress.h
 compress_agos.o compress_saga.o compress_scumm_sou.o \
 compress_scumm_bun.o compress_sword1.o compress_sword2.o \
-compress_kyra.o compress.o encode_dxa.o: compress.h
+compress_kyra.o compress_queen.o compress.o encode_dxa.o: compress.h
 
 # extract_parallaction.h
 extract_parallaction.o: extract_parallaction.h
@@ -155,6 +170,10 @@
 clean:
 	rm -f *.o utils/*.o $(TARGETS)
 
+
+tools_gui.o: tools_gui.cpp tools_gui.h
+	$(CXX) $(CFLAGS) $(CPPFLAGS) `wx-config --cxxflags` -c tools_gui.cpp -o tools_gui.o
+
 .cpp.o:
 	$(CXX) $(CFLAGS) $(CPPFLAGS) -c $(<) -o $*.o
 

Modified: tools/trunk/Makefile.mingw
===================================================================
--- tools/trunk/Makefile.mingw	2008-01-28 20:40:05 UTC (rev 30689)
+++ tools/trunk/Makefile.mingw	2008-01-28 20:41:00 UTC (rev 30690)
@@ -34,6 +34,8 @@
 	strip extract_parallaction.exe -o $(SCUMMVMPATH)/tools/extract_parallaction.exe
 	strip extract_scumm_mac.exe -o $(SCUMMVMPATH)/tools/extract_scumm_mac.exe
 	strip extract_zak_c64.exe -o $(SCUMMVMPATH)/tools/extract_zak_c64.exe
+	strip tools_gui.exe -o $(SCUMMVMPATH)/tools/tools_gui.exe
+
 	cp *.bat $(SCUMMVMPATH)/tools
 	cp COPYING $(SCUMMVMPATH)/tools/COPYING.txt
 	cp README $(SCUMMVMPATH)/tools/README.txt

Modified: tools/trunk/README
===================================================================
--- tools/trunk/README	2008-01-28 20:40:05 UTC (rev 30689)
+++ tools/trunk/README	2008-01-28 20:41:00 UTC (rev 30690)
@@ -102,7 +102,7 @@
                 or FLAC. 
 
                 Example of usage:
-                compress_saga <flags here> <file>
+                compress_saga [params] <file>
 
                 Where <file> is the sound file you with to compress, without the
                 extension.
@@ -125,19 +125,16 @@
                 or FLAC.
 
                 Example of usage:
-                compress_scumm.bun digmusic.bun uncomp comp --flac
+                compress_scumm_bun [params] <file> <inputdir> <outputdir>
 
                 Please note that FLAC compression will produce larger files
                 than the original, for The Curse of Monkey Island!
 
-        compress_scumm_san <inputfile> <inputdir> <outputdir> [--ogg]
+        compress_scumm_san
                 Compresses '.san' smush animation files. It uses lossless
                 zlib for compressing FOBJ gfx chunks inside a san file.
                 It also can create a separate Ogg file with the audio track.
 
-                Example of usage:
-                compress_scumm_san opening.san uncomp comp
-
                 In order to use such compressed files, your ScummVM binary
                 must have been built with zlib support enabled (you can find
                 out whether that's the case by looking at the About dialog).
@@ -199,7 +196,7 @@
                 Basic script disassembler for Legend of Kyrandia games
 
 Encoder Tools:
-        encode_dxa <filename>
+        encode_dxa [params] <file>
 
                 Creates DXA file out of extracted Smacker video.
 

Copied: tools/trunk/TODO (from rev 30663, tools/branches/gsoc2007-toolsgui/TODO)
===================================================================
--- tools/trunk/TODO	                        (rev 0)
+++ tools/trunk/TODO	2008-01-28 20:41:00 UTC (rev 30690)
@@ -0,0 +1,31 @@
+-------------
+Current Goals
+-------------
+
+* Final testing on all platforms
+
+------------
+Future Goals
+------------
+
+* Default Options
+    - Things like default games path, default LAME path, default compression 
+      type, etc. could be added to a menu and saved to an *.ini file.
+* Batch Processing
+    - Batch processing can be performed by holding a list of jobs to done in
+      the ProcessArray already used in MainFrame.  To accomplish this we would
+      need to modify the Process class to add a wxString class member to hold
+      the command line string, add wxButtons and a wxListBox to facilitate
+      adding, removing, and starting batch jobs, and adding a function which
+      would iterate through the ProcessArray and perform each job, starting
+      subsequent jobs in the OnTerminate function of the previous job.
+* Encode DXA Improvements
+    - The current implementation of 'Encode DXA' compression only performs the
+      final step of the process.  There are already Windows and Unix scripts to
+      perform all of the steps in the process.  Another tab could be added to
+      the GUI which simply implements the steps found in the DXA scripts.
+* Automatic Compression
+    - Another tab could be added that would automatically compress an original
+      CD.  This would involve identifying the game, either by using filenames
+      or md5 hashes, copying all of the files needed to play the game to a
+      specified directory, and compressing any applicable files.

Modified: tools/trunk/compress.c
===================================================================
--- tools/trunk/compress.c	2008-01-28 20:40:05 UTC (rev 30689)
+++ tools/trunk/compress.c	2008-01-28 20:41:00 UTC (rev 30690)
@@ -35,37 +35,32 @@
 	int nominalBitr;
 	int minBitr;
 	int maxBitr;
-	int quality;
+	float quality;
 	bool silent;
 } oggencparams;
 
-/* FIXME: This is an evil way to pass on the params to FLAC.
- It makes it near impossible to reliably pass default params to the
- encoder.
-*/
 typedef struct {
-	char * const* argv;
-	int numArgs;
+	int compressionLevel;
+	int blocksize;
+	bool verify;
+	bool silent;
 } flaccparams;
 
 typedef struct {
-	bool isLittleEndian;
-	bool isStereo;
-	bool isUnsigned;
+	bool isLittleEndian, isStereo;
 	uint8 bitsPerSample;
 } rawtype;
 
 lameparams encparms = { minBitrDef, maxBitrDef, false, algqualDef, vbrqualDef, 0 };
 oggencparams oggparms = { -1, -1, -1, oggqualDef, 0 };
-flaccparams flacparms;
-rawtype	rawAudioType = { false, false, false, 8 };
+flaccparams flacparms = { flacCompressDef, flacBlocksizeDef, false, false };
+rawtype	rawAudioType = { false, false, 8 };
 
 const char *tempEncoded = TEMP_MP3;
 
-void setRawAudioType(bool isLittleEndian, bool isStereo, bool isUnsigned, uint8 bitsPerSample) {
+void setRawAudioType(bool isLittleEndian, bool isStereo, uint8 bitsPerSample) {
 	rawAudioType.isLittleEndian = isLittleEndian;
 	rawAudioType.isStereo = isStereo;
-	rawAudioType.isUnsigned = isUnsigned;
 	rawAudioType.bitsPerSample = bitsPerSample;
 }
 
@@ -105,43 +100,20 @@
 }
 
 void encodeAudio(const char *inname, bool rawInput, int rawSamplerate, const char *outname, CompressMode compmode) {
+	bool err = false;
 	char fbuf[2048];
 	char *tmp = fbuf;
-	int i;
-	bool err = false;
 
-	switch (compmode) {
-	case kVorbisMode:
-		tmp += sprintf(tmp, "oggenc ");
-		if (rawInput) {
-			tmp += sprintf(tmp, "--raw ");
-			tmp += sprintf(tmp, "--raw-chan=%d ", (rawAudioType.isStereo ? 2 : 1));
-			tmp += sprintf(tmp, "--raw-bits=%d ", rawAudioType.bitsPerSample);
-			tmp += sprintf(tmp, "--raw-rate=%d ", rawSamplerate);
-			tmp += sprintf(tmp, "--raw-endianness=%d ", (rawAudioType.isLittleEndian ? 0 : 1));
-		}
-
-		if (oggparms.nominalBitr != -1)
-			tmp += sprintf(tmp, "--bitrate=%d ", oggparms.nominalBitr);
-		if (oggparms.minBitr != -1)
-			tmp += sprintf(tmp, "--min-bitrate=%d ", oggparms.minBitr);
-		if (oggparms.maxBitr != -1)
-			tmp += sprintf(tmp, "--max-bitrate=%d ", oggparms.maxBitr);
-		if (oggparms.silent)
-			tmp += sprintf(tmp, "--quiet ");
-		tmp += sprintf(tmp, "--quality=%d ", oggparms.quality);
-		tmp += sprintf(tmp, "--output=\"%s\" ", outname);
-		tmp += sprintf(tmp, "\"%s\" ", inname);
-		err = system(fbuf) != 0;
-		break;
-
-	case kMP3Mode:
+	if (compmode == kMP3Mode) {
 		tmp += sprintf(tmp, "lame -t ");
 		if (rawInput) {
 			tmp += sprintf(tmp, "-r ");
 			tmp += sprintf(tmp, "--bitwidth %d ", rawAudioType.bitsPerSample);
-			if (rawAudioType.isLittleEndian)
+
+			if (rawAudioType.isLittleEndian) {
 				tmp += sprintf(tmp, "-x ");
+			}
+
 			tmp += sprintf(tmp, (rawAudioType.isStereo ? "-m j " : "-m m "));
 			tmp += sprintf(tmp, "-s %d ", rawSamplerate);
 		}
@@ -152,55 +124,451 @@
 			tmp += sprintf(tmp, "--vbr-new -b %d ", encparms.minBitr);
 
 		/* Explicitly specify a target sample rate, to work around a bug (?)
-		 * in newer lame versions (>= 3.95) which causes it to malfunction
-		 * for odd sample rates when in VBR mode. See also bug #934026.
-		 * We essentially duplicate the old behaviour of lame (found in e.g.
-		 * version 3.93.1): we round the input sample rate up to the next
-		 * higher valid MP3 sample rate, with a margin of 3%.
-		 */
-		if (rawSamplerate != -1)
+		* in newer lame versions (>= 3.95) which causes it to malfunction
+		* for odd sample rates when in VBR mode. See also bug #934026.
+		* We essentially duplicate the old behaviour of lame (found in e.g.
+		* version 3.93.1): we round the input sample rate up to the next
+		* higher valid MP3 sample rate, with a margin of 3%.
+		*/
+		if (rawSamplerate != -1) {
 			tmp += sprintf(tmp, "--resample %d ", map2MP3Frequency(97 * rawSamplerate / 100));
+		}
 
-		if (encparms.silent)
+		if (encparms.silent) {
 			tmp += sprintf(tmp, " --silent ");
+		}
+
 		tmp += sprintf(tmp, "-q %d ", encparms.algqual);
 		tmp += sprintf(tmp, "-V %d ", encparms.vbrqual);
 		tmp += sprintf(tmp, "-B %d ", encparms.maxBitr);
 		tmp += sprintf(tmp, "\"%s\" \"%s\" ", inname, outname);
+
 		err = system(fbuf) != 0;
-		break;
 
-	case kFlacMode:
-		/* --lax is needed to allow 11kHz, we dont need place for meta-tags, and no seektable */
-		/* -f is reqired to force override of unremoved temp file. See bug #1294648 */
-		tmp += sprintf(tmp, "flac --best -b 1152 -f --lax --no-padding --no-seektable --no-ogg ");
+		if (err) {
+			printf("Got error from encoder. (check your parameters)\n");
+			printf("Encoder Commandline: %s\n", fbuf );
+			exit(-1);
+		} else {
+			return;
+		}
+	}
 
+#ifdef DISABLE_VORBIS
+		if (compmode == kVorbisMode) {
+			tmp += sprintf(tmp, "oggenc ");
+			if (rawInput) {
+				tmp += sprintf(tmp, "--raw ");
+				tmp += sprintf(tmp, "--raw-chan=%d ", (rawAudioType.isStereo ? 2 : 1));
+				tmp += sprintf(tmp, "--raw-bits=%d ", rawAudioType.bitsPerSample);
+				tmp += sprintf(tmp, "--raw-rate=%d ", rawSamplerate);
+				tmp += sprintf(tmp, "--raw-endianness=%d ", (rawAudioType.isLittleEndian ? 0 : 1));
+			}
+
+			if (oggparms.nominalBitr != -1) {
+				tmp += sprintf(tmp, "--bitrate=%d ", oggparms.nominalBitr);
+			} else {
+				tmp += sprintf(tmp, "--quality=%d ", oggparms.quality);
+			}
+
+			if (oggparms.minBitr != -1) {
+				tmp += sprintf(tmp, "--min-bitrate=%d ", oggparms.minBitr);
+			}
+
+			if (oggparms.maxBitr != -1) {
+				tmp += sprintf(tmp, "--max-bitrate=%d ", oggparms.maxBitr);
+			}
+
+			if (oggparms.silent) {
+				tmp += sprintf(tmp, "--quiet ");
+			}
+
+			tmp += sprintf(tmp, "--output=\"%s\" ", outname);
+			tmp += sprintf(tmp, "\"%s\" ", inname);
+
+			err = system(fbuf) != 0;
+
+			if (err) {
+				printf("Got error from encoder. (check your parameters)\n");
+				printf("Encoder Commandline: %s\n", fbuf );
+				exit(-1);
+			} else {
+				return;
+			}
+		}
+#endif
+
+#ifdef DISABLE_FLAC
+		if (compmode == kFlacMode) {
+			/* --lax is needed to allow 11kHz, we dont need place for meta-tags, and no seektable */
+			/* -f is reqired to force override of unremoved temp file. See bug #1294648 */
+			tmp += sprintf(tmp, "flac -f --lax --no-padding --no-seektable --no-ogg ");
+
+			if (rawInput) {
+				tmp += sprintf(tmp, "--force-raw-format ");
+				tmp += sprintf(tmp, "--sign=%s ", ((rawAudioType.bitsPerSample == 8) ? "unsigned" : "signed"));
+				tmp += sprintf(tmp, "--channels=%d ", (rawAudioType.isStereo ? 2 : 1));
+				tmp += sprintf(tmp, "--bps=%d ", rawAudioType.bitsPerSample);
+				tmp += sprintf(tmp, "--sample-rate=%d ", rawSamplerate);
+				tmp += sprintf(tmp, "--endian=%s ", (rawAudioType.isLittleEndian ? "little" : "big"));
+			}
+
+			if (flacparms.silent) {
+				tmp += sprintf(tmp, "--silent ");
+			}
+
+			if (flacparms.verify) {
+				tmp += sprintf(tmp, "--verify ");
+			}
+
+			tmp += sprintf(tmp, "--compression-level-%d ", flacparms.compressionLevel);
+			tmp += sprintf(tmp, "-b %d ", flacparms.blocksize);
+			tmp += sprintf(tmp, "-o \"%s\" ", outname);
+			tmp += sprintf(tmp, "\"%s\" ", inname);
+
+			err = system(fbuf) != 0;
+
+			if (err) {
+				printf("Got error from encoder. (check your parameters)\n");
+				printf("Encoder Commandline: %s\n", fbuf );
+				exit(-1);
+			} else {
+				return;
+			}
+		}
+#endif
 		if (rawInput) {
-			tmp += sprintf(tmp, "--force-raw-format ");
-			tmp += sprintf(tmp, "--sign=%s ", (rawAudioType.isUnsigned ? "unsigned" : "signed"));
-			tmp += sprintf(tmp, "--channels=%d ", (rawAudioType.isStereo ? 2 : 1));
-			tmp += sprintf(tmp, "--bps=%d ", rawAudioType.bitsPerSample);
-			tmp += sprintf(tmp, "--sample-rate=%d ", rawSamplerate);
-			tmp += sprintf(tmp, "--endian=%s ", (rawAudioType.isLittleEndian ? "little" : "big"));
+			FILE *inputRaw;
+			long length;
+			char *rawData;
+
+			inputRaw = fopen(inname, "rb");
+			length = fileSize(inputRaw);
+			rawData = (char *)malloc(length);
+			fread(rawData, 1, length, inputRaw);
+
+			printf(" - length = %ld\n", length);
+			printf(" - channels = %d\n", (rawAudioType.isStereo ? 2 : 1));
+			printf(" - sample rate = %d\n", rawSamplerate);
+			printf(" - compression = %dbits\n", rawAudioType.bitsPerSample);
+
+			encodeRaw(rawData, length, rawSamplerate, outname, compmode);
+
+			fclose(inputRaw);
+			free(rawData);
+		} else {
+			FILE *inputWav;
+			int fmtHeaderSize, length, numChannels, sampleRate, bitsPerSample;
+			char *wavData;
+
+			inputWav = fopen(inname, "rb");
+
+			/* Standard PCM fmt header is 16 bits, but at least Simon 1 and 2 use 18 bits */
+			fseek(inputWav, 16, SEEK_SET);
+			fmtHeaderSize = readUint32LE(inputWav);
+
+			fseek(inputWav, 22, SEEK_SET);
+			numChannels = readUint16LE(inputWav);
+			sampleRate = readUint32LE(inputWav);
+
+			fseek(inputWav, 34, SEEK_SET);
+			bitsPerSample = readUint16LE(inputWav);
+
+			/* The size of the raw audio is after the RIFF chunk (12 bytes), fmt chunk (8 + fmtHeaderSize bytes), and data chunk id (4 bytes) */
+			fseek(inputWav, 24 + fmtHeaderSize, SEEK_SET);
+			length = readUint32LE(inputWav);
+
+			wavData = (char *)malloc(length);
+			fread(wavData, 1, length, inputWav);
+
+			printf(" - length = %d\n", length);
+			printf(" - channels = %d\n", numChannels);
+			printf(" - sample rate = %d\n", sampleRate);
+			printf(" - compression = %dbits\n", bitsPerSample);
+
+			setRawAudioType(true, numChannels == 2, bitsPerSample);
+			encodeRaw(wavData, length, sampleRate, outname, compmode);
+
+			fclose(inputWav);
+			free (wavData);
 		}
+}
 
-		for (i = 0; i < flacparms.numArgs; i++) {
-			/* Append optional encoder arguments */
-			tmp += sprintf(tmp, "%s ", flacparms.argv[i]);
+void encodeRaw(char *rawData, int length, int samplerate, const char *outname, CompressMode compmode) {
+#ifndef DISABLE_VORBIS
+	if (compmode == kVorbisMode) {
+		FILE *outputOgg;
+		char outputString[256] = "";
+		int numChannels = (rawAudioType.isStereo ? 2 : 1);
+		int totalSamples = length / ((rawAudioType.bitsPerSample / 8) * numChannels);
+		int samplesLeft = totalSamples;
+		int eos = 0;
+		int totalBytes = 0;
+
+		vorbis_info vi;
+		vorbis_comment vc;
+		vorbis_dsp_state vd;
+		vorbis_block vb;
+
+		ogg_stream_state os;
+		ogg_page og;
+		ogg_packet op;
+
+		ogg_packet header;
+		ogg_packet header_comm;
+		ogg_packet header_code;
+
+		outputOgg = fopen(outname,"wb");
+
+		vorbis_info_init(&vi);
+
+		if (oggparms.nominalBitr > 0) {
+			int result = 0;
+
+			/* Input is in kbps, function takes bps */
+			result = vorbis_encode_setup_managed(&vi, numChannels, samplerate, (oggparms.maxBitr > 0 ? 1000 * oggparms.maxBitr : -1), (1000 * oggparms.nominalBitr), (oggparms.minBitr > 0 ? 1000 * oggparms.minBitr : -1));
+
+			if (result == OV_EFAULT) {
+				printf("Error: Internal Logic Fault.\n\n");
+				vorbis_info_clear(&vi);
+				exit(-1);
+			} else if ((result == OV_EINVAL) || (result == OV_EIMPL)) {
+				printf("Error: Invalid bitrate parameters.\n\n");
+				vorbis_info_clear(&vi);
+				exit(-1);
+			}
+
+			if (!oggparms.silent) {
+				sprintf(outputString, "Encoding to\n         \"%s\"\nat average bitrate %i kbps (", outname, oggparms.nominalBitr);
+
+				if (oggparms.minBitr > 0) {
+					sprintf(outputString + strlen(outputString), "min %i kbps, ", oggparms.minBitr);
+				} else {
+					sprintf(outputString + strlen(outputString), "no min, ");
+				}
+
+				if (oggparms.maxBitr > 0) {
+					sprintf(outputString + strlen(outputString), "max %i kbps),\nusing full bitrate management engine\nSet optional hard quality restrictions\n", oggparms.maxBitr);
+				} else {
+					sprintf(outputString + strlen(outputString), "no max),\nusing full bitrate management engine\nSet optional hard quality restrictions\n");
+				}
+			}
+		} else {
+			int result = 0;
+
+			/* Quality input is 1 - 10, function takes -0.1 through 1.0 */
+			result = vorbis_encode_setup_vbr(&vi, numChannels, samplerate, oggparms.quality * 0.1);
+
+			if (result == OV_EFAULT) {
+				printf("Error: Internal Logic Fault.\n\n");
+				vorbis_info_clear(&vi);
+				exit(-1);
+			} else if ((result == OV_EINVAL) || (result == OV_EIMPL)) {
+				printf("Error: Invalid bitrate parameters.\n\n");
+				vorbis_info_clear(&vi);
+				exit(-1);
+			}
+
+			if (!oggparms.silent) {
+				sprintf(outputString, "Encoding to\n         \"%s\"\nat quality %2.2f", outname, oggparms.quality);
+			}
+
+			if ((oggparms.minBitr > 0) || (oggparms.maxBitr > 0)) {
+				struct ovectl_ratemanage_arg extraParam;
+				vorbis_encode_ctl(&vi, OV_ECTL_RATEMANAGE_GET, &extraParam);
+
+				extraParam.bitrate_hard_min = (oggparms.minBitr > 0 ? (1000 * oggparms.minBitr) : -1);
+				extraParam.bitrate_hard_max = (oggparms.maxBitr > 0 ? (1000 * oggparms.maxBitr) : -1);
+				extraParam.management_active = 1;
+
+				vorbis_encode_ctl(&vi, OV_ECTL_RATEMANAGE_SET, &extraParam);
+
+				if (!oggparms.silent) {
+					sprintf(outputString + strlen(outputString), " using constrained VBR (");
+
+					if (oggparms.minBitr != -1) {
+						sprintf(outputString + strlen(outputString), "min %i kbps, ", oggparms.minBitr);
+					} else {
+						sprintf(outputString + strlen(outputString), "no min, ");
+					}
+
+					if (oggparms.maxBitr != -1) {
+						sprintf(outputString + strlen(outputString), "max %i kbps)\nSet optional hard quality restrictions\n", oggparms.maxBitr);
+					} else {
+						sprintf(outputString + strlen(outputString), "no max)\nSet optional hard quality restrictions\n");
+					}
+				}
+			} else {
+				sprintf(outputString + strlen(outputString), "\n");
+			}
 		}
 
-		tmp += sprintf(tmp, "-o \"%s\" ", outname);
-		tmp += sprintf(tmp, "\"%s\" ", inname);
+		printf(outputString);
 
-		err = system(fbuf) != 0;
-		break;
+		vorbis_encode_setup_init(&vi);
+		vorbis_comment_init(&vc);
+		vorbis_analysis_init(&vd, &vi);
+		vorbis_block_init(&vd, &vb);
+		ogg_stream_init(&os, 0);
+		vorbis_analysis_headerout(&vd, &vc, &header, &header_comm, &header_code);
+
+		ogg_stream_packetin(&os, &header);
+		ogg_stream_packetin(&os, &header_comm);
+		ogg_stream_packetin(&os, &header_code);
+
+		while (!eos) {
+			int result = ogg_stream_flush(&os,&og);
+
+			if (result == 0) {
+				break;
+			}
+
+			fwrite(og.header, 1, og.header_len, outputOgg);
+			fwrite(og.body, 1, og.body_len, outputOgg);
+		}
+
+		while (!eos) {
+			int i, j;
+			int numSamples = ((samplesLeft < 2048) ? samplesLeft : 2048);
+			float **buffer = vorbis_analysis_buffer(&vd, numSamples);
+
+			/* We must tell the encoder that we have reached the end of the stream */
+			if (numSamples == 0) {
+				vorbis_analysis_wrote(&vd, 0);
+			} else {
+				/* Adapted from oggenc 1.1.1 */
+				if (rawAudioType.bitsPerSample == 8) {
+					unsigned char *rawDataUnsigned = (unsigned char *)rawData;
+					for (i = 0; i < numSamples; i++) {
+						for (j = 0; j < numChannels; j++) {
+							buffer[j][i] = ((int)(rawDataUnsigned[i * numChannels + j]) - 128) / 128.0f;
+						}
+					}
+				} else if(rawAudioType.bitsPerSample == 16) {
+					if(rawAudioType.isLittleEndian) {
+						for(i = 0; i < numSamples; i++) {
+							for(j = 0; j < numChannels; j++) {
+								buffer[j][i] = ((rawData[(i * 2 * numChannels) + (2 * j) + 1] << 8) | (rawData[(i * 2 * numChannels) + (2 * j)] & 0xff)) / 32768.0f;
+							}
+						}
+					}
+					else {
+						for(i = 0; i < numSamples; i++) {
+							for(j = 0; j < numChannels; j++) {
+								buffer[j][i] = ((rawData[(i * 2 * numChannels) + (2 * j)] << 8) | (rawData[(i * 2 * numChannels) + (2 * j) + 1] & 0xff)) / 32768.0f;
+							}
+						}
+					}
+				}
+
+				vorbis_analysis_wrote(&vd, numSamples);
+			}
+
+			while (vorbis_analysis_blockout(&vd, &vb) == 1) {
+				vorbis_analysis(&vb, NULL);
+				vorbis_bitrate_addblock(&vb);
+
+				while (vorbis_bitrate_flushpacket(&vd, &op)) {
+					ogg_stream_packetin(&os, &op);
+
+					while (!eos) {
+						int result = ogg_stream_pageout(&os, &og);
+
+						if(result == 0) {
+							break;
+						}
+
+						totalBytes += fwrite(og.header, 1, og.header_len, outputOgg);
+						totalBytes += fwrite(og.body, 1, og.body_len, outputOgg);
+
+						if(ogg_page_eos(&og)) {
+							eos = 1;
+						}
+					}
+				}
+			}
+
+			rawData += 2048 * (rawAudioType.bitsPerSample / 8) * numChannels;
+			samplesLeft -= 2048;
+		}
+
+		ogg_stream_clear(&os);
+		vorbis_block_clear(&vb);
+		vorbis_dsp_clear(&vd);
+		vorbis_info_clear(&vi);
+
+		fclose(outputOgg);
+
+		if (!oggparms.silent) {
+			printf("\nDone encoding file \"%s\"\n", outname);
+			printf("\n\tFile length:  %dm %ds\n", (int)(totalSamples / samplerate / 60), (totalSamples / samplerate % 60));
+			printf("\tAverage bitrate: %.1f kb/s\n\n", (8.0 * (double)totalBytes / 1000.0) / ((double)totalSamples / (double)samplerate));
+		}
 	}
+#endif
 
-	if (err) {
-		printf("Got error from encoder. (check your parameters)\n");
-		printf("Encoder Commandline: %s\n", fbuf );
-		exit(-1);
+#ifndef DISABLE_FLAC
+	if (compmode == kFlacMode) {
+		int i;
+		int numChannels = (rawAudioType.isStereo ? 2 : 1);
+		int samplesPerChannel = length / ((rawAudioType.bitsPerSample / 8) * numChannels);
+		FLAC__StreamEncoder *encoder;
+		FLAC__StreamEncoderInitStatus initStatus;
+		FLAC__int32 *flacData;
+
+		flacData = (FLAC__int32 *)malloc(samplesPerChannel * numChannels * sizeof(FLAC__int32));
+
+		if (rawAudioType.bitsPerSample == 8) {
+			for (i = 0; i < samplesPerChannel * numChannels; i++) {
+				FLAC__uint8 *rawDataUnsigned;
+				rawDataUnsigned = (FLAC__uint8 *)rawData;
+				flacData[i] = (FLAC__int32)rawDataUnsigned[i] - 0x80;
+			}
+		} else if (rawAudioType.bitsPerSample == 16) {
+			/* The rawData pointer is an 8-bit char so we must create a new pointer to access 16-bit samples */
+			FLAC__int16 *rawData16;
+			rawData16 = (FLAC__int16 *)rawData;
+			for (i = 0; i < samplesPerChannel * numChannels; i++) {
+				flacData[i] = (FLAC__int32)rawData16[i];
+			}
+		}
+
+		if (!flacparms.silent) {
+			printf("Encoding to\n         \"%s\"\nat compression level %d using blocksize %d\n\n", outname, flacparms.compressionLevel, flacparms.blocksize);
+		}
+
+		encoder = FLAC__stream_encoder_new();
+
+		FLAC__stream_encoder_set_bits_per_sample(encoder, rawAudioType.bitsPerSample);
+		FLAC__stream_encoder_set_blocksize(encoder, flacparms.blocksize);
+		FLAC__stream_encoder_set_channels(encoder, numChannels);
+		FLAC__stream_encoder_set_compression_level(encoder, flacparms.compressionLevel);
+		FLAC__stream_encoder_set_sample_rate(encoder, samplerate);
+		FLAC__stream_encoder_set_streamable_subset(encoder, false);
+		FLAC__stream_encoder_set_total_samples_estimate(encoder, samplesPerChannel);
+		FLAC__stream_encoder_set_verify(encoder, flacparms.verify);
+
+		initStatus = FLAC__stream_encoder_init_file(encoder, outname, NULL, NULL);
+
+		if (initStatus != FLAC__STREAM_ENCODER_INIT_STATUS_OK) {
+			printf("Got error from encoder. (check your paramters)\n");
+			printf("FLAC error: %s\n\n", FLAC__StreamEncoderInitStatusString[initStatus]);
+			exit(-1);
+		} else {
+			FLAC__stream_encoder_process_interleaved(encoder, flacData, samplesPerChannel);
+		}
+
+		FLAC__stream_encoder_finish(encoder);
+		FLAC__stream_encoder_delete(encoder);
+
+		free(flacData);
+
+		if (!flacparms.silent) {
+			printf("\nDone encoding file \"%s\"\n", outname);
+			printf("\n\tFile length:  %dm %ds\n\n", (int)(samplesPerChannel / samplerate / 60), (samplesPerChannel / samplerate % 60));
+		}
 	}
+#endif
 }
 
 void extractAndEncodeWAV(const char *outName, FILE *input, CompressMode compMode) {
@@ -261,6 +629,7 @@
 		length = fgetc(input);
 		length |= fgetc(input) << 8;
 		length |= fgetc(input) << 16;
+
 		if (blocktype == 1) {
 			length -= 2;
 			sample_rate = fgetc(input);
@@ -287,14 +656,18 @@
 				  (comp == 3 ? "2bits"   :
 								"Multi")))), comp);
 
-		if (comp != 0)
+		if (comp != 0) {
 			error("Cannot handle compressed VOC data");
+		}
 
 		/* Copy the raw data to a temporary file */
 		while (length > 0) {
 			size = fread(fbuf, 1, length > sizeof(fbuf) ? sizeof(fbuf) : (uint32)length, input);
-			if (size <= 0)
+
+			if (size <= 0) {
 				break;
+			}
+
 			length -= (int)size;
 			fwrite(fbuf, 1, size, f);
 		}
@@ -304,7 +677,7 @@
 
 	assert(real_samplerate != -1);
 
-	setRawAudioType(false, false, true, 8);
+	setRawAudioType(false, false, 8);
 
 	/* Convert the raw temp file to OGG/MP3 */
 	encodeAudio(outName, true, real_samplerate, tempEncoded, compMode);
@@ -313,40 +686,64 @@
 int process_mp3_parms(int argc, char *argv[], int i) {
 	for (; i < argc; i++) {
 		if (strcmp(argv[i], "--vbr") == 0) {
-			encparms.abr=0;
+			encparms.abr = 0;
 		} else if (strcmp(argv[i], "--abr") == 0) {
-			encparms.abr=1;
+			encparms.abr = 1;
 		} else if (strcmp(argv[i], "-b") == 0) {
 			encparms.minBitr = atoi(argv[i + 1]);
-			if ((encparms.minBitr % 8) != 0)
+
+			if ((encparms.minBitr % 8) != 0) {
 				encparms.minBitr -= encparms.minBitr % 8;
-			if (encparms.minBitr >160)
+			}
+
+			if (encparms.minBitr > 160) {
 				encparms.minBitr = 160;
-			if (encparms.minBitr < 8)
-				encparms.minBitr=8;
+			}
+
+			if (encparms.minBitr < 8) {
+				encparms.minBitr = 8;
+			}
+
 			i++;
 		} else if (strcmp(argv[i], "-B") == 0) {
 			encparms.maxBitr = atoi(argv[i + 1]);
-			if ((encparms.maxBitr % 8) != 0)
+
+			if ((encparms.maxBitr % 8) != 0) {
 				encparms.maxBitr -= encparms.maxBitr % 8;
-			if (encparms.maxBitr > 160)
+			}
+
+			if (encparms.maxBitr > 160) {
 				encparms.maxBitr = 160;
-			if (encparms.maxBitr < 8)
+			}
+
+			if (encparms.maxBitr < 8) {
 				encparms.maxBitr = 8;
+			}
+
 			i++;
 		} else if (strcmp(argv[i], "-V") == 0) {
 			encparms.vbrqual = atoi(argv[i + 1]);
-			if(encparms.vbrqual < 0)
+
+			if(encparms.vbrqual < 0) {
 				encparms.vbrqual = 0;
-			if(encparms.vbrqual > 9)
+			}
+
+			if(encparms.vbrqual > 9) {
 				encparms.vbrqual = 9;
+			}
+
 			i++;
 		} else if (strcmp(argv[i], "-q") == 0) {
 			encparms.algqual = atoi(argv[i + 1]);
-			if (encparms.algqual < 0)
+
+			if (encparms.algqual < 0) {
 				encparms.algqual = 0;
-			if (encparms.algqual > 9)
+			}
+
+			if (encparms.algqual > 9) {
 				encparms.algqual = 9;
+			}
+
 			i++;
 		} else if (strcmp(argv[i], "--silent") == 0) {
 			encparms.silent = 1;
@@ -358,9 +755,11 @@
 			break;
 		}
 	}
+
 	if (i != (argc - 1)) {
 		return 0;
 	}
+
 	return 1;
 }
 
@@ -368,14 +767,52 @@
 	for (; i < argc; i++) {
 		if (strcmp(argv[i], "-b") == 0) {
 			oggparms.nominalBitr = atoi(argv[i + 1]);
+
+			if ((oggparms.nominalBitr % 8) != 0) {
+				oggparms.nominalBitr -= oggparms.nominalBitr % 8;
+			}
+
+			if (oggparms.nominalBitr >160) {
+				oggparms.nominalBitr = 160;
+			}
+
+			if (oggparms.nominalBitr < 8) {
+				oggparms.nominalBitr = 8;
+			}
+
 			i++;
-		}
-		else if (strcmp(argv[i], "-m") == 0) {
+		} else if (strcmp(argv[i], "-m") == 0) {
 			oggparms.minBitr = atoi(argv[i + 1]);
+
+			if ((oggparms.minBitr % 8) != 0) {
+				oggparms.minBitr -= oggparms.minBitr % 8;
+			}
+
+			if (oggparms.minBitr >160) {
+				oggparms.minBitr = 160;
+			}
+
+			if (oggparms.minBitr < 8) {
+				oggparms.minBitr = 8;
+			}
+
 			i++;
 		}
 		else if (strcmp(argv[i], "-M") == 0) {
 			oggparms.maxBitr = atoi(argv[i + 1]);
+
+			if ((oggparms.maxBitr % 8) != 0) {
+				oggparms.maxBitr -= encparms.minBitr % 8;
+			}
+
+			if (oggparms.maxBitr >160) {
+				oggparms.maxBitr = 160;
+			}
+
+			if (oggparms.maxBitr < 8) {
+				oggparms.maxBitr = 8;
+			}
+
 			i++;
 		}
 		else if (strcmp(argv[i], "-q") == 0) {
@@ -391,19 +828,77 @@
 		else if (argv[i][0] == '-') {
 			return 0;
 		}
-		else
+		else {
 			break;
+		}
 	}
-	if (i != argc - 1)
+
+	if (i != argc - 1) {
 		return 0;
+	}
+
 	return 1;
 }
 
 int process_flac_parms(int argc, char *argv[], int i){
-	flacparms.argv = &argv[i];
-	flacparms.numArgs = argc - 1 - i;
+	for (; i < argc; i++) {
+		if (strcmp(argv[i], "-b") == 0) {
+			flacparms.blocksize = atoi(argv[i + 1]);
+			i++;
+		}
+		else if (strcmp(argv[i], "--fast") == 0) {
+			flacparms.compressionLevel = 0;
+		}
+		else if (strcmp(argv[i], "--best") == 0) {
+			flacparms.compressionLevel = 8;
+		}
+		else if (strcmp(argv[i], "-0") == 0) {
+			flacparms.compressionLevel = 0;
+		}
+		else if (strcmp(argv[i], "-1") == 0) {
+			flacparms.compressionLevel = 1;
+		}
+		else if (strcmp(argv[i], "-2") == 0) {
+			flacparms.compressionLevel = 2;
+		}
+		else if (strcmp(argv[i], "-3") == 0) {
+			flacparms.compressionLevel = 3;
+		}
+		else if (strcmp(argv[i], "-4") == 0) {
+			flacparms.compressionLevel = 4;
+		}
+		else if (strcmp(argv[i], "-5") == 0) {
+			flacparms.compressionLevel = 5;
+		}
+		else if (strcmp(argv[i], "-6") == 0) {
+			flacparms.compressionLevel = 6;
+		}
+		else if (strcmp(argv[i], "-7") == 0) {
+			flacparms.compressionLevel = 7;
+		}
+		else if (strcmp(argv[i], "-8") == 0) {
+			flacparms.compressionLevel = 8;
+		}
+		else if (strcmp(argv[i], "--verify") == 0) {
+			flacparms.verify = true;
+		}
+		else if (strcmp(argv[i], "--silent") == 0) {
+			flacparms.silent = true;
+		}
+		else if (strcmp(argv[i], "--help") == 0) {
+			return 0;
+		}
+		else if (argv[i][0] == '-') {
+			return 0;
+		}
+		else {
+			break;
+		}
+	}
 
-	if (i >= argc)
+	if (i != argc - 1) {
 		return 0;
+	}
+
 	return 1;
 }

Modified: tools/trunk/compress.h
===================================================================
--- tools/trunk/compress.h	2008-01-28 20:40:05 UTC (rev 30689)
+++ tools/trunk/compress.h	2008-01-28 20:41:00 UTC (rev 30690)
@@ -24,6 +24,8 @@
 #define EXTRACT_H
 
 #include "util.h"
+#include <vorbis/vorbisenc.h>
+#include <FLAC/stream_encoder.h>
 
 #if defined(__cplusplus)
 extern "C" {
@@ -38,6 +40,10 @@
 /* The default for oggenc invocation is to use the --quality option only */
 #define oggqualDef 3
 
+/* These are the default parameters for the FLAC invocation */
+#define flacCompressDef 8
+#define flacBlocksizeDef 1152
+
 #define TEMP_WAV	"tempfile.wav"
 #define TEMP_RAW	"tempfile.raw"
 #define TEMP_MP3	"tempfile.mp3"
@@ -60,7 +66,8 @@
 extern void extractAndEncodeWAV(const char *outName, FILE *input, CompressMode compMode);
 
 extern void encodeAudio(const char *inname, bool rawInput, int rawSamplerate, const char *outname, CompressMode compmode);
-extern void setRawAudioType(bool isLittleEndian, bool isStereo, bool isUnSigned, uint8 bitsPerSample);
+extern void encodeRaw(char *rawData, int length, int samplerate, const char *outname, CompressMode compmode);
+extern void setRawAudioType(bool isLittleEndian, bool isStereo, uint8 bitsPerSample);
 
 #if defined(__cplusplus)
 }

Modified: tools/trunk/compress_agos.c
===================================================================
--- tools/trunk/compress_agos.c	2008-01-28 20:40:05 UTC (rev 30689)
+++ tools/trunk/compress_agos.c	2008-01-28 20:41:00 UTC (rev 30690)
@@ -29,22 +29,23 @@
 
 static CompressMode gCompMode = kMP3Mode;
 
-static char infile_base[256];
-
-static void end(void)
-{
+static void end(char *inputPath, char* inputFile) {
 	int size;
 	char fbuf[2048];
-	char tmp[256];
+	char tmp[1024];
+	char *p;
 	const char *head;
 
 	switch (gCompMode) {
 	case kMP3Mode:
-		head = "mp3"; break;
+		head = "mp3";
+		break;
 	case kVorbisMode:
-		head = "ogg"; break;
+		head = "ogg";
+		break;
 	case kFlacMode:
-		head = "fla"; break;
+		head = "fla";
+		break;
 	default:
 		error("Unknown compression mode");
 	}
@@ -53,18 +54,29 @@
 	fclose(output_idx);
 	fclose(input);
 
-	sprintf(tmp, "%s.%s", infile_base, head);
+	/* Remove the extension from the filename if it exists
+	 * so that we can append the new extension
+	*/
+	p = strrchr(inputFile, '.');
+	if (p) {
+		*p = '\0';
+	}
+
+	sprintf(tmp, "%s/%s.%s", inputPath, inputFile, head);
 	output_idx = fopen(tmp, "wb");
 
 	input = fopen(TEMP_IDX, "rb");
 	while ((size = fread(fbuf, 1, 2048, input)) > 0) {
 		fwrite(fbuf, 1, size, output_idx);
 	}
+
 	fclose(input);
+
 	input = fopen(TEMP_DAT, "rb");
 	while ((size = fread(fbuf, 1, 2048, input)) > 0) {
 		fwrite(fbuf, 1, size, output_idx);
 	}
+
 	fclose(input);
 	fclose(output_idx);
 
@@ -74,13 +86,12 @@
 	unlink(TEMP_RAW);
 	unlink(tempEncoded);
 	unlink(TEMP_WAV);
-	
+
 	exit(0);
 }
 
-	
-static int get_offsets(uint32 filenums[], uint32 offsets[])
-{
+
+static int get_offsets(uint32 filenums[], uint32 offsets[]) {
 	int i;
 	char buf[8];
 
@@ -95,23 +106,20 @@
 	}
 }
 
-static int get_offsets_mac(uint32 filenums[], uint32 offsets[])
-{
+static int get_offsets_mac(uint32 filenums[], uint32 offsets[]) {
 	int i, size;
-	fseek(input, 0, SEEK_END);
-	size = ftell(input);
-	fseek(input, 0, SEEK_SET);
+	size = fileSize(input);
 
 	for (i = 1; i <= size / 6; i++) {
 		filenums[i] = readUint16BE(input);
 		offsets[i] = readUint32BE(input);
 	}
+
 	return(size/6);
 }
 
 
-static uint32 get_sound(uint32 offset)
-{
+static uint32 get_sound(uint32 offset) {
 	FILE *f;
 	uint32 tot_size;
 	char outname[256];
@@ -146,14 +154,14 @@
 	return(tot_size);
 }
 
-void showhelp(char *exename)
-{
-	printf("\nUsage: %s <params> [<file> | mac]\n", exename);
+void showhelp(char *exename) {
+	printf("\nUsage: %s [params] [--mac] <file>\n", exename);
 
 	printf("\nParams:\n");
 	printf(" --mp3        encode to MP3 format (default)\n");
 	printf(" --vorbis     encode to Vorbis format\n");
 	printf(" --flac       encode to Flac format\n");
+	printf(" --mac        encode simon2mac sounds\n");
 	printf("(If one of these is specified, it must be the first parameter.)\n");
 
 	printf("\nMP3 mode params:\n");
@@ -173,41 +181,34 @@
 	printf(" --silent     the output of oggenc is hidden (default:disabled)\n");
 
 	printf("\nFlac mode params:\n");
-	printf(" [params]     optional arguments passed directly to the encoder\n");
-	printf("              recommended is: --best -b 1152\n");
+ 	printf(" --fast       FLAC uses compresion level 0\n");
+ 	printf(" --best       FLAC uses compresion level 8\n");
+ 	printf(" -<value>     specifies the value (0 - 8) of compresion (8=best)(default:%d)\n", flacCompressDef);
+ 	printf(" -b <value>   specifies a blocksize of <value> samples (default:%d)\n", flacBlocksizeDef);
+	printf(" --verify     files are encoded and then decoded to check accuracy\n");
+ 	printf(" --silent     the output of FLAC is hidden (default:disabled)\n");
 
 	printf("\n --help     this help message\n");
 
 	printf("\n\nIf a parameter is not given the default value is used\n");
 	printf("If using VBR mode for MP3 -b and -B must be multiples of 8; the maximum is 160!\n");
-	printf("Use the `mac' option instead of a filename if converting simon2mac sounds\n");
+	printf("\nIf converting simon2mac sounds, use the --mac option\n");
+	printf("and replace <file> with the path to the 'voices' folder\n");
+	printf("If the input directory is the same as the current directory use '.'\n");
 	exit(2);
 }
 
 
-static void convert_pc(char *infile)
-{
+static void convert_pc(char *inputPath, char *inputFile) {
 	int i, size, num;
+	char tmp[1024];
 	uint32 filenums[32768];
 	uint32 offsets[32768];
-	char *p;
 
-	p = strrchr(infile, '/');
-	if (!p) {
-		p = strrchr(infile, '\\');
-		if (!p) {
-			p = infile - 1;
-		}
-	}
-	strcpy(infile_base, p + 1);
-	p = strrchr(infile_base, '.');
-	if (p) {
-		*p = '\0';
-	}
-
-	input = fopen(infile, "rb");
+	sprintf(tmp, "%s/%s", inputPath, inputFile);
+	input = fopen(tmp, "rb");
 	if (!input) {
-		printf("Cannot open file: %s\n", infile);
+		printf("Cannot open file: %s\n", tmp);
 		exit(-1);
 	}
 
@@ -224,18 +225,17 @@
 	}
 
 	num = get_offsets(filenums, offsets);
-
 	if (!num) {
 		printf("This does not seem to be a valid file\n");
 		exit(-1);
 	}
-	size = num*4;
+	size = num * 4;
 
 	writeUint32LE(output_idx, 0);
 	writeUint32LE(output_idx, size);
 
 	for (i = 1; i < num; i++) {
-		if (offsets[i] == offsets[i+1]) {
+		if (offsets[i] == offsets[i + 1]) {
 			writeUint32LE(output_idx, size);
 			continue;
 		}
@@ -247,16 +247,14 @@
 	}
 }
 
-static void convert_mac(void)
-{
+static void convert_mac(char *inputPath) {
 	int i, size, num;
-	char tmp[256];
+	char tmp[1024];
 	uint32 filenums[32768];
 	uint32 offsets[32768];
-	
-	sprintf(infile_base, "simon2");
 
-	input = fopen("voices.idx", "rb");
+	sprintf(tmp, "%s/voices.idx", inputPath);
+	input = fopen(tmp, "rb");
 	if (!input) {
 		printf("Cannot open file: %s\n", "voices.idx");
 		exit(-1);
@@ -275,27 +273,29 @@
 	}
 
 	num = get_offsets_mac(filenums, offsets);
-
 	if (!num) {
 		printf("This does not seem to be a valid file\n");
 		exit(-1);
 	}
-	size = num*4;
+	size = num * 4;
 
 	writeUint32LE(output_idx, 0);
 	writeUint32LE(output_idx, size);
 
 	for (i = 1; i < num; i++) {
-		if (filenums[i] == filenums[i+1] && offsets[i] == offsets[i+1]) {
+		if (filenums[i] == filenums[i + 1] && offsets[i] == offsets[i + 1]) {
 			writeUint32LE(output_idx, size);
 			continue;
 		}
 
-		if (filenums[i] != filenums[i-1]) {
-			sprintf(tmp, "voices%d.dat", filenums[i]);
-			if (input)
+		if (filenums[i] != filenums[i - 1]) {
+			sprintf(tmp, "%s/voices%d.dat", inputPath, filenums[i]);
+
+			if (input) {
 				fclose(input);
-			input = fopen(tmp, "rb"); 
+			}
+
+			input = fopen(tmp, "rb");
 			if (!input) {
 				printf("Cannot open file: %s\n", tmp);
 				exit(-1);
@@ -303,61 +303,78 @@
 		}
 
 		size += get_sound(offsets[i]);
-		if (i < num - 1)
+
+		if (i < num - 1) {
 			writeUint32LE(output_idx, size);
+		}
 	}
 }
 
-int main(int argc, char *argv[])
-{
+int main(int argc, char *argv[]) {
 	int i;
-	
-	if (argc < 2)
+	char inputFile[256];
+	char inputPath[768];
+	bool convertMac = false;
+
+	if (argc < 2) {
 		showhelp(argv[0]);
+	}
 
 	/* compression mode */
 	gCompMode = kMP3Mode;
 	i = 1;
-	if (strcmp(argv[1], "--mp3") == 0) {
+
+	if (strcmp(argv[i], "--mp3") == 0) {
 		gCompMode = kMP3Mode;
 		i++;
-	}
-	else if (strcmp(argv[1], "--vorbis") == 0) {
+	} else if (strcmp(argv[i], "--vorbis") == 0) {
 		gCompMode = kVorbisMode;
 		i++;
-	}
-	else if (strcmp(argv[1], "--flac") == 0) {
+	} else if (strcmp(argv[i], "--flac") == 0) {
 		gCompMode = kFlacMode;
 		i++;
 	}
 
+	if (strcmp(argv[i], "--mac") == 0) {
+		convertMac = true;
+		i++;
+	}
+
 	switch (gCompMode) {
 	case kMP3Mode:
 		tempEncoded = TEMP_MP3;
-		if (!process_mp3_parms(argc, argv, i))
+		if (!process_mp3_parms(argc, argv, i)) {
 			showhelp(argv[0]);
+		}
+
 		break;
 	case kVorbisMode:
 		tempEncoded = TEMP_OGG;
-		if (!process_ogg_parms(argc, argv, i))
+		if (!process_ogg_parms(argc, argv, i)) {
 			showhelp(argv[0]);
+		}
+
 		break;
 	case kFlacMode:
 		tempEncoded = TEMP_FLAC;
-		if (!process_flac_parms(argc, argv, i))
+		if (!process_flac_parms(argc, argv, i)) {
 			showhelp(argv[0]);
+		}
+
 		break;
 	}
 
-	i = argc - 1;
-
-	if (strcmp(argv[i], "mac") == 0) {
-		convert_mac();
+	if (convertMac) {
+		strcpy(inputFile, "simon2");
+		strcpy(inputPath, argv[argc - 1]);
+		convert_mac(inputPath);
 	} else {
-		convert_pc(argv[i]);
+		getPath(argv[argc - 1], inputPath);
+		getFilename(argv[argc - 1], inputFile);
+		convert_pc(inputPath, inputFile);
 	}
 
-	end();
+	end(inputPath, inputFile);
 
 	return(0);
 }

Modified: tools/trunk/compress_kyra.cpp
===================================================================
--- tools/trunk/compress_kyra.cpp	2008-01-28 20:40:05 UTC (rev 30689)
+++ tools/trunk/compress_kyra.cpp	2008-01-28 20:41:00 UTC (rev 30690)
@@ -39,10 +39,14 @@
 	if (argc < 3)
 		showhelp(argv[0]);
 
+	char inputFile[1024];
+	char outputFile[1024];
 	int i = 0;
+
 	/* Compression mode */
 	gCompMode = kMP3Mode;
 	i = 1;
+
 	if (strcmp(argv[1], "--mp3") == 0) {
 		gCompMode = kMP3Mode;
 		i++;
@@ -60,31 +64,37 @@
 	case kMP3Mode:
 		outputExt = OUTPUT_MP3;
 		tempEncoded = TEMP_MP3;
-		if (!process_mp3_parms(argc - 1, argv, i))
+		if (!process_mp3_parms(argc - 2, argv, i))
 			showhelp(argv[0]);
 		break;
 	case kVorbisMode:
 		outputExt = OUTPUT_OGG;
 		tempEncoded = TEMP_OGG;
-		if (!process_ogg_parms(argc - 1, argv, i))
+		if (!process_ogg_parms(argc - 2, argv, i))
 			showhelp(argv[0]);
 		break;
 	case kFlacMode:
 		outputExt = OUTPUT_FLAC;
 		tempEncoded = TEMP_FLAC;
-		if (!process_flac_parms(argc - 1, argv, i))
+		if (!process_flac_parms(argc - 2, argv, i))
 			showhelp(argv[0]);
 		break;
 	}
-	
-	if (scumm_stricmp(argv[argc - 2], argv[argc - 1]) == 0)
+
+	sprintf(inputFile, "%s/%s", argv[argc - 2], argv[argc - 3]);
+	sprintf(outputFile, "%s/%s", argv[argc - 1], argv[argc - 3]);
+
+	if (scumm_stricmp(inputFile, outputFile) == 0) {
 		error("infile and outfile are the same file");
-	process(argv[argc - 2], argv[argc - 1]);
+	}
+
+	process(inputFile, outputFile);
+
 	return 0;
 }
 
 static void showhelp(const char *exename) {
-	printf("\nUsage: %s <params> infile outfile\n", exename);
+	printf("\nUsage: %s [params] <file> <inputdir> <outputdir>\n", exename);
 
 	printf("\nParams:\n");
 	printf(" --mp3        encode to MP3 format (default)\n");
@@ -109,7 +119,12 @@
 	printf(" --silent     the output of oggenc is hidden (default:disabled)\n");
 
 	printf("\nFlac mode params:\n");
-	printf(" [params]     optional arguments passed directly to the encoder\n");
+ 	printf(" --fast       FLAC uses compresion level 0\n");
+ 	printf(" --best       FLAC uses compresion level 8\n");
+ 	printf(" -<value>     specifies the value (0 - 8) of compresion (8=best)(default:%d)\n", flacCompressDef);
+ 	printf(" -b <value>   specifies a blocksize of <value> samples (default:%d)\n", flacBlocksizeDef);
+	printf(" --verify     files are encoded and then decoded to check accuracy\n");
+	printf(" --silent     the output of FLAC is hidden (default:disabled)\n");
 
 	printf("\n --help     this help message\n");
 
@@ -121,26 +136,35 @@
 
 static bool hasSuffix(const char *str, const char *suf) {
 	const int sufSize = strlen(suf);
+
 	int off = strlen(str);
 	if (off < sufSize)
 		return false;
+
 	off -= sufSize;
 	printf("'%s'\n", &str[off]);
+
 	return (scumm_stricmp(&str[off], suf) == 0);
 }
 
 static void process(const char *infile, const char *outfile) {
 	PAKFile input, output;
-	if (!input.loadFile(infile, false))
+
+	if (!input.loadFile(infile, false)) {
 		return;
-	if (!output.loadFile(0, false))
+	}
+
+	if (!output.loadFile(0, false)) {
 		return;
-		
+	}
+
 	PAKFile::cFileList *list = input.getFileList();
 	char outputName[32];
+
 	for (; list; list = list->next) {
-		if (!hasSuffix(list->filename, ".VOC"))
+		if (!hasSuffix(list->filename, ".VOC")) {
 			continue;
+		}
 
 		if (list->data[26] != 1) {
 			warning("broken VOC file '%s' skipping it...", list->filename);
@@ -149,22 +173,24 @@
 
 		input.outputFileAs(list->filename, TEMPFILE);
 		strncpy(outputName, list->filename, 32);
-		
+
 		FILE *tempFile = fopen(TEMPFILE, "rb");
 		fseek(tempFile, 26, SEEK_CUR);
 		extractAndEncodeVOC(TEMP_RAW, tempFile, gCompMode);
 		fclose(tempFile);
-		
+
 		char *vocStart = strstr(outputName, ".VOC");
-		for (unsigned int i = 0; i < strlen(outputExt); ++i)
+		for (unsigned int i = 0; i < strlen(outputExt); ++i) {
 			vocStart[i] = outputExt[i];
+		}
+
 		output.addFile(outputName, tempEncoded);
-		
+
 		unlink(TEMPFILE);
 		unlink(TEMP_RAW);
 		unlink(tempEncoded);
 	}
-	
+
 	if (output.getFileList()) {
 		output.saveFile(outfile);
 	} else {

Modified: tools/trunk/compress_queen.c
===================================================================
--- tools/trunk/compress_queen.c	2008-01-28 20:40:05 UTC (rev 30689)
+++ tools/trunk/compress_queen.c	2008-01-28 20:41:00 UTC (rev 30690)
@@ -20,9 +20,10 @@
  *
  */
 
-#include "util.h"
+#include "compress.h"
 
 static const uint32 QTBL = 'QTBL';
+static CompressMode gCompMode = kMP3Mode;
 
 #define INPUT_TBL	"queen.tbl"
 #define FINAL_OUT	"queen.1c"
@@ -31,18 +32,11 @@
 #define TEMP_TBL	"tempfile.tbl"
 #define TEMP_SB		"tempfile.sb"
 
-#define TEMP_MP3	"tempfile.mp3"
-#define TEMP_OGG	"tempfile.ogg"
-#define TEMP_FLAC	"tempfile.fla"
-
-const char *tempEncoded;
-
 #define CURRENT_TBL_VERSION	2
 #define EXTRA_TBL_HEADER 8
 #define SB_HEADER_SIZE_V104 110
 #define SB_HEADER_SIZE_V110 122
 
-
 enum {
 	COMPRESSION_NONE = 0,
 	COMPRESSION_MP3 = 1,
@@ -123,29 +117,60 @@
 
 const struct GameVersion *version;
 
+void showhelp(char *exename) {
+	printf("\nUsage: %s [params] queen.1\n", exename);
 
-void showhelp(char *exename)
-{
-	printf("\nUsage: %s [--mp3/--vorbis/--flac <args>] queen.1\n", exename);
 	printf("\nParams:\n");
-	printf(" --mp3 <args>         encode to MP3 format\n");
-	printf(" --vorbis <args>      encode to Ogg Vorbis Format\n");
-	printf(" --flac <args>        encode to Flac Format\n");
-	printf("                      (Optional: <args> are passed on to the encoder)\n");
-	printf("\nExample: %s --mp3 -q 5 queen.1\n", exename);
+
+	printf(" --mp3        encode to MP3 format (default)\n");
+	printf(" --vorbis     encode to Ogg Vorbis format\n");
+	printf(" --flac       encode to Flac format\n");
+	printf("(If one of these is specified, it must be the first parameter.)\n");
+
+	printf("\nMP3 mode params:\n");
+	printf(" -b <rate>    <rate> is the target bitrate(ABR)/minimal bitrate(VBR) (default:%d)\n", minBitrDef);
+	printf(" -B <rate>    <rate> is the maximum VBR/ABR bitrate (default:%d)\n", maxBitrDef);
+	printf(" --vbr        LAME uses the VBR mode (default)\n");
+	printf(" --abr        LAME uses the ABR mode\n");
+	printf(" -V <value>   specifies the value (0 - 9) of VBR quality (0=best) (default:%d)\n", vbrqualDef);
+	printf(" -q <value>   specifies the MPEG algorithm quality (0-9; 0=best) (default:%d)\n", algqualDef);
+	printf(" --silent     the output of LAME is hidden (default:disabled)\n");
+
+	printf("\nVorbis mode params:\n");
+	printf(" -b <rate>    <rate> is the nominal bitrate (default:unset)\n");
+	printf(" -m <rate>    <rate> is the minimum bitrate (default:unset)\n");
+	printf(" -M <rate>    <rate> is the maximum bitrate (default:unset)\n");
+	printf(" -q <value>   specifies the value (0 - 10) of VBR quality (10=best) (default:%d)\n", oggqualDef);
+	printf(" --silent     the output of oggenc is hidden (default:disabled)\n");
+
+	printf("\nFlac mode params:\n");
+	printf(" --fast       FLAC uses compresion level 0\n");
+	printf(" --best       FLAC uses compresion level 8\n");
+	printf(" -<value>     specifies the value (0 - 8) of compresion (8=best)(default:%d)\n", flacCompressDef);
+	printf(" -b <value>   specifies a blocksize of <value> samples (default:%d)\n", flacBlocksizeDef);
+	printf(" --verify     files are encoded and then decoded to check accuracy\n");
+	printf(" --silent     the output of FLAC is hidden (default:disabled)\n");
+
+	printf("\n --help     this help message\n");
+
+	printf("\n\nIf a parameter is not given the default value is used\n");
+	printf("If using VBR mode for MP3 -b and -B must be multiples of 8; the maximum is 160!\n");
 	exit(2);
 }
 
 const struct GameVersion *detectGameVersion(uint32 size) {
 	const struct GameVersion *pgv = gameVersions;
 	int i;
+
 	/* Compressing/rebuiling an Amiga version is not supported */
 	for (i = 0; i < VER_PC_COUNT; ++i, ++pgv) {
 		if (pgv->dataFileSize == size) {
 			return pgv;
 		}
  	}
+
 	printf("Unknown/unsupported FOTAQ version!\n");
+
 	exit(1);
 	return NULL;
 }
@@ -160,17 +185,21 @@
 void fromFileToFile(FILE *in, FILE *out, uint32 amount) {
 	char fBuf[2048];
 	uint32 numRead;
+
 	while (amount > 0) {
 		numRead = fread(fBuf, 1, amount > 2048 ? 2048 : amount, in);
-		if (numRead <= 0)
+		if (numRead <= 0) {
 			break;
+		}
+
 		amount -= numRead;
 		fwrite(fBuf, 1, numRead, out);
 	}
 }
 
-void createFinalFile(void) {
+void createFinalFile(char *inputPath) {
 	FILE *inTbl, *inData, *outFinal;
+	char tmp[1024];
 	int i;
 	uint32 dataStartOffset;
 	uint32 dataSize;
@@ -179,7 +208,8 @@
 	checkOpen(inTbl, TEMP_TBL);
 	inData = fopen(TEMP_DAT, "rb");
 	checkOpen(inData, TEMP_DAT);
-	outFinal = fopen(FINAL_OUT, "wb");
+	sprintf(tmp, "%s/%s", inputPath, FINAL_OUT);
+	outFinal = fopen(tmp, "wb");
 	checkOpen(outFinal, FINAL_OUT);
 
 	dataStartOffset = fileSize(inTbl) + EXTRA_TBL_HEADER;
@@ -214,75 +244,84 @@
 	unlink(TEMP_DAT);
 }
 
-int main(int argc, char *argv[])
-{
+int main(int argc, char *argv[]) {
 	FILE *inputData, *inputTbl, *outputTbl, *outputData, *tmpFile, *compFile;
 	uint8 compressionType = COMPRESSION_NONE;
+	char inputPath[768];
+	char tblPath[1024];
 	char tmp[5];
-	char sysBuf[1024];
-	char *ptr = sysBuf;
 	int size, i = 1;
 	uint32 prevOffset;
 
-
-	if (argc < 2)
+	if (argc < 2) {
 		showhelp(argv[0]);
+	}
 
+	/* compression mode */
+	compressionType = COMPRESSION_MP3;
+	gCompMode = kMP3Mode;
+
 	if (strcmp(argv[1], "--mp3") == 0) {
 		compressionType = COMPRESSION_MP3;
-		tempEncoded = TEMP_MP3;
+		gCompMode = kMP3Mode;
 		i++;
-		ptr += sprintf(ptr, "lame -r -h -s 11 --bitwidth 8 -m m ");
-		for (; i < (argc - 1); i++) {
-			/* Append optional encoder arguments */
-			ptr += sprintf(ptr, "%s ", argv[i]);
-		}
-		ptr += sprintf(ptr, "%s %s", TEMP_SB, tempEncoded);
 	} else if (strcmp(argv[1], "--vorbis") == 0) {
 		compressionType = COMPRESSION_OGG;
-		tempEncoded = TEMP_OGG;
+		gCompMode = kVorbisMode;
 		i++;
-		ptr += sprintf(ptr, "oggenc -r -B 8 -C 1 -R 11025 %s -o %s ", TEMP_SB, tempEncoded);
-		for (; i < (argc - 1); i++) {
-			/* Append optional encoder arguments */
-			ptr += sprintf(ptr, "%s ", argv[i]);
-		}
 	} else if (strcmp(argv[1], "--flac") == 0) {
 		compressionType = COMPRESSION_FLAC;
-		tempEncoded = TEMP_FLAC;
+		gCompMode = kFlacMode;
 		i++;
-		ptr += sprintf(ptr, "flac --force-raw-format --endian=little --sign=unsigned --bps=8 --channels=1 --sample-rate=11025 " );
-		ptr += sprintf(ptr, "--no-padding --lax --no-seektable --no-ogg " );
-		for (; i < (argc - 1); i++) {
-			/* Append optional encoder arguments */
-			ptr += sprintf(ptr, "%s ", argv[i]);
+	}
+
+	switch (gCompMode) {
+	case kMP3Mode:
+		tempEncoded = TEMP_MP3;
+		if (!process_mp3_parms(argc, argv, i)) {
+			showhelp(argv[0]);
 		}
 
-		ptr += sprintf(ptr, "-o %s %s", tempEncoded, TEMP_SB );
-	} else {
-		showhelp(argv[0]);
+		break;
+	case kVorbisMode:
+		tempEncoded = TEMP_OGG;
+		if (!process_ogg_parms(argc, argv, i)) {
+			showhelp(argv[0]);
+		}
+
+		break;
+	case kFlacMode:
+		tempEncoded = TEMP_FLAC;
+		if (!process_flac_parms(argc, argv, i)) {
+			showhelp(argv[0]);
+		}
+
+		break;
 	}
 
+	getPath(argv[argc - 1], inputPath);
+
 	/* Open input file (QUEEN.1) */
 	inputData = fopen(argv[argc-1], "rb");
 	checkOpen(inputData, argv[argc-1]);
 
 	/* Open TBL file (QUEEN.TBL) */
-	inputTbl = fopen(INPUT_TBL, "rb");
+	sprintf(tblPath, "%s/%s", inputPath, INPUT_TBL);
+	inputTbl = fopen(tblPath, "rb");
 	checkOpen(inputTbl, INPUT_TBL);
 
 	size = fileSize(inputData);
 	fread(tmp, 1, 4, inputTbl);
 	tmp[4] = '\0';
+
 	if (memcmp(tmp, "QTBL", 4)) {
-		printf("Invalid TBL file!\n");
-		exit(-1);
+		error("Invalid TBL file");
 	}
 
 	if (readUint32BE(inputTbl) != CURRENT_TBL_VERSION) {
-		printf("Error: You are using an incorrect (outdated?) version of the queen.tbl file\n");
-		exit(1);
+		error("You are using an incorrect (outdated?) version of the queen.tbl file");
 	}
+
 	version = detectGameVersion(size);
 	fseek(inputTbl, version->tableOffset, SEEK_SET);
 
@@ -323,6 +362,7 @@
 
 			fseek(inputData, 2, SEEK_CUR);
 			sbVersion = readUint16LE(inputData);
+
 			switch (sbVersion) {
 			case 104:
 				headerSize = SB_HEADER_SIZE_V104;
@@ -335,6 +375,7 @@
 				headerSize = SB_HEADER_SIZE_V104;
 				break;
 			}
+
 			fseek(inputData, headerSize - 4, SEEK_CUR);
 			entry.size -= headerSize;
 
@@ -342,11 +383,8 @@
 			fclose(tmpFile);
 
 			/* Invoke encoder */
-			if (system(sysBuf)) {
-				printf("Got error from encoder. (check your parameters)\n");
-				unlink(TEMP_SB);
-				exit(-1);
-			}
+			setRawAudioType(false, false, 8);
+			encodeAudio(TEMP_SB, true, 11025, tempEncoded, gCompMode);
 
 			/* Append MP3/OGG to data file */
 			compFile = fopen(tempEncoded, "rb");
@@ -361,12 +399,15 @@
 			/* Non .SB file */
 			bool patched = false;
 			/* Check for external files */
+
 			uint8 j;
 			for (j = 0; j < ARRAYSIZE(patchFiles); ++j) {
 				const struct PatchFile *pf = &patchFiles[j];
+
 				if (version->versionString[1] == pf->lang && strcmp(pf->filename, entry.filename) == 0) {
 					/* XXX patched data files are supposed to be in cwd */
 					FILE *fpPatch = fopen(pf->filename, "rb");
+
 					if (fpPatch) {
 						entry.size = fileSize(fpPatch);
 						printf("Patching entry, new size = %d bytes\n", entry.size);
@@ -374,9 +415,11 @@
 						fclose(fpPatch);
 						patched = true;
 					}
+
 					break;
 				}
 			}
+
 			if (!patched) {
 				fromFileToFile(inputData, outputData, entry.size);
 			}
@@ -396,7 +439,7 @@
 	fclose(inputData);
 
 	/* Merge the temporary table and temporary datafile to create final file */
-	createFinalFile();
+	createFinalFile(inputPath);
 
 	return 0;
 }

Modified: tools/trunk/compress_saga.cpp
===================================================================
--- tools/trunk/compress_saga.cpp	2008-01-28 20:40:05 UTC (rev 30689)
+++ tools/trunk/compress_saga.cpp	2008-01-28 20:41:00 UTC (rev 30690)
@@ -19,7 +19,7 @@
  *
  * $URL$
  * $Id$
- * 
+ *
  */
 
 #include "compress.h"
@@ -214,7 +214,7 @@
 	uint32 size;
 	char fbuf[2048];
 	FILE * tempf;
-	
+
 	tempf = fopen(fromFileName, "rb");
 	if (tempf == NULL)
 		error("Unable to open %s", fromFileName);
@@ -231,7 +231,7 @@
 	uint32 size;
 	char fbuf[2048];
 	FILE * tempf;
-	
+
 	tempf = fopen(toFileName, "wb");
 	if (tempf == NULL)
 		error("Unable to open %s", toFileName);
@@ -248,7 +248,7 @@
 
 void writeBufferToFile(uint8* data, uint32 inputSize, const char* toFileName) {
 	FILE * tempf;
-	
+
 	tempf = fopen(toFileName, "wb");
 	if (tempf == NULL)
 		error("Unable to open %s", toFileName);
@@ -283,7 +283,7 @@
 		writeBufferToFile(inputData, sampleSize, TEMP_RAW);
 		free(inputData);
 
-		setRawAudioType( true, false, false, 8);
+		setRawAudioType( true, false, 8);
 		encodeAudio(TEMP_RAW, true, sampleRate, tempEncoded, gCompMode);
 		return copyFile(tempEncoded, outputFile) + HEADER_SIZE;
 	}
@@ -296,7 +296,7 @@
 
 		copyFile(inputFile, inputSize, TEMP_RAW);
 
-		setRawAudioType( !currentFileDescription->swapEndian, sampleStereo != 0, false, sampleBits);
+		setRawAudioType( !currentFileDescription->swapEndian, sampleStereo != 0, sampleBits);
 		encodeAudio(TEMP_RAW, true, sampleRate, tempEncoded, gCompMode);
 		return copyFile(tempEncoded, outputFile) + HEADER_SIZE;
 	}
@@ -312,7 +312,7 @@
 
 		copyFile(inputFile, size, TEMP_RAW);
 
-		setRawAudioType( true, sampleStereo != 0, false, sampleBits);
+		setRawAudioType( true, sampleStereo != 0, sampleBits);
 		encodeAudio(TEMP_RAW, true, sampleRate, tempEncoded, gCompMode);
 		return copyFile(tempEncoded, outputFile) + HEADER_SIZE;
 	}
@@ -333,7 +333,7 @@
 		writeBufferToFile((uint8 *)buffer, sampleSize, TEMP_RAW);
 		free(buffer);
 
-		setRawAudioType( !currentFileDescription->swapEndian, sampleStereo != 0, false, sampleBits);
+		setRawAudioType( !currentFileDescription->swapEndian, sampleStereo != 0, sampleBits);
 		encodeAudio(TEMP_RAW, true, sampleRate, tempEncoded, gCompMode);
 		return copyFile(tempEncoded, outputFile) + HEADER_SIZE;
 	}
@@ -351,7 +351,7 @@
 		sampleStereo = currentFileDescription->stereo;
 		writeHeader(outputFile);
 
-		setRawAudioType( !currentFileDescription->swapEndian, currentFileDescription->stereo, false, sampleBits);
+		setRawAudioType( !currentFileDescription->swapEndian, currentFileDescription->stereo, sampleBits);
 		encodeAudio(TEMP_RAW, true, currentFileDescription->frequency, tempEncoded, gCompMode);
 		return copyFile(tempEncoded, outputFile) + HEADER_SIZE;
 		*/
@@ -360,7 +360,7 @@
 	error("Unsupported resourceType %ul\n", currentFileDescription->resourceType);
 }
 
-void sagaEncode(const char *inputFileName, const char *inputFileNameExt) {
+void sagaEncode(const char *inputPath, const char *inputFileName, const char *inputFileNameExt) {
 	char inputFileNameWithExt[256];
 	char outputFileNameWithExt[256];
 	FILE *inputFile;
@@ -373,7 +373,7 @@
 	Record *inputTable;
 	Record *outputTable;
 
-	sprintf(inputFileNameWithExt, "%s%s", inputFileName, inputFileNameExt);
+	sprintf(inputFileNameWithExt, "%s/%s%s", inputPath, inputFileName, inputFileNameExt);
 	inputFile = fopen(inputFileNameWithExt, "rb");
 	inputFileSize = fileSize(inputFile);
 	printf("Filesize: %ul\n", inputFileSize);
@@ -397,24 +397,24 @@
 		error("Something's wrong with your resource file");
 	}
 
-	// Go to beginning of the table 
+	// Go to beginning of the table
 	fseek(inputFile, resTableOffset, SEEK_SET);
 
 	inputTable = (Record*)malloc(resTableCount * sizeof(Record));
 
-	// Put offsets of all the records in a table 
+	// Put offsets of all the records in a table
 	for (i = 0; i < resTableCount; i++) {
 
-	if (!currentFileDescription->swapEndian) {
-		inputTable[i].offset = readUint32LE(inputFile);
-		inputTable[i].size = readUint32LE(inputFile);
-	} else {
-		inputTable[i].offset = readUint32BE(inputFile);
-		inputTable[i].size = readUint32BE(inputFile);
-	}
+		if (!currentFileDescription->swapEndian) {
+			inputTable[i].offset = readUint32LE(inputFile);
+			inputTable[i].size = readUint32LE(inputFile);
+		} else {
+			inputTable[i].offset = readUint32BE(inputFile);
+			inputTable[i].size = readUint32BE(inputFile);
+		}
 
-		 printf("Record: %ul, offset: %ul, size: %ul\n", i, inputTable[i].offset, inputTable[i].size);
-	
+		printf("Record: %ul, offset: %ul, size: %ul\n", i, inputTable[i].offset, inputTable[i].size);
+
 		if ((inputTable[i].offset > inputFileSize) ||
 		    (inputTable[i].offset + inputTable[i].size > inputFileSize)) {
 			error("The offset points outside the file");
@@ -423,13 +423,13 @@
 	}
 	outputTable = (Record*)malloc(resTableCount * sizeof(Record));
 
-	sprintf(outputFileNameWithExt, "%s.cmp", inputFileName);	
+	sprintf(outputFileNameWithExt, "%s/%s.cmp", inputPath, inputFileName);
 	outputFile = fopen(outputFileNameWithExt, "wb");
 
 	for (i = 0; i < resTableCount; i++) {
 		fseek(inputFile, inputTable[i].offset, SEEK_SET);
 		outputTable[i].offset = ftell(outputFile);
-		
+
 		if (inputTable[i].size >= 8) {
 			outputTable[i].size = encodeEntry(inputFile, inputTable[i].size, outputFile);
 		} else {
@@ -444,13 +444,13 @@
 		writeUint32LE(outputFile, outputTable[i].size);
 	}
 	writeUint32LE(outputFile, resTableOffset);
-	writeUint32LE(outputFile, resTableCount);	// Should be the same number of entries 
+	writeUint32LE(outputFile, resTableCount);	// Should be the same number of entries
 
 	fclose(outputFile);
 
 	free(inputTable);
 	free(outputTable);
-	
+
 	// Cleanup
 	unlink(TEMP_RAW);
 	unlink(tempEncoded);
@@ -485,7 +485,12 @@
 	printf("--silent     the output of oggenc is hidden (default:disabled)\n");
 
 	printf("\nFlac mode params:\n");
-	printf("[params]     optional Arguments passed to the Encoder\n");
+ 	printf(" --fast       FLAC uses compresion level 0\n");
+ 	printf(" --best       FLAC uses compresion level 8\n");
+ 	printf(" -<value>     specifies the value (0 - 8) of compresion (8=best)(default:%d)\n", flacCompressDef);
+ 	printf(" -b <value>   specifies a blocksize of <value> samples (default:%d)\n", flacBlocksizeDef);
+	printf(" --verify     files are encoded and then decoded to check accuracy\n");
+ 	printf(" --silent     the output of FLAC is hidden (default:disabled)\n");
 
 	printf("\n--help     this help message\n");
 
@@ -495,8 +500,9 @@
 }
 
 int main(int argc, char *argv[]) {
-	int		i;
-	char *inputFileName;
+	int	i;
+	char inputPath[768];
+	char inputFileName[256];
 	char inputFileNameWithExt[256];
 
 	if (argc < 2) {
@@ -539,30 +545,31 @@
 		break;
 	}
 
-	inputFileName = argv[argc - 1];
+	getPath(argv[argc - 1], inputPath);
+	getFilename(argv[argc - 1], inputFileName);
 
 	if (strrchr(inputFileName, '.') != NULL) {
 		error("Please specify the filename without an extension");
 	}
 
 	// ITE
-	sprintf(inputFileNameWithExt, "%s.rsc", inputFileName);
+	sprintf(inputFileNameWithExt, "%s/%s.rsc", inputPath, inputFileName);
 	if (detectFile(inputFileNameWithExt)) {
-		sagaEncode(inputFileName, ".rsc");
+		sagaEncode(inputPath, inputFileName, ".rsc");
 	} else {
 		// IHNM
-		sprintf(inputFileNameWithExt, "%s.res", inputFileName);
+		sprintf(inputFileNameWithExt, "%s/%s.res", inputPath, inputFileName);
 		if (detectFile(inputFileNameWithExt)) {
-			sagaEncode(inputFileName, ".res");
+			sagaEncode(inputPath, inputFileName, ".res");
 		} else {
 			// Check for "inherit the earth voices"
 			if (detectFile("inherit the earth voices")) {
-				sagaEncode("inherit the earth voices", "");
+				sagaEncode(inputPath, "inherit the earth voices", "");
 			} else {
 				// Check for MacBinary
-				sprintf(inputFileNameWithExt, "%s.bin", inputFileName);
+				sprintf(inputFileNameWithExt, "%s/%s.bin", inputPath, inputFileName);
 				if (detectFile(inputFileNameWithExt)) {
-					sagaEncode(inputFileName, ".bin");
+					sagaEncode(inputPath, inputFileName, ".bin");
 				}
 			}
 		}

Modified: tools/trunk/compress_scumm_bun.cpp
===================================================================
--- tools/trunk/compress_scumm_bun.cpp	2008-01-28 20:40:05 UTC (rev 30689)
+++ tools/trunk/compress_scumm_bun.cpp	2008-01-28 20:41:00 UTC (rev 30690)
@@ -614,12 +614,12 @@
 }
 
 void showhelp(char *exename) {
-	printf("\nUsage: %s <inputfile> <inputdir> <outputdir> [params] [encoder params]\n", exename);
-
+	printf("\nUsage: %s [params] <file> <inputdir> <outputdir>\n", exename);
 	printf("\nParams:\n");
 	printf(" --mp3        encode to MP3 format (default)\n");
 	printf(" --vorbis     encode to Vorbis format\n");
 	printf(" --flac       encode to Flac format\n");
+	printf("(If one of these is specified, it must be the first parameter.)\n");
 
 	printf("\nMP3 mode params:\n");
 	printf(" -b <rate>    <rate> is the target bitrate(ABR)/minimal bitrate(VBR) (default:%d)\n", minBitrDef);
@@ -638,8 +638,17 @@
 	printf(" --silent     the output of oggenc is hidden (default:disabled)\n");
 
 	printf("\nFlac mode params:\n");
-	printf(" [params]     optional arguments passed directly to the encoder\n");
+ 	printf(" --fast       FLAC uses compresion level 0\n");
+ 	printf(" --best       FLAC uses compresion level 8\n");
+ 	printf(" -<value>     specifies the value (0 - 8) of compresion (8=best)(default:%d)\n", flacCompressDef);
+ 	printf(" -b <value>   specifies a blocksize of <value> samples (default:%d)\n", flacBlocksizeDef);
+	printf(" --verify     files are encoded and then decoded to check accuracy\n");
+ 	printf(" --silent     the output of FLAC is hidden (default:disabled)\n");
 
+	printf("\n --help     this help message\n");
+
+	printf("\n\nIf a parameter is not given the default value is used\n");
+	printf("If using VBR mode for MP3 -b and -B must be multiples of 8; the maximum is 160!\n");
 	exit(2);
 }
 
@@ -1122,75 +1131,50 @@
 	if (argc < 4)
 		showhelp(argv[0]);
 
-	char inputDir[200];
-	char outputDir[200];
-	char inputFilename[200];
-	char tmpPath[200];
+	char inputDir[768];
+	char outputDir[768];
+	char inputFilename[256];
+	char tmpPath[768];
 
 	uint32 tag;
-	int32 numFiles, offset, i;
+	int32 numFiles, offset;
+	int i = 1;
 
-	strcpy(inputFilename, argv[1]);
-	strcpy(inputDir, argv[2]);
-	strcpy(outputDir, argv[3]);
+	strcpy(inputFilename, argv[argc - 3]);
+	strcpy(inputDir, argv[argc - 2]);
+	strcpy(outputDir, argv[argc - 1]);
 
-	if (argc > 4) {
-		i = 4;
+	if (!strcmp(argv[i], "--mp3")) {
+		gCompMode = kMP3Mode;
+		i++;
+	} else if (!strcmp(argv[i], "--vorbis")) {
+		gCompMode = kVorbisMode;
+		i++;
+	} else if (!strcmp(argv[i], "--flac")) {
+		gCompMode = kFlacMode;
+		i++;
+	}
 
-		if (!strcmp(argv[i], "--mp3")) {
-			gCompMode = kMP3Mode;
-			i++;
-		} else if (!strcmp(argv[i], "--vorbis")) {
-			gCompMode = kVorbisMode;
-			i++;
-		} else if (!strcmp(argv[i], "--flac")) {
-			gCompMode = kFlacMode;
-			i++;
-		}
-
-		if (argc > i) {
-			// HACK: The functions in compress.c expect the last
-			// argument to be a filename. As we don't expect one,
-			// we simply add a dummy argument to the list.
-			char **args = (char **)malloc((argc + 1) * sizeof(char *));
-			char dummyName[] = "dummy";
-			int j;
-
-			for (j = 0; j < argc; j++)
-				args[j] = argv[j];
-			args[j] = dummyName;
-		
-			switch (gCompMode) {
-			case kMP3Mode:
-				if (!process_mp3_parms(argc + 1, args, i)) {
-					showhelp(argv[0]);
-				}
-
-				break;
-			case kVorbisMode:
-				if (!process_ogg_parms(argc + 1, args, i)) {
-					showhelp(argv[0]);
-				}
-
-				break;
-			case kFlacMode:
-				if (!process_flac_parms(argc + 1, args, i)){
-					showhelp(argv[0]);
-				}
-
-				break;
-			default:
-				error("Unknown encoding method");
-			}
-
-			free(args);
-		}
+	switch (gCompMode) {
+	case kMP3Mode:
+		if (!process_mp3_parms(argc - 2, argv, i))
+			showhelp(argv[0]);
+		break;
+	case kVorbisMode:
+		if (!process_ogg_parms(argc - 2, argv, i))
+			showhelp(argv[0]);
+		break;
+	case kFlacMode:
+		if (!process_flac_parms(argc - 2, argv, i))
+			showhelp(argv[0]);
+		break;
+	default:
+		error("Unknown encoding method");
 	}
 
 	char *index = strrchr(inputFilename, '.');
-	if (index != NULL) {
+	if (index != NULL)
 		*index = 0;
-	}
 
 	sprintf(tmpPath, "%s/%s.bun", inputDir, inputFilename);
 
@@ -1226,7 +1210,7 @@
 		char filename[13], c;
 		int z = 0;
 		int z2;
-			
+
 		for (z2 = 0; z2 < 8; z2++)
 			if ((c = readByte(input)) != 0)
 				filename[z++] = c;
@@ -1266,6 +1250,6 @@
 	fclose(input);
 
 	printf("compression done.\n");
-		
+
 	return 0;
 }

Modified: tools/trunk/compress_scumm_san.cpp
===================================================================
--- tools/trunk/compress_scumm_san.cpp	2008-01-28 20:40:05 UTC (rev 30689)
+++ tools/trunk/compress_scumm_san.cpp	2008-01-28 20:41:00 UTC (rev 30690)
@@ -24,7 +24,7 @@
 #include "zlib.h"
 
 void showhelp(char *exename) {
-	printf("\nUsage: %s <inputfile> <inputdir> <outputdir> [--ogg] [encoder params]\n", exename);
+	printf("\nUsage: %s [--vorbis] [params] <file> <inputdir> <outputdir>\n", exename);
 	printf("\nMP3 mode params:\n");
 	printf(" -b <rate>    <rate> is the target bitrate(ABR)/minimal bitrate(VBR) (default:%d)\n", minBitrDef);
 	printf(" -B <rate>    <rate> is the maximum VBR/ABR bitrate (default:%d)\n", maxBitrDef);
@@ -654,47 +654,32 @@
 	if (argc < 4)
 		showhelp(argv[0]);
 
-	char inputDir[200];
-	char outputDir[200];
-	char inputFilename[200];
-	char tmpPath[200];
+	char inputDir[768];
+	char outputDir[768];
+	char inputFilename[256];
+	char tmpPath[768];
 
-	strcpy(inputFilename, argv[1]);
-	strcpy(inputDir, argv[2]);
-	strcpy(outputDir, argv[3]);
+	strcpy(inputFilename, argv[argc - 3]);
+	strcpy(inputDir, argv[argc - 2]);
+	strcpy(outputDir, argv[argc - 1]);
 
 	if (argc > 4) {
-		int i = 4;
+		int result;
+		int i = 1;
 
-		if (strcmp(argv[i], "--ogg") == 0) {
+		if (strcmp(argv[1], "--vorbis") == 0) {
 			_oggMode = true;
 			i++;
 		}
 
-		if (argc > i) {
-			// HACK: The functions in compress.c expect the last
-			// argument to be a filename. As we don't expect one,
-			// we simply add a dummy argument to the list.
-			char **args = (char **)malloc((argc + 1) * sizeof(char *));
-			char dummyName[] = "dummy";
-			int j;
 
-			for (j = 0; j < argc; j++)
-				args[j] = argv[j];
-			args[j] = dummyName;
-		
-			int result;
+		if (_oggMode)
+			result = process_ogg_parms(argc - 2, argv, i);
+		else
+			result = process_mp3_parms(argc - 2, argv, i);
 
-			if (_oggMode)
-				result = process_ogg_parms(argc + 1, args, i);
-			else
-				result = process_mp3_parms(argc + 1, args, i);
-
-			if (!result)
-				showhelp(argv[0]);
-
-			free(args);
-		}
+		if (!result)
+			showhelp(argv[0]);
 	}
 
 	char *index = strrchr(inputFilename, '.');
@@ -919,10 +904,10 @@
 	}
 
 	free(frameInfo);
-	
+
 	fclose(output);
 
 	printf("compression done.\n");
-		
+
 	return 0;
 }

Modified: tools/trunk/compress_scumm_sou.c
===================================================================
--- tools/trunk/compress_scumm_sou.c	2008-01-28 20:40:05 UTC (rev 30689)
+++ tools/trunk/compress_scumm_sou.c	2008-01-28 20:41:00 UTC (rev 30690)
@@ -41,17 +41,18 @@
 static CompressMode gCompMode = kMP3Mode;
 
 
-void end_of_file(void)
-{
+void end_of_file(char *inputPath) {
 	FILE *in;
 	int idx_size = ftell(output_idx);
 	size_t size;
+	char tmp[1024];
 	char buf[2048];
 
 	fclose(output_snd);
 	fclose(output_idx);
 
-	output_idx = fopen(outputName , "wb");
+	sprintf(tmp, "%s/%s", inputPath, outputName);
+	output_idx = fopen(tmp , "wb");
 	writeUint32BE(output_idx, (uint32)idx_size);
 
 	in = fopen(TEMP_IDX, "rb");
@@ -72,20 +73,18 @@
 	unlink(TEMP_DAT);
 	unlink(TEMP_RAW);
 	unlink(tempEncoded);
-	
+
 	exit(-1);
 }
 
-void append_byte(int size, char buf[])
-{
+void append_byte(int size, char buf[]) {
 	int i;
 	for (i = 0; i < (size - 1); i++)
 		buf[i] = buf[i + 1];
 	buf[i] = fgetc(input);
 }
 
-void get_part(void)
-{
+void get_part(char *inputPath) {
 	FILE *f;
 	uint32 tot_size;
 	char outname[256];
@@ -103,8 +102,9 @@
 		pos++;
 		append_byte(4, buf);
 		if (feof(input))
-			end_of_file();
+			end_of_file(inputPath);
 	}
+
 	tags = readUint32BE(input);
 	if (tags < 8)
 		exit(-1);
@@ -119,18 +119,17 @@
 	}
 
 	fread(buf, 1, 8, input);
-	if (!memcmp(buf, "Creative", 8)) {
+	if (!memcmp(buf, "Creative", 8))
 		fseek(input, 18, SEEK_CUR);
-	} else if (!memcmp(buf, "VTLK", 4)) {
+	else if (!memcmp(buf, "VTLK", 4))
 		fseek(input, 26, SEEK_CUR);
-	} else {
+	else
 		error("Unexpected data encountered");
-	}
 	printf("Voice file found (pos = %d) :", pos);
 
-	/* Conver the VOC data */
+	/* Convert the VOC data */
 	extractAndEncodeVOC(TEMP_RAW, input, gCompMode);
-	
+
 	/* Append the converted data to the master output file */
 	sprintf(outname, tempEncoded);
 	f = fopen(outname, "rb");
@@ -144,9 +143,8 @@
 	writeUint32BE(output_idx, tot_size);
 }
 
-void showhelp(char *exename)
-{
-	printf("\nUsage: %s <params> monster.sou\n", exename);
+void showhelp(char *exename) {
+	printf("\nUsage: %s [params] monster.sou\n", exename);
 
 	printf("\nParams:\n");
 	printf(" --mp3        encode to MP3 format (default)\n");
@@ -171,8 +169,12 @@
 	printf(" --silent     the output of oggenc is hidden (default:disabled)\n");
 
 	printf("\nFlac mode params:\n");
-	printf(" [params]     optional arguments passed directly to the encoder\n");
-	printf("              recommended is: --best -b 1152\n");
+ 	printf(" --fast       FLAC uses compresion level 0\n");
+ 	printf(" --best       FLAC uses compresion level 8\n");
+ 	printf(" -<value>     specifies the value (0 - 8) of compresion (8=best)(default:%d)\n", flacCompressDef);
+ 	printf(" -b <value>   specifies a blocksize of <value> samples (default:%d)\n", flacBlocksizeDef);
+	printf(" --verify     files are encoded and then decoded to check accuracy\n");
+ 	printf(" --silent     the output of FLAC is hidden (default:disabled)\n");
 
 	printf("\n --help     this help message\n");
 
@@ -181,24 +183,26 @@
 	exit(2);
 }
 
-int main(int argc, char *argv[])
-{
+int main(int argc, char *argv[]) {
+	char inputPath[768];
 	char buf[2048];
 	int i;
-	if (argc < 2)
+
+	if (argc < 2) {
 		showhelp(argv[0]);
+	}
+
 	/* Compression mode */
 	gCompMode = kMP3Mode;
 	i = 1;
+
 	if (strcmp(argv[1], "--mp3") == 0) {
 		gCompMode = kMP3Mode;
 		i++;
-	}
-	else if (strcmp(argv[1], "--vorbis") == 0) {
+	} else if (strcmp(argv[1], "--vorbis") == 0) {
 		gCompMode = kVorbisMode;
 		i++;
-	}
-	else if (strcmp(argv[1], "--flac") == 0) {
+	} else if (strcmp(argv[1], "--flac") == 0) {
 		gCompMode = kFlacMode;
 		i++;
 	}
@@ -224,9 +228,9 @@
 		break;
 	}
 
+	getPath(argv[argc - 1], inputPath);
 
-	i = argc - 1;
-	input = fopen(argv[i], "rb");
+	input = fopen(argv[argc - 1], "rb");
 	if (!input) {
 		printf("Cannot open file: %s\n", argv[i]);
 		exit(-1);
@@ -242,14 +246,16 @@
 		printf("Can't open file " TEMP_DAT " for write!\n");
 		exit(-1);
 	}
-	
+
 	/* Get the 'SOU ....' header */
 	fread(buf, 1, 8, input);
 	if (strncmp(buf, f_hdr, 8)) {
 		printf("Bad SOU\n");
 		exit(-1);
 	}
+
 	while (1)
-		get_part();
+		get_part(inputPath);
+
 	return 0;
 }

Modified: tools/trunk/compress_sword1.c
===================================================================
--- tools/trunk/compress_sword1.c	2008-01-28 20:40:05 UTC (rev 30689)
+++ tools/trunk/compress_sword1.c	2008-01-28 20:41:00 UTC (rev 30690)
@@ -28,6 +28,7 @@
 #define TOTAL_TUNES 269
 
 char tempOutName[16];
+char inputDir[256];
 
 typedef struct {
 	char fileName[8];
@@ -116,7 +117,7 @@
 	{ "2M26", false },
 	{ "3M7", false },
 	{ "3M8", false },
-	{ "3M9", true }, 
+	{ "3M9", true },
 	{ "3M10", false },
 	{ "2M13", false },
 	{ "3M12", false },
@@ -163,7 +164,7 @@
 	{ "4M31", false },
 	{ "4M32", false },
 	{ "5M1", false },
-	{ "5M2", true }, 
+	{ "5M2", true },
 	{ "5M3", false },
 	{ "5M4", false },
 	{ "5M5", false },
@@ -275,7 +276,7 @@
 	{ "11M4", false },
 	{ "11M7", false },
 	{ "11M8", false },
-	{ "11M9", true }, 
+	{ "11M9", true },
 	{ "12M1", false },
 	{ "11M2", false },
 	{ "SPM2", false },
@@ -308,7 +309,7 @@
 };
 
 void showhelp(char *exename) {
-	printf("\nUsage: %s <params>\n", exename);
+	printf("\nUsage: %s [params] <inputdir>\n", exename);
 
 	printf("\nParams:\n");
 	printf(" --mp3          encode to MP3 format (default)\n");
@@ -337,12 +338,20 @@
 	printf("                (default:%d)\n", oggqualDef);
 	printf(" --silent       the output of oggenc is hidden (default:disabled)\n");
 
+	printf("\nFlac mode params:\n");
+ 	printf(" --fast       FLAC uses compresion level 0\n");
+ 	printf(" --best       FLAC uses compresion level 8\n");
+ 	printf(" -<value>     specifies the value (0 - 8) of compresion (8=best)(default:%d)\n", flacCompressDef);
+ 	printf(" -b <value>   specifies a blocksize of <value> samples (default:%d)\n", flacBlocksizeDef);
+	printf(" --verify     files are encoded and then decoded to check accuracy\n");
+ 	printf(" --silent     the output of FLAC is hidden (default:disabled)\n");
+
 	printf("\n --help         this help message\n");
 
 	printf("\nIf a parameter is not given the default value is used\n");
 	printf("If using VBR mode for MP3 -b and -B must be multiples of 8; the maximum is 160!\n");
-	printf("\nPlease run this tool from your BS1 main directory.\n");
-	printf("(The one with the subdirectories \"MUSIC\" and \"SPEECH\")\n");
+	printf("\nMake sure the input directory contains the \"MUSIC\" and \"SPEECH\" subdirectories.\n");
+	printf("If the input directory is the same as the current directory use '.'\n");
 	exit(2);
 }
 
@@ -391,6 +400,7 @@
 uint8 *convertData(uint8 *rawData, uint32 rawSize, CompressMode compMode, uint32 *resSize) {
 	FILE *temp;
 	uint8 *resBuf;
+
 	uint32 size;
 	temp = fopen(TEMP_RAW, "wb");
 	assert(fwrite(rawData, 1, rawSize, temp) == rawSize);
@@ -419,11 +429,13 @@
 
 	assert(!(headerSize & 3));
 	cowHeader = (uint32*)malloc(headerSize);
+
 	for (cnt = 0; cnt < (headerSize / 4) - 1; cnt++)
 		cowHeader[cnt] = readUint32LE(clu);
 	assert(!(cowHeader[0] & 3));
 	numRooms = cowHeader[0] / 4;
 	assert(cowHeader[numRooms] == 0);	/* This dword should be unused. */
+
 	/* The samples are divided into rooms and samples. We don't care about the room indexes at all. */
 	/* We simply copy them and go to the sample-index data. */
 	writeUint32LE(cl3, headerSize);
@@ -438,7 +450,7 @@
 	}
 	cl3Index = (uint32*)malloc(numSamples * 8);
 	memset(cl3Index, 0, numSamples * 8);
-	
+
 	sampleIndex = cowHeader + numRooms + 1;
 	/* This points to the sample index table. 8 bytes each (4 bytes size and then 4 bytes file index) */
 
@@ -446,7 +458,7 @@
 
 	for (cnt = 0; cnt < numSamples; cnt++) {
 		if (sampleIndex[cnt << 1] | sampleIndex[(cnt << 1) | 1]) {
-			printf("sample %5d: ", cnt);
+			printf("sample %5d: \n", cnt);
 			smpData = (uint8*)uncompressSpeech(clu, sampleIndex[cnt << 1] + headerSize, sampleIndex[(cnt << 1) | 1], &smpSize);
 			if ((!smpData) || (!smpSize))
 				error("unable to handle speech sample %d!\n", cnt);
@@ -475,9 +487,10 @@
 	int i;
 	char cluName[256], outName[256];
 
-	setRawAudioType(true, false, false, 16);
+	setRawAudioType(true, false, 16);
+
 	for (i = 1; i <= 2; i++) {
-		sprintf(cluName, "SPEECH/SPEECH%d.CLU", i);
+		sprintf(cluName, "%s/SPEECH/SPEECH%d.CLU", inputDir, i);
 		clu = fopen(cluName, "rb");
 		if (!clu) {
 			printf("Unable to open \"SPEECH%d.CLU\".\n", i);
@@ -485,13 +498,13 @@
 		} else {
 			switch (compMode) {
 			case kMP3Mode:
-				sprintf(outName, "SPEECH/SPEECH%d.%s", i, "CL3");
+				sprintf(outName, "%s/SPEECH/SPEECH%d.%s", inputDir, i, "CL3");
 				break;
 			case kVorbisMode:
-				sprintf(outName, "SPEECH/SPEECH%d.%s", i, "CLV");
+				sprintf(outName, "%s/SPEECH/SPEECH%d.%s", inputDir, i, "CLV");
 				break;
 			case kFlacMode:
-				sprintf(outName, "SPEECH/SPEECH%d.%s", i, "CLF");
+				sprintf(outName, "%s/SPEECH/SPEECH%d.%s", inputDir, i, "CLF");
 				break;
 			default:
 				error("Unknown encoding method");
@@ -519,9 +532,11 @@
 	int i;
 	FILE *inf;
 	char fNameIn[256], fNameOut[256];
+
 	for (i = 0; i < TOTAL_TUNES; i++) {
-		sprintf(fNameIn, "MUSIC/%s.WAV", musicNames[i].fileName);
+		sprintf(fNameIn, "%s/MUSIC/%s.WAV", inputDir, musicNames[i].fileName);
 		inf = fopen(fNameIn, "rb");
+
 		if (!inf) {
 			if (!musicNames[i].missing) {
 				printf("unable to open file \"%s\"\n", fNameIn);
@@ -531,13 +546,13 @@
 
 			switch (compMode) {
 			case kMP3Mode:
-				sprintf(fNameOut, "MUSIC/%s.%s", musicNames[i].fileName, "MP3");
+				sprintf(fNameOut, "%s/MUSIC/%s.%s", inputDir, musicNames[i].fileName, "MP3");
 				break;
 			case kVorbisMode:
-				sprintf(fNameOut, "MUSIC/%s.%s", musicNames[i].fileName, "OGG");
+				sprintf(fNameOut, "%s/MUSIC/%s.%s", inputDir, musicNames[i].fileName, "OGG");
 				break;
 			case kFlacMode:
-				sprintf(fNameOut, "MUSIC/%s.%s", musicNames[i].fileName, "FLA");
+				sprintf(fNameOut, "%s/MUSIC/%s.%s", inputDir, musicNames[i].fileName, "FLA");
 				break;
 			default:
 				error("Unknown encoding method");
@@ -549,51 +564,23 @@
 	}
 }
 
-void processArgs(int argc, char *argv[], int i, CompressMode compMode) {
-	/* HACK: the functions in compress.c expect the last argument to be a filename. */
-	/*       As we don't expect one, we simply add a dummy argument to the list. */
-	char **args;
-	int cnt;
-	int result;
-	char dummyName[] = "dummy";
-	args = (char **)malloc((argc + 1) * sizeof(char *));
-	for (cnt = 0; cnt < argc; cnt++)
-		args[cnt] = argv[cnt];
-	args[argc] = dummyName;
-
-	switch (compMode) {
-	case kMP3Mode:
-		result = process_mp3_parms(argc + 1, args, i);
-		break;
-	case kVorbisMode:
-		result = process_ogg_parms(argc + 1, args, i);
-		break;
-	case kFlacMode:
-		result = process_flac_parms(argc + 1, args, i);
-		break;
-	default:
-		error("Unknown encoding method");
-	}
-
-	if (!result)
-		showhelp(argv[0]);
-	free(args);
-}
-
 void checkFilesExist(bool checkSpeech, bool checkMusic) {
 	int i;
 	FILE *testFile;
 	char fileName[256];
 	bool speechFound = false, musicFound = false;
+
 	if (checkSpeech) {
 		for (i = 1; i <= 2; i++) {
-			sprintf(fileName, "SPEECH/SPEECH%d.CLU", i);
+			sprintf(fileName, "%s/SPEECH/SPEECH%d.CLU", inputDir, i);
 			testFile = fopen(fileName, "rb");
+
 			if (testFile){
 				speechFound = true;
 				fclose(testFile);
 			}
 		}
+
 		if (!speechFound) {
 			printf("Unable to find speech files.\n");
 			printf("Please copy the SPEECH.CLU files from Broken Sword CD1 and CD2\n");
@@ -603,15 +590,18 @@
 			printf("and directorynames are all upper-case.\n\n");
 		}
 	}
+
 	if (checkMusic) {
 		for (i = 0; i < 20; i++) { /* Check the first 20 music files */
-			sprintf(fileName, "MUSIC/%s.WAV", musicNames[i].fileName);
+			sprintf(fileName, "%s/MUSIC/%s.WAV", inputDir, musicNames[i].fileName);
 			testFile = fopen(fileName, "rb");
+
 			if (testFile) {
 				musicFound = true;
 				fclose(testFile);
 			}
 		}
+
 		if (!musicFound) {
 			printf("Unable to find music files.\n");
 			printf("Please copy the music files from Broken Sword CD1 and CD2\n");
@@ -620,6 +610,7 @@
 			printf("and directorynames are all upper-case.\n");
 		}
 	}
+
 	if ((checkSpeech && (!speechFound)) || (checkMusic && (!musicFound))) {
 		printf("\nUse --help for more information\n");
 		exit(2);
@@ -650,27 +641,42 @@
 	switch (compMode) {
 	case kMP3Mode:
 		strcpy(tempOutName, TEMP_MP3);
+		if (!process_mp3_parms(argc, argv, i)) {
+			showhelp(argv[0]);
+		}
+
 		break;
 	case kVorbisMode:
 		strcpy(tempOutName, TEMP_OGG);
+		if (!process_ogg_parms(argc, argv, i)) {
+			showhelp(argv[0]);
+		}
+
 		break;
 	case kFlacMode:
 		strcpy(tempOutName, TEMP_FLAC);
+		if (!process_flac_parms(argc, argv, i)){
+			showhelp(argv[0]);
+		}
+
 		break;
 	default:
 		error("Unknown encoding method");
 	}
 
-	processArgs(argc, argv, i, compMode);
+	sprintf(inputDir, argv[argc - 1]);
 
 	/* Do a quick check to see if we can open any files at all */
 	checkFilesExist(compSpeech, compMusic);
 
-	if (compSpeech)
+	if (compSpeech) {
 		compressSpeech(compMode);
-	if (compMusic)
+	}
+
+	if (compMusic) {
 		compressMusic(compMode);
-	
+	}
+
 	return EXIT_SUCCESS;
 }
 

Modified: tools/trunk/compress_sword2.c
===================================================================
--- tools/trunk/compress_sword2.c	2008-01-28 20:40:05 UTC (rev 30689)
+++ tools/trunk/compress_sword2.c	2008-01-28 20:41:00 UTC (rev 30690)
@@ -31,7 +31,7 @@
 
 void showhelp(char *exename)
 {
-	printf("\nUsage: %s <params> file.clu\n", exename);
+	printf("\nUsage: %s [params] <file>\n", exename);
 
 	printf("\nParams:\n");
 	printf(" --mp3        encode to MP3 format (default)\n");
@@ -56,8 +56,12 @@
 	printf(" --silent     the output of oggenc is hidden (default:disabled)\n");
 
 	printf("\nFlac mode params:\n");
-	printf(" [params]     optional arguments passed directly to the encoder\n");
-	printf("              recommended is: --best -b 1152\n");
+	printf(" --fast       FLAC uses compresion level 0\n");
+	printf(" --best       FLAC uses compresion level 8\n");
+	printf(" -<value>     specifies the value (0 - 8) of compresion (8=best)(default:%d)\n", flacCompressDef);
+	printf(" -b <value>   specifies a blocksize of <value> samples (default:%d)\n", flacBlocksizeDef);
+	printf(" --verify     files are encoded and then decoded to check accuracy\n");
+	printf(" --silent     the output of FLAC is hidden (default:disabled)\n");
 
 	printf("\n --help     this help message\n");
 
@@ -82,8 +86,10 @@
 
 	while (length > 0) {
 		size = fread(fbuf, 1, length > sizeof(fbuf) ? sizeof(fbuf) : length, f2);
-		if (size <= 0)
+		if (size <= 0) {
 			break;
+		}
+
 		length -= size;
 		fwrite(fbuf, 1, size, f1);
 	}
@@ -97,17 +103,19 @@
 #define GetCompressedAmplitude(n)  ((n) & 7)
 
 int main(int argc, char *argv[]) {
-	char output_filename[40];
+	char output_filename[1024];
 	FILE *output, *f;
 	char *ptr;
 	int i, j;
 	uint32 indexSize;
 	uint32 totalSize;
 	uint32 length;
-	
+
 	if (argc < 2)
 		showhelp(argv[0]);
+
 	i = 1;
+
 	if (strcmp(argv[1], "--mp3") == 0) {
 		gCompMode = kMP3Mode;
 		i++;
@@ -123,18 +131,24 @@
 	switch (gCompMode) {
 	case kMP3Mode:
 		tempEncoded = TEMP_MP3;
-		if (!process_mp3_parms(argc, argv, i))
+		if (!process_mp3_parms(argc, argv, i)) {
 			showhelp(argv[0]);
+		}
+
 		break;
 	case kVorbisMode:
 		tempEncoded = TEMP_OGG;
-		if (!process_ogg_parms(argc, argv, i))
+		if (!process_ogg_parms(argc, argv, i)) {
 			showhelp(argv[0]);
+		}
+
 		break;
 	case kFlacMode:
 		tempEncoded = TEMP_FLAC;
-		if (!process_flac_parms(argc, argv, i))
+		if (!process_flac_parms(argc, argv, i)) {
 			showhelp(argv[0]);
+		}
+
 		break;
 	}
 
@@ -170,33 +184,6 @@
 	writeUint32BE(output_idx, 0xfff0fff0);
 	writeUint32BE(output_idx, 0xfff0fff0);
 
-	for (j = strlen(argv[i]) - 1; j >= 0; j--) {
-		if (argv[i][j] == '/' || argv[i][j] == '\\' || argv[i][j] == ':') {
-			j++;
-			break;
-		}
-	}
-
-	if (j < 0)
-		j = 0;
-
-	strncpy(output_filename, argv[i] + j, sizeof(output_filename) - 1);
-	output_filename[sizeof(output_filename) - 1] = 0;
-
-	ptr = output_filename + strlen(output_filename) - 1;
-
-	switch (gCompMode) {
-	case kMP3Mode:
-		*ptr = '3';
-		break;
-	case kVorbisMode:
-		*ptr = 'g';
-		break;
-	case kFlacMode:
-		*ptr = 'f';
-		break;
-	}
-
 	for (i = 0; i < indexSize; i++) {
 		uint32 pos;
 		uint32 enc_length;
@@ -285,6 +272,22 @@
 	fclose(output_idx);
 	fclose(output_snd);
 
+	strcpy(output_filename, argv[argc - 1]);
+	ptr = output_filename + strlen(output_filename) - 1;
+
+	switch (gCompMode) {
+	case kMP3Mode:
+		*ptr = '3';
+		break;
+	case kVorbisMode:
+		*ptr = 'g';
+		break;
+	case kFlacMode:
+		*ptr = 'f';
+		break;
+	}
+
+
 	output = fopen(output_filename, "wb");
 	if (!output) {
 		printf("Can't open file %s for writing!\n", output_filename);

Modified: tools/trunk/compress_touche.c
===================================================================
--- tools/trunk/compress_touche.c	2008-01-28 20:40:05 UTC (rev 30689)
+++ tools/trunk/compress_touche.c	2008-01-28 20:41:00 UTC (rev 30690)
@@ -34,6 +34,7 @@
 
 static CompressMode g_mode = kMP3Mode;
 static const char *g_output_filename = OUTPUT_MP3;
+static const char *g_output_directory = NULL;
 static const char *g_input_directory = NULL;
 
 static uint32 input_OBJ_offs[OBJ_HDR_LEN];
@@ -61,9 +62,11 @@
 		} else {
 			fseek(input, offs_table[i], SEEK_SET);
 			fread(buf, 1, 8, input);
+
 			if (memcmp(buf, "Creative", 8) != 0) {
 				error("Invalid VOC data found");
 			}
+
 			printf("VOC found (pos = %d) :\n", offs_table[i]);
 			fseek(input, 18, SEEK_CUR);
 			extractAndEncodeVOC(TEMP_RAW, input, g_mode);
@@ -73,11 +76,14 @@
 			if (!temp) {
 				error("Cannot open file '%s' for reading", tempEncoded);
 			}
+
 			size_table[i] = 0;
+
 			while ((size = fread(buf, 1, 2048, temp)) > 0) {
 				fwrite(buf, 1, size, output);
 				size_table[i] += size;
 			}
+
 			fclose(temp);
 			offs_table[i] = current_offset;
 			current_offset += size_table[i];
@@ -97,14 +103,15 @@
 
 static void compress_sound_data() {
 	int i;
-	char filepath[512];
+	char filepath[1024];
 	FILE *output, *input;
 	uint32 current_offset;
 	uint32 offsets_table[MAX_OFFSETS];
 
-	output = fopen(g_output_filename, "wb");
+	sprintf(filepath, "%s/%s", g_output_directory, g_output_filename);
+	output = fopen(filepath, "wb");
 	if (!output) {
-		error("Cannot open file '%s' for writing", g_output_filename);
+		error("Cannot open file '%s' for writing", filepath);
 	}
 
 	writeUint16LE(output, 1); /* current version */
@@ -125,6 +132,7 @@
 	if (!input) {
 		error("Cannot open file 'OBJ' for reading");
 	}
+
 	offsets_table[0] = current_offset;
 	current_offset = compress_sound_data_file(current_offset, output, input, input_OBJ_offs, input_OBJ_size, OBJ_HDR_LEN);
 	fclose(input);
@@ -133,6 +141,7 @@
 	/* process Vxx files */
 	for (i = 1; i < MAX_OFFSETS; ++i) {
 		sprintf(filepath, "%s/V%d", g_input_directory, i);
+
 		input = fopen(filepath, "rb");
 		if (input) {
 			offsets_table[i] = current_offset;
@@ -158,9 +167,10 @@
 }
 
 static void showhelp(const char *exename) {
-	printf("\nUsage: %s <params> input_directory\n", exename);
+	printf("\nUsage: %s [params] <inputdir> <outputdir>\n", exename);
 
 	printf("\nParams:\n");
+
 	printf(" --mp3        encode to MP3 format (default)\n");
 	printf(" --vorbis     encode to Vorbis format\n");
 	printf(" --flac       encode to Flac format\n");
@@ -183,8 +193,12 @@
 	printf(" --silent     the output of oggenc is hidden (default:disabled)\n");
 
 	printf("\nFlac mode params:\n");
-	printf(" [params]     optional arguments passed directly to the encoder\n");
-	printf("              recommended is: --best -b 1152\n");
+	printf(" --fast       FLAC uses compresion level 0\n");
+	printf(" --best       FLAC uses compresion level 8\n");
+	printf(" -<value>     specifies the value (0 - 8) of compresion (8=best)(default:%d)\n", flacCompressDef);
+	printf(" -b <value>   specifies a blocksize of <value> samples (default:%d)\n", flacBlocksizeDef);
+	printf(" --verify     files are encoded and then decoded to check accuracy\n");
+	printf(" --silent     the output of FLAC is hidden (default:disabled)\n");
 
 	printf("\n --help     this help message\n");
 
@@ -215,29 +229,35 @@
 		++i;
 	}
 
-	g_input_directory = argv[argc - 1];
+	g_input_directory = argv[argc - 2];
+	g_output_directory = argv[argc - 1];
 
 	switch (g_mode) {
 	case kMP3Mode:
 		tempEncoded = TEMP_MP3;
-		if (!process_mp3_parms(argc, argv, i)) {
+		if (!process_mp3_parms(argc - 1, argv, i)) {
 			showhelp(argv[0]);
 		}
+
 		break;
 	case kVorbisMode:
 		tempEncoded = TEMP_OGG;
-		if (!process_ogg_parms(argc, argv, i)) {
+		if (!process_ogg_parms(argc - 1, argv, i)) {
 			showhelp(argv[0]);
 		}
+
 		break;
 	case kFlacMode:
 		tempEncoded = TEMP_FLAC;
-		if (!process_flac_parms(argc, argv, i)) {
+		if (!process_flac_parms(argc - 1, argv, i)) {
 			showhelp(argv[0]);
 		}
+
 		break;
 	}
 
+
+
 	compress_sound_data();
 	return 0;
 }

Modified: tools/trunk/dekyra.cpp
===================================================================
--- tools/trunk/dekyra.cpp	2008-01-28 20:40:05 UTC (rev 30689)
+++ tools/trunk/dekyra.cpp	2008-01-28 20:41:00 UTC (rev 30690)
@@ -42,15 +42,15 @@
 			   "-e   set engine version (1 for kyra1 (default), 2 for kyra2)\n"
 			   "-o   set optional outputfilename (default: stdout)\n",
 			   argv[0]);
-			   
+
 		return -1;
 	}
-	
+
 	int file = -1;
 	int outputfile = -1;
 	bool displayText = false;
 	int32 engine = 1;
-	
+
 	// search for some parameters
 	for (int param = 1; param < argc; ++param) {
 		if (*argv[param] != '-' && file == -1)
@@ -60,13 +60,13 @@
 				displayText = true;
 			} else if (argv[param][1] == 'e') {
 				engine = atoi(argv[param+1]);
-				++param;				
+				++param;
 			} else if (argv[param][1] == 'o' && outputfile == -1) {
 				outputfile = ++param;
 			}
 		}
 	}
-	
+
 	if (file == -1) {
 		printf("Use:\n"
 			   "%s filename\n"
@@ -74,27 +74,27 @@
 			   "-e   set engine version (1 for kyra1 (default), 2 for kyra2)\n"
 			   "-o   set optional outputfilename (default: stdout)\n",
 			   argv[0]);
-			   
+
 		return -1;
 	} else if (engine != 1 && engine != 2) {
 		printf("-e (engine version) must be set to 1 or 2!\n");
 		return -1;
 	}
-	
+
 	// currently output goes to stdout
 	if (outputfile == -1 || outputfile >= argc) {
 		outputFile = stdout;
 	} else {
 		outputFile = fopen(argv[outputfile], "w");
 	}
-	
+
 	Script myScript;
 	ScriptData scriptData;
 	memset(&scriptData, 0, sizeof(ScriptData));
-	
+
 	OpcodeEntry *opcodes;
 	int opcodesSize;
-	
+
 	if (engine == 1) {
 		getOpcodesV1(opcodes, opcodesSize);
 	} else if (engine == 2) {
@@ -105,7 +105,7 @@
 		printf("ERROR: script loading failed!\n");
 		return -1;
 	}
-	
+
 	myScript.setEngineVersion(engine);
 	if (!displayText) {
 		if (engine == 1) {
@@ -114,10 +114,10 @@
 			// TODO: maybe kyra2 has other commands?
 			setupTraceCommandsV1(&myScript);
 		}
-		
+
 		myScript.processScriptTrace(&scriptData);
 	}
-	
+
 	fprintf(outputFile, "/-----------------------------------\\\n");
 	fprintf(outputFile, "|                                   |\n");
 	fprintf(outputFile, "|  Dekyra output for file:          |\n");
@@ -145,7 +145,7 @@
 	}
 	fprintf(outputFile, "|                                   |\n");
 	fprintf(outputFile, "\\-----------------------------------/\n\n");
-	
+
 	myScript.setEngineVersion(engine);
 	myScript.printTextArea(&scriptData, argv[file]);
 	if (!displayText) {
@@ -160,12 +160,12 @@
 
 		myScript.decodeScript(&scriptData);
 	}
-	
+
 	myScript.unloadScript(&scriptData);
-	
+
 	if (outputFile != stdout)
 		fclose(outputFile);
-	
+
 	return 0;
 }
 
@@ -202,14 +202,14 @@
 	scriptFile = NULL;
 
 	byte *curData = data;
-	
+
 	uint32 formBlockSize = Script::getFORMBlockSize(curData);
 	if (formBlockSize == (uint32)-1) {
 		delete [] data;
 		error("No FORM chunk found in file: '%s'", filename);
 		return false;
 	}
-	
+
 	uint32 chunkSize = Script::getIFFBlockSize(data, curData, size, TEXT_CHUNK);
 	if (chunkSize != (uint32)-1) {
 		scriptData->text = new byte[chunkSize];
@@ -222,7 +222,7 @@
 			error("Couldn't load TEXT chunk from file: '%s'", filename);
 			return false;
 		}
-		
+
 		uint16 minTextOffset = 0xFFFF;
 		for (int i = 0; i < scriptData->textChunkSize / 2; ++i, ++scriptData->numStrings) {
 			if (minTextOffset > READ_BE_UINT16(&((uint16 *)scriptData->text)[i])) {
@@ -232,7 +232,7 @@
 				break;
 		}
 	}
-	
+
 	chunkSize = Script::getIFFBlockSize(data, curData, size, ORDR_CHUNK);
 	if (chunkSize == (uint32)-1) {
 		delete [] data;
@@ -255,7 +255,7 @@
 	while (chunkSize--) {
 		((uint16*)scriptData->ordr)[chunkSize] = READ_BE_UINT16(&((uint16*)scriptData->ordr)[chunkSize]);
 	}
-	
+
 	chunkSize = Script::getIFFBlockSize(data, curData, size, DATA_CHUNK);
 	if (chunkSize == (uint32)-1) {
 		delete [] data;
@@ -273,11 +273,11 @@
 		error("Couldn't load DATA chunk from file: '%s'", filename);
 		return false;
 	}
-	
+
 	scriptData->dataChunkSize = chunkSize;
 	scriptData->opcodes = opcodes;
 	scriptData->opcodeSize = opcodeSize;
-	
+
 	delete [] data;
 	return true;
 }
@@ -339,13 +339,13 @@
 		} else {
 			parameter = 0;
 		}
-		
+
 		if (opcode < _commandsSize) {
 			if (_commands[(uint)opcode])
 				_commands[(uint)opcode](dataPtr, parameter);
 		}
 	}
-	
+
 	// TODO: sort the 'function' list (except for the functions with id != -1) after start address
 }
 
@@ -360,11 +360,11 @@
 		int temp = (dataPtr->functions[i].startOffset < offset) ? dataPtr->functions[i].startOffset : offset;
 		if (temp == offset)
 			continue;
-		
+
 		int temp2 = (bestStartOffset > temp) ? bestStartOffset : temp;
 		if (temp2 == bestStartOffset)
 			continue;
-		
+
 		bestStartOffset = temp2;
 		functionFittingBest = i;
 	}
@@ -409,7 +409,7 @@
 
 void Script::decodeScript(ScriptData *dataPtr) {
 	uint8 *ip = dataPtr->data;
-	
+
 	fprintf(outputFile, "\n");
 	fprintf(outputFile, "---------- scriptfunction list ----------------\n\n");
 	for (int i = 0; i < dataPtr->ordrChunkSize / 2; ++i) {
@@ -418,7 +418,7 @@
 			fprintf(outputFile, "Scriptfunction %d starts at 0x%.04X\n", i, offset << 1);
 	}
 	fprintf(outputFile, "\n");
-	
+
 	fprintf(outputFile, "--------- detected functionchunk list ----------\n\n");
 	outputFunctionInfo(dataPtr, 0, true);
 
@@ -427,7 +427,7 @@
 		uint16 curOffset = (uint16)(ip - dataPtr->data);
 
 		outputFunctionInfo(dataPtr, curOffset);
-		
+
 		fprintf(outputFile, "0x%.04X: ", curOffset);
 
 		int16 parameter = 0;
@@ -444,7 +444,7 @@
 		} else {
 			parameter = 0;
 		}
-		
+
 		fprintf(outputFile, "0x%.02X ", opcode);
 		if (opcode >= _commandsSize) {
 			fprintf(outputFile, "unknown command\n");
@@ -472,7 +472,7 @@
 uint32 Script::getIFFBlockSize(byte *start, byte *&data, uint32 maxSize, const uint32 chunkName) {
 	uint32 size = (uint32)-1;
 	bool special = false;
-	
+
 	if (data == (start + maxSize)) {
 		data = start + 0x0C;
 	}
@@ -498,7 +498,7 @@
 
 bool Script::loadIFFBlock(byte *start, byte *&data, uint32 maxSize, const uint32 chunkName, byte *loadTo, uint32 ptrSize) {
 	bool special = false;
-	
+
 	if (data == (start + maxSize)) {
 		data = start + 0x0C;
 	}

Modified: tools/trunk/dekyra.h
===================================================================
--- tools/trunk/dekyra.h	2008-01-28 20:40:05 UTC (rev 30689)
+++ tools/trunk/dekyra.h	2008-01-28 20:41:00 UTC (rev 30690)
@@ -29,7 +29,7 @@
 typedef unsigned int uint;
 
 struct OpcodeEntry {
-	uint16 opcode;	
+	uint16 opcode;
 	const char *name;
 };
 
@@ -50,23 +50,23 @@
 	byte *text;
 	int numStrings;
 	int textChunkSize;
-	
+
 	byte *data;
 	int dataChunkSize;
-	
+
 	byte *ordr;
 	int validORDRFunctions;
 	int ordrChunkSize;
-	
+
 	OpcodeEntry *opcodes;
 	int opcodeSize;
-	
+
 	// trace information
 	uint16 curOffset;
 
 	int numFunctions;
 	Function functions[MAX_FUNCTIONS];
-	
+
 	Function *getFunction(uint16 startOff) {
 		for (int i = 0; i < numFunctions; ++i) {
 			if (functions[i].startOffset == startOff)
@@ -93,7 +93,7 @@
 
 	bool loadScript(const char *filename, ScriptData *data, OpcodeEntry *opcodes, int opcodeSize);
 	void unloadScript(ScriptData *data);
-	
+
 	void printTextArea(ScriptData *dataPtr, const char *filename);
 	void processScriptTrace(ScriptData *dataPtr);
 	void decodeScript(ScriptData *dataPtr);

Modified: tools/trunk/dekyra_v1.cpp
===================================================================
--- tools/trunk/dekyra_v1.cpp	2008-01-28 20:40:05 UTC (rev 30689)
+++ tools/trunk/dekyra_v1.cpp	2008-01-28 20:41:00 UTC (rev 30690)
@@ -70,7 +70,7 @@
 	case 0:
 	case 1:
 		break;
-	
+
 	default:
 		fprintf(outputFile, "; called with illegal param! breaks execution!");
 		break;
@@ -106,7 +106,7 @@
 	case 0:
 	case 1:
 		break;
-	
+
 	default:
 		fprintf(outputFile, "; called with illegal param! breaks execution!");
 		break;
@@ -153,7 +153,7 @@
 	case 1:
 	case 2:
 		break;
-	
+
 	default:
 		fprintf(outputFile, "; called with illegal param! breaks execution");
 		break;
@@ -163,85 +163,85 @@
 
 void c1_eval(ScriptData *script, int argument) {
 	fprintf(outputFile, "c1_eval %d ; (C syntax): '", argument);
-	
+
 	switch (argument) {
 	case 0:
 		fprintf(outputFile, "(val2 && val1)");
 		break;
-	
+
 	case 1:
 		fprintf(outputFile, "(val2 || val1)");
 		break;
-	
+
 	case 2:
 		fprintf(outputFile, "(val1 == val2)");
 		break;
-	
+
 	case 3:
 		fprintf(outputFile, "(val1 != val2)");
 		break;
-	
+
 	case 4:
 		fprintf(outputFile, "(val1 > val2)");
 		break;
-	
+
 	case 5:
 		fprintf(outputFile, "(val1 >= val2)");
 		break;
-	
+
 	case 6:
 		fprintf(outputFile, "(val1 < val2)");
 		break;
-	
+
 	case 7:
 		fprintf(outputFile, "(val1 <= val2)");
 		break;
-	
+
 	case 8:
 		fprintf(outputFile, "val1 + val2");
 		break;
-	
+
 	case 9:
 		fprintf(outputFile, "val2 - val1");
 		break;
-	
+
 	case 10:
 		fprintf(outputFile, "val1 * val2");
 		break;
-	
+
 	case 11:
 		fprintf(outputFile, "val2 / val1");
 		break;
-	
+
 	case 12:
 		fprintf(outputFile, "val2 >> val1");
 		break;
-	
+
 	case 13:
 		fprintf(outputFile, "val2 << val1");
 		break;
-	
+
 	case 14:
 		fprintf(outputFile, "val1 & val2");
 		break;
-	
+
 	case 15:
 		fprintf(outputFile, "val1 | val2");
 		break;
-	
+
 	case 16:
 		fprintf(outputFile, "val2 %% val1");
 		break;
-	
+
 	case 17:
 		fprintf(outputFile, "val1 ^ val2");
 		break;
-	
+
 	default:
 		fprintf(outputFile, "!error breaking exectution!");
 		break;
 	}
-	
+
 	fprintf(outputFile, "'\n");
 }
 
@@ -271,7 +271,7 @@
 		&c1_eval,
 		&c1_setRetAndJmp
 	};
-	
+
 	myScript->setCommands(commands, ARRAYSIZE(commands));
 }
 
@@ -283,7 +283,7 @@
 			if (call->refOffs[i] == script->curOffset)
 				return;
 		}
-		
+
 		if (call->refs < MAX_REFS) {
 			call->refOffs[call->refs++] = script->curOffset;
 		} else {
@@ -309,7 +309,7 @@
 			if (call->refOffs[i] == script->curOffset)
 				return;
 		}
-		
+
 		if (call->refs < MAX_REFS) {
 			call->refOffs[call->refs++] = script->curOffset;
 		} else {
@@ -350,7 +350,7 @@
 		0,
 		0
 	};
-	
+
 	myScript->setCommands(commands, ARRAYSIZE(commands));
 }
 
@@ -408,7 +408,7 @@
 		{ 0x30 ,"o1_popBrandonIntoScene" },
 		{ 0x31 ,"o1_restoreAllObjectBackgrounds" },
 		{ 0x32 ,"o1_setCustomPaletteRange" },
-		{ 0x33 ,"o1_loadPageFromDisk" },		
+		{ 0x33 ,"o1_loadPageFromDisk" },
 		{ 0x34 ,"o1_customPrintTalkString" },

@@ 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