Skip to content

Commit

Permalink
released 4.5.2
Browse files Browse the repository at this point in the history
- PR #344
- PR #343
- fix 7zip search on 32 bit systems when option -M (or -t setting -M) is used
  • Loading branch information
genivia-inc committed Jan 10, 2024
1 parent 66c3879 commit e42a5ce
Show file tree
Hide file tree
Showing 18 changed files with 109 additions and 84 deletions.
2 changes: 0 additions & 2 deletions Makefile.am
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
SUBDIRS = lib

if ENABLE_7ZIP
SUBDIRS += lzma/C
endif

SUBDIRS += src

man1_MANS = man/ugrep.1
Expand Down
5 changes: 3 additions & 2 deletions Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ PRE_UNINSTALL = :
POST_UNINSTALL = :
build_triplet = @build@
host_triplet = @host@
@ENABLE_7ZIP_TRUE@am__append_1 = lzma/C
subdir = .
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/m4/ax_boost_regex.m4 \
Expand Down Expand Up @@ -209,7 +210,7 @@ am__define_uniq_tagged_files = \
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | $(am__uniquify_input)`
DIST_SUBDIRS = $(SUBDIRS)
DIST_SUBDIRS = lib lzma/C src
am__DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/config.h.in \
INSTALL.md README.md ar-lib compile config.guess config.sub \
depcomp install-sh missing
Expand Down Expand Up @@ -382,7 +383,7 @@ target_alias = @target_alias@
top_build_prefix = @top_build_prefix@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
SUBDIRS = lib lzma/C src
SUBDIRS = lib $(am__append_1) src
man1_MANS = man/ugrep.1
EXTRA_DIST = README.md LICENSE.txt CONTRIBUTING.md CODE_OF_CONDUCT.md
UGREP = $(shell pwd)/$(top_builddir)/bin/ugrep$(EXEEXT)
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Overview

### Commands

- `ug` is for interactive use with a .ugrep configuration file with your preferences located in the working directory or home directory, `ug+` also searches pdfs, documents, e-books, image metadata
- `ug` is for interactive use, which loads an optional .ugrep configuration file with your preferences located in the working directory or home directory, `ug+` also searches pdfs, documents, e-books, image metadata

- `ugrep` for batch use like GNU grep without a .ugrep configuration file, `ugrep+` also searches pdfs, documents, e-books, image metadata

Expand Down Expand Up @@ -5353,7 +5353,7 @@ in markdown:



ugrep 4.5.1 January 6, 2024 UGREP(1)
ugrep 4.5.2 January 9, 2024 UGREP(1)

🔝 [Back to table of contents](#toc)

Expand Down
Binary file modified bin/win32/ug.exe
Binary file not shown.
Binary file modified bin/win32/ugrep.exe
Binary file not shown.
Binary file modified bin/win64/ug.exe
Binary file not shown.
Binary file modified bin/win64/ugrep.exe
Binary file not shown.
3 changes: 3 additions & 0 deletions config.h.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
/* config.h.in. Generated from configure.ac by autoheader. */

/* Define if built with 7ZIP support */
#undef HAVE_7ZIP

/* define if the Boost::Regex library is available */
#undef HAVE_BOOST_REGEX

Expand Down
17 changes: 17 additions & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,8 @@ ENABLE_BASH_COMPLETION_TRUE
BASH_COMPLETION_DIR
BASH_COMPLETION_LIBS
BASH_COMPLETION_CFLAGS
ENABLE_7ZIP_FALSE
ENABLE_7ZIP_TRUE
PLATFORM
PKG_CONFIG_LIBDIR
PKG_CONFIG_PATH
Expand Down Expand Up @@ -8927,13 +8929,24 @@ printf "%s\n" "no" >&6; }
CPPFLAGS="$CPPFLAGS -I../lzma/C"
LDFLAGS="$LDFLAGS -L../lzma/C"
LIBS="-lviiz $LIBS"

printf "%s\n" "#define HAVE_7ZIP 1" >>confdefs.h

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

fi
if test "x$with_7zip" = "xyes"; then
ENABLE_7ZIP_TRUE=
ENABLE_7ZIP_FALSE='#'
else
ENABLE_7ZIP_TRUE='#'
ENABLE_7ZIP_FALSE=
fi



# Check whether --with-bash-completion-dir was given.
Expand Down Expand Up @@ -9815,6 +9828,10 @@ if test -z "${am__fastdepCC_TRUE}" && test -z "${am__fastdepCC_FALSE}"; then
as_fn_error $? "conditional \"am__fastdepCC\" was never defined.
Usually this means the macro was only invoked conditionally." "$LINENO" 5
fi
if test -z "${ENABLE_7ZIP_TRUE}" && test -z "${ENABLE_7ZIP_FALSE}"; then
as_fn_error $? "conditional \"ENABLE_7ZIP\" was never defined.
Usually this means the macro was only invoked conditionally." "$LINENO" 5
fi
if test -z "${ENABLE_BASH_COMPLETION_TRUE}" && test -z "${ENABLE_BASH_COMPLETION_FALSE}"; then
as_fn_error $? "conditional \"ENABLE_BASH_COMPLETION\" was never defined.
Usually this means the macro was only invoked conditionally." "$LINENO" 5
Expand Down
5 changes: 5 additions & 0 deletions lzma/7zls.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
@copyright (c) BSD-3 License - see LICENSE.txt
*/

/* to build and run 7zls:
cc -o 7zls 7zls.c C/libviiz.a
./7zls ../tests/archive.7z
*/

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
Expand Down
5 changes: 3 additions & 2 deletions lzma/C/7zCrc.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,9 @@ UInt32 Z7_FASTCALL CrcUpdateT1(UInt32 v, const void *data, size_t size, const UI
#endif
#endif
#endif
#elif (defined(__clang__) && (__clang_major__ >= 3)) \
|| (defined(__GNUC__) && (__GNUC__ > 4))
#elif ( (defined(__clang__) && (__clang_major__ >= 3)) || \
(defined(__GNUC__) && (__GNUC__ > 4) ) ) && \
(__ARM_ARCH >= 8)
#if !defined(__ARM_FEATURE_CRC32)
#define __ARM_FEATURE_CRC32 1
#if defined(__clang__)
Expand Down
3 changes: 3 additions & 0 deletions lzma/C/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ LZMA SDK is placed in the public domain.

LZMA SDK by Igor Pavlov.

Updated to apply YOKOTA Hiroshi's patches:
https://salsa.debian.org/debian/7zip/-/blob/master/debian/patches/0002-Disable-hardware-acceleration-support-on-armel.patch?ref_type=heads

Included in this directory is a new C API to simplify decompression:

- viizip.h declarations, see below (hides implementation details)
Expand Down
5 changes: 3 additions & 2 deletions lzma/C/viizip.c
Original file line number Diff line number Diff line change
Expand Up @@ -333,10 +333,11 @@ int viiget(struct viizip *viizip, char *name, size_t max, time_t *mtime, uint64_
return res == SZ_OK ? 0 : -1;
}

/* decompress up to len bytes into buf[], return number of bytes decompressed */
/* decompress up to len bytes into buf[], return number of bytes decompressed or -1 on error */
ssize_t viidec(struct viizip *viizip, unsigned char *buf, size_t len)
{
if (viizip == NULL)
/* if not initialized or not called viiget() then return error */
if (viizip == NULL || viizip->index == 0)
return -1;

switch (viizip->state)
Expand Down
2 changes: 1 addition & 1 deletion man/ugrep.1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.TH UGREP "1" "January 06, 2024" "ugrep 4.5.1" "User Commands"
.TH UGREP "1" "January 09, 2024" "ugrep 4.5.2" "User Commands"
.SH NAME
\fBugrep\fR, \fBug\fR -- file pattern searcher
.SH SYNOPSIS
Expand Down
134 changes: 64 additions & 70 deletions src/ugrep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1873,28 +1873,20 @@ struct Zthread {
if (*basename == '.' && !flag_hidden)
return false;

// -O, -t, and -g (--include and --exclude): check if pathname or basename matches globs, is_selected = false if not
if (!flag_all_exclude.empty() || !flag_all_include.empty())
// exclude files whose basename matches any one of the --exclude globs
for (const auto& glob : flag_all_exclude)
{
// exclude files whose basename matches any one of the --exclude globs
for (const auto& glob : flag_all_exclude)
{
bool ignore_case = &glob < &flag_all_exclude.front() + flag_exclude_iglob_size;
if (!(is_selected = !glob_match(path, basename, glob.c_str(), ignore_case)))
break;
}
bool ignore_case = &glob < &flag_all_exclude.front() + flag_exclude_iglob_size;
if (glob_match(path, basename, glob.c_str(), ignore_case))
return false;
}

// include only if not excluded
if (is_selected)
{
// include files whose basename matches any one of the --include globs
for (const auto& glob : flag_all_include)
{
bool ignore_case = &glob < &flag_all_include.front() + flag_include_iglob_size;
if ((is_selected = glob_match(path, basename, glob.c_str(), ignore_case)))
break;
}
}
// include files whose basename matches any one of the --include globs
for (const auto& glob : flag_all_include)
{
bool ignore_case = &glob < &flag_all_include.front() + flag_include_iglob_size;
if ((is_selected = glob_match(path, basename, glob.c_str(), ignore_case)))
break;
}

// -M: check magic bytes, requires sufficiently large len of buf[] to match patterns, which is fine when Z_BUF_LEN is large e.g. 64K to contain all magic bytes
Expand Down Expand Up @@ -8806,10 +8798,11 @@ Grep::Type Grep::select(size_t level, const char *pathname, const char *basename
if (flag_min_depth > 0 && level <= flag_min_depth)
return Type::SKIP;

bool ok = true;

if (!flag_all_exclude.empty())
{
// exclude files whose pathname matches any one of the --exclude globs unless negated with !
bool ok = true;
for (const auto& glob : flag_all_exclude)
{
bool ignore_case = &glob < &flag_all_exclude.front() + flag_exclude_iglob_size;
Expand All @@ -8827,8 +8820,29 @@ Grep::Type Grep::select(size_t level, const char *pathname, const char *basename
return Type::SKIP;
}

if (!flag_all_include.empty())
{
// include files whose pathname matches any one of the --include globs unless negated with !
ok = false;
for (const auto& glob : flag_all_include)
{
bool ignore_case = &glob < &flag_all_include.front() + flag_include_iglob_size;
if (glob.front() == '!')
{
if (ok && glob_match(pathname, basename, glob.c_str() + 1), ignore_case)
ok = false;
}
else if (!ok && glob_match(pathname, basename, glob.c_str(), ignore_case))
{
ok = true;
}
}
if (!ok && flag_file_magic.empty())
return Type::SKIP;
}

// check magic pattern against the file signature, when --file-magic=MAGIC is specified
if (!flag_file_magic.empty())
if (!flag_file_magic.empty() && (flag_all_include.empty() || !ok))
{
FILE *file;

Expand Down Expand Up @@ -8871,29 +8885,7 @@ Grep::Type Grep::select(size_t level, const char *pathname, const char *basename

fclose(file);

if (flag_all_include.empty())
return Type::SKIP;
}

if (!flag_all_include.empty())
{
// include files whose pathname matches any one of the --include globs unless negated with !
bool ok = false;
for (const auto& glob : flag_all_include)
{
bool ignore_case = &glob < &flag_all_include.front() + flag_include_iglob_size;
if (glob.front() == '!')
{
if (ok && glob_match(pathname, basename, glob.c_str() + 1), ignore_case)
ok = false;
}
else if (!ok && glob_match(pathname, basename, glob.c_str(), ignore_case))
{
ok = true;
}
}
if (!ok)
return Type::SKIP;
return Type::SKIP;
}

Stats::score_file();
Expand Down Expand Up @@ -9012,10 +9004,11 @@ Grep::Type Grep::select(size_t level, const char *pathname, const char *basename
if (flag_min_depth > 0 && level <= flag_min_depth)
return Type::SKIP;

bool ok = true;

if (!flag_all_exclude.empty())
{
// exclude files whose pathname matches any one of the --exclude globs unless negated with !
bool ok = true;
for (const auto& glob : flag_all_exclude)
{
bool ignore_case = &glob < &flag_all_exclude.front() + flag_exclude_iglob_size;
Expand All @@ -9033,8 +9026,29 @@ Grep::Type Grep::select(size_t level, const char *pathname, const char *basename
return Type::SKIP;
}

if (!flag_all_include.empty())
{
// include files whose basename matches any one of the --include globs if not negated with !
ok = false;
for (const auto& glob : flag_all_include)
{
bool ignore_case = &glob < &flag_all_include.front() + flag_include_iglob_size;
if (glob.front() == '!')
{
if (ok && glob_match(pathname, basename, glob.c_str() + 1, ignore_case))
ok = false;
}
else if (!ok && glob_match(pathname, basename, glob.c_str(), ignore_case))
{
ok = true;
}
}
if (!ok && flag_file_magic.empty())
return Type::SKIP;
}

// check magic pattern against the file signature, when --file-magic=MAGIC is specified
if (!flag_file_magic.empty())
if (!flag_file_magic.empty() && (flag_all_include.empty() || !ok))
{
FILE *file;

Expand Down Expand Up @@ -9082,29 +9096,7 @@ Grep::Type Grep::select(size_t level, const char *pathname, const char *basename

fclose(file);

if (flag_all_include.empty())
return Type::SKIP;
}

if (!flag_all_include.empty())
{
// include directories whose basename matches any one of the --include-dir globs if not negated with !
bool ok = false;
for (const auto& glob : flag_all_include)
{
bool ignore_case = &glob < &flag_all_include.front() + flag_include_iglob_size;
if (glob.front() == '!')
{
if (ok && glob_match(pathname, basename, glob.c_str() + 1, ignore_case))
ok = false;
}
else if (!ok && glob_match(pathname, basename, glob.c_str(), ignore_case))
{
ok = true;
}
}
if (!ok)
return Type::SKIP;
return Type::SKIP;
}

Stats::score_file();
Expand Down Expand Up @@ -14334,6 +14326,8 @@ void help(const char *what)

if (found == 0)
std::cout << "ugrep --help: nothing appropriate for " << what;
else
std::cout << "\n\nLong options may start with `--no-' to disable, when applicable.";

std::cout << "\n\n";

Expand Down
2 changes: 1 addition & 1 deletion src/ugrep.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
#define UGREP_HPP

// ugrep version
#define UGREP_VERSION "4.5.1"
#define UGREP_VERSION "4.5.2"

// disable mmap because mmap is almost always slower than the file reading speed improvements since 3.0.0
#define WITH_NO_MMAP
Expand Down
4 changes: 2 additions & 2 deletions src/zstream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -538,8 +538,8 @@ class zstreambuf : public std::streambuf {
// read and decompress zip file data into buf[0..len-1], return number of bytes decompressed, 0 for EOF or -1 for error
std::streamsize decompress(unsigned char *buf, size_t len)
{
// if no more data to decompress, then return 0 to indicate EOF
if (zend_)
// if header() was not called or no more data to decompress, then return 0 to indicate EOF
if (znew_ || zend_)
return 0;

std::streamsize num = 0;
Expand Down
2 changes: 2 additions & 0 deletions tests/out/archive-t.7z.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
archive.7z{Hello.bat}:1
archive.7z{Hello.sh}:1

0 comments on commit e42a5ce

Please sign in to comment.