*** empty log message ***

This commit is contained in:
dockes
2004-12-13 15:42:16 +00:00
parent 063727df38
commit 0786c283ef
4 changed files with 361 additions and 0 deletions
+51
View File
@@ -0,0 +1,51 @@
#ifndef lint
static char rcsid[] = "@(#$Id: mimetype.cpp,v 1.1 2004-12-13 15:42:16 dockes Exp $ (C) 2004 J.F.Dockes";
#endif
#include <ctype.h>
#include <string>
using std::string;
#include "mimetype.h"
string mimetype(const string &filename, ConfTree *mtypes)
{
// If filename has a suffix and we find it in the map, we're done
string::size_type dot = filename.find_last_of(".");
if (dot != string::npos) {
string suff = filename.substr(dot);
for (int i = 0; i < suff.length(); i++)
suff[i] = tolower(suff[i]);
string mtype;
if (mtypes->get(suff, mtype, ""))
return mtype;
}
// Look at file data
return "";
}
#ifdef _TEST_MIMETYPE_
#include <iostream>
const char *tvec[] = {
"/toto/tutu",
"/",
"toto.txt",
"toto.TXT",
"toto.C.txt",
"toto.C1",
"",
};
const int n = sizeof(tvec) / sizeof(char*);
using namespace std;
int main(int argc, const char **argv)
{
map<string, string>mtypes;
mtypes[".txt"] = "text/plain";
for (int i = 0; i < n; i++) {
cout << tvec[i] << " -> " << mimetype(string(tvec[i]), mtypes) << endl;
}
}
#endif
+16
View File
@@ -0,0 +1,16 @@
#ifndef _MIMETYPE_H_INCLUDED_
#define _MIMETYPE_H_INCLUDED_
/* @(#$Id: mimetype.h,v 1.1 2004-12-13 15:42:16 dockes Exp $ (C) 2004 J.F.Dockes */
#include <string>
#include "conftree.h"
/**
* Try to determine a mime type for filename.
* This may imply more than matching the suffix, the name must be usable
* to actually access file data.
*/
string mimetype(const std::string &filename, ConfTree *mtypes);
#endif /* _MIMETYPE_H_INCLUDED_ */
+74
View File
@@ -0,0 +1,74 @@
#ifndef lint
static char rcsid[] = "@(#$Id: recollindex.cpp,v 1.1 2004-12-13 15:42:16 dockes Exp $ (C) 2004 J.F.Dockes";
#endif
#include <iostream>
#include "pathut.h"
#include "conftree.h"
#include "rclconfig.h"
#include "fstreewalk.h"
#include "mimetype.h"
using namespace std;
class DirIndexer {
FsTreeWalker walker;
RclConfig *config;
string topdir;
public:
DirIndexer(RclConfig *cnf, const string &top)
: config(cnf), topdir(top)
{
}
friend FsTreeWalker::Status
indexfile(void *, const std::string &, const struct stat *,
FsTreeWalker::CbFlag);
void index()
{
walker.walk(topdir, indexfile, this);
}
};
FsTreeWalker::Status
indexfile(void *cdata, const std::string &fn,
const struct stat *stp, FsTreeWalker::CbFlag flg)
{
DirIndexer *me = (DirIndexer *)cdata;
if (flg == FsTreeWalker::FtwDirEnter || flg == FsTreeWalker::FtwDirReturn) {
// Possibly adjust defaults
cout << "indexfile: [" << fn << "]" << endl;
return FsTreeWalker::FtwOk;
}
string mtype = mimetype(fn, me->config->getMimeMap());
if (mtype.length() > 0)
cout << "indexfile: " << mtype << " " << fn << endl;
else
cout << "indexfile: " << "(nomime)" << " " << fn << endl;
}
int main(int argc, const char **argv)
{
RclConfig *config = new RclConfig;
if (!config->ok())
cerr << "Config could not be built" << endl;
ConfTree *conf = config->getConfig();
string topdirs;
if (conf->get("topdirs", topdirs, "") == 0) {
cerr << "No top directories in configuration" << endl;
exit(1);
}
list<string> tdl;
if (ConfTree::stringToStrings(topdirs, tdl)) {
for (list<string>::iterator it = tdl.begin(); it != tdl.end(); it++) {
cout << *it << endl;
DirIndexer indexer(config, *it);
indexer.index();
}
}
}