mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
Reformat the world
This commit is contained in:
parent
194cb24547
commit
b2f171ec69
714 changed files with 35149 additions and 35203 deletions
73
src/RE.cc
73
src/RE.cc
|
@ -1,16 +1,16 @@
|
|||
// See the file "COPYING" in the main distribution directory for copyright.
|
||||
|
||||
#include "zeek/zeek-config.h"
|
||||
#include "zeek/RE.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <utility>
|
||||
|
||||
#include "zeek/DFA.h"
|
||||
#include "zeek/CCL.h"
|
||||
#include "zeek/DFA.h"
|
||||
#include "zeek/EquivClass.h"
|
||||
#include "zeek/Reporter.h"
|
||||
#include "zeek/ZeekString.h"
|
||||
#include "zeek/zeek-config.h"
|
||||
|
||||
zeek::detail::CCL* zeek::detail::curr_ccl = nullptr;
|
||||
zeek::detail::Specific_RE_Matcher* zeek::detail::rem = nullptr;
|
||||
|
@ -21,11 +21,13 @@ extern int RE_parse(void);
|
|||
extern void RE_set_input(const char* str);
|
||||
extern void RE_done_with_scan();
|
||||
|
||||
namespace zeek {
|
||||
namespace detail {
|
||||
namespace zeek
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
|
||||
Specific_RE_Matcher::Specific_RE_Matcher(match_type arg_mt, int arg_multiline)
|
||||
: equiv_class(NUM_SYM)
|
||||
: equiv_class(NUM_SYM)
|
||||
{
|
||||
mt = arg_mt;
|
||||
multiline = arg_multiline;
|
||||
|
@ -42,7 +44,7 @@ Specific_RE_Matcher::~Specific_RE_Matcher()
|
|||
delete ccl_list[i];
|
||||
|
||||
Unref(dfa);
|
||||
delete [] pattern_text;
|
||||
delete[] pattern_text;
|
||||
delete accepted;
|
||||
}
|
||||
|
||||
|
@ -84,8 +86,7 @@ void Specific_RE_Matcher::AddExactPat(const char* new_pat)
|
|||
AddPat(new_pat, "^?(%s)$?", "(%s)|(^?(%s)$?)");
|
||||
}
|
||||
|
||||
void Specific_RE_Matcher::AddPat(const char* new_pat,
|
||||
const char* orig_fmt, const char* app_fmt)
|
||||
void Specific_RE_Matcher::AddPat(const char* new_pat, const char* orig_fmt, const char* app_fmt)
|
||||
{
|
||||
int n = strlen(new_pat);
|
||||
|
||||
|
@ -101,7 +102,7 @@ void Specific_RE_Matcher::AddPat(const char* new_pat,
|
|||
else
|
||||
sprintf(s, orig_fmt, new_pat);
|
||||
|
||||
delete [] pattern_text;
|
||||
delete[] pattern_text;
|
||||
pattern_text = s;
|
||||
}
|
||||
|
||||
|
@ -114,7 +115,7 @@ void Specific_RE_Matcher::MakeCaseInsensitive()
|
|||
|
||||
snprintf(s, n + 5, fmt, pattern_text);
|
||||
|
||||
delete [] pattern_text;
|
||||
delete[] pattern_text;
|
||||
pattern_text = s;
|
||||
}
|
||||
|
||||
|
@ -186,7 +187,7 @@ bool Specific_RE_Matcher::CompileSet(const string_list& set, const int_list& idx
|
|||
nfa = new NFA_Machine(new NFA_State(SYM_BOL, rem->EC()));
|
||||
nfa->MakeOptional();
|
||||
if ( set_nfa )
|
||||
nfa->AppendMachine( set_nfa );
|
||||
nfa->AppendMachine(set_nfa);
|
||||
|
||||
EC()->BuildECs();
|
||||
ConvertCCLs();
|
||||
|
@ -262,7 +263,6 @@ bool Specific_RE_Matcher::MatchAll(const u_char* bv, int n)
|
|||
return d && d->Accept() != nullptr;
|
||||
}
|
||||
|
||||
|
||||
int Specific_RE_Matcher::Match(const u_char* bv, int n)
|
||||
{
|
||||
if ( ! dfa )
|
||||
|
@ -272,7 +272,8 @@ int Specific_RE_Matcher::Match(const u_char* bv, int n)
|
|||
DFA_State* d = dfa->StartState();
|
||||
|
||||
d = d->Xtion(ecs[SYM_BOL], dfa);
|
||||
if ( ! d ) return 0;
|
||||
if ( ! d )
|
||||
return 0;
|
||||
|
||||
for ( int i = 0; i < n; ++i )
|
||||
{
|
||||
|
@ -289,20 +290,18 @@ int Specific_RE_Matcher::Match(const u_char* bv, int n)
|
|||
{
|
||||
d = d->Xtion(ecs[SYM_EOL], dfa);
|
||||
if ( d && d->Accept() )
|
||||
return n > 0 ? n : 1; // we can't return 0 here for match...
|
||||
return n > 0 ? n : 1; // we can't return 0 here for match...
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void Specific_RE_Matcher::Dump(FILE* f)
|
||||
{
|
||||
dfa->Dump(f);
|
||||
}
|
||||
|
||||
inline void RE_Match_State::AddMatches(const AcceptingSet& as,
|
||||
MatchPos position)
|
||||
inline void RE_Match_State::AddMatches(const AcceptingSet& as, MatchPos position)
|
||||
{
|
||||
typedef std::pair<AcceptIdx, MatchPos> am_idx;
|
||||
|
||||
|
@ -310,8 +309,7 @@ inline void RE_Match_State::AddMatches(const AcceptingSet& as,
|
|||
accepted_matches.insert(am_idx(*it, position));
|
||||
}
|
||||
|
||||
bool RE_Match_State::Match(const u_char* bv, int n,
|
||||
bool bol, bool eol, bool clear)
|
||||
bool RE_Match_State::Match(const u_char* bv, int n, bool bol, bool eol, bool clear)
|
||||
{
|
||||
if ( current_pos == -1 )
|
||||
{
|
||||
|
@ -352,7 +350,7 @@ bool RE_Match_State::Match(const u_char* bv, int n,
|
|||
else
|
||||
ec = ecs[*(bv++)];
|
||||
|
||||
DFA_State* next_state = current_state->Xtion(ec,dfa);
|
||||
DFA_State* next_state = current_state->Xtion(ec, dfa);
|
||||
|
||||
if ( ! next_state )
|
||||
{
|
||||
|
@ -425,7 +423,8 @@ unsigned int Specific_RE_Matcher::MemoryAllocation() const
|
|||
size += util::pad_size(sizeof(CCL*) * ccl_dict.size());
|
||||
for ( const auto& entry : ccl_dict )
|
||||
{
|
||||
size += padded_sizeof(std::string) + util::pad_size(sizeof(std::string::value_type) * entry.first.size());
|
||||
size += padded_sizeof(std::string) +
|
||||
util::pad_size(sizeof(std::string::value_type) * entry.first.size());
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||
size += entry.second->MemoryAllocation();
|
||||
|
@ -434,36 +433,36 @@ unsigned int Specific_RE_Matcher::MemoryAllocation() const
|
|||
|
||||
for ( const auto& entry : defs )
|
||||
{
|
||||
size += padded_sizeof(std::string) + util::pad_size(sizeof(std::string::value_type) * entry.first.size());
|
||||
size += padded_sizeof(std::string) + util::pad_size(sizeof(std::string::value_type) * entry.second.size());
|
||||
size += padded_sizeof(std::string) +
|
||||
util::pad_size(sizeof(std::string::value_type) * entry.first.size());
|
||||
size += padded_sizeof(std::string) +
|
||||
util::pad_size(sizeof(std::string::value_type) * entry.second.size());
|
||||
}
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||
return size + padded_sizeof(*this)
|
||||
+ (pattern_text ? util::pad_size(strlen(pattern_text) + 1) : 0)
|
||||
+ ccl_list.MemoryAllocation() - padded_sizeof(ccl_list)
|
||||
+ equiv_class.Size() - padded_sizeof(EquivClass)
|
||||
+ (dfa ? dfa->MemoryAllocation() : 0) // this is ref counted; consider the bytes here?
|
||||
+ padded_sizeof(*any_ccl)
|
||||
+ padded_sizeof(*accepted) // NOLINT(bugprone-sizeof-container)
|
||||
+ accepted->size() * padded_sizeof(AcceptingSet::key_type);
|
||||
return size + padded_sizeof(*this) +
|
||||
(pattern_text ? util::pad_size(strlen(pattern_text) + 1) : 0) +
|
||||
ccl_list.MemoryAllocation() - padded_sizeof(ccl_list) + equiv_class.Size() -
|
||||
padded_sizeof(EquivClass) +
|
||||
(dfa ? dfa->MemoryAllocation() : 0) // this is ref counted; consider the bytes here?
|
||||
+ padded_sizeof(*any_ccl) + padded_sizeof(*accepted) // NOLINT(bugprone-sizeof-container)
|
||||
+ accepted->size() * padded_sizeof(AcceptingSet::key_type);
|
||||
#pragma GCC diagnostic pop
|
||||
}
|
||||
|
||||
static RE_Matcher* matcher_merge(const RE_Matcher* re1, const RE_Matcher* re2,
|
||||
const char* merge_op)
|
||||
static RE_Matcher* matcher_merge(const RE_Matcher* re1, const RE_Matcher* re2, const char* merge_op)
|
||||
{
|
||||
const char* text1 = re1->PatternText();
|
||||
const char* text2 = re2->PatternText();
|
||||
|
||||
int n = strlen(text1) + strlen(text2) + strlen(merge_op) + 32 /* slop */ ;
|
||||
int n = strlen(text1) + strlen(text2) + strlen(merge_op) + 32 /* slop */;
|
||||
|
||||
char* merge_text = new char[n];
|
||||
snprintf(merge_text, n, "(%s)%s(%s)", text1, merge_op, text2);
|
||||
|
||||
RE_Matcher* merge = new RE_Matcher(merge_text);
|
||||
delete [] merge_text;
|
||||
delete[] merge_text;
|
||||
|
||||
merge->Compile();
|
||||
|
||||
|
@ -480,7 +479,7 @@ RE_Matcher* RE_Matcher_disjunction(const RE_Matcher* re1, const RE_Matcher* re2)
|
|||
return matcher_merge(re1, re2, "|");
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
} // namespace detail
|
||||
|
||||
RE_Matcher::RE_Matcher()
|
||||
{
|
||||
|
@ -529,4 +528,4 @@ bool RE_Matcher::Compile(bool lazy)
|
|||
return re_anywhere->Compile(lazy) && re_exact->Compile(lazy);
|
||||
}
|
||||
|
||||
} // namespace zeek
|
||||
} // namespace zeek
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue