Skip to content

Commit

Permalink
add 7z archive indexing #7
Browse files Browse the repository at this point in the history
  • Loading branch information
genivia-inc committed Jan 1, 2024
1 parent 1a00d2a commit 4e03c78
Show file tree
Hide file tree
Showing 50 changed files with 13,712 additions and 77 deletions.
Binary file modified bin/win32/ugrep-indexer.exe
Binary file not shown.
Binary file modified bin/win64/ugrep-indexer.exe
Binary file not shown.
28 changes: 28 additions & 0 deletions configure
Expand Up @@ -769,6 +769,7 @@ with_lzma
with_lz4
with_zstd
with_brotli
enable_7zip
with_bzip3
'
ac_precious_vars='build_alias
Expand Down Expand Up @@ -1415,6 +1416,7 @@ Optional Features:
do not reject slow dependency extractors
--disable-dependency-tracking
speeds up one-time build
--disable-7zip to disable 7zip and no longer index .7z files
Optional Packages:
--with-PACKAGE[=ARG] use PACKAGE [ARG=yes]
Expand Down Expand Up @@ -6968,6 +6970,8 @@ printf "%s\n" "#define HAVE_LIBZ 1" >>confdefs.h
fi


if test -n "${zlib_places}"; then

#
# Handle user hints
#
Expand Down Expand Up @@ -7633,6 +7637,28 @@ printf "%s\n" "#define HAVE_LIBBROTLI 1" >>confdefs.h
fi


# Check whether --enable-7zip was given.
if test ${enable_7zip+y}
then :
enableval=$enable_7zip; with_no_7zip="yes"
else $as_nop
with_no_7zip="no"
fi

{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for --disable-7zip" >&5
printf %s "checking for --disable-7zip... " >&6; }
if test "x$with_no_7zip" = "xno"; then
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
printf "%s\n" "no" >&6; }
CPPFLAGS="$CPPFLAGS -I../lzma/C"
LDFLAGS="$LDFLAGS -L../lzma/C"
LIBS="-lviiz $LIBS"
else
EXTRA_CFLAGS="-DWITH_NO_7ZIP ${EXTRA_CFLAGS}"
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5
printf "%s\n" "yes" >&6; }
fi


# Check whether --with-bzip3 was given.
if test ${with_bzip3+y}
Expand Down Expand Up @@ -7780,6 +7806,8 @@ fi

fi

fi

PTHREAD_CFLAGS=""

PTHREAD_LIBS="-lpthread"
Expand Down
20 changes: 20 additions & 0 deletions configure.ac
Expand Up @@ -35,6 +35,8 @@ AC_SUBST(PLATFORM)

AX_CHECK_ZLIB([], [echo "recommended zlib not found: ugrep-indexer option -z is disabled"])

if test -n "${zlib_places}"; then

AX_CHECK_BZ2LIB([], [echo "recommended libbz2 not found: ugrep-indexer option -z cannot index .bz and .bz2 files"])

AX_CHECK_LZMALIB([], [echo "recommended liblzma not found: ugrep-indexer option -z cannot index .lzma and .xz files"])
Expand All @@ -45,6 +47,22 @@ AX_CHECK_ZSTDLIB([], [echo "optional libzstd not found: install if you want ugre

AX_CHECK_BROTLILIB([], [echo "optional brotli library not found: install if you want ugrep-indexer option -z to index .br files"])

AC_ARG_ENABLE(7zip,
[AS_HELP_STRING([--disable-7zip],
[to disable 7zip and no longer index .7z files])],
[with_no_7zip="yes"],
[with_no_7zip="no"])
AC_MSG_CHECKING(for --disable-7zip)
if test "x$with_no_7zip" = "xno"; then
AC_MSG_RESULT(no)
CPPFLAGS="$CPPFLAGS -I../lzma/C"
LDFLAGS="$LDFLAGS -L../lzma/C"
LIBS="-lviiz $LIBS"
else
EXTRA_CFLAGS="-DWITH_NO_7ZIP ${EXTRA_CFLAGS}"
AC_MSG_RESULT(yes)
fi

AC_ARG_WITH(bzip3,
[AS_HELP_STRING([--with-bzip3],
[to enable bzip3 library to decompress .bz3 files])],
Expand All @@ -57,6 +75,8 @@ if test "x$with_bzip3_library" != "x"; then
AX_CHECK_BZIP3LIB([], [echo "optional libbzip3 not found: install if you want ugrep-indexer option -z to index .bz3 files"])
fi

fi

AC_SUBST([PTHREAD_CFLAGS], [""])
AC_SUBST([PTHREAD_LIBS], ["-lpthread"])

Expand Down
117 changes: 117 additions & 0 deletions lzma/7zls.c
@@ -0,0 +1,117 @@
/******************************************************************************\
* Copyright (c) 2023, Robert van Engelen, Genivia Inc. All rights reserved. *
* *
* Redistribution and use in source and binary forms, with or without *
* modification, are permitted provided that the following conditions are met: *
* *
* (1) Redistributions of source code must retain the above copyright notice, *
* this list of conditions and the following disclaimer. *
* *
* (2) Redistributions in binary form must reproduce the above copyright *
* notice, this list of conditions and the following disclaimer in the *
* documentation and/or other materials provided with the distribution. *
* *
* (3) The name of the author may not be used to endorse or promote products *
* derived from this software without specific prior written permission. *
* *
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED *
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF *
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO *
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, *
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; *
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, *
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR *
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF *
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
\******************************************************************************/

/**
@file 7zls.c
@brief list 7zip archive contents to test and use the new viizip API
@author Robert van Engelen - engelen@genivia.com
@copyright (c) 2023-2023, Robert van Engelen, Genivia Inc. All rights reserved.
@copyright (c) BSD-3 License - see LICENSE.txt
*/

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <limits.h>

#include "C/viizip.h"

/* 7zip archive part pathname max length if limits.h doesn't define it */
#ifndef PATH_MAX
#define PATH_MAX 4096
#endif

int main(int argc, char **argv)
{
struct viizip *viizip;
FILE *file;

if (argc < 2)
exit(EXIT_FAILURE);

file = fopen(argv[1], "rb");
if (file == NULL)
{
perror("cannot open file");
exit(EXIT_FAILURE);
}

viizip = viinew(file);
if (viizip == NULL)
{
fprintf(stderr, "viinew() failed\n");
exit(EXIT_FAILURE);
}

printf("%zu entries:\n", viinum(viizip));

while (1)
{
unsigned char buf[65536];
char name[PATH_MAX];
size_t len;
time_t mtime;
uint64_t usize;
char *ct = "??? ??? ?? ??:??\0?? ????";
int res = viiget(viizip, name, PATH_MAX, &mtime, &usize);
if (res < 0)
{
fprintf(stderr, "viiget() failed\n");
exit(EXIT_FAILURE);
}

/* no more entries? */
if (res != 0)
break;

len = strlen(name);
if (len > 0 && name[len - 1] != '/')
printf("%12llu", usize);
else
printf("%12s", "");
ct = ctime(&mtime); /* note: not MT safe */
if (ct != NULL)
ct[19] = ct[24] = '\0';
printf(" %s %s %s\n", ct + 20, ct + 4, name);

/* uncomment this code to test incremental decompression into buf[] with viidec()
{
ssize_t num;
while ((num = viidec(viizip, buf, sizeof(buf))) > 0)
usize -= num;
if (usize != 0)
fprintf(stderr, "viidec() failed\n");
}
*/
}

viifree(viizip);
fclose(file);
exit(EXIT_SUCCESS);
}

0 comments on commit 4e03c78

Please sign in to comment.