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 "pcre.h"

Go to the source code of this file.

Classes

struct  option_item

Defines

#define FALSE   0
#define TRUE   1
#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_EXCLUDE_DIR   (-3)
#define N_HELP   (-4)
#define N_INCLUDE   (-5)
#define N_INCLUDE_DIR   (-6)
#define N_LABEL   (-7)
#define N_LOCALE   (-8)
#define N_NULL   (-9)
#define N_LOFFSETS   (-10)
#define N_FOFFSETS   (-11)

Typedefs

typedef int BOOL
typedef void directory_type

Enumerations

enum  
enum  
enum  
enum  
enum  
enum  

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 (void *handle, int frtype, 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 = NULL
static pcre_extra ** hints_list = NULL
static char * include_pattern = NULL
static char * exclude_pattern = NULL
static char * include_dir_pattern = NULL
static char * exclude_dir_pattern = NULL
static pcreinclude_compiled = NULL
static pcreexclude_compiled = NULL
static pcreinclude_dir_compiled = NULL
static pcreexclude_dir_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 = FALSE
static BOOL do_colour = FALSE
static BOOL file_offsets = FALSE
static BOOL hyphenpending = FALSE
static BOOL invert = FALSE
static BOOL line_offsets = FALSE
static BOOL multiline = FALSE
static BOOL number = FALSE
static BOOL only_matching = FALSE
static BOOL quiet = FALSE
static BOOL silent = FALSE
static BOOL utf8 = FALSE
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 []


Define Documentation

#define FALSE   0

Definition at line 68 of file pcregrep.c.

#define MAX_PATTERN_COUNT   100

Definition at line 73 of file pcregrep.c.

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

#define MBUFTHIRD   8192

Definition at line 78 of file pcregrep.c.

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

#define N_COLOUR   (-1)

Definition at line 188 of file pcregrep.c.

#define N_EXCLUDE   (-2)

Definition at line 189 of file pcregrep.c.

#define N_EXCLUDE_DIR   (-3)

Definition at line 190 of file pcregrep.c.

#define N_FOFFSETS   (-11)

Definition at line 198 of file pcregrep.c.

Referenced by handle_option().

#define N_HELP   (-4)

Definition at line 191 of file pcregrep.c.

Referenced by handle_option().

#define N_INCLUDE   (-5)

Definition at line 192 of file pcregrep.c.

#define N_INCLUDE_DIR   (-6)

Definition at line 193 of file pcregrep.c.

#define N_LABEL   (-7)

Definition at line 194 of file pcregrep.c.

#define N_LOCALE   (-8)

Definition at line 195 of file pcregrep.c.

#define N_LOFFSETS   (-10)

Definition at line 197 of file pcregrep.c.

Referenced by handle_option().

#define N_NULL   (-9)

Definition at line 196 of file pcregrep.c.

#define PO_FIXED_STRINGS   0x0004

Definition at line 100 of file pcregrep.c.

Referenced by compile_pattern(), and handle_option().

#define PO_LINE_MATCH   0x0002

Definition at line 99 of file pcregrep.c.

Referenced by handle_option().

#define PO_WORD_MATCH   0x0001

Definition at line 98 of file pcregrep.c.

Referenced by handle_option().

#define TRUE   1

Definition at line 69 of file pcregrep.c.


Typedef Documentation

typedef int BOOL

Definition at line 71 of file pcregrep.c.

typedef void directory_type

Definition at line 469 of file pcregrep.c.


Enumeration Type Documentation

anonymous enum

Definition at line 85 of file pcregrep.c.

anonymous enum

Definition at line 89 of file pcregrep.c.

anonymous enum

Definition at line 93 of file pcregrep.c.

anonymous enum

Definition at line 94 of file pcregrep.c.

anonymous enum

Definition at line 104 of file pcregrep.c.

anonymous enum

Definition at line 174 of file pcregrep.c.


Function Documentation

void closedirectory ( directory_type dir  ) 

Definition at line 474 of file pcregrep.c.

Referenced by grep_or_recurse().

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

Definition at line 1777 of file pcregrep.c.

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

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

Definition at line 1710 of file pcregrep.c.

References buffer, error, FALSE, fprintf(), int, MAX_PATTERN_COUNT, MBUFTHIRD, NULL, ordin(), pattern_count, pattern_list, pcre_compile(), pcretables, prefix, process_options, sprintf(), suffix, and TRUE.

Referenced by compile_pattern().

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

Definition at line 801 of file pcregrep.c.

References after_context, end_of_line(), fprintf(), fwrite, hyphenpending, NULL, number, and TRUE.

Referenced by pcregrep().

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

Definition at line 535 of file pcregrep.c.

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

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

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

Definition at line 1345 of file pcregrep.c.

References buffer, closedirectory(), dee_action, DEE_action, dee_RECURSE, dee_SKIP, DEE_SKIP, dir(), exclude_compiled, exclude_dir_compiled, FALSE, fclose(), filenames, FN_DEFAULT, fopen, fprintf(), FR_LIBBZ2, FR_LIBZ, FR_PLAIN, gzclose(), gzopen(), handle(), include_compiled, include_dir_compiled, isdirectory(), isregfile(), NULL, opendirectory(), pcre_exec(), pcregrep(), readdirectory(), ROOT::Math::detail::sep, silent, sprintf(), stdin_name, and strerror().

static int handle_option ( int  letter,
int  options 
) [static]

Definition at line 1625 of file pcregrep.c.

References count_only, dee_action, dee_RECURSE, file_offsets, filenames, FN_FORCE, FN_NOMATCH_ONLY, FN_NONE, FN_ONLY, fprintf(), help(), invert, line_offsets, multiline, N_FOFFSETS, N_HELP, N_LOFFSETS, number, only_matching, PCRE_CASELESS, PCRE_FIRSTLINE, PCRE_MULTILINE, PCRE_UTF8, pcre_version(), PO_FIXED_STRINGS, PO_LINE_MATCH, PO_WORD_MATCH, process_options, quiet, silent, TRUE, usage, and utf8.

Referenced by main().

static void help ( void   )  [static]

Definition at line 1573 of file pcregrep.c.

References option_item::help_text, option_item::long_name, MAX_PATTERN_COUNT, n, option_item::one_char, optionlist, s, sprintf(), and strcpy().

Referenced by ApplicationWindow::ApplicationWindow(), el_get(), el_set(), getargs(), handle_option(), main(), TProof::ShowQueries(), and TUnixSystem::StackTrace().

static BOOL is_stdout_tty ( void   )  [static]

Definition at line 487 of file pcregrep.c.

References FALSE.

int isdirectory ( char *  filename  ) 

Definition at line 471 of file pcregrep.c.

Referenced by grep_or_recurse().

int isregfile ( char *  filename  ) 

Definition at line 481 of file pcregrep.c.

Referenced by grep_or_recurse().

int main ( int  argc,
char **  argv 
)

Definition at line 1807 of file pcregrep.c.

References equals(), error, FALSE, fprintf(), handle_option(), i, if(), j, MAX_PATTERN_COUNT, newline, NULL, option_item::one_char, OP_NODATA, optionlist, pattern_count, pattern_filename, patterns(), pcre_config(), PCRE_CONFIG_NEWLINE, s, sprintf(), TRUE, usage, and void.

directory_type* opendirectory ( char *  filename  ) 

Definition at line 472 of file pcregrep.c.

Referenced by grep_or_recurse().

static char* ordin ( int  n  )  [static]

Definition at line 1673 of file pcregrep.c.

References buffer, p, sprintf(), and strcpy().

Referenced by compile_single_pattern().

static int pcregrep ( void *  handle,
int  frtype,
char *  printname 
) [static]

Definition at line 849 of file pcregrep.c.

References after_context, before_context, buffer, colour_string, count_only, do_after_lines(), do_colour, dummy, end_of_line(), error_count, FALSE, file_offsets, filenames, FN_NOMATCH_ONLY, FN_ONLY, fprintf(), FR_LIBBZ2, FR_LIBZ, fread, fwrite, gettimeofday(), gzread(), hints_list, hyphenpending, i, invert, length, line_offsets, malloc(), match(), MBUFTHIRD, memmove, multiline, NULL, number, only_matching, p, pattern_count, pattern_list, PCRE_ERROR_MATCHLIMIT, PCRE_ERROR_NOMATCH, PCRE_ERROR_RECURSIONLIMIT, pcre_exec(), previous_line(), ptr, quiet, size_t, strcpy(), t, and TRUE.

Referenced by grep_or_recurse().

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

Definition at line 694 of file pcregrep.c.

References c, EL_ANY, EL_ANYCRLF, EL_CR, EL_CRLF, EL_LF, endlinetype, extra, utf8, utf8_table3, utf8_table4, and x80.

Referenced by pcregrep().

char* readdirectory ( directory_type dir  ) 

Definition at line 473 of file pcregrep.c.

Referenced by grep_or_recurse().

char* strerror ( int  n  ) 

Definition at line 510 of file pcregrep.c.

Referenced by XrdXrootdProtocol::do_Endsess(), doCp_loc2xrd(), doCp_xrd2loc(), XrdSysError::ec2text(), XrdSfsNative::Emsg(), XrdFrmAdmin::Emsg(), XrdSecsssKT::eMsg(), XrdSecProtocolsss::eMsg(), Ereason(), XrdSutPFile::Err(), XrdOucUtils::eText(), XrdW41Dirs::Expand(), XrdCmsNode::fsFail(), TVirtualPacketizer::GetEntries(), TUnixSystem::GetError(), grep_or_recurse(), XrdSecProtocolsss::Load_Crypto(), TEventIter::LoadDir(), main(), mkdirIfNecessary(), XrdPosixXrootd::OpenCB(), TChirpFile::OpenChirpClient(), ROOT::Perror(), XrdClientSock::RecvRaw(), XrdSecTLayer::secError(), XrdClientSock::SendRaw_sock(), XrdW41Gate::Serialize(), XrdNetDNS::setET(), TChirpFile::SysClose(), TChirpFile::SysOpen(), THDFSFile::SysRead(), TChirpFile::SysRead(), TChirpFile::SysSeek(), TChirpFile::SysSync(), TChirpFile::SysWrite(), XrdSysLogger::Trim(), tty_cookedmode(), tty_noquotemode(), tty_quotemode(), tty_rawmode(), tty_setup(), XrdW41Gate::Wait41(), XrdSecsssAdmin_addKey(), XrdSecsssAdmin_delKey(), and XrdSecsssAdmin_insKey().

static int usage ( int  rc  )  [static]

Definition at line 1551 of file pcregrep.c.

References fprintf(), option_item::one_char, and optionlist.


Variable Documentation

int after_context = 0 [static]

Definition at line 150 of file pcregrep.c.

Referenced by do_after_lines(), and pcregrep().

int before_context = 0 [static]

Definition at line 151 of file pcregrep.c.

Referenced by pcregrep().

int both_context = 0 [static]

Definition at line 152 of file pcregrep.c.

char* colour_option = NULL [static]

Definition at line 126 of file pcregrep.c.

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

Definition at line 125 of file pcregrep.c.

Referenced by pcregrep().

BOOL count_only = FALSE [static]

Definition at line 159 of file pcregrep.c.

Referenced by handle_option(), and pcregrep().

int DEE_action = DEE_READ [static]

Definition at line 154 of file pcregrep.c.

Referenced by grep_or_recurse().

int dee_action = dee_READ [static]

Definition at line 153 of file pcregrep.c.

Referenced by grep_or_recurse(), and handle_option().

char* DEE_option = NULL [static]

Definition at line 128 of file pcregrep.c.

char* dee_option = NULL [static]

Definition at line 127 of file pcregrep.c.

BOOL do_colour = FALSE [static]

Definition at line 160 of file pcregrep.c.

Referenced by pcregrep().

int endlinetype [static]

Definition at line 123 of file pcregrep.c.

Referenced by end_of_line(), and previous_line().

int error_count = 0 [static]

Definition at line 155 of file pcregrep.c.

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

pcre* exclude_compiled = NULL [static]

Definition at line 146 of file pcregrep.c.

Referenced by grep_or_recurse().

pcre* exclude_dir_compiled = NULL [static]

Definition at line 148 of file pcregrep.c.

Referenced by grep_or_recurse().

char* exclude_dir_pattern = NULL [static]

Definition at line 143 of file pcregrep.c.

char* exclude_pattern = NULL [static]

Definition at line 141 of file pcregrep.c.

BOOL file_offsets = FALSE [static]

Definition at line 161 of file pcregrep.c.

Referenced by handle_option(), and pcregrep().

int filenames = FN_DEFAULT [static]

Definition at line 156 of file pcregrep.c.

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

pcre_extra** hints_list = NULL [static]

Definition at line 138 of file pcregrep.c.

Referenced by pcregrep().

BOOL hyphenpending = FALSE [static]

Definition at line 162 of file pcregrep.c.

Referenced by do_after_lines(), and pcregrep().

pcre* include_compiled = NULL [static]

Definition at line 145 of file pcregrep.c.

Referenced by grep_or_recurse().

pcre* include_dir_compiled = NULL [static]

Definition at line 147 of file pcregrep.c.

Referenced by grep_or_recurse().

char* include_dir_pattern = NULL [static]

Definition at line 142 of file pcregrep.c.

char* include_pattern = NULL [static]

Definition at line 140 of file pcregrep.c.

BOOL invert = FALSE [static]

Definition at line 163 of file pcregrep.c.

Referenced by cff_font_load(), handle_option(), and pcregrep().

BOOL line_offsets = FALSE [static]

Definition at line 164 of file pcregrep.c.

Referenced by handle_option(), and pcregrep().

char* locale = NULL [static]

Definition at line 132 of file pcregrep.c.

Referenced by operator<<(), and StreemCurrAndMax().

BOOL multiline = FALSE [static]

Definition at line 165 of file pcregrep.c.

Referenced by handle_option(), and pcregrep().

char* newline = NULL [static]

Definition at line 129 of file pcregrep.c.

Referenced by TPaveText::AddLine(), TSystem::CompileMacro(), TLine::DrawLine(), TLine::DrawLineNDC(), ed_replay_hist(), gl2psPrintPostScriptPrimitive(), gl2psPrintSVGPrimitive(), TPaveText::InsertLine(), TGText::InsLine(), main(), pcrecpp::NewlineMode(), pcre_compile2(), pcre_dfa_exec(), and pcre_exec().

BOOL number = FALSE [static]

Definition at line 166 of file pcregrep.c.

Referenced by AddText(), TProcessUUID::AddUUID(), cff_parse_fixed_dynamic(), cff_parse_real(), TPad::Divide(), do_after_lines(), TH1Editor::DoBinMoved1(), TH1Editor::DoBinReleased1(), HistAction::drawHist(), TMVA::DataInputHandler::GetEntries(), handle_option(), XrdMonDecSink::initRT(), match(), pcregrep(), rotate(), StatusPrint(), TBufferFile::TagStreamerInfo(), testBinarySearch(), TestScanner(), TLinearFitter::TLinearFitter(), TXlfd::ToString(), and TGDMLParse::VolProcess().

BOOL only_matching = FALSE [static]

Definition at line 167 of file pcregrep.c.

Referenced by handle_option(), and pcregrep().

option_item optionlist[] [static]

Definition at line 200 of file pcregrep.c.

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

int pattern_count = 0 [static]

Definition at line 136 of file pcregrep.c.

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

char* pattern_filename = NULL [static]

Definition at line 130 of file pcregrep.c.

Referenced by main().

pcre** pattern_list = NULL [static]

Definition at line 137 of file pcregrep.c.

Referenced by compile_single_pattern(), and pcregrep().

const unsigned char* pcretables = NULL [static]

Definition at line 134 of file pcregrep.c.

Referenced by compile_single_pattern().

const char* prefix[] [static]

Initial value:

 {
  "", "\\b", "^(?:", "^(?:", "\\Q", "\\b\\Q", "^(?:\\Q", "^(?:\\Q" }

Definition at line 250 of file pcregrep.c.

Referenced by RooMsgService::addStream(), ROOT::TTreeProxyGenerator::AnalyzeBranches(), ROOT::TTreeProxyGenerator::AnalyzeOldBranch(), ClassApplication(), ClassImp(), compile_single_pattern(), TMVA::ResultsRegression::CreateDeviationHistograms(), TMVA::ResultsMulticlass::CreateMulticlassHistos(), TFile::GetType(), TProof::HandleInputMessage(), TProof::HandleSubmerger(), TTabCom::Hook(), RooMsgService::log(), main(), TMultiDimFit::MakeRealCode(), TPrincipal::MakeRealCode(), my_if_errors(), PlotDecisionBoundary(), RooFactoryWSTool::processSingleExpression(), runTest(), RooCmdArg::setProcessRecArgs(), TMVAClassificationApplication(), TMVAMulticlassApplication(), TMVARegressionApplication(), TMVA::MethodLikelihood::WriteOptionsToStream(), TMVA::MethodBase::WriteStateToStream(), and TMVA::MethodBase::WriteVarsToStream().

int process_options = 0 [static]

Definition at line 157 of file pcregrep.c.

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

BOOL quiet = FALSE [static]

Definition at line 168 of file pcregrep.c.

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

BOOL silent = FALSE [static]

Definition at line 169 of file pcregrep.c.

Referenced by RooSetProxy::add(), RooArgSet::add(), RooListProxy::add(), RooArgSet::addClone(), RooSetProxy::addClone(), RooListProxy::addOwned(), RooSetProxy::addOwned(), RooArgSet::addOwned(), ClassImp(), TXProofMgr::GetFile(), grep_or_recurse(), handle_option(), and term_echotc().

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

Definition at line 131 of file pcregrep.c.

Referenced by grep_or_recurse().

const char* suffix[] [static]

Initial value:

 {
  "", "\\b", ")$",   ")$",   "\\E", "\\E\\b", "\\E)$",   "\\E)$" }

Definition at line 253 of file pcregrep.c.

Referenced by RooAbsArg::aggregateCacheUniqueSuffix(), compile_single_pattern(), TGHtml::DecodeBaseIndex(), TSQLFile::DefineTableName(), TMVA::MethodBase::GetWeightFileName(), RooWorkspace::import(), TClass::ReadRules(), and TGQt::WritePixmap().

char* sys_errlist[]

Referenced by TWinNTSystem::GetError(), TUnixSystem::GetError(), and ROOT::Perror().

int sys_nerr

Referenced by TWinNTSystem::GetError(), TUnixSystem::GetError(), and ROOT::Perror().

BOOL utf8 = FALSE [static]

Definition at line 170 of file pcregrep.c.

Referenced by check_escape(), compile_branch(), end_of_line(), handle_option(), internal_dfa_exec(), match(), pcre_compile2(), pcre_dfa_exec(), pcre_exec(), and previous_line().

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

Definition at line 258 of file pcregrep.c.

Referenced by end_of_line(), and previous_line().

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 260 of file pcregrep.c.

Referenced by end_of_line(), and previous_line().


Generated on Tue Jul 5 15:57:31 2011 for ROOT_528-00b_version by  doxygen 1.5.1