--- /dev/null
+/*
+ * 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:
+ */
--- /dev/null
+/*
+ * 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:
+ */
#! /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.
#
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@
$(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 \
--- /dev/null
+#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
* 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 ___
{ /* 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;
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
* 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 ____ }
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
#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 ___
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
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;
*/