minimal experimental stopword functionality

This commit is contained in:
dockes
2007-06-02 08:30:42 +00:00
parent fcb2762048
commit 0f1b917b7b
14 changed files with 259 additions and 35 deletions
+16 -5
View File
@@ -1,5 +1,5 @@
#ifndef lint
static char rcsid[] = "@(#$Id: readfile.cpp,v 1.3 2006-01-23 13:32:28 dockes Exp $ (C) 2004 J.F.Dockes";
static char rcsid[] = "@(#$Id: readfile.cpp,v 1.4 2007-06-02 08:30:42 dockes Exp $ (C) 2004 J.F.Dockes";
#endif
/*
* This program is free software; you can redistribute it and/or modify
@@ -32,20 +32,28 @@ using std::string;
#include "readfile.h"
bool file_to_string(const string &fn, string &data)
bool file_to_string(const string &fn, string &data, string *reason)
{
#define ERRBUFSZ 200
char errbuf[ERRBUFSZ];
bool ret = false;
int fd = open(fn.c_str(), O_RDONLY|O_STREAMING);
if (fd < 0) {
// perror("open");
if (reason) {
strerror_r(errno, errbuf, ERRBUFSZ);
*reason += string("file_to_string: open failed: ") + errbuf;
}
return false;
}
char buf[4096];
for (;;) {
int n = read(fd, buf, 4096);
if (n < 0) {
// perror("read");
if (reason) {
strerror_r(errno, errbuf, ERRBUFSZ);
*reason += string("file_to_string: read failed: ") + errbuf;
}
goto out;
}
if (n == 0)
@@ -54,7 +62,10 @@ bool file_to_string(const string &fn, string &data)
try {
data.append(buf, n);
} catch (...) {
// fprintf(stderr, "file_to_string: out of memory\n");
if (reason) {
strerror_r(errno, errbuf, ERRBUFSZ);
*reason += string("file_to_string: out of memory? : ") +errbuf;
}
goto out;
}
}
+3 -2
View File
@@ -16,7 +16,7 @@
*/
#ifndef _READFILE_H_INCLUDED_
#define _READFILE_H_INCLUDED_
/* @(#$Id: readfile.h,v 1.2 2006-01-30 11:15:28 dockes Exp $ (C) 2004 J.F.Dockes */
/* @(#$Id: readfile.h,v 1.3 2007-06-02 08:30:42 dockes Exp $ (C) 2004 J.F.Dockes */
#include <string>
@@ -24,6 +24,7 @@
* Read whole file into string.
* @return true for ok, false else
*/
bool file_to_string(const std::string &filename, std::string &data);
bool file_to_string(const std::string &filename, std::string &data,
std::string *reason = 0);
#endif /* _READFILE_H_INCLUDED_ */