mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
Revert "Convert config framework to use std::regex"
This reverts commit 65ee2287e9
.
This commit is contained in:
parent
a811722d72
commit
777dff18cd
1 changed files with 12 additions and 14 deletions
|
@ -2,11 +2,11 @@
|
|||
|
||||
#include "zeek/input/readers/config/Config.h"
|
||||
|
||||
#include <regex.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <cerrno>
|
||||
#include <regex>
|
||||
#include <sstream>
|
||||
#include <unordered_set>
|
||||
|
||||
|
@ -181,32 +181,28 @@ bool Config::DoUpdate()
|
|||
unseen_options.insert(i.first);
|
||||
}
|
||||
|
||||
std::regex re;
|
||||
try
|
||||
regex_t re;
|
||||
if ( regcomp(&re, "^([^[:blank:]]+)[[:blank:]]+([^[:blank:]](.*[^[:blank:]])?)?[[:blank:]]*$",
|
||||
REG_EXTENDED) )
|
||||
{
|
||||
re.assign("^([^[:blank:]]+)[[:blank:]]+([^[:blank:]](.*[^[:blank:]])?)?[[:blank:]]*$",
|
||||
std::regex::extended);
|
||||
}
|
||||
catch ( const std::regex_error& e )
|
||||
{
|
||||
Error(Fmt("Failed to compile regex: %s", e.what()));
|
||||
Error(Fmt("Failed to compile regex."));
|
||||
return true;
|
||||
}
|
||||
|
||||
while ( GetLine(line) )
|
||||
{
|
||||
std::smatch match;
|
||||
if ( ! std::regex_match(line, match, re) )
|
||||
regmatch_t match[3];
|
||||
if ( regexec(&re, line.c_str(), 3, match, 0) )
|
||||
{
|
||||
Warning(
|
||||
Fmt("Could not parse '%s'; line has invalid format. Ignoring line.", line.c_str()));
|
||||
continue;
|
||||
}
|
||||
|
||||
std::string key = match[1].str();
|
||||
std::string key = line.substr(match[1].rm_so, match[1].rm_eo - match[1].rm_so);
|
||||
std::string value;
|
||||
if ( match.size() > 2 )
|
||||
value = match[2].str();
|
||||
if ( match[2].rm_so > 0 )
|
||||
value = line.substr(match[2].rm_so, match[2].rm_eo - match[2].rm_so);
|
||||
|
||||
auto typeit = option_types.find(key);
|
||||
if ( typeit == option_types.end() )
|
||||
|
@ -287,6 +283,8 @@ bool Config::DoUpdate()
|
|||
}
|
||||
}
|
||||
|
||||
regfree(&re);
|
||||
|
||||
if ( Info().mode != MODE_STREAM )
|
||||
EndCurrentSend();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue