libmobi
C library for handling MOBI format ebook documents
Functions
structure.c File Reference

Data structures. More...

#include <stdlib.h>
#include <string.h>
#include "structure.h"
#include "debug.h"

Functions

MOBIArrayarray_init (const size_t len)
 Initializer for MOBIArray structure. More...
 
MOBI_RET array_insert (MOBIArray *arr, const uint32_t value)
 Inserts value into MOBIArray array. More...
 
void array_sort (MOBIArray *arr, const bool unique)
 Sort MOBIArray in ascending order. More...
 
size_t array_size (MOBIArray *arr)
 Get size of the array. More...
 
void array_free (MOBIArray *arr)
 Free MOBIArray structure and contained data. More...
 
void mobi_trie_free (MOBITrie *node)
 Recursively free MOBITrie trie starting from node. More...
 
MOBI_RET mobi_trie_insert_reversed (MOBITrie **root, char *string, char *value)
 Insert reversed string into MOBITrie trie. More...
 
MOBITriemobi_trie_get_next (char ***values, size_t *values_count, const MOBITrie *node, const char c)
 Fetch values for key c from MOBITrie trie's current level starting at node. More...
 
MOBIFragmentmobi_list_add (MOBIFragment *curr, size_t raw_offset, unsigned char *fragment, const size_t size, const bool is_malloc)
 Allocate fragment, fill with data, append to linked list. More...
 
MOBI_RET mobi_list_insert (MOBIFragment **fragment, size_t raw_offset, unsigned char *data, const size_t size, const bool is_malloc, const size_t offset)
 Allocate fragment, fill with data, insert into linked list at given offset. More...
 
MOBIFragmentmobi_list_del (MOBIFragment *curr)
 Delete fragment from linked list. More...
 
void mobi_list_del_all (MOBIFragment *first)
 Delete all fragments from linked list. More...
 

Detailed Description

Data structures.

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/

Function Documentation

◆ array_free()

void array_free ( MOBIArray arr)

Free MOBIArray structure and contained data.

Free data initialized with array_init();

Parameters
[in]arrMOBIArray structure

◆ array_init()

MOBIArray* array_init ( const size_t  len)

Initializer for MOBIArray structure.

It allocates memory for structure and for data: array of uint32_t variables. Memory should be freed with array_free().

Parameters
[in]lenInitial size of the array
Returns
MOBIArray on success, NULL otherwise

◆ array_insert()

MOBI_RET array_insert ( MOBIArray arr,
const uint32_t  value 
)

Inserts value into MOBIArray array.

Parameters
[in,out]arrMOBIArray array
[in]valueValue to be inserted
Returns
MOBI_RET status code (on success MOBI_SUCCESS)

◆ array_size()

size_t array_size ( MOBIArray arr)

Get size of the array.

Parameters
[in]arrMOBIArray structure
Returns
Array size

◆ array_sort()

void array_sort ( MOBIArray arr,
const bool  unique 
)

Sort MOBIArray in ascending order.

When unique is set to true, duplicate values are discarded.

Parameters
[in,out]arrMOBIArray array
[in]uniqueDiscard duplicate values if true

◆ mobi_list_add()

MOBIFragment* mobi_list_add ( MOBIFragment curr,
size_t  raw_offset,
unsigned char *  fragment,
const size_t  size,
const bool  is_malloc 
)

Allocate fragment, fill with data, append to linked list.

Parameters
[in]currLast fragment in linked list
[in]raw_offsetFragment offset in raw markup, SIZE_MAX if not present in original markup
[in]fragmentFragment data
[in]sizeSize data
[in]is_mallocis_maloc data
Returns
Fragment structure filled with data

◆ mobi_list_del()

MOBIFragment* mobi_list_del ( MOBIFragment curr)

Delete fragment from linked list.

Parameters
[in]currFragment to be deleted
Returns
Next fragment in the linked list or NULL if absent

◆ mobi_list_del_all()

void mobi_list_del_all ( MOBIFragment first)

Delete all fragments from linked list.

Parameters
[in]firstFirst fragment from the list

◆ mobi_list_insert()

MOBI_RET mobi_list_insert ( MOBIFragment **  fragment,
size_t  raw_offset,
unsigned char *  data,
const size_t  size,
const bool  is_malloc,
const size_t  offset 
)

Allocate fragment, fill with data, insert into linked list at given offset.

Starts to search for offset at given fragment. The pointer to input fragment will be replaced by newly added one.

Parameters
[in,out]fragmentFragment where search starts, on success pointer to new fragment structure filled with data
[in]raw_offsetFragment offset in raw markup, SIZE_MAX if not present in original markup
[in]dataFragment data
[in]sizeSize data
[in]is_mallocis_maloc data
[in]offsetoffset where new chunk will be inserted
Returns
MOBI_RET status code (on success MOBI_SUCCESS, on offset not found MOBI_DATA_CORRUPT)

◆ mobi_trie_free()

void mobi_trie_free ( MOBITrie node)

Recursively free MOBITrie trie starting from node.

Parameters
[in]nodeStarting node

◆ mobi_trie_get_next()

MOBITrie* mobi_trie_get_next ( char ***  values,
size_t *  values_count,
const MOBITrie node,
const char  c 
)

Fetch values for key c from MOBITrie trie's current level starting at node.

Parameters
[in,out]valuesArray of values to be fetched
[in,out]values_countArray size
[in]nodeMOBITrie node to start search
[in]cKey character
Returns
MOBITrie children node of the node with c key or NULL if not found

◆ mobi_trie_insert_reversed()

MOBI_RET mobi_trie_insert_reversed ( MOBITrie **  root,
char *  string,
char *  value 
)

Insert reversed string into MOBITrie trie.

Parameters
[in,out]rootRoot node
[in]stringString to be inserted
[in]valueValue associated with the string
Returns
MOBI_RET status code (on success MOBI_SUCCESS)