Ensure the EOF \n in both UserPhrases and Replacement Map.
This commit is contained in:
parent
842f3e12de
commit
73a0730c9e
|
@ -41,7 +41,7 @@ bool FastLM::open(const char *path)
|
|||
char z;
|
||||
zfd.get(z);
|
||||
if(z!='\n'){
|
||||
syslog(LOG_CONS, "REPORT: File is not ended with a new line.\n");
|
||||
syslog(LOG_CONS, "REPORT: Core Language Data 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;
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
* Some rights reserved. See "LICENSE.TXT" for details.
|
||||
*/
|
||||
|
||||
#include <syslog.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
|
@ -38,6 +39,22 @@ bool PhraseReplacementMap::open(const char *path)
|
|||
return false;
|
||||
}
|
||||
|
||||
std::fstream zfd(path);
|
||||
zfd.seekg(-1,std::ios_base::end);
|
||||
char z;
|
||||
zfd.get(z);
|
||||
if(z!='\n'){
|
||||
syslog(LOG_CONS, "REPORT: Phrase Replacement Map 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");
|
||||
std::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) {
|
||||
printf("open:: file not exist");
|
||||
|
|
|
@ -7,12 +7,12 @@
|
|||
*/
|
||||
|
||||
#include "UserPhrasesLM.h"
|
||||
|
||||
#include <sys/mman.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <fstream>
|
||||
#include <unistd.h>
|
||||
#include <syslog.h>
|
||||
|
||||
#include "KeyValueBlobReader.h"
|
||||
|
||||
|
@ -38,6 +38,22 @@ bool UserPhrasesLM::open(const char *path)
|
|||
return false;
|
||||
}
|
||||
|
||||
std::fstream zfd(path);
|
||||
zfd.seekg(-1,std::ios_base::end);
|
||||
char z;
|
||||
zfd.get(z);
|
||||
if(z!='\n'){
|
||||
syslog(LOG_CONS, "REPORT: User Phrase Data 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");
|
||||
std::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) {
|
||||
printf("open:: file not exist");
|
||||
|
|
Loading…
Reference in New Issue