mirror of https://github.com/kiwix/libkiwix.git
Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
8e08340efd
|
@ -1,91 +0,0 @@
|
||||||
/*-
|
|
||||||
* Copyright (c) 2004 - 2010 CTPP Team
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions
|
|
||||||
* are met:
|
|
||||||
* 1. Redistributions of source code must retain the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer.
|
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
|
||||||
* documentation and/or other materials provided with the distribution.
|
|
||||||
* 4. Neither the name of the CTPP Team nor the names of its contributors
|
|
||||||
* may be used to endorse or promote products derived from this software
|
|
||||||
* without specific prior written permission.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
||||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
||||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
||||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
||||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
||||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
||||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
||||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
||||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
||||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
||||||
* SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
* CTPP2SourceLoader.hpp
|
|
||||||
*
|
|
||||||
* $CTPP$
|
|
||||||
*/
|
|
||||||
#ifndef _CTPP2_TEXT_LOADER_H__
|
|
||||||
#define _CTPP2_TEXT_LOADER_H__ 1
|
|
||||||
|
|
||||||
#include "CTPP2SourceLoader.hpp"
|
|
||||||
|
|
||||||
#include "STLString.hpp"
|
|
||||||
|
|
||||||
/**
|
|
||||||
@file CTPP2FileSourceLoader.hpp
|
|
||||||
@brief Load template from file
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace CTPP // C++ Template Engine
|
|
||||||
{
|
|
||||||
|
|
||||||
/**
|
|
||||||
@class CTPP2FileSourceLoader CTPP2FileSourceLoader.hpp> <CTPP2FileSourceLoader.hpp>
|
|
||||||
@brief Load template from file
|
|
||||||
*/
|
|
||||||
class CTPP2DECL CTPP2TextLoader:
|
|
||||||
public CTPP2SourceLoader
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
/**
|
|
||||||
@brief Constructor
|
|
||||||
*/
|
|
||||||
CTPP2TextLoader();
|
|
||||||
|
|
||||||
/**
|
|
||||||
@brief Load template with specified name
|
|
||||||
@param szTemplateName - template name
|
|
||||||
@return 0 if success, -1 if any error occured
|
|
||||||
*/
|
|
||||||
INT_32 LoadTemplate(CCHAR_P szTemplateName);
|
|
||||||
|
|
||||||
/**
|
|
||||||
@brief Get template
|
|
||||||
@param iTemplateSize - template size [out]
|
|
||||||
@return pointer to start of template buffer if success, NULL - if any error occured
|
|
||||||
*/
|
|
||||||
CCHAR_P GetTemplate(UINT_32 & iTemplateSize);
|
|
||||||
|
|
||||||
/**
|
|
||||||
@brief Clone loader object
|
|
||||||
@return clone to self
|
|
||||||
*/
|
|
||||||
CTPP2SourceLoader * Clone();
|
|
||||||
|
|
||||||
/**
|
|
||||||
@brief A destructor
|
|
||||||
*/
|
|
||||||
~CTPP2TextLoader() throw();
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::string templateText;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace CTPP
|
|
||||||
#endif // _CTPP2_FILE_SOURCE_LOADER_H__
|
|
||||||
// End.
|
|
|
@ -0,0 +1,244 @@
|
||||||
|
/*-
|
||||||
|
* Copyright (c) 2004 - 2011 CTPP Team
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 4. Neither the name of the CTPP Team nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
* CTPP2VMStringLoader.cpp
|
||||||
|
*
|
||||||
|
* $CTPP$
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "CTPP2VMStringLoader.hpp"
|
||||||
|
|
||||||
|
#include "CTPP2Util.hpp"
|
||||||
|
#include "CTPP2Exception.hpp"
|
||||||
|
#include "CTPP2VMExecutable.hpp"
|
||||||
|
#include "CTPP2VMInstruction.hpp"
|
||||||
|
#include "CTPP2VMMemoryCore.hpp"
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include <resourceTools.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace CTPP // C++ Template Engine
|
||||||
|
{
|
||||||
|
|
||||||
|
//
|
||||||
|
// Convert byte order
|
||||||
|
//
|
||||||
|
static void ConvertExecutable(VMExecutable * oCore)
|
||||||
|
{
|
||||||
|
// Code entry point
|
||||||
|
oCore -> entry_point = Swap32(oCore -> entry_point);
|
||||||
|
// Offset of code segment
|
||||||
|
oCore -> code_offset = Swap32(oCore -> code_offset);
|
||||||
|
|
||||||
|
// Code segment size
|
||||||
|
oCore -> code_size = Swap32(oCore -> code_size);
|
||||||
|
|
||||||
|
// Offset of static text segment
|
||||||
|
oCore -> syscalls_offset = Swap32(oCore -> syscalls_offset);
|
||||||
|
// Static text segment size
|
||||||
|
oCore -> syscalls_data_size = Swap32(oCore -> syscalls_data_size);
|
||||||
|
|
||||||
|
// Offset of static text index segment
|
||||||
|
oCore -> syscalls_index_offset = Swap32(oCore -> syscalls_index_offset);
|
||||||
|
// Static text index segment size
|
||||||
|
oCore -> syscalls_index_size = Swap32(oCore -> syscalls_index_size);
|
||||||
|
|
||||||
|
// Offset of static data segment
|
||||||
|
oCore -> static_data_offset = Swap32(oCore -> static_data_offset);
|
||||||
|
|
||||||
|
// Static data segment size
|
||||||
|
oCore -> static_data_data_size = Swap32(oCore -> static_data_data_size);
|
||||||
|
|
||||||
|
// Offset of static text segment
|
||||||
|
oCore -> static_text_offset = Swap32(oCore -> static_text_offset);
|
||||||
|
// Static text segment size
|
||||||
|
oCore -> static_text_data_size = Swap32(oCore -> static_text_data_size);
|
||||||
|
|
||||||
|
// Offset of static text index segment
|
||||||
|
oCore -> static_text_index_offset = Swap32(oCore -> static_text_index_offset);
|
||||||
|
// Static text index segment size
|
||||||
|
oCore -> static_text_index_size = Swap32(oCore -> static_text_index_size);
|
||||||
|
|
||||||
|
// Version 2.2+
|
||||||
|
// Offset of static data bit index
|
||||||
|
oCore -> static_data_bit_index_offset = Swap32(oCore -> static_data_bit_index_offset);
|
||||||
|
/// Offset of static data bit index
|
||||||
|
oCore -> static_data_bit_index_size = Swap32(oCore -> static_data_bit_index_size);
|
||||||
|
|
||||||
|
// Platform
|
||||||
|
oCore -> platform = Swap64(oCore -> platform);
|
||||||
|
|
||||||
|
// Ugly-jolly hack!
|
||||||
|
// ... dereferencing type-punned pointer will break strict-aliasing rules ...
|
||||||
|
UINT_64 iTMP;
|
||||||
|
memcpy(&iTMP, &(oCore -> ieee754double), sizeof(UINT_64));
|
||||||
|
iTMP = Swap64(iTMP);
|
||||||
|
memcpy(&(oCore -> ieee754double), &iTMP, sizeof(UINT_64));
|
||||||
|
|
||||||
|
// Cyclic Redundancy Check
|
||||||
|
oCore -> crc = 0;
|
||||||
|
|
||||||
|
// Convert data structures
|
||||||
|
|
||||||
|
// Convert code segment
|
||||||
|
VMInstruction * pInstructions = const_cast<VMInstruction *>(VMExecutable::GetCodeSeg(oCore));
|
||||||
|
UINT_32 iI = 0;
|
||||||
|
UINT_32 iSteps = oCore -> code_size / sizeof(VMInstruction);
|
||||||
|
for(iI = 0; iI < iSteps; ++iI)
|
||||||
|
{
|
||||||
|
pInstructions -> instruction = Swap32(pInstructions -> instruction);
|
||||||
|
pInstructions -> argument = Swap32(pInstructions -> argument);
|
||||||
|
pInstructions -> reserved = Swap64(pInstructions -> reserved);
|
||||||
|
++pInstructions;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convert syscalls index
|
||||||
|
TextDataIndex * pTextIndex = const_cast<TextDataIndex *>(VMExecutable::GetSyscallsIndexSeg(oCore));
|
||||||
|
iSteps = oCore -> syscalls_index_size / sizeof(TextDataIndex);
|
||||||
|
for(iI = 0; iI < iSteps; ++iI)
|
||||||
|
{
|
||||||
|
pTextIndex -> offset = Swap32(pTextIndex -> offset);
|
||||||
|
pTextIndex -> length = Swap32(pTextIndex -> length);
|
||||||
|
++pTextIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convert static text index
|
||||||
|
pTextIndex = const_cast<TextDataIndex *>(VMExecutable::GetStaticTextIndexSeg(oCore));
|
||||||
|
iSteps = oCore -> static_text_index_size / sizeof(TextDataIndex);
|
||||||
|
for(iI = 0; iI < iSteps; ++iI)
|
||||||
|
{
|
||||||
|
pTextIndex -> offset = Swap32(pTextIndex -> offset);
|
||||||
|
pTextIndex -> length = Swap32(pTextIndex -> length);
|
||||||
|
++pTextIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convert static data
|
||||||
|
StaticDataVar * pStaticDataVar = const_cast<StaticDataVar *>(VMExecutable::GetStaticDataSeg(oCore));
|
||||||
|
iSteps = oCore -> static_data_data_size / sizeof(StaticDataVar);
|
||||||
|
for(iI = 0; iI < iSteps; ++iI)
|
||||||
|
{
|
||||||
|
(*pStaticDataVar).i_data = Swap64((*pStaticDataVar).i_data);
|
||||||
|
++pStaticDataVar;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Constructor
|
||||||
|
//
|
||||||
|
VMStringLoader::VMStringLoader(CCHAR_P rawContent, size_t rawContentSize)
|
||||||
|
{
|
||||||
|
oCore = (VMExecutable *)malloc(rawContentSize + 1);
|
||||||
|
memcpy(oCore, rawContent, rawContentSize);
|
||||||
|
|
||||||
|
if (oCore -> magic[0] == 'C' &&
|
||||||
|
oCore -> magic[1] == 'T' &&
|
||||||
|
oCore -> magic[2] == 'P' &&
|
||||||
|
oCore -> magic[3] == 'P')
|
||||||
|
{
|
||||||
|
// Check version
|
||||||
|
if (oCore -> version[0] >= 1)
|
||||||
|
{
|
||||||
|
// Platform-dependent data (byte order)
|
||||||
|
if (oCore -> platform == 0x4142434445464748ull)
|
||||||
|
{
|
||||||
|
#ifdef _DEBUG
|
||||||
|
fprintf(stderr, "Big/Little Endian conversion: Nothing to do\n");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Nothing to do, only check crc
|
||||||
|
UINT_32 iCRC = oCore -> crc;
|
||||||
|
oCore -> crc = 0;
|
||||||
|
|
||||||
|
// Calculate CRC of file
|
||||||
|
// KELSON: next line used to refer to oStat.st_size
|
||||||
|
// changed it to rawContentSize
|
||||||
|
if (iCRC != crc32((UCCHAR_P)oCore, rawContentSize))
|
||||||
|
{
|
||||||
|
free(oCore);
|
||||||
|
throw CTPPLogicError("CRC checksum invalid");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Platform-dependent data (byte order)
|
||||||
|
else if (oCore -> platform == 0x4847464544434241ull)
|
||||||
|
{
|
||||||
|
// Need to reconvert data
|
||||||
|
#ifdef _DEBUG
|
||||||
|
fprintf(stderr, "Big/Little Endian conversion: Need to reconvert core\n");
|
||||||
|
#endif
|
||||||
|
ConvertExecutable(oCore);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
free(oCore);
|
||||||
|
throw CTPPLogicError("Conversion of middle-end architecture does not supported.");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check IEEE 754 format
|
||||||
|
if (oCore -> ieee754double != 15839800103804824402926068484019465486336.0)
|
||||||
|
{
|
||||||
|
free(oCore);
|
||||||
|
throw CTPPLogicError("IEEE 754 format is broken, cannot convert file");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cout << "Last ?" << std::endl;
|
||||||
|
|
||||||
|
pVMMemoryCore = new VMMemoryCore(oCore);
|
||||||
|
|
||||||
|
std::cout << "last2" << std::endl;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
free(oCore);
|
||||||
|
throw CTPPLogicError("Not an CTPP bytecode file.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Get ready-to-run program
|
||||||
|
//
|
||||||
|
const VMMemoryCore * VMStringLoader::GetCore() const { return pVMMemoryCore; }
|
||||||
|
|
||||||
|
//
|
||||||
|
// A destructor
|
||||||
|
//
|
||||||
|
VMStringLoader::~VMStringLoader() throw()
|
||||||
|
{
|
||||||
|
delete pVMMemoryCore;
|
||||||
|
free(oCore);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace CTPP
|
||||||
|
// End.
|
|
@ -1,5 +1,5 @@
|
||||||
/*-
|
/*-
|
||||||
* Copyright (c) 2004 - 2010 CTPP Team
|
* Copyright (c) 2004 - 2011 CTPP Team
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
|
@ -25,66 +25,52 @@
|
||||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
* CTPP2FileSourceLoader.cpp
|
* CTPP2VMStringLoader.hpp
|
||||||
*
|
*
|
||||||
* $CTPP$
|
* $CTPP$
|
||||||
*/
|
*/
|
||||||
|
#ifndef _CTPP2_VM_STRING_LOADER_HPP__
|
||||||
|
#define _CTPP2_VM_STRING_LOADER_HPP__ 1
|
||||||
|
|
||||||
#include "CTPP2TextLoader.hpp"
|
#include "CTPP2VMLoader.hpp"
|
||||||
|
|
||||||
#include "CTPP2Exception.hpp"
|
|
||||||
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@file FileOutputCollector.hpp
|
@file VMStringLoader.hpp
|
||||||
@brief Virtual machine file output data collector
|
@brief Load program core from file
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace CTPP // C++ Template Engine
|
namespace CTPP // C++ Template Engine
|
||||||
{
|
{
|
||||||
|
// FWD
|
||||||
|
struct VMExecutable;
|
||||||
|
|
||||||
//
|
/**
|
||||||
// Clone loader
|
@class VMStringLoader CTPP2VMStringLoader.hpp <CTPP2VMStringLoader.hpp>
|
||||||
//
|
@brief Load program core from file
|
||||||
CTPP2SourceLoader * CTPP2TextLoader::Clone()
|
*/
|
||||||
|
class CTPP2DECL VMStringLoader:
|
||||||
|
public VMLoader
|
||||||
{
|
{
|
||||||
return new CTPP2TextLoader;
|
public:
|
||||||
}
|
/**
|
||||||
|
*/
|
||||||
|
VMStringLoader(CCHAR_P rawContent, size_t rawContentSize);
|
||||||
|
/**
|
||||||
|
@brief Get ready-to-run program
|
||||||
|
*/
|
||||||
|
const VMMemoryCore * GetCore() const;
|
||||||
|
|
||||||
//
|
/**
|
||||||
// Constructor
|
@brief A destructor
|
||||||
//
|
*/
|
||||||
CTPP2TextLoader::CTPP2TextLoader() {
|
~VMStringLoader() throw();
|
||||||
}
|
private:
|
||||||
|
/** Program core */
|
||||||
//
|
VMExecutable * oCore;
|
||||||
// Load template with specified name
|
/** Ready-to-run program */
|
||||||
//
|
VMMemoryCore * pVMMemoryCore;
|
||||||
INT_32 CTPP2TextLoader::LoadTemplate(CCHAR_P szTemplateName)
|
};
|
||||||
{
|
|
||||||
this->templateText = std::string(szTemplateName);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Get template
|
|
||||||
//
|
|
||||||
CCHAR_P CTPP2TextLoader::GetTemplate(UINT_32 & iITemplateSize)
|
|
||||||
{
|
|
||||||
iITemplateSize = this->templateText.size();
|
|
||||||
return this->templateText.data();
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// A destructor
|
|
||||||
//
|
|
||||||
CTPP2TextLoader::~CTPP2TextLoader() throw()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace CTPP
|
} // namespace CTPP
|
||||||
|
#endif // _CTPP2_VM_STRING_LOADER_HPP__
|
||||||
// End.
|
// End.
|
|
@ -36,7 +36,7 @@ using namespace std;
|
||||||
|
|
||||||
namespace kiwix {
|
namespace kiwix {
|
||||||
|
|
||||||
enum supportedIndexType { UNKNOWN, XAPIAN, CLUCENE };
|
enum supportedIndexType { UNKNOWN, XAPIAN };
|
||||||
|
|
||||||
class Book {
|
class Book {
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,7 @@ namespace kiwix {
|
||||||
book.last = (std::string(bookNode.attribute("last").value()) != "undefined" ?
|
book.last = (std::string(bookNode.attribute("last").value()) != "undefined" ?
|
||||||
bookNode.attribute("last").value() : "");
|
bookNode.attribute("last").value() : "");
|
||||||
book.indexPath = bookNode.attribute("indexPath").value();
|
book.indexPath = bookNode.attribute("indexPath").value();
|
||||||
book.indexType = (std::string(bookNode.attribute("indexType").value()) == "xapian" ? XAPIAN : CLUCENE);
|
book.indexType = XAPIAN;
|
||||||
book.title = bookNode.attribute("title").value();
|
book.title = bookNode.attribute("title").value();
|
||||||
book.description = bookNode.attribute("description").value();
|
book.description = bookNode.attribute("description").value();
|
||||||
book.language = bookNode.attribute("language").value();
|
book.language = bookNode.attribute("language").value();
|
||||||
|
@ -153,8 +153,6 @@ namespace kiwix {
|
||||||
if (!itr->indexPath.empty() || !itr->indexPathAbsolute.empty()) {
|
if (!itr->indexPath.empty() || !itr->indexPathAbsolute.empty()) {
|
||||||
if (itr->indexType == XAPIAN)
|
if (itr->indexType == XAPIAN)
|
||||||
bookNode.append_attribute("indexType") = "xapian";
|
bookNode.append_attribute("indexType") = "xapian";
|
||||||
else if (itr->indexType == CLUCENE)
|
|
||||||
bookNode.append_attribute("indexType") = "clucene";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (itr->origId.empty()) {
|
if (itr->origId.empty()) {
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
|
|
||||||
#include "searcher.h"
|
#include "searcher.h"
|
||||||
|
|
||||||
|
|
||||||
namespace kiwix {
|
namespace kiwix {
|
||||||
|
|
||||||
/* Constructor */
|
/* Constructor */
|
||||||
|
@ -30,15 +31,16 @@ namespace kiwix {
|
||||||
estimatedResultCount(0),
|
estimatedResultCount(0),
|
||||||
resultStart(0),
|
resultStart(0),
|
||||||
resultEnd(0),
|
resultEnd(0),
|
||||||
resultRange(20) {
|
resultRange(20)
|
||||||
|
{
|
||||||
|
template_ct2 = getResourceAsString("results.ct2");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Search strings in the database */
|
/* Search strings in the database */
|
||||||
void Searcher::search(std::string &search, const unsigned int resultStart,
|
void Searcher::search(std::string &search, const unsigned int resultStart,
|
||||||
const unsigned int resultEnd, const bool verbose) {
|
const unsigned int resultEnd, const bool verbose) {
|
||||||
|
|
||||||
this->reset();
|
this->reset();
|
||||||
|
|
||||||
if (verbose == true) {
|
if (verbose == true) {
|
||||||
cout << "Performing query `" << search << "'" << endl;
|
cout << "Performing query `" << search << "'" << endl;
|
||||||
}
|
}
|
||||||
|
@ -53,7 +55,7 @@ namespace kiwix {
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Reset the results */
|
/* Reset the results */
|
||||||
void Searcher::reset() {
|
void Searcher::reset() {
|
||||||
this->results.clear();
|
this->results.clear();
|
||||||
|
@ -67,25 +69,25 @@ namespace kiwix {
|
||||||
unsigned int Searcher::getEstimatedResultCount() {
|
unsigned int Searcher::getEstimatedResultCount() {
|
||||||
return this->estimatedResultCount;
|
return this->estimatedResultCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get next result */
|
/* Get next result */
|
||||||
bool Searcher::getNextResult(string &url, string &title, unsigned int &score) {
|
bool Searcher::getNextResult(string &url, string &title, unsigned int &score) {
|
||||||
bool retVal = false;
|
bool retVal = false;
|
||||||
|
|
||||||
if (this->resultOffset != this->results.end()) {
|
if (this->resultOffset != this->results.end()) {
|
||||||
|
|
||||||
/* url */
|
/* url */
|
||||||
url = this->resultOffset->url;
|
url = this->resultOffset->url;
|
||||||
|
|
||||||
/* title */
|
/* title */
|
||||||
title = this->resultOffset->title;
|
title = this->resultOffset->title;
|
||||||
|
|
||||||
/* score */
|
/* score */
|
||||||
score = this->resultOffset->score;
|
score = this->resultOffset->score;
|
||||||
|
|
||||||
/* increment the cursor for the next call */
|
/* increment the cursor for the next call */
|
||||||
this->resultOffset++;
|
this->resultOffset++;
|
||||||
|
|
||||||
retVal = true;
|
retVal = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,45 +109,8 @@ namespace kiwix {
|
||||||
}
|
}
|
||||||
|
|
||||||
string Searcher::getHtml() {
|
string Searcher::getHtml() {
|
||||||
|
|
||||||
VMOpcodeCollector oVMOpcodeCollector;
|
|
||||||
StaticText oSyscalls;
|
|
||||||
StaticData oStaticData;
|
|
||||||
StaticText oStaticText;
|
|
||||||
HashTable oHashTable;
|
|
||||||
CTPP2Compiler oCompiler(oVMOpcodeCollector, oSyscalls, oStaticData, oStaticText, oHashTable);
|
|
||||||
|
|
||||||
/* Load template & create template parser */
|
|
||||||
// cout << getResourceAsString("results.tmpl") << endl;
|
|
||||||
|
|
||||||
/* Parse template */
|
SimpleVM oSimpleVM;
|
||||||
const STLW::string & sSourceFile = getResourceAsString("results.tmpl");
|
|
||||||
CTPP2TextLoader oSourceLoader;
|
|
||||||
oSourceLoader.LoadTemplate(sSourceFile.c_str());
|
|
||||||
CTPP2Parser oCTPP2Parser(&oSourceLoader, &oCompiler, "template");
|
|
||||||
oCTPP2Parser.Compile();
|
|
||||||
|
|
||||||
// Get program core
|
|
||||||
UINT_32 iCodeSize = 0;
|
|
||||||
const VMInstruction * oVMInstruction = oVMOpcodeCollector.GetCode(iCodeSize);
|
|
||||||
|
|
||||||
// Dump program
|
|
||||||
VMDumper oDumper(iCodeSize, oVMInstruction, oSyscalls, oStaticData, oStaticText, oHashTable);
|
|
||||||
UINT_32 iSize = 0;
|
|
||||||
const VMExecutable * aProgramCore = oDumper.GetExecutable(iSize);
|
|
||||||
|
|
||||||
// Memory core
|
|
||||||
const VMMemoryCore vm_core(aProgramCore);
|
|
||||||
|
|
||||||
// Initiate the VM
|
|
||||||
SyscallFactory oSyscallFactory(100);
|
|
||||||
// Load standard library
|
|
||||||
STDLibInitializer::InitLibrary(oSyscallFactory);
|
|
||||||
|
|
||||||
VM * pVM = new VM(&oSyscallFactory);
|
|
||||||
|
|
||||||
// Initiate the logger
|
|
||||||
FileLogger oLogger(stderr);
|
|
||||||
|
|
||||||
// Fill data
|
// Fill data
|
||||||
CDT oData;
|
CDT oData;
|
||||||
|
@ -159,10 +124,10 @@ namespace kiwix {
|
||||||
result["snippet"] = this->resultOffset->snippet;
|
result["snippet"] = this->resultOffset->snippet;
|
||||||
|
|
||||||
if (this->resultOffset->size >= 0)
|
if (this->resultOffset->size >= 0)
|
||||||
result["size"] = kiwix::beautifyInteger(this->resultOffset->size);
|
result["size"] = kiwix::beautifyInteger(this->resultOffset->size);
|
||||||
|
|
||||||
if (this->resultOffset->wordCount >= 0)
|
if (this->resultOffset->wordCount >= 0)
|
||||||
result["wordCount"] = kiwix::beautifyInteger(this->resultOffset->wordCount);
|
result["wordCount"] = kiwix::beautifyInteger(this->resultOffset->wordCount);
|
||||||
|
|
||||||
resultsCDT.PushBack(result);
|
resultsCDT.PushBack(result);
|
||||||
this->resultOffset++;
|
this->resultOffset++;
|
||||||
|
@ -180,7 +145,7 @@ namespace kiwix {
|
||||||
pageCount = 10;
|
pageCount = 10;
|
||||||
else if (pageCount == 1)
|
else if (pageCount == 1)
|
||||||
pageCount = 0;
|
pageCount = 0;
|
||||||
|
|
||||||
for (unsigned int i=pageStart; i<pageStart+pageCount; i++) {
|
for (unsigned int i=pageStart; i<pageStart+pageCount; i++) {
|
||||||
CDT page;
|
CDT page;
|
||||||
page["label"] = i + 1;
|
page["label"] = i + 1;
|
||||||
|
@ -188,7 +153,7 @@ namespace kiwix {
|
||||||
page["end"] = (i+1) * this->resultCountPerPage;
|
page["end"] = (i+1) * this->resultCountPerPage;
|
||||||
|
|
||||||
if (i * this->resultCountPerPage == this->resultStart)
|
if (i * this->resultCountPerPage == this->resultStart)
|
||||||
page["selected"] = true;
|
page["selected"] = true;
|
||||||
|
|
||||||
pagesCDT.PushBack(page);
|
pagesCDT.PushBack(page);
|
||||||
}
|
}
|
||||||
|
@ -205,15 +170,23 @@ namespace kiwix {
|
||||||
oData["searchProtocolPrefix"] = this->searchProtocolPrefix;
|
oData["searchProtocolPrefix"] = this->searchProtocolPrefix;
|
||||||
oData["contentId"] = this->contentHumanReadableId;
|
oData["contentId"] = this->contentHumanReadableId;
|
||||||
|
|
||||||
STLW::string sResult;
|
VMStringLoader oLoader(template_ct2.c_str(), template_ct2.size());
|
||||||
StringOutputCollector oDataCollector(sResult);
|
|
||||||
|
|
||||||
// Run VM
|
FileLogger oLogger(stderr);
|
||||||
pVM->Init(&vm_core, &oDataCollector, &oLogger);
|
|
||||||
UINT_32 iIP = 0;
|
// DEBUG only (write output to stdout)
|
||||||
pVM -> Run(&vm_core, &oDataCollector, iIP, oData, &oLogger);
|
// oSimpleVM.Run(oData, oLoader, stdout, oLogger);
|
||||||
|
|
||||||
|
std::string sResult;
|
||||||
|
oSimpleVM.Run(oData, oLoader, sResult, oLogger);
|
||||||
|
|
||||||
return sResult;
|
return sResult;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Destructor */
|
||||||
|
Searcher::~Searcher() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,21 +29,14 @@
|
||||||
#include <cctype>
|
#include <cctype>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <resourceTools.h>
|
#include <resourceTools.h>
|
||||||
|
#include <pathTools.h>
|
||||||
#include <stringTools.h>
|
#include <stringTools.h>
|
||||||
|
|
||||||
#include <CTPP2Parser.hpp>
|
#include <CDT.hpp>
|
||||||
#include <CTPP2FileSourceLoader.hpp>
|
|
||||||
#include <CTPP2ParserException.hpp>
|
|
||||||
#include <CTPP2HashTable.hpp>
|
|
||||||
#include <CTPP2VMDumper.hpp>
|
|
||||||
#include <CTPP2VMOpcodes.h>
|
|
||||||
#include <CTPP2VM.hpp>
|
|
||||||
#include <CTPP2VMSTDLib.hpp>
|
|
||||||
#include <CTPP2StringOutputCollector.hpp>
|
|
||||||
#include <CTPP2SyscallFactory.hpp>
|
|
||||||
#include <CTPP2FileLogger.hpp>
|
#include <CTPP2FileLogger.hpp>
|
||||||
|
#include <CTPP2SimpleVM.hpp>
|
||||||
|
|
||||||
#include "ctpp2/CTPP2TextLoader.hpp"
|
#include "kiwix/ctpp2/CTPP2VMStringLoader.hpp"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace CTPP;
|
using namespace CTPP;
|
||||||
|
@ -56,16 +49,16 @@ struct Result
|
||||||
string snippet;
|
string snippet;
|
||||||
int wordCount;
|
int wordCount;
|
||||||
int size;
|
int size;
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace kiwix {
|
namespace kiwix {
|
||||||
|
|
||||||
class Searcher {
|
class Searcher {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Searcher();
|
Searcher();
|
||||||
|
|
||||||
void search(std::string &search, const unsigned int resultStart,
|
void search(std::string &search, const unsigned int resultStart,
|
||||||
const unsigned int resultEnd, const bool verbose=false);
|
const unsigned int resultEnd, const bool verbose=false);
|
||||||
bool getNextResult(string &url, string &title, unsigned int &score);
|
bool getNextResult(string &url, string &title, unsigned int &score);
|
||||||
unsigned int getEstimatedResultCount();
|
unsigned int getEstimatedResultCount();
|
||||||
|
@ -74,11 +67,12 @@ namespace kiwix {
|
||||||
string getHtml();
|
string getHtml();
|
||||||
void reset();
|
void reset();
|
||||||
void setContentHumanReadableId(const string &contentHumanReadableId);
|
void setContentHumanReadableId(const string &contentHumanReadableId);
|
||||||
|
~Searcher();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::string beautifyInteger(const unsigned int number);
|
std::string beautifyInteger(const unsigned int number);
|
||||||
virtual void closeIndex() = 0;
|
virtual void closeIndex() = 0;
|
||||||
virtual void searchInIndex(string &search, const unsigned int resultStart,
|
virtual void searchInIndex(string &search, const unsigned int resultStart,
|
||||||
const unsigned int resultEnd, const bool verbose=false) = 0;
|
const unsigned int resultEnd, const bool verbose=false) = 0;
|
||||||
|
|
||||||
std::vector<Result> results;
|
std::vector<Result> results;
|
||||||
|
@ -86,6 +80,7 @@ namespace kiwix {
|
||||||
std::string searchPattern;
|
std::string searchPattern;
|
||||||
std::string protocolPrefix;
|
std::string protocolPrefix;
|
||||||
std::string searchProtocolPrefix;
|
std::string searchProtocolPrefix;
|
||||||
|
std::string template_ct2;
|
||||||
unsigned int resultCountPerPage;
|
unsigned int resultCountPerPage;
|
||||||
unsigned int estimatedResultCount;
|
unsigned int estimatedResultCount;
|
||||||
unsigned int resultStart;
|
unsigned int resultStart;
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -26,13 +26,13 @@ do
|
||||||
FILE_ID=`echo "$FILE" | sed "s/\//_/g" | sed "s/\./_/g" | sed "s/\-/_/g"`
|
FILE_ID=`echo "$FILE" | sed "s/\//_/g" | sed "s/\./_/g" | sed "s/\-/_/g"`
|
||||||
echo "Inserting $FILE... [$FILE_ID]"
|
echo "Inserting $FILE... [$FILE_ID]"
|
||||||
reswrap -s -x -oa $RESOURCE_FILE -r $FILE_ID $FILE
|
reswrap -s -x -oa $RESOURCE_FILE -r $FILE_ID $FILE
|
||||||
MAP=$MAP"\tm[\""$FILE"\"] = std::pair <const unsigned char*, unsigned int>("$FILE_ID", sizeof "$FILE_ID"); \n";
|
MAP=$MAP"\tm[\""$FILE"\"] = std::pair <const unsigned char*, unsigned int>("$FILE_ID", sizeof "$FILE_ID"); \n";
|
||||||
done;
|
done;
|
||||||
MAP=$MAP"\treturn m; \n";
|
MAP=$MAP"\treturn m; \n";
|
||||||
MAP=$MAP"} \n\n"
|
MAP=$MAP"} \n\n"
|
||||||
MAP=$MAP"static std::map<std::string, std::pair<const unsigned char*, unsigned int> > resourceMap = createResourceMap(); \n\n"
|
MAP=$MAP"static std::map<std::string, std::pair<const unsigned char*, unsigned int> > resourceMap = createResourceMap(); \n\n"
|
||||||
|
|
||||||
# Create the map table
|
# Create the map table
|
||||||
# map<int, int> m = map_list_of (1,2) (3,4) (5,6) (7,8);
|
# map<int, int> m = map_list_of (1,2) (3,4) (5,6) (7,8);
|
||||||
echo $MAP >> "$RESOURCE_FILE"
|
echo $MAP >> "$RESOURCE_FILE"
|
||||||
|
|
||||||
|
|
Binary file not shown.
|
@ -9,32 +9,32 @@
|
||||||
margin-top: 0.5em;
|
margin-top: 0.5em;
|
||||||
font-size: 90%;
|
font-size: 90%;
|
||||||
}
|
}
|
||||||
|
|
||||||
a{
|
a{
|
||||||
color: #04c;
|
color: #04c;
|
||||||
}
|
}
|
||||||
|
|
||||||
a:visited {
|
a:visited {
|
||||||
color: #639
|
color: #639
|
||||||
}
|
}
|
||||||
|
|
||||||
a:hover {
|
a:hover {
|
||||||
text-decoration: underline
|
text-decoration: underline
|
||||||
}
|
}
|
||||||
|
|
||||||
.header {
|
.header {
|
||||||
font-size: 120%;
|
font-size: 120%;
|
||||||
}
|
}
|
||||||
|
|
||||||
ul {
|
ul {
|
||||||
margin:0;
|
margin:0;
|
||||||
padding:0
|
padding:0
|
||||||
}
|
}
|
||||||
|
|
||||||
.results {
|
.results {
|
||||||
font-size: 110%;
|
font-size: 110%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.results li {
|
.results li {
|
||||||
list-style-type:none;
|
list-style-type:none;
|
||||||
margin-top: 0.5em;
|
margin-top: 0.5em;
|
||||||
|
@ -50,7 +50,7 @@
|
||||||
word-wrap:break-word;
|
word-wrap:break-word;
|
||||||
display: block;
|
display: block;
|
||||||
font-size: 100%;
|
font-size: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.informations {
|
.informations {
|
||||||
color: #388222;
|
color: #388222;
|
||||||
|
@ -62,25 +62,25 @@
|
||||||
margin-top: 1em;
|
margin-top: 1em;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
float: left
|
float: left
|
||||||
}
|
}
|
||||||
|
|
||||||
.footer a, .footer span {
|
.footer a, .footer span {
|
||||||
display: block;
|
display: block;
|
||||||
padding: .3em .7em;
|
padding: .3em .7em;
|
||||||
margin: 0 .38em 0 0;
|
margin: 0 .38em 0 0;
|
||||||
text-align:center;
|
text-align:center;
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.footer a:hover {
|
.footer a:hover {
|
||||||
background: #ededed;
|
background: #ededed;
|
||||||
}
|
}
|
||||||
|
|
||||||
.footer ul, .footer li {
|
.footer ul, .footer li {
|
||||||
list-style:none;
|
list-style:none;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.footer li {
|
.footer li {
|
||||||
float: left;
|
float: left;
|
||||||
|
@ -88,42 +88,40 @@
|
||||||
|
|
||||||
.selected {
|
.selected {
|
||||||
background: #ededed;
|
background: #ededed;
|
||||||
}
|
}
|
||||||
|
|
||||||
</style>
|
</style>
|
||||||
<title>Search: <TMPL_var searchPattern></title>
|
<title>Search: <TMPL_var searchPattern></title>
|
||||||
</head>
|
</head>
|
||||||
<body bgcolor="white">
|
<body bgcolor="white">
|
||||||
<div class="header">
|
<div class="header">
|
||||||
<TMPL_if results>
|
<TMPL_if results>Results <b><TMPL_var resultStart>-<TMPL_var resultEnd></b> of <b><TMPL_var count></b> for <b><TMPL_var searchPattern></b><TMPL_else>No result were found for <b><TMPL_var searchPattern></b></TMPL_if>
|
||||||
Results <b><TMPL_var resultStart>-<TMPL_var resultEnd></b> of <b><TMPL_var count></b> for <b><TMPL_var searchPattern></b><TMPL_else>No result were found for <b><TMPL_var searchPattern></b></TMPL_if>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="results">
|
<div class="results">
|
||||||
<ul>
|
<ul>
|
||||||
|
<TMPL_foreach results as result>
|
||||||
<TMPL_loop results>
|
<li><a href="<TMPL_var protocolPrefix><TMPL_var contentId>/<TMPL_var result.url>"><TMPL_var result.title></a>
|
||||||
<li>
|
<cite><TMPL_if result.snippet><TMPL_var result.snippet>...</TMPL_if></cite>
|
||||||
<a href="<TMPL_var protocolPrefix><TMPL_var contentId>/<TMPL_var url>"><TMPL_var title></a>
|
<TMPL_if wordCount><div class="informations"><TMPL_var wordCount> words</div></TMPL_if>
|
||||||
<cite><TMPL_if snippet><TMPL_var snippet>...</TMPL_if></cite>
|
</li>
|
||||||
<TMPL_if wordCount><div class="informations"><TMPL_var wordCount> words</div></TMPL_if>
|
</TMPL_foreach>
|
||||||
</li>
|
</ul>
|
||||||
</TMPL_loop>
|
|
||||||
</ul>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="footer">
|
<div class="footer">
|
||||||
<ul>
|
<ul>
|
||||||
<TMPL_if (resultLastPageStart>0)>
|
<TMPL_if (resultLastPageStart>0)>
|
||||||
<li><a href="<TMPL_var searchProtocolPrefix>content=<TMPL_var contentId>&pattern=<TMPL_var searchPatternEncoded>&start=0&end=<TMPL_var resultRange>">◀</a></li>
|
<li><a href="<TMPL_var searchProtocolPrefix>content=<TMPL_var contentId>&pattern=<TMPL_var searchPatternEncoded>&start=0&end=<TMPL_var resultRange>">◀</a></li>
|
||||||
</TMPL_if>
|
</TMPL_if>
|
||||||
<TMPL_loop pages>
|
<TMPL_foreach pages as page>
|
||||||
<li><a <TMPL_if selected>class="selected"</TMPL_if> href="<TMPL_var searchProtocolPrefix>content=<TMPL_var contentId>&pattern=<TMPL_var searchPatternEncoded>&start=<TMPL_var start>&end=<TMPL_var end>"><TMPL_var label></a></li>
|
<li><a <TMPL_if page.selected>class="selected"</TMPL_if> href="<TMPL_var searchProtocolPrefix>content=<TMPL_var contentId>&pattern=<TMPL_var searchPatternEncoded>&start=<TMPL_var page.start>&end=<TMPL_var page.end>"><TMPL_var page.label></a></li>
|
||||||
</TMPL_LOOP>
|
</TMPL_foreach>
|
||||||
<TMPL_if (resultLastPageStart>0)>
|
<TMPL_if (resultLastPageStart>0)>
|
||||||
<li><a href="<TMPL_var searchProtocolPrefix>content=<TMPL_var contentId>&pattern=<TMPL_var searchPatternEncoded>&start=<TMPL_var resultLastPageStart>&end=<TMPL_var (resultLastPageStart+resultRange)>">▶</a></li>
|
<li><a href="<TMPL_var searchProtocolPrefix>content=<TMPL_var contentId>&pattern=<TMPL_var searchPatternEncoded>&start=<TMPL_var resultLastPageStart>&end=<TMPL_var (resultLastPageStart+resultRange)>">▶</a></li>
|
||||||
</TMPL_if>
|
</TMPL_if>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
Loading…
Reference in New Issue