diff options
| author | Alex Marshall <SquidMan72@gmail.com> | 2009-02-15 03:58:17 -0800 |
|---|---|---|
| committer | Alex Marshall <SquidMan72@gmail.com> | 2009-02-15 03:58:17 -0800 |
| commit | 5614e8c852cb627d05736a01d3a349966faa4d24 (patch) | |
| tree | c7f3cd9ff8989f12b3af1b1c96a4c133c05ddc59 /xml.c | |
| parent | 215cd892afdf8827b3c73d7b726bf073a729ef4c (diff) | |
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.
Diffstat (limited to 'xml.c')
| -rw-r--r-- | xml.c | 68 |
1 files changed, 68 insertions, 0 deletions
@@ -0,0 +1,68 @@ +#include <string.h> +#include <mxml.h> + +#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; +} |
