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:
Benjamin Bannier 2023-10-10 21:13:34 +02:00
parent 7b8e7ed72c
commit f5a76c1aed
786 changed files with 131714 additions and 153609 deletions

View file

@ -10,18 +10,16 @@
#include "zeek/Val.h"
#include "zeek/util.h"
namespace zeek
{
namespace zeek {
namespace detail
{
namespace detail {
class PrintStmt;
class Attributes;
extern void do_print_stmt(const std::vector<ValPtr>& vals);
} // namespace detail;
} // namespace detail
class RecordVal;
class Type;
@ -30,94 +28,93 @@ using TypePtr = IntrusivePtr<Type>;
class File;
using FilePtr = IntrusivePtr<File>;
class File final : public Obj
{
class File final : public Obj {
public:
explicit File(FILE* arg_f);
File(FILE* arg_f, const char* filename, const char* access);
File(const char* filename, const char* access);
~File() override;
explicit File(FILE* arg_f);
File(FILE* arg_f, const char* filename, const char* access);
File(const char* filename, const char* access);
~File() override;
const char* Name() const;
const char* Name() const;
// Returns false if an error occurred.
bool Write(const char* data, int len = 0);
// Returns false if an error occurred.
bool Write(const char* data, int len = 0);
void Flush() { fflush(f); }
void Flush() { fflush(f); }
FILE* Seek(long position); // seek to absolute position
FILE* Seek(long position); // seek to absolute position
void SetBuf(bool buffered); // false=line buffered, true=fully buffered
void SetBuf(bool buffered); // false=line buffered, true=fully buffered
const TypePtr& GetType() const { return t; }
const TypePtr& GetType() const { return t; }
// Whether the file is open in a general sense; it might
// not be open as a Unix file due to our management of
// a finite number of FDs.
bool IsOpen() const { return is_open; }
// Whether the file is open in a general sense; it might
// not be open as a Unix file due to our management of
// a finite number of FDs.
bool IsOpen() const { return is_open; }
// Returns true if the close made sense, false if it was already
// closed, not active, or whatever.
bool Close();
// Returns true if the close made sense, false if it was already
// closed, not active, or whatever.
bool Close();
void Describe(ODesc* d) const override;
void Describe(ODesc* d) const override;
// Rotates the logfile. Returns rotate_info.
RecordVal* Rotate();
// Rotates the logfile. Returns rotate_info.
RecordVal* Rotate();
// Set &raw_output attribute.
void SetAttrs(detail::Attributes* attrs);
// Set &raw_output attribute.
void SetAttrs(detail::Attributes* attrs);
// Returns the current size of the file, after fresh stat'ing.
double Size();
// Returns the current size of the file, after fresh stat'ing.
double Size();
// Close all files which are currently open.
static void CloseOpenFiles();
// Close all files which are currently open.
static void CloseOpenFiles();
// Get the file with the given name, opening it if it doesn't yet exist.
static FilePtr Get(const char* name);
// Get the file with the given name, opening it if it doesn't yet exist.
static FilePtr Get(const char* name);
void EnableRawOutput() { raw_output = true; }
bool IsRawOutput() const { return raw_output; }
void EnableRawOutput() { raw_output = true; }
bool IsRawOutput() const { return raw_output; }
protected:
friend void detail::do_print_stmt(const std::vector<ValPtr>& vals);
friend void detail::do_print_stmt(const std::vector<ValPtr>& vals);
File() { Init(); }
void Init();
File() { Init(); }
void Init();
/**
* If file is given, it's an open file to use already.
* If file is not given and mode is, the filename will be opened with that
* access mode.
*/
bool Open(FILE* f = nullptr, const char* mode = nullptr);
/**
* If file is given, it's an open file to use already.
* If file is not given and mode is, the filename will be opened with that
* access mode.
*/
bool Open(FILE* f = nullptr, const char* mode = nullptr);
void Unlink();
void Unlink();
// Returns nil if the file is not active, was in error, etc.
// (Protected because we do not want anyone to write directly
// to the file, but the PrintStmt friend uses this to check whether
// it's really stdout.)
FILE* FileHandle();
// Returns nil if the file is not active, was in error, etc.
// (Protected because we do not want anyone to write directly
// to the file, but the PrintStmt friend uses this to check whether
// it's really stdout.)
FILE* FileHandle();
// Raises a file_opened event.
void RaiseOpenEvent();
// Raises a file_opened event.
void RaiseOpenEvent();
FILE* f = nullptr;
TypePtr t;
char* name = nullptr;
char* access = nullptr;
detail::Attributes* attrs = nullptr;
double open_time = 0.0;
bool is_open = false; // whether the file is open in a general sense
bool buffered = false;
bool raw_output = false;
FILE* f = nullptr;
TypePtr t;
char* name = nullptr;
char* access = nullptr;
detail::Attributes* attrs = nullptr;
double open_time = 0.0;
bool is_open = false; // whether the file is open in a general sense
bool buffered = false;
bool raw_output = false;
static constexpr int MIN_BUFFER_SIZE = 1024;
static constexpr int MIN_BUFFER_SIZE = 1024;
private:
static std::list<std::pair<std::string, File*>> open_files;
};
static std::list<std::pair<std::string, File*>> open_files;
};
} // namespace zeek
} // namespace zeek