diff lwar/replace.c @ 427:45df37e81741

Add option to ignore paths when extracting or adding files with lwar Add option to lwar to strip path names from filenames when objects are added to an archive. Also strip path names from objects when extracting them, if present.
author David Flamand <dlflamand@gmail.com>
date Tue, 15 Nov 2016 21:43:33 -0700
parents 221b5f58d8ad
children 6df8d62302e2
line wrap: on
line diff
--- a/lwar/replace.c	Thu Nov 03 21:44:32 2016 -0600
+++ b/lwar/replace.c	Tue Nov 15 21:43:33 2016 -0700
@@ -37,6 +37,7 @@
 	FILE *f;
 	FILE *nf;
 	unsigned char buf[8];
+	char *filename;
 	long l;
 	int c;
 	FILE *f2;
@@ -106,6 +107,7 @@
 			}
 		}
 		fnbuf2[i] = 0;
+		filename = get_file_name(fnbuf2);
 		
 		// get length of archive member
 		l = 0;
@@ -121,7 +123,7 @@
 		// is it a file we are replacing? if so, do not copy it
 		for (i = 0; i < nfiles; i++)
 		{
-			if (!strcmp(files[i], fnbuf2))
+			if (!strcmp(get_file_name(files[i]), filename))
 				break;
 		}
 		if (i < nfiles)
@@ -131,7 +133,7 @@
 		else
 		{
 			// otherwise, copy it
-			fprintf(nf, "%s", fnbuf2);
+			fprintf(nf, "%s", filename);
 			fputc(0, nf);
 			fputc(l >> 24, nf);
 			fputc((l >> 16) & 0xff, nf);
@@ -151,10 +153,11 @@
 doadd:
 	for (i = 0; i < nfiles; i++)
 	{
-		f2 = fopen(files[i], "rb");
+		filename = get_file_name(files[i]);
+		f2 = fopen(filename, "rb");
 		if (!f2)
 		{
-			fprintf(stderr, "Cannot open file %s:", files[i]);
+			fprintf(stderr, "Cannot open file %s:", filename);
 			perror("");
 			exit(1);
 		}
@@ -220,7 +223,7 @@
 		fseek(f2, 0, SEEK_END);
 		l = ftell(f2);
 		fseek(f2, 0, SEEK_SET);
-		fputs(files[i], nf);
+		fputs(filename, nf);
 		fputc(0, nf);
 		fputc(l >> 24, nf);
 		fputc((l >> 16) & 0xff, nf);