- Use getprogname() instead of __progname
- Allow disabling bzip2 support with WITHOUT_BZIP2 - Fix handling patterns that start with a dot - Remove superfluous semicolon Approved by: delphij (mentor)
This commit is contained in:
parent
6aa1145c84
commit
afbbd357de
@ -26,9 +26,6 @@ LINKS= ${BINDIR}/grep ${BINDIR}/egrep \
|
||||
${BINDIR}/grep ${BINDIR}/zgrep \
|
||||
${BINDIR}/grep ${BINDIR}/zegrep \
|
||||
${BINDIR}/grep ${BINDIR}/zfgrep \
|
||||
${BINDIR}/grep ${BINDIR}/bzgrep \
|
||||
${BINDIR}/grep ${BINDIR}/bzegrep \
|
||||
${BINDIR}/grep ${BINDIR}/bzfgrep \
|
||||
${BINDIR}/grep ${BINDIR}/xzgrep \
|
||||
${BINDIR}/grep ${BINDIR}/xzegrep \
|
||||
${BINDIR}/grep ${BINDIR}/xzfgrep \
|
||||
@ -41,9 +38,6 @@ MLINKS= grep.1 egrep.1 \
|
||||
grep.1 zgrep.1 \
|
||||
grep.1 zegrep.1 \
|
||||
grep.1 zfgrep.1 \
|
||||
grep.1 bzgrep.1 \
|
||||
grep.1 bzegrep.1 \
|
||||
grep.1 bzfgrep.1 \
|
||||
grep.1 xzgrep.1 \
|
||||
grep.1 xzegrep.1 \
|
||||
grep.1 xzfgrep.1 \
|
||||
@ -52,8 +46,22 @@ MLINKS= grep.1 egrep.1 \
|
||||
grep.1 lzfgrep.1
|
||||
.endif
|
||||
|
||||
LDADD= -lz -lbz2 -llzma
|
||||
DPADD= ${LIBZ} ${LIBBZ2} ${LIBLZMA}
|
||||
LDADD= -lz -llzma
|
||||
DPADD= ${LIBZ} ${LIBLZMA}
|
||||
|
||||
.if !defined(WITHOUT_BZIP2)
|
||||
LDADD+= -lbz2
|
||||
DPADD+= ${LIBBZ2}
|
||||
|
||||
LINKS+= ${BINDIR}/grep ${BINDIR}/bzgrep \
|
||||
${BINDIR}/grep ${BINDIR}/bzegrep \
|
||||
${BINDIR}/grep ${BINDIR}/bzfgrep
|
||||
MLINKS+= grep.1 bzgrep.1 \
|
||||
grep.1 bzegrep.1 \
|
||||
grep.1 bzfgrep.1
|
||||
.else
|
||||
CFLAGS+= -DWITHOUT_BZIP2
|
||||
.endif
|
||||
|
||||
.if !defined(WITHOUT_GNU_COMPAT)
|
||||
CFLAGS+= -I/usr/include/gnu
|
||||
|
@ -38,7 +38,6 @@ __FBSDID("$FreeBSD$");
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <bzlib.h>
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
@ -51,14 +50,20 @@ __FBSDID("$FreeBSD$");
|
||||
#include <wctype.h>
|
||||
#include <zlib.h>
|
||||
|
||||
#ifndef WITHOUT_BZIP2
|
||||
#include <bzlib.h>
|
||||
#endif
|
||||
|
||||
#include "grep.h"
|
||||
|
||||
#define MAXBUFSIZ (32 * 1024)
|
||||
#define LNBUFBUMP 80
|
||||
|
||||
static gzFile gzbufdesc;
|
||||
static BZFILE* bzbufdesc;
|
||||
static lzma_stream lstrm = LZMA_STREAM_INIT;
|
||||
#ifndef WITHOUT_BZIP2
|
||||
static BZFILE* bzbufdesc;
|
||||
#endif
|
||||
|
||||
static unsigned char *buffer;
|
||||
static unsigned char *bufpos;
|
||||
@ -72,7 +77,6 @@ static inline int
|
||||
grep_refill(struct file *f)
|
||||
{
|
||||
ssize_t nr;
|
||||
int bzerr;
|
||||
|
||||
if (filebehave == FILE_MMAP)
|
||||
return (0);
|
||||
@ -80,9 +84,12 @@ grep_refill(struct file *f)
|
||||
bufpos = buffer;
|
||||
bufrem = 0;
|
||||
|
||||
if (filebehave == FILE_GZIP)
|
||||
if (filebehave == FILE_GZIP) {
|
||||
nr = gzread(gzbufdesc, buffer, MAXBUFSIZ);
|
||||
else if (filebehave == FILE_BZIP && bzbufdesc != NULL) {
|
||||
#ifndef WITHOUT_BZIP2
|
||||
} else if (filebehave == FILE_BZIP && bzbufdesc != NULL) {
|
||||
int bzerr;
|
||||
|
||||
nr = BZ2_bzRead(&bzerr, bzbufdesc, buffer, MAXBUFSIZ);
|
||||
switch (bzerr) {
|
||||
case BZ_OK:
|
||||
@ -108,6 +115,7 @@ grep_refill(struct file *f)
|
||||
/* Make sure we exit with an error */
|
||||
nr = -1;
|
||||
}
|
||||
#endif
|
||||
} else if ((filebehave == FILE_XZ) || (filebehave == FILE_LZMA)) {
|
||||
lzma_action action = LZMA_RUN;
|
||||
uint8_t in_buf[MAXBUFSIZ];
|
||||
@ -271,9 +279,11 @@ grep_open(const char *path)
|
||||
(gzbufdesc = gzdopen(f->fd, "r")) == NULL)
|
||||
goto error2;
|
||||
|
||||
#ifndef WITHOUT_BZIP2
|
||||
if (filebehave == FILE_BZIP &&
|
||||
(bzbufdesc = BZ2_bzdopen(f->fd, "r")) == NULL)
|
||||
goto error2;
|
||||
#endif
|
||||
|
||||
/* Fill read buffer, also catches errors early */
|
||||
if (bufrem == 0 && grep_refill(f) != 0)
|
||||
|
@ -150,15 +150,13 @@ bool prev; /* flag whether or not the previous line matched */
|
||||
int tail; /* lines left to print */
|
||||
bool notfound; /* file not found */
|
||||
|
||||
extern char *__progname;
|
||||
|
||||
/*
|
||||
* Prints usage information and returns 2.
|
||||
*/
|
||||
static void
|
||||
usage(void)
|
||||
{
|
||||
fprintf(stderr, getstr(4), __progname);
|
||||
fprintf(stderr, getstr(4), getprogname());
|
||||
fprintf(stderr, "%s", getstr(5));
|
||||
fprintf(stderr, "%s", getstr(5));
|
||||
fprintf(stderr, "%s", getstr(6));
|
||||
@ -332,7 +330,8 @@ int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
char **aargv, **eargv, *eopts;
|
||||
char *pn, *ep;
|
||||
char *ep;
|
||||
const char *pn;
|
||||
unsigned long long l;
|
||||
unsigned int aargc, eargc, i;
|
||||
int c, lastc, needpattern, newarg, prevoptind;
|
||||
@ -346,7 +345,7 @@ main(int argc, char *argv[])
|
||||
/* Check what is the program name of the binary. In this
|
||||
way we can have all the funcionalities in one binary
|
||||
without the need of scripting and using ugly hacks. */
|
||||
pn = __progname;
|
||||
pn = getprogname();
|
||||
if (pn[0] == 'b' && pn[1] == 'z') {
|
||||
filebehave = FILE_BZIP;
|
||||
pn += 2;
|
||||
@ -508,6 +507,10 @@ main(int argc, char *argv[])
|
||||
cflags |= REG_ICASE;
|
||||
break;
|
||||
case 'J':
|
||||
#ifdef WITHOUT_BZIP2
|
||||
errno = EOPNOTSUPP;
|
||||
err(2, "bzip2 support was disabled at compile-time");
|
||||
#endif
|
||||
filebehave = FILE_BZIP;
|
||||
break;
|
||||
case 'L':
|
||||
@ -568,7 +571,7 @@ main(int argc, char *argv[])
|
||||
filebehave = FILE_MMAP;
|
||||
break;
|
||||
case 'V':
|
||||
printf(getstr(9), __progname, VERSION);
|
||||
printf(getstr(9), getprogname(), VERSION);
|
||||
exit(0);
|
||||
case 'v':
|
||||
vflag = true;
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $FreeBSD$ */
|
||||
/* $FreeBSD$ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1999 James Howard and Dag-Erling Coïdan Smørgrav
|
||||
@ -548,7 +548,7 @@ tre_compile_fast(fastmatch_t *fg, const tre_char_t *pat, size_t n,
|
||||
int cflags)
|
||||
{
|
||||
tre_char_t *tmp;
|
||||
size_t pos = 0, hasdot = 0, whasdot = 0;;
|
||||
size_t pos = 0, hasdot = 0, whasdot = 0;
|
||||
ssize_t firstdot = -1, wfirstdot = -1;
|
||||
bool escaped = false;
|
||||
bool *_escmap = NULL;
|
||||
@ -694,7 +694,7 @@ tre_compile_fast(fastmatch_t *fg, const tre_char_t *pat, size_t n,
|
||||
return REG_BADPAT;
|
||||
}
|
||||
|
||||
fg->hasdot = whasdot;
|
||||
fg->hasdot = wfirstdot > -1;
|
||||
|
||||
/*
|
||||
* The pattern has been processed and copied to tmp as a literal string
|
||||
|
Loading…
Reference in New Issue
Block a user