mirror of
https://github.com/zeek/zeek.git
synced 2025-10-07 09:08:20 +00:00
Reformat Zeek in Spicy style
This largely copies over Spicy's `.clang-format` configuration file. The one place where we deviate is header include order since Zeek depends on headers being included in a certain order.
This commit is contained in:
parent
7b8e7ed72c
commit
f5a76c1aed
786 changed files with 131714 additions and 153609 deletions
|
@ -8,126 +8,90 @@
|
|||
|
||||
#include "zeek/script_opt/StmtOptInfo.h"
|
||||
|
||||
namespace zeek::detail
|
||||
{
|
||||
namespace zeek::detail {
|
||||
|
||||
using namespace std;
|
||||
|
||||
string Fmt(double d)
|
||||
{
|
||||
// Special hack to preserve the signed-ness of the magic -0.0.
|
||||
if ( d == 0.0 && signbit(d) )
|
||||
return "-0.0";
|
||||
string Fmt(double d) {
|
||||
// Special hack to preserve the signed-ness of the magic -0.0.
|
||||
if ( d == 0.0 && signbit(d) )
|
||||
return "-0.0";
|
||||
|
||||
// Unfortunately, to_string(double) is hardwired to use %f with
|
||||
// default of 6 digits precision.
|
||||
char buf[8192];
|
||||
snprintf(buf, sizeof buf, "%.17g", d);
|
||||
return buf;
|
||||
}
|
||||
// Unfortunately, to_string(double) is hardwired to use %f with
|
||||
// default of 6 digits precision.
|
||||
char buf[8192];
|
||||
snprintf(buf, sizeof buf, "%.17g", d);
|
||||
return buf;
|
||||
}
|
||||
|
||||
string scope_prefix(const string& scope)
|
||||
{
|
||||
return "zeek::detail::CPP_" + scope;
|
||||
}
|
||||
string scope_prefix(const string& scope) { return "zeek::detail::CPP_" + scope; }
|
||||
|
||||
string scope_prefix(int scope)
|
||||
{
|
||||
return scope_prefix(to_string(scope));
|
||||
}
|
||||
string scope_prefix(int scope) { return scope_prefix(to_string(scope)); }
|
||||
|
||||
bool is_CPP_compilable(const ProfileFunc* pf, const char** reason)
|
||||
{
|
||||
if ( analysis_options.allow_cond )
|
||||
return true;
|
||||
bool is_CPP_compilable(const ProfileFunc* pf, const char** reason) {
|
||||
if ( analysis_options.allow_cond )
|
||||
return true;
|
||||
|
||||
auto body = pf->ProfiledBody();
|
||||
if ( body && ! body->GetOptInfo()->is_free_of_conditionals )
|
||||
{
|
||||
if ( reason )
|
||||
*reason = "body may be affected by @if conditional";
|
||||
return false;
|
||||
}
|
||||
auto body = pf->ProfiledBody();
|
||||
if ( body && ! body->GetOptInfo()->is_free_of_conditionals ) {
|
||||
if ( reason )
|
||||
*reason = "body may be affected by @if conditional";
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void lock_file(const string& fname, FILE* f)
|
||||
{
|
||||
if ( flock(fileno(f), LOCK_EX) < 0 )
|
||||
{
|
||||
char buf[256];
|
||||
util::zeek_strerror_r(errno, buf, sizeof(buf));
|
||||
reporter->Error("flock failed on %s: %s", fname.c_str(), buf);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
void lock_file(const string& fname, FILE* f) {
|
||||
if ( flock(fileno(f), LOCK_EX) < 0 ) {
|
||||
char buf[256];
|
||||
util::zeek_strerror_r(errno, buf, sizeof(buf));
|
||||
reporter->Error("flock failed on %s: %s", fname.c_str(), buf);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
void unlock_file(const string& fname, FILE* f)
|
||||
{
|
||||
if ( flock(fileno(f), LOCK_UN) < 0 )
|
||||
{
|
||||
char buf[256];
|
||||
util::zeek_strerror_r(errno, buf, sizeof(buf));
|
||||
reporter->Error("un-flock failed on %s: %s", fname.c_str(), buf);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
void unlock_file(const string& fname, FILE* f) {
|
||||
if ( flock(fileno(f), LOCK_UN) < 0 ) {
|
||||
char buf[256];
|
||||
util::zeek_strerror_r(errno, buf, sizeof(buf));
|
||||
reporter->Error("un-flock failed on %s: %s", fname.c_str(), buf);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
string CPPEscape(const char* b, int len)
|
||||
{
|
||||
string res;
|
||||
string CPPEscape(const char* b, int len) {
|
||||
string res;
|
||||
|
||||
for ( int i = 0; i < len; ++i )
|
||||
{
|
||||
unsigned char c = b[i];
|
||||
for ( int i = 0; i < len; ++i ) {
|
||||
unsigned char c = b[i];
|
||||
|
||||
switch ( c )
|
||||
{
|
||||
case '\a':
|
||||
res += "\\a";
|
||||
break;
|
||||
case '\b':
|
||||
res += "\\b";
|
||||
break;
|
||||
case '\f':
|
||||
res += "\\f";
|
||||
break;
|
||||
case '\n':
|
||||
res += "\\n";
|
||||
break;
|
||||
case '\r':
|
||||
res += "\\r";
|
||||
break;
|
||||
case '\t':
|
||||
res += "\\t";
|
||||
break;
|
||||
case '\v':
|
||||
res += "\\v";
|
||||
break;
|
||||
switch ( c ) {
|
||||
case '\a': res += "\\a"; break;
|
||||
case '\b': res += "\\b"; break;
|
||||
case '\f': res += "\\f"; break;
|
||||
case '\n': res += "\\n"; break;
|
||||
case '\r': res += "\\r"; break;
|
||||
case '\t': res += "\\t"; break;
|
||||
case '\v': res += "\\v"; break;
|
||||
|
||||
case '\\':
|
||||
res += "\\\\";
|
||||
break;
|
||||
case '"':
|
||||
res += "\\\"";
|
||||
break;
|
||||
case '\\': res += "\\\\"; break;
|
||||
case '"': res += "\\\""; break;
|
||||
|
||||
default:
|
||||
if ( isprint(c) )
|
||||
res += c;
|
||||
else
|
||||
{
|
||||
char buf[8192];
|
||||
snprintf(buf, sizeof buf, "%03o", c);
|
||||
res += "\\";
|
||||
res += buf;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
default:
|
||||
if ( isprint(c) )
|
||||
res += c;
|
||||
else {
|
||||
char buf[8192];
|
||||
snprintf(buf, sizeof buf, "%03o", c);
|
||||
res += "\\";
|
||||
res += buf;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
} // zeek::detail
|
||||
} // namespace zeek::detail
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue