-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog_parser.cpp
70 lines (68 loc) · 2.06 KB
/
log_parser.cpp
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
63
64
65
66
67
68
69
70
#include <cstring>
#include <fstream>
#include <vector>
#include "compiler_output_parser.hpp"
int main(int argc, char* argv[])
{
if (argc < 2)
{
fprintf(stderr, "Usage %s <log file>\n", argv[0]);
return -1;
}
std::ifstream stream(argv[1]);
if (!stream.good())
{
fprintf(stderr, "Error opening file %s : %s\n", argv[0], strerror(errno));
return -1;
}
std::vector<CompilerOutputLineInfo> compilerOutputLineInfos;
std::string line;
while (std::getline(stream, line))
{
CompilerOutputLineInfo compilerOutputLineInfo = GetCompilerOutputLineInfo(line);
if (compilerOutputLineInfo.type != CompilerOutputLineType::normal)
{
compilerOutputLineInfos.push_back(std::move(compilerOutputLineInfo));
}
}
stream.close();
for (const CompilerOutputLineInfo& compilerOutputLineInfo : compilerOutputLineInfos)
{
const char* type;
switch (compilerOutputLineInfo.type)
{
case CompilerOutputLineType::warning:
type = "WARNING :";
break;
case CompilerOutputLineType::error:
type = "ERROR :";
break;
case CompilerOutputLineType::info:
type = "INFO :";
break;
default:
type = "UNKNOWN :";
break;
}
printf("%s ", type);
if (!compilerOutputLineInfo.fileName.empty())
{
if (compilerOutputLineInfo.fileName.at(0) == '/')
{
printf("file://%s ", compilerOutputLineInfo.fileName.c_str());
}
else
{
printf("%s", compilerOutputLineInfo.fileName.c_str());
}
if (!compilerOutputLineInfo.line.empty())
{
printf(":%s ", compilerOutputLineInfo.line.c_str());
}
}
if (!compilerOutputLineInfo.message.empty())
{
printf("%s\n", compilerOutputLineInfo.message.c_str());
}
}
}