mirror of https://github.com/kiwix/libkiwix.git
Move the templating system to mustache instead of ctpp2.
Mustache templating system is a bit simpler than ctpp2 and ctpp2 is no more maintained (see #189). We are moving to the kainjow's Mustache project (https://github.com/kainjow/Mustache). It simplify a lot our system has it is header only and we don't have to precompile the template. Fix #21
This commit is contained in:
parent
c73ac9f2cd
commit
92c9a47a0d
|
@ -33,8 +33,6 @@ libraries need to be available:
|
||||||
(package libzim-dev on Ubuntu)
|
(package libzim-dev on Ubuntu)
|
||||||
* Pugixml ........................................ http://pugixml.org/
|
* Pugixml ........................................ http://pugixml.org/
|
||||||
(package libpugixml-dev on Ubuntu)
|
(package libpugixml-dev on Ubuntu)
|
||||||
* ctpp2 ........................................ http://ctpp.havoc.ru/
|
|
||||||
(package libctpp2-dev on Ubuntu)
|
|
||||||
* libaria2 .................................. https://aria2.github.io/
|
* libaria2 .................................. https://aria2.github.io/
|
||||||
(no package on Ubuntu)
|
(no package on Ubuntu)
|
||||||
|
|
||||||
|
@ -47,10 +45,6 @@ version by hand.
|
||||||
If you want to install these dependencies locally, then use the
|
If you want to install these dependencies locally, then use the
|
||||||
kiwix-lib directory as install prefix.
|
kiwix-lib directory as install prefix.
|
||||||
|
|
||||||
If you compile ctpp2 from source and want to compile the Kiwix library
|
|
||||||
statically then you will probably need to rename ctpp2 static library
|
|
||||||
from ctpp2-st.a to ctpp2.a.
|
|
||||||
|
|
||||||
Environment
|
Environment
|
||||||
-------------
|
-------------
|
||||||
|
|
||||||
|
|
|
@ -1,79 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2013 Renaud Gaudin <reg@kiwix.org>
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation; either version 3 of the License, or
|
|
||||||
* any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program; if not, write to the Free Software
|
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
||||||
* MA 02110-1301, USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef _CTPP2_VM_STRING_LOADER_HPP__
|
|
||||||
#define _CTPP2_VM_STRING_LOADER_HPP__ 1
|
|
||||||
|
|
||||||
#include <ctpp2/CTPP2VMLoader.hpp>
|
|
||||||
#include <ctpp2/CTPP2Util.hpp>
|
|
||||||
#include <ctpp2/CTPP2Exception.hpp>
|
|
||||||
#include <ctpp2/CTPP2VMExecutable.hpp>
|
|
||||||
#include <ctpp2/CTPP2VMInstruction.hpp>
|
|
||||||
#include <ctpp2/CTPP2VMMemoryCore.hpp>
|
|
||||||
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
|
|
||||||
#include <errno.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
/**
|
|
||||||
@file VMStringLoader.hpp
|
|
||||||
@brief Load program core from file
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace CTPP // C++ Template Engine
|
|
||||||
{
|
|
||||||
// FWD
|
|
||||||
struct VMExecutable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
@class VMStringLoader CTPP2VMStringLoader.hpp <CTPP2VMStringLoader.hpp>
|
|
||||||
@brief Load program core from file
|
|
||||||
*/
|
|
||||||
class CTPP2DECL VMStringLoader:
|
|
||||||
public VMLoader
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
/**
|
|
||||||
*/
|
|
||||||
VMStringLoader(CCHAR_P rawContent, size_t rawContentSize);
|
|
||||||
/**
|
|
||||||
@brief Get ready-to-run program
|
|
||||||
*/
|
|
||||||
const VMMemoryCore * GetCore() const;
|
|
||||||
|
|
||||||
/**
|
|
||||||
@brief A destructor
|
|
||||||
*/
|
|
||||||
~VMStringLoader() throw();
|
|
||||||
private:
|
|
||||||
/** Program core */
|
|
||||||
VMExecutable * oCore;
|
|
||||||
/** Ready-to-run program */
|
|
||||||
VMMemoryCore * pVMMemoryCore;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace CTPP
|
|
||||||
#endif // _CTPP2_VM_STRING_LOADER_HPP__
|
|
||||||
// End.
|
|
|
@ -24,10 +24,3 @@ install_headers(
|
||||||
subdir:'kiwix/common'
|
subdir:'kiwix/common'
|
||||||
)
|
)
|
||||||
|
|
||||||
if has_ctpp2_dep
|
|
||||||
install_headers(
|
|
||||||
'ctpp2/CTPP2VMStringLoader.hpp',
|
|
||||||
subdir:'kiwix/ctpp2'
|
|
||||||
)
|
|
||||||
endif
|
|
||||||
|
|
||||||
|
|
|
@ -163,12 +163,10 @@ class Searcher
|
||||||
*/
|
*/
|
||||||
bool setSearchProtocolPrefix(const std::string prefix);
|
bool setSearchProtocolPrefix(const std::string prefix);
|
||||||
|
|
||||||
#ifdef ENABLE_CTPP2
|
|
||||||
/**
|
/**
|
||||||
* Generate the html page with the resutls of the search.
|
* Generate the html page with the resutls of the search.
|
||||||
*/
|
*/
|
||||||
string getHtml();
|
string getHtml();
|
||||||
#endif
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::string beautifyInteger(const unsigned int number);
|
std::string beautifyInteger(const unsigned int number);
|
||||||
|
|
75
meson.build
75
meson.build
|
@ -4,7 +4,6 @@ project('kiwix-lib', 'cpp',
|
||||||
default_options : ['c_std=c11', 'cpp_std=c++11', 'werror=true'])
|
default_options : ['c_std=c11', 'cpp_std=c++11', 'werror=true'])
|
||||||
|
|
||||||
compiler = meson.get_compiler('cpp')
|
compiler = meson.get_compiler('cpp')
|
||||||
find_library_in_compiler = meson.version().version_compare('>=0.31.0')
|
|
||||||
|
|
||||||
static_deps = get_option('android') or get_option('default_library') == 'static'
|
static_deps = get_option('android') or get_option('default_library') == 'static'
|
||||||
if get_option('android')
|
if get_option('android')
|
||||||
|
@ -19,81 +18,22 @@ libzim_dep = dependency('libzim', version : '>=4.0.0', static:static_deps)
|
||||||
pugixml_dep = dependency('pugixml', static:static_deps)
|
pugixml_dep = dependency('pugixml', static:static_deps)
|
||||||
libcurl_dep = dependency('libcurl', static:static_deps)
|
libcurl_dep = dependency('libcurl', static:static_deps)
|
||||||
|
|
||||||
|
if not compiler.has_header('mustache.hpp')
|
||||||
|
error('Cannot found header mustache.hpp')
|
||||||
|
endif
|
||||||
|
|
||||||
extra_cflags = ''
|
extra_cflags = ''
|
||||||
if target_machine.system() == 'windows' and static_deps
|
if target_machine.system() == 'windows' and static_deps
|
||||||
add_project_arguments('-DCURL_STATICLIB', language : 'cpp')
|
add_project_arguments('-DCURL_STATICLIB', language : 'cpp')
|
||||||
extra_cflags += '-DCURL_STATICLIB'
|
extra_cflags += '-DCURL_STATICLIB'
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ctpp2_include_path = ''
|
|
||||||
has_ctpp2_dep = false
|
|
||||||
ctpp2_prefix_install = get_option('ctpp2-install-prefix')
|
|
||||||
ctpp2_link_args = []
|
|
||||||
if ctpp2_prefix_install == ''
|
|
||||||
if compiler.has_header('ctpp2/CTPP2Logger.hpp')
|
|
||||||
if find_library_in_compiler
|
|
||||||
ctpp2_lib = compiler.find_library('ctpp2')
|
|
||||||
else
|
|
||||||
ctpp2_lib = find_library('ctpp2')
|
|
||||||
endif
|
|
||||||
ctpp2_link_args = ['-lctpp2']
|
|
||||||
if meson.is_cross_build() and host_machine.system() == 'windows'
|
|
||||||
if find_library_in_compiler
|
|
||||||
iconv_lib = compiler.find_library('iconv', required:false)
|
|
||||||
else
|
|
||||||
iconv_lib = find_library('iconv', required:false)
|
|
||||||
endif
|
|
||||||
if iconv_lib.found()
|
|
||||||
ctpp2_link_args += ['-liconv']
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
has_ctpp2_dep = true
|
|
||||||
ctpp2_dep = declare_dependency(link_args:ctpp2_link_args)
|
|
||||||
else
|
|
||||||
message('ctpp2/CTPP2Logger.hpp not found. Compiling without CTPP2 support')
|
|
||||||
endif
|
|
||||||
else
|
|
||||||
if not find_library_in_compiler
|
|
||||||
error('For custom ctpp2_prefix_install you need a meson version >=0.31.0')
|
|
||||||
endif
|
|
||||||
ctpp2_include_path = ctpp2_prefix_install + '/include'
|
|
||||||
ctpp2_include_args = ['-I'+ctpp2_include_path]
|
|
||||||
if compiler.has_header('ctpp2/CTPP2Logger.hpp', args:ctpp2_include_args)
|
|
||||||
ctpp2_include_dir = include_directories(ctpp2_include_path, is_system:true)
|
|
||||||
ctpp2_lib_path = join_paths(ctpp2_prefix_install, get_option('libdir'))
|
|
||||||
message(ctpp2_lib_path)
|
|
||||||
ctpp2_lib = compiler.find_library('ctpp2', dirs:ctpp2_lib_path, required:false)
|
|
||||||
if not ctpp2_lib.found()
|
|
||||||
ctpp2_lib_path = join_paths(ctpp2_prefix_install, 'lib')
|
|
||||||
message(ctpp2_lib_path)
|
|
||||||
ctpp2_lib = compiler.find_library('ctpp2', dirs:ctpp2_lib_path)
|
|
||||||
endif
|
|
||||||
ctpp2_link_args = ['-L'+ctpp2_lib_path, '-lctpp2']
|
|
||||||
if meson.is_cross_build() and host_machine.system() == 'windows'
|
|
||||||
iconv_lib = compiler.find_library('iconv', required:false)
|
|
||||||
if iconv_lib.found()
|
|
||||||
ctpp2_link_args += ['-liconv']
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
has_ctpp2_dep = true
|
|
||||||
ctpp2_dep = declare_dependency(include_directories:ctpp2_include_dir, link_args:ctpp2_link_args)
|
|
||||||
else
|
|
||||||
message('ctpp2/CTPP2Logger.hpp not found. Compiling without CTPP2 support')
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
|
|
||||||
all_deps = [thread_dep, libicu_dep, libzim_dep, pugixml_dep, libcurl_dep]
|
all_deps = [thread_dep, libicu_dep, libzim_dep, pugixml_dep, libcurl_dep]
|
||||||
if has_ctpp2_dep
|
|
||||||
all_deps += [ctpp2_dep]
|
|
||||||
endif
|
|
||||||
|
|
||||||
inc = include_directories('include')
|
inc = include_directories('include')
|
||||||
|
|
||||||
conf = configuration_data()
|
conf = configuration_data()
|
||||||
conf.set('VERSION', '"@0@"'.format(meson.project_version()))
|
conf.set('VERSION', '"@0@"'.format(meson.project_version()))
|
||||||
conf.set('ENABLE_CTPP2', has_ctpp2_dep)
|
|
||||||
|
|
||||||
if build_machine.system() == 'windows'
|
if build_machine.system() == 'windows'
|
||||||
extra_link_args = ['-lshlwapi', '-lwinmm']
|
extra_link_args = ['-lshlwapi', '-lwinmm']
|
||||||
|
@ -109,13 +49,6 @@ subdir('test')
|
||||||
|
|
||||||
pkg_requires = ['libzim', 'icu-i18n', 'pugixml', 'libcurl']
|
pkg_requires = ['libzim', 'icu-i18n', 'pugixml', 'libcurl']
|
||||||
|
|
||||||
if has_ctpp2_dep
|
|
||||||
extra_libs += ctpp2_link_args
|
|
||||||
if ctpp2_include_path != ''
|
|
||||||
extra_cflags = ' -I'+ctpp2_include_path
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
|
|
||||||
pkg_conf = configuration_data()
|
pkg_conf = configuration_data()
|
||||||
pkg_conf.set('prefix', get_option('prefix'))
|
pkg_conf.set('prefix', get_option('prefix'))
|
||||||
pkg_conf.set('requires', ' '.join(pkg_requires))
|
pkg_conf.set('requires', ' '.join(pkg_requires))
|
||||||
|
|
|
@ -1,4 +1,2 @@
|
||||||
option('ctpp2-install-prefix', type : 'string', value : '',
|
|
||||||
description : 'Prefix where ctpp libs has been installed')
|
|
||||||
option('android', type : 'boolean', value : false,
|
option('android', type : 'boolean', value : false,
|
||||||
description : 'Do we make a kiwix-lib for android')
|
description : 'Do we make a kiwix-lib for android')
|
||||||
|
|
|
@ -1,8 +0,0 @@
|
||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
|
|
||||||
ctpp2c=$1
|
|
||||||
SOURCE=$(pwd)/$2
|
|
||||||
DEST=$3
|
|
||||||
|
|
||||||
$ctpp2c $SOURCE $DEST
|
|
|
@ -1,5 +1,4 @@
|
||||||
|
|
||||||
res_compiler = find_program('kiwix-compile-resources')
|
res_compiler = find_program('kiwix-compile-resources')
|
||||||
intermediate_ctpp2c = find_program('ctpp2c.sh')
|
|
||||||
|
|
||||||
install_data(res_compiler.path(), install_dir:get_option('bindir'))
|
install_data(res_compiler.path(), install_dir:get_option('bindir'))
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
#mesondefine VERSION
|
#mesondefine VERSION
|
||||||
|
|
||||||
#mesondefine ENABLE_CTPP2
|
|
||||||
|
|
|
@ -1,210 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2013 Renaud Gaudin <reg@kiwix.org>
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation; either version 3 of the License, or
|
|
||||||
* any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program; if not, write to the Free Software
|
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
||||||
* MA 02110-1301, USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <ctpp2/CTPP2VMStringLoader.hpp>
|
|
||||||
|
|
||||||
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");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pVMMemoryCore = new VMMemoryCore(oCore);
|
|
||||||
}
|
|
||||||
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.
|
|
|
@ -33,11 +33,6 @@ else
|
||||||
install_dir = get_option('libdir')
|
install_dir = get_option('libdir')
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
|
||||||
if has_ctpp2_dep
|
|
||||||
kiwix_sources += ['ctpp2/CTPP2VMStringLoader.cpp']
|
|
||||||
endif
|
|
||||||
|
|
||||||
config_h = configure_file(output : 'kiwix_config.h',
|
config_h = configure_file(output : 'kiwix_config.h',
|
||||||
configuration : conf,
|
configuration : conf,
|
||||||
input : 'config.h.in')
|
input : 'config.h.in')
|
||||||
|
|
108
src/searcher.cpp
108
src/searcher.cpp
|
@ -25,16 +25,9 @@
|
||||||
|
|
||||||
#include <zim/search.h>
|
#include <zim/search.h>
|
||||||
|
|
||||||
#ifdef ENABLE_CTPP2
|
#include <mustache.hpp>
|
||||||
#include <ctpp2/CDT.hpp>
|
|
||||||
#include <ctpp2/CTPP2FileLogger.hpp>
|
|
||||||
#include <ctpp2/CTPP2SimpleVM.hpp>
|
|
||||||
#include "ctpp2/CTPP2VMStringLoader.hpp"
|
|
||||||
#include "kiwixlib-resources.h"
|
#include "kiwixlib-resources.h"
|
||||||
|
|
||||||
using namespace CTPP;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define MAX_SEARCH_LEN 140
|
#define MAX_SEARCH_LEN 140
|
||||||
|
|
||||||
namespace kiwix
|
namespace kiwix
|
||||||
|
@ -317,46 +310,30 @@ int _Result::get_readerIndex()
|
||||||
{
|
{
|
||||||
return iterator.get_fileIndex();
|
return iterator.get_fileIndex();
|
||||||
}
|
}
|
||||||
#ifdef ENABLE_CTPP2
|
|
||||||
|
|
||||||
string Searcher::getHtml()
|
string Searcher::getHtml()
|
||||||
{
|
{
|
||||||
SimpleVM oSimpleVM(
|
kainjow::mustache::data results{kainjow::mustache::data::type::list};
|
||||||
1024, //iIMaxFunctions (default value)
|
|
||||||
4096, //iIMaxArgStackSize (default value)
|
|
||||||
4096, //iIMaxCodeStackSize (default value)
|
|
||||||
10240 * 2 //iIMaxSteps (default*2)
|
|
||||||
);
|
|
||||||
|
|
||||||
// Fill data
|
|
||||||
CDT oData;
|
|
||||||
CDT resultsCDT(CDT::ARRAY_VAL);
|
|
||||||
|
|
||||||
this->restart_search();
|
this->restart_search();
|
||||||
Result* p_result = NULL;
|
Result* p_result = NULL;
|
||||||
while ((p_result = this->getNextResult())) {
|
while ((p_result = this->getNextResult())) {
|
||||||
CDT result;
|
kainjow::mustache::data result;
|
||||||
result["title"] = p_result->get_title();
|
result.set("title", p_result->get_title());
|
||||||
result["url"] = p_result->get_url();
|
result.set("url", p_result->get_url());
|
||||||
result["snippet"] = p_result->get_snippet();
|
result.set("snippet", p_result->get_snippet());
|
||||||
result["contentId"] = humanReaderNames[p_result->get_readerIndex()];
|
result.set("resultContentId", humanReaderNames[p_result->get_readerIndex()]);
|
||||||
|
|
||||||
if (p_result->get_size() >= 0) {
|
|
||||||
result["size"] = kiwix::beautifyInteger(p_result->get_size());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (p_result->get_wordCount() >= 0) {
|
if (p_result->get_wordCount() >= 0) {
|
||||||
result["wordCount"] = kiwix::beautifyInteger(p_result->get_wordCount());
|
result.set("wordCount", kiwix::beautifyInteger(p_result->get_wordCount()));
|
||||||
}
|
}
|
||||||
|
|
||||||
resultsCDT.PushBack(result);
|
results.push_back(result);
|
||||||
delete p_result;
|
delete p_result;
|
||||||
}
|
}
|
||||||
this->restart_search();
|
|
||||||
oData["results"] = resultsCDT;
|
|
||||||
|
|
||||||
// pages
|
// pages
|
||||||
CDT pagesCDT(CDT::ARRAY_VAL);
|
kainjow::mustache::data pages{kainjow::mustache::data::type::list};
|
||||||
|
|
||||||
unsigned int pageStart
|
unsigned int pageStart
|
||||||
= this->resultStart / this->resultCountPerPage >= 5
|
= this->resultStart / this->resultCountPerPage >= 5
|
||||||
|
@ -372,48 +349,41 @@ string Searcher::getHtml()
|
||||||
}
|
}
|
||||||
|
|
||||||
for (unsigned int i = pageStart; i < pageStart + pageCount; i++) {
|
for (unsigned int i = pageStart; i < pageStart + pageCount; i++) {
|
||||||
CDT page;
|
kainjow::mustache::data page;
|
||||||
page["label"] = i + 1;
|
page.set("label", to_string(i + 1));
|
||||||
page["start"] = i * this->resultCountPerPage;
|
page.set("start", to_string(i * this->resultCountPerPage));
|
||||||
page["end"] = (i + 1) * this->resultCountPerPage;
|
page.set("end", to_string((i + 1) * this->resultCountPerPage));
|
||||||
|
|
||||||
if (i * this->resultCountPerPage == this->resultStart) {
|
if (i * this->resultCountPerPage == this->resultStart) {
|
||||||
page["selected"] = true;
|
page.set("selected", true);
|
||||||
|
}
|
||||||
|
pages.push_back(page);
|
||||||
}
|
}
|
||||||
|
|
||||||
pagesCDT.PushBack(page);
|
std::string template_str = RESOURCE::search_result_tmpl;
|
||||||
}
|
kainjow::mustache::mustache tmpl(template_str);
|
||||||
oData["pages"] = pagesCDT;
|
|
||||||
|
|
||||||
oData["count"] = kiwix::beautifyInteger(this->estimatedResultCount);
|
kainjow::mustache::data allData;
|
||||||
oData["searchPattern"] = kiwix::encodeDiples(this->searchPattern);
|
allData.set("results", results);
|
||||||
oData["searchPatternEncoded"] = urlEncode(this->searchPattern);
|
allData.set("pages", pages);
|
||||||
oData["resultStart"] = this->resultStart + 1;
|
allData.set("hasResult", this->estimatedResultCount != 0);
|
||||||
oData["resultEnd"] = (this->resultEnd > this->estimatedResultCount
|
allData.set("count", kiwix::beautifyInteger(this->estimatedResultCount));
|
||||||
? this->estimatedResultCount
|
allData.set("searchPattern", kiwix::encodeDiples(this->searchPattern));
|
||||||
: this->resultEnd);
|
allData.set("searchPatternEncoded", urlEncode(this->searchPattern));
|
||||||
oData["resultRange"] = this->resultCountPerPage;
|
allData.set("resultStart", to_string(this->resultStart + 1));
|
||||||
oData["resultLastPageStart"]
|
allData.set("resultEnd", to_string(min(this->resultEnd, this->estimatedResultCount)));
|
||||||
= this->estimatedResultCount > this->resultCountPerPage
|
allData.set("resultRange", to_string(this->resultCountPerPage));
|
||||||
? std::round(this->estimatedResultCount / this->resultCountPerPage) * this->resultCountPerPage
|
allData.set("resultLastPageStart", to_string(this->estimatedResultCount > this->resultCountPerPage
|
||||||
: 0;
|
? round(this->estimatedResultCount / this->resultCountPerPage) * this->resultCountPerPage
|
||||||
oData["protocolPrefix"] = this->protocolPrefix;
|
: 0));
|
||||||
oData["searchProtocolPrefix"] = this->searchProtocolPrefix;
|
allData.set("lastResult", to_string(this->estimatedResultCount));
|
||||||
oData["contentId"] = this->contentHumanReadableId;
|
allData.set("protocolPrefix", this->protocolPrefix);
|
||||||
|
allData.set("searchProtocolPrefix", this->searchProtocolPrefix);
|
||||||
|
allData.set("contentId", this->contentHumanReadableId);
|
||||||
|
|
||||||
std::string template_ct2 = RESOURCE::results_ct2;
|
std::stringstream ss;
|
||||||
VMStringLoader oLoader(template_ct2.c_str(), template_ct2.size());
|
tmpl.render(allData, [&ss](const std::string& str) { ss << str; });
|
||||||
|
return ss.str();
|
||||||
FileLogger oLogger(stderr);
|
|
||||||
|
|
||||||
// DEBUG only (write output to stdout)
|
|
||||||
// oSimpleVM.Run(oData, oLoader, stdout, oLogger);
|
|
||||||
|
|
||||||
std::string sResult;
|
|
||||||
oSimpleVM.Run(oData, oLoader, sResult, oLogger);
|
|
||||||
|
|
||||||
return sResult;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,4 @@
|
||||||
|
|
||||||
|
|
||||||
ctpp2c = find_program('ctpp2c', required:false)
|
|
||||||
|
|
||||||
if ctpp2c.found()
|
|
||||||
search_result_template = custom_target('result_template',
|
|
||||||
input: 'results.tmpl',
|
|
||||||
output: 'results.ct2',
|
|
||||||
command: [intermediate_ctpp2c, ctpp2c, '@INPUT@', '@OUTPUT@']
|
|
||||||
)
|
|
||||||
resources_list = 'resources_list_ctpp2.txt'
|
|
||||||
lib_resources = custom_target('resources',
|
lib_resources = custom_target('resources',
|
||||||
input: 'resources_list.txt',
|
input: 'resources_list.txt',
|
||||||
output: ['kiwixlib-resources.cpp', 'kiwixlib-resources.h'],
|
output: ['kiwixlib-resources.cpp', 'kiwixlib-resources.h'],
|
||||||
|
@ -17,8 +7,5 @@ if ctpp2c.found()
|
||||||
'--hfile', '@OUTPUT1@',
|
'--hfile', '@OUTPUT1@',
|
||||||
'--source_dir', '@OUTDIR@',
|
'--source_dir', '@OUTDIR@',
|
||||||
'@INPUT@'],
|
'@INPUT@'],
|
||||||
depends: [search_result_template]
|
depend_files: 'static/search_result.tmpl'
|
||||||
)
|
)
|
||||||
else
|
|
||||||
lib_resources = []
|
|
||||||
endif
|
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
results.ct2
|
search_result.tmpl
|
||||||
|
|
|
@ -91,68 +91,67 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
</style>
|
</style>
|
||||||
<title>Search: <TMPL_var searchPattern></title>
|
<title>Search: {{searchPattern}}</title>
|
||||||
</head>
|
</head>
|
||||||
<body bgcolor="white">
|
<body bgcolor="white">
|
||||||
<div class="header">
|
<div class="header">
|
||||||
<TMPL_if results>
|
{{#hasResult}}
|
||||||
Results
|
Results
|
||||||
<b>
|
<b>
|
||||||
<TMPL_var resultStart>-<TMPL_var resultEnd>
|
{{resultStart}}-{{resultEnd}}
|
||||||
</b> of <b>
|
</b> of <b>
|
||||||
<TMPL_var count>
|
{{count}}
|
||||||
</b> for <b>
|
</b> for <b>
|
||||||
<TMPL_var searchPattern>
|
{{searchPattern}}
|
||||||
</b>
|
</b>
|
||||||
<TMPL_else>
|
{{/hasResult}}
|
||||||
No results were found for <b><TMPL_var searchPattern></b>
|
{{^hasResult}}
|
||||||
</TMPL_if>
|
No results were found for <b>{{searchPattern}}</b>
|
||||||
|
{{/hasResult}}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="results">
|
<div class="results">
|
||||||
<ul>
|
<ul>
|
||||||
<TMPL_foreach results as result>
|
{{#results}}
|
||||||
<li>
|
<li>
|
||||||
<a href="<TMPL_var protocolPrefix><TMPL_var result.contentId>/<TMPL_var result.url>">
|
<a href="{{protocolPrefix}}{{resultContentId}}/{{url}}">
|
||||||
<TMPL_var result.title>
|
{{title}}
|
||||||
</a>
|
</a>
|
||||||
<cite>
|
{{#snippet}}
|
||||||
<TMPL_if result.snippet>
|
<cite>{{>snippet}}...</cite>
|
||||||
<TMPL_var result.snippet>...
|
{{/snippet}}
|
||||||
</TMPL_if>
|
{{#wordCount}}
|
||||||
</cite>
|
<div class="informations">{{wordCount}} words</div>
|
||||||
<TMPL_if wordCount>
|
{{/wordCount}}
|
||||||
<div class="informations"><TMPL_var wordCount> words</div>
|
|
||||||
</TMPL_if>
|
|
||||||
</li>
|
</li>
|
||||||
</TMPL_foreach>
|
{{/results}}
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="footer">
|
<div class="footer">
|
||||||
<ul>
|
<ul>
|
||||||
<TMPL_if (resultLastPageStart>0)>
|
{{#resultLastPageStart}}
|
||||||
<li>
|
<li>
|
||||||
<a href="<TMPL_var searchProtocolPrefix>pattern=<TMPL_var searchPatternEncoded><TMPL_if contentId>&content=<TMPL_var contentId></TMPL_if>&start=0&end=<TMPL_var resultRange>">
|
<a href="{{searchProtocolPrefix}}pattern={{searchPatternEncoded}}{{#contentId}}&content={{.}}{{/contentId}}&start=0&end={{resultRange}}">
|
||||||
◀
|
◀
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
</TMPL_if>
|
{{/resultLastPageStart}}
|
||||||
<TMPL_foreach pages as page>
|
{{#pages}}
|
||||||
<li>
|
<li>
|
||||||
<a <TMPL_if page.selected>class="selected"</TMPL_if>
|
<a {{#selected}}class="selected"{{/selected}}
|
||||||
href="<TMPL_var searchProtocolPrefix>pattern=<TMPL_var searchPatternEncoded><TMPL_if contentId>&content=<TMPL_var contentId></TMPL_if>&start=<TMPL_var page.start>&end=<TMPL_var page.end>">
|
href="{{searchProtocolPrefix}}pattern={{searchPatternEncoded}}{{#contentId}}&content={{.}}{{/contentId}}&start={{start}}&end={{end}}">
|
||||||
<TMPL_var page.label>
|
{{label}}
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
</TMPL_foreach>
|
{{/pages}}
|
||||||
<TMPL_if (resultLastPageStart>0)>
|
{{#resultLastPageStart}}
|
||||||
<li>
|
<li>
|
||||||
<a href="<TMPL_var searchProtocolPrefix>pattern=<TMPL_var searchPatternEncoded><TMPL_if contentId>&content=<TMPL_var contentId></TMPL_if>&start=<TMPL_var resultLastPageStart>&end=<TMPL_var (resultLastPageStart+resultRange)>">
|
<a href="{{searchProtocolPrefix}}pattern={{searchPatternEncoded}}{{#contentId}}&content={{.}}{{/contentId}}&start={{resultLastPageStart}}&end={{lastResult}}">
|
||||||
▶
|
▶
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
</TMPL_if>
|
{{/resultLastPageStart}}
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
|
@ -35,6 +35,7 @@ then
|
||||||
else
|
else
|
||||||
export PKG_CONFIG_PATH=${INSTALL_DIR}/lib/x86_64-linux-gnu/pkgconfig
|
export PKG_CONFIG_PATH=${INSTALL_DIR}/lib/x86_64-linux-gnu/pkgconfig
|
||||||
fi
|
fi
|
||||||
meson . build -Dctpp2-install-prefix=${INSTALL_DIR} ${MESON_OPTION}
|
export CPPFLAGS="-I${INSTALL_DIR}/include"
|
||||||
|
meson . build ${MESON_OPTION}
|
||||||
cd build
|
cd build
|
||||||
ninja
|
ninja
|
||||||
|
|
Loading…
Reference in New Issue