mirror of
https://github.com/zeek/zeek.git
synced 2025-10-07 17:18:20 +00:00
Reformat the world
This commit is contained in:
parent
194cb24547
commit
b2f171ec69
714 changed files with 35149 additions and 35203 deletions
137
src/Desc.h
137
src/Desc.h
|
@ -3,95 +3,97 @@
|
|||
#pragma once
|
||||
|
||||
#include <sys/types.h> // for u_char
|
||||
|
||||
#include <set>
|
||||
#include <utility>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include "zeek/ZeekString.h" // for byte_vec
|
||||
#include "zeek/util.h" // for bro_int_t
|
||||
|
||||
namespace zeek {
|
||||
namespace zeek
|
||||
{
|
||||
|
||||
class IPAddr;
|
||||
class IPPrefix;
|
||||
class File;
|
||||
class Type;
|
||||
|
||||
enum DescType {
|
||||
enum DescType
|
||||
{
|
||||
DESC_READABLE,
|
||||
DESC_PORTABLE,
|
||||
DESC_BINARY,
|
||||
};
|
||||
};
|
||||
|
||||
enum DescStyle {
|
||||
enum DescStyle
|
||||
{
|
||||
STANDARD_STYLE,
|
||||
RAW_STYLE,
|
||||
};
|
||||
};
|
||||
|
||||
class ODesc {
|
||||
class ODesc
|
||||
{
|
||||
public:
|
||||
explicit ODesc(DescType t=DESC_READABLE, File* f=nullptr);
|
||||
explicit ODesc(DescType t = DESC_READABLE, File* f = nullptr);
|
||||
|
||||
~ODesc();
|
||||
|
||||
bool IsReadable() const { return type == DESC_READABLE; }
|
||||
bool IsPortable() const { return type == DESC_PORTABLE; }
|
||||
bool IsBinary() const { return type == DESC_BINARY; }
|
||||
bool IsReadable() const { return type == DESC_READABLE; }
|
||||
bool IsPortable() const { return type == DESC_PORTABLE; }
|
||||
bool IsBinary() const { return type == DESC_BINARY; }
|
||||
|
||||
bool IsShort() const { return is_short; }
|
||||
void SetShort() { is_short = true; }
|
||||
void SetShort(bool s) { is_short = s; }
|
||||
bool IsShort() const { return is_short; }
|
||||
void SetShort() { is_short = true; }
|
||||
void SetShort(bool s) { is_short = s; }
|
||||
|
||||
// Whether we want to have quotes around strings.
|
||||
bool WantQuotes() const { return want_quotes; }
|
||||
void SetQuotes(bool q) { want_quotes = q; }
|
||||
bool WantQuotes() const { return want_quotes; }
|
||||
void SetQuotes(bool q) { want_quotes = q; }
|
||||
|
||||
// Whether to ensure deterministic output (for example, when
|
||||
// describing TableVal's).
|
||||
bool WantDeterminism() const { return want_determinism; }
|
||||
void SetDeterminism(bool d) { want_determinism = d; }
|
||||
bool WantDeterminism() const { return want_determinism; }
|
||||
void SetDeterminism(bool d) { want_determinism = d; }
|
||||
|
||||
// Whether we want to print statistics like access time and execution
|
||||
// count where available.
|
||||
bool IncludeStats() const { return include_stats; }
|
||||
void SetIncludeStats(bool s) { include_stats = s; }
|
||||
bool IncludeStats() const { return include_stats; }
|
||||
void SetIncludeStats(bool s) { include_stats = s; }
|
||||
|
||||
DescStyle Style() const { return style; }
|
||||
void SetStyle(DescStyle s) { style = s; }
|
||||
DescStyle Style() const { return style; }
|
||||
void SetStyle(DescStyle s) { style = s; }
|
||||
|
||||
void SetFlush(bool arg_do_flush) { do_flush = arg_do_flush; }
|
||||
void SetFlush(bool arg_do_flush) { do_flush = arg_do_flush; }
|
||||
|
||||
void EnableEscaping();
|
||||
void EnableUTF8();
|
||||
void AddEscapeSequence(const char* s) { escape_sequences.insert(s); }
|
||||
void AddEscapeSequence(const char* s, size_t n)
|
||||
{ escape_sequences.insert(std::string(s, n)); }
|
||||
void AddEscapeSequence(const std::string & s)
|
||||
{ escape_sequences.insert(s); }
|
||||
void AddEscapeSequence(const char* s, size_t n) { escape_sequences.insert(std::string(s, n)); }
|
||||
void AddEscapeSequence(const std::string& s) { escape_sequences.insert(s); }
|
||||
void RemoveEscapeSequence(const char* s) { escape_sequences.erase(s); }
|
||||
void RemoveEscapeSequence(const char* s, size_t n)
|
||||
{ escape_sequences.erase(std::string(s, n)); }
|
||||
void RemoveEscapeSequence(const std::string & s)
|
||||
{ escape_sequences.erase(s); }
|
||||
{
|
||||
escape_sequences.erase(std::string(s, n));
|
||||
}
|
||||
void RemoveEscapeSequence(const std::string& s) { escape_sequences.erase(s); }
|
||||
|
||||
void PushIndent();
|
||||
void PopIndent();
|
||||
void PopIndentNoNL();
|
||||
int GetIndentLevel() const { return indent_level; }
|
||||
int GetIndentLevel() const { return indent_level; }
|
||||
void ClearIndentLevel() { indent_level = 0; }
|
||||
|
||||
int IndentSpaces() const { return indent_with_spaces; }
|
||||
void SetIndentSpaces(int i) { indent_with_spaces = i; }
|
||||
int IndentSpaces() const { return indent_with_spaces; }
|
||||
void SetIndentSpaces(int i) { indent_with_spaces = i; }
|
||||
|
||||
void Add(const char* s, int do_indent=1);
|
||||
void AddN(const char* s, int len) { AddBytes(s, len); }
|
||||
void Add(const std::string& s) { AddBytes(s.data(), s.size()); }
|
||||
void Add(const char* s, int do_indent = 1);
|
||||
void AddN(const char* s, int len) { AddBytes(s, len); }
|
||||
void Add(const std::string& s) { AddBytes(s.data(), s.size()); }
|
||||
void Add(int i);
|
||||
void Add(uint32_t u);
|
||||
void Add(int64_t i);
|
||||
void Add(uint64_t u);
|
||||
void Add(double d, bool no_exp=false);
|
||||
void Add(double d, bool no_exp = false);
|
||||
void Add(const IPAddr& addr);
|
||||
void Add(const IPPrefix& prefix);
|
||||
|
||||
|
@ -101,13 +103,22 @@ public:
|
|||
void AddBytes(const String* s);
|
||||
|
||||
void Add(const char* s1, const char* s2)
|
||||
{ Add(s1); Add(s2); }
|
||||
{
|
||||
Add(s1);
|
||||
Add(s2);
|
||||
}
|
||||
|
||||
void AddSP(const char* s1, const char* s2)
|
||||
{ Add(s1); AddSP(s2); }
|
||||
{
|
||||
Add(s1);
|
||||
AddSP(s2);
|
||||
}
|
||||
|
||||
void AddSP(const char* s )
|
||||
{ Add(s); SP(); }
|
||||
void AddSP(const char* s)
|
||||
{
|
||||
Add(s);
|
||||
SP();
|
||||
}
|
||||
|
||||
void AddCount(bro_int_t n)
|
||||
{
|
||||
|
@ -118,23 +129,25 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
void SP() {
|
||||
if ( ! IsBinary() )
|
||||
Add(" ", 0);
|
||||
}
|
||||
void NL() {
|
||||
if ( ! IsBinary() && ! is_short )
|
||||
Add("\n", 0);
|
||||
}
|
||||
void SP()
|
||||
{
|
||||
if ( ! IsBinary() )
|
||||
Add(" ", 0);
|
||||
}
|
||||
void NL()
|
||||
{
|
||||
if ( ! IsBinary() && ! is_short )
|
||||
Add("\n", 0);
|
||||
}
|
||||
|
||||
// Bypasses the escaping enabled via EnableEscaping().
|
||||
void AddRaw(const char* s, int len) { AddBytesRaw(s, len); }
|
||||
void AddRaw(const std::string &s) { AddBytesRaw(s.data(), s.size()); }
|
||||
void AddRaw(const char* s, int len) { AddBytesRaw(s, len); }
|
||||
void AddRaw(const std::string& s) { AddBytesRaw(s.data(), s.size()); }
|
||||
|
||||
// Returns the description as a string.
|
||||
const char* Description() const { return (const char*) base; }
|
||||
const char* Description() const { return (const char*)base; }
|
||||
|
||||
const u_char* Bytes() const { return (const u_char *) base; }
|
||||
const u_char* Bytes() const { return (const u_char*)base; }
|
||||
byte_vec TakeBytes()
|
||||
{
|
||||
const void* t = base;
|
||||
|
@ -147,7 +160,7 @@ public:
|
|||
return byte_vec(t);
|
||||
}
|
||||
|
||||
int Len() const { return offset; }
|
||||
int Len() const { return offset; }
|
||||
|
||||
void Clear();
|
||||
|
||||
|
@ -191,12 +204,12 @@ protected:
|
|||
DescType type;
|
||||
DescStyle style;
|
||||
|
||||
void* base; // beginning of buffer
|
||||
unsigned int offset; // where we are in the buffer
|
||||
unsigned int size; // size of buffer in bytes
|
||||
void* base; // beginning of buffer
|
||||
unsigned int offset; // where we are in the buffer
|
||||
unsigned int size; // size of buffer in bytes
|
||||
|
||||
bool utf8; // whether valid utf-8 sequences may pass through unescaped
|
||||
bool escape; // escape unprintable characters in output?
|
||||
bool escape; // escape unprintable characters in output?
|
||||
bool is_short;
|
||||
bool want_quotes;
|
||||
bool want_determinism;
|
||||
|
@ -209,10 +222,10 @@ protected:
|
|||
using escape_set = std::set<std::string>;
|
||||
escape_set escape_sequences; // additional sequences of chars to escape
|
||||
|
||||
File* f; // or the file we're using.
|
||||
File* f; // or the file we're using.
|
||||
|
||||
std::set<const Type*> encountered_types;
|
||||
};
|
||||
};
|
||||
|
||||
// Returns a string representation of an object's description. Used for
|
||||
// debugging and error messages. takes a bare pointer rather than an
|
||||
|
@ -221,4 +234,4 @@ protected:
|
|||
class Obj;
|
||||
extern std::string obj_desc(const Obj* o);
|
||||
|
||||
} // namespace zeek
|
||||
} // namespace zeek
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue