diff lwar/add.c @ 174:cc41ccee8f64

added --merge to lwar
author lost
date Tue, 03 Mar 2009 00:42:47 +0000
parents 47427342e41d
children bae1e3ecdce1
line wrap: on
line diff
--- a/lwar/add.c	Mon Mar 02 04:13:49 2009 +0000
+++ b/lwar/add.c	Tue Mar 03 00:42:47 2009 +0000
@@ -116,6 +116,65 @@
 			perror("");
 			exit(1);
 		}
+		fread(buf, 1, 6, f2);
+		if (mergeflag && !memcmp("LWAR1V", buf, 6))
+		{
+			// add archive contents...
+			for (;;)
+			{
+				c = fgetc(f2);
+				if (c == EOF || ferror(f2))
+				{
+					perror("Reading input archive file");
+					exit(1);
+				}
+				if (c == EOF)
+					break;
+		
+				if (!c)
+				{
+					break;
+				}
+		
+				// find the end of the file name
+				while (c)
+				{
+					fputc(c, f);
+					c = fgetc(f2);
+					if (c == EOF || ferror(f))
+					{
+						fprintf(stderr, "Bad input archive file\n");
+						exit(1);
+					}
+				}
+				fputc(0, f);
+				
+				// get length of archive member
+				l = 0;
+				c = fgetc(f2);
+				fputc(c, f);
+				l = c << 24;
+				c = fgetc(f2);
+				fputc(c, f);
+				l |= c << 16;
+				c = fgetc(f2);
+				fputc(c, f);
+				l |= c << 8;
+				c = fgetc(f2);
+				fputc(c, f);
+				l |= c;
+		
+				while (l)
+				{
+					c = fgetc(f2);
+					fputc(c, f);
+					l--;
+				}
+			}
+			
+			fclose(f2);
+			continue;
+		}
 		fseek(f2, 0, SEEK_END);
 		l = ftell(f2);
 		fseek(f2, 0, SEEK_SET);