[Scummvm-cvs-logs] SF.net SVN: scummvm: [28085] tools/branches/gsoc2007-toolsgui

lightcast at users.sourceforge.net lightcast at users.sourceforge.net
Sun Jul 15 05:29:33 CEST 2007


Revision: 28085
          http://scummvm.svn.sourceforge.net/scummvm/?rev=28085&view=rev
Author:   lightcast
Date:     2007-07-14 20:29:33 -0700 (Sat, 14 Jul 2007)

Log Message:
-----------
Compression tools no longer assume that input files are in the current directory.  Full paths can now be specified to the input file and the output file will be written to the same directory, or to the directory specified in the command line arguments depending on the tool.

Modified Paths:
--------------
    tools/branches/gsoc2007-toolsgui/compress.c
    tools/branches/gsoc2007-toolsgui/compress_agos.c
    tools/branches/gsoc2007-toolsgui/compress_kyra.cpp
    tools/branches/gsoc2007-toolsgui/compress_queen.c
    tools/branches/gsoc2007-toolsgui/compress_saga.cpp
    tools/branches/gsoc2007-toolsgui/compress_scumm_bun.cpp
    tools/branches/gsoc2007-toolsgui/compress_scumm_san.cpp
    tools/branches/gsoc2007-toolsgui/compress_scumm_sou.c
    tools/branches/gsoc2007-toolsgui/compress_sword1.c
    tools/branches/gsoc2007-toolsgui/compress_sword2.c
    tools/branches/gsoc2007-toolsgui/compress_touche.c
    tools/branches/gsoc2007-toolsgui/encode_dxa.cpp

Modified: tools/branches/gsoc2007-toolsgui/compress.c
===================================================================
--- tools/branches/gsoc2007-toolsgui/compress.c	2007-07-15 03:25:23 UTC (rev 28084)
+++ tools/branches/gsoc2007-toolsgui/compress.c	2007-07-15 03:29:33 UTC (rev 28085)
@@ -687,9 +687,9 @@
 int process_mp3_parms(int argc, char *argv[], int i) {
 	for (; i < argc; i++) {
 		if (strcmp(argv[i], "--vbr") == 0) {
-			encparms.abr=0;
+			encparms.abr = 0;
 		} else if (strcmp(argv[i], "--abr") == 0) {
-			encparms.abr=1;
+			encparms.abr = 1;
 		} else if (strcmp(argv[i], "-b") == 0) {
 			encparms.minBitr = atoi(argv[i + 1]);
 
@@ -697,7 +697,7 @@
 				encparms.minBitr -= encparms.minBitr % 8;
 			}
 
-			if (encparms.minBitr >160) {
+			if (encparms.minBitr > 160) {
 				encparms.minBitr = 160;
 			}
 

Modified: tools/branches/gsoc2007-toolsgui/compress_agos.c
===================================================================
--- tools/branches/gsoc2007-toolsgui/compress_agos.c	2007-07-15 03:25:23 UTC (rev 28084)
+++ tools/branches/gsoc2007-toolsgui/compress_agos.c	2007-07-15 03:29:33 UTC (rev 28085)
@@ -29,22 +29,23 @@
 
 static CompressMode gCompMode = kMP3Mode;
 
-static char infile_base[256];
-
-static void end(void)
-{
+static void end(char *inputPath, char* inputFile) {
 	int size;
 	char fbuf[2048];
-	char tmp[256];
+	char tmp[1024];
+	char *p;
 	const char *head;
 
 	switch (gCompMode) {
 	case kMP3Mode:
-		head = "mp3"; break;
+		head = "mp3";
+		break;
 	case kVorbisMode:
-		head = "ogg"; break;
+		head = "ogg";
+		break;
 	case kFlacMode:
-		head = "fla"; break;
+		head = "fla";
+		break;
 	default:
 		error("Unknown compression mode");
 	}
@@ -53,18 +54,29 @@
 	fclose(output_idx);
 	fclose(input);
 
-	sprintf(tmp, "%s.%s", infile_base, head);
+	/* Remove the extension from the filename if it exists
+	 * so that we can append the new extension
+	*/
+	p = strrchr(inputFile, '.');
+	if (p) {
+		*p = '\0';
+	}
+
+	sprintf(tmp, "%s/%s.%s", inputPath, inputFile, head);
 	output_idx = fopen(tmp, "wb");
 
 	input = fopen(TEMP_IDX, "rb");
 	while ((size = fread(fbuf, 1, 2048, input)) > 0) {
 		fwrite(fbuf, 1, size, output_idx);
 	}
+
 	fclose(input);
+
 	input = fopen(TEMP_DAT, "rb");
 	while ((size = fread(fbuf, 1, 2048, input)) > 0) {
 		fwrite(fbuf, 1, size, output_idx);
 	}
+
 	fclose(input);
 	fclose(output_idx);
 
@@ -79,8 +91,7 @@
 }
 
 
-static int get_offsets(uint32 filenums[], uint32 offsets[])
-{
+static int get_offsets(uint32 filenums[], uint32 offsets[]) {
 	int i;
 	char buf[8];
 
@@ -95,23 +106,20 @@
 	}
 }
 
-static int get_offsets_mac(uint32 filenums[], uint32 offsets[])
-{
+static int get_offsets_mac(uint32 filenums[], uint32 offsets[]) {
 	int i, size;
-	fseek(input, 0, SEEK_END);
-	size = ftell(input);
-	fseek(input, 0, SEEK_SET);
+	size = fileSize(input);
 
 	for (i = 1; i <= size / 6; i++) {
 		filenums[i] = readUint16BE(input);
 		offsets[i] = readUint32BE(input);
 	}
+
 	return(size/6);
 }
 
 
-static uint32 get_sound(uint32 offset)
-{
+static uint32 get_sound(uint32 offset) {
 	FILE *f;
 	uint32 tot_size;
 	char outname[256];
@@ -146,14 +154,14 @@
 	return(tot_size);
 }
 
-void showhelp(char *exename)
-{
-	printf("\nUsage: %s [params] (<file> | mac)\n", exename);
+void showhelp(char *exename) {
+	printf("\nUsage: %s [params] [--mac] <file>\n", exename);
 
 	printf("\nParams:\n");
 	printf(" --mp3        encode to MP3 format (default)\n");
 	printf(" --vorbis     encode to Vorbis format\n");
 	printf(" --flac       encode to Flac format\n");
+	printf(" --mac        encode simon2mac sounds\n");
 	printf("(If one of these is specified, it must be the first parameter.)\n");
 
 	printf("\nMP3 mode params:\n");
@@ -184,34 +192,23 @@
 
 	printf("\n\nIf a parameter is not given the default value is used\n");
 	printf("If using VBR mode for MP3 -b and -B must be multiples of 8; the maximum is 160!\n");
-	printf("Use the `mac' option instead of a filename if converting simon2mac sounds\n");
+	printf("\nIf converting simon2mac sounds, use the --mac option\n");
+	printf("and replace <file> with the path to the 'voices' folder\n");
+	printf("If the input directory is the same as the current directory use '.'\n");
 	exit(2);
 }
 
 
-static void convert_pc(char *infile)
-{
+static void convert_pc(char *inputPath, char *inputFile) {
 	int i, size, num;
+	char tmp[1024];
 	uint32 filenums[32768];
 	uint32 offsets[32768];
-	char *p;
 
-	p = strrchr(infile, '/');
-	if (!p) {
-		p = strrchr(infile, '\\');
-		if (!p) {
-			p = infile - 1;
-		}
-	}
-	strcpy(infile_base, p + 1);
-	p = strrchr(infile_base, '.');
-	if (p) {
-		*p = '\0';
-	}
-
-	input = fopen(infile, "rb");
+	sprintf(tmp, "%s/%s", inputPath, inputFile);
+	input = fopen(tmp, "rb");
 	if (!input) {
-		printf("Cannot open file: %s\n", infile);
+		printf("Cannot open file: %s\n", tmp);
 		exit(-1);
 	}
 
@@ -228,18 +225,17 @@
 	}
 
 	num = get_offsets(filenums, offsets);
-
 	if (!num) {
 		printf("This does not seem to be a valid file\n");
 		exit(-1);
 	}
-	size = num*4;
+	size = num * 4;
 
 	writeUint32LE(output_idx, 0);
 	writeUint32LE(output_idx, size);
 
 	for (i = 1; i < num; i++) {
-		if (offsets[i] == offsets[i+1]) {
+		if (offsets[i] == offsets[i + 1]) {
 			writeUint32LE(output_idx, size);
 			continue;
 		}
@@ -251,16 +247,14 @@
 	}
 }
 
-static void convert_mac(void)
-{
+static void convert_mac(char *inputPath) {
 	int i, size, num;
-	char tmp[256];
+	char tmp[1024];
 	uint32 filenums[32768];
 	uint32 offsets[32768];
 
-	sprintf(infile_base, "simon2");
-
-	input = fopen("voices.idx", "rb");
+	sprintf(tmp, "%s/voices.idx", inputPath);
+	input = fopen(tmp, "rb");
 	if (!input) {
 		printf("Cannot open file: %s\n", "voices.idx");
 		exit(-1);
@@ -279,26 +273,28 @@
 	}
 
 	num = get_offsets_mac(filenums, offsets);
-
 	if (!num) {
 		printf("This does not seem to be a valid file\n");
 		exit(-1);
 	}
-	size = num*4;
+	size = num * 4;
 
 	writeUint32LE(output_idx, 0);
 	writeUint32LE(output_idx, size);
 
 	for (i = 1; i < num; i++) {
-		if (filenums[i] == filenums[i+1] && offsets[i] == offsets[i+1]) {
+		if (filenums[i] == filenums[i + 1] && offsets[i] == offsets[i + 1]) {
 			writeUint32LE(output_idx, size);
 			continue;
 		}
 
-		if (filenums[i] != filenums[i-1]) {
-			sprintf(tmp, "voices%d.dat", filenums[i]);
-			if (input)
+		if (filenums[i] != filenums[i - 1]) {
+			sprintf(tmp, "%s/voices%d.dat", inputPath, filenums[i]);
+
+			if (input) {
 				fclose(input);
+			}
+
 			input = fopen(tmp, "rb");
 			if (!input) {
 				printf("Cannot open file: %s\n", tmp);
@@ -307,62 +303,104 @@
 		}
 
 		size += get_sound(offsets[i]);
-		if (i < num - 1)
+
+		if (i < num - 1) {
 			writeUint32LE(output_idx, size);
+		}
 	}
 }
 
-int main(int argc, char *argv[])
-{
+int main(int argc, char *argv[]) {
 	int i;
+	char *p;
+	char inputFile[256];
+	char inputPath[768];
+	bool convertMac = false;
 
-	if (argc < 2)
+	if (argc < 2) {
 		showhelp(argv[0]);
+	}
 
 	/* compression mode */
 	gCompMode = kMP3Mode;
 	i = 1;
+
 	if (strcmp(argv[1], "--mp3") == 0) {
 		gCompMode = kMP3Mode;
 		i++;
-	}
-	else if (strcmp(argv[1], "--vorbis") == 0) {
+	} else if (strcmp(argv[1], "--vorbis") == 0) {
 		gCompMode = kVorbisMode;
 		i++;
-	}
-	else if (strcmp(argv[1], "--flac") == 0) {
+	} else if (strcmp(argv[1], "--flac") == 0) {
 		gCompMode = kFlacMode;
 		i++;
 	}
 
+	if (strcmp(argv[2], "--mac") == 0) {
+		convertMac = true;
+		i++;
+	}
+
 	switch (gCompMode) {
 	case kMP3Mode:
 		tempEncoded = TEMP_MP3;
-		if (!process_mp3_parms(argc, argv, i))
+		if (!process_mp3_parms(argc, argv, i)) {
 			showhelp(argv[0]);
+		}
+
 		break;
 	case kVorbisMode:
 		tempEncoded = TEMP_OGG;
-		if (!process_ogg_parms(argc, argv, i))
+		if (!process_ogg_parms(argc, argv, i)) {
 			showhelp(argv[0]);
+		}
+
 		break;
 	case kFlacMode:
 		tempEncoded = TEMP_FLAC;
-		if (!process_flac_parms(argc, argv, i))
+		if (!process_flac_parms(argc, argv, i)) {
 			showhelp(argv[0]);
+		}
+
 		break;
 	}
 
-	i = argc - 1;
+	/* Find the last occurence of '/' or '\'
+	 * Everything before this point is the path
+	 * Everything after this point is the filename
+	 */
+	p = strrchr(argv[argc - 1], '/');
+	if (!p) {
+		p = strrchr(argv[argc - 1], '\\');
 
-	if (strcmp(argv[i], "mac") == 0) {
-		convert_mac();
+		if (!p) {
+			p = argv[argc - 1] - 1;
+		}
+	}
+
+	/* For simon2mac the filename defaults to "simon2" and the path is the whole arguement
+	 * Otherwise, the filename is everything after p and the path is everything before p,
+	 * unless the file is in the current directory, in which case the path is '.'
+	 */
+	if (convertMac) {
+		strcpy(inputFile, "simon2");
+		strcpy(inputPath, argv[argc - 1]);
+	} else if (p < argv[argc - 1]) {
+		strcpy(inputFile, p + 1);
+		strcpy(inputPath, ".");
 	} else {
-		convert_pc(argv[i]);
+		strcpy(inputFile, p + 1);
+		strncpy(inputPath, argv[argc - 1], p - argv[argc - 1]);
 	}
 
-	end();
+	if (convertMac) {
+		convert_mac(inputPath);
+	} else {
+		convert_pc(inputPath, inputFile);
+	}
 
+	end(inputPath, inputFile);
+
 	return(0);
 }
 

Modified: tools/branches/gsoc2007-toolsgui/compress_kyra.cpp
===================================================================
--- tools/branches/gsoc2007-toolsgui/compress_kyra.cpp	2007-07-15 03:25:23 UTC (rev 28084)
+++ tools/branches/gsoc2007-toolsgui/compress_kyra.cpp	2007-07-15 03:29:33 UTC (rev 28085)
@@ -36,11 +36,12 @@
 static CompressMode gCompMode = kMP3Mode;
 
 int main(int argc, char *argv[]) {
-	if (argc < 3)
+	if (argc < 3) {
 		showhelp(argv[0]);
+	}
 
-	char inputFile[256];
-	char outputFile[256];
+	char inputFile[1024];
+	char outputFile[1024];
 	int i = 0;
 
 	/* Compression mode */
@@ -64,34 +65,43 @@
 	case kMP3Mode:
 		outputExt = OUTPUT_MP3;
 		tempEncoded = TEMP_MP3;
-		if (!process_mp3_parms(argc - 2, argv, i))
+		if (!process_mp3_parms(argc - 2, argv, i)) {
 			showhelp(argv[0]);
+		}
+
 		break;
 	case kVorbisMode:
 		outputExt = OUTPUT_OGG;
 		tempEncoded = TEMP_OGG;
-		if (!process_ogg_parms(argc - 2, argv, i))
+		if (!process_ogg_parms(argc - 2, argv, i)) {
 			showhelp(argv[0]);
+		}
+
 		break;
 	case kFlacMode:
 		outputExt = OUTPUT_FLAC;
 		tempEncoded = TEMP_FLAC;
-		if (!process_flac_parms(argc - 2, argv, i))
+		if (!process_flac_parms(argc - 2, argv, i)) {
 			showhelp(argv[0]);
+		}
+
 		break;
 	}
 
 	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)
+	if (scumm_stricmp(inputFile, outputFile) == 0) {
 		error("infile and outfile are the same file");
+	}
+
 	process(inputFile, outputFile);
+
 	return 0;
 }
 
 static void showhelp(const char *exename) {
-	printf("\nUsage: %s [params] <inputfile> <inputdir> <outputdir>\n", exename);
+	printf("\nUsage: %s [params] <file> <inputdir> <outputdir>\n", exename);
 
 	printf("\nParams:\n");
 	printf(" --mp3        encode to MP3 format (default)\n");
@@ -133,26 +143,36 @@
 
 static bool hasSuffix(const char *str, const char *suf) {
 	const int sufSize = strlen(suf);
+
 	int off = strlen(str);
-	if (off < sufSize)
+	if (off < sufSize) {
 		return false;
+	}
+
 	off -= sufSize;
 	printf("'%s'\n", &str[off]);
+
 	return (scumm_stricmp(&str[off], suf) == 0);
 }
 
 static void process(const char *infile, const char *outfile) {
 	PAKFile input, output;
-	if (!input.loadFile(infile, false))
+
+	if (!input.loadFile(infile, false)) {
 		return;
-	if (!output.loadFile(0, false))
+	}
+
+	if (!output.loadFile(0, false)) {
 		return;
+	}
 
 	PAKFile::cFileList *list = input.getFileList();
 	char outputName[32];
+
 	for (; list; list = list->next) {
-		if (!hasSuffix(list->filename, ".VOC"))
+		if (!hasSuffix(list->filename, ".VOC")) {
 			continue;
+		}
 
 		if (list->data[26] != 1) {
 			warning("broken VOC file '%s' skipping it...", list->filename);
@@ -168,8 +188,10 @@
 		fclose(tempFile);
 
 		char *vocStart = strstr(outputName, ".VOC");
-		for (unsigned int i = 0; i < strlen(outputExt); ++i)
+		for (unsigned int i = 0; i < strlen(outputExt); ++i) {
 			vocStart[i] = outputExt[i];
+		}
+
 		output.addFile(outputName, tempEncoded);
 
 		unlink(TEMPFILE);

Modified: tools/branches/gsoc2007-toolsgui/compress_queen.c
===================================================================
--- tools/branches/gsoc2007-toolsgui/compress_queen.c	2007-07-15 03:25:23 UTC (rev 28084)
+++ tools/branches/gsoc2007-toolsgui/compress_queen.c	2007-07-15 03:29:33 UTC (rev 28085)
@@ -118,7 +118,6 @@
 
 const struct GameVersion *version;
 
-
 void showhelp(char *exename)
 {
 	printf("\nUsage: %s [params] queen.1\n", exename);
@@ -164,13 +163,16 @@
 const struct GameVersion *detectGameVersion(uint32 size) {
 	const struct GameVersion *pgv = gameVersions;
 	int i;
+
 	/* Compressing/rebuiling an Amiga version is not supported */
 	for (i = 0; i < VER_PC_COUNT; ++i, ++pgv) {
 		if (pgv->dataFileSize == size) {
 			return pgv;
 		}
  	}
+
 	printf("Unknown/unsupported FOTAQ version!\n");
+
 	exit(1);
 	return NULL;
 }
@@ -185,17 +187,21 @@
 void fromFileToFile(FILE *in, FILE *out, uint32 amount) {
 	char fBuf[2048];
 	uint32 numRead;
+
 	while (amount > 0) {
 		numRead = fread(fBuf, 1, amount > 2048 ? 2048 : amount, in);
-		if (numRead <= 0)
+		if (numRead <= 0) {
 			break;
+		}
+
 		amount -= numRead;
 		fwrite(fBuf, 1, numRead, out);
 	}
 }
 
-void createFinalFile(void) {
+void createFinalFile(char *inputPath) {
 	FILE *inTbl, *inData, *outFinal;
+	char tmp[1024];
 	int i;
 	uint32 dataStartOffset;
 	uint32 dataSize;
@@ -204,7 +210,8 @@
 	checkOpen(inTbl, TEMP_TBL);
 	inData = fopen(TEMP_DAT, "rb");
 	checkOpen(inData, TEMP_DAT);
-	outFinal = fopen(FINAL_OUT, "wb");
+	sprintf(tmp, "%s/%s", inputPath, FINAL_OUT);
+	outFinal = fopen(tmp, "wb");
 	checkOpen(outFinal, FINAL_OUT);
 
 	dataStartOffset = fileSize(inTbl) + EXTRA_TBL_HEADER;
@@ -243,13 +250,16 @@
 {
 	FILE *inputData, *inputTbl, *outputTbl, *outputData, *tmpFile, *compFile;
 	uint8 compressionType = COMPRESSION_NONE;
+	char *p;
+	char inputPath[768];
+	char tblPath[1024];
 	char tmp[5];
 	int size, i = 1;
 	uint32 prevOffset;
 
-
-	if (argc < 2)
+	if (argc < 2) {
 		showhelp(argv[0]);
+	}
 
 	/* compression mode */
 	compressionType = COMPRESSION_MP3;
@@ -272,32 +282,62 @@
 	switch (gCompMode) {
 	case kMP3Mode:
 		tempEncoded = TEMP_MP3;
-		if (!process_mp3_parms(argc, argv, i))
+		if (!process_mp3_parms(argc, argv, i)) {
 			showhelp(argv[0]);
+		}
+
 		break;
 	case kVorbisMode:
 		tempEncoded = TEMP_OGG;
-		if (!process_ogg_parms(argc, argv, i))
+		if (!process_ogg_parms(argc, argv, i)) {
 			showhelp(argv[0]);
+		}
+
 		break;
 	case kFlacMode:
 		tempEncoded = TEMP_FLAC;
-		if (!process_flac_parms(argc, argv, i))
+		if (!process_flac_parms(argc, argv, i)) {
 			showhelp(argv[0]);
+		}
+
 		break;
 	}
 
+	/* Find the last occurence of '/' or '\'
+	 * Everything before this point is the path
+	 * Everything after this point is the filename
+	 */
+	p = strrchr(argv[argc - 1], '/');
+	if (!p) {
+		p = strrchr(argv[argc - 1], '\\');
+
+		if (!p) {
+			p = argv[argc - 1] - 1;
+		}
+	}
+
+	/* The path is everything before p, unless the file is in the current directory,
+	 * in which case the path is '.'
+	 */
+	if (p < argv[argc - 1]) {
+		strcpy(inputPath, ".");
+	} else {
+		strncpy(inputPath, argv[argc - 1], p - argv[argc - 1]);
+	}
+
 	/* Open input file (QUEEN.1) */
 	inputData = fopen(argv[argc-1], "rb");
 	checkOpen(inputData, argv[argc-1]);
 
 	/* Open TBL file (QUEEN.TBL) */
-	inputTbl = fopen(INPUT_TBL, "rb");
+	sprintf(tblPath, "%s/%s", inputPath, INPUT_TBL);
+	inputTbl = fopen(tblPath, "rb");
 	checkOpen(inputTbl, INPUT_TBL);
 
 	size = fileSize(inputData);
 	fread(tmp, 1, 4, inputTbl);
 	tmp[4] = '\0';
+
 	if (memcmp(tmp, "QTBL", 4)) {
 		printf("Invalid TBL file!\n");
 		exit(-1);
@@ -307,6 +347,7 @@
 		printf("Error: You are using an incorrect (outdated?) version of the queen.tbl file\n");
 		exit(1);
 	}
+
 	version = detectGameVersion(size);
 	fseek(inputTbl, version->tableOffset, SEEK_SET);
 
@@ -347,6 +388,7 @@
 
 			fseek(inputData, 2, SEEK_CUR);
 			sbVersion = readUint16LE(inputData);
+
 			switch (sbVersion) {
 			case 104:
 				headerSize = SB_HEADER_SIZE_V104;
@@ -359,6 +401,7 @@
 				headerSize = SB_HEADER_SIZE_V104;
 				break;
 			}
+
 			fseek(inputData, headerSize - 4, SEEK_CUR);
 			entry.size -= headerSize;
 
@@ -382,12 +425,15 @@
 			/* Non .SB file */
 			bool patched = false;
 			/* Check for external files */
+
 			uint8 j;
 			for (j = 0; j < ARRAYSIZE(patchFiles); ++j) {
 				const struct PatchFile *pf = &patchFiles[j];
+
 				if (version->versionString[1] == pf->lang && strcmp(pf->filename, entry.filename) == 0) {
 					/* XXX patched data files are supposed to be in cwd */
 					FILE *fpPatch = fopen(pf->filename, "rb");
+
 					if (fpPatch) {
 						entry.size = fileSize(fpPatch);
 						printf("Patching entry, new size = %d bytes\n", entry.size);
@@ -395,9 +441,11 @@
 						fclose(fpPatch);
 						patched = true;
 					}
+
 					break;
 				}
 			}
+
 			if (!patched) {
 				fromFileToFile(inputData, outputData, entry.size);
 			}
@@ -417,7 +465,7 @@
 	fclose(inputData);
 
 	/* Merge the temporary table and temporary datafile to create final file */
-	createFinalFile();
+	createFinalFile(inputPath);
 
 	return 0;
 }

Modified: tools/branches/gsoc2007-toolsgui/compress_saga.cpp
===================================================================
--- tools/branches/gsoc2007-toolsgui/compress_saga.cpp	2007-07-15 03:25:23 UTC (rev 28084)
+++ tools/branches/gsoc2007-toolsgui/compress_saga.cpp	2007-07-15 03:29:33 UTC (rev 28085)
@@ -243,6 +243,7 @@
 	writeByte(outputFile, sampleBits);
 	writeByte(outputFile, sampleStereo);
 }
+
 uint32 encodeEntry(FILE* inputFile, uint32 inputSize, FILE* outputFile) {
 	uint8 *inputData;
 	Common::File inputFileStream(inputFile);
@@ -311,7 +312,7 @@
 	error("Unsupported resourceType %ul\n", currentFileDescription->resourceType);
 }
 
-void sagaEncode(const char *inputFileName) {
+void sagaEncode(const char *inputPath, const char *inputFileName) {
 	char inputFileNameWithExt[256];
 	char outputFileNameWithExt[256];
 	FILE *inputFile;
@@ -324,7 +325,7 @@
 	Record *inputTable;
 	Record *outputTable;
 
-	sprintf(inputFileNameWithExt, "%s.rsc", inputFileName);
+	sprintf(inputFileNameWithExt, "%s/%s.rsc", inputPath, inputFileName);
 	inputFile = fopen(inputFileNameWithExt, "rb");
 	inputFileSize = fileSize(inputFile);
 	printf("Filesize: %ul\n", inputFileSize);
@@ -356,15 +357,15 @@
 	// Put offsets of all the records in a table
 	for (i = 0; i < resTableCount; i++) {
 
-	if (!currentFileDescription->swapEndian) {
-		inputTable[i].offset = readUint32LE(inputFile);
-		inputTable[i].size = readUint32LE(inputFile);
-	} else {
-		inputTable[i].offset = readUint32BE(inputFile);
-		inputTable[i].size = readUint32BE(inputFile);
-	}
+		if (!currentFileDescription->swapEndian) {
+			inputTable[i].offset = readUint32LE(inputFile);
+			inputTable[i].size = readUint32LE(inputFile);
+		} else {
+			inputTable[i].offset = readUint32BE(inputFile);
+			inputTable[i].size = readUint32BE(inputFile);
+		}
 
-		 printf("Record: %ul, offset: %ul, size: %ul\n", i, inputTable[i].offset, inputTable[i].size);
+		printf("Record: %ul, offset: %ul, size: %ul\n", i, inputTable[i].offset, inputTable[i].size);
 
 		if ((inputTable[i].offset > inputFileSize) ||
 		    (inputTable[i].offset + inputTable[i].size > inputFileSize)) {
@@ -374,7 +375,7 @@
 	}
 	outputTable = (Record*)malloc(resTableCount * sizeof(Record));
 
-	sprintf(outputFileNameWithExt, "%s.cmp", inputFileName);
+	sprintf(outputFileNameWithExt, "%s/%s.cmp", inputPath, inputFileName);
 	outputFile = fopen(outputFileNameWithExt, "wb");
 
 	for (i = 0; i < resTableCount; i++) {
@@ -447,16 +448,20 @@
 }
 
 int main(int argc, char *argv[]) {
-	int		i;
+	int	i;
+	char *p;
+	char inputPath[768];
 	char *inputFileName;
 	char inputFileNameWithExt[256];
 
-	if (argc < 2)
+	if (argc < 2) {
 		showhelp(argv[0]);
+	}
 
 	/* compression mode */
 	gCompMode = kMP3Mode;
 	i = 1;
+
 	if (strcmp(argv[1], "--mp3") == 0) {
 		gCompMode = kMP3Mode;
 		i++;
@@ -467,46 +472,79 @@
 		gCompMode = kFlacMode;
 		i++;
 	}
+
 	switch (gCompMode) {
 	case kMP3Mode:
 		tempEncoded = TEMP_MP3;
-		if (!process_mp3_parms(argc, argv, i))
+		if (!process_mp3_parms(argc, argv, i)) {
 			showhelp(argv[0]);
+		}
+
 		break;
 	case kVorbisMode:
 		tempEncoded = TEMP_OGG;
-		if (!process_ogg_parms(argc, argv, i))
+		if (!process_ogg_parms(argc, argv, i)) {
 			showhelp(argv[0]);
+		}
+
 		break;
 	case kFlacMode:
 		tempEncoded = TEMP_FLAC;
-		if (!process_flac_parms(argc, argv, i))
+		if (!process_flac_parms(argc, argv, i)) {
 			showhelp(argv[0]);
+		}
+
 		break;
 	}
 
-	i = argc - 1;
-	inputFileName = argv[i];
+	/* Find the last occurence of '/' or '\'
+	 * Everything before this point is the path
+	 * Everything after this point is the filename
+	 */
+	p = strrchr(argv[argc - 1], '/');
+	if (!p) {
+		p = strrchr(argv[argc - 1], '\\');
 
+		if (!p) {
+			p = argv[argc - 1] - 1;
+		}
+	}
+
+	/* The path is everything before p, unless the file is in the current directory,
+	 * in which case the path is '.'
+	 */
+	if (p < argv[argc - 1]) {
+		strcpy(inputPath, ".");
+	} else {
+		strncpy(inputPath, argv[argc - 1], p - argv[argc - 1]);
+	}
+
+	strcpy(inputFileName, p + 1);
+
+	if (strrchr(inputFileName, '.') != NULL) {
+		error("Please specifiy the filename without an extension");
+	}
+
 	// ITE
-	sprintf(inputFileNameWithExt, "%s.rsc", inputFileName);
+	sprintf(inputFileNameWithExt, "%s/%s.rsc", inputPath, inputFileName);
+
 	if (detectFile(inputFileNameWithExt)) {
-		sagaEncode(inputFileName);
+		sagaEncode(inputPath, inputFileName);
 	} else {
 		// IHNM
-		sprintf(inputFileNameWithExt, "%s.res", inputFileName);
+		sprintf(inputFileNameWithExt, "%s/%s.res", inputPath, inputFileName);
 		if (detectFile(inputFileNameWithExt)) {
-			sagaEncode(inputFileName);
+			sagaEncode(inputPath, inputFileName);
 		} else {
 			// Check for "inherit the earth voices"
 			if (detectFile("inherit the earth voices")) {
-				sagaEncode("inherit the earth voices");
+				sagaEncode(inputPath, "inherit the earth voices");
 			} else {
 				// Check for MacBinary
-				sprintf(inputFileNameWithExt, "%s.bin", inputFileName);
+				sprintf(inputFileNameWithExt, "%s/%s.bin", inputPath, inputFileName);
 				if (detectFile(inputFileNameWithExt)) {
 					isSigned = false;
-					sagaEncode(inputFileName);
+					sagaEncode(inputPath, inputFileName);
 				}
 			}
 		}

Modified: tools/branches/gsoc2007-toolsgui/compress_scumm_bun.cpp
===================================================================
--- tools/branches/gsoc2007-toolsgui/compress_scumm_bun.cpp	2007-07-15 03:25:23 UTC (rev 28084)
+++ tools/branches/gsoc2007-toolsgui/compress_scumm_bun.cpp	2007-07-15 03:29:33 UTC (rev 28085)
@@ -614,7 +614,7 @@
 }
 
 void showhelp(char *exename) {
-	printf("\nUsage: %s [--vorbis] [params] <inputfile> <inputdir> <outputdir>\n", exename);
+	printf("\nUsage: %s [--vorbis] [params] <file> <inputdir> <outputdir>\n", exename);
 	printf("\nMP3 mode params:\n");
 	printf(" -b <rate>    <rate> is the target bitrate(ABR)/minimal bitrate(VBR) (default:%d)\n", minBitrDef);
 	printf(" -B <rate>    <rate> is the maximum VBR/ABR bitrate (default:%d)\n", maxBitrDef);

Modified: tools/branches/gsoc2007-toolsgui/compress_scumm_san.cpp
===================================================================
--- tools/branches/gsoc2007-toolsgui/compress_scumm_san.cpp	2007-07-15 03:25:23 UTC (rev 28084)
+++ tools/branches/gsoc2007-toolsgui/compress_scumm_san.cpp	2007-07-15 03:29:33 UTC (rev 28085)
@@ -24,7 +24,7 @@
 #include "zlib.h"
 
 void showhelp(char *exename) {
-	printf("\nUsage: %s [--vorbis] [encoder params] <inputfile> <inputdir> <outputdir>\n", exename);
+	printf("\nUsage: %s [--vorbis] [params] <file> <inputdir> <outputdir>\n", exename);
 	printf("\nMP3 mode params:\n");
 	printf(" -b <rate>    <rate> is the target bitrate(ABR)/minimal bitrate(VBR) (default:%d)\n", minBitrDef);
 	printf(" -B <rate>    <rate> is the maximum VBR/ABR bitrate (default:%d)\n", maxBitrDef);

Modified: tools/branches/gsoc2007-toolsgui/compress_scumm_sou.c
===================================================================
--- tools/branches/gsoc2007-toolsgui/compress_scumm_sou.c	2007-07-15 03:25:23 UTC (rev 28084)
+++ tools/branches/gsoc2007-toolsgui/compress_scumm_sou.c	2007-07-15 03:29:33 UTC (rev 28085)
@@ -41,17 +41,19 @@
 static CompressMode gCompMode = kMP3Mode;
 
 
-void end_of_file(void)
+void end_of_file(char *inputPath)
 {
 	FILE *in;
 	int idx_size = ftell(output_idx);
 	size_t size;
+	char tmp[1024];
 	char buf[2048];
 
 	fclose(output_snd);
 	fclose(output_idx);
 
-	output_idx = fopen(outputName , "wb");
+	sprintf(tmp, "%s/%s", inputPath, outputName);
+	output_idx = fopen(tmp , "wb");
 	writeUint32BE(output_idx, (uint32)idx_size);
 
 	in = fopen(TEMP_IDX, "rb");
@@ -84,7 +86,7 @@
 	buf[i] = fgetc(input);
 }
 
-void get_part(void)
+void get_part(char *inputPath)
 {
 	FILE *f;
 	uint32 tot_size;
@@ -102,12 +104,16 @@
 	while (memcmp(buf, "VCTL", 4)&&memcmp(buf, "VTTL", 4)) {
 		pos++;
 		append_byte(4, buf);
-		if (feof(input))
-			end_of_file();
+
+		if (feof(input)) {
+			end_of_file(inputPath);
+		}
 	}
+
 	tags = readUint32BE(input);
-	if (tags < 8)
+	if (tags < 8) {
 		exit(-1);
+	}
 	tags -= 8;
 
 	writeUint32BE(output_idx, (uint32)pos);
@@ -187,22 +193,27 @@
 
 int main(int argc, char *argv[])
 {
+	char *p;
+	char inputPath[768];
+	char tmp[1024];
 	char buf[2048];
 	int i;
-	if (argc < 2)
+
+	if (argc < 2) {
 		showhelp(argv[0]);
+	}
+
 	/* Compression mode */
 	gCompMode = kMP3Mode;
 	i = 1;
+
 	if (strcmp(argv[1], "--mp3") == 0) {
 		gCompMode = kMP3Mode;
 		i++;
-	}
-	else if (strcmp(argv[1], "--vorbis") == 0) {
+	} else if (strcmp(argv[1], "--vorbis") == 0) {
 		gCompMode = kVorbisMode;
 		i++;
-	}
-	else if (strcmp(argv[1], "--flac") == 0) {
+	} else if (strcmp(argv[1], "--flac") == 0) {
 		gCompMode = kFlacMode;
 		i++;
 	}
@@ -211,26 +222,52 @@
 	case kMP3Mode:
 		outputName = OUTPUT_MP3;
 		tempEncoded = TEMP_MP3;
-		if (!process_mp3_parms(argc, argv, i))
+		if (!process_mp3_parms(argc, argv, i)) {
 			showhelp(argv[0]);
+		}
+
 		break;
 	case kVorbisMode:
 		outputName = OUTPUT_OGG;
 		tempEncoded = TEMP_OGG;
-		if (!process_ogg_parms(argc, argv, i))
+		if (!process_ogg_parms(argc, argv, i)) {
 			showhelp(argv[0]);
+		}
+
 		break;
 	case kFlacMode:
 		outputName = OUTPUT_FLAC;
 		tempEncoded = TEMP_FLAC;
-		if (!process_flac_parms(argc, argv, i))
+		if (!process_flac_parms(argc, argv, i)) {
 			showhelp(argv[0]);
+		}
+
 		break;
 	}
 
+	/* Find the last occurence of '/' or '\'
+	 * Everything before this point is the path
+	 * Everything after this point is the filename
+	 */
+	p = strrchr(argv[argc - 1], '/');
+	if (!p) {
+		p = strrchr(argv[argc - 1], '\\');
 
-	i = argc - 1;
-	input = fopen(argv[i], "rb");
+		if (!p) {
+			p = argv[argc - 1] - 1;
+		}
+	}
+
+	/* The path is everything before p, unless the file is in the current directory,
+	 * in which case the path is '.'
+	 */
+	if (p < argv[argc - 1]) {
+		strcpy(inputPath, ".");
+	} else {
+		strncpy(inputPath, argv[argc - 1], p - argv[argc - 1]);
+	}
+
+	input = fopen(argv[argc - 1], "rb");
 	if (!input) {
 		printf("Cannot open file: %s\n", argv[i]);
 		exit(-1);
@@ -253,7 +290,10 @@
 		printf("Bad SOU\n");
 		exit(-1);
 	}
-	while (1)
-		get_part();
+
+	while (1) {
+		get_part(inputPath);
+	}
+
 	return 0;
 }

Modified: tools/branches/gsoc2007-toolsgui/compress_sword1.c
===================================================================
--- tools/branches/gsoc2007-toolsgui/compress_sword1.c	2007-07-15 03:25:23 UTC (rev 28084)
+++ tools/branches/gsoc2007-toolsgui/compress_sword1.c	2007-07-15 03:29:33 UTC (rev 28085)
@@ -28,6 +28,7 @@
 #define TOTAL_TUNES 269
 
 char tempOutName[16];
+char inputDir[256];
 
 typedef struct {
 	char fileName[8];
@@ -308,7 +309,7 @@
 };
 
 void showhelp(char *exename) {
-	printf("\nUsage: %s [params]\n", exename);
+	printf("\nUsage: %s [params] <inputdir>\n", exename);
 
 	printf("\nParams:\n");
 	printf(" --mp3          encode to MP3 format (default)\n");
@@ -349,8 +350,8 @@
 
 	printf("\nIf a parameter is not given the default value is used\n");
 	printf("If using VBR mode for MP3 -b and -B must be multiples of 8; the maximum is 160!\n");
-	printf("\nPlease run this tool from your BS1 main directory.\n");
-	printf("(The one with the subdirectories \"MUSIC\" and \"SPEECH\")\n");
+	printf("\nMake sure the input directory contains the \"MUSIC\" and \"SPEECH\" subdirectories.\n");
+	printf("If the input directory is the same as the current directory use '.'\n");
 	exit(2);
 }
 
@@ -362,8 +363,11 @@
 	uint8 *fBuf = (uint8 *)malloc(cSize);
 	fseek(clu, idx, SEEK_SET);
 	assert(fread(fBuf, 1, cSize, clu) == cSize);
-	while ((READ_BE_UINT32(fBuf + headerPos) != 'data') && (headerPos < 100))
+
+	while ((READ_BE_UINT32(fBuf + headerPos) != 'data') && (headerPos < 100)) {
 		headerPos++;
+	}
+
 	if (headerPos < 100) {
 		resSize = READ_LE_UINT32(fBuf + headerPos + 4) >> 1;
 		srcData = (int16 *)(fBuf + headerPos + 8);
@@ -371,13 +375,18 @@
 		srcPos = 0;
 		dstPos = dstData;
 		cSize = (cSize - (headerPos + 8)) / 2;
+
 		while (srcPos < cSize) {
 			length = (int16)READ_LE_UINT16(srcData + srcPos);
 			srcPos++;
+
 			if (length < 0) {
 				length = -length;
-				for (cnt = 0; cnt < (uint16)length; cnt++)
+
+				for (cnt = 0; cnt < (uint16)length; cnt++) {
 					*dstPos++ = srcData[srcPos];
+				}
+
 				srcPos++;
 			} else {
 				memcpy(dstPos, srcData + srcPos, length * 2);
@@ -385,13 +394,16 @@
 				srcPos += length;
 			}
 		}
+
 		free(fBuf);
 		*returnSize = resSize * 2;
+
 		return dstData;
 	} else {
 		free(fBuf);
 		error("Sound::uncompressSpeech(): DATA tag not found in wave header");
 		*returnSize = 0;
+
 		return NULL;
 	}
 }
@@ -400,10 +412,13 @@
 	FILE *temp;
 	uint8 *resBuf;
 	uint32 size;
+
 	temp = fopen(TEMP_RAW, "wb");
 	assert(fwrite(rawData, 1, rawSize, temp) == rawSize);
 	fclose(temp);
+
 	encodeAudio(TEMP_RAW, true, 11025, tempOutName, compMode);
+
 	temp = fopen(tempOutName, "rb");
 	fseek(temp, 0, SEEK_END);
 	*resSize = size = ftell(temp);
@@ -411,6 +426,7 @@
 	fseek(temp, 0, SEEK_SET);
 	fread(resBuf, 1, size, temp);
 	fclose(temp);
+
 	return resBuf;
 }
 
@@ -427,16 +443,21 @@
 
 	assert(!(headerSize & 3));
 	cowHeader = (uint32*)malloc(headerSize);
-	for (cnt = 0; cnt < (headerSize / 4) - 1; cnt++)
+
+	for (cnt = 0; cnt < (headerSize / 4) - 1; cnt++) {
 		cowHeader[cnt] = readUint32LE(clu);
+	}
+
 	assert(!(cowHeader[0] & 3));
 	numRooms = cowHeader[0] / 4;
 	assert(cowHeader[numRooms] == 0);	/* This dword should be unused. */
+
 	/* The samples are divided into rooms and samples. We don't care about the room indexes at all. */
 	/* We simply copy them and go to the sample-index data. */
 	writeUint32LE(cl3, headerSize);
-	for (cnt = 0; cnt < numRooms; cnt++)
+	for (cnt = 0; cnt < numRooms; cnt++) {
 		writeUint32LE(cl3, cowHeader[cnt]);
+	}
 	writeUint32LE(cl3, cowHeader[numRooms]);
 
 	numSamples = (((headerSize / 4) - numRooms) / 2) - 1;
@@ -456,8 +477,10 @@
 		if (sampleIndex[cnt << 1] | sampleIndex[(cnt << 1) | 1]) {
 			printf("sample %5d: \n", cnt);
 			smpData = (uint8*)uncompressSpeech(clu, sampleIndex[cnt << 1] + headerSize, sampleIndex[(cnt << 1) | 1], &smpSize);
-			if ((!smpData) || (!smpSize))
+
+			if ((!smpData) || (!smpSize)) {
 				error("unable to handle speech sample %d!\n", cnt);
+			}
 
 			mp3Data = convertData(smpData, smpSize, compMode, &mp3Size);
 			cl3Index[cnt << 1] = ftell(cl3);
@@ -471,9 +494,12 @@
 			printf("sample %5d: skipped\n", cnt);
 		}
 	}
+
 	fseek(cl3, (numRooms + 2) * 4, SEEK_SET);	/* Now write the sample index into the CL3 file */
-	for (cnt = 0; cnt < numSamples * 2; cnt++)
+	for (cnt = 0; cnt < numSamples * 2; cnt++) {
 		writeUint32LE(cl3, cl3Index[cnt]);
+	}
+
 	free(cl3Index);
 	free(cowHeader);
 }
@@ -484,22 +510,24 @@
 	char cluName[256], outName[256];
 
 	setRawAudioType(true, false, 16);
+
 	for (i = 1; i <= 2; i++) {
-		sprintf(cluName, "SPEECH/SPEECH%d.CLU", i);
+		sprintf(cluName, "%s/SPEECH/SPEECH%d.CLU", inputDir, i);
 		clu = fopen(cluName, "rb");
+
 		if (!clu) {
 			printf("Unable to open \"SPEECH%d.CLU\".\n", i);
 			printf("Please copy the \"SPEECH.CLU\" from CD %d\nand rename it to \"SPEECH%d.CLU\".\n", i, i);
 		} else {
 			switch (compMode) {
 			case kMP3Mode:
-				sprintf(outName, "SPEECH/SPEECH%d.%s", i, "CL3");
+				sprintf(outName, "%s/SPEECH/SPEECH%d.%s", inputDir, i, "CL3");
 				break;
 			case kVorbisMode:
-				sprintf(outName, "SPEECH/SPEECH%d.%s", i, "CLV");
+				sprintf(outName, "%s/SPEECH/SPEECH%d.%s", inputDir, i, "CLV");
 				break;
 			case kFlacMode:
-				sprintf(outName, "SPEECH/SPEECH%d.%s", i, "CLF");
+				sprintf(outName, "%s/SPEECH/SPEECH%d.%s", inputDir, i, "CLF");
 				break;
 			default:
 				error("Unknown encoding method");
@@ -519,6 +547,7 @@
 		if (cl3)
 			fclose(cl3);
 	}
+
 	unlink(TEMP_RAW);
 	unlink(tempOutName);
 }
@@ -527,9 +556,11 @@
 	int i;
 	FILE *inf;
 	char fNameIn[256], fNameOut[256];
+
 	for (i = 0; i < TOTAL_TUNES; i++) {
-		sprintf(fNameIn, "MUSIC/%s.WAV", musicNames[i].fileName);
+		sprintf(fNameIn, "%s/MUSIC/%s.WAV", inputDir, musicNames[i].fileName);
 		inf = fopen(fNameIn, "rb");
+
 		if (!inf) {
 			if (!musicNames[i].missing) {
 				printf("unable to open file \"%s\"\n", fNameIn);
@@ -539,13 +570,13 @@
 
 			switch (compMode) {
 			case kMP3Mode:
-				sprintf(fNameOut, "MUSIC/%s.%s", musicNames[i].fileName, "MP3");
+				sprintf(fNameOut, "%s/MUSIC/%s.%s", inputDir, musicNames[i].fileName, "MP3");
 				break;
 			case kVorbisMode:
-				sprintf(fNameOut, "MUSIC/%s.%s", musicNames[i].fileName, "OGG");
+				sprintf(fNameOut, "%s/MUSIC/%s.%s", inputDir, musicNames[i].fileName, "OGG");
 				break;
 			case kFlacMode:
-				sprintf(fNameOut, "MUSIC/%s.%s", musicNames[i].fileName, "FLA");
+				sprintf(fNameOut, "%s/MUSIC/%s.%s", inputDir, musicNames[i].fileName, "FLA");
 				break;
 			default:
 				error("Unknown encoding method");
@@ -557,51 +588,23 @@
 	}
 }
 
-void processArgs(int argc, char *argv[], int i, CompressMode compMode) {
-	/* HACK: the functions in compress.c expect the last argument to be a filename. */
-	/*       As we don't expect one, we simply add a dummy argument to the list. */
-	char **args;
-	int cnt;
-	int result;
-	char dummyName[] = "dummy";
-	args = (char **)malloc((argc + 1) * sizeof(char *));
-	for (cnt = 0; cnt < argc; cnt++)
-		args[cnt] = argv[cnt];
-	args[argc] = dummyName;
-
-	switch (compMode) {
-	case kMP3Mode:
-		result = process_mp3_parms(argc + 1, args, i);
-		break;
-	case kVorbisMode:
-		result = process_ogg_parms(argc + 1, args, i);
-		break;
-	case kFlacMode:
-		result = process_flac_parms(argc + 1, args, i);
-		break;
-	default:
-		error("Unknown encoding method");
-	}
-
-	if (!result)
-		showhelp(argv[0]);
-	free(args);
-}
-
 void checkFilesExist(bool checkSpeech, bool checkMusic) {
 	int i;
 	FILE *testFile;
 	char fileName[256];
 	bool speechFound = false, musicFound = false;
+
 	if (checkSpeech) {
 		for (i = 1; i <= 2; i++) {
-			sprintf(fileName, "SPEECH/SPEECH%d.CLU", i);
+			sprintf(fileName, "%s/SPEECH/SPEECH%d.CLU", inputDir, i);
 			testFile = fopen(fileName, "rb");
+
 			if (testFile){
 				speechFound = true;
 				fclose(testFile);
 			}
 		}
+
 		if (!speechFound) {
 			printf("Unable to find speech files.\n");
 			printf("Please copy the SPEECH.CLU files from Broken Sword CD1 and CD2\n");
@@ -611,15 +614,18 @@
 			printf("and directorynames are all upper-case.\n\n");
 		}
 	}
+
 	if (checkMusic) {
 		for (i = 0; i < 20; i++) { /* Check the first 20 music files */
-			sprintf(fileName, "MUSIC/%s.WAV", musicNames[i].fileName);
+			sprintf(fileName, "%s/MUSIC/%s.WAV", inputDir, musicNames[i].fileName);
 			testFile = fopen(fileName, "rb");
+
 			if (testFile) {
 				musicFound = true;
 				fclose(testFile);
 			}
 		}
+
 		if (!musicFound) {
 			printf("Unable to find music files.\n");
 			printf("Please copy the music files from Broken Sword CD1 and CD2\n");
@@ -628,6 +634,7 @@
 			printf("and directorynames are all upper-case.\n");
 		}
 	}
+
 	if ((checkSpeech && (!speechFound)) || (checkMusic && (!musicFound))) {
 		printf("\nUse --help for more information\n");
 		exit(2);
@@ -658,26 +665,41 @@
 	switch (compMode) {
 	case kMP3Mode:
 		strcpy(tempOutName, TEMP_MP3);
+		if (!process_mp3_parms(argc, argv, i)) {
+			showhelp(argv[0]);
+		}
+
 		break;
 	case kVorbisMode:
 		strcpy(tempOutName, TEMP_OGG);
+		if (!process_ogg_parms(argc, argv, i)) {
+			showhelp(argv[0]);
+		}
+
 		break;
 	case kFlacMode:
 		strcpy(tempOutName, TEMP_FLAC);
+		if (!process_flac_parms(argc, argv, i)){
+			showhelp(argv[0]);
+		}
+
 		break;
 	default:
 		error("Unknown encoding method");
 	}
 
-	processArgs(argc, argv, i, compMode);
+	sprintf(inputDir, argv[argc - 1]);
 
 	/* Do a quick check to see if we can open any files at all */
 	checkFilesExist(compSpeech, compMusic);
 
-	if (compSpeech)
+	if (compSpeech) {
 		compressSpeech(compMode);
-	if (compMusic)
+	}
+
+	if (compMusic) {
 		compressMusic(compMode);
+	}
 
 	return EXIT_SUCCESS;
 }

Modified: tools/branches/gsoc2007-toolsgui/compress_sword2.c
===================================================================
--- tools/branches/gsoc2007-toolsgui/compress_sword2.c	2007-07-15 03:25:23 UTC (rev 28084)
+++ tools/branches/gsoc2007-toolsgui/compress_sword2.c	2007-07-15 03:29:33 UTC (rev 28085)
@@ -86,8 +86,10 @@
 
 	while (length > 0) {
 		size = fread(fbuf, 1, length > sizeof(fbuf) ? sizeof(fbuf) : length, f2);
-		if (size <= 0)
+		if (size <= 0) {
 			break;
+		}
+
 		length -= size;
 		fwrite(fbuf, 1, size, f1);
 	}
@@ -101,7 +103,7 @@
 #define GetCompressedAmplitude(n)  ((n) & 7)
 
 int main(int argc, char *argv[]) {
-	char output_filename[40];
+	char output_filename[1024];
 	FILE *output, *f;
 	char *ptr;
 	int i, j;
@@ -109,9 +111,12 @@
 	uint32 totalSize;
 	uint32 length;
 
-	if (argc < 2)
+	if (argc < 2) {
 		showhelp(argv[0]);
+	}
+
 	i = 1;
+
 	if (strcmp(argv[1], "--mp3") == 0) {
 		gCompMode = kMP3Mode;
 		i++;
@@ -127,18 +132,24 @@
 	switch (gCompMode) {
 	case kMP3Mode:
 		tempEncoded = TEMP_MP3;
-		if (!process_mp3_parms(argc, argv, i))
+		if (!process_mp3_parms(argc, argv, i)) {
 			showhelp(argv[0]);
+		}
+
 		break;
 	case kVorbisMode:
 		tempEncoded = TEMP_OGG;
-		if (!process_ogg_parms(argc, argv, i))
+		if (!process_ogg_parms(argc, argv, i)) {
 			showhelp(argv[0]);
+		}
+
 		break;
 	case kFlacMode:
 		tempEncoded = TEMP_FLAC;
-		if (!process_flac_parms(argc, argv, i))
+		if (!process_flac_parms(argc, argv, i)) {
 			showhelp(argv[0]);
+		}
+
 		break;
 	}
 
@@ -174,33 +185,6 @@
 	writeUint32BE(output_idx, 0xfff0fff0);
 	writeUint32BE(output_idx, 0xfff0fff0);
 
-	for (j = strlen(argv[i]) - 1; j >= 0; j--) {
-		if (argv[i][j] == '/' || argv[i][j] == '\\' || argv[i][j] == ':') {
-			j++;
-			break;
-		}
-	}
-
-	if (j < 0)
-		j = 0;
-
-	strncpy(output_filename, argv[i] + j, sizeof(output_filename) - 1);
-	output_filename[sizeof(output_filename) - 1] = 0;
-
-	ptr = output_filename + strlen(output_filename) - 1;
-
-	switch (gCompMode) {
-	case kMP3Mode:
-		*ptr = '3';
-		break;
-	case kVorbisMode:
-		*ptr = 'g';
-		break;
-	case kFlacMode:
-		*ptr = 'f';
-		break;
-	}
-
 	for (i = 0; i < indexSize; i++) {
 		uint32 pos;
 		uint32 enc_length;
@@ -289,6 +273,22 @@
 	fclose(output_idx);
 	fclose(output_snd);
 
+	strcpy(output_filename, argv[argc - 1]);
+	ptr = output_filename + strlen(output_filename) - 1;
+
+	switch (gCompMode) {
+	case kMP3Mode:
+		*ptr = '3';
+		break;
+	case kVorbisMode:
+		*ptr = 'g';
+		break;
+	case kFlacMode:
+		*ptr = 'f';
+		break;
+	}
+
+
 	output = fopen(output_filename, "wb");
 	if (!output) {
 		printf("Can't open file %s for writing!\n", output_filename);

Modified: tools/branches/gsoc2007-toolsgui/compress_touche.c
===================================================================
--- tools/branches/gsoc2007-toolsgui/compress_touche.c	2007-07-15 03:25:23 UTC (rev 28084)
+++ tools/branches/gsoc2007-toolsgui/compress_touche.c	2007-07-15 03:29:33 UTC (rev 28085)
@@ -34,6 +34,7 @@
 
 static CompressMode g_mode = kMP3Mode;
 static const char *g_output_filename = OUTPUT_MP3;
+static const char *g_output_directory = NULL;
 static const char *g_input_directory = NULL;
 
 static uint32 input_OBJ_offs[OBJ_HDR_LEN];
@@ -61,9 +62,11 @@
 		} else {
 			fseek(input, offs_table[i], SEEK_SET);
 			fread(buf, 1, 8, input);
+
 			if (memcmp(buf, "Creative", 8) != 0) {
 				error("Invalid VOC data found");
 			}
+
 			printf("VOC found (pos = %d) :\n", offs_table[i]);
 			fseek(input, 18, SEEK_CUR);
 			extractAndEncodeVOC(TEMP_RAW, input, g_mode);
@@ -73,11 +76,14 @@
 			if (!temp) {
 				error("Cannot open file '%s' for reading", tempEncoded);
 			}
+
 			size_table[i] = 0;
+
 			while ((size = fread(buf, 1, 2048, temp)) > 0) {
 				fwrite(buf, 1, size, output);
 				size_table[i] += size;
 			}
+
 			fclose(temp);
 			offs_table[i] = current_offset;
 			current_offset += size_table[i];
@@ -97,14 +103,15 @@
 
 static void compress_sound_data() {
 	int i;
-	char filepath[512];
+	char filepath[1024];
 	FILE *output, *input;
 	uint32 current_offset;
 	uint32 offsets_table[MAX_OFFSETS];
 
-	output = fopen(g_output_filename, "wb");
+	sprintf(filepath, "%s/%s", g_output_directory, g_output_filename);
+	output = fopen(filepath, "wb");
 	if (!output) {
-		error("Cannot open file '%s' for writing", g_output_filename);
+		error("Cannot open file '%s' for writing", filepath);
 	}
 
 	writeUint16LE(output, 1); /* current version */
@@ -125,6 +132,7 @@
 	if (!input) {
 		error("Cannot open file 'OBJ' for reading");
 	}
+
 	offsets_table[0] = current_offset;
 	current_offset = compress_sound_data_file(current_offset, output, input, input_OBJ_offs, input_OBJ_size, OBJ_HDR_LEN);
 	fclose(input);
@@ -133,6 +141,7 @@
 	/* process Vxx files */
 	for (i = 1; i < MAX_OFFSETS; ++i) {
 		sprintf(filepath, "%s/V%d", g_input_directory, i);
+
 		input = fopen(filepath, "rb");
 		if (input) {
 			offsets_table[i] = current_offset;
@@ -158,7 +167,7 @@
 }
 
 static void showhelp(const char *exename) {
-	printf("\nUsage: %s [params] <inputdir>\n", exename);
+	printf("\nUsage: %s [params] <inputdir> <outputdir>\n", exename);
 
 	printf("\nParams:\n");
 
@@ -220,29 +229,35 @@
 		++i;
 	}
 
-	g_input_directory = argv[argc - 1];
+	g_input_directory = argv[argc - 2];
+	g_output_directory = argv[argc - 1];
 
 	switch (g_mode) {
 	case kMP3Mode:
 		tempEncoded = TEMP_MP3;
-		if (!process_mp3_parms(argc, argv, i)) {
+		if (!process_mp3_parms(argc - 1, argv, i)) {
 			showhelp(argv[0]);
 		}
+
 		break;
 	case kVorbisMode:
 		tempEncoded = TEMP_OGG;
-		if (!process_ogg_parms(argc, argv, i)) {
+		if (!process_ogg_parms(argc - 1, argv, i)) {
 			showhelp(argv[0]);
 		}
+
 		break;
 	case kFlacMode:
 		tempEncoded = TEMP_FLAC;
-		if (!process_flac_parms(argc, argv, i)) {
+		if (!process_flac_parms(argc - 1, argv, i)) {
 			showhelp(argv[0]);
 		}
+
 		break;
 	}
 
+
+
 	compress_sound_data();
 	return 0;
 }

Modified: tools/branches/gsoc2007-toolsgui/encode_dxa.cpp
===================================================================
--- tools/branches/gsoc2007-toolsgui/encode_dxa.cpp	2007-07-15 03:25:23 UTC (rev 28084)
+++ tools/branches/gsoc2007-toolsgui/encode_dxa.cpp	2007-07-15 03:29:33 UTC (rev 28085)
@@ -699,7 +699,7 @@
 }
 
 void showhelp(char *exename) {
-	printf("\nUsage: %s <params> <file>\n", exename);
+	printf("\nUsage: %s [params] <file>\n", exename);
 
 	printf("\nParams:\n");
 	printf(" --mp3        encode to MP3 format (default)\n");


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