From ab3f5bcb9c1ea73f06977467374344282b50cb8b Mon Sep 17 00:00:00 2001 From: ShikiSuen Date: Wed, 12 Jan 2022 13:11:26 +0800 Subject: [PATCH] Shiki #15 FastLM Patch // + \n to the end of LM data if not exist. --- Source/Engine/FastLM.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/Source/Engine/FastLM.cpp b/Source/Engine/FastLM.cpp index 48569c65..7d759c7a 100644 --- a/Source/Engine/FastLM.cpp +++ b/Source/Engine/FastLM.cpp @@ -31,6 +31,7 @@ #include #include #include +#include using namespace Formosa::Gramambular; @@ -53,7 +54,23 @@ bool FastLM::open(const char *path) if (data) { return false; } - + + fstream zfd(path); + zfd.seekg(-1,ios_base::end); + char z; + zfd.get(z); + if(z!='\n'){ + syslog(LOG_CONS, "REPORT: File is not ended with a new line.\n"); + syslog(LOG_CONS, "PROCEDURE: Trying to insert a new line as EOF before per-line check process.\n"); + ofstream zfdo(path, std::ios_base::app); + zfdo << std::endl; + zfdo.close(); + if (zfdo.fail()) { + syslog(LOG_CONS, "REPORT: Failed to append a newline to the data file. Insufficient Privileges?\n"); + return false; + } + } + fd = ::open(path, O_RDONLY); if (fd == -1) { return false;