-
Notifications
You must be signed in to change notification settings - Fork 0
/
CCExecutionInput.cpp
40 lines (35 loc) · 1.03 KB
/
CCExecutionInput.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
//
// CCExecutionInput.cpp
// ncc
//
// Created by yuki on 2022/04/21.
//
#include "CCExecutionInput.hpp"
#include <iterator>
CCExecutionInput::CCExecutionInput(vector<string> _args) {
this->args = _args;
this->build_commandline(_args);
this->build_file_contents(_args);
}
void CCExecutionInput::build_commandline(vector<string> args) {
auto os = ostringstream();
copy(args.begin(), args.end(), ostream_iterator<string>(os, " "));
this->commandline = os.str();
}
void CCExecutionInput::build_file_contents(vector<string> args) {
auto cfiles = extract_cfiles(args);
for (auto cfile: cfiles) {
auto ifs = ifstream(cfile);
stringstream buffer;
buffer << ifs.rdbuf();
auto content = buffer.str();
this->file_contents[cfile] = content;
}
}
auto CCExecutionInput::extract_cfiles(vector<string> args) -> vector<string> {
vector<string> res;
for (auto &e: args) {
if (e.size() > 2 && e.substr(e.size()-2, 2) == ".c") res.push_back(e);
}
return res;
}