ELinks 0.16.1.1
stack.c File Reference
#include <stdlib.h>
#include <string.h>
#include "elinks.h"
#include "dom/node.h"
#include "dom/stack.h"
#include "util/memory.h"
Include dependency graph for stack.c:

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_staterealloc_dom_stack_states (struct dom_stack_state **states, size_t size)
static struct dom_stack_staterealloc_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_contextadd_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_statesearch_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

Macro Definition Documentation

◆ DOM_STACK_CALLBACKS_SIZE

#define DOM_STACK_CALLBACKS_SIZE   (sizeof(dom_stack_callback_T) * DOM_NODES)

◆ DOM_STACK_STATE_GRANULARITY

#define DOM_STACK_STATE_GRANULARITY   0x7

Enumeration Type Documentation

◆ dom_stack_action

Enumerator
DOM_STACK_PUSH 
DOM_STACK_POP 

Function Documentation

◆ add_dom_stack_context()

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.

Parameters
stackThe stack where the context should be created.
dataPrivate data to be stored in ref:[dom_stack_context.data].
context_infoInformation about state objects and node callbacks.
Returns
A pointer to the newly created context or NULL.

◆ call_dom_stack_callbacks()

int call_dom_stack_callbacks ( struct dom_stack * stack,
struct dom_stack_state * state,
enum dom_stack_action action )
static

◆ done_dom_stack()

void done_dom_stack ( struct dom_stack * stack)

Release a DOM stack.

Free all resources collected by the stack.

Parameters
stackThe stack to release.

◆ done_dom_stack_context()

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.

◆ init_dom_stack()

void init_dom_stack ( struct dom_stack * stack,
unsigned int flags )

Initialise a DOM stack.

Parameters
stackPointer to a (preallocated) stack.
flagsAny flags needed for controlling the behaviour of the stack.

◆ pop_dom_node()

void pop_dom_node ( struct dom_stack * stack)

Pop the top stack state.

Parameters
stackThe stack to pop from.

◆ pop_dom_nodes()

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.

Note
The popping is stopped if an immutable state is encountered.

◆ pop_dom_state()

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.

Parameters
stackThe stack to pop from.
targetThe state to pop until and including.

◆ push_dom_node()

enum dom_code push_dom_node ( struct dom_stack * stack,
struct dom_node * node )

Push a node onto the stack.

Makes the pushed node the new top of the stack.

Parameters
stackThe stack to push onto.
nodeThe node to push onto the stack.
Returns
If an error occurs the node is released with done_dom_node and NULL is returned. Else the pushed node is returned.

◆ realloc_dom_stack_context()

struct dom_stack_state * realloc_dom_stack_context ( struct dom_stack_context *** contexts,
size_t size )
inlinestatic

◆ realloc_dom_stack_state_objects()

char * realloc_dom_stack_state_objects ( struct dom_stack_context * context,
size_t depth )
inlinestatic

◆ realloc_dom_stack_states()

struct dom_stack_state * realloc_dom_stack_states ( struct dom_stack_state ** states,
size_t size )
inlinestatic

◆ search_dom_stack()

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.

Parameters
stackThe stack to search in.
typeThe type of node to match against.
stringThe string to match against.
Returns
A state that matched the type and string or NULL.

◆ walk_dom_nodes()

void walk_dom_nodes ( struct dom_stack * stack,
struct dom_node * root )

Walk all nodes reachable from a given node.

Visits each node in the DOM tree rooted at a given node, pre-order style.

Parameters
stackThe stack to use for walking the nodes.
rootThe 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.

Variable Documentation

◆ dom_stack_walk_context_info

struct dom_stack_context_info dom_stack_walk_context_info
static