rpm  5.4.10
Macros | Typedefs | Enumerations | Functions | Variables
rpmgrep.c File Reference
#include "system.h"
#include <rpmio_internal.h>
#include <rpmdir.h>
#include <poptIO.h>
#include "debug.h"
Include dependency graph for rpmgrep.c:

Go to the source code of this file.

Macros

#define _MIRE_INTERNAL
#define FALSE   ((BOOL)0)
#define TRUE   ((BOOL)1)
#define MAX_PATTERN_COUNT   100
#define MBUFTHIRD   8192
#define _GFB(n)   ((1U << (n)) | 0x40000000)
#define GF_ISSET(_FLAG)   ((grepFlags & ((GREP_FLAGS_##_FLAG) & ~0x40000000)) != GREP_FLAGS_NONE)

Typedefs

typedef unsigned BOOL

Enumerations

enum  dee_e { dee_READ = 1, dee_SKIP, dee_RECURSE }
 Actions for the -d option. More...
enum  DEE_e { DEE_READ = 1, DEE_SKIP }
 Actions for the -D option. More...
enum  FN_e {
  FN_NONE, FN_DEFAULT, FN_ONLY, FN_NOMATCH_ONLY,
  FN_FORCE
}
 Values for the "filenames" variable, which specifies options for file name output. More...
enum  grepFlags_e {
  GREP_FLAGS_NONE = 0, GREP_FLAGS_WORD_MATCH = ((1U << ( 0 )) | 0x40000000), GREP_FLAGS_LINE_MATCH = ((1U << ( 1 )) | 0x40000000), GREP_FLAGS_FIXED_STRINGS = ((1U << ( 2 )) | 0x40000000),
  GREP_FLAGS_COUNT = ((1U << ( 3 )) | 0x40000000), GREP_FLAGS_COLOR = ((1U << ( 4 )) | 0x40000000), GREP_FLAGS_FOFFSETS = ((1U << ( 5 )) | 0x40000000), GREP_FLAGS_LOFFSETS = ((1U << ( 6 )) | 0x40000000),
  GREP_FLAGS_LNUMBER = ((1U << ( 7 )) | 0x40000000), GREP_FLAGS_MULTILINE = ((1U << ( 8 )) | 0x40000000), GREP_FLAGS_ONLY_MATCHING = ((1U << ( 9 )) | 0x40000000), GREP_FLAGS_INVERT = ((1U << ( 10 )) | 0x40000000),
  GREP_FLAGS_QUIET = ((1U << ( 11 )) | 0x40000000), GREP_FLAGS_SILENT = ((1U << ( 12 )) | 0x40000000), GREP_FLAGS_UTF8 = ((1U << ( 13 )) | 0x40000000), GREP_FLAGS_CASELESS = ((1U << ( 14 )) | 0x40000000)
}

Functions

static void fwrite_check (const void *ptr, size_t size, size_t nmemb, FILE *stream)
static const char * end_of_line (const char *p, const char *endptr, size_t *lenptr)
static const char * previous_line (const char *p, const char *startptr)
static void do_after_lines (int lastmatchnumber, const char *lastmatchrestart, const char *endptr, const char *printname)
static int pcregrep (FD_t fd, const char *printname)
static int chkSuffix (const char *fn, const char *suffix)
 Check file name for a suffix.
static int grep_or_recurse (const char *pathname, BOOL dir_recurse, BOOL only_one_at_top)
static BOOL compile_single_pattern (const char *pattern, const char *filename, int count)
static BOOL compile_pattern (const char *pattern, const char *filename, int count)
static int mireLoadPatternFiles (ARGV_t files)
 Load patterns from files.
static void grepArgCallback (poptContext con, enum poptCallbackReason reason, const struct poptOption *opt, const char *arg, void *data)
int main (int argc, char **argv)

Variables

static const char * newline = NULL
static const char * color_string = NULL
static ARGV_t pattern_filenames = NULL
static const char * stdin_name = NULL
static const char * locale = NULL
static ARGV_t patterns = NULL
static miRE pattern_list = NULL
static int pattern_count = 0
static ARGV_t exclude_patterns = NULL
static miRE excludeMire = NULL
static int nexcludes = 0
static ARGV_t include_patterns = NULL
static miRE includeMire = NULL
static int nincludes = 0
static int after_context = 0
static int before_context = 0
static int both_context = 0
static enum dee_e dee_action = dee_READ
static enum DEE_e DEE_action = DEE_READ
static int error_count = 0
static enum FN_e filenames = FN_DEFAULT
static enum grepFlags_e grepFlags = GREP_FLAGS_NONE
static rpmMireMode grepMode = RPMMIRE_REGEX
static struct rpmop_s grep_totalops
static struct rpmop_s grep_readops
static const char * prefix []
 Tables for prefixing and suffixing patterns, according to the -w, -x, and -F options.
static const char * suffix []
static const unsigned utf8_table3 []
 UTF-8 tables - used only when the newline setting is "any".
static const char utf8_table4 []
static struct poptOption optionsTable []

Macro Definition Documentation

#define _GFB (   n)    ((1U << (n)) | 0x40000000)

Definition at line 136 of file rpmgrep.c.

#define _MIRE_INTERNAL

Definition at line 42 of file rpmgrep.c.

#define FALSE   ((BOOL)0)

Definition at line 52 of file rpmgrep.c.

Referenced by compile_pattern(), compile_single_pattern(), grep_or_recurse(), and pcregrep().

#define GF_ISSET (   _FLAG)    ((grepFlags & ((GREP_FLAGS_##_FLAG) & ~0x40000000)) != GREP_FLAGS_NONE)
#define MAX_PATTERN_COUNT   100

Definition at line 55 of file rpmgrep.c.

Referenced by compile_single_pattern(), and main().

#define MBUFTHIRD   8192

Definition at line 60 of file rpmgrep.c.

Referenced by compile_pattern(), compile_single_pattern(), mireLoadPatternFiles(), and pcregrep().

#define TRUE   ((BOOL)1)

Definition at line 53 of file rpmgrep.c.

Referenced by compile_single_pattern(), pcregrep(), and rpmperlRun().

Typedef Documentation

typedef unsigned BOOL

Definition at line 51 of file rpmgrep.c.

Enumeration Type Documentation

enum dee_e

Actions for the -d option.

Enumerator:
dee_READ 
dee_SKIP 
dee_RECURSE 

Definition at line 115 of file rpmgrep.c.

enum DEE_e

Actions for the -D option.

Enumerator:
DEE_READ 
DEE_SKIP 

Definition at line 120 of file rpmgrep.c.

enum FN_e

Values for the "filenames" variable, which specifies options for file name output.

The order is important; it is assumed that a file name is wanted for all values greater than FN_DEFAULT.

Enumerator:
FN_NONE 
FN_DEFAULT 
FN_ONLY 
FN_NOMATCH_ONLY 
FN_FORCE 

Definition at line 132 of file rpmgrep.c.

Enumerator:
GREP_FLAGS_NONE 
GREP_FLAGS_WORD_MATCH 

-w,–word-regex ...

GREP_FLAGS_LINE_MATCH 

-x,–line-regex ...

GREP_FLAGS_FIXED_STRINGS 

-F,–fixed-strings ...

GREP_FLAGS_COUNT 

-c,–count ...

GREP_FLAGS_COLOR 

–color ...

GREP_FLAGS_FOFFSETS 

–file-offsets ...

GREP_FLAGS_LOFFSETS 

–line-offsets ...

GREP_FLAGS_LNUMBER 

-n,–line-number ...

GREP_FLAGS_MULTILINE 

-M,–multiline ...

GREP_FLAGS_ONLY_MATCHING 

-o,–only-matching ...

GREP_FLAGS_INVERT 

-v,–invert ...

GREP_FLAGS_QUIET 

-q,–quiet ...

GREP_FLAGS_SILENT 

-s,–no-messages ...

GREP_FLAGS_UTF8 

-u,–utf8 ...

GREP_FLAGS_CASELESS 

-i,–ignore-case ...

Definition at line 139 of file rpmgrep.c.

Function Documentation

static int chkSuffix ( const char *  fn,
const char *  suffix 
)
static

Check file name for a suffix.

Parameters
fnfile name
suffixsuffix
Returns
1 if file name ends with suffix

Definition at line 909 of file rpmgrep.c.

Referenced by grep_or_recurse().

static BOOL compile_pattern ( const char *  pattern,
const char *  filename,
int  count 
)
static

Definition at line 1128 of file rpmgrep.c.

References compile_single_pattern(), end_of_line(), FALSE, GF_ISSET, and MBUFTHIRD.

Referenced by main(), and mireLoadPatternFiles().

static BOOL compile_single_pattern ( const char *  pattern,
const char *  filename,
int  count 
)
static
static void do_after_lines ( int  lastmatchnumber,
const char *  lastmatchrestart,
const char *  endptr,
const char *  printname 
)
static

Definition at line 472 of file rpmgrep.c.

References after_context, rpmop_s::count, end_of_line(), fwrite_check(), and GF_ISSET.

Referenced by pcregrep().

static const char* end_of_line ( const char *  p,
const char *  endptr,
size_t *  lenptr 
)
static

Definition at line 222 of file rpmgrep.c.

References _mireEL, EL_ANY, EL_ANYCRLF, EL_CR, EL_CRLF, EL_LF, GF_ISSET, utf8_table3, and utf8_table4.

Referenced by compile_pattern(), do_after_lines(), and pcregrep().

static void fwrite_check ( const void *  ptr,
size_t  size,
size_t  nmemb,
FILE *  stream 
)
inlinestatic

Definition at line 63 of file rpmgrep.c.

Referenced by do_after_lines(), and pcregrep().

static int grep_or_recurse ( const char *  pathname,
BOOL  dir_recurse,
BOOL  only_one_at_top 
)
static
static void grepArgCallback ( poptContext  con,
enum poptCallbackReason  reason,
const struct poptOption *  opt,
const char *  arg,
void *  data 
)
static
int main ( int  argc,
char **  argv 
)
static int mireLoadPatternFiles ( ARGV_t  files)
static

Load patterns from files.

Parameters
filesarray of file names
Returns
0 on success

Definition at line 1154 of file rpmgrep.c.

References _, __progname, compile_pattern(), Fclose(), fdGetFILE, fdstat_op(), FDSTAT_READ, Ferror(), Fopen(), Fstrerror(), grep_readops, MBUFTHIRD, rpmswAdd(), stdin_name, and xisspace().

Referenced by main().

static int pcregrep ( FD_t  fd,
const char *  printname 
)
static
static const char* previous_line ( const char *  p,
const char *  startptr 
)
static

Definition at line 372 of file rpmgrep.c.

References _mireEL, EL_ANY, EL_ANYCRLF, EL_CR, EL_CRLF, EL_LF, GF_ISSET, utf8_table3, and utf8_table4.

Referenced by pcregrep().

Variable Documentation

int after_context = 0
static

Definition at line 108 of file rpmgrep.c.

Referenced by do_after_lines(), main(), and pcregrep().

int before_context = 0
static

Definition at line 110 of file rpmgrep.c.

Referenced by main(), and pcregrep().

int both_context = 0
static

Definition at line 112 of file rpmgrep.c.

Referenced by main().

const char* color_string = NULL
static

Definition at line 77 of file rpmgrep.c.

Referenced by grepArgCallback(), main(), and pcregrep().

enum dee_e dee_action = dee_READ
static

Definition at line 117 of file rpmgrep.c.

Referenced by grep_or_recurse(), grepArgCallback(), and main().

enum DEE_e DEE_action = DEE_READ
static

Definition at line 122 of file rpmgrep.c.

Referenced by grep_or_recurse(), and grepArgCallback().

int error_count = 0
static

Definition at line 125 of file rpmgrep.c.

Referenced by pcregrep().

ARGV_t exclude_patterns = NULL
static

Definition at line 94 of file rpmgrep.c.

Referenced by main().

miRE excludeMire = NULL
static

Definition at line 96 of file rpmgrep.c.

Referenced by grep_or_recurse(), and main().

enum FN_e filenames = FN_DEFAULT
static

Definition at line 134 of file rpmgrep.c.

Referenced by grep_or_recurse(), and pcregrep().

struct rpmop_s grep_readops
static

Definition at line 174 of file rpmgrep.c.

Referenced by grep_or_recurse(), main(), and mireLoadPatternFiles().

struct rpmop_s grep_totalops
static

Definition at line 172 of file rpmgrep.c.

Referenced by main().

enum grepFlags_e grepFlags = GREP_FLAGS_NONE
static

Definition at line 162 of file rpmgrep.c.

Referenced by compile_single_pattern(), grepArgCallback(), and main().

rpmMireMode grepMode = RPMMIRE_REGEX
static

Definition at line 168 of file rpmgrep.c.

Referenced by compile_single_pattern(), and main().

ARGV_t include_patterns = NULL
static

Definition at line 101 of file rpmgrep.c.

Referenced by main().

miRE includeMire = NULL
static

Definition at line 103 of file rpmgrep.c.

Referenced by grep_or_recurse(), and main().

const char* locale = NULL
static

Definition at line 84 of file rpmgrep.c.

Referenced by main().

const char* newline = NULL
static

Definition at line 74 of file rpmgrep.c.

Referenced by main().

int nexcludes = 0
static

Definition at line 98 of file rpmgrep.c.

Referenced by grep_or_recurse(), and main().

int nincludes = 0
static

Definition at line 105 of file rpmgrep.c.

Referenced by grep_or_recurse(), and main().

struct poptOption optionsTable[]
static

Definition at line 1293 of file rpmgrep.c.

Referenced by main().

int pattern_count = 0
static

Definition at line 91 of file rpmgrep.c.

Referenced by compile_single_pattern(), main(), and pcregrep().

ARGV_t pattern_filenames = NULL
static

Definition at line 79 of file rpmgrep.c.

Referenced by main().

miRE pattern_list = NULL
static

Definition at line 89 of file rpmgrep.c.

Referenced by compile_single_pattern(), main(), and pcregrep().

ARGV_t patterns = NULL
static

Definition at line 87 of file rpmgrep.c.

Referenced by cacheWalkPathFilter(), freeGlobs(), initGlobs(), and main().

const char* prefix[]
static
Initial value:
{
"", "\\b", "^(?:", "^(?:", "\\Q", "\\b\\Q", "^(?:\\Q", "^(?:\\Q"
}

Tables for prefixing and suffixing patterns, according to the -w, -x, and -F options.

These set the 1, 2, and 4 bits in grepFlags, respectively. Note that the combination of -w and -x has the same effect as -x on its own, so we can treat them as the same.

Definition at line 183 of file rpmgrep.c.

Referenced by compile_single_pattern(), rpmbcSetRSA(), and showQueryPackage().

const char* stdin_name = NULL
static

Definition at line 81 of file rpmgrep.c.

Referenced by main(), and mireLoadPatternFiles().

const char* suffix[]
static
Initial value:
{
"", "\\b", ")$", ")$", "\\E", "\\E\\b", "\\E)$", "\\E)$"
}

Definition at line 188 of file rpmgrep.c.

Referenced by compile_single_pattern().

const unsigned utf8_table3[]
static
Initial value:
{
0xff, 0x1f, 0x0f, 0x07, 0x03, 0x01
}

UTF-8 tables - used only when the newline setting is "any".

Definition at line 194 of file rpmgrep.c.

Referenced by end_of_line(), and previous_line().

const char utf8_table4[]
static
Initial value:
{
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
3,3,3,3,3,3,3,3,4,4,4,4,5,5,5,5
}

Definition at line 200 of file rpmgrep.c.

Referenced by end_of_line(), and previous_line().