From 5614e8c852cb627d05736a01d3a349966faa4d24 Mon Sep 17 00:00:00 2001 From: Alex Marshall Date: Sun, 15 Feb 2009 03:58:17 -0800 Subject: Added (partially) functional XML -> BRLAN converter to C side Benzin. Added some other new fun stuff. Look at the converter please comex, its output doesn't work in parse-brlan but works in C benzin. --- xml.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 xml.c (limited to 'xml.c') diff --git a/xml.c b/xml.c new file mode 100644 index 0000000..7eb1cfb --- /dev/null +++ b/xml.c @@ -0,0 +1,68 @@ +#include +#include + +#include "types.h" +#include "xml.h" + +char * /* O - Buffer */ +get_value(mxml_node_t *node, /* I - Node to get */ + void *buffer, /* I - Buffer */ + int buflen) /* I - Size of buffer */ +{ + char *ptr, /* Pointer into buffer */ + *end; /* End of buffer */ + int len; /* Length of node */ + mxml_node_t *current; /* Current node */ + + + ptr = (char*)buffer; + end = (char*)buffer + buflen - 1; + char tempbuf[256]; + current = node->child; + for (current = node->child; current && ptr < end; current = current->next) + { + if (current->type == MXML_TEXT) + { + if (current->value.text.whitespace) + *ptr++ = ' '; + + len = (int)strlen(current->value.text.string); + if (len > (int)(end - ptr)) + len = (int)(end - ptr); + + memcpy(ptr, current->value.text.string, len); + ptr += len; + } + else if (current->type == MXML_OPAQUE) + { + len = (int)strlen(current->value.opaque); + if (len > (int)(end - ptr)) + len = (int)(end - ptr); + + memcpy(ptr, current->value.opaque, len); + ptr += len; + } + else if (current->type == MXML_INTEGER) + { + sprintf(tempbuf, "%f", current->value.integer); + len = (int)strlen(tempbuf); + if (len > (int)(end - ptr)) + len = (int)(end - ptr); + + memcpy(ptr, tempbuf, len); + ptr += len; + } + else if (current->type == MXML_REAL) + { + sprintf(tempbuf, "%f", current->value.real); + len = (int)strlen(tempbuf); + if (len > (int)(end - ptr)) + len = (int)(end - ptr); + + memcpy(ptr, tempbuf, len); + ptr += len; + } + } + *ptr = 0; + return buffer; +} -- cgit v1.3.1