tin  2.4.5
About: TIN is a threaded NNTP and spool based UseNet newsreader.
  Fossies Dox: tin-2.4.5.tar.xz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

pcregrep.c File Reference
#include <ctype.h>
#include <locale.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include "config.h"
#include "pcre.h"
Include dependency graph for pcregrep.c:

Go to the source code of this file.

Data Structures

struct  option_item
 

Macros

#define FALSE   0
 
#define TRUE   1
 
#define VERSION   "4.4 29-Nov-2006"
 
#define MAX_PATTERN_COUNT   100
 
#define MBUFTHIRD   8192
 
#define PO_WORD_MATCH   0x0001
 
#define PO_LINE_MATCH   0x0002
 
#define PO_FIXED_STRINGS   0x0004
 
#define N_COLOUR   (-1)
 
#define N_EXCLUDE   (-2)
 
#define N_HELP   (-3)
 
#define N_INCLUDE   (-4)
 
#define N_LABEL   (-5)
 
#define N_LOCALE   (-6)
 
#define N_NULL   (-7)
 

Typedefs

typedef int BOOL
 
typedef struct option_item option_item
 
typedef void directory_type
 

Enumerations

enum  {
  FN_NONE , FN_DEFAULT , FN_ONLY , FN_NOMATCH_ONLY ,
  FN_FORCE
}
 
enum  { dee_READ , dee_SKIP , dee_RECURSE }
 
enum  { DEE_READ , DEE_SKIP }
 
enum  { EL_LF , EL_CR , EL_CRLF , EL_ANY }
 
enum  {
  OP_NODATA , OP_STRING , OP_OP_STRING , OP_NUMBER ,
  OP_OP_NUMBER , OP_PATLIST
}
 

Functions

int isdirectory (char *filename)
 
directory_typeopendirectory (char *filename)
 
char * readdirectory (directory_type *dir)
 
void closedirectory (directory_type *dir)
 
int isregfile (char *filename)
 
static BOOL is_stdout_tty (void)
 
char * strerror (int n)
 
static char * end_of_line (char *p, char *endptr, int *lenptr)
 
static char * previous_line (char *p, char *startptr)
 
static void do_after_lines (int lastmatchnumber, char *lastmatchrestart, char *endptr, char *printname)
 
static int pcregrep (FILE *in, char *printname)
 
static int grep_or_recurse (char *pathname, BOOL dir_recurse, BOOL only_one_at_top)
 
static int usage (int rc)
 
static void help (void)
 
static int handle_option (int letter, int options)
 
static char * ordin (int n)
 
static BOOL compile_single_pattern (char *pattern, int options, char *filename, int count)
 
static BOOL compile_pattern (char *pattern, int options, char *filename, int count)
 
int main (int argc, char **argv)
 

Variables

static int endlinetype
 
static char * colour_string = (char *)"1;31"
 
static char * colour_option = NULL
 
static char * dee_option = NULL
 
static char * DEE_option = NULL
 
static char * newline = NULL
 
static char * pattern_filename = NULL
 
static char * stdin_name = (char *)"(standard input)"
 
static char * locale = NULL
 
static const unsigned char * pcretables = NULL
 
static int pattern_count = 0
 
static pcre ** pattern_list
 
static pcre_extra ** hints_list
 
static char * include_pattern = NULL
 
static char * exclude_pattern = NULL
 
static pcreinclude_compiled = NULL
 
static pcreexclude_compiled = NULL
 
static int after_context = 0
 
static int before_context = 0
 
static int both_context = 0
 
static int dee_action = dee_READ
 
static int DEE_action = DEE_READ
 
static int error_count = 0
 
static int filenames = FN_DEFAULT
 
static int process_options = 0
 
static BOOL count_only = 0
 
static BOOL do_colour = 0
 
static BOOL hyphenpending = 0
 
static BOOL invert = 0
 
static BOOL multiline = 0
 
static BOOL number = 0
 
static BOOL only_matching = 0
 
static BOOL quiet = 0
 
static BOOL silent = 0
 
static BOOL utf8 = 0
 
static option_item optionlist []
 
static const char * prefix []
 
static const char * suffix []
 
const int utf8_table3 [] = { 0xff, 0x1f, 0x0f, 0x07, 0x03, 0x01}
 
const char utf8_table4 []
 
int sys_nerr
 
char * sys_errlist []
 

Macro Definition Documentation

◆ FALSE

#define FALSE   0

pcregrep program *

Definition at line 54 of file pcregrep.c.

◆ MAX_PATTERN_COUNT

#define MAX_PATTERN_COUNT   100

Definition at line 60 of file pcregrep.c.

◆ MBUFTHIRD

#define MBUFTHIRD   8192

Definition at line 65 of file pcregrep.c.

◆ N_COLOUR

#define N_COLOUR   (-1)

Definition at line 165 of file pcregrep.c.

◆ N_EXCLUDE

#define N_EXCLUDE   (-2)

Definition at line 166 of file pcregrep.c.

◆ N_HELP

#define N_HELP   (-3)

Definition at line 167 of file pcregrep.c.

◆ N_INCLUDE

#define N_INCLUDE   (-4)

Definition at line 168 of file pcregrep.c.

◆ N_LABEL

#define N_LABEL   (-5)

Definition at line 169 of file pcregrep.c.

◆ N_LOCALE

#define N_LOCALE   (-6)

Definition at line 170 of file pcregrep.c.

◆ N_NULL

#define N_NULL   (-7)

Definition at line 171 of file pcregrep.c.

◆ PO_FIXED_STRINGS

#define PO_FIXED_STRINGS   0x0004

Definition at line 83 of file pcregrep.c.

◆ PO_LINE_MATCH

#define PO_LINE_MATCH   0x0002

Definition at line 82 of file pcregrep.c.

◆ PO_WORD_MATCH

#define PO_WORD_MATCH   0x0001

Definition at line 81 of file pcregrep.c.

◆ TRUE

#define TRUE   1

Definition at line 55 of file pcregrep.c.

◆ VERSION

#define VERSION   "4.4 29-Nov-2006"

Definition at line 59 of file pcregrep.c.

Typedef Documentation

◆ BOOL

typedef int BOOL

Definition at line 57 of file pcregrep.c.

◆ directory_type

typedef void directory_type

OS-specific functions *

Definition at line 436 of file pcregrep.c.

◆ option_item

typedef struct option_item option_item

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
FN_NONE 
FN_DEFAULT 
FN_ONLY 
FN_NOMATCH_ONLY 
FN_FORCE 

Definition at line 72 of file pcregrep.c.

◆ anonymous enum

anonymous enum
Enumerator
dee_READ 
dee_SKIP 
dee_RECURSE 

Definition at line 76 of file pcregrep.c.

◆ anonymous enum

anonymous enum
Enumerator
DEE_READ 
DEE_SKIP 

Definition at line 77 of file pcregrep.c.

◆ anonymous enum

anonymous enum
Enumerator
EL_LF 
EL_CR 
EL_CRLF 
EL_ANY 

Definition at line 87 of file pcregrep.c.

◆ anonymous enum

anonymous enum
Enumerator
OP_NODATA 
OP_STRING 
OP_OP_STRING 
OP_NUMBER 
OP_OP_NUMBER 
OP_PATLIST 

Definition at line 151 of file pcregrep.c.

Function Documentation

◆ closedirectory()

void closedirectory ( directory_type dir)

Definition at line 441 of file pcregrep.c.

Referenced by grep_or_recurse().

◆ compile_pattern()

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

Compile one supplied pattern *

Definition at line 1454 of file pcregrep.c.

References buffer, compile_single_pattern(), end_of_line(), FALSE, MBUFTHIRD, PO_FIXED_STRINGS, and process_options.

Referenced by main().

◆ compile_single_pattern()

static BOOL compile_single_pattern ( char *  pattern,
int  options,
char *  filename,
int  count 
)
static

Compile a single pattern *

Definition at line 1391 of file pcregrep.c.

References buffer, FALSE, MAX_PATTERN_COUNT, MBUFTHIRD, ordin(), pattern_count, pattern_list, pcre_compile(), pcretables, prefix, process_options, suffix, and TRUE.

Referenced by compile_pattern().

◆ do_after_lines()

static void do_after_lines ( int  lastmatchnumber,
char *  lastmatchrestart,
char *  endptr,
char *  printname 
)
static

Print the previous "after" lines *

Definition at line 713 of file pcregrep.c.

References after_context, end_of_line(), hyphenpending, number, and TRUE.

Referenced by pcregrep().

◆ end_of_line()

static char* end_of_line ( char *  p,
char *  endptr,
int *  lenptr 
)
static

Find end of line *

Definition at line 502 of file pcregrep.c.

References EL_ANY, EL_CR, EL_CRLF, EL_LF, endlinetype, utf8, utf8_table3, and utf8_table4.

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

◆ grep_or_recurse()

static int grep_or_recurse ( char *  pathname,
BOOL  dir_recurse,
BOOL  only_one_at_top 
)
static

◆ handle_option()

static int handle_option ( int  letter,
int  options 
)
static

◆ help()

static void help ( void  )
static

Help function *

Definition at line 1268 of file pcregrep.c.

References option_item::help_text, option_item::long_name, MAX_PATTERN_COUNT, option_item::one_char, and optionlist.

Referenced by get_choice(), and handle_option().

◆ is_stdout_tty()

static BOOL is_stdout_tty ( void  )
static

Definition at line 454 of file pcregrep.c.

References FALSE.

Referenced by main().

◆ isdirectory()

int isdirectory ( char *  filename)

Definition at line 438 of file pcregrep.c.

Referenced by grep_or_recurse().

◆ isregfile()

int isregfile ( char *  filename)

Definition at line 448 of file pcregrep.c.

Referenced by grep_or_recurse().

◆ main()

◆ opendirectory()

directory_type* opendirectory ( char *  filename)

Definition at line 439 of file pcregrep.c.

Referenced by grep_or_recurse().

◆ ordin()

static char* ordin ( int  n)
static

Construct printed ordinal *

Definition at line 1354 of file pcregrep.c.

References buffer.

Referenced by compile_single_pattern().

◆ pcregrep()

◆ previous_line()

static char* previous_line ( char *  p,
char *  startptr 
)
static

Find start of previous line *

Definition at line 617 of file pcregrep.c.

References EL_ANY, EL_CR, EL_CRLF, EL_LF, endlinetype, utf8, utf8_table3, and utf8_table4.

Referenced by pcregrep().

◆ readdirectory()

char* readdirectory ( directory_type dir)

Definition at line 440 of file pcregrep.c.

Referenced by grep_or_recurse().

◆ strerror()

char* strerror ( int  n)

◆ usage()

static int usage ( int  rc)
static

Usage function *

Definition at line 1247 of file pcregrep.c.

References option_item::one_char, and optionlist.

Referenced by handle_option(), and main().

Variable Documentation

◆ after_context

int after_context = 0
static

Definition at line 129 of file pcregrep.c.

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

◆ before_context

int before_context = 0
static

Definition at line 130 of file pcregrep.c.

Referenced by main(), and pcregrep().

◆ both_context

int both_context = 0
static

Definition at line 131 of file pcregrep.c.

Referenced by main().

◆ colour_option

char* colour_option = NULL
static

Definition at line 109 of file pcregrep.c.

Referenced by main().

◆ colour_string

char* colour_string = (char *)"1;31"
static

Definition at line 108 of file pcregrep.c.

Referenced by main(), and pcregrep().

◆ count_only

BOOL count_only = 0
static

Definition at line 138 of file pcregrep.c.

Referenced by handle_option(), and pcregrep().

◆ dee_action

int dee_action = dee_READ
static

Definition at line 132 of file pcregrep.c.

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

◆ DEE_action

int DEE_action = DEE_READ
static

Definition at line 133 of file pcregrep.c.

Referenced by grep_or_recurse(), and main().

◆ dee_option

char* dee_option = NULL
static

Definition at line 110 of file pcregrep.c.

Referenced by main().

◆ DEE_option

char* DEE_option = NULL
static

Definition at line 111 of file pcregrep.c.

Referenced by main().

◆ do_colour

BOOL do_colour = 0
static

Definition at line 139 of file pcregrep.c.

Referenced by main(), and pcregrep().

◆ endlinetype

int endlinetype
static

Global variables *

Definition at line 106 of file pcregrep.c.

Referenced by end_of_line(), main(), and previous_line().

◆ error_count

int error_count = 0
static

Definition at line 134 of file pcregrep.c.

Referenced by pcregrep().

◆ exclude_compiled

pcre* exclude_compiled = NULL
static

Definition at line 127 of file pcregrep.c.

Referenced by grep_or_recurse(), and main().

◆ exclude_pattern

char* exclude_pattern = NULL
static

Definition at line 124 of file pcregrep.c.

Referenced by main().

◆ filenames

int filenames = FN_DEFAULT
static

Definition at line 135 of file pcregrep.c.

Referenced by grep_or_recurse(), handle_option(), main(), and pcregrep().

◆ hints_list

pcre_extra** hints_list
static

Definition at line 121 of file pcregrep.c.

Referenced by main(), and pcregrep().

◆ hyphenpending

BOOL hyphenpending = 0
static

Definition at line 140 of file pcregrep.c.

Referenced by do_after_lines(), and pcregrep().

◆ include_compiled

pcre* include_compiled = NULL
static

Definition at line 126 of file pcregrep.c.

Referenced by grep_or_recurse(), and main().

◆ include_pattern

char* include_pattern = NULL
static

Definition at line 123 of file pcregrep.c.

Referenced by main().

◆ invert

BOOL invert = 0
static

Definition at line 141 of file pcregrep.c.

Referenced by handle_option(), and pcregrep().

◆ locale

char* locale = NULL
static

Definition at line 115 of file pcregrep.c.

Referenced by main().

◆ multiline

BOOL multiline = 0
static

Definition at line 142 of file pcregrep.c.

Referenced by handle_option(), and pcregrep().

◆ newline

char* newline = NULL
static

Definition at line 112 of file pcregrep.c.

Referenced by main(), pcre_compile2(), pcre_dfa_exec(), and pcre_exec().

◆ number

BOOL number = 0
static

◆ only_matching

BOOL only_matching = 0
static

Definition at line 144 of file pcregrep.c.

Referenced by handle_option(), and pcregrep().

◆ optionlist

option_item optionlist[]
static

Definition at line 173 of file pcregrep.c.

Referenced by help(), main(), and usage().

◆ pattern_count

int pattern_count = 0
static

Definition at line 119 of file pcregrep.c.

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

◆ pattern_filename

char* pattern_filename = NULL
static

Definition at line 113 of file pcregrep.c.

Referenced by main().

◆ pattern_list

pcre** pattern_list
static

Definition at line 120 of file pcregrep.c.

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

◆ pcretables

const unsigned char* pcretables = NULL
static

Definition at line 117 of file pcregrep.c.

Referenced by compile_single_pattern(), and main().

◆ prefix

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

Definition at line 219 of file pcregrep.c.

Referenced by compile_single_pattern(), copy_body(), generate_tbl(), and make_prefix().

◆ process_options

int process_options = 0
static

Definition at line 136 of file pcregrep.c.

Referenced by compile_pattern(), compile_single_pattern(), and handle_option().

◆ quiet

BOOL quiet = 0
static

Definition at line 145 of file pcregrep.c.

Referenced by exec_request(), handle_option(), main(), and pcregrep().

◆ silent

BOOL silent = 0
static

Definition at line 146 of file pcregrep.c.

Referenced by grep_or_recurse(), and handle_option().

◆ stdin_name

char* stdin_name = (char *)"(standard input)"
static

Definition at line 114 of file pcregrep.c.

Referenced by grep_or_recurse(), and main().

◆ suffix

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

Definition at line 222 of file pcregrep.c.

Referenced by checknadd_headers(), compile_single_pattern(), create_mail_headers(), generate_filename(), and generate_tbl().

◆ sys_errlist

char* sys_errlist[]
extern

Referenced by my_strerror(), plp_Errormsg(), and strerror().

◆ sys_nerr

int sys_nerr
extern

Provide strerror() for non-ANSI libraries *

Referenced by my_strerror(), and strerror().

◆ utf8

◆ utf8_table3

const int utf8_table3[] = { 0xff, 0x1f, 0x0f, 0x07, 0x03, 0x01}

Definition at line 227 of file pcregrep.c.

Referenced by end_of_line(), previous_line(), and utf82ord().

◆ utf8_table4

const char utf8_table4[]
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 229 of file pcregrep.c.

Referenced by end_of_line(), and previous_line().