added mxml_suppress_date and mxml_write_empty_line.

fixed a bug in mxml_add_tree
This commit is contained in:
Matthias Schneebeli 2007-02-15 12:37:08 +00:00
parent e77b8b1116
commit dd5481e113
2 changed files with 43 additions and 7 deletions

44
mxml.c
View File

@ -78,6 +78,8 @@
#define XML_INDENT " " #define XML_INDENT " "
static int mxml_suppress_date_flag = 0; /* suppress writing date at the top of file. */
/* local prototypes */ /* local prototypes */
static PMXML_NODE read_error(PMXML_NODE root, const char *file_name, int line_number, char *error, int error_size, char *format, ...); static PMXML_NODE read_error(PMXML_NODE root, const char *file_name, int line_number, char *error, int error_size, char *format, ...);
static void mxml_encode(char *src, int size, int translate); static void mxml_encode(char *src, int size, int translate);
@ -138,6 +140,7 @@ MXML_WRITER *mxml_open_buffer()
strcpy(str, ctime(&now)); strcpy(str, ctime(&now));
str[24] = 0; str[24] = 0;
sprintf(line, "<!-- created by MXML on %s -->\n", str); sprintf(line, "<!-- created by MXML on %s -->\n", str);
if (mxml_suppress_date_flag == 0)
mxml_write_line(writer, line); mxml_write_line(writer, line);
/* initialize stack */ /* initialize stack */
@ -149,6 +152,16 @@ MXML_WRITER *mxml_open_buffer()
/*------------------------------------------------------------------*/ /*------------------------------------------------------------------*/
/**
* suppress writing date at the top of file.
*/
void mxml_suppress_date(int suppress)
{
mxml_suppress_date_flag = suppress;
}
/*------------------------------------------------------------------*/
/** /**
* open a file and write XML header * open a file and write XML header
*/ */
@ -178,6 +191,7 @@ MXML_WRITER *mxml_open_file(const char *file_name)
strcpy(str, ctime(&now)); strcpy(str, ctime(&now));
str[24] = 0; str[24] = 0;
sprintf(line, "<!-- created by MXML on %s -->\n", str); sprintf(line, "<!-- created by MXML on %s -->\n", str);
if (mxml_suppress_date_flag == 0)
mxml_write_line(writer, line); mxml_write_line(writer, line);
/* initialize stack */ /* initialize stack */
@ -457,6 +471,24 @@ int mxml_write_value(MXML_WRITER *writer, const char *data)
/*------------------------------------------------------------------*/ /*------------------------------------------------------------------*/
/**
* write empty line
*/
int mxml_write_empty_line(MXML_WRITER *writer)
{
if (writer->element_is_open) {
mxml_write_line(writer, ">\n");
writer->element_is_open = FALSE;
}
if (mxml_write_line(writer, "\n") != 1)
return FALSE;
return TRUE;
}
/*------------------------------------------------------------------*/
/** /**
* write a comment to an XML file, enclosed in "<!--" and "-->" * write a comment to an XML file, enclosed in "<!--" and "-->"
*/ */
@ -636,7 +668,7 @@ PMXML_NODE mxml_add_node_at(PMXML_NODE parent, const char *node_name, const char
int mxml_add_tree_at(PMXML_NODE parent, PMXML_NODE tree, int index) int mxml_add_tree_at(PMXML_NODE parent, PMXML_NODE tree, int index)
{ {
PMXML_NODE pchild; PMXML_NODE pchild;
int i, j; int i, j, k;
assert(parent); assert(parent);
assert(tree); assert(tree);
@ -663,10 +695,10 @@ int mxml_add_tree_at(PMXML_NODE parent, PMXML_NODE tree, int index)
memcpy(&parent->child[i], &parent->child[i-1], sizeof(MXML_NODE)); memcpy(&parent->child[i], &parent->child[i-1], sizeof(MXML_NODE));
/* correct parent pointer for children */ /* correct parent pointer for children */
for (i=0 ; i<parent->n_children ; i++) { for (j=0 ; j<parent->n_children ; j++) {
pchild = parent->child+i; pchild = parent->child+j;
for (j=0 ; j<pchild->n_children ; j++) for (k=0 ; k<pchild->n_children ; k++)
pchild->child[j].parent = pchild; pchild->child[k].parent = pchild;
} }
} }
@ -745,6 +777,8 @@ PMXML_NODE mxml_subnode(PMXML_NODE pnode, int index)
/*------------------------------------------------------------------*/ /*------------------------------------------------------------------*/
int mxml_find_nodes1(PMXML_NODE tree, const char *xml_path, PMXML_NODE **nodelist, int *found);
int mxml_add_resultnode(PMXML_NODE node, const char *xml_path, PMXML_NODE **nodelist, int *found) int mxml_add_resultnode(PMXML_NODE node, const char *xml_path, PMXML_NODE **nodelist, int *found)
{ {
/* if at end of path, add this node */ /* if at end of path, add this node */

2
mxml.h
View File

@ -73,6 +73,7 @@ extern "C" {
#endif #endif
#endif #endif
void mxml_suppress_date(int suppress);
MXML_WRITER *mxml_open_file(const char *file_name); MXML_WRITER *mxml_open_file(const char *file_name);
MXML_WRITER *mxml_open_buffer(void); MXML_WRITER *mxml_open_buffer(void);
int mxml_set_translate(MXML_WRITER *writer, int flag); int mxml_set_translate(MXML_WRITER *writer, int flag);
@ -82,6 +83,7 @@ int mxml_end_element(MXML_WRITER *writer);
int mxml_write_comment(MXML_WRITER *writer, const char *string); int mxml_write_comment(MXML_WRITER *writer, const char *string);
int mxml_write_attribute(MXML_WRITER *writer, const char *name, const char *value); int mxml_write_attribute(MXML_WRITER *writer, const char *name, const char *value);
int mxml_write_value(MXML_WRITER *writer, const char *value); int mxml_write_value(MXML_WRITER *writer, const char *value);
int mxml_write_empty_line(MXML_WRITER *writer);
char *mxml_close_buffer(MXML_WRITER *writer); char *mxml_close_buffer(MXML_WRITER *writer);
int mxml_close_file(MXML_WRITER *writer); int mxml_close_file(MXML_WRITER *writer);