Skip to content

Commit

Permalink
fix: unable to load console input il
Browse files Browse the repository at this point in the history
  • Loading branch information
QRWells committed Jun 27, 2023
1 parent c3f1f65 commit 37dc59c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
14 changes: 5 additions & 9 deletions src/element/re2c/file_buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,31 +45,27 @@
#include "../exception.hpp"
#include "buffer.hpp"

namespace slim {
namespace element {
namespace re2c {
namespace slim::element::re2c {
class file_buffer : public buffer {
std::unique_ptr<std::ifstream> ifs;

public:
file_buffer(const std::string &file_path, int fill_size, int size = 256)
: buffer(fill_size, size), ifs(std::unique_ptr<std::ifstream>(new std::ifstream(file_path))) {
: buffer(fill_size, size), ifs(std::make_unique<std::ifstream>(file_path)) {
if (ifs->fail())
throw exception("cannot open file '" + file_path + "'");
}

file_buffer(std::unique_ptr<std::ifstream> ifs, int fill_size, int size = 256)
: buffer(fill_size, size), ifs(std::move(ifs)) {}

bool is_finished() const { return ifs->eof(); }
bool is_finished() const override { return ifs->eof(); }

void update_limit(size_t free) {
void update_limit(size_t free) override {
ifs->read(YYLIMIT, free);
YYLIMIT += ifs->gcount();
}
};
} // namespace re2c
} // namespace element
} // namespace slim
} // namespace slim::element::re2c

#endif /* ELEMENT_RE2C_FILE_BUFFER_HPP */
3 changes: 2 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,14 @@ static inline void slim_finalize() {
slim::element::LifetimeProfiler::check_memory_leak();
}

static inline bool load_input_files(std::vector<LmnRuleSetRef> &start_rulesets, std::vector<std::string> const &files) {
bool load_input_files(std::vector<LmnRuleSetRef> &start_rulesets, std::vector<std::string> const &files) {
for (auto const &f : files) {
LmnRuleSetRef t;

try {
if (f == "-") { /* 標準入力からの読込み */
t = load(std::unique_ptr<FILE, decltype(&fclose)>(stdin, [](FILE *) -> int { return 0; }));
start_rulesets.push_back(t);
} else {
t = load_file(f);
if (t != nullptr) {
Expand Down

0 comments on commit 37dc59c

Please sign in to comment.