ELinks 0.18.0
|
#include <stdlib.h>
#include <string.h>
#include "elinks.h"
#include "dom/node.h"
#include "dom/stack.h"
#include "util/memory.h"
Data Structures | |
struct | dom_stack_walk_state |
Macros | |
#define | DOM_STACK_STATE_GRANULARITY 0x7 |
#define | DOM_STACK_CALLBACKS_SIZE (sizeof(dom_stack_callback_T) * DOM_NODES) |
Enumerations | |
enum | dom_stack_action { DOM_STACK_PUSH , DOM_STACK_POP } |
Functions | |
static struct dom_stack_state * | realloc_dom_stack_states (struct dom_stack_state **states, size_t size) |
static struct dom_stack_state * | realloc_dom_stack_context (struct dom_stack_context ***contexts, size_t size) |
static char * | realloc_dom_stack_state_objects (struct dom_stack_context *context, size_t depth) |
void | init_dom_stack (struct dom_stack *stack, unsigned int flags) |
Initialise a DOM stack. | |
void | done_dom_stack (struct dom_stack *stack) |
Release a DOM stack. | |
struct dom_stack_context * | add_dom_stack_context (struct dom_stack *stack, void *data, struct dom_stack_context_info *context_info) |
Add a context to the stack. | |
void | done_dom_stack_context (struct dom_stack *stack, struct dom_stack_context *context) |
Unregister a stack context. | |
static int | call_dom_stack_callbacks (struct dom_stack *stack, struct dom_stack_state *state, enum dom_stack_action action) |
enum dom_code | push_dom_node (struct dom_stack *stack, struct dom_node *node) |
Push a node onto the stack. | |
void | pop_dom_node (struct dom_stack *stack) |
Pop the top stack state. | |
void | pop_dom_nodes (struct dom_stack *stack, enum dom_node_type type, struct dom_string *string) |
Conditionally pop the stack states. | |
void | pop_dom_state (struct dom_stack *stack, struct dom_stack_state *target) |
Pop all states until target state. | |
struct dom_stack_state * | search_dom_stack (struct dom_stack *stack, enum dom_node_type type, struct dom_string *string) |
Search the stack states. | |
void | walk_dom_nodes (struct dom_stack *stack, struct dom_node *root) |
Walk all nodes reachable from a given node. | |
Variables | |
static struct dom_stack_context_info | dom_stack_walk_context_info |
#define DOM_STACK_CALLBACKS_SIZE (sizeof(dom_stack_callback_T) * DOM_NODES) |
#define DOM_STACK_STATE_GRANULARITY 0x7 |
enum dom_stack_action |
struct dom_stack_context * add_dom_stack_context | ( | struct dom_stack * | stack, |
void * | data, | ||
struct dom_stack_context_info * | context_info ) |
Add a context to the stack.
This is needed if either you want to have the stack allocated objects for created states and/or if you want to install callbacks for pushing or popping.
stack | The stack where the context should be created. |
data | Private data to be stored in ref:[dom_stack_context.data]. |
context_info | Information about state objects and node callbacks. |
|
static |
void done_dom_stack | ( | struct dom_stack * | stack | ) |
Release a DOM stack.
Free all resources collected by the stack.
stack | The stack to release. |
void done_dom_stack_context | ( | struct dom_stack * | stack, |
struct dom_stack_context * | context ) |
Unregister a stack context.
This should be done especially for temporary stack contexts (without any callbacks) so that they do not increasing the memory usage.
void init_dom_stack | ( | struct dom_stack * | stack, |
unsigned int | flags ) |
Initialise a DOM stack.
stack | Pointer to a (preallocated) stack. |
flags | Any flags needed for controlling the behaviour of the stack. |
void pop_dom_node | ( | struct dom_stack * | stack | ) |
Pop the top stack state.
stack | The stack to pop from. |
void pop_dom_nodes | ( | struct dom_stack * | stack, |
enum dom_node_type | type, | ||
struct dom_string * | string ) |
Conditionally pop the stack states.
Searches the stack (using ref:[search_dom_stack]) for a specific node and pops all states until that particular state is met.
void pop_dom_state | ( | struct dom_stack * | stack, |
struct dom_stack_state * | target ) |
Pop all states until target state.
Pop all stack states until a specific state is reached. The target state is also popped.
stack | The stack to pop from. |
target | The state to pop until and including. |
Push a node onto the stack.
Makes the pushed node the new top of the stack.
stack | The stack to push onto. |
node | The node to push onto the stack. |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
struct dom_stack_state * search_dom_stack | ( | struct dom_stack * | stack, |
enum dom_node_type | type, | ||
struct dom_string * | string ) |
Search the stack states.
The string comparison is done against the ref:[dom_node.string] member of the of the state nodes.
stack | The stack to search in. |
type | The type of node to match against. |
string | The string to match against. |
Walk all nodes reachable from a given node.
Visits each node in the DOM tree rooted at a given node, pre-order style.
stack | The stack to use for walking the nodes. |
root | The root node to start from. |
It is assummed that the given stack has been initialised with init_dom_stack and that the caller already added one or more context to the stack.
|
static |