changeset 174:cc41ccee8f64

added --merge to lwar
author lost
date Tue, 03 Mar 2009 00:42:47 +0000
parents 0395e6fd67e9
children f8ec28ace0c6
files lwar/add.c lwar/lwar.c lwar/lwar.h lwar/main.c
diffstat 4 files changed, 87 insertions(+), 1 deletions(-) [+]
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);
--- a/lwar/lwar.c	Mon Mar 02 04:13:49 2009 +0000
+++ b/lwar/lwar.c	Tue Mar 03 00:42:47 2009 +0000
@@ -26,16 +26,26 @@
 #include "config.h"
 #endif
 
+#include <stdio.h>
 #include <stdlib.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
 
 #define __lwar_c_seen__
 #include "lwar.h"
 #include "util.h"
 
+typedef struct
+{
+	FILE *f;
+} arhandle_real;
+
 int debug_level = 0;
 int operation = 0;
 int nfiles = 0;
 char *archive_file = NULL;
+int mergeflag = 0;
 
 char **files = NULL;
 
--- a/lwar/lwar.h	Mon Mar 02 04:13:49 2009 +0000
+++ b/lwar/lwar.h	Tue Mar 03 00:42:47 2009 +0000
@@ -36,6 +36,15 @@
 extern int operation;
 extern int nfiles;
 extern char **files;
+extern int mergeflag;
+
+//typedef void * ARHANDLE;
+
+#define AR_MODE_RD		1
+#define AR_MODE_WR		2
+#define AR_MODE_RW		3
+#define AR_MODE_CREATE	4
+
 
 #define __lwar_E__ extern
 #else
@@ -44,6 +53,8 @@
 
 __lwar_E__ void add_file_name(char *fn);
 
+//__lwar_E__ ARHANDLE open_archive(char *fn, int mode);
+
 #undef __lwar_E__
 
 #endif //__lwar_h_seen__
--- a/lwar/main.c	Mon Mar 02 04:13:49 2009 +0000
+++ b/lwar/main.c	Tue Mar 03 00:42:47 2009 +0000
@@ -58,7 +58,11 @@
 		// create archive
 		operation = LWAR_OP_CREATE;
 		break;
-		
+	
+	case 'm':
+		mergeflag = 1;
+		break;
+
 //	case 'r':
 //		// remove members
 //		operation = LWAR_OP_REMOVE;
@@ -95,6 +99,8 @@
 				"List the contents of the archive" },
 	{ "create",		'c',	0,		0,
 				"Create new archive (or truncate existing one)" },
+	{ "merge",		'm',	0,		0,
+				"Add the contents of archive arguments instead of the archives themselves" },
 	{ "debug",		'd',	0,		0,
 				"Set debug mode"},
 	{ 0 }