]> granicus.if.org Git - zziplib/commitdiff
memdisk-stuff
authorGuido Draheim <guidod@gmx.de>
Mon, 16 May 2005 10:40:47 +0000 (10:40 +0000)
committerGuido Draheim <guidod@gmx.de>
Mon, 16 May 2005 10:40:47 +0000 (10:40 +0000)
 (.)

12 files changed:
bins/unzzipcat-mem.c [new file with mode: 0644]
bins/unzzipdir-mem.c [new file with mode: 0644]
configure
zzip/Makefile.am
zzip/Makefile.in
zzip/__fnmatch.h [new file with mode: 0644]
zzip/fseeko.c
zzip/fseeko.h
zzip/memdisk.c
zzip/memdisk.h
zzip/mmapped.c
zzip/mmapped.h

diff --git a/bins/unzzipcat-mem.c b/bins/unzzipcat-mem.c
new file mode 100644 (file)
index 0000000..7474854
--- /dev/null
@@ -0,0 +1,128 @@
+/*
+ *     Copyright (c) 2003 Guido Draheim <guidod@gmx.de>
+ *      Use freely under the restrictions of the ZLIB license.
+ *
+ *      This file is used as an example to clarify zzipmmap api usage.
+ */
+
+#include <zzip/memdisk.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#ifdef ZZIP_HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+#ifdef ZZIP_HAVE_IO_H
+#include <io.h>
+#endif
+
+#ifdef ZZIP_HAVE_FNMATCH_H
+#include <fnmatch.h>
+#else
+#define fnmatch(x,y,z) strcmp(x,y)
+#endif
+
+#ifndef O_BINARY
+#define O_BINARY 0
+#endif
+
+static const char usage[] = 
+{
+    "unzzipdir-mem <zip> [names].. \n"
+    "  - unzzip data content of files contained in a zip archive.\n"
+};
+
+static void zzip_mem_entry_fprint(ZZIP_MEM_DISK* disk, 
+                                 ZZIP_MEM_ENTRY* entry, FILE* out)
+{
+    ZZIP_DISK_FILE* file = zzip_mem_entry_fopen (disk, entry);
+    if (file) 
+    {
+       char buffer[1024]; int len;
+       while ((len = zzip_mem_disk_fread (buffer, 1024, 1, file)))
+           fwrite (buffer, len, 1, out);
+       
+       zzip_mem_disk_fclose (file);
+    }
+}
+
+static void zzip_mem_disk_cat_file(ZZIP_MEM_DISK* disk, char* name, FILE* out)
+{
+    ZZIP_DISK_FILE* file = zzip_mem_disk_fopen (disk, name);
+    if (file) 
+    {
+       char buffer[1024]; int len;
+       while ((len = zzip_mem_disk_fread (buffer, 1, 1024, file))) 
+       {
+           fwrite (buffer, 1, len, out);
+       }
+       
+       zzip_mem_disk_fclose (file);
+    }
+}
+
+int 
+main (int argc, char ** argv)
+{
+    int argn;
+    ZZIP_MEM_DISK* disk;
+
+    if (argc <= 1 || ! strcmp (argv[1], "--help"))
+    {
+        printf (usage);
+        return 0;
+    }
+    if (! strcmp (argv[1], "--version"))
+    {
+       printf (__FILE__" version "ZZIP_PACKAGE" "ZZIP_VERSION"\n");
+       return 0;
+    }
+
+    disk = zzip_mem_disk_open (argv[1]);
+    if (! disk) {
+       perror(argv[1]);
+       return -1;
+    }
+
+    if (argc == 2)
+    {  /* print directory list */
+       ZZIP_MEM_ENTRY* entry = zzip_mem_disk_findfirst(disk);
+       for (; entry ; entry = zzip_mem_disk_findnext(disk, entry))
+       {
+           char* name = zzip_mem_entry_to_name (entry);
+           printf ("%s\n", name);
+       }
+       return 0;
+    }
+
+    if (argc == 3)
+    {  /* list from one spec */
+       ZZIP_MEM_ENTRY* entry = 0;
+       while ((entry = zzip_mem_disk_findmatch(disk, argv[2], entry, 0, 0)))
+       {
+            zzip_mem_entry_fprint (disk, entry, stdout);
+       }
+
+       return 0;
+    }
+
+    for (argn=1; argn < argc; argn++)
+    {   /* list only the matching entries - each in order of commandline */
+       ZZIP_MEM_ENTRY* entry = zzip_mem_disk_findfirst(disk);
+       for (; entry ; entry = zzip_mem_disk_findnext(disk, entry))
+       {
+           char* name = zzip_mem_entry_to_name (entry);
+           if (! fnmatch (argv[argn], name, 
+                          FNM_NOESCAPE|FNM_PATHNAME|FNM_PERIOD))
+               zzip_mem_disk_cat_file (disk, name, stdout);
+       }
+    }
+    return 0;
+} 
+
+/* 
+ * Local variables:
+ * c-file-style: "stroustrup"
+ * End:
+ */
diff --git a/bins/unzzipdir-mem.c b/bins/unzzipdir-mem.c
new file mode 100644 (file)
index 0000000..dc02077
--- /dev/null
@@ -0,0 +1,101 @@
+/*
+ *     Copyright (c) 2003 Guido Draheim <guidod@gmx.de>
+ *      Use freely under the restrictions of the ZLIB license.
+ *
+ *      This file is used as an example to clarify zzipmmap api usage.
+ */
+
+#include <zzip/memdisk.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#ifdef ZZIP_HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+#ifdef ZZIP_HAVE_IO_H
+#include <io.h>
+#endif
+
+#ifdef ZZIP_HAVE_FNMATCH_H
+#include <fnmatch.h>
+#else
+#define fnmatch(x,y,z) strcmp(x,y)
+#endif
+
+#ifndef O_BINARY
+#define O_BINARY 0
+#endif
+
+static const char usage[] = 
+{
+    "unzzipdir <zip> [names].. \n"
+    "  - unzzip a listing of files contained in a zip archive.\n"
+};
+
+int 
+main (int argc, char ** argv)
+{
+    int argn;
+    ZZIP_MEM_DISK* disk;
+
+    if (argc <= 1 || ! strcmp (argv[1], "--help"))
+    {
+        printf (usage);
+        return 0;
+    }
+    if (! strcmp (argv[1], "--version"))
+    {
+       printf (__FILE__" version "ZZIP_PACKAGE" "ZZIP_VERSION"\n");
+       return 0;
+    }
+
+    disk = zzip_mem_disk_open (argv[1]);
+    if (! disk) {
+       perror(argv[1]);
+       return -1;
+    }
+
+    if (argc == 2)
+    {  /* list all */
+       ZZIP_MEM_ENTRY* entry = zzip_mem_disk_findfirst(disk);
+       for (; entry ; entry = zzip_mem_disk_findnext(disk, entry))
+       {
+           char* name = zzip_mem_entry_to_name (entry);
+           printf ("%s\n", name);
+       }
+       return 0;
+    }
+
+    if (argc == 3)
+    {  /* list from one spec */
+       ZZIP_MEM_ENTRY* entry = 0;
+       while ((entry = zzip_mem_disk_findmatch(disk, argv[2], entry, 0, 0)))
+       {
+           char* name = zzip_mem_entry_to_name (entry);
+           printf ("%s\n", name);
+       }
+       return 0;
+    }
+
+    {   /* list only the matching entries - in order of zip directory */
+       ZZIP_MEM_ENTRY* entry = zzip_mem_disk_findfirst(disk);
+       for (; entry ; entry = zzip_mem_disk_findnext(disk, entry))
+       {
+           char* name = zzip_mem_entry_to_name (entry);
+           for (argn=1; argn < argc; argn++)
+           {
+               if (! fnmatch (argv[argn], name, 
+                              FNM_NOESCAPE|FNM_PATHNAME|FNM_PERIOD))
+                   printf ("%s\n", name);
+           }
+       }
+       return 0;
+    }
+} 
+
+/* 
+ * Local variables:
+ * c-file-style: "stroustrup"
+ * End:
+ */
index 456c6eb5809a6da5cc4bd539d7dbe7c1adf64159..ce272cefbe07cbd1ca87b58c9437c8e02ac52955 100755 (executable)
--- a/configure
+++ b/configure
@@ -1,5 +1,5 @@
 #! /bin/sh
-# From configure.ac Revision: 1.3 .
+# From configure.ac Revision: 1.4 .
 # Guess values for system-dependent variables and create Makefiles.
 # Generated by GNU Autoconf 2.59.
 #
index 3533dbaa187c359af77fccbc1827706559ee7ea3..951210b955f727d989d8e90dfbc35e787a4950d4 100644 (file)
@@ -8,7 +8,7 @@ zzipdir = ${includedir}/zzip
 zzip_HEADERS = $(libzzip_la_headers) \
                $(libzzipmmapped_la_headers) \
                $(libzzipfseeko_la_headers)
-noinst_HEADERS = __debug.h __hints.h __mmap.h __dirent.h
+noinst_HEADERS = __debug.h __hints.h __mmap.h __dirent.h __fnmatch.h
 #
 VERSION_INFO=@VERSION_INFO@
 RELEASE_INFO=@RELEASE_INFO@
index 11ac9ec95bc1e904e85b1bb31eeb71dc08394bcd..fb232f7fb4a8b1f5edf681642558c9f598a9a074 100644 (file)
@@ -234,7 +234,7 @@ zzip_HEADERS = $(libzzip_la_headers) \
                $(libzzipmmapped_la_headers) \
                $(libzzipfseeko_la_headers)
 
-noinst_HEADERS = __debug.h __hints.h __mmap.h __dirent.h
+noinst_HEADERS = __debug.h __hints.h __mmap.h __dirent.h __fnmatch.h
 #
 libzzip_la_SOURCES = \
        zip.c \
diff --git a/zzip/__fnmatch.h b/zzip/__fnmatch.h
new file mode 100644 (file)
index 0000000..3456a56
--- /dev/null
@@ -0,0 +1,28 @@
+#ifndef __ZZIP__FNMATCH_H
+#define __ZZIP__FNMATCH_H
+/** included by fseeko.c, mmapped.c, memdisk.c */
+
+#include <zzip/conf.h>
+
+#ifdef ZZIP_HAVE_FNMATCH_H
+#include <fnmatch.h>
+#endif
+
+#ifdef ZZIP_HAVE_FNMATCH_H
+#define _zzip_fnmatch fnmatch
+# ifdef FNM_CASEFOLD
+# define _zzip_fnmatch_CASEFOLD FNM_CASEFOLD
+# else
+# define _zzip_fnmatch_CASEFOLD 0
+# endif
+#else
+# define _zzip_fnmatch_CASEFOLD 0
+/* if your system does not have fnmatch, we fall back to strcmp: */
+static int _zzip_fnmatch(char* pattern, char* string, int flags)
+{ 
+    puts ("<zzip:mmapped:strcmp>");
+    return strcmp (pattern, string); 
+}
+#endif
+
+#endif
index 7daab3379f6aae674f81a3947940e46c0cefa075..1f026e9058719d789c42ddcaedc44565629c060d 100644 (file)
  *          of the Mozilla Public License 1.1
  */
 
-#define _LARGEFILE_SOURCE
+#define _LARGEFILE_SOURCE 1
+#define _ZZIP_ENTRY_STRUCT 1
+
+#include <zzip/types.h>
 
-#include <zzip/fseeko.h>
 #include <assert.h>
 #include <stdlib.h>
 #include <sys/stat.h>
 
-#ifdef ZZIP_HAVE_FNMATCH_H
-#include <fnmatch.h>
-#endif
-
 #if   defined ZZIP_HAVE_STRING_H
 #include <string.h>
 #elif defined ZZIP_HAVE_STRINGS_H
 
 #include <zlib.h>
 #include <zzip/format.h>
+#include <zzip/fseeko.h>
 #include <zzip/fetch.h>
 #include <zzip/__mmap.h>
+#include <zzip/__fnmatch.h>
 
 #if __STDC_VERSION__+0 > 199900L
 #define ___
@@ -397,7 +397,7 @@ zzip_entry_findmatch(FILE* disk, char* filespec,
     {  /* filenames within zip files are often not null-terminated! */
        char* realname = zzip_entry_strdup_name (entry);
        if (! realname) continue;
-       if (! compare (filespec, realname, flags)) 
+       if (! compare (filespec, realname, flags)) {
            free (realname);    return entry;
        } else {
            free (realname);    continue;
index 34ce3c5dac81e3d8ef7e0599eb303a6c380e80b8..59ca576dac4d4b21369f5eff2dceef9368c7ce96 100644 (file)
@@ -72,7 +72,7 @@ zzip_entry_fclose (ZZIP_ENTRY_FILE* file);
 int
 zzip_entry_feof (ZZIP_ENTRY_FILE* file);
 
-# ifdef _ZZIP_MEM_ENTRY_PRIVATE
+# ifdef _ZZIP_ENTRY_STRUCT
 #  ifdef __cplusplus
 #  define __zzip_entry_extends_zzip_disk_entry
 struct zzip_entry : public struct zzip_disk_entry
index fab5087873f8ddcaf310dd0ddf0bc53d427994b9..1abd04303e9afc55d042397ffd9ea7ef115355bf 100644 (file)
  *          or alternatively the restrictions 
  *          of the Mozilla Public License 1.1
  */
-#define _ZZIP_MEM_DISK_PRIVATE 1
-#define _ZZIP_MMAPPED_PRIVATE 1
+#define _ZZIP_DISK_FILE_STRUCT 1
 
-#include <zzip/lib.h>                                  /* archive handling */
-#include <zzip/file.h>
-#include <zzip/format.h>
-#include <zzip/fetch.h>
+#include <zzip/types.h>
 
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
 
+#include <zlib.h>
+#include <zzip/format.h>
+#include <zzip/fetch.h>
 #include <zzip/mmapped.h>
 #include <zzip/memdisk.h>
+#include <zzip/__fnmatch.h>
 
 #define ___ {
 #define ____ }
index eb3d9c58cbc3a75883b4840b8889249964b17371..292226716ff3a94262e310bf453b5a5e3e779b96 100644 (file)
@@ -9,10 +9,8 @@ typedef struct _zzip_mem_entry ZZIP_MEM_ENTRY;
 
 struct _zzip_mem_disk {
     ZZIP_DISK* disk;
-#  ifdef _ZZIP_MEM_DISK_PRIVATE
     ZZIP_MEM_ENTRY* list;
     ZZIP_MEM_ENTRY* last;
-#  endif
 };
 
 #ifndef zzip_mem_disk_extern
index 3fd736c916d4e6b4ff544c7732e5c0f033914999..76b6000c325e5aa9d1bf5421379b8c1bf976681c 100644 (file)
 #define _GNU_SOURCE _glibc_developers_are_idiots_to_call_this_gnu_specific_
 #endif
 
-#define _ZZIP_MMAPPED_PRIVATE 1
+#define _ZZIP_DISK_FILE_STRUCT 1
 
-#include <zlib.h>
-#include <zzip/format.h>
-#include <zzip/fetch.h>
-#include <zzip/__mmap.h>
+#include <zzip/types.h>
 
-#include <zzip/mmapped.h>
 #include <stdlib.h>
 #include <sys/stat.h>
 
-#ifdef ZZIP_HAVE_FNMATCH_H
-#include <fnmatch.h>
-#endif
-
 #if   defined ZZIP_HAVE_UNISTD_H
 #include <unistd.h>
 #elif defined ZZIP_HAVE_IO_H
 #include <strings.h>
 #endif
 
+#include <zlib.h>
+#include <zzip/mmapped.h>
+#include <zzip/format.h>
+#include <zzip/fetch.h>
+#include <zzip/__mmap.h>
+#include <zzip/__fnmatch.h>
 
 #if __STDC_VERSION__+0 > 199900L
 #define ___
@@ -407,23 +405,6 @@ zzip_disk_findfile(ZZIP_DISK* disk, char* filename,
     return 0;
 }
 
-#ifdef ZZIP_HAVE_FNMATCH_H
-#define _zzip_fnmatch fnmatch
-# ifdef FNM_CASEFOLD
-# define _zzip_fnmatch_CASEFOLD FNM_CASEFOLD
-# else
-# define _zzip_fnmatch_CASEFOLD 0
-# endif
-#else
-# define _zzip_fnmatch_CASEFOLD 0
-/* if your system does not have fnmatch, we fall back to strcmp: */
-static int _zzip_fnmatch(char* pattern, char* string, int flags)
-{ 
-    puts ("<zzip:mmapped:strcmp>");
-    return strcmp (pattern, string); 
-}
-#endif
-
 /** => zzip_disk_findfile
  *
  * This function uses a compare-function with an additional argument
index f27869f7606783d4b511b25c934748ef325e2608..47a750c59fdf6875bd1e71fc40d9d35ad140f999 100644 (file)
@@ -100,7 +100,7 @@ zzip_disk_fclose (ZZIP_DISK_FILE* file);
 int
 zzip_disk_feof (ZZIP_DISK_FILE* file);
 
-#ifdef _ZZIP_MMAPPED_PRIVATE
+#ifdef _ZZIP_DISK_FILE_STRUCT
 /**
  * typedef struct zzip_disk_file ZZIP_DISK_FILE;
  */