libmobi
C library for handling MOBI format ebook documents
Data Structures | Macros | Functions
index.h File Reference
#include "config.h"
#include "structure.h"
#include "mobi.h"

Go to the source code of this file.

Data Structures

struct  TAGXTags
 Tag entries in TAGX section (for internal INDX parsing) More...
 
struct  MOBITagx
 Parsed TAGX section (for internal INDX parsing) More...
 
struct  MOBIIdxt
 Parsed IDXT section (for internal INDX parsing) More...
 
struct  MOBIOrdt
 Parsed ORDT sections (for internal INDX parsing) More...
 

Macros

#define INDX_TAG_GUIDE_TITLE_CNCX   (unsigned[]) {1, 0}
 
#define INDX_TAG_NCX_FILEPOS   (unsigned[]) {1, 0}
 
#define INDX_TAG_NCX_TEXT_CNCX   (unsigned[]) {3, 0}
 
#define INDX_TAG_NCX_LEVEL   (unsigned[]) {4, 0}
 
#define INDX_TAG_NCX_KIND_CNCX   (unsigned[]) {5, 0}
 
#define INDX_TAG_NCX_POSFID   (unsigned[]) {6, 0}
 
#define INDX_TAG_NCX_POSOFF   (unsigned[]) {6, 1}
 
#define INDX_TAG_NCX_PARENT   (unsigned[]) {21, 0}
 
#define INDX_TAG_NCX_CHILD_START   (unsigned[]) {22, 0}
 
#define INDX_TAG_NCX_CHILD_END   (unsigned[]) {23, 0}
 
#define INDX_TAG_SKEL_COUNT   (unsigned[]) {1, 0}
 
#define INDX_TAG_SKEL_POSITION   (unsigned[]) {6, 0}
 
#define INDX_TAG_SKEL_LENGTH   (unsigned[]) {6, 1}
 
#define INDX_TAG_FRAG_AID_CNCX   (unsigned[]) {2, 0}
 
#define INDX_TAG_FRAG_FILE_NR   (unsigned[]) {3, 0}
 
#define INDX_TAG_FRAG_SEQUENCE_NR   (unsigned[]) {4, 0}
 
#define INDX_TAG_FRAG_POSITION   (unsigned[]) {6, 0}
 
#define INDX_TAG_FRAG_LENGTH   (unsigned[]) {6, 1}
 
#define INDX_TAG_ORTH_POSITION   (unsigned[]) {1, 0}
 
#define INDX_TAG_ORTH_LENGTH   (unsigned[]) {2, 0}
 
#define INDX_TAGARR_ORTH_INFL   42
 
#define INDX_TAGARR_INFL_GROUPS   5
 
#define INDX_TAGARR_INFL_PARTS_V2   26
 
#define INDX_TAGARR_INFL_PARTS_V1   7
 
#define INDX_LABEL_SIZEMAX   1000
 
#define INDX_INFLTAG_SIZEMAX   25000
 
#define INDX_INFLBUF_SIZEMAX   500
 
#define INDX_INFLSTRINGS_MAX   500
 
#define ORDT_RECORD_MAXCNT   256 /* max entries count in old ordt */
 
#define CNCX_RECORD_MAXCNT   0xf /* max entries count */
 
#define INDX_RECORD_MAXCNT   6000 /* max index entries per record */
 
#define INDX_TOTAL_MAXCNT   ((size_t) INDX_RECORD_MAXCNT * 0xffff) /* max total index entries */
 
#define INDX_NAME_SIZEMAX   0xff
 
#define INDX_TAGVALUES_MAX   100
 Maximum value of tag values in index entry (MOBIIndexTag)
 

Functions

MOBI_RET mobi_parse_index (const MOBIData *m, MOBIIndx *indx, const size_t indx_record_number)
 Parser of a set of index records. More...
 
MOBI_RET mobi_parse_indx (const MOBIPdbRecord *indx_record, MOBIIndx *indx, MOBITagx *tagx, MOBIOrdt *ordt)
 Parser of INDX record. More...
 
MOBI_RET mobi_get_indxentry_tagvalue (uint32_t *tagvalue, const MOBIIndexEntry *entry, const unsigned tag_arr[])
 Get a value of tag[tagid][tagindex] for given index entry. More...
 
size_t mobi_get_indxentry_tagarray (uint32_t **tagarr, const MOBIIndexEntry *entry, const size_t tagid)
 Get array of tagvalues of tag[tagid] for given index entry. More...
 
bool mobi_indx_has_tag (const MOBIIndx *indx, const size_t tagid)
 Check if given tagid is present in the index. More...
 
char * mobi_get_cncx_string (const MOBIPdbRecord *cncx_record, const uint32_t cncx_offset)
 Get compiled index entry string. More...
 
char * mobi_get_cncx_string_utf8 (const MOBIPdbRecord *cncx_record, const uint32_t cncx_offset, MOBIEncoding cncx_encoding)
 Get compiled index entry string, converted to utf8 encoding. More...
 
char * mobi_get_cncx_string_flat (const MOBIPdbRecord *cncx_record, const uint32_t cncx_offset, const size_t length)
 Get flat index entry string. More...
 
MOBI_RET mobi_decode_infl (unsigned char *decoded, int *decoded_size, const unsigned char *rule)
 Decode compiled infl index entry. More...
 
MOBI_RET mobi_trie_insert_infl (MOBITrie **root, const MOBIIndx *indx, size_t i)
 Insert inversed inlection string for given entry into trie structure. More...
 
size_t mobi_trie_get_inflgroups (char **infl_strings, MOBITrie *const root, const char *string)
 Get all matches for given string from trie structure. More...
 

Detailed Description

Copyright (c) 2014 Bartek Fabiszewski http://www.fabiszewski.net

This file is part of libmobi. Licensed under LGPL, either version 3, or any later. See http://www.gnu.org/licenses/

Macro Definition Documentation

◆ INDX_INFLBUF_SIZEMAX

#define INDX_INFLBUF_SIZEMAX   500

Max size of index label

◆ INDX_INFLSTRINGS_MAX

#define INDX_INFLSTRINGS_MAX   500

Max number of inflected strings

◆ INDX_INFLTAG_SIZEMAX

#define INDX_INFLTAG_SIZEMAX   25000

Max size of inflections tags per entry

◆ INDX_LABEL_SIZEMAX

#define INDX_LABEL_SIZEMAX   1000

Max size of index label

Function Documentation

◆ mobi_decode_infl()

MOBI_RET mobi_decode_infl ( unsigned char *  decoded,
int *  decoded_size,
const unsigned char *  rule 
)

Decode compiled infl index entry.

Buffer decoded must be initialized with basic index entry. Basic index entry will be transformed into inflected form, based on compiled rule. Min. size of input buffer (decoded) must be INDX_INFLBUF_SIZEMAX + 1

Parameters
[in,out]decodedDecoded entry string
[in,out]decoded_sizeDecoded entry size
[in]ruleCompiled rule
Returns
MOBI_RET status code (on success MOBI_SUCCESS)

◆ mobi_get_cncx_string()

char* mobi_get_cncx_string ( const MOBIPdbRecord cncx_record,
const uint32_t  cncx_offset 
)

Get compiled index entry string.

Allocates memory for the string. Must be freed by caller.

Parameters
[in]cncx_recordMOBIPdbRecord structure with cncx record
[in]cncx_offsetOffset of string entry from the beginning of the record
Returns
Entry string or null if malloc failed

◆ mobi_get_cncx_string_flat()

char* mobi_get_cncx_string_flat ( const MOBIPdbRecord cncx_record,
const uint32_t  cncx_offset,
const size_t  length 
)

Get flat index entry string.

Allocates memory for the string. Must be freed by caller.

Parameters
[in]cncx_recordMOBIPdbRecord structure with cncx record
[in]cncx_offsetOffset of string entry from the beginning of the record
[in]lengthLength of the string to be extracted
Returns
Entry string

◆ mobi_get_cncx_string_utf8()

char* mobi_get_cncx_string_utf8 ( const MOBIPdbRecord cncx_record,
const uint32_t  cncx_offset,
MOBIEncoding  cncx_encoding 
)

Get compiled index entry string, converted to utf8 encoding.

Allocates memory for the string. Must be freed by caller.

Parameters
[in]cncx_recordMOBIPdbRecord structure with cncx record
[in]cncx_offsetOffset of string entry from the beginning of the record
[in]cncx_encodingEncoding
Returns
Entry string or null if malloc failed

◆ mobi_get_indxentry_tagarray()

size_t mobi_get_indxentry_tagarray ( uint32_t **  tagarr,
const MOBIIndexEntry entry,
const size_t  tagid 
)

Get array of tagvalues of tag[tagid] for given index entry.

Parameters
[in,out]tagarrPointer to tagvalues array
[in]entryIndex entry to be search for the value
[in]tagidId of the tag
Returns
Size of the array (zero on failure)

◆ mobi_get_indxentry_tagvalue()

MOBI_RET mobi_get_indxentry_tagvalue ( uint32_t *  tagvalue,
const MOBIIndexEntry entry,
const unsigned  tag_arr[] 
)

Get a value of tag[tagid][tagindex] for given index entry.

Parameters
[in,out]tagvalueWill be set to a tag value
[in]entryIndex entry to be search for the value
[in]tag_arrArray: tag_arr[0] = tagid, tag_arr[1] = tagindex
Returns
MOBI_RET status code (on success MOBI_SUCCESS)

◆ mobi_indx_has_tag()

bool mobi_indx_has_tag ( const MOBIIndx indx,
const size_t  tagid 
)

Check if given tagid is present in the index.

Parameters
[in]indxIndex MOBIIndx structure
[in]tagidId of the tag
Returns
True on success, false otherwise

◆ mobi_parse_index()

MOBI_RET mobi_parse_index ( const MOBIData m,
MOBIIndx indx,
const size_t  indx_record_number 
)

Parser of a set of index records.

Parameters
[in]mMOBIData structure containing MOBI file metadata and data
[in,out]indxMOBIIndx structure to be filled with parsed entries
[in]indx_record_numberNumber of the first record of the set
Returns
MOBI_RET status code (on success MOBI_SUCCESS)

◆ mobi_parse_indx()

MOBI_RET mobi_parse_indx ( const MOBIPdbRecord indx_record,
MOBIIndx indx,
MOBITagx tagx,
MOBIOrdt ordt 
)

Parser of INDX record.

Parameters
[in]indx_recordMOBIPdbRecord structure with INDX record
[in,out]indxMOBIIndx structure to be filled with parsed entries
[in,out]tagxMOBITagx structure, will be filled with parsed TAGX section data if present in the INDX record, otherwise TAGX data will be used to parse the record
[in,out]ordtMOBIOrdt structure, will be filled with parsed ORDT sections
Returns
MOBI_RET status code (on success MOBI_SUCCESS)

◆ mobi_trie_get_inflgroups()

size_t mobi_trie_get_inflgroups ( char **  infl_strings,
MOBITrie *const  root,
const char *  string 
)

Get all matches for given string from trie structure.

Matches are made agains reversed string and all its substrings

Parameters
[in,out]infl_stringsArray of returned strings
[in]rootRoot node of the tree
[in]stringIndex entry number
Returns
Number of returned strings

◆ mobi_trie_insert_infl()

MOBI_RET mobi_trie_insert_infl ( MOBITrie **  root,
const MOBIIndx indx,
size_t  i 
)

Insert inversed inlection string for given entry into trie structure.

Parameters
[in,out]rootRoot node of the tree, created if NULL
[in]indxMOBIIndx infl index records
[in]iIndex entry number
Returns
MOBI_RET status code (on success MOBI_SUCCESS)