Small, Fast S-Expression Library
Defines | Functions
sexp_ops.h File Reference

A collection of useful operations to perform on s-expressions. More...

#include "sexp.h"

Go to the source code of this file.

Defines

#define hd_sexp(s)   ((s)->list)
#define tl_sexp(s)   ((s)->list->next)
#define next_sexp(s)   ((s)->next)
#define reset_pcont(c)   ((c)->lastPos = NULL)

Functions

sexp_tfind_sexp (const char *name, sexp_t *start)
sexp_tbfs_find_sexp (const char *name, sexp_t *start)
int sexp_list_length (const sexp_t *sx)
sexp_tcopy_sexp (const sexp_t *sx)

Detailed Description

A collection of useful operations to perform on s-expressions.

A set of routines for operating on s-expressions.


Define Documentation

#define hd_sexp (   s)    ((s)->list)

Return the head of a list s by reference, not copy.

#define next_sexp (   s)    ((s)->next)

Return the element following the argument s.

#define reset_pcont (   c)    ((c)->lastPos = NULL)

Reset the continuation c by setting the lastPos pointer to NULL.

#define tl_sexp (   s)    ((s)->list->next)

Return the tail of a list s by reference, not copy.


Function Documentation

sexp_t* bfs_find_sexp ( const char *  name,
sexp_t start 
)

Breadth first search for s-expressions. Depth first search will find the first occurance of a string in an s-expression by basically finding the earliest occurance in the string representation of the expression itself. Breadth first search will find the first occurance of a string in relation to the structure of the expression itself (IE: the instance with the lowest depth will be found).

Parameters:
nameValue to search for.
startRoot element of the s-expression to search from.
Returns:
If the value is found, return a pointer to the first occurrence in a breadth-first traversal. NULL if not found.
sexp_t* copy_sexp ( const sexp_t sx)

Copy an s-expression. This is a deep copy - so the resulting s-expression shares no pointers with the original. The new one can be changed without damaging the contents of the original.

Parameters:
sxS-expression to copy.
Returns:
A pointer to a copy of sx. This is a deep copy, so no memory is shared between the original and the returned copy.
sexp_t* find_sexp ( const char *  name,
sexp_t start 
)

Find an atom in a sexpression data structure and return a pointer to it. Return NULL if the string doesn't occur anywhere as an atom. This is a depth-first search algorithm.

Parameters:
nameValue to search for.
startRoot element of the s-expression to search from.
Returns:
If the value is found, return a pointer to the first occurrence in a depth-first traversal. NULL if not found.
int sexp_list_length ( const sexp_t sx)

Given an s-expression, determine the length of the list that it encodes. A null expression has length 0. An atom has length 1. A list has length equal to the number of sexp_t elements from the list head to the end of the ->next linked list from that point.

Parameters:
sxS-expression input.
Returns:
Number of sexp_t elements at the same level as sx, 0 for NULL, 1 for an atom.