Skip to content

Commit a1d04ae

Browse files
committed
fdsdump: extract main lister component
1 parent f0ada73 commit a1d04ae

File tree

4 files changed

+84
-74
lines changed

4 files changed

+84
-74
lines changed

src/tools/fdsdump/src/lister/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Create a lister "object" library
22
set(LISTER_SRC
3+
lister.cpp
34
printer.cpp
45
jsonPrinter.cpp
56
jsonRawPrinter.cpp
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#include "lister.hpp"
2+
#include "printer.hpp"
3+
#include "storageSorted.hpp"
4+
5+
static void
6+
mode_list_unordered(const shared_iemgr &iemgr, const Options &opts, FlowProvider &flows)
7+
{
8+
auto printer = printer_factory(iemgr, opts.get_output_specifier());
9+
const size_t rec_limit = opts.get_output_limit();
10+
size_t rec_printed = 0;
11+
12+
printer->print_prologue();
13+
14+
while (rec_limit == 0 || rec_printed < rec_limit) {
15+
Flow *flow = flows.next_record();
16+
17+
if (!flow) {
18+
break;
19+
}
20+
21+
rec_printed += printer->print_record(flow);
22+
}
23+
24+
printer->print_epilogue();
25+
}
26+
27+
static void
28+
mode_list_ordered(const shared_iemgr &iemgr, const Options &opts, FlowProvider &flows)
29+
{
30+
StorageSorter sorter {opts.get_order_by(), iemgr};
31+
StorageSorted storage {sorter, opts.get_output_limit()};
32+
auto printer = printer_factory(iemgr, opts.get_output_specifier());
33+
34+
while (true) {
35+
Flow *flow = flows.next_record();
36+
37+
if (!flow) {
38+
break;
39+
}
40+
41+
storage.insert(flow);
42+
}
43+
44+
printer->print_prologue();
45+
46+
for (const auto &rec : storage) {
47+
const Flow *flow = &rec.get_flow_const();
48+
printer->print_record(const_cast<Flow *>(flow));
49+
}
50+
51+
printer->print_epilogue();
52+
}
53+
54+
void
55+
mode_list(const shared_iemgr &iemgr, const Options &opts)
56+
{
57+
FlowProvider flows {iemgr};
58+
59+
flows.set_biflow_autoignore(opts.get_biflow_autoignore());
60+
61+
if (!opts.get_input_filter().empty()) {
62+
flows.set_filter(opts.get_input_filter());
63+
}
64+
65+
for (const auto &it : opts.get_input_files()) {
66+
flows.add_file(it);
67+
}
68+
69+
if (opts.get_order_by().empty()) {
70+
mode_list_unordered(iemgr, opts, flows);
71+
} else {
72+
mode_list_ordered(iemgr, opts, flows);
73+
}
74+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
#pragma once
3+
4+
#include <options.hpp>
5+
#include <common/flowProvider.hpp>
6+
7+
void
8+
mode_list(const shared_iemgr &iemgr, const Options &opts);

src/tools/fdsdump/src/main.cpp

Lines changed: 1 addition & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88

99
#include <common/common.hpp>
1010
#include <common/filelist.hpp>
11-
#include <common/flowProvider.hpp>
12-
#include <lister/printer.hpp>
13-
#include <lister/storageSorted.hpp>
11+
#include <lister/lister.hpp>
1412

1513
#include "options.hpp"
1614

@@ -39,77 +37,6 @@ static void fds_iemgr_deleter(fds_iemgr_t *mgr) {
3937
}
4038
}
4139

42-
static void
43-
mode_list_unordered(const shared_iemgr &iemgr, const Options &opts, FlowProvider &flows)
44-
{
45-
auto printer = printer_factory(iemgr, opts.get_output_specifier());
46-
const size_t rec_limit = opts.get_output_limit();
47-
size_t rec_printed = 0;
48-
49-
printer->print_prologue();
50-
51-
while (rec_limit == 0 || rec_printed < rec_limit) {
52-
Flow *flow = flows.next_record();
53-
54-
if (!flow) {
55-
break;
56-
}
57-
58-
rec_printed += printer->print_record(flow);
59-
}
60-
61-
printer->print_epilogue();
62-
}
63-
64-
static void
65-
mode_list_ordered(const shared_iemgr &iemgr, const Options &opts, FlowProvider &flows)
66-
{
67-
StorageSorter sorter {opts.get_order_by(), iemgr};
68-
StorageSorted storage {sorter, opts.get_output_limit()};
69-
auto printer = printer_factory(iemgr, opts.get_output_specifier());
70-
71-
while (true) {
72-
Flow *flow = flows.next_record();
73-
74-
if (!flow) {
75-
break;
76-
}
77-
78-
storage.insert(flow);
79-
}
80-
81-
printer->print_prologue();
82-
83-
for (const auto &rec : storage) {
84-
const Flow *flow = &rec.get_flow_const();
85-
printer->print_record(const_cast<Flow *>(flow));
86-
}
87-
88-
printer->print_epilogue();
89-
}
90-
91-
static void
92-
mode_list(const shared_iemgr &iemgr, const Options &opts)
93-
{
94-
FlowProvider flows {iemgr};
95-
96-
flows.set_biflow_autoignore(opts.get_biflow_autoignore());
97-
98-
if (!opts.get_input_filter().empty()) {
99-
flows.set_filter(opts.get_input_filter());
100-
}
101-
102-
for (const auto &it : opts.get_input_files()) {
103-
flows.add_file(it);
104-
}
105-
106-
if (opts.get_order_by().empty()) {
107-
mode_list_unordered(iemgr, opts, flows);
108-
} else {
109-
mode_list_ordered(iemgr, opts, flows);
110-
}
111-
}
112-
11340
int
11441
main(int argc, char *argv[])
11542
{

0 commit comments

Comments
 (0)