-
Notifications
You must be signed in to change notification settings - Fork 5
/
bugs.cc
62 lines (51 loc) · 1.47 KB
/
bugs.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright © 2022 Alexandre Detiste <[email protected]>
// SPDX-License-Identifier: GPL-2.0-or-later
#include <fstream>
#include <iostream>
#include <sstream>
#include <map>
#include "owner.h"
#include "bugs.h"
using namespace std;
bug::bug( std::string package_, std::string bugno_ )
{
package = std::move(package_);
bugno = std::move(bugno_);
}
bool operator<(bug const& l, bug const &r)
{
return l.bugno < r.bugno;
}
static void error(const string& bugs_path, const string& bugs_line)
{
cerr << bugs_path << " is corrupted here: " << bugs_line << '\n';
}
void read_bugs(map<string, bug>& bugs, const string& bugs_path)
{
ifstream bugs_file(bugs_path);
if (!bugs_file.is_open())
bugs_file.open("/usr/share/cruft/bugs");
for (string bugs_line; getline(bugs_file, bugs_line);)
{
if (bugs_line.empty()) continue;
stringstream ss (bugs_line);
string path, bug_nr, package;
if(!getline (ss, path, ' ')) return error(bugs_path, bugs_line);
if(!getline (ss, bug_nr, ' ')) return error(bugs_path, bugs_line);
if(!getline (ss, package, ' ')) return error(bugs_path, bugs_line);
bug entry(package, bug_nr);
bugs.emplace(std::move(path), std::move(entry));
}
}
#ifdef UNIT_TEST
//clang++ -DUNIT_TEST bugs.cc owner.cc -o test_bugs && ./test_bugs
int main()
{
map<string, bug> bugs;
read_bugs(bugs, "bugs");
for(const auto& bug: bugs)
{
std::cout << bug.first << ' ' << bug.second.package << ' ' << bug.second.bugno << '\n';
}
}
#endif