[Scummvm-cvs-logs] SF.net SVN: scummvm:[41441] tools/branches/gsoc2009-gui

Remere at users.sourceforge.net Remere at users.sourceforge.net
Thu Jun 11 01:55:22 CEST 2009


Revision: 41441
          http://scummvm.svn.sourceforge.net/scummvm/?rev=41441&view=rev
Author:   Remere
Date:     2009-06-10 23:55:21 +0000 (Wed, 10 Jun 2009)

Log Message:
-----------
*All compression except sword1 and sword2 converted to new argument format (due to them taking additional arguments which I haven't decided exactly what to do about yet).
*Extended Filename functionality and output argument parsing.
*Not all tools are tested, and none are tested thoroughly yet. You have been warned ;)
*All compression tools now display the entire audio text help, and it's centralized!
*Fixed minor syntax errors and compiler warnings.

Modified Paths:
--------------
    tools/branches/gsoc2009-gui/compress.cpp
    tools/branches/gsoc2009-gui/compress.h
    tools/branches/gsoc2009-gui/compress_agos.cpp
    tools/branches/gsoc2009-gui/compress_gob.cpp
    tools/branches/gsoc2009-gui/compress_kyra.cpp
    tools/branches/gsoc2009-gui/compress_queen.cpp
    tools/branches/gsoc2009-gui/compress_saga.cpp
    tools/branches/gsoc2009-gui/compress_scumm_bun.cpp
    tools/branches/gsoc2009-gui/compress_scumm_san.cpp
    tools/branches/gsoc2009-gui/compress_sword2.cpp
    tools/branches/gsoc2009-gui/compress_touche.cpp
    tools/branches/gsoc2009-gui/dekyra.cpp
    tools/branches/gsoc2009-gui/extract_agos.cpp
    tools/branches/gsoc2009-gui/extract_gob_stk.cpp
    tools/branches/gsoc2009-gui/extract_kyra.cpp
    tools/branches/gsoc2009-gui/extract_kyra.h
    tools/branches/gsoc2009-gui/extract_loom_tg16.cpp
    tools/branches/gsoc2009-gui/extract_mm_apple.cpp
    tools/branches/gsoc2009-gui/extract_mm_c64.cpp
    tools/branches/gsoc2009-gui/extract_mm_nes.cpp
    tools/branches/gsoc2009-gui/extract_parallaction.cpp
    tools/branches/gsoc2009-gui/extract_scumm_mac.cpp
    tools/branches/gsoc2009-gui/extract_zak_c64.cpp
    tools/branches/gsoc2009-gui/kyra_pak.cpp
    tools/branches/gsoc2009-gui/kyra_pak.h
    tools/branches/gsoc2009-gui/util.cpp
    tools/branches/gsoc2009-gui/util.h

Modified: tools/branches/gsoc2009-gui/compress.cpp
===================================================================
--- tools/branches/gsoc2009-gui/compress.cpp	2009-06-10 21:28:16 UTC (rev 41440)
+++ tools/branches/gsoc2009-gui/compress.cpp	2009-06-10 23:55:21 UTC (rev 41441)
@@ -52,7 +52,7 @@
 } rawtype;
 
 lameparams encparms = { minBitrDef, maxBitrDef, false, algqualDef, vbrqualDef, 0 };
-oggencparams oggparms = { -1, -1, -1, oggqualDef, 0 };
+oggencparams oggparms = { -1, -1, -1, (float)oggqualDef, 0 };
 flaccparams flacparms = { flacCompressDef, flacBlocksizeDef, false, false };
 rawtype	rawAudioType = { false, false, 8 };
 
@@ -358,7 +358,7 @@
 			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);
+			result = vorbis_encode_setup_vbr(&vi, numChannels, samplerate, oggparms.quality * 0.1f);
 
 			if (result == OV_EFAULT) {
 				printf("Error: Internal Logic Fault.\n\n");
@@ -445,8 +445,8 @@
 							buffer[j][i] = ((int)(rawDataUnsigned[i * numChannels + j]) - 128) / 128.0f;
 						}
 					}
-				} else if(rawAudioType.bitsPerSample == 16) {
-					if(rawAudioType.isLittleEndian) {
+				} 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;
@@ -475,14 +475,14 @@
 					while (!eos) {
 						int result = ogg_stream_pageout(&os, &og);
 
-						if(result == 0) {
+						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)) {
+						if (ogg_page_eos(&og)) {
 							eos = 1;
 						}
 					}
@@ -684,14 +684,14 @@
 	encodeAudio(outName, true, real_samplerate, tempEncoded, compMode);
 }
 
-int process_mp3_parms(int argc, char *argv[], int i) {
-	for (; i < argc; i++) {
-		if (strcmp(argv[i], "--vbr") == 0) {
+int process_mp3_parms(int argc, char *argv[], int* i) {
+	for (; *i < argc; (*i)++) {
+		if (strcmp(argv[*i], "--vbr") == 0) {
 			encparms.abr = 0;
-		} else if (strcmp(argv[i], "--abr") == 0) {
+		} else if (strcmp(argv[*i], "--abr") == 0) {
 			encparms.abr = 1;
-		} else if (strcmp(argv[i], "-b") == 0) {
-			encparms.minBitr = atoi(argv[i + 1]);
+		} else if (strcmp(argv[*i], "-b") == 0) {
+			encparms.minBitr = atoi(argv[*i + 1]);
 
 			if ((encparms.minBitr % 8) != 0) {
 				encparms.minBitr -= encparms.minBitr % 8;
@@ -705,9 +705,9 @@
 				encparms.minBitr = 8;
 			}
 
-			i++;
-		} else if (strcmp(argv[i], "-B") == 0) {
-			encparms.maxBitr = atoi(argv[i + 1]);
+			(*i)++;
+		} else if (strcmp(argv[*i], "-B") == 0) {
+			encparms.maxBitr = atoi(argv[*i + 1]);
 
 			if ((encparms.maxBitr % 8) != 0) {
 				encparms.maxBitr -= encparms.maxBitr % 8;
@@ -721,21 +721,21 @@
 				encparms.maxBitr = 8;
 			}
 
-			i++;
-		} else if (strcmp(argv[i], "-V") == 0) {
-			encparms.vbrqual = atoi(argv[i + 1]);
+			(*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]);
+			(*i)++;
+		} else if (strcmp(argv[*i], "-q") == 0) {
+			encparms.algqual = atoi(argv[*i + 1]);
 
 			if (encparms.algqual < 0) {
 				encparms.algqual = 0;
@@ -745,29 +745,29 @@
 				encparms.algqual = 9;
 			}
 
-			i++;
-		} else if (strcmp(argv[i], "--silent") == 0) {
+			(*i)++;
+		} else if (strcmp(argv[*i], "--silent") == 0) {
 			encparms.silent = 1;
-		} else if (strcmp(argv[i], "--help") == 0) {
+		} else if (strcmp(argv[*i], "--help") == 0) {
 			return 0;
-		} else if (argv[i][0] == '-') {
+		} else if (argv[*i][0] == '-') {
 			return 0;
 		} else {
 			break;
 		}
 	}
 
-	if (i != (argc - 1)) {
+	if (*i != (argc - 1)) {
 		return 0;
 	}
 
 	return 1;
 }
 
-int process_ogg_parms(int argc, char *argv[], int i) {
-	for (; i < argc; i++) {
-		if (strcmp(argv[i], "-b") == 0) {
-			oggparms.nominalBitr = atoi(argv[i + 1]);
+int process_ogg_parms(int argc, char *argv[], int* i) {
+	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;
@@ -781,9 +781,9 @@
 				oggparms.nominalBitr = 8;
 			}
 
-			i++;
-		} else if (strcmp(argv[i], "-m") == 0) {
-			oggparms.minBitr = atoi(argv[i + 1]);
+			(*i)++;
+		} else if (strcmp(argv[*i], "-m") == 0) {
+			oggparms.minBitr = atoi(argv[*i + 1]);
 
 			if ((oggparms.minBitr % 8) != 0) {
 				oggparms.minBitr -= oggparms.minBitr % 8;
@@ -797,9 +797,9 @@
 				oggparms.minBitr = 8;
 			}
 
-			i++;
-		} else if (strcmp(argv[i], "-M") == 0) {
-			oggparms.maxBitr = atoi(argv[i + 1]);
+			(*i)++;
+		} else if (strcmp(argv[*i], "-M") == 0) {
+			oggparms.maxBitr = atoi(argv[*i + 1]);
 
 			if ((oggparms.maxBitr % 8) != 0) {
 				oggparms.maxBitr -= encparms.minBitr % 8;
@@ -813,71 +813,107 @@
 				oggparms.maxBitr = 8;
 			}
 
-			i++;
-		} else if (strcmp(argv[i], "-q") == 0) {
-			oggparms.quality = atoi(argv[i + 1]);
-			i++;
-		} else if (strcmp(argv[i], "--silent") == 0) {
+			(*i)++;
+		} else if (strcmp(argv[*i], "-q") == 0) {
+			oggparms.quality = (float)atoi(argv[*i + 1]);
+			(*i)++;
+		} else if (strcmp(argv[*i], "--silent") == 0) {
 			oggparms.silent = 1;
-		} else if (strcmp(argv[i], "--help") == 0) {
+		} else if (strcmp(argv[*i], "--help") == 0) {
 			return 0;
-		} else if (argv[i][0] == '-') {
+		} else if (argv[*i][0] == '-') {
 			return 0;
 		} else {
 			break;
 		}
 	}
 
-	if (i != argc - 1) {
+	if (*i != argc - 1) {
 		return 0;
 	}
 
 	return 1;
 }
 
-int process_flac_parms(int argc, char *argv[], int 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) {
+int process_flac_parms(int argc, char *argv[], int *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) {
+		} else if (strcmp(argv[*i], "--best") == 0) {
 			flacparms.compressionLevel = 8;
-		} else if (strcmp(argv[i], "-0") == 0) {
+		} else if (strcmp(argv[*i], "-0") == 0) {
 			flacparms.compressionLevel = 0;
-		} else if (strcmp(argv[i], "-1") == 0) {
+		} else if (strcmp(argv[*i], "-1") == 0) {
 			flacparms.compressionLevel = 1;
-		} else if (strcmp(argv[i], "-2") == 0) {
+		} else if (strcmp(argv[*i], "-2") == 0) {
 			flacparms.compressionLevel = 2;
-		} else if (strcmp(argv[i], "-3") == 0) {
+		} else if (strcmp(argv[*i], "-3") == 0) {
 			flacparms.compressionLevel = 3;
-		} else if (strcmp(argv[i], "-4") == 0) {
+		} else if (strcmp(argv[*i], "-4") == 0) {
 			flacparms.compressionLevel = 4;
-		} else if (strcmp(argv[i], "-5") == 0) {
+		} else if (strcmp(argv[*i], "-5") == 0) {
 			flacparms.compressionLevel = 5;
-		} else if (strcmp(argv[i], "-6") == 0) {
+		} else if (strcmp(argv[*i], "-6") == 0) {
 			flacparms.compressionLevel = 6;
-		} else if (strcmp(argv[i], "-7") == 0) {
+		} else if (strcmp(argv[*i], "-7") == 0) {
 			flacparms.compressionLevel = 7;
-		} else if (strcmp(argv[i], "-8") == 0) {
+		} else if (strcmp(argv[*i], "-8") == 0) {
 			flacparms.compressionLevel = 8;
-		} else if (strcmp(argv[i], "--verify") == 0) {
+		} else if (strcmp(argv[*i], "--verify") == 0) {
 			flacparms.verify = true;
-		} else if (strcmp(argv[i], "--silent") == 0) {
+		} else if (strcmp(argv[*i], "--silent") == 0) {
 			flacparms.silent = true;
-		} else if (strcmp(argv[i], "--help") == 0) {
+		} else if (strcmp(argv[*i], "--help") == 0) {
 			return 0;
-		} else if (argv[i][0] == '-') {
+		} else if (argv[*i][0] == '-') {
 			return 0;
 		} else {
 			break;
 		}
 	}
 
-	if (i != argc - 1) {
+	if (*i != argc - 1) {
 		return 0;
 	}
 
 	return 1;
 }
+
+CompressMode process_audio_params(int argc, char *argv[], int* i) {
+	/* Compression mode */
+	CompressMode compMode = kMP3Mode;
+
+	for (; *i < argc - 2; ++*i) {
+		if (strcmp(argv[*i], "--mp3") == 0)
+			compMode = kMP3Mode;
+		else if (strcmp(argv[*i], "--vorbis") == 0)
+			compMode = kVorbisMode;
+		else if (strcmp(argv[*i], "--flac") == 0)
+			compMode = kFlacMode;
+		else
+			break;
+	}
+
+	switch (compMode) {
+	case kMP3Mode:
+		tempEncoded = TEMP_MP3;
+		if (!process_mp3_parms(argc - 2, argv, i))
+			return kNoAudioMode;
+		break;
+	case kVorbisMode:
+		tempEncoded = TEMP_OGG;
+		if (!process_ogg_parms(argc - 2, argv, i))
+			return kNoAudioMode;
+		break;
+	case kFlacMode:
+		tempEncoded = TEMP_FLAC;
+		if (!process_flac_parms(argc - 2, argv, i))
+			return kNoAudioMode;
+		break;
+	}
+
+	return compMode;
+}

Modified: tools/branches/gsoc2009-gui/compress.h
===================================================================
--- tools/branches/gsoc2009-gui/compress.h	2009-06-10 21:28:16 UTC (rev 41440)
+++ tools/branches/gsoc2009-gui/compress.h	2009-06-10 23:55:21 UTC (rev 41441)
@@ -32,18 +32,23 @@
 #include <FLAC/stream_encoder.h>
 #endif
 
+/* We use string constants here, so we can insert the
+ * constants directly into literals
+ * These are given integer definitions below
+ */
+
 /* These are the defaults parameters for the Lame invocation */
-#define minBitrDef 24
-#define maxBitrDef 64
-#define algqualDef 2
-#define vbrqualDef 4
+#define minBitrDef_str "24"
+#define maxBitrDef_str "64"
+#define algqualDef_str "2"
+#define vbrqualDef_str "4"
 
 /* The default for oggenc invocation is to use the --quality option only */
-#define oggqualDef 3
+#define oggqualDef_str "3"
 
 /* These are the default parameters for the FLAC invocation */
-#define flacCompressDef 8
-#define flacBlocksizeDef 1152
+#define flacCompressDef_str "8"
+#define flacBlocksizeDef_str "1152"
 
 #define TEMP_WAV	"tempfile.wav"
 #define TEMP_RAW	"tempfile.raw"
@@ -51,17 +56,26 @@
 #define TEMP_OGG	"tempfile.ogg"
 #define TEMP_FLAC	"tempfile.fla"
 
-typedef enum { kMP3Mode, kVorbisMode, kFlacMode } CompressMode;
+typedef enum { kNoAudioMode, kMP3Mode, kVorbisMode, kFlacMode } CompressMode;
 
+// The order should match the enum above
+static const char *audio_extensions[] = {
+	".unk",
+	".mp3",
+	".ogg",
+	".fla"
+};
+
 /*
  * Stuff which is in compress.c
  */
 
 const extern char *tempEncoded;
 
-extern int process_mp3_parms(int argc, char *argv[], int i);
-extern int process_ogg_parms(int argc, char *argv[], int i);
-extern int process_flac_parms(int argc, char *argv[], int i);
+extern CompressMode process_audio_params(int argc, char *argv[], int* i);
+extern int process_mp3_parms(int argc, char *argv[], int* i);
+extern int process_ogg_parms(int argc, char *argv[], int* i);
+extern int process_flac_parms(int argc, char *argv[], int* i);
 
 extern void extractAndEncodeVOC(const char *outName, FILE *input, CompressMode compMode);
 extern void extractAndEncodeWAV(const char *outName, FILE *input, CompressMode compMode);
@@ -70,4 +84,51 @@
 extern void encodeRaw(char *rawData, int length, int samplerate, const char *outname, CompressMode compmode);
 extern void setRawAudioType(bool isLittleEndian, bool isStereo, uint8 bitsPerSample);
 
+
+/* Integer definitions for the constants above */
+#define minBitrDef atoi(minBitrDef_str)
+#define maxBitrDef atoi(maxBitrDef_str)
+#define algqualDef atoi(algqualDef_str)
+#define vbrqualDef atoi(vbrqualDef_str)
+#define oggqualDef atoi(oggqualDef_str)
+#define flacCompressDef atoi(flacCompressDef_str)
+#define flacBlocksizeDef atoi(flacBlocksizeDef_str)
+
+/* Perhaps this should be in a seperate file */
+#define kCompressionAudioHelp \
+	"\nParams:\n" \
+	" --mp3        encode to MP3 format (default)\n" \
+	" --vorbis     encode to Vorbis format\n" \
+	" --flac       encode to Flac format\n" \
+	"(If one of these is specified, it must be the first parameter.)\n" \
+	\
+	"\nMP3 mode params:\n" \
+	" -b <rate>    <rate> is the target bitrate(ABR)/minimal bitrate(VBR) (default:" minBitrDef_str "%d)\n" \
+	" -B <rate>    <rate> is the maximum VBR/ABR bitrate (default:%" maxBitrDef_str ")\n" \
+	" --vbr        LAME uses the VBR mode (default)\n" \
+	" --abr        LAME uses the ABR mode\n" \
+	" -V <value>   specifies the value (0 - 9) of VBR quality (0=best) (default:" vbrqualDef_str "%d)\n" \
+	" -q <value>   specifies the MPEG algorithm quality (0-9; 0=best) (default:" algqualDef_str ")\n" \
+	" --silent     the output of LAME is hidden (default:disabled)\n" \
+	\
+	"\nVorbis mode params:\n" \
+	" -b <rate>    <rate> is the nominal bitrate (default:unset)\n" \
+	" -m <rate>    <rate> is the minimum bitrate (default:unset)\n" \
+	" -M <rate>    <rate> is the maximum bitrate (default:unset)\n" \
+	" -q <value>   specifies the value (0 - 10) of VBR quality (10=best) (default:" oggqualDef_str ")\n" \
+	" --silent     the output of oggenc is hidden (default:disabled)\n" \
+	\
+	"\nFlac mode params:\n" \
+	" --fast       FLAC uses compression level 0\n" \
+	" --best       FLAC uses compression level 8\n" \
+	" -<value>     specifies the value (0 - 8) of compression (8=best)(default:" flacCompressDef_str ")\n" \
+	" -b <value>   specifies a blocksize of <value> samples (default:" flacBlocksizeDef_str ")\n" \
+	" --verify     files are encoded and then decoded to check accuracy\n" \
+	" --silent     the output of FLAC is hidden (default:disabled)\n" \
+	\
+	"\n --help     this help message\n" \
+	\
+	"\n\nIf a parameter is not given the default value is used\n" \
+	"If using VBR mode for MP3 -b and -B must be multiples of 8; the maximum is 160!\n";
+
 #endif

Modified: tools/branches/gsoc2009-gui/compress_agos.cpp
===================================================================
--- tools/branches/gsoc2009-gui/compress_agos.cpp	2009-06-10 21:28:16 UTC (rev 41440)
+++ tools/branches/gsoc2009-gui/compress_agos.cpp	2009-06-10 23:55:21 UTC (rev 41441)
@@ -29,42 +29,18 @@
 
 static CompressMode gCompMode = kMP3Mode;
 
-static void end(char *inputPath, char* inputFile) {
+static void end(Filename *inputPath) {
 	int size;
 	char fbuf[2048];
-	char tmp[1024];
-	char *p;
-	const char *head;
 
-	switch (gCompMode) {
-	case kMP3Mode:
-		head = "mp3";
-		break;
-	case kVorbisMode:
-		head = "ogg";
-		break;
-	case kFlacMode:
-		head = "fla";
-		break;
-	default:
-		error("Unknown compression mode");
-	}
+	inputPath->setExtension(audio_extensions[gCompMode]);
 
 	fclose(output_snd);
 	fclose(output_idx);
 	fclose(input);
 
-	/* Remove the extension from the filename if it exists
-	 * so that we can append the new extension
-	*/
-	p = strrchr(inputFile, '.');
-	if (p) {
-		*p = '\0';
-	}
+	output_idx = fopen(inputPath->getFullPath(), "wb");
 
-	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);
@@ -154,61 +130,15 @@
 	return(tot_size);
 }
 
-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");
-	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 compression level 0\n");
- 	printf(" --best       FLAC uses compression level 8\n");
- 	printf(" -<value>     specifies the value (0 - 8) of compression (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("\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 *inputPath, char *inputFile) {
+static void convert_pc(Filename* inputPath) {
 	int i, size, num;
-	char tmp[1024];
 	uint32 filenums[32768];
 	uint32 offsets[32768];
 
-	sprintf(tmp, "%s/%s", inputPath, inputFile);
-	input = fopen(tmp, "rb");
+	input = fopen(inputPath->getFullPath(), "rb");
 	if (!input) {
-		printf("Cannot open file: %s\n", tmp);
+		printf("Cannot open file: %s\n", inputPath->getFullPath());
 		exit(-1);
 	}
 
@@ -247,14 +177,13 @@
 	}
 }
 
-static void convert_mac(char *inputPath) {
+static void convert_mac(Filename *inputPath) {
 	int i, size, num;
-	char tmp[1024];
 	uint32 filenums[32768];
 	uint32 offsets[32768];
 
-	sprintf(tmp, "%s/voices.idx", inputPath);
-	input = fopen(tmp, "rb");
+	inputPath->setFullName("voices.idx");
+	input = fopen(inputPath->getFullPath(), "rb");
 	if (!input) {
 		printf("Cannot open file: %s\n", "voices.idx");
 		exit(-1);
@@ -289,15 +218,17 @@
 		}
 
 		if (filenums[i] != filenums[i - 1]) {
-			sprintf(tmp, "%s/voices%d.dat", inputPath, filenums[i]);
+			char filename[256];
+			sprintf(filename, "voices%d.dat", filenums[i]);
+			inputPath->setFullName(filename);
 
 			if (input) {
 				fclose(input);
 			}
 
-			input = fopen(tmp, "rb");
+			input = fopen(inputPath->getFullPath(), "rb");
 			if (!input) {
-				printf("Cannot open file: %s\n", tmp);
+				printf("Cannot open file: %s\n", inputPath->getFullPath());
 				exit(-1);
 			}
 		}
@@ -310,71 +241,35 @@
 	}
 }
 
+const char *helptext = "\nUsage: %s [params] [--mac] <file>\n" kCompressionAudioHelp;
+
 int main(int argc, char *argv[]) {
-	int i;
-	char inputFile[256];
-	char inputPath[768];
 	bool convertMac = false;
 
-	if (argc < 2) {
-		showhelp(argv[0]);
-	}
+	Filename inpath;
+	int first_arg = 1;
+	int last_arg = argc - 1;
 
-	/* compression mode */
-	gCompMode = kMP3Mode;
-	i = 1;
+	parseHelpArguments(argv, argc, helptext);
 
-	if (strcmp(argv[i], "--mp3") == 0) {
-		gCompMode = kMP3Mode;
-		i++;
-	} else if (strcmp(argv[i], "--vorbis") == 0) {
-		gCompMode = kVorbisMode;
-		i++;
-	} else if (strcmp(argv[i], "--flac") == 0) {
-		gCompMode = kFlacMode;
-		i++;
-	}
+	gCompMode = process_audio_params(argc, argv, &first_arg);
 
-	if (strcmp(argv[i], "--mac") == 0) {
-		convertMac = true;
-		i++;
+	if(gCompMode == kNoAudioMode) {
+		// Unknown mode (failed to parse arguments), display help and exit
+		printf(helptext, argv[0]);
+		exit(2);
 	}
 
-	switch (gCompMode) {
-	case kMP3Mode:
-		tempEncoded = TEMP_MP3;
-		if (!process_mp3_parms(argc, argv, i)) {
-			showhelp(argv[0]);
-		}
+	inpath.setFullPath(argv[first_arg]);
 
-		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;
-	}
-
 	if (convertMac) {
-		strcpy(inputFile, "simon2");
-		strcpy(inputPath, argv[argc - 1]);
-		convert_mac(inputPath);
+		convert_mac(&inpath);
+		inpath.setFullName("simon2");
 	} else {
-		getPath(argv[argc - 1], inputPath);
-		getFilename(argv[argc - 1], inputFile);
-		convert_pc(inputPath, inputFile);
+		convert_pc(&inpath);
 	}
 
-	end(inputPath, inputFile);
+	end(&inpath);
 
 	return(0);
 }

Modified: tools/branches/gsoc2009-gui/compress_gob.cpp
===================================================================
--- tools/branches/gsoc2009-gui/compress_gob.cpp	2009-06-10 21:28:16 UTC (rev 41440)
+++ tools/branches/gsoc2009-gui/compress_gob.cpp	2009-06-10 23:55:21 UTC (rev 41441)
@@ -52,35 +52,47 @@
 	FILE *stk;
 	FILE *gobConf;
 	uint16 chunkCount;
+	Filename inpath, outpath;
+	int first_arg = 1;
+	int last_arg = argc - 1;
 
-	if ((argc < 2) || !strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")) {
-		printf("Usage: %s <Conf file>\n\n", argv[0]);
-		printf("The archive will be created into the current directory.\n");
-		return -1;
-	}
+	// Check if we should display some helpful text
+	parseHelpArguments(argv, argc, "\nUsage: %s [-o <output> = out.stk] <input file>\n");
 
-	if (!(gobConf = fopen(argv[1], "r")))
-		error("Couldn't open conf file \"%s\"", argv[1]);
+	// Now we try to find the proper output
+	// also make sure we skip those arguments
+	if (parseOutputFileArguments(&outpath, argv, argc, first_arg))
+		first_arg += 2;
+	else if (parseOutputFileArguments(&outpath, argv, argc, last_arg - 2))
+		last_arg -= 2;
+	else
+		// Standard output
+		outpath.setFullPath("out.stk");
 
-	outFilename = new char[strlen(argv[1]) + 5];
-	getFilename(argv[1], outFilename);
+	if(last_arg - first_arg != 0)
+		error("Expected only one input file");
 
-	tmpStr = strstr(outFilename, ".");
-	if (tmpStr != 0)
-		strcpy(tmpStr, ".stk");
-	else
-		strcat(outFilename, ".stk");
+	// Open input (config) file
+	if (!(gobConf = fopen(argv[first_arg], "r")))
+		error("Couldn't open conf file '%s'", argv[first_arg]);
 
+	// We output with .stk extension
+	outpath.setExtension(".stk");
+
+	// Open output filk
 	if (!(stk = fopen(outFilename, "wb")))
 		error("Couldn't create file \"%s\"", outFilename);
 
+	// Read the input into memory
 	chunks = readChunkConf(gobConf, chunkCount);
 	fclose(gobConf);
 
+	// Output in compressed format
 	writeEmptyHeader (stk, chunkCount);
 	writeBody(stk, chunkCount, chunks);
 	rewriteHeader(stk, chunkCount, chunks);
 
+	// Cleanup
 	fflush(stk);
 	delete chunks;
 	fclose(stk);

Modified: tools/branches/gsoc2009-gui/compress_kyra.cpp
===================================================================
--- tools/branches/gsoc2009-gui/compress_kyra.cpp	2009-06-10 21:28:16 UTC (rev 41440)
+++ tools/branches/gsoc2009-gui/compress_kyra.cpp	2009-06-10 23:55:21 UTC (rev 41441)
@@ -23,112 +23,57 @@
 #include "compress.h"
 #include "kyra_pak.h"
 
-static void showhelp(const char *exename);
-static void process(const char *infile, const char *output);
-static void processKyra3(const char *infile, const char *output);
-static bool detectKyra3File(const char *infile);
+static void process(Filename *infile, Filename *output);
+static void processKyra3(Filename *infile, Filename *output);
+static bool detectKyra3File(Filename *infile);
 
 #define TEMPFILE "TEMP.VOC"
 
 static CompressMode gCompMode = kMP3Mode;
 
+const char *helptext = "\nUsage: %s [params] [mode params] [-o out = ] <infile>\n" kCompressionAudioHelp;
+
 int main(int argc, char *argv[]) {
-	if (argc < 3)
-		showhelp(argv[0]);
+	Filename inpath, outpath;
+	int first_arg = 1;
+	int last_arg = argc - 1;
 
-	char inputFile[1024];
-	char outputFile[1024];
-	int i = 0;
+	parseHelpArguments(argv, argc, helptext);
 
-	/* Compression mode */
-	gCompMode = kMP3Mode;
-	i = 1;
+	// Compression mode
+	gCompMode = process_audio_params(argc, argv, &first_arg);
 
-	for (; i < argc - 2; ++i) {
-		if (strcmp(argv[i], "--mp3") == 0)
-			gCompMode = kMP3Mode;
-		else if (strcmp(argv[i], "--vorbis") == 0)
-			gCompMode = kVorbisMode;
-		else if (strcmp(argv[i], "--flac") == 0)
-			gCompMode = kFlacMode;
-		else
-			break;
+	if(gCompMode == kNoAudioMode) {
+		// Unknown mode (failed to parse arguments), display help and exit
+		printf(helptext, argv[0]);
+		exit(2);
 	}
+	
+	// Now we try to find the proper output file
+	// also make sure we skip those arguments
+	if (parseOutputFileArguments(&outpath, argv, argc, first_arg))
+		first_arg += 2;
+	else if (parseOutputFileArguments(&outpath, argv, argc, last_arg - 2))
+		last_arg -= 2;
+	else
+		// Standard output file is 'out'
+		outpath.setFullPath("out");
+	
+	inpath.setFullName(argv[first_arg]);
+	outpath.setFullName(argv[first_arg]);
 
-	switch (gCompMode) {
-	case kMP3Mode:
-		tempEncoded = TEMP_MP3;
-		if (!process_mp3_parms(argc - 2, argv, i))
-			showhelp(argv[0]);
-		break;
-	case kVorbisMode:
-		tempEncoded = TEMP_OGG;
-		if (!process_ogg_parms(argc - 2, argv, i))
-			showhelp(argv[0]);
-		break;
-	case kFlacMode:
-		tempEncoded = TEMP_FLAC;
-		if (!process_flac_parms(argc - 2, argv, i))
-			showhelp(argv[0]);
-		break;
-	}
+	if (inpath.equals(&outpath))
+		error("Infile and outfile cannot be the same file");
 
-	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");
-
-	bool isKyra3 = detectKyra3File(inputFile);
+	bool isKyra3 = detectKyra3File(&inpath);
 	if (!isKyra3)
-		process(inputFile, outputFile);
+		process(&inpath, &outpath);
 	else
-		processKyra3(inputFile, outputFile);
+		processKyra3(&inpath, &outpath);
 
 	return 0;
 }
 
-static void showhelp(const char *exename) {
-	printf("\nUsage: %s [params] [mode 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);
-	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 compression level 0\n");
- 	printf(" --best       FLAC uses compression level 8\n");
- 	printf(" -<value>     specifies the value (0 - 8) of compression (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);
-}
-
 static bool hasSuffix(const char *str, const char *suf) {
 	const int sufSize = strlen(suf);
 
@@ -141,52 +86,16 @@
 	return (scumm_stricmp(&str[off], suf) == 0);
 }
 
-static void changeFileExt(char *filename) {
-	char *str = filename + strlen(filename) - 4;
-
-	if (*str != '.')
-		error("Invalid filename '%s'", filename);
-
-	++str;
-
-	switch (gCompMode) {
-	case kMP3Mode:
-		*str++ = 'm';
-		*str++ = 'p';
-		*str++ = '3';
-		break;
-
-	case kVorbisMode:
-		*str++ = 'o';
-		*str++ = 'g';
-		*str++ = 'g';
-		break;
-
-	case kFlacMode:
-		*str++ = 'f';
-		*str++ = 'l';
-		*str++ = 'a';
-		break;
-
-	default:
-		error("Unknown compression mode");
-	}
-
-	*str = 0;
-}
-
-
-static void process(const char *infile, const char *outfile) {
+static void process(Filename *infile, Filename *outfile) {
 	PAKFile input, output;
 
-	if (!input.loadFile(infile, false))
+	if (!input.loadFile(infile->getFullPath(), false))
 		return;
 
-	if (!output.loadFile(0, false))
+	if (!output.loadFile(NULL, false))
 		return;
 
 	PAKFile::cFileList *list = input.getFileList();
-	char outputName[32];
 
 	for (; list; list = list->next) {
 		// Detect VOC file from content instead of extension. This is needed for Lands of Lore TLK files.
@@ -194,31 +103,23 @@
 			continue;
 
 		if (list->data[26] != 1) {
-			warning("'%s' contains broken VOC file '%s' skipping it...", infile, list->filename);
+			warning("'%s' contains broken VOC file '%s' skipping it...", infile->getFullPath(), list->filename);
 			continue;
 		}
 
+		Filename outputName;
 		input.outputFileAs(list->filename, TEMPFILE);
-		strncpy(outputName, list->filename, sizeof(outputName) - 5);
-		outputName[sizeof(outputName) - 5] = 0;
+		strncpy(outputName._path, list->filename, 27);
+		outputName._path[27] = 0;
 
 		FILE *tempFile = fopen(TEMPFILE, "rb");
 		fseek(tempFile, 26, SEEK_CUR);
 		extractAndEncodeVOC(TEMP_RAW, tempFile, gCompMode);
 		fclose(tempFile);
 
-		if (hasSuffix(outputName, ".VOC")) {
-			// When a ".VOC" extension is present we will replace it with a extension
-			// based on the compression method used.
-			changeFileExt(outputName);
-		} else {
-			// When no ".VOC" extension is present we will just append a extension
-			// based on the compression method used.
-			strcat(outputName, ".VOC");
-			changeFileExt(outputName);
-		}
+		outputName.setExtension(audio_extensions[gCompMode]);
 
-		output.addFile(outputName, tempEncoded);
+		output.addFile(outputName.getFullPath(), tempEncoded);
 
 		unlink(TEMPFILE);
 		unlink(TEMP_RAW);
@@ -226,9 +127,9 @@
 	}
 
 	if (output.getFileList())
-		output.saveFile(outfile);
+		output.saveFile(outfile->getFullPath());
 	else
-		printf("file '%s' doesn't contain any .voc files\n", infile);
+		printf("file '%s' doesn't contain any .voc files\n", infile->getFullPath());
 }
 
 // Kyra3 specifc code
@@ -315,7 +216,7 @@
 				/* NOTE: count is signed! */
 				count <<= 3;
 				curSample += (count >> 3);
-				outputBuffer[j++] = curSample;
+				outputBuffer[j++] = (byte)curSample;
 				remaining--;
 			} else {
 				for (; count >= 0; count--) {
@@ -331,11 +232,11 @@
 
 				curSample += WSTable4Bit[code & 0x0f];
 				curSample = clip8BitSample(curSample);
-				outputBuffer[j++] = curSample;
+				outputBuffer[j++] = (byte)curSample;
 
 				curSample += WSTable4Bit[code >> 4];
 				curSample = clip8BitSample(curSample);
-				outputBuffer[j++] = curSample;
+				outputBuffer[j++] = (byte)curSample;
 
 				remaining -= 2;
 			}
@@ -346,26 +247,26 @@
 
 				curSample += WSTable2Bit[code & 0x03];
 				curSample = clip8BitSample(curSample);
-				outputBuffer[j++] = curSample;
+				outputBuffer[j++] = (byte)curSample;
 
 				curSample += WSTable2Bit[(code >> 2) & 0x03];
 				curSample = clip8BitSample(curSample);
-				outputBuffer[j++] = curSample;
+				outputBuffer[j++] = (byte)curSample;
 
 				curSample += WSTable2Bit[(code >> 4) & 0x03];
 				curSample = clip8BitSample(curSample);
-				outputBuffer[j++] = curSample;
+				outputBuffer[j++] = (byte)curSample;
 
 				curSample += WSTable2Bit[(code >> 6) & 0x03];
 				curSample = clip8BitSample(curSample);
-				outputBuffer[j++] = curSample;
+				outputBuffer[j++] = (byte)curSample;
 
 				remaining -= 4;
 			}
 			break;
 		default:
 			for (; count >= 0; count--) {
-				outputBuffer[j++] = curSample;
+				outputBuffer[j++] = (byte)curSample;
 				remaining--;
 			}
 		}
@@ -430,28 +331,25 @@
 	return 0;
 }
 
-static void processKyra3(const char *infile, const char *outfile) {
-	if (hasSuffix(infile, ".AUD")) {
-		char outname[1024];
+static void processKyra3(Filename *infile, Filename *outfile) {
+	if (infile->hasExtension("AUD")) {
+		outfile->setExtension(audio_extensions[gCompMode]);
 
-		strncpy(outname, outfile, sizeof(outname));
-		changeFileExt(outname);
-
-		FILE *input = fopen(infile, "rb");
+		FILE *input = fopen(infile->getFullPath(), "rb");
 		if (!input)
-			error("Couldn't open file '%s'", infile);
+			error("Couldn't open file '%s'", infile->getFullPath());
 
-		compressAUDFile(input, outname);
+		compressAUDFile(input, outfile->getFullPath());
 
 		fclose(input);
-	} else if (hasSuffix(infile, ".TLK")) {
+	} else if (infile->hasExtension("TLK")) {
 		PAKFile output;
 
-		FILE *input = fopen(infile, "rb");
+		FILE *input = fopen(infile->getFullPath(), "rb");
 		if (!input)
-			error("Couldn't open file '%s'", infile);
+			error("Couldn't open file '%s'", infile->getFullPath());
 
-		if (!output.loadFile(0, false))
+		if (!output.loadFile(NULL, false))
 			return;
 
 		uint16 files = readUint16LE(input);
@@ -463,14 +361,12 @@
 			uint32 resOffset = readUint32LE(input);
 
 			char outname[16];
-			snprintf(outname, 16, "%.08u.AUD", resFilename);
-			changeFileExt(outname);
+			snprintf(outname, 16, "%.08u.%s", resFilename, audio_extensions[gCompMode]);
 
 			const DuplicatedFile *file = findDuplicatedFile(resOffset, red, files);
 			if (file) {
 				char linkname[16];
-				snprintf(linkname, 16, "%.08u.AUD", file->resFilename);
-				changeFileExt(linkname);
+				snprintf(linkname, 16, "%.08u.%s", file->resFilename, audio_extensions[gCompMode]);
 
 				output.linkFiles(outname, linkname);
 			} else {
@@ -494,26 +390,26 @@
 		fclose(input);
 
 		if (output.getFileList())
-			output.saveFile(outfile);
+			output.saveFile(outfile->getFullPath());
 	} else {
-		error("Unsupported file '%s'", infile);
+		error("Unsupported file '%s'", infile->getFullPath());
 	}
 }
 
-bool detectKyra3File(const char *infile) {
-	if (hasSuffix(infile, ".AUD")) {
+bool detectKyra3File(Filename *infile) {
+	if (infile->hasExtension("AUD")) {
 		return true;
-	} else if (hasSuffix(infile, ".VRM") || hasSuffix(infile, ".PAK")) {
-		if (!PAKFile::isPakFile(infile))
-			error("Unknown filetype of file: '%s'", infile);
+	} else if (infile->hasExtension("VRM") || infile->hasExtension("PAK")) {
+		if (!PAKFile::isPakFile(infile->getFullPath()))
+			error("Unknown filetype of file: '%s'", infile->getFullPath());
 		return false;
-	} else if (hasSuffix(infile, ".TLK")) {
-		if (PAKFile::isPakFile(infile))
+	} else if (infile->hasExtension("TLK")) {
+		if (PAKFile::isPakFile(infile->getFullPath()))
 			return false;
 
-		FILE *f = fopen(infile, "rb");
+		FILE *f = fopen(infile->getFullPath(), "rb");
 		if (!f)
-			error("Couldn't open file '%s'", infile);
+			error("Couldn't open file '%s'", infile->getFullPath());
 
 		uint16 entries = readUint16LE(f);
 		uint32 entryTableSize = (entries * 8);
@@ -521,7 +417,7 @@
 
 		if (entryTableSize + 2 > filesize) {
 			fclose(f);
-			error("Unknown filetype of file: '%s'", infile);
+			error("Unknown filetype of file: '%s'", infile->getFullPath());
 		}
 
 		uint32 offset = 0;
@@ -530,12 +426,12 @@
 			offset = readUint32LE(f);
 
 			if (offset > filesize)
-				error("Unknown filetype of file: '%s'", infile);
+				error("Unknown filetype of file: '%s'", infile->getFullPath());
 		}
 
 		return true;
 	}
 
-	error("Unknown filetype of file: '%s'", infile);
+	error("Unknown filetype of file: '%s'", infile->getFullPath());
 }
 

Modified: tools/branches/gsoc2009-gui/compress_queen.cpp
===================================================================
--- tools/branches/gsoc2009-gui/compress_queen.cpp	2009-06-10 21:28:16 UTC (rev 41440)
+++ tools/branches/gsoc2009-gui/compress_queen.cpp	2009-06-10 23:55:21 UTC (rev 41441)
@@ -121,47 +121,6 @@
 
 const struct GameVersion *version;
 
-void showhelp(char *exename) {
-	printf("\nUsage: %s [params] queen.1\n", exename);
-
-	printf("\nParams:\n");
-
-	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 compression level 0\n");
-	printf(" --best       FLAC uses compression level 8\n");
-	printf(" -<value>     specifies the value (0 - 8) of compression (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;
@@ -201,9 +160,8 @@
 	}
 }
 
-void createFinalFile(char *inputPath) {
+void createFinalFile(Filename *inputPath) {
 	FILE *inTbl, *inData, *outFinal;
-	char tmp[1024];
 	int i;
 	uint32 dataStartOffset;
 	uint32 dataSize;
@@ -212,9 +170,9 @@
 	checkOpen(inTbl, TEMP_TBL);
 	inData = fopen(TEMP_DAT, "rb");
 	checkOpen(inData, TEMP_DAT);
-	sprintf(tmp, "%s/%s", inputPath, FINAL_OUT);
-	outFinal = fopen(tmp, "wb");
-	checkOpen(outFinal, FINAL_OUT);
+	inputPath->setFullName(FINAL_OUT);
+	outFinal = fopen(inputPath->getFullPath(), "wb");
+	checkOpen(outFinal, inputPath->getFullPath());
 
 	dataStartOffset = fileSize(inTbl) + EXTRA_TBL_HEADER;
 	dataSize = fileSize(inData);
@@ -248,71 +206,48 @@
 	unlink(TEMP_DAT);
 }
 
+const char *helptext = "\nUsage: %s [params] queen.1\n" kCompressionAudioHelp;
+
 int main(int argc, char *argv[]) {
 	FILE *inputData, *inputTbl, *outputTbl, *outputData, *tmpFile, *compFile;
 	uint8 compressionType = COMPRESSION_NONE;
-	char inputPath[768];
-	char tblPath[1024];
+	Filename inpath, outpath;;
 	char tmp[5];
 	int size, i = 1;
 	uint32 prevOffset;
+	int first_arg = 1;
+	int last_arg = argc - 1;
 
-	if (argc < 2) {
-		showhelp(argv[0]);
-	}
+	parseHelpArguments(argv, argc, helptext);
 
-	/* compression mode */
-	compressionType = COMPRESSION_MP3;
-	gCompMode = kMP3Mode;
+	gCompMode = process_audio_params(argc, argv, &first_arg);
 
-	if (strcmp(argv[1], "--mp3") == 0) {
-		compressionType = COMPRESSION_MP3;
-		gCompMode = kMP3Mode;
-		i++;
-	} else if (strcmp(argv[1], "--vorbis") == 0) {
-		compressionType = COMPRESSION_OGG;
-		gCompMode = kVorbisMode;
-		i++;
-	} else if (strcmp(argv[1], "--flac") == 0) {
-		compressionType = COMPRESSION_FLAC;
-		gCompMode = kFlacMode;
-		i++;
+	if(gCompMode == kNoAudioMode) {
+		// Unknown mode (failed to parse arguments), display help and exit
+		printf(helptext, argv[0]);
+		exit(2);
 	}
+	
+	// Now we try to find the proper output file
+	// also make sure we skip those arguments
+	if (parseOutputFileArguments(&outpath, argv, argc, first_arg))
+		first_arg += 2;
+	else if (parseOutputFileArguments(&outpath, argv, argc, last_arg - 2))
+		last_arg -= 2;
+	else
+		// Standard output
+		outpath.setFullPath("out");
 
-	switch (gCompMode) {
-	case kMP3Mode:
-		tempEncoded = TEMP_MP3;
-		if (!process_mp3_parms(argc, argv, i)) {
-			showhelp(argv[0]);
-		}
+	inpath.setFullPath(argv[first_arg]);
 
-		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]);
+	inputData = fopen(inpath.getFullPath(), "rb");
+	checkOpen(inputData, inpath.getFullPath());
 
 	/* Open TBL file (QUEEN.TBL) */
-	sprintf(tblPath, "%s/%s", inputPath, INPUT_TBL);
-	inputTbl = fopen(tblPath, "rb");
-	checkOpen(inputTbl, INPUT_TBL);
+	inpath.setFullName(INPUT_TBL);
+	inputTbl = fopen(inpath.getFullPath(), "rb");
+	checkOpen(inputTbl, inpath.getFullPath());
 
 	size = fileSize(inputData);
 	fread(tmp, 1, 4, inputTbl);
@@ -443,7 +378,7 @@
 	fclose(inputData);
 
 	/* Merge the temporary table and temporary datafile to create final file */
-	createFinalFile(inputPath);
+	createFinalFile(&inpath);
 
 	return 0;
 }

Modified: tools/branches/gsoc2009-gui/compress_saga.cpp
===================================================================
--- tools/branches/gsoc2009-gui/compress_saga.cpp	2009-06-10 21:28:16 UTC (rev 41440)
+++ tools/branches/gsoc2009-gui/compress_saga.cpp	2009-06-10 23:55:21 UTC (rev 41441)
@@ -147,15 +147,14 @@
 
 // --------------------------------------------------------------------------------
 
-bool detectFile(const char *inFileName) {
+bool detectFile(Filename *infile) {
 	int gamesCount = ARRAYSIZE(gameDescriptions);
 	int i, j;
 	uint8 md5sum[16];
 	char md5str[32+1];
-	char currentFile[256];
 
-	Common::md5_file(inFileName, md5sum, FILE_MD5_BYTES);
-	printf("Input file name: %s\n", inFileName);
+	Common::md5_file(infile->getFullPath(), md5sum, FILE_MD5_BYTES);
+	printf("Input file name: %s\n", infile->getFullPath());
 	for (j = 0; j < 16; j++) {
 		sprintf(md5str + j*2, "%02x", (int)md5sum[j]);
 	}
@@ -177,11 +176,7 @@
 				// Filename based detection, used in IHNM, as all its sound files have the
 				// same encoding
 
-				getFilename(inFileName, currentFile);
-				for (unsigned int k = 0; k < strlen(currentFile); k++)
-					currentFile[k] = tolower(currentFile[k]);
-
-				if (strcmp(gameDescriptions[i].filesDescriptions[j].fileName, currentFile) == 0) {
+				if (scumm_stricmp(gameDescriptions[i].filesDescriptions[j].fileName, infile->getFullName()) == 0) {
 					currentGameDescription = &gameDescriptions[i];
 					currentFileDescription = &currentGameDescription->filesDescriptions[j];
 
@@ -343,9 +338,7 @@
 	error("Unsupported resourceType %ul\n", currentFileDescription->resourceType);
 }
 
-void sagaEncode(const char *inputPath, const char *inputFileName, const char *inputFileNameExt) {
-	char inputFileNameWithExt[256];
-	char outputFileNameWithExt[256];
+void sagaEncode(Filename *inpath, Filename *outpath) {
 	FILE *inputFile;
 	FILE *outputFile;
 	uint32 inputFileSize;
@@ -356,8 +349,7 @@
 	Record *inputTable;
 	Record *outputTable;
 
-	sprintf(inputFileNameWithExt, "%s/%s%s", inputPath, inputFileName, inputFileNameExt);
-	inputFile = fopen(inputFileNameWithExt, "rb");
+	inputFile = fopen(inpath->getFullPath(), "rb");
 	inputFileSize = fileSize(inputFile);
 	printf("Filesize: %ul\n", inputFileSize);
 	/*
@@ -399,15 +391,18 @@
 		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)) {
+			(inputTable[i].offset + inputTable[i].size > inputFileSize)) {
 			error("The offset points outside the file");
 		}
 
 	}
 	outputTable = (Record*)malloc(resTableCount * sizeof(Record));
 
-	sprintf(outputFileNameWithExt, "%s/%s.cmp", inputPath, inputFileName);
-	outputFile = fopen(outputFileNameWithExt, "wb");
+	if(outpath->empty()) {
+		*outpath = *inpath;
+		outpath->setExtension(".cmp");
+	}
+	outputFile = fopen(outpath->getFullPath(), "wb");
 
 	for (i = 0; i < resTableCount; i++) {
 		fseek(inputFile, inputTable[i].offset, SEEK_SET);
@@ -441,122 +436,59 @@
 	printf("Done!\n");
 }
 
-void showhelp(char *exename) {
-	printf("\nUsage: %s [params] <file>\n", exename);
+const char *helptext = "\nUsage: %s [params] [mode params] [-o out = 'infile.cmp'] <infile>\n" kCompressionAudioHelp;
 
-	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);
-	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 compression level 0\n");
- 	printf(" --best       FLAC uses compression level 8\n");
- 	printf(" -<value>     specifies the value (0 - 8) of compression (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);
-}
-
 int main(int argc, char *argv[]) {
-	int	i;
-	char inputPath[768];
-	char inputFileName[256];
-	char inputFileNameWithExt[256];
+	Filename inpath, outpath;
+	int first_arg = 1;
+	int last_arg = argc - 1;
 
-	if (argc < 2) {
-		showhelp(argv[0]);
-	}
 
-	/* compression mode */
-	gCompMode = kMP3Mode;
-	i = 1;
+	parseHelpArguments(argv, argc, helptext);
 
-	if (strcmp(argv[1], "--mp3") == 0) {
-		gCompMode = kMP3Mode;
-		i++;
-	} else if (strcmp(argv[1], "--vorbis") == 0) {
-		gCompMode = kVorbisMode;
-		i++;
-	} else if (strcmp(argv[1], "--flac") == 0) {
-		gCompMode = kFlacMode;
-		i++;
-	}
+	// compression mode
+	gCompMode = process_audio_params(argc, argv, &first_arg);
 
-	switch (gCompMode) {
-	case kMP3Mode:
-		tempEncoded = TEMP_MP3;
-		if (!process_mp3_parms(argc, argv, i)) {
-			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;
+	if(gCompMode == kNoAudioMode) {
+		// Unknown mode (failed to parse arguments), display help and exit
+		printf(helptext, argv[0]);
+		exit(2);
 	}
 
-	getPath(argv[argc - 1], inputPath);
-	getFilename(argv[argc - 1], inputFileName);
+	// Now we try to find the proper output file
+	// also make sure we skip those arguments
+	if (parseOutputFileArguments(&outpath, argv, argc, first_arg))
+		first_arg += 2;
+	else if (parseOutputFileArguments(&outpath, argv, argc, last_arg - 2))
+		last_arg -= 2;;
 
-	if (strrchr(inputFileName, '.') != NULL) {
-		error("Please specify the filename without an extension");
-	}
+	inpath.setFullPath(argv[first_arg]);
 
 	// ITE
-	sprintf(inputFileNameWithExt, "%s/%s.rsc", inputPath, inputFileName);
-	if (detectFile(inputFileNameWithExt)) {
-		sagaEncode(inputPath, inputFileName, ".rsc");
+	inpath.setExtension(".rsc");
+	if (detectFile(&inpath)) {
+		sagaEncode(&inpath, &outpath);
 	} else {
 		// IHNM
-		sprintf(inputFileNameWithExt, "%s/%s.res", inputPath, inputFileName);
-		if (detectFile(inputFileNameWithExt)) {
-			sagaEncode(inputPath, inputFileName, ".res");
+		inpath.setExtension(".res");
+		if (detectFile(&inpath)) {
+			sagaEncode(&inpath, &outpath);
 		} else {
 			// Check for "inherit the earth voices"
-			if (detectFile("inherit the earth voices")) {
-				sagaEncode(inputPath, "inherit the earth voices", "");
+			inpath.setFullName("inherit the earth voices");
+			if (detectFile(&inpath)) {
+				sagaEncode(&inpath, &outpath);
 			} else {
 				// Check for MacBinary
-				sprintf(inputFileNameWithExt, "%s/%s.bin", inputPath, inputFileName);
-				if (detectFile(inputFileNameWithExt)) {
-					sagaEncode(inputPath, inputFileName, ".bin");
+				inpath.setExtension(".bin");
+				if (detectFile(&inpath)) {
+					sagaEncode(&inpath, &outpath);
+				} else {
+					error("Failed to compress file %s", inpath.getFullPath());
 				}
 			}
 		}
 	}
 
-	return (0);
+	return 0;
 }

Modified: tools/branches/gsoc2009-gui/compress_scumm_bun.cpp
===================================================================
--- tools/branches/gsoc2009-gui/compress_scumm_bun.cpp	2009-06-10 21:28:16 UTC (rev 41440)
+++ tools/branches/gsoc2009-gui/compress_scumm_bun.cpp	2009-06-10 23:55:21 UTC (rev 41441)
@@ -613,45 +613,6 @@
 	return output_size;
 }
 
-void showhelp(char *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);
-	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 compression level 0\n");
- 	printf(" --best       FLAC uses compression level 8\n");
- 	printf(" -<value>     specifies the value (0 - 8) of compression (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);
-}
-
 struct BundleAudioTable {
 	char filename[24];
 	int size;
@@ -1127,68 +1088,54 @@
 	cbundleCurIndex++;
 }
 
+const char *helptext = "\nUsage: %s [mode] [mode-params] [-o outputfile = inputfile.san] <inputfile>\n";
+
 int main(int argc, char *argv[]) {
-	if (argc < 4)
-		showhelp(argv[0]);
+	Filename inpath, outpath;
+	int first_arg = 1;
+	int last_arg = argc - 1;
 
-	char inputDir[768];
-	char outputDir[768];
-	char inputFilename[256];
-	char tmpPath[768];
+	parseHelpArguments(argv, argc, helptext);
 
-	uint32 tag;
-	int32 numFiles, offset;
-	int i = 1;
+	// compression mode
+	gCompMode = process_audio_params(argc, argv, &first_arg);
 
-	strcpy(inputFilename, argv[argc - 3]);
-	strcpy(inputDir, argv[argc - 2]);
-	strcpy(outputDir, argv[argc - 1]);
-
-	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(gCompMode == kNoAudioMode) {
+		// Unknown mode (failed to parse arguments), display help and exit
+		printf(helptext, argv[0]);
+		exit(2);
 	}
 
-	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");
-	}
+	uint32 tag;
+	int32 numFiles, offset;
 
-	char *index = strrchr(inputFilename, '.');
-	if (index != NULL)
-		*index = 0;
+	// Now we try to find the proper output file
+	// also make sure we skip those arguments
+	if (parseOutputFileArguments(&outpath, argv, argc, first_arg))
+		first_arg += 2;
+	else if (parseOutputFileArguments(&outpath, argv, argc, last_arg - 2))
+		last_arg -= 2;
+	else 
+		// Just leave it empty, we just change extension of input file
+		;
 
-	sprintf(tmpPath, "%s/%s.bun", inputDir, inputFilename);
+	inpath.setFullPath(argv[first_arg]);
 
-	FILE *input = fopen(tmpPath, "rb");
+	FILE *input = fopen(inpath.getFullPath(), "rb");
 	if (!input) {
-		printf("Cannot open file: %s\n", tmpPath);
+		printf("Cannot open file: %s\n", inpath.getFullPath());
 		exit(-1);
 	}
 
-	sprintf(tmpPath, "%s/%s.bun", outputDir, inputFilename);
+	if(outpath.empty()) {
+		// Change extension for output
+		outpath = inpath;
+		outpath.setExtension(".bun");
+	}
 
-	FILE *output = fopen(tmpPath, "wb");
+	FILE *output = fopen(outpath.getFullPath(), "wb");
 	if (!output) {
-		printf("Cannot open file: %s\n", tmpPath);
+		printf("Cannot open file: %s\n", outpath.getFullPath());
 		exit(-1);
 	}
 
@@ -1206,7 +1153,7 @@
 	bundleTable = (BundleAudioTable *)malloc(numFiles * sizeof(BundleAudioTable));
 	fseek(input, offset, SEEK_SET);
 
-	for (i = 0; i < numFiles; i++) {
+	for (int i = 0; i < numFiles; i++) {
 		char filename[13], c;
 		int z = 0;
 		int z2;
@@ -1224,19 +1171,21 @@
 		bundleTable[i].size = readUint32BE(input);
 	}
 
-	for (i = 0; i < numFiles; i++) {
+	for (int i = 0; i < numFiles; i++) {
 		if (strcmp(bundleTable[i].filename, "PRELOAD.") == 0)
 			continue;
 		int offsetData = 0, bits = 0, freq = 0, channels = 0;
 		int32 size = 0;
 		byte *compFinal = decompressBundleSound(i, input, size);
 		writeToRMAPFile(compFinal, output, bundleTable[i].filename, offsetData, bits, freq, channels);
-		writeRegions(compFinal + offsetData, bits, freq, channels, outputDir, bundleTable[i].filename, output);
+		char outdir[1024];
+		outpath.getPath(outdir);
+		writeRegions(compFinal + offsetData, bits, freq, channels, outdir, bundleTable[i].filename, output);
 		free(compFinal);
 	}
 
 	int32 curPos = ftell(output);
-	for (i = 0; i < cbundleCurIndex; i++) {
+	for (int i = 0; i < cbundleCurIndex; i++) {
 		fwrite(cbundleTable[i].filename, 24, 1, output);
 		writeUint32BE(output, cbundleTable[i].offset);
 		writeUint32BE(output, cbundleTable[i].size);

Modified: tools/branches/gsoc2009-gui/compress_scumm_san.cpp
===================================================================
--- tools/branches/gsoc2009-gui/compress_scumm_san.cpp	2009-06-10 21:28:16 UTC (rev 41440)
+++ tools/branches/gsoc2009-gui/compress_scumm_san.cpp	2009-06-10 23:55:21 UTC (rev 41441)
@@ -23,26 +23,6 @@
 #include "compress.h"
 #include "zlib.h"
 
-void showhelp(char *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);
-	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");
-	exit(2);
-}
-
 struct FrameInfo {
 	int32 frameSize;
 	int32 offsetOutput;
@@ -235,7 +215,8 @@
 	}
 }
 
-void handleComiIACT(FILE *input, int size, char *outputDir, char *inputFilename, char *tmpPath) {
+void handleComiIACT(FILE *input, int size, const char *outputDir, const char *inputFilename) {
+	char tmpPath[1024];
 	fseek(input, 10, SEEK_CUR);
 	int bsize = size - 18;
 	byte output_data[0x1000];
@@ -273,7 +254,7 @@
 	}
 }
 
-void prepareForMixing(char *outputDir, char *inputFilename) {
+void prepareForMixing(const char *outputDir, const char *inputFilename) {
 	char filename[200];
 
 	printf("Decompresing tracks files...\n");
@@ -392,7 +373,7 @@
 
 	a = val;
 }
-void mixing(char *outputDir, char *inputFilename, int frames, int fps) {
+void mixing(const char *outputDir, const char *inputFilename, int frames, int fps) {
 	char wavPath[200];
 	char filename[200];
 	int l, r, z;
@@ -538,8 +519,9 @@
 	return size;
 }
 
-void handleAudioTrack(int index, int trackId, int frame, int nbframes, FILE *input, char *outputDir,
-					  char *inputFilename, char *tmpPath, int &size, int volume, int pan, bool iact) {
+void handleAudioTrack(int index, int trackId, int frame, int nbframes, FILE *input, const char *outputDir,
+					  const char *inputFilename, int &size, int volume, int pan, bool iact) {
+	char tmpPath[1024];
 	AudioTrackInfo *audioTrack = NULL;
 	if (index == 0) {
 		audioTrack = allocAudioTrack(trackId, frame);
@@ -607,7 +589,7 @@
 	}
 }
 
-void handleDigIACT(FILE *input, int size, char *outputDir, char *inputFilename, char *tmpPath, int flags, int track_flags, int frame) {
+void handleDigIACT(FILE *input, int size, const char *outputDir, const char *inputFilename,int flags, int track_flags, int frame) {
 	int track = readUint16LE(input);
 	int index = readUint16LE(input);
 	int nbframes = readUint16LE(input);
@@ -636,10 +618,10 @@
 		exit(1);
 	}
 
-	handleAudioTrack(index, trackId, frame, nbframes, input, outputDir, inputFilename, tmpPath, size, volume, pan, true);
+	handleAudioTrack(index, trackId, frame, nbframes, input, outputDir, inputFilename, size, volume, pan, true);
 }
 
-void handlePSAD(FILE *input, int size, char *outputDir, char *inputFilename, char *tmpPath, int frame) {
+void handlePSAD(FILE *input, int size, const char *outputDir, const char *inputFilename, int frame) {
 	int trackId = readUint16LE(input);
 	int index = readUint16LE(input);
 	int nbframes = readUint16LE(input);
@@ -647,78 +629,90 @@
 	int volume = readByte(input);
 	int pan = readByte(input);
 
-	handleAudioTrack(index, trackId, frame, nbframes, input, outputDir, inputFilename, tmpPath, size, volume, pan, false);
+	handleAudioTrack(index, trackId, frame, nbframes, input, outputDir, inputFilename, size, volume, pan, false);
 }
 
+// TODO
+// Feature set seems more limited than what kCompressionAudioHelp contains
+const char *helptext = "\nUsage: %s [mode] [mode-params] <file> <inputdir> <outputdir>\n" kCompressionAudioHelp;
+
 int main(int argc, char *argv[]) {
-	if (argc < 4)
-		showhelp(argv[0]);
+	Filename inpath, outpath;
+	char outdir[768];
+	int first_arg = 1;
+	int last_arg = argc - 1;
 
-	char inputDir[768];
-	char outputDir[768];
-	char inputFilename[256];
-	char tmpPath[768];
+	parseHelpArguments(argv, argc, helptext);
 
-	strcpy(inputFilename, argv[argc - 3]);
-	strcpy(inputDir, argv[argc - 2]);
-	strcpy(outputDir, argv[argc - 1]);
+	// compression mode
+	CompressMode compMode = process_audio_params(argc, argv, &first_arg);
 
-	if (argc > 4) {
-		int result;
-		int i = 1;
+	// TODO
+	// Support flac too?
+	if(compMode == kVorbisMode)
+		_oggMode = true;
+	else if(compMode != kMP3Mode)
+		notice("Only ogg vorbis and MP3 is supported for this tool.");
+	if(compMode == kNoAudioMode) {
+		// Unknown mode (failed to parse arguments), display help and exit
+		printf(helptext, argv[0]);
+		exit(2);
+	}
 
-		if (strcmp(argv[1], "--vorbis") == 0) {
-			_oggMode = true;
-			i++;
-		}
+	uint32 tag;
 
+	// Now we try to find the proper output file
+	// also make sure we skip those arguments
+	if (parseOutputFileArguments(&outpath, argv, argc, first_arg))
+		first_arg += 2;
+	else if (parseOutputFileArguments(&outpath, argv, argc, last_arg - 2))
+		last_arg -= 2;
+	else 
+		// Just leave it empty, we just change extension of input file
+		;
 
-		if (_oggMode)
-			result = process_ogg_parms(argc - 2, argv, i);
-		else
-			result = process_mp3_parms(argc - 2, argv, i);
+	// We need this path for some functions, alot quicker than rewriting
+	// them to use the Filename class
+	outpath.getPath(outdir);
 
-		if (!result)
-			showhelp(argv[0]);
-	}
 
-	char *index = strrchr(inputFilename, '.');
-	if (index != NULL) {
-		*index = 0;
-	}
+	inpath.setFullPath(argv[first_arg]);
 
-	sprintf(tmpPath, "%s/%s.san", inputDir, inputFilename);
-
-	FILE *input = fopen(tmpPath, "rb");
+	FILE *input = fopen(inpath.getFullPath(), "rb");
 	if (!input) {
-		printf("Cannot open file: %s\n", tmpPath);
+		printf("Cannot open file: %s\n", inpath.getFullPath());
 		exit(-1);
 	}
 
-	sprintf(tmpPath, "%s/%s.san", outputDir, inputFilename);
+	if(outpath.empty()) {
+		// Change extension for output
+		outpath = inpath;
+		outpath.setExtension(".san");
+	}
 
-	FILE *output = fopen(tmpPath, "wb");
+	FILE *output = fopen(outpath.getFullPath(), "wb");
 	if (!output) {
-		printf("Cannot open file: %s\n", tmpPath);
+		printf("Cannot open file: %s\n", outpath.getFullPath());
 		exit(-1);
 	}
 
-	sprintf(tmpPath, "%s/%s.flu", inputDir, inputFilename);
+	Filename flupath(inpath);
+	flupath.setExtension(".flu");
 
 	FILE *flu_in = NULL;
 	FILE *flu_out = NULL;
-	flu_in = fopen(tmpPath, "rb");
+	flu_in = fopen(flupath.getFullPath(), "rb");
 
 	if (flu_in) {
-		sprintf(tmpPath, "%s/%s.flu", outputDir, inputFilename);
-		flu_out = fopen(tmpPath, "wb");
+		flupath = outpath;
+		flupath.setExtension(".flu");
+		flu_out = fopen(flupath.getFullPath(), "wb");
 		if (!flu_out) {
-			printf("Cannot open file: %s\n", tmpPath);
+			printf("Cannot open ancillary file: %s\n", flupath.getFullPath());
 			exit(-1);
 		}
 	}
 
-	uint32 tag;
 	int32 l, size;
 
 	writeUint32BE(output, readUint32BE(input)); // ANIM
@@ -802,9 +796,9 @@
 				int unk = readUint16LE(input);
 				int track_flags = readUint16LE(input);
 				if ((code == 8) && (track_flags == 0) && (unk == 0) && (flags == 46)) {
-					handleComiIACT(input, size, outputDir, inputFilename, tmpPath);
+					handleComiIACT(input, size, outdir, inpath.getFullName());
 				} else if ((code == 8) && (track_flags != 0) && (unk == 0) && (flags == 46)) {
-					handleDigIACT(input, size, outputDir, inputFilename, tmpPath, flags, track_flags, l);
+					handleDigIACT(input, size, outdir, inpath.getFullName(), flags, track_flags, l);
 					tracksCompress = true;
 					fps = 12;
 				} else {
@@ -820,7 +814,7 @@
 				continue;
 			} else if ((tag == 'PSAD') && (!flu_in)) {
 				size = readUint32BE(input); // chunk size
-				handlePSAD(input, size, outputDir, inputFilename, tmpPath, l);
+				handlePSAD(input, size, outdir, inpath.getFullName(), l);
 				if ((size & 1) != 0) {
 					fseek(input, 1, SEEK_CUR);
 					size++;
@@ -843,19 +837,20 @@
 	}
 
 	if (tracksCompress) {
-		prepareForMixing(outputDir, inputFilename);
+		prepareForMixing(outdir, inpath.getFullName());
 		assert(fps);
-		mixing(outputDir, inputFilename, nbframes, fps);
+		mixing(outdir, inpath.getFullName(), nbframes, fps);
 	}
 
 	if (_waveTmpFile) {
+		char tmpPath[1024];
 		writeWaveHeader(_waveDataSize);
-		sprintf(tmpPath, "%s/%s", outputDir, inputFilename);
+		sprintf(tmpPath, "%s/%s", outdir, inpath.getFullName());
 		if (_oggMode)
 			encodeWaveWithOgg(tmpPath);
 		else
 			encodeWaveWithLame(tmpPath);
-		sprintf(tmpPath, "%s/%s.wav", outputDir, inputFilename);
+		sprintf(tmpPath, "%s/%s.wav", outdir, inpath.getFullName());
 		unlink(tmpPath);
 	}
 

Modified: tools/branches/gsoc2009-gui/compress_sword2.cpp
===================================================================
--- tools/branches/gsoc2009-gui/compress_sword2.cpp	2009-06-10 21:28:16 UTC (rev 41440)
+++ tools/branches/gsoc2009-gui/compress_sword2.cpp	2009-06-10 23:55:21 UTC (rev 41441)
@@ -29,46 +29,6 @@
 
 static CompressMode gCompMode = kMP3Mode;
 
-void showhelp(char *exename) {
-	printf("\nUsage: %s [params] <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("(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 compression level 0\n");
-	printf(" --best       FLAC uses compression level 8\n");
-	printf(" -<value>     specifies the value (0 - 8) of compression (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);
-}
-
 uint32 append_to_file(FILE *f1, const char *filename) {
 	FILE *f2;
 	uint32 length, orig_length;
@@ -101,6 +61,8 @@
 #define GetCompressedSign(n)       (((n) >> 3) & 1)
 #define GetCompressedAmplitude(n)  ((n) & 7)
 
+const char *helptext = "\nUsage: %s [params] <file>\n\n" kCompressionAudioHelp;
+
 int main(int argc, char *argv[]) {
 	char output_filename[1024];
 	FILE *output, *f;
@@ -109,10 +71,40 @@
 	uint32 indexSize;
 	uint32 totalSize;
 	uint32 length;
+	
+	Filename inpath, outpath;
+	int first_arg = 1;
+	int last_arg = argc - 1;
 
-	if (argc < 2)
-		showhelp(argv[0]);
+	parseHelpArguments(argv, argc, helptext);
 
+	/* compression mode */
+	gCompMode = process_audio_params(argc, argv, &first_arg);
+
+	// Now we try to find the proper output file
+	// also make sure we skip those arguments
+	if (parseOutputFileArguments(&outpath, argv, argc, first_arg))
+		first_arg += 2;
+	else if (parseOutputFileArguments(&outpath, argv, argc, last_arg - 2))
+		last_arg -= 2;
+	else {
+		switch(gCompMode) {
+		case kMP3Mode:
+			g_output_filename = OUTPUT_MP3;
+			break;
+		case kVorbisMode:
+			g_output_filename = OUTPUT_OGG;
+			break;
+		case kFlacMode:
+			g_output_filename = OUTPUT_FLA;
+			break;
+		default:
+			printf(helptext, argv[0]);
+			exit(2);
+			break;
+		}
+	}
+
 	i = 1;
 
 	if (strcmp(argv[1], "--mp3") == 0) {

Modified: tools/branches/gsoc2009-gui/compress_touche.cpp
===================================================================
--- tools/branches/gsoc2009-gui/compress_touche.cpp	2009-06-10 21:28:16 UTC (rev 41440)
+++ tools/branches/gsoc2009-gui/compress_touche.cpp	2009-06-10 23:55:21 UTC (rev 41441)
@@ -32,10 +32,7 @@
 #define OUTPUT_OGG   "TOUCHE.SOG"
 #define OUTPUT_FLA   "TOUCHE.SOF"
 
-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 CompressMode gCompMode = kMP3Mode;
 
 static uint32 input_OBJ_offs[OBJ_HDR_LEN];
 static uint32 input_OBJ_size[OBJ_HDR_LEN];
@@ -69,7 +66,7 @@
 
 			printf("VOC found (pos = %d) :\n", offs_table[i]);
 			fseek(input, 18, SEEK_CUR);
-			extractAndEncodeVOC(TEMP_RAW, input, g_mode);
+			extractAndEncodeVOC(TEMP_RAW, input, gCompMode);
 
 			/* append converted data to output file */
 			temp = fopen(tempEncoded, "rb");
@@ -101,17 +98,15 @@
 	return current_offset;
 }
 
-static void compress_sound_data() {
+static void compress_sound_data(Filename *inpath, Filename *outpath) {
 	int i;
-	char filepath[1024];
 	FILE *output, *input;
 	uint32 current_offset;
 	uint32 offsets_table[MAX_OFFSETS];
 
-	sprintf(filepath, "%s/%s", g_output_directory, g_output_filename);
-	output = fopen(filepath, "wb");
+	output = fopen(outpath->getFullPath(), "wb");
 	if (!output) {
-		error("Cannot open file '%s' for writing", filepath);
+		error("Cannot open file '%s' for writing", outpath->getFullPath());
 	}
 
 	writeUint16LE(output, 1); /* current version */
@@ -127,8 +122,8 @@
 	}
 
 	/* process 'OBJ' file */
-	sprintf(filepath, "%s/OBJ", g_input_directory);
-	input = fopen(filepath, "rb");
+	inpath->setFullName("OBJ");
+	input = fopen(inpath->getFullPath(), "rb");
 	if (!input) {
 		error("Cannot open file 'OBJ' for reading");
 	}
@@ -136,18 +131,21 @@
 	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);
-	printf("Processed '%s'.\n", filepath);
+	printf("Processed '%s'.\n", inpath->getFullPath());
 
 	/* process Vxx files */
 	for (i = 1; i < MAX_OFFSETS; ++i) {
-		sprintf(filepath, "%s/V%d", g_input_directory, i);
 
-		input = fopen(filepath, "rb");
+		char d[16];
+		sprintf(d, "V%d", i);
+		inpath->setFullName(d);
+
+		input = fopen(inpath->getFullPath(), "rb");
 		if (input) {
 			offsets_table[i] = current_offset;
 			current_offset = compress_sound_data_file(current_offset, output, input, input_Vxx_offs, input_Vxx_size, Vxx_HDR_LEN);
 			fclose(input);
-			printf("Processed '%s'.\n", filepath);
+			printf("Processed '%s'.\n", inpath->getFullPath());
 		}
 	}
 
@@ -166,98 +164,58 @@
 	printf("Done.\n");
 }
 
-static void showhelp(const char *exename) {
-	printf("\nUsage: %s [params] <inputdir> <outputdir>\n", exename);
+const char *helptext = "\nUsage: %s [params] [-o outputfile TOUCHE.*] <inputdir>\n* differs with compression type.\n" kCompressionAudioHelp;
 
-	printf("\nParams:\n");
+int main(int argc, char *argv[]) {
+	Filename inpath, outpath;
+	int first_arg = 1;
+	int last_arg = argc - 1;
 
-	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");
+	parseHelpArguments(argv, argc, helptext);
 
-	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");
+	// compression mode
+	gCompMode = process_audio_params(argc, argv, &first_arg);
 
-	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 compression level 0\n");
-	printf(" --best       FLAC uses compression level 8\n");
-	printf(" -<value>     specifies the value (0 - 8) of compression (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);
-}
-
-int main(int argc, char *argv[]) {
-	int i;
-
-	if (argc < 2) {
-		showhelp(argv[0]);
+	if(gCompMode == kNoAudioMode) {
+		// Unknown mode (failed to parse arguments), display help and exit
+		printf(helptext, argv[0]);
+		exit(2);
 	}
 
-	i = 1;
-	if (strcmp(argv[1], "--mp3") == 0) {
-		g_mode = kMP3Mode;
-		g_output_filename = OUTPUT_MP3;
-		++i;
-	} else if (strcmp(argv[1], "--vorbis") == 0) {
-		g_mode = kVorbisMode;
-		g_output_filename = OUTPUT_OGG;
-		++i;
-	} else if (strcmp(argv[1], "--flac") == 0) {
-		g_mode = kFlacMode;
-		g_output_filename = OUTPUT_FLA;
-		++i;
+	// Now we try to find the proper output file
+	// also make sure we skip those arguments
+	if (parseOutputFileArguments(&outpath, argv, argc, first_arg))
+		first_arg += 2;
+	else if (parseOutputFileArguments(&outpath, argv, argc, last_arg - 2))
+		last_arg -= 2;
+	else {
+		switch(gCompMode) {
+		case kMP3Mode:
+			outpath.setFullName(OUTPUT_MP3);
+			break;
+		case kVorbisMode:
+			outpath.setFullName(OUTPUT_OGG);
+			break;
+		case kFlacMode:
+			outpath.setFullName(OUTPUT_FLA);
+			break;
+		default:
+			printf(helptext, argv[0]);
+			exit(2);
+			break;
+		}
 	}
 
-	g_input_directory = argv[argc - 2];
-	g_output_directory = argv[argc - 1];
+	inpath.setFullPath(argv[first_arg]);
 
-	switch (g_mode) {
-	case kMP3Mode:
-		tempEncoded = TEMP_MP3;
-		if (!process_mp3_parms(argc - 1, argv, i)) {
-			showhelp(argv[0]);
-		}
-
-		break;
-	case kVorbisMode:
-		tempEncoded = TEMP_OGG;
-		if (!process_ogg_parms(argc - 1, argv, i)) {
-			showhelp(argv[0]);
-		}
-
-		break;
-	case kFlacMode:
-		tempEncoded = TEMP_FLAC;
-		if (!process_flac_parms(argc - 1, argv, i)) {
-			showhelp(argv[0]);
-		}
-
-		break;
+	// Append '/' if it's not already done
+	// TODO: We need a way to detect a directory here!
+	size_t s = strlen(inpath._path);
+	if(inpath._path[s-1] == '/' || inpath._path[s-1] == '\\') {
+		inpath._path[s] = '/';
+		inpath._path[s+1] = '\0';
 	}
 
-
-
-	compress_sound_data();
+	compress_sound_data(&inpath, &outpath);
 	return 0;
 }

Modified: tools/branches/gsoc2009-gui/dekyra.cpp
===================================================================
--- tools/branches/gsoc2009-gui/dekyra.cpp	2009-06-10 21:28:16 UTC (rev 41440)
+++ tools/branches/gsoc2009-gui/dekyra.cpp	2009-06-10 23:55:21 UTC (rev 41441)
@@ -56,7 +56,7 @@
 		if (*argv[param] != '-' && file == -1)
 			file = param;
 		else {
-			if(argv[param][1] == 't') {
+			if (argv[param][1] == 't') {
 				displayText = true;
 			} else if (argv[param][1] == 'e') {
 				engine = atoi(argv[param+1]);

Modified: tools/branches/gsoc2009-gui/extract_agos.cpp
===================================================================
--- tools/branches/gsoc2009-gui/extract_agos.cpp	2009-06-10 21:28:16 UTC (rev 41440)
+++ tools/branches/gsoc2009-gui/extract_agos.cpp	2009-06-10 23:55:21 UTC (rev 41441)
@@ -195,11 +195,11 @@
 	// Check if we should display some helpful text
 	parseHelpArguments(argv, argc);
 	
-	// Continuing with finding out output directory
+	// Now we try to find the proper output directory
 	// also make sure we skip those arguments
-	if ( parseOutputArguments(&outpath, argv, argc, first_arg))
+	if (parseOutputDirectoryArguments(&outpath, argv, argc, first_arg))
 		first_arg += 2;
-	else if (parseOutputArguments(&outpath, argv, argc, last_arg - 2))
+	else if (parseOutputDirectoryArguments(&outpath, argv, argc, last_arg - 2))
 		last_arg -= 2;
 	else
 		// Standard output dir

Modified: tools/branches/gsoc2009-gui/extract_gob_stk.cpp
===================================================================
--- tools/branches/gsoc2009-gui/extract_gob_stk.cpp	2009-06-10 21:28:16 UTC (rev 41440)
+++ tools/branches/gsoc2009-gui/extract_gob_stk.cpp	2009-06-10 23:55:21 UTC (rev 41441)
@@ -59,9 +59,9 @@
 	
 	// Continuing with finding out output directory
 	// also make sure we skip those arguments
-	if (parseOutputArguments(&outpath, argv, argc, first_arg))
+	if (parseOutputDirectoryArguments(&outpath, argv, argc, first_arg))
 		first_arg += 2;
-	else if (parseOutputArguments(&outpath, argv, argc, last_arg - 2))
+	else if (parseOutputDirectoryArguments(&outpath, argv, argc, last_arg - 2))
 		last_arg -= 2;
 	else
 		// Standard output dir

Modified: tools/branches/gsoc2009-gui/extract_kyra.cpp
===================================================================
--- tools/branches/gsoc2009-gui/extract_kyra.cpp	2009-06-10 21:28:16 UTC (rev 41440)
+++ tools/branches/gsoc2009-gui/extract_kyra.cpp	2009-06-10 23:55:21 UTC (rev 41441)
@@ -25,8 +25,6 @@
 #include "kyra_ins.h"
 
 int main(int argc, char **argv) {
-	char inputPath[768];
-
 	int first_arg = 1;
 	int last_arg = argc - 1;
 
@@ -74,9 +72,9 @@
 	}
 
 	// Parse output argument
-	if (parseOutputArguments(&outpath, argv, argc, param))
+	if (parseOutputDirectoryArguments(&outpath, argv, argc, param))
 		param += 2;
-	else if (parseOutputArguments(&outpath, argv, argc, argc - 2))
+	else if (parseOutputDirectoryArguments(&outpath, argv, argc, argc - 2))
 		last_arg -= 1;
 	else
 		outpath.setFullPath("out/");
@@ -101,7 +99,7 @@
 
 	// Everything has been decided, do the actual extraction
 	if (extractAll) {
-		extract->outputAllFiles(outpath.getFullPath());
+		extract->outputAllFiles(&outpath);
 	} else if (extractOne) {
 		inputpath.setFullName(singleFilename);
 		extract->outputFileAs(singleFilename, inputpath.getFullPath());

Modified: tools/branches/gsoc2009-gui/extract_kyra.h
===================================================================
--- tools/branches/gsoc2009-gui/extract_kyra.h	2009-06-10 21:28:16 UTC (rev 41440)
+++ tools/branches/gsoc2009-gui/extract_kyra.h	2009-06-10 23:55:21 UTC (rev 41441)
@@ -31,7 +31,7 @@
 
 	virtual void drawFileList();
 
-	virtual bool outputAllFiles(const char *outputPath);
+	virtual bool outputAllFiles(Filename *outputPath);
 
 	virtual bool outputFile(const char *file) { return outputFileAs(file, file); }
 	virtual bool outputFileAs(const char *file, const char *outputName);

Modified: tools/branches/gsoc2009-gui/extract_loom_tg16.cpp
===================================================================
--- tools/branches/gsoc2009-gui/extract_loom_tg16.cpp	2009-06-10 21:28:16 UTC (rev 41440)
+++ tools/branches/gsoc2009-gui/extract_loom_tg16.cpp	2009-06-10 23:55:21 UTC (rev 41441)
@@ -1245,9 +1245,9 @@
 	
 	// Continuing with finding out output directory
 	// also make sure we skip those arguments
-	if (parseOutputArguments(&outpath, argv, argc, first_arg))
+	if (parseOutputDirectoryArguments(&outpath, argv, argc, first_arg))
 		first_arg += 2;
-	else if (parseOutputArguments(&outpath, argv, argc, last_arg - 2))
+	else if (parseOutputDirectoryArguments(&outpath, argv, argc, last_arg - 2))
 		last_arg -= 2;
 	else
 		// Standard output dir

Modified: tools/branches/gsoc2009-gui/extract_mm_apple.cpp
===================================================================
--- tools/branches/gsoc2009-gui/extract_mm_apple.cpp	2009-06-10 21:28:16 UTC (rev 41440)
+++ tools/branches/gsoc2009-gui/extract_mm_apple.cpp	2009-06-10 23:55:21 UTC (rev 41441)
@@ -69,9 +69,9 @@
 	
 	// Continuing with finding out output directory
 	// also make sure we skip those arguments
-	if (parseOutputArguments(&outpath, argv, argc, first_arg))
+	if (parseOutputDirectoryArguments(&outpath, argv, argc, first_arg))
 		first_arg += 2;
-	else if (parseOutputArguments(&outpath, argv, argc, last_arg - 2))
+	else if (parseOutputDirectoryArguments(&outpath, argv, argc, last_arg - 2))
 		last_arg -= 2;
 	else
 		// Standard output dir

Modified: tools/branches/gsoc2009-gui/extract_mm_c64.cpp
===================================================================
--- tools/branches/gsoc2009-gui/extract_mm_c64.cpp	2009-06-10 21:28:16 UTC (rev 41440)
+++ tools/branches/gsoc2009-gui/extract_mm_c64.cpp	2009-06-10 23:55:21 UTC (rev 41441)
@@ -70,9 +70,9 @@
 	
 	// Continuing with finding out output directory
 	// also make sure we skip those arguments
-	if (parseOutputArguments(&outpath, argv, argc, first_arg))
+	if (parseOutputDirectoryArguments(&outpath, argv, argc, first_arg))
 		first_arg += 2;
-	else if (parseOutputArguments(&outpath, argv, argc, last_arg - 2))
+	else if (parseOutputDirectoryArguments(&outpath, argv, argc, last_arg - 2))
 		last_arg -= 2;
 	else
 		// Standard output dir

Modified: tools/branches/gsoc2009-gui/extract_mm_nes.cpp
===================================================================
--- tools/branches/gsoc2009-gui/extract_mm_nes.cpp	2009-06-10 21:28:16 UTC (rev 41440)
+++ tools/branches/gsoc2009-gui/extract_mm_nes.cpp	2009-06-10 23:55:21 UTC (rev 41441)
@@ -1184,9 +1184,9 @@
 	
 	// Continuing with finding out output directory
 	// also make sure we skip those arguments
-	if (parseOutputArguments(&outpath, argv, argc, first_arg))
+	if (parseOutputDirectoryArguments(&outpath, argv, argc, first_arg))
 		first_arg += 2;
-	else if (parseOutputArguments(&outpath, argv, argc, last_arg - 2))
+	else if (parseOutputDirectoryArguments(&outpath, argv, argc, last_arg - 2))
 		last_arg -= 2;
 	else
 		// Standard output dir

Modified: tools/branches/gsoc2009-gui/extract_parallaction.cpp
===================================================================
--- tools/branches/gsoc2009-gui/extract_parallaction.cpp	2009-06-10 21:28:16 UTC (rev 41440)
+++ tools/branches/gsoc2009-gui/extract_parallaction.cpp	2009-06-10 23:55:21 UTC (rev 41441)
@@ -329,9 +329,9 @@
 	// Continuing with finding out output directory
 	// also make sure we skip those arguments
 	int arg = 1;
-	if (parseOutputArguments(&outpath, argv, argc, 1))
+	if (parseOutputDirectoryArguments(&outpath, argv, argc, 1))
 		arg += 2;
-	else if (parseOutputArguments(&outpath, argv, argc, argc - 3))
+	else if (parseOutputDirectoryArguments(&outpath, argv, argc, argc - 3))
 		arg -= 2;
 	else
 		// Standard output dir

Modified: tools/branches/gsoc2009-gui/extract_scumm_mac.cpp
===================================================================
--- tools/branches/gsoc2009-gui/extract_scumm_mac.cpp	2009-06-10 21:28:16 UTC (rev 41440)
+++ tools/branches/gsoc2009-gui/extract_scumm_mac.cpp	2009-06-10 23:55:21 UTC (rev 41441)
@@ -49,9 +49,9 @@
 	
 	// Continuing with finding out output directory
 	// also make sure we skip those arguments
-	if (parseOutputArguments(&outpath, argv, argc, first_arg))
+	if (parseOutputDirectoryArguments(&outpath, argv, argc, first_arg))
 		first_arg += 2;
-	else if (parseOutputArguments(&outpath, argv, argc, last_arg - 2))
+	else if (parseOutputDirectoryArguments(&outpath, argv, argc, last_arg - 2))
 		last_arg -= 2;
 	else
 		// Standard output dir

Modified: tools/branches/gsoc2009-gui/extract_zak_c64.cpp
===================================================================
--- tools/branches/gsoc2009-gui/extract_zak_c64.cpp	2009-06-10 21:28:16 UTC (rev 41440)
+++ tools/branches/gsoc2009-gui/extract_zak_c64.cpp	2009-06-10 23:55:21 UTC (rev 41441)
@@ -70,9 +70,9 @@
 	
 	// Continuing with finding out output directory
 	// also make sure we skip those arguments
-	if (parseOutputArguments(&outpath, argv, argc, first_arg))
+	if (parseOutputDirectoryArguments(&outpath, argv, argc, first_arg))
 		first_arg += 2;
-	else if (parseOutputArguments(&outpath, argv, argc, last_arg - 2))
+	else if (parseOutputDirectoryArguments(&outpath, argv, argc, last_arg - 2))
 		last_arg -= 2;
 	else
 		// Standard output dir

Modified: tools/branches/gsoc2009-gui/kyra_pak.cpp
===================================================================
--- tools/branches/gsoc2009-gui/kyra_pak.cpp	2009-06-10 21:28:16 UTC (rev 41440)
+++ tools/branches/gsoc2009-gui/kyra_pak.cpp	2009-06-10 23:55:21 UTC (rev 41441)
@@ -436,14 +436,13 @@
 	}
 }
 
-bool PAKFile::outputAllFiles(const char *outputPath) {
+bool PAKFile::outputAllFiles(Filename *outputPath) {
 	if (!Extractor::outputAllFiles(outputPath))
 		return false;
 
-	char outputFilename[1024];
 	for (const LinkList *entry = _links; entry; entry = entry->next) {
-		sprintf(outputFilename, "%s/%s", outputPath, entry->filename);
-		if (!outputFileAs(entry->linksTo, outputPath))
+		outputPath->setFullName(entry->filename);
+		if (!outputFileAs(entry->linksTo, outputPath->getFullPath()))
 			return false;
 	}
 
@@ -471,15 +470,14 @@
 	}
 }
 
-bool Extractor::outputAllFiles(const char *outputPath) {
+bool Extractor::outputAllFiles(Filename *outputPath) {
 	cFileList *cur = getFileList();
-	char outputFilename[1024];
 
 	while (cur) {
-		sprintf(outputFilename, "%s/%s", outputPath, cur->filename);
-		FILE *file = fopen(outputFilename, "wb");
+		outputPath->setFullName(cur->filename);
+		FILE *file = fopen(outputPath->getFullPath(), "wb");
 		if (!file) {
-			error("couldn't open file '%s' for writing", outputFilename);
+			error("couldn't open file '%s' for writing", outputPath->getFullPath());
 			return false;
 		}
 		printf("Exracting file '%s'...", cur->filename);

Modified: tools/branches/gsoc2009-gui/kyra_pak.h
===================================================================
--- tools/branches/gsoc2009-gui/kyra_pak.h	2009-06-10 21:28:16 UTC (rev 41440)
+++ tools/branches/gsoc2009-gui/kyra_pak.h	2009-06-10 23:55:21 UTC (rev 41441)
@@ -51,7 +51,7 @@
 	cFileList *getFileList() const { return _fileList; }
 
 	void drawFileList();
-	bool outputAllFiles(const char *outputPath);
+	bool outputAllFiles(Filename *outputPath);
 	bool outputFileAs(const char *file, const char *outputName);
 private:
 	FileList *_fileList;

Modified: tools/branches/gsoc2009-gui/util.cpp
===================================================================
--- tools/branches/gsoc2009-gui/util.cpp	2009-06-10 21:28:16 UTC (rev 41440)
+++ tools/branches/gsoc2009-gui/util.cpp	2009-06-10 23:55:21 UTC (rev 41441)
@@ -150,6 +150,15 @@
 	strcpy(_path, path);
 }
 
+Filename::Filename(const Filename& filename) {
+	strcpy(_path, filename._path);
+}
+
+Filename& Filename::operator=(const Filename& filename) {
+	strcpy(_path, filename._path);
+	return *this;
+}
+
 void Filename::setFullPath(const char *path) {
 	strcpy(_path, path);
 }
@@ -168,10 +177,58 @@
 	strcat(_path, ext);
 }
 
+void Filename::setExtension(const char *ext) {
+	char *dot = strrchr(_path, '.');
+	if(!dot)
+		dot = _path + strlen(_path);
+	// Don't copy the dot
+	if(*ext == '.')
+		ext++;
+	strcpy(dot+1, ext);
+}
+
+bool Filename::equals(const Filename *other) const {
+#ifdef _WIN32
+	// On Windows paths are case-insensitive
+	return scumm_stricmp(_path, other->_path) == 0;
+#else
+	return strcmp(_path, other->_path) == 0;
+#endif
+}
+
 bool Filename::empty() const {
 	return *_path == 0;
 }
 
+bool Filename::hasExtension(const char *suffix) const {
+	const char *dot = strrchr(_path, '.');
+	if(!dot)
+		dot = _path + strlen(_path);
+
+	// Check that dot position is less than /, since some
+	// directories contain ., like /home/.data/file
+	const char *slash = strrchr(_path, '/');
+	if(slash && slash > dot)
+		return false;
+
+	slash = strrchr(_path, '\\');
+	if(slash && slash > dot)
+		return false;
+
+	// We compare extensions, skip any dots
+	if(*dot == '.')
+		dot++;
+	if(*suffix == '.')
+		suffix++;
+
+#ifdef _WIN32
+	// On Windows paths are case-insensitive
+	return scumm_stricmp(dot, suffix) == 0;
+#else
+	return strcmp(dot, suffix) == 0;
+#endif
+}
+
 const char *Filename::getFullPath() const {
 	return _path;
 }
@@ -206,31 +263,40 @@
 	return out;
 }
 
+void displayHelp(const char *msg, const char *exename) {
+	if (!msg) {
+		printf("\nUsage: %s [-o <output dir> = out/] <file 1> ... <file n>\n", exename);
+	}
+	else {
+		printf(msg, exename);
+	}
+	exit(2);
+}
+
 void parseHelpArguments(const char * const argv[], int argc, const char *msg) {
 	if (argc < 2 || strcmp(argv[1], "--help") == 0 || stricmp(argv[1], "-h") == 0) {
-		if (!msg) {
-			printf("\nUsage: %s [-o <output dir> = out/] <file 1> ... <file n>\n", argv[0]);
-		}
-		else {
-			printf(msg, argv[0]);
-		}
-		exit(2);
+		displayHelp(msg, argv[0]);
 	}
 }
 
-bool parseOutputArguments(Filename *outputname, const char * const argv[], int argc, int start_arg) {
-	char lastchr;
-
+bool parseOutputArguments(Filename *outputname, bool output_directory, const char * const argv[], int argc, int start_arg) {
 	if (start_arg >= 0 && (strcmp(argv[start_arg], "-o") == 0 || strcmp(argv[start_arg], "--output") == 0)) {
 		/* It's a -o argument, can we check next arg? */
 
 		if (start_arg + 1 < argc) {
 			outputname->setFullPath(argv[start_arg + 1]);
 
-			/* Ensure last character is a /, this way we force directory output */
-			lastchr = outputname->getFullPath()[strlen(outputname->getFullPath()) - 1];
-			if (lastchr != '/' && lastchr != '\\') {
-				strcat(outputname->_path, "/");
+			if (output_directory) {
+				/* Ensure last character is a /, this way we force directory output */
+				char lastchr = outputname->getFullPath()[strlen(outputname->getFullPath()) - 1];
+				if (lastchr != '/' && lastchr != '\\') {
+					strcat(outputname->_path, "/");
+				}
+			} else {
+				char* lastchr = outputname->_path + strlen(outputname->getFullPath()) - 1;
+				if (*lastchr == '/' && *lastchr == '\\') {
+					*lastchr = '\0';
+				}
 			}
 			return true;
 		} else {
@@ -239,3 +305,11 @@
 	}
 	return false;
 }
+
+bool parseOutputFileArguments(Filename *outputname, const char * const argv[], int argc, int start_arg) {
+	return parseOutputArguments(outputname, false, argv, argc, start_arg);
+}
+
+bool parseOutputDirectoryArguments(Filename *outputname, const char * const argv[], int argc, int start_arg) {
+	return parseOutputArguments(outputname, true, argv, argc, start_arg);
+}

Modified: tools/branches/gsoc2009-gui/util.h
===================================================================
--- tools/branches/gsoc2009-gui/util.h	2009-06-10 21:28:16 UTC (rev 41440)
+++ tools/branches/gsoc2009-gui/util.h	2009-06-10 23:55:21 UTC (rev 41441)
@@ -209,12 +209,20 @@
 	char _path[1024];
 
 	Filename(const char *path = "");
+	Filename(const Filename &path);
+	Filename& operator=(const Filename &fn);
 
 	void setFullPath(const char *path);
 	Filename *setFullName(const char *name);
 	void addExtension(const char *ext);
+	void setExtension(const char *ext);
 
+	bool hasExtension(const char *suffix) const;
 	bool empty() const;
+	bool equals(const Filename* other) const;
+	
+	// Doesn't work
+	bool mkdir(int permission = 077);
 
 	const char *getFullPath() const;
 	const char *getFullName() const;
@@ -222,8 +230,14 @@
 	const char *getPath(char *out) const;
 };
 
+inline bool operator==(const Filename &f1, const Filename &f2){
+	return f1.equals(&f2);
+}
+
+void displayHelp(const char *msg = NULL, const char *exename = NULL);
 void parseHelpArguments(const char * const argv[], int argc, const char *msg = NULL);
-bool parseOutputArguments(Filename *outputname, const char * const argv[], int argc, int start_arg);
+bool parseOutputFileArguments(Filename *outputname, const char * const argv[], int argc, int start_arg);
+bool parseOutputDirectoryArguments(Filename *outputname, const char * const argv[], int argc, int start_arg);
 
 
 #endif


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