mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
factor out "print" statement's execution functionality
This commit is contained in:
parent
b792feccab
commit
22776167bb
3 changed files with 15 additions and 9 deletions
|
@ -12,8 +12,7 @@
|
||||||
#include <krb5.h>
|
#include <krb5.h>
|
||||||
#endif // NEED_KRB5_H
|
#endif // NEED_KRB5_H
|
||||||
|
|
||||||
#include "zeek/Obj.h"
|
#include "zeek/Val.h"
|
||||||
#include "zeek/IntrusivePtr.h"
|
|
||||||
#include "zeek/util.h"
|
#include "zeek/util.h"
|
||||||
|
|
||||||
namespace zeek {
|
namespace zeek {
|
||||||
|
@ -23,6 +22,8 @@ namespace detail {
|
||||||
class PrintStmt;
|
class PrintStmt;
|
||||||
class Attributes;
|
class Attributes;
|
||||||
|
|
||||||
|
extern void do_print_stmt(const std::vector<ValPtr>& vals);
|
||||||
|
|
||||||
} // namespace detail;
|
} // namespace detail;
|
||||||
|
|
||||||
class RecordVal;
|
class RecordVal;
|
||||||
|
@ -84,7 +85,7 @@ public:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
friend class detail::PrintStmt;
|
friend void detail::do_print_stmt(const std::vector<ValPtr>& vals);
|
||||||
|
|
||||||
File() { Init(); }
|
File() { Init(); }
|
||||||
void Init();
|
void Init();
|
||||||
|
|
15
src/Stmt.cc
15
src/Stmt.cc
|
@ -306,18 +306,23 @@ ValPtr PrintStmt::DoExec(std::vector<ValPtr> vals,
|
||||||
StmtFlowType& /* flow */)
|
StmtFlowType& /* flow */)
|
||||||
{
|
{
|
||||||
RegisterAccess();
|
RegisterAccess();
|
||||||
|
do_print_stmt(vals);
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void do_print_stmt(const std::vector<ValPtr>& vals)
|
||||||
|
{
|
||||||
if ( ! print_stdout )
|
if ( ! print_stdout )
|
||||||
print_stdout = new File(stdout);
|
print_stdout = new File(stdout);
|
||||||
|
|
||||||
File* f = print_stdout;
|
File* f = print_stdout;
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
|
|
||||||
if ( vals.size() > 0 && (vals)[0]->GetType()->Tag() == TYPE_FILE )
|
if ( vals.size() > 0 && vals[0] && vals[0]->GetType()->Tag() == TYPE_FILE )
|
||||||
{
|
{
|
||||||
f = (vals)[0]->AsFile();
|
f = (vals)[0]->AsFile();
|
||||||
if ( ! f->IsOpen() )
|
if ( ! f->IsOpen() )
|
||||||
return nullptr;
|
return;
|
||||||
|
|
||||||
++offset;
|
++offset;
|
||||||
}
|
}
|
||||||
|
@ -331,7 +336,7 @@ ValPtr PrintStmt::DoExec(std::vector<ValPtr> vals,
|
||||||
case BifEnum::Log::REDIRECT_ALL:
|
case BifEnum::Log::REDIRECT_ALL:
|
||||||
{
|
{
|
||||||
print_log(vals);
|
print_log(vals);
|
||||||
return nullptr;
|
return;
|
||||||
}
|
}
|
||||||
case BifEnum::Log::REDIRECT_STDOUT:
|
case BifEnum::Log::REDIRECT_STDOUT:
|
||||||
if ( f->FileHandle() == stdout )
|
if ( f->FileHandle() == stdout )
|
||||||
|
@ -339,7 +344,7 @@ ValPtr PrintStmt::DoExec(std::vector<ValPtr> vals,
|
||||||
// Should catch even printing to a "manually opened" stdout file,
|
// Should catch even printing to a "manually opened" stdout file,
|
||||||
// like "/dev/stdout" or "-".
|
// like "/dev/stdout" or "-".
|
||||||
print_log(vals);
|
print_log(vals);
|
||||||
return nullptr;
|
return;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -368,8 +373,6 @@ ValPtr PrintStmt::DoExec(std::vector<ValPtr> vals,
|
||||||
describe_vals(vals, &d, offset);
|
describe_vals(vals, &d, offset);
|
||||||
f->Write("\n", 1);
|
f->Write("\n", 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ExprStmt::ExprStmt(ExprPtr arg_e) : Stmt(STMT_EXPR), e(std::move(arg_e))
|
ExprStmt::ExprStmt(ExprPtr arg_e) : Stmt(STMT_EXPR), e(std::move(arg_e))
|
||||||
|
|
|
@ -62,6 +62,8 @@ protected:
|
||||||
StmtPtr DoSubclassReduce(ListExprPtr singletons, Reducer* c) override;
|
StmtPtr DoSubclassReduce(ListExprPtr singletons, Reducer* c) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
extern void do_print_stmt(const std::vector<ValPtr>& vals);
|
||||||
|
|
||||||
class ExprStmt : public Stmt {
|
class ExprStmt : public Stmt {
|
||||||
public:
|
public:
|
||||||
explicit ExprStmt(ExprPtr e);
|
explicit ExprStmt(ExprPtr e);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue