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

Remere at users.sourceforge.net Remere at users.sourceforge.net
Fri Jun 12 01:49:06 CEST 2009


Revision: 41456
          http://scummvm.svn.sourceforge.net/scummvm/?rev=41456&view=rev
Author:   Remere
Date:     2009-06-11 23:49:06 +0000 (Thu, 11 Jun 2009)

Log Message:
-----------
*Forgot to commit compress_scumm_sou. (drowned among intermediate files)

Modified Paths:
--------------
    tools/branches/gsoc2009-gui/compress_scumm_sou.cpp

Modified: tools/branches/gsoc2009-gui/compress_scumm_sou.cpp
===================================================================
--- tools/branches/gsoc2009-gui/compress_scumm_sou.cpp	2009-06-11 21:42:48 UTC (rev 41455)
+++ tools/branches/gsoc2009-gui/compress_scumm_sou.cpp	2009-06-11 23:49:06 UTC (rev 41456)
@@ -31,7 +31,7 @@
 #define OUTPUT_OGG	"monster.sog"
 #define OUTPUT_FLAC	"monster.sof"
 
-static const char *outputName = OUTPUT_MP3;
+static const char *g_output_filename = OUTPUT_MP3;
 
 #define TEMP_DAT	"tempfile.dat"
 #define TEMP_IDX	"tempfile.idx"
@@ -41,18 +41,16 @@
 static CompressMode gCompMode = kMP3Mode;
 
 
-void end_of_file(char *inputPath) {
+void end_of_file(const 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);
 
-	sprintf(tmp, "%s/%s", inputPath, outputName);
-	output_idx = fopen(tmp , "wb");
+	output_idx = fopen(g_output_filename, "wb");
 	writeUint32BE(output_idx, (uint32)idx_size);
 
 	in = fopen(TEMP_IDX, "rb");
@@ -84,7 +82,7 @@
 	buf[i] = fgetc(input);
 }
 
-void get_part(char *inputPath) {
+void get_part(const char *inputPath) {
 	FILE *f;
 	uint32 tot_size;
 	char outname[256];
@@ -143,96 +141,55 @@
 	writeUint32BE(output_idx, tot_size);
 }
 
-void showhelp(char *exename) {
-	printf("\nUsage: %s [params] monster.sou\n", exename);
+const char *helptext = "\nUsage: %s [mode] [mode params] monster.sou\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[]) {
-	char inputPath[768];
 	char buf[2048];
-	int i;
+	Filename inpath, outpath;
+	int first_arg = 1;
+	int last_arg = argc - 1;
 
-	if (argc < 2) {
-		showhelp(argv[0]);
-	}
+	// Should we help the user?
+	parseHelpArguments(argv, argc, helptext);
 
-	/* Compression mode */
-	gCompMode = kMP3Mode;
-	i = 1;
+	// compression mode
+	gCompMode = process_audio_params(argc, argv, &first_arg);
 
-	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++;
+	if(gCompMode == kNoAudioMode) {
+		// Unknown mode (failed to parse arguments), display help and exit
+		printf(helptext, argv[0]);
+		exit(2);
 	}
 
-	switch (gCompMode) {
-	case kMP3Mode:
-		outputName = OUTPUT_MP3;
-		tempEncoded = TEMP_MP3;
-		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))
-			showhelp(argv[0]);
-		break;
-	case kFlacMode:
-		outputName = OUTPUT_FLAC;
-		tempEncoded = TEMP_FLAC;
-		if (!process_flac_parms(argc, argv, i))
-			showhelp(argv[0]);
-		break;
+	// 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_FLAC;
+			break;
+		default:
+			printf(helptext, argv[0]);
+			exit(2);
+			break;
+		}
 	}
 
-	getPath(argv[argc - 1], inputPath);
+	inpath.setFullPath(argv[first_arg]);
 
-	input = fopen(argv[argc - 1], "rb");
+	input = fopen(inpath.getFullPath(), "rb");
 	if (!input) {
-		printf("Cannot open file: %s\n", argv[i]);
+		printf("Cannot open file: %s\n", inpath.getFullPath());
 		exit(-1);
 	}
 
@@ -255,7 +212,7 @@
 	}
 
 	while (1)
-		get_part(inputPath);
+		get_part(inpath.getFullPath());
 
 	return 0;
 }


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