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

lightcast at users.sourceforge.net lightcast at users.sourceforge.net
Mon Aug 13 04:47:30 CEST 2007


Revision: 28573
          http://scummvm.svn.sourceforge.net/scummvm/?rev=28573&view=rev
Author:   lightcast
Date:     2007-08-12 19:47:30 -0700 (Sun, 12 Aug 2007)

Log Message:
-----------
Fixed a bug when splitting the filename specified on the command line into a filename and path.  Also moved this code into util.c as it is used by almost all of the compression/extraction tools..

Modified Paths:
--------------
    tools/branches/gsoc2007-toolsgui/compress_agos.c
    tools/branches/gsoc2007-toolsgui/compress_queen.c
    tools/branches/gsoc2007-toolsgui/compress_saga.cpp
    tools/branches/gsoc2007-toolsgui/compress_scumm_sou.c
    tools/branches/gsoc2007-toolsgui/encode_dxa.cpp
    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_scumm_mac.c
    tools/branches/gsoc2007-toolsgui/extract_zak_c64.c
    tools/branches/gsoc2007-toolsgui/util.c
    tools/branches/gsoc2007-toolsgui/util.h

Modified: tools/branches/gsoc2007-toolsgui/compress_agos.c
===================================================================
--- tools/branches/gsoc2007-toolsgui/compress_agos.c	2007-08-13 02:11:55 UTC (rev 28572)
+++ tools/branches/gsoc2007-toolsgui/compress_agos.c	2007-08-13 02:47:30 UTC (rev 28573)
@@ -312,7 +312,6 @@
 
 int main(int argc, char *argv[]) {
 	int i;
-	char *p;
 	char inputFile[256];
 	char inputPath[768];
 	bool convertMac = false;
@@ -325,18 +324,18 @@
 	gCompMode = kMP3Mode;
 	i = 1;
 
-	if (strcmp(argv[1], "--mp3") == 0) {
+	if (strcmp(argv[i], "--mp3") == 0) {
 		gCompMode = kMP3Mode;
 		i++;
-	} else if (strcmp(argv[1], "--vorbis") == 0) {
+	} else if (strcmp(argv[i], "--vorbis") == 0) {
 		gCompMode = kVorbisMode;
 		i++;
-	} else if (strcmp(argv[1], "--flac") == 0) {
+	} else if (strcmp(argv[i], "--flac") == 0) {
 		gCompMode = kFlacMode;
 		i++;
 	}
 
-	if (strcmp(argv[2], "--mac") == 0) {
+	if (strcmp(argv[i], "--mac") == 0) {
 		convertMac = true;
 		i++;
 	}
@@ -365,37 +364,13 @@
 		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;
-		}
-	}
-
-	/* 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 {
-		strcpy(inputFile, p + 1);
-		strncpy(inputPath, argv[argc - 1], p - argv[argc - 1]);
-	}
-
-	if (convertMac) {
 		convert_mac(inputPath);
 	} else {
+		getPath(argv[argc - 1], inputPath);
+		getFilename(argv[argc - 1], inputFile);
 		convert_pc(inputPath, inputFile);
 	}
 

Modified: tools/branches/gsoc2007-toolsgui/compress_queen.c
===================================================================
--- tools/branches/gsoc2007-toolsgui/compress_queen.c	2007-08-13 02:11:55 UTC (rev 28572)
+++ tools/branches/gsoc2007-toolsgui/compress_queen.c	2007-08-13 02:47:30 UTC (rev 28573)
@@ -37,7 +37,6 @@
 #define SB_HEADER_SIZE_V104 110
 #define SB_HEADER_SIZE_V110 122
 
-
 enum {
 	COMPRESSION_NONE = 0,
 	COMPRESSION_MP3 = 1,
@@ -118,8 +117,7 @@
 
 const struct GameVersion *version;
 
-void showhelp(char *exename)
-{
+void showhelp(char *exename) {
 	printf("\nUsage: %s [params] queen.1\n", exename);
 
 	printf("\nParams:\n");
@@ -246,11 +244,9 @@
 	unlink(TEMP_DAT);
 }
 
-int main(int argc, char *argv[])
-{
+int main(int argc, char *argv[]) {
 	FILE *inputData, *inputTbl, *outputTbl, *outputData, *tmpFile, *compFile;
 	uint8 compressionType = COMPRESSION_NONE;
-	char *p;
 	char inputPath[768];
 	char tblPath[1024];
 	char tmp[5];
@@ -303,28 +299,8 @@
 		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], '\\');
+	getPath(argv[argc - 1], inputPath);
 
-		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]);

Modified: tools/branches/gsoc2007-toolsgui/compress_saga.cpp
===================================================================
--- tools/branches/gsoc2007-toolsgui/compress_saga.cpp	2007-08-13 02:11:55 UTC (rev 28572)
+++ tools/branches/gsoc2007-toolsgui/compress_saga.cpp	2007-08-13 02:47:30 UTC (rev 28573)
@@ -495,7 +495,6 @@
 
 int main(int argc, char *argv[]) {
 	int	i;
-	char *p;
 	char inputPath[768];
 	char *inputFileName = NULL;
 	char inputFileNameWithExt[256];
@@ -543,30 +542,9 @@
 		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], '\\');
+	getPath(argv[argc - 1], inputPath);
+	getFilename(argv[argc - 1], inputFileName);
 
-		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");
 	}

Modified: tools/branches/gsoc2007-toolsgui/compress_scumm_sou.c
===================================================================
--- tools/branches/gsoc2007-toolsgui/compress_scumm_sou.c	2007-08-13 02:11:55 UTC (rev 28572)
+++ tools/branches/gsoc2007-toolsgui/compress_scumm_sou.c	2007-08-13 02:47:30 UTC (rev 28573)
@@ -188,7 +188,6 @@
 }
 
 int main(int argc, char *argv[]) {
-	char *p;
 	char inputPath[768];
 	char buf[2048];
 	int i;
@@ -239,28 +238,8 @@
 		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], '\\');
+	getPath(argv[argc - 1], inputPath);
 
-		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]);

Modified: tools/branches/gsoc2007-toolsgui/encode_dxa.cpp
===================================================================
--- tools/branches/gsoc2007-toolsgui/encode_dxa.cpp	2007-08-13 02:11:55 UTC (rev 28572)
+++ tools/branches/gsoc2007-toolsgui/encode_dxa.cpp	2007-08-13 02:47:30 UTC (rev 28573)
@@ -778,17 +778,12 @@
 	i = argc - 1;
 
 	// get filename prefix
-	char prefix[256];
 	char *filename = argv[i++];
+	char prefix[256];
+	char *p;
 
-	char *p = strrchr(filename, '/');
-	if (!p) {
-		p = strrchr(filename, '\\');
-		if (!p) {
-			p = filename - 1;
-		}
-	}
-	strcpy(prefix, p + 1);
+	getFilename(filename, prefix);
+
 	p = strrchr(prefix, '.');
 	if (p) {
 		*p = '\0';

Modified: tools/branches/gsoc2007-toolsgui/extract_kyra.cpp
===================================================================
--- tools/branches/gsoc2007-toolsgui/extract_kyra.cpp	2007-08-13 02:11:55 UTC (rev 28572)
+++ tools/branches/gsoc2007-toolsgui/extract_kyra.cpp	2007-08-13 02:47:30 UTC (rev 28573)
@@ -36,7 +36,6 @@
 }
 
 int main(int argc, char **argv) {
-	char *p;
 	char inputPath[768];
 
 	if (argc < 2) {
@@ -76,28 +75,8 @@
 		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], '\\');
+	getPath(argc[argv - 1], inputPath);
 
-		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(inputPath);
 	} else if(extractOne) {

Modified: tools/branches/gsoc2007-toolsgui/extract_loom_tg16.c
===================================================================
--- tools/branches/gsoc2007-toolsgui/extract_loom_tg16.c	2007-08-13 02:11:55 UTC (rev 28572)
+++ tools/branches/gsoc2007-toolsgui/extract_loom_tg16.c	2007-08-13 02:47:30 UTC (rev 28573)
@@ -1335,7 +1335,6 @@
 	FILE *input, *output;
 	char fname[1024];
 	int i, j;
-	char *p;
 	char inputPath[768];
 #else
 	FILE *input;
@@ -1348,28 +1347,8 @@
 		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], '\\');
+	getPath(argv[argc - 1], inputPath);
 
-		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]);
 	}

Modified: tools/branches/gsoc2007-toolsgui/extract_mm_apple.c
===================================================================
--- tools/branches/gsoc2007-toolsgui/extract_mm_apple.c	2007-08-13 02:11:55 UTC (rev 28572)
+++ tools/branches/gsoc2007-toolsgui/extract_mm_apple.c	2007-08-13 02:47:30 UTC (rev 28573)
@@ -58,7 +58,6 @@
 int main (int argc, char **argv) {
 	FILE *input1, *input2, *output;
 	char fname[1024];
-	char *p;
 	char inputPath[768];
 	int i, j;
 	unsigned short signature;
@@ -68,28 +67,8 @@
 		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], '\\');
+	getPath(argv[argc - 1], inputPath);
 
-		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]);
 	}

Modified: tools/branches/gsoc2007-toolsgui/extract_mm_c64.c
===================================================================
--- tools/branches/gsoc2007-toolsgui/extract_mm_c64.c	2007-08-13 02:11:55 UTC (rev 28572)
+++ tools/branches/gsoc2007-toolsgui/extract_mm_c64.c	2007-08-13 02:47:30 UTC (rev 28573)
@@ -58,7 +58,6 @@
 int main (int argc, char **argv) {
 	FILE *input1, *input2, *output;
 	char fname[1024];
-	char *p;
 	char inputPath[768];
 	int i, j;
 	unsigned short signature;
@@ -68,28 +67,8 @@
 		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], '\\');
+	getPath(argv[argc - 1], inputPath);
 
-		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]);
 	}

Modified: tools/branches/gsoc2007-toolsgui/extract_mm_nes.c
===================================================================
--- tools/branches/gsoc2007-toolsgui/extract_mm_nes.c	2007-08-13 02:11:55 UTC (rev 28572)
+++ tools/branches/gsoc2007-toolsgui/extract_mm_nes.c	2007-08-13 02:47:30 UTC (rev 28573)
@@ -1085,7 +1085,6 @@
 int main (int argc, char **argv) {
 	FILE *input, *output;
 	char fname[1024];
-	char *p;
 	char inputPath[768];
 	int i, j;
 	uint32 CRC;
@@ -1097,28 +1096,8 @@
 		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], '\\');
+	getPath(argv[argc - 1], inputPath);
 
-		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]);
 	}

Modified: tools/branches/gsoc2007-toolsgui/extract_scumm_mac.c
===================================================================
--- tools/branches/gsoc2007-toolsgui/extract_scumm_mac.c	2007-08-13 02:11:55 UTC (rev 28572)
+++ tools/branches/gsoc2007-toolsgui/extract_scumm_mac.c	2007-08-13 02:47:30 UTC (rev 28573)
@@ -32,7 +32,6 @@
 	unsigned long file_off, file_len;
 	unsigned long data_file_len;
 	char fname[1024];
-	char* p;
 	char inputPath[768];
 	char file_name[0x20];
 	char *buf;
@@ -47,28 +46,8 @@
 		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], '\\');
+	getPath(argv[argc - 1], inputPath);
 
-		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]);
 	}

Modified: tools/branches/gsoc2007-toolsgui/extract_zak_c64.c
===================================================================
--- tools/branches/gsoc2007-toolsgui/extract_zak_c64.c	2007-08-13 02:11:55 UTC (rev 28572)
+++ tools/branches/gsoc2007-toolsgui/extract_zak_c64.c	2007-08-13 02:47:30 UTC (rev 28573)
@@ -58,7 +58,6 @@
 int main (int argc, char **argv) {
 	FILE *input1, *input2, *output;
 	char fname[1024];
-	char* p;
 	char inputPath[768];
 	int i, j;
 	unsigned short signature;
@@ -68,28 +67,8 @@
 		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], '\\');
+	getPath(argv[argc - 1], inputPath);
 
-		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]);
 	}

Modified: tools/branches/gsoc2007-toolsgui/util.c
===================================================================
--- tools/branches/gsoc2007-toolsgui/util.c	2007-08-13 02:11:55 UTC (rev 28572)
+++ tools/branches/gsoc2007-toolsgui/util.c	2007-08-13 02:47:30 UTC (rev 28573)
@@ -135,3 +135,48 @@
 	return sz;
 }
 
+void getPath(const char *fullpath, char *path) {
+	const char *p;
+
+	/* Find the last occurence of '/' or '\'
+	 * Everything before this point is the path
+	 * Everything after this point is the filename
+	 */
+	p = strrchr(fullpath, '/');
+	if (!p) {
+		p = strrchr(fullpath, '\\');
+
+		if (!p) {
+			p = fullpath - 1;
+		}
+	}
+
+	/* The path is everything before p, unless the file is in the current
+	 * directory, in which case the path is '.'
+	 */
+	if (p < fullpath) {
+		strcpy(path, ".");
+	} else {
+		strncpy(path, fullpath, p - fullpath);
+		path[strlen(fullpath) - strlen(p)] = '\0';
+	}
+}
+
+void getFilename(const char *fullpath, char *filename) {
+	const char *p;
+
+	/* Find the last occurence of '/' or '\'
+	 * Everything before this point is the path
+	 * Everything after this point is the filename
+	 */
+	p = strrchr(fullpath, '/');
+	if (!p) {
+		p = strrchr(fullpath, '\\');
+
+		if (!p) {
+			p = fullpath - 1;
+		}
+	}
+
+	strcpy(filename, p + 1);
+}

Modified: tools/branches/gsoc2007-toolsgui/util.h
===================================================================
--- tools/branches/gsoc2007-toolsgui/util.h	2007-08-13 02:11:55 UTC (rev 28572)
+++ tools/branches/gsoc2007-toolsgui/util.h	2007-08-13 02:47:30 UTC (rev 28573)
@@ -228,6 +228,8 @@
 void NORETURN_PRE error(const char *s, ...) NORETURN_POST;
 void warning(const char *s, ...);
 void debug(int level, const char *s, ...);
+void getPath(const char *fullpath, char *path);
+void getFilename(const char *fullpath, char *filename);
 
 #if defined(__cplusplus)
 }


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