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

lightcast at users.sourceforge.net lightcast at users.sourceforge.net
Fri Aug 3 05:39:24 CEST 2007


Revision: 28426
          http://scummvm.svn.sourceforge.net/scummvm/?rev=28426&view=rev
Author:   lightcast
Date:     2007-08-02 20:39:23 -0700 (Thu, 02 Aug 2007)

Log Message:
-----------
Extraction 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/extract_agos.c
    tools/branches/gsoc2007-toolsgui/extract_kyra.cpp
    tools/branches/gsoc2007-toolsgui/extract_loom_tg16.c
    tools/branches/gsoc2007-toolsgui/extract_mm_apple.c
    tools/branches/gsoc2007-toolsgui/extract_mm_c64.c
    tools/branches/gsoc2007-toolsgui/extract_mm_nes.c
    tools/branches/gsoc2007-toolsgui/extract_parallaction.cpp
    tools/branches/gsoc2007-toolsgui/extract_scumm_mac.c
    tools/branches/gsoc2007-toolsgui/extract_zak_c64.c
    tools/branches/gsoc2007-toolsgui/kyra_pak.cpp
    tools/branches/gsoc2007-toolsgui/kyra_pak.h

Modified: tools/branches/gsoc2007-toolsgui/extract_agos.c
===================================================================
--- tools/branches/gsoc2007-toolsgui/extract_agos.c	2007-08-03 03:30:50 UTC (rev 28425)
+++ tools/branches/gsoc2007-toolsgui/extract_agos.c	2007-08-03 03:39:23 UTC (rev 28426)
@@ -185,16 +185,19 @@
 	return 1;
 }
 
-char filename[256];
+char filename[1024];
 
 int main(int argc, char *argv[]) {
+	int i;
+
 	if (argc < 2) {
 		printf("\nUsage: %s <file 1> ... <file n>\n", argv[0]);
 		exit(2);
 	}
 
-	for (argv++; *argv; argv++) {
-		UBYTE *x = (UBYTE *) loadfile(*argv);
+	for (i = 1; i < argc; i++) {
+		UBYTE *x = (UBYTE *) loadfile(argv[i]);
+		strcpy(filename, argv[i]);
 
 		if (x) {
 			ULONG decrlen = simon_decr_length(x, (ULONG) filelen);
@@ -202,7 +205,6 @@
 
 			if (out) {
 				if (simon_decr(x, out, filelen)) {
-					strcpy(filename, *argv);
 					strcat(filename, ".out");
 					savefile(filename, out, decrlen);
 				}

Modified: tools/branches/gsoc2007-toolsgui/extract_kyra.cpp
===================================================================
--- tools/branches/gsoc2007-toolsgui/extract_kyra.cpp	2007-08-03 03:30:50 UTC (rev 28425)
+++ tools/branches/gsoc2007-toolsgui/extract_kyra.cpp	2007-08-03 03:39:23 UTC (rev 28426)
@@ -36,6 +36,9 @@
 }
 
 int main(int argc, char **argv) {
+	char *p;
+	char inputPath[768];
+
 	if (argc < 2) {
 		showhelp(argv[0]);
 	}
@@ -73,10 +76,34 @@
 		error("Couldn't load file '%s'", argv[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 (!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]);
+	}
+
 	if(extractAll) {
-		myfile.outputAllFiles();
+		myfile.outputAllFiles(inputPath);
 	} else if(extractOne) {
-		myfile.outputFile(singleFilename);
+		char outputFilename[1024];
+		sprintf(outputFilename, "%s/%s", inputPath, singleFilename);
+		myfile.outputFileAs(singleFilename, outputFilename);
 	} else {
 		myfile.drawFileList();
 	}

Modified: tools/branches/gsoc2007-toolsgui/extract_loom_tg16.c
===================================================================
--- tools/branches/gsoc2007-toolsgui/extract_loom_tg16.c	2007-08-03 03:30:50 UTC (rev 28425)
+++ tools/branches/gsoc2007-toolsgui/extract_loom_tg16.c	2007-08-03 03:39:23 UTC (rev 28426)
@@ -1333,8 +1333,10 @@
 int main (int argc, char **argv) {
 #ifdef MAKE_LFLS
 	FILE *input, *output;
-	char fname[256];
+	char fname[1024];
 	int i, j;
+	char *p;
+	char inputPath[768];
 #else
 	FILE *input;
 	int i;
@@ -1342,10 +1344,32 @@
 	uint32 CRC;
 
 	if (argc < 2) {
-		printf("nUsage: %s <code_##.ISO>\n", argv[0]);
+		printf("Usage: %s <code_##.ISO>\n", argv[0]);
 		return 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 (!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]);
+	}
+
 	if (!(input = fopen(argv[1], "rb"))) {
 		error("Error: unable to open file %s for input!", argv[1]);
 	}
@@ -1368,8 +1392,8 @@
 
 	for (i = 0; lfls[i].num != -1; i++) {
 		p_lfl lfl = &lfls[i];
-		sprintf(fname, "%02i.LFL", lfl->num);
 
+		sprintf(fname, "%s/%02i.LFL", inputPath, lfl->num);
 		if (!(output = fopen(fname, "wb"))) {
 			error("Error: unable to create %s!", fname);
 		}
@@ -1406,11 +1430,12 @@
 		fclose(output);
 	}
 
-	if (!(output = fopen("00.LFL", "wb"))) {
+	sprintf(fname, "%s/00.LFL", inputPath);
+	if (!(output = fopen(fname, "wb"))) {
 		error("Error: unable to create index file!");
 	}
 
-	notice("Creating 00.LFL...");
+	notice("Creating %s...", fname);
 
 	lfl_index.num_rooms = NUM_ROOMS;
 	lfl_index.num_costumes = NUM_COSTUMES;
@@ -1459,27 +1484,30 @@
 
 	fclose(output);
 
-	if (!(output = fopen("97.LFL", "wb"))) {
+	sprintf(fname, "%s/97.LFL", inputPath);
+	if (!(output = fopen(fname, "wb"))) {
 		error("Error: unable to create charset file!");
 	}
 
-	notice("Creating 97.LFL...");
+	notice("Creating %s...", fname);
 	extract_resource(input, output, &res_charset);
 	fclose(output);
 
-	if (!(output = fopen("98.LFL", "wb"))) {
+	sprintf(fname, "%s/98.LFL", inputPath);
+	if (!(output = fopen(fname, "wb"))) {
 		error("Error: unable to create charset file!");
 	}
 
-	notice("Creating 98.LFL...");
+	notice("Creating %s...", fname);
 	extract_resource(input, output, &res_charset);
 	fclose(output);
 
-	if (!(output = fopen("99.LFL", "wb"))) {
+	sprintf(fname, "%s/99.LFL", inputPath);
+	if (!(output = fopen(fname, "wb"))) {
 		error("Error: unable to create charset file!");
 	}
 
-	notice("Creating 99.LFL...");
+	notice("Creating %s...", fname);
 	extract_resource(input, output, &res_charset);
 	fclose(output);
 

Modified: tools/branches/gsoc2007-toolsgui/extract_mm_apple.c
===================================================================
--- tools/branches/gsoc2007-toolsgui/extract_mm_apple.c	2007-08-03 03:30:50 UTC (rev 28425)
+++ tools/branches/gsoc2007-toolsgui/extract_mm_apple.c	2007-08-03 03:39:23 UTC (rev 28426)
@@ -57,7 +57,9 @@
 
 int main (int argc, char **argv) {
 	FILE *input1, *input2, *output;
-	char fname[256];
+	char fname[1024];
+	char *p;
+	char inputPath[768];
 	int i, j;
 	unsigned short signature;
 
@@ -66,6 +68,28 @@
 		exit(2);
 	}
 
+	/* 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]);
+	}
+
 	if (!(input1 = fopen(argv[1], "rb"))) {
 		error("Error: unable to open file %s for input!", argv[1]);
 	}
@@ -90,7 +114,8 @@
 		error("Signature not found in disk 2!");
 	}
 
-	if (!(output = fopen("00.LFL", "wb"))) {
+	sprintf(fname, "%s/00.LFL", inputPath);
+	if (!(output = fopen(fname, "wb"))) {
 		error("Unable to create index file!");
 	}
 
@@ -175,7 +200,7 @@
 			continue;
 		}
 
-		sprintf(fname, "%02i.LFL", i);
+		sprintf(fname, "%s/%02i.LFL", inputPath, i);
 		output = fopen(fname, "wb");
 
 		if (output == NULL) {

Modified: tools/branches/gsoc2007-toolsgui/extract_mm_c64.c
===================================================================
--- tools/branches/gsoc2007-toolsgui/extract_mm_c64.c	2007-08-03 03:30:50 UTC (rev 28425)
+++ tools/branches/gsoc2007-toolsgui/extract_mm_c64.c	2007-08-03 03:39:23 UTC (rev 28426)
@@ -57,15 +57,39 @@
 
 int main (int argc, char **argv) {
 	FILE *input1, *input2, *output;
-	char fname[256];
+	char fname[1024];
+	char *p;
+	char inputPath[768];
 	int i, j;
 	unsigned short signature;
 
 	if (argc < 3) {
 		printf("Syntax: %s <disk1.d64> <disk2.d64>\n", argv[0]);
-		return 1;
+		exit(2);
 	}
 
+	/* 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]);
+	}
+
 	if (!(input1 = fopen(argv[1], "rb"))) {
 		error("Error: unable to open file %s for input!", argv[1]);
 	}
@@ -87,7 +111,8 @@
 		error("Signature not found in disk 2!");
 	}
 
-	if (!(output = fopen("00.LFL", "wb"))) {
+	sprintf(fname, "%s/00.LFL", inputPath);
+	if (!(output = fopen(fname, "wb"))) {
 		error("Unable to create index file!");
 	}
 
@@ -171,7 +196,7 @@
 			continue;
 		}
 
-		sprintf(fname, "%02i.LFL", i);
+		sprintf(fname, "%s/%02i.LFL", inputPath, i);
 		output = fopen(fname, "wb");
 
 		if (output == NULL) {

Modified: tools/branches/gsoc2007-toolsgui/extract_mm_nes.c
===================================================================
--- tools/branches/gsoc2007-toolsgui/extract_mm_nes.c	2007-08-03 03:30:50 UTC (rev 28425)
+++ tools/branches/gsoc2007-toolsgui/extract_mm_nes.c	2007-08-03 03:39:23 UTC (rev 28426)
@@ -1084,7 +1084,9 @@
 
 int main (int argc, char **argv) {
 	FILE *input, *output;
-	char fname[256];
+	char fname[1024];
+	char *p;
+	char inputPath[768];
 	int i, j;
 	uint32 CRC;
 
@@ -1092,9 +1094,31 @@
 		printf("Usage: %s <file.PRG>\n", argv[0]);
 		printf("\tSupported versions: Europe, France, Germany, Sweden and USA\n");
 		printf("\tJapanese version is NOT supported!\n");
-		return 1;
+		exit(2);
 	}
 
+	/* 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]);
+	}
+
 	if (!(input = fopen(argv[1], "rb"))) {
 		error("Error: unable to open file %s for input!", argv[1]);
 	}
@@ -1143,8 +1167,8 @@
 
 	for (i = 0; lfls[i].num != -1; i++) {
 		p_lfl lfl = &lfls[i];
-		sprintf(fname, "%02i.LFL", lfl->num);
 
+		sprintf(fname, "%s/%02i.LFL", inputPath, lfl->num);
 		if (!(output = fopen(fname, "wb"))) {
 			error("Error: unable to create %s!", fname);
 		}
@@ -1219,11 +1243,12 @@
 		fclose(output);
 	}
 
-	if (!(output = fopen("00.LFL", "wb"))) {
+	sprintf(fname, "%s/00.LFL", inputPath);
+	if (!(output = fopen(fname, "wb"))) {
 		error("Error: unable to create index file!");
 	}
 
-	notice("Creating 00.LFL...");
+	notice("Creating %s...", fname);
 	writeUint16LE(output, 0x4643);
 	extract_resource(input, output, &res_globdata[ROMset][0]);
 

Modified: tools/branches/gsoc2007-toolsgui/extract_parallaction.cpp
===================================================================
--- tools/branches/gsoc2007-toolsgui/extract_parallaction.cpp	2007-08-03 03:30:50 UTC (rev 28425)
+++ tools/branches/gsoc2007-toolsgui/extract_parallaction.cpp	2007-08-03 03:39:23 UTC (rev 28426)
@@ -363,11 +363,11 @@
 int main(int argc, char *argv[]) {
 
 	if (argc < 3) {
-		printf("Usage: %s [small] <file> <outputdir>", argv[0]);
+		printf("Usage: %s [--small] <file> <outputdir>", argv[0]);
 		exit(1);
 	}
 
-	if (!strcmp(argv[1], "small")) {
+	if (!strcmp(argv[1], "--small")) {
 		optDump(argv[2], argv[3], true);
 	} else {
 		optDump(argv[1], argv[2], false);

Modified: tools/branches/gsoc2007-toolsgui/extract_scumm_mac.c
===================================================================
--- tools/branches/gsoc2007-toolsgui/extract_scumm_mac.c	2007-08-03 03:30:50 UTC (rev 28425)
+++ tools/branches/gsoc2007-toolsgui/extract_scumm_mac.c	2007-08-03 03:39:23 UTC (rev 28426)
@@ -31,7 +31,9 @@
 	unsigned long file_record_off, file_record_len;
 	unsigned long file_off, file_len;
 	unsigned long data_file_len;
-	const char *data_file_name;
+	char fname[1024];
+	char* p;
+	char inputPath[768];
 	char file_name[0x20];
 	char *buf;
 	unsigned long i;
@@ -45,12 +47,32 @@
 		exit(2);
 	}
 
-	data_file_name = argv[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 ((ifp = fopen(data_file_name, "rb")) == NULL) {
-		error("Could not open \'%s\'.", data_file_name);
+		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]);
+	}
+
+	if ((ifp = fopen(argv[1], "rb")) == NULL) {
+		error("Could not open \'%s\'.", argv[1]);
+	}
+
 	/* Get the length of the data file to use for consistency checks */
 	data_file_len = fileSize(ifp);
 
@@ -61,13 +83,13 @@
 	/* Do a quick check to make sure the offset and length are good */
 	if (file_record_off + file_record_len > data_file_len) {
 		fclose(ifp);
-		error("\'%s\'. file records out of bounds.", data_file_name);
+		error("\'%s\'. file records out of bounds.", argv[1]);
 	}
 
 	/* Do a little consistancy check on file_record_length */
 	if (file_record_len % 0x28) {
 		fclose(ifp);
-		error("\'%s\'. file record length not multiple of 40.", data_file_name);
+		error("\'%s\'. file record length not multiple of 40.", argv[1]);
 	}
 
 	/* Extract the files */
@@ -84,7 +106,7 @@
 
 		if (!file_name[0]) {
 			fclose(ifp);
-			error("\'%s\'. file has no name.", data_file_name);
+			error("\'%s\'. file has no name.", argv[1]);
 		}
 		printf("extracting \'%s\'", file_name);
 
@@ -108,7 +130,7 @@
 		if (j == 0x20) {
 			file_name[0x1f] = 0;
 			fprintf(stderr, "\nwarning: \'%s\'. file name not null terminated.\n", file_name);
-			fprintf(stderr, "data file \'%s\' may be not a file extract_scumm_mac can extract.\n", data_file_name);
+			fprintf(stderr, "data file \'%s\' may be not a file extract_scumm_mac can extract.\n", argv[1]);
 		}
 
 		printf(", saving as \'%s\'\n", file_name);
@@ -116,7 +138,7 @@
 		/* Consistency check. make sure the file data is in the file */
 		if (file_off + file_len > data_file_len) {
 			fclose(ifp);
-			error("\'%s\'. file out of bounds.", data_file_name);
+			error("\'%s\'. file out of bounds.", argv[1]);
 		}
 
 		/* Write a file */
@@ -125,7 +147,8 @@
 			error("Seek error.");
 		}
 
-		ofp = fopen(file_name, "wb");
+		sprintf(fname, "%s/%s", inputPath, file_name);
+		ofp = fopen(fname, "wb");
 
 		if (!(buf = malloc(file_len))) {
 			fclose(ifp);

Modified: tools/branches/gsoc2007-toolsgui/extract_zak_c64.c
===================================================================
--- tools/branches/gsoc2007-toolsgui/extract_zak_c64.c	2007-08-03 03:30:50 UTC (rev 28425)
+++ tools/branches/gsoc2007-toolsgui/extract_zak_c64.c	2007-08-03 03:39:23 UTC (rev 28426)
@@ -57,7 +57,9 @@
 
 int main (int argc, char **argv) {
 	FILE *input1, *input2, *output;
-	char fname[256];
+	char fname[1024];
+	char* p;
+	char inputPath[768];
 	int i, j;
 	unsigned short signature;
 
@@ -66,6 +68,28 @@
 		exit(2);
 	}
 
+	/* 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]);
+	}
+
 	if (!(input1 = fopen(argv[1],"rb"))) {
 		error("Unable to open file %s for input!",argv[1]);
 	}
@@ -87,11 +111,12 @@
 		error("Signature not found in disk 2!");
 	}
 
-	if (!(output = fopen("00.LFL","wb"))) {
+	sprintf(fname, "%s/00.LFL", inputPath);
+	if (!(output = fopen(fname, "wb"))) {
 		error("Unable to create index file!");
 	}
 
-	notice("Creating 00.LFL...");
+	notice("Creating %s...", fname);
 
 	/* write signature */
 	writeUint16LE(output, signature);
@@ -171,7 +196,7 @@
 			continue;
 		}
 
-		sprintf(fname,"%02i.LFL", i);
+		sprintf(fname,"%s/%02i.LFL", inputPath, i);
 		output = fopen(fname, "wb");
 
 		if (output == NULL) {

Modified: tools/branches/gsoc2007-toolsgui/kyra_pak.cpp
===================================================================
--- tools/branches/gsoc2007-toolsgui/kyra_pak.cpp	2007-08-03 03:30:50 UTC (rev 28425)
+++ tools/branches/gsoc2007-toolsgui/kyra_pak.cpp	2007-08-03 03:39:23 UTC (rev 28426)
@@ -147,6 +147,30 @@
 	return true;
 }
 
+bool PAKFile::outputAllFiles(char* outputPath) {
+	FileList *cur = _fileList;
+	char outputFilename[1024];
+
+	while (cur) {
+		sprintf(outputFilename, "%s/%s", outputPath, cur->filename);
+		FILE *file = fopen(outputFilename, "wb");
+		if (!file) {
+			error("couldn't open file '%s' for writing", outputFilename);
+			return false;
+		}
+		printf("Exracting file '%s'...", cur->filename);
+		if (fwrite(cur->data, 1, cur->size, file) == cur->size) {
+			printf("OK\n");
+		} else {
+			printf("FAILED\n");
+			return false;
+		}
+		fclose(file);
+		cur = cur->next;
+	}
+	return true;
+}
+
 bool PAKFile::outputFileAs(const char *f, const char *fn) {
 	FileList *cur = (_fileList != 0) ? _fileList->findEntry(f) : 0;
 

Modified: tools/branches/gsoc2007-toolsgui/kyra_pak.h
===================================================================
--- tools/branches/gsoc2007-toolsgui/kyra_pak.h	2007-08-03 03:30:50 UTC (rev 28425)
+++ tools/branches/gsoc2007-toolsgui/kyra_pak.h	2007-08-03 03:39:23 UTC (rev 28426)
@@ -39,6 +39,7 @@
 	void drawFileList();
 
 	bool outputAllFiles();
+	bool outputAllFiles(char* outputPath);
 
 	bool outputFile(const char *file) { return outputFileAs(file, file); }
 	bool outputFileAs(const char *file, const char *outputName);


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