ROOTANA
Macros | Functions | Variables
mxml.cxx File Reference
#include <stdio.h>
#include <fcntl.h>
#include <string.h>
#include <assert.h>
#include <string>
#include <stdlib.h>
#include <unistd.h>
#include <ctype.h>
#include <stdarg.h>
#include <errno.h>
#include <sys/time.h>
#include <time.h>
#include "mxml.h"
Include dependency graph for mxml.cxx:

Go to the source code of this file.

Macros

#define TRUE   1
 
#define FALSE   0
 
#define O_TEXT   0
 
#define O_BINARY   0
 
#define XML_INDENT   " "
 
#define MXML_GNUC_PRINTF(format_idx, arg_idx)
 
#define MXML_GNUC_SCANF(format_idx, arg_idx)
 
#define MXML_GNUC_FORMAT(arg_idx)
 
#define HERE   root, file_name, line_number, error, error_size, error_line
 

Functions

static PMXML_NODE read_error (PMXML_NODE root, const char *file_name, int line_number, char *error, int error_size, int *error_line, const char *format,...) MXML_GNUC_PRINTF(7
 
static PMXML_NODE static void mxml_encode (char *buf, int buf_size, const char *src, int src_len, int translate)
 
static void mxml_decode (char *str)
 
static int mxml_write_subtree (MXML_WRITER *writer, PMXML_NODE tree, int indent)
 
static int mxml_write_line (MXML_WRITER *writer, const char *line)
 
static int mxml_start_element1 (MXML_WRITER *writer, const char *name, int indent)
 
static int mxml_add_resultnode (PMXML_NODE node, const char *xml_path, PMXML_NODE **nodelist, int *found)
 
static int mxml_find_nodes1 (PMXML_NODE tree, const char *xml_path, PMXML_NODE **nodelist, int *found)
 
static void * mxml_malloc (size_t size)
 
static void * mxml_realloc (void *p, size_t size)
 
static void mxml_free (void *p)
 
static size_t mxml_strlcpy (char *dst, const char *src, size_t size)
 
static std::string toString (int i)
 
static std::string toStrerror (int err)
 
MXML_WRITERmxml_open_buffer (void)
 
void mxml_suppress_date (int suppress)
 
MXML_WRITERmxml_open_file (const char *file_name)
 
int mxml_set_translate (MXML_WRITER *writer, int flag)
 
int mxml_start_element (MXML_WRITER *writer, const char *name)
 
int mxml_start_element_noindent (MXML_WRITER *writer, const char *name)
 
int mxml_end_element (MXML_WRITER *writer)
 
int mxml_write_attribute (MXML_WRITER *writer, const char *name, const char *value)
 
int mxml_write_value (MXML_WRITER *writer, const char *data)
 
int mxml_write_empty_line (MXML_WRITER *writer)
 
int mxml_write_comment (MXML_WRITER *writer, const char *string)
 
int mxml_write_element (MXML_WRITER *writer, const char *name, const char *value)
 
char * mxml_close_buffer (MXML_WRITER *writer)
 
int mxml_close_file (MXML_WRITER *writer)
 
PMXML_NODE mxml_create_root_node (void)
 
PMXML_NODE mxml_add_special_node_at (PMXML_NODE parent, int node_type, const char *node_name, const char *value, int idx)
 
PMXML_NODE mxml_add_special_node (PMXML_NODE parent, int node_type, const char *node_name, const char *value)
 
PMXML_NODE mxml_add_node (PMXML_NODE parent, const char *node_name, const char *value)
 
PMXML_NODE mxml_add_node_at (PMXML_NODE parent, const char *node_name, const char *value, int idx)
 
int mxml_add_tree_at (PMXML_NODE parent, PMXML_NODE tree, int idx)
 
int mxml_add_tree (PMXML_NODE parent, PMXML_NODE tree)
 
int mxml_add_attribute (PMXML_NODE pnode, const char *attrib_name, const char *attrib_value)
 
int mxml_get_number_of_children (PMXML_NODE pnode)
 
PMXML_NODE mxml_subnode (PMXML_NODE pnode, int idx)
 
int mxml_find_nodes (PMXML_NODE tree, const char *xml_path, PMXML_NODE **nodelist)
 
PMXML_NODE mxml_find_node (PMXML_NODE tree, const char *xml_path)
 
PMXML_NODE mxml_get_parent (PMXML_NODE pnode)
 
char * mxml_get_name (PMXML_NODE pnode)
 
char * mxml_get_value (PMXML_NODE pnode)
 
int mxml_get_line_number_start (PMXML_NODE pnode)
 
int mxml_get_line_number_end (PMXML_NODE pnode)
 
char * mxml_get_attribute (PMXML_NODE pnode, const char *name)
 
int mxml_replace_node_name (PMXML_NODE pnode, const char *name)
 
int mxml_replace_node_value (PMXML_NODE pnode, const char *value)
 
int mxml_replace_subvalue (PMXML_NODE pnode, const char *name, const char *value)
 
int mxml_replace_attribute_name (PMXML_NODE pnode, const char *old_name, const char *new_name)
 
int mxml_replace_attribute_value (PMXML_NODE pnode, const char *attrib_name, const char *attrib_value)
 
int mxml_delete_node (PMXML_NODE pnode)
 
int mxml_delete_attribute (PMXML_NODE pnode, const char *attrib_name)
 
PMXML_NODE mxml_parse_buffer (const char *buf, char *error, int error_size, int *error_line)
 
int mxml_parse_entity (char **buf, const char *file_name, char *error, int error_size, int *error_line)
 
PMXML_NODE mxml_parse_file (const char *file_name, char *error, int error_size, int *error_line)
 
int mxml_write_tree (const char *file_name, PMXML_NODE tree)
 
PMXML_NODE mxml_clone_tree (PMXML_NODE tree)
 
void mxml_debug_tree (PMXML_NODE tree, int level)
 
void mxml_free_tree (PMXML_NODE tree)
 
void mxml_basename (char *path)
 
void mxml_dirname (char *path)
 
PMXML_NODE mxml_get_node_at_line (PMXML_NODE tree, int line_number)
 

Variables

static int mxml_suppress_date_flag = 0
 

Macro Definition Documentation

◆ FALSE

#define FALSE   0

Definition at line 76 of file mxml.cxx.

◆ HERE

#define HERE   root, file_name, line_number, error, error_size, error_line

Definition at line 1308 of file mxml.cxx.

◆ MXML_GNUC_FORMAT

#define MXML_GNUC_FORMAT (   arg_idx)

Definition at line 109 of file mxml.cxx.

◆ MXML_GNUC_PRINTF

#define MXML_GNUC_PRINTF (   format_idx,
  arg_idx 
)

Definition at line 107 of file mxml.cxx.

◆ MXML_GNUC_SCANF

#define MXML_GNUC_SCANF (   format_idx,
  arg_idx 
)

Definition at line 108 of file mxml.cxx.

◆ O_BINARY

#define O_BINARY   0

Definition at line 80 of file mxml.cxx.

◆ O_TEXT

#define O_TEXT   0

Definition at line 79 of file mxml.cxx.

◆ TRUE

#define TRUE   1

Definition at line 75 of file mxml.cxx.

◆ XML_INDENT

#define XML_INDENT   " "

Definition at line 97 of file mxml.cxx.

Function Documentation

◆ mxml_add_attribute()

int mxml_add_attribute ( PMXML_NODE  pnode,
const char *  attrib_name,
const char *  attrib_value 
)

add an attribute to an existing node

Definition at line 842 of file mxml.cxx.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mxml_add_node()

PMXML_NODE mxml_add_node ( PMXML_NODE  parent,
const char *  node_name,
const char *  value 
)

write value of an XML element, like <[name]>[value]</[name]>

Definition at line 755 of file mxml.cxx.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mxml_add_node_at()

PMXML_NODE mxml_add_node_at ( PMXML_NODE  parent,
const char *  node_name,
const char *  value,
int  idx 
)

add a subnode (child) to an existing parent node at the end

Definition at line 765 of file mxml.cxx.

Here is the call graph for this function:

◆ mxml_add_resultnode()

int mxml_add_resultnode ( PMXML_NODE  node,
const char *  xml_path,
PMXML_NODE **  nodelist,
int *  found 
)
static

Definition at line 891 of file mxml.cxx.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mxml_add_special_node()

PMXML_NODE mxml_add_special_node ( PMXML_NODE  parent,
int  node_type,
const char *  node_name,
const char *  value 
)

add a subnode (child) to an existing parent node at the end

Definition at line 745 of file mxml.cxx.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mxml_add_special_node_at()

PMXML_NODE mxml_add_special_node_at ( PMXML_NODE  parent,
int  node_type,
const char *  node_name,
const char *  value,
int  idx 
)

add a subnode (child) to an existing parent node as a specific position

Definition at line 697 of file mxml.cxx.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mxml_add_tree()

int mxml_add_tree ( PMXML_NODE  parent,
PMXML_NODE  tree 
)

add a whole node tree to an existing parent node at the end

Definition at line 832 of file mxml.cxx.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mxml_add_tree_at()

int mxml_add_tree_at ( PMXML_NODE  parent,
PMXML_NODE  tree,
int  idx 
)

add a whole node tree to an existing parent node at a specific position

Definition at line 775 of file mxml.cxx.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mxml_basename()

void mxml_basename ( char *  path)

mxml_basename deletes any prefix ending with the last slash '/' character present in path. mxml_dirname deletes the filename portion, beginning with the last slash '/' character to the end of path. Followings are examples from these functions

path dirname basename "/" "/" "" "." "." "." "" "" "" "/test.txt" "/" "test.txt" "path/to/test.txt" "path/to" "test.txt" "test.txt "." "test.txt"

Under Windows, '\' and ':' are recognized ad separator too.

Definition at line 2344 of file mxml.cxx.

◆ mxml_clone_tree()

PMXML_NODE mxml_clone_tree ( PMXML_NODE  tree)

Definition at line 2192 of file mxml.cxx.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mxml_close_buffer()

char* mxml_close_buffer ( MXML_WRITER writer)

close a file opened with mxml_open_writer

Definition at line 632 of file mxml.cxx.

Here is the call graph for this function:

◆ mxml_close_file()

int mxml_close_file ( MXML_WRITER writer)

close a file opened with mxml_open_writer

Definition at line 657 of file mxml.cxx.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mxml_create_root_node()

PMXML_NODE mxml_create_root_node ( void  )

create root node of an XML tree

Definition at line 681 of file mxml.cxx.

Here is the caller graph for this function:

◆ mxml_debug_tree()

void mxml_debug_tree ( PMXML_NODE  tree,
int  level 
)

print XML tree for debugging

Definition at line 2223 of file mxml.cxx.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mxml_decode()

void mxml_decode ( char *  str)
static

reverse of mxml_encode, strip leading or trailing '"'

Definition at line 375 of file mxml.cxx.

Here is the caller graph for this function:

◆ mxml_delete_attribute()

int mxml_delete_attribute ( PMXML_NODE  pnode,
const char *  attrib_name 
)

Definition at line 1278 of file mxml.cxx.

Here is the call graph for this function:

◆ mxml_delete_node()

int mxml_delete_node ( PMXML_NODE  pnode)

free memory of a node and remove it from the parent's child list

Definition at line 1245 of file mxml.cxx.

Here is the call graph for this function:

◆ mxml_dirname()

void mxml_dirname ( char *  path)

Definition at line 2371 of file mxml.cxx.

Here is the caller graph for this function:

◆ mxml_encode()

void mxml_encode ( char *  buf,
int  buf_size,
const char *  src,
int  src_len,
int  translate 
)
static

convert '<' '>' '&' '"' ''' into

Definition at line 318 of file mxml.cxx.

Here is the caller graph for this function:

◆ mxml_end_element()

int mxml_end_element ( MXML_WRITER writer)

close an open XML element

Definition at line 483 of file mxml.cxx.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mxml_find_node()

PMXML_NODE mxml_find_node ( PMXML_NODE  tree,
const char *  xml_path 
)

Search for a specific XML node with a subset of XPATH specifications. Return first found node. For syntax see mxml_find_nodes()

Definition at line 1078 of file mxml.cxx.

Here is the call graph for this function:

◆ mxml_find_nodes()

int mxml_find_nodes ( PMXML_NODE  tree,
const char *  xml_path,
PMXML_NODE **  nodelist 
)

Definition at line 1060 of file mxml.cxx.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mxml_find_nodes1()

int mxml_find_nodes1 ( PMXML_NODE  tree,
const char *  xml_path,
PMXML_NODE **  nodelist,
int *  found 
)
static

Return list of XML nodes with a subset of XPATH specifications. Following elemets are possible

/<node>/<node>/..../<node> Find a node in the tree hierarchy /<node>[idx] Find child #[idx] of node (index starts from 1) /<node>[idx]/<node> Find subnode of the above /<node>[<subnode>=

] Find a node which has a specific subnode /<node>[<subnode>=

]/<node> Find subnode of the above /<node>[<attrib>=

]/<node> Find a node which has a specific attribute

Definition at line 923 of file mxml.cxx.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mxml_free()

void mxml_free ( void *  p)
static

Definition at line 191 of file mxml.cxx.

Here is the caller graph for this function:

◆ mxml_free_tree()

void mxml_free_tree ( PMXML_NODE  tree)

free memory of XML tree, must be called after any mxml_create_root_node() or mxml_parse_file()

Definition at line 2273 of file mxml.cxx.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mxml_get_attribute()

char* mxml_get_attribute ( PMXML_NODE  pnode,
const char *  name 
)

Definition at line 1135 of file mxml.cxx.

Here is the caller graph for this function:

◆ mxml_get_line_number_end()

int mxml_get_line_number_end ( PMXML_NODE  pnode)

Definition at line 1127 of file mxml.cxx.

◆ mxml_get_line_number_start()

int mxml_get_line_number_start ( PMXML_NODE  pnode)

Definition at line 1119 of file mxml.cxx.

◆ mxml_get_name()

char* mxml_get_name ( PMXML_NODE  pnode)

Definition at line 1103 of file mxml.cxx.

◆ mxml_get_node_at_line()

PMXML_NODE mxml_get_node_at_line ( PMXML_NODE  tree,
int  line_number 
)

Retieve node at a certain line number

Definition at line 2406 of file mxml.cxx.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mxml_get_number_of_children()

int mxml_get_number_of_children ( PMXML_NODE  pnode)

return number of subnodes (children) of a node

Definition at line 867 of file mxml.cxx.

◆ mxml_get_parent()

PMXML_NODE mxml_get_parent ( PMXML_NODE  pnode)

Definition at line 1095 of file mxml.cxx.

◆ mxml_get_value()

char* mxml_get_value ( PMXML_NODE  pnode)

Definition at line 1111 of file mxml.cxx.

◆ mxml_malloc()

void * mxml_malloc ( size_t  size)
static

Definition at line 177 of file mxml.cxx.

Here is the caller graph for this function:

◆ mxml_open_buffer()

MXML_WRITER* mxml_open_buffer ( void  )

open a memory buffer and write XML header

Definition at line 223 of file mxml.cxx.

Here is the call graph for this function:

◆ mxml_open_file()

MXML_WRITER* mxml_open_file ( const char *  file_name)

open a file and write XML header

Definition at line 272 of file mxml.cxx.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mxml_parse_buffer()

PMXML_NODE mxml_parse_buffer ( const char *  buf,
char *  error,
int  error_size,
int *  error_line 
)

Parse a XML buffer and convert it into a tree of MXML_NODE's. Return NULL in case of an error, return error description. Optional file_name is used for error reporting if called from mxml_parse_file()

Definition at line 1357 of file mxml.cxx.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mxml_parse_entity()

int mxml_parse_entity ( char **  buf,
const char *  file_name,
char *  error,
int  error_size,
int *  error_line 
)

parse !ENTYTY entries of XML files and replace with references. Return 0 in case of no errors, return error description. Optional file_name is used for error reporting if called from mxml_parse_file()

Definition at line 1675 of file mxml.cxx.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mxml_parse_file()

PMXML_NODE mxml_parse_file ( const char *  file_name,
char *  error,
int  error_size,
int *  error_line 
)

parse a XML file and convert it into a tree of MXML_NODE's. Return NULL in case of an error, return error description

Definition at line 2073 of file mxml.cxx.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mxml_realloc()

void * mxml_realloc ( void *  p,
size_t  size 
)
static

Definition at line 184 of file mxml.cxx.

Here is the caller graph for this function:

◆ mxml_replace_attribute_name()

int mxml_replace_attribute_name ( PMXML_NODE  pnode,
const char *  old_name,
const char *  new_name 
)

change the name of an attribute, keep its value

Definition at line 1203 of file mxml.cxx.

Here is the call graph for this function:

◆ mxml_replace_attribute_value()

int mxml_replace_attribute_value ( PMXML_NODE  pnode,
const char *  attrib_name,
const char *  attrib_value 
)

change the value of an attribute

Definition at line 1223 of file mxml.cxx.

Here is the call graph for this function:

◆ mxml_replace_node_name()

int mxml_replace_node_name ( PMXML_NODE  pnode,
const char *  name 
)

Definition at line 1149 of file mxml.cxx.

Here is the call graph for this function:

◆ mxml_replace_node_value()

int mxml_replace_node_value ( PMXML_NODE  pnode,
const char *  value 
)

Definition at line 1157 of file mxml.cxx.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mxml_replace_subvalue()

int mxml_replace_subvalue ( PMXML_NODE  pnode,
const char *  name,
const char *  value 
)

replace value os a subnode, like

<parent> <child>value</child> </parent>

if pnode=parent, and "name"="child", then "value" gets replaced

Definition at line 1184 of file mxml.cxx.

Here is the call graph for this function:

◆ mxml_set_translate()

int mxml_set_translate ( MXML_WRITER writer,
int  flag 
)

set translation of <,>,",',&, on/off in writer

Definition at line 416 of file mxml.cxx.

◆ mxml_start_element()

int mxml_start_element ( MXML_WRITER writer,
const char *  name 
)

Definition at line 466 of file mxml.cxx.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mxml_start_element1()

int mxml_start_element1 ( MXML_WRITER writer,
const char *  name,
int  indent 
)
static

start a new XML element, must be followed by mxml_end_elemnt

Definition at line 429 of file mxml.cxx.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mxml_start_element_noindent()

int mxml_start_element_noindent ( MXML_WRITER writer,
const char *  name 
)

Definition at line 473 of file mxml.cxx.

Here is the call graph for this function:

◆ mxml_strlcpy()

static size_t mxml_strlcpy ( char *  dst,
const char *  src,
size_t  size 
)
static

Definition at line 133 of file mxml.cxx.

Here is the caller graph for this function:

◆ mxml_subnode()

PMXML_NODE mxml_subnode ( PMXML_NODE  pnode,
int  idx 
)

return number of subnodes (children) of a node

Definition at line 878 of file mxml.cxx.

Here is the caller graph for this function:

◆ mxml_suppress_date()

void mxml_suppress_date ( int  suppress)

suppress writing date at the top of file.

Definition at line 262 of file mxml.cxx.

◆ mxml_write_attribute()

int mxml_write_attribute ( MXML_WRITER writer,
const char *  name,
const char *  value 
)

write an attribute to the currently open XML element

Definition at line 523 of file mxml.cxx.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mxml_write_comment()

int mxml_write_comment ( MXML_WRITER writer,
const char *  string 
)

write a comment to an XML file, enclosed in "<!--" and "-->"

Definition at line 590 of file mxml.cxx.

Here is the call graph for this function:

◆ mxml_write_element()

int mxml_write_element ( MXML_WRITER writer,
const char *  name,
const char *  value 
)

shortcut to write an element with a value but without attribute

Definition at line 617 of file mxml.cxx.

Here is the call graph for this function:

◆ mxml_write_empty_line()

int mxml_write_empty_line ( MXML_WRITER writer)

write empty line

Definition at line 572 of file mxml.cxx.

Here is the call graph for this function:

◆ mxml_write_line()

int mxml_write_line ( MXML_WRITER writer,
const char *  line 
)
static

Definition at line 198 of file mxml.cxx.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mxml_write_subtree()

int mxml_write_subtree ( MXML_WRITER writer,
PMXML_NODE  tree,
int  indent 
)
static

write complete subtree recursively into file opened with mxml_open_document()

Definition at line 2144 of file mxml.cxx.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mxml_write_tree()

int mxml_write_tree ( const char *  file_name,
PMXML_NODE  tree 
)

write a complete XML tree to a file

Definition at line 2169 of file mxml.cxx.

Here is the call graph for this function:

◆ mxml_write_value()

int mxml_write_value ( MXML_WRITER writer,
const char *  data 
)

write value of an XML element, like <[name]>[value]</[name]>

Definition at line 547 of file mxml.cxx.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ read_error()

PMXML_NODE read_error ( PMXML_NODE  root,
const char *  file_name,
int  line_number,
char *  error,
int  error_size,
int *  error_line,
const char *  format,
  ... 
)
static

used inside mxml_parse_file for reporting errors

Definition at line 1313 of file mxml.cxx.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ toStrerror()

static std::string toStrerror ( int  err)
static

Definition at line 168 of file mxml.cxx.

Here is the caller graph for this function:

◆ toString()

static std::string toString ( int  i)
static

Definition at line 159 of file mxml.cxx.

Here is the caller graph for this function:

Variable Documentation

◆ mxml_suppress_date_flag

int mxml_suppress_date_flag = 0
static

Definition at line 112 of file mxml.cxx.