From f8952f732115d36a2b5f0c2a8a520f1ccd9db545 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 16 Dec 2014 15:50:30 +0200 Subject: Update to new revision of genx Now by elements with empty content a closed immediately and attributes are no longer sorted. --- NEWS | 7 + libxsde/xsde/c/genx/char-props.c | 8 +- libxsde/xsde/c/genx/genx.c | 370 +++++++++++++++------ libxsde/xsde/c/genx/genx.h | 25 +- tests/cxx/hybrid/binary/cdr/test-000.std | 2 +- tests/cxx/hybrid/binary/custom/test-000.std | 2 +- tests/cxx/hybrid/binary/xdr/test-000.std | 2 +- tests/cxx/hybrid/built-in/test-000.std | 2 +- tests/cxx/hybrid/choice/test-000.std | 2 +- tests/cxx/hybrid/clone/test-000.std | 2 +- tests/cxx/hybrid/default/test-000.std | 2 +- .../cxx/hybrid/polymorphism/any-type/test-000.std | 6 +- .../hybrid/polymorphism/enumeration/test-000.std | 2 +- tests/cxx/hybrid/recursive/test-000.std | 2 +- tests/cxx/serializer/all/test-000.std | 2 +- tests/cxx/serializer/built-in/test-001.std | 4 +- tests/cxx/serializer/choice/test-000.std | 2 +- tests/cxx/serializer/list/test-000.std | 2 +- tests/cxx/serializer/recursive/test-000.std | 2 +- tests/cxx/serializer/restriction/test-000.std | 2 +- tests/cxx/serializer/sequence/test-000.std | 2 +- tests/cxx/serializer/wildcard/test-000.std | 2 +- 22 files changed, 317 insertions(+), 135 deletions(-) diff --git a/NEWS b/NEWS index 6ae571e..0e58e03 100644 --- a/NEWS +++ b/NEWS @@ -9,6 +9,13 @@ Version 3.3.0 C++/Serializer + * Elements with empty content are now closed immediately (for example, + ) rather than with a separate closing tag (for example, + ). + + * To improve serialization performance, attributes are not longer + sorted but rather written in the order that they were specified. + * Support for the fractionDigits facet for the decimal data type. * New functions, format() and precision(), allow changing of the diff --git a/libxsde/xsde/c/genx/char-props.c b/libxsde/xsde/c/genx/char-props.c index c9db225..1b9a5aa 100644 --- a/libxsde/xsde/c/genx/char-props.c +++ b/libxsde/xsde/c/genx/char-props.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007-2014 Code Synthesis Tools CC. + * Copyright (c) 2007-2013 Code Synthesis Tools CC. * Copyright (c) 2004 by Tim Bray and Sun Microsystems. * * For copying permission, see the accompanying COPYING file. @@ -20,16 +20,16 @@ static void charProp(char * p, int c, int prop) p[c] |= prop; } -static void rangeProp(char * p, int start, int end, int prop) +static void rangeProp(char * p, size_t start, size_t end, int prop) { - int i; + size_t i; for (i = start; i <= end; i++) p[i] |= prop; } void genxSetCharProps(char * p) { - int i; + size_t i; for (i = 0; i < GENX_CHAR_TABLE_SIZE; i++) p[i] = 0; diff --git a/libxsde/xsde/c/genx/genx.c b/libxsde/xsde/c/genx/genx.c index 39cd8ae..c4c73a8 100644 --- a/libxsde/xsde/c/genx/genx.c +++ b/libxsde/xsde/c/genx/genx.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007-2014 Code Synthesis Tools CC. + * Copyright (c) 2007-2013 Code Synthesis Tools CC. * Copyright (c) 2004 by Tim Bray and Sun Microsystems. * * For copying permission, see the accompanying COPYING file. @@ -47,8 +47,8 @@ typedef enum typedef struct { genxWriter writer; - int count; - int space; + size_t count; + size_t space; void * * pointers; } plist; @@ -58,8 +58,8 @@ typedef struct typedef struct { utf8 buf; - int used; - int space; + size_t used; + size_t space; } collector; /******************************* @@ -79,7 +79,7 @@ struct genxNamespace_rec { genxWriter writer; utf8 name; - int declCount; + size_t declCount; Boolean baroque; genxAttribute declaration; genxAttribute defaultDecl; @@ -107,6 +107,7 @@ struct genxAttribute_rec collector value; int provided; /* provided for current element? */ attrType atype; + genxAttribute next; /* Attribute order chain if not canonical. */ }; /******************************* @@ -130,7 +131,7 @@ struct genxWriter_rec plist attributes; plist prefixes; plist stack; - struct genxAttribute_rec arec; + struct genxAttribute_rec arec; /* Dummy attribute used for lookup. */ char * etext[100]; genxAlloc alloc; genxDealloc dealloc; @@ -139,6 +140,13 @@ struct genxWriter_rec int ppIndent; int ppDepth; Boolean ppSimple; + + /* Canonicalization. */ + Boolean canonical; + + /* Attrbute order when not canonical. */ + genxAttribute firstAttribute; + genxAttribute lastAttribute; }; /******************************* @@ -159,7 +167,7 @@ void genxSetCharProps(char * p); /******************************* * private memory utilities */ -static void * allocate(genxWriter w, int bytes) +static void * allocate(genxWriter w, size_t bytes) { if (w->alloc) return (void *) (*w->alloc)(w->userData, bytes); @@ -202,7 +210,7 @@ static genxStatus initCollector(genxWriter w, collector * c) return GENX_SUCCESS; } -static genxStatus growCollector(genxWriter w, collector * c, int size) +static genxStatus growCollector(genxWriter w, collector * c, size_t size) { utf8 newSpace; @@ -228,7 +236,7 @@ static void endCollect(collector * c) static genxStatus collectString(genxWriter w, collector * c, constUtf8 string) { - int sl = strlen((const char *) string); + size_t sl = strlen((const char *) string); if (sl >= c->space) if ((w->status = growCollector(w, c, sl)) != GENX_SUCCESS) @@ -261,7 +269,7 @@ static genxStatus initPlist(genxWriter w, plist * pl) static Boolean checkExpand(plist * pl) { void * * newlist; - int i; + size_t i; if (pl->count < pl->space) return True; @@ -293,9 +301,9 @@ static genxStatus listAppend(plist * pl, void * pointer) /* * insert in place, shuffling up */ -static genxStatus listInsert(plist * pl, void * pointer, int at) +static genxStatus listInsert(plist * pl, void * pointer, size_t at) { - int i; + size_t i; if (!checkExpand(pl)) return GENX_ALLOC_FAILED; @@ -314,7 +322,7 @@ static genxStatus listInsert(plist * pl, void * pointer, int at) static genxNamespace findNamespace(plist * pl, constUtf8 uri) { - int i; + size_t i; genxNamespace * nn = (genxNamespace *) pl->pointers; for (i = 0; i < pl->count; i++) @@ -326,7 +334,7 @@ static genxNamespace findNamespace(plist * pl, constUtf8 uri) static genxElement findElement(plist * pl, constUtf8 xmlns, constUtf8 type) { - int i; + size_t i; genxElement * ee = (genxElement *) pl->pointers; for (i = 0; i < pl->count; i++) @@ -368,7 +376,8 @@ static utf8 storePrefix(genxWriter w, constUtf8 prefix, Boolean force) prefix = buf; } - high = w->prefixes.count; low = -1; + high = (int) w->prefixes.count; + low = -1; while (high - low > 1) { int probe = (high + low) / 2; @@ -395,7 +404,7 @@ static utf8 storePrefix(genxWriter w, constUtf8 prefix, Boolean force) return NULL; } - w->status = listInsert(&w->prefixes, (void *) prefix, high); + w->status = listInsert(&w->prefixes, (void *) prefix, (size_t) high); if (w->status != GENX_SUCCESS) return NULL; @@ -593,29 +602,28 @@ genxWriter genxNew(genxAlloc alloc, genxDealloc dealloc, void * userData) genxSetCharProps(w->xmlChars); - w->etext[GENX_SUCCESS] = "Success"; - w->etext[GENX_BAD_UTF8] = "Bad UTF8"; - w->etext[GENX_NON_XML_CHARACTER] = "Non XML Character"; - w->etext[GENX_BAD_NAME] = "Bad NAME"; - w->etext[GENX_ALLOC_FAILED] = "Memory allocation failed"; - w->etext[GENX_BAD_NAMESPACE_NAME] = "Bad namespace name"; - w->etext[GENX_INTERNAL_ERROR] = "Internal error"; - w->etext[GENX_DUPLICATE_PREFIX] = "Duplicate prefix"; - w->etext[GENX_SEQUENCE_ERROR] = "Call out of sequence"; - w->etext[GENX_NO_START_TAG] = "No Start-tag for EndElement call"; - w->etext[GENX_IO_ERROR] = "I/O error"; - w->etext[GENX_MISSING_VALUE] = "Missing attribute value"; - w->etext[GENX_MALFORMED_COMMENT] = "Malformed comment body"; + w->etext[GENX_SUCCESS] = "success"; + w->etext[GENX_BAD_UTF8] = "invalid UTF-8"; + w->etext[GENX_NON_XML_CHARACTER] = "non-XML character"; + w->etext[GENX_BAD_NAME] = "invalid name"; + w->etext[GENX_ALLOC_FAILED] = "memory allocation failed"; + w->etext[GENX_BAD_NAMESPACE_NAME] = "invalid namespace name"; + w->etext[GENX_INTERNAL_ERROR] = "internal error"; + w->etext[GENX_DUPLICATE_PREFIX] = "duplicate prefix"; + w->etext[GENX_SEQUENCE_ERROR] = "call out of sequence"; + w->etext[GENX_NO_START_TAG] = "no start tag for end element call"; + w->etext[GENX_IO_ERROR] = "io error"; + w->etext[GENX_MISSING_VALUE] = "missing attribute value"; + w->etext[GENX_MALFORMED_COMMENT] = "malformed comment body"; w->etext[GENX_MALFORMED_PI] = "?> in PI"; - w->etext[GENX_XML_PI_TARGET] = "Target of PI matches [xX][mM][lL]"; - w->etext[GENX_DUPLICATE_ATTRIBUTE] = - "Same attribute specified more than once"; + w->etext[GENX_XML_PI_TARGET] = "target of PI matches [xX][mM][lL]"; + w->etext[GENX_DUPLICATE_ATTRIBUTE] = "duplicate attribute"; w->etext[GENX_ATTRIBUTE_IN_DEFAULT_NAMESPACE] = - "Attribute cannot be in default namespace"; + "attribute is default namespace"; w->etext[GENX_DUPLICATE_NAMESPACE] = - "Declared namespace twice with different prefixes on one element."; + "namespace declared twice with different prefixes"; w->etext[GENX_BAD_DEFAULT_DECLARATION] = - "Declared a default namespace on an element which is in no namespace"; + "default namespace declared on an element which is not in a namespace"; /* the xml: namespace is pre-wired */ xml = genxDeclareNamespace(w, (utf8) "http://www.w3.org/XML/1998/namespace", @@ -626,13 +634,16 @@ genxWriter genxNew(genxAlloc alloc, genxDealloc dealloc, void * userData) xml->declaration = xml->defaultDecl; w->ppIndent = 0; /* Pretty-printing is disabled by default. */ + w->canonical = False; /* No canonicalization by default. */ + w->firstAttribute = NULL; + w->lastAttribute = NULL; return w; } genxStatus genxReset (genxWriter w) { - int i; + size_t i; /* Clean up the stack. */ w->stack.count = 0; @@ -647,6 +658,23 @@ genxStatus genxReset (genxWriter w) ((genxNamespace) w->namespaces.pointers[i])->baroque = False; } + /* Clear provided attributes. */ + for (i = 0; i < w->attributes.count; i++) + ((genxAttribute) w->attributes.pointers[i])->provided = False; + + /* Clear attribute list. */ + if (!w->canonical) + { + while (w->firstAttribute != NULL) + { + genxAttribute t = w->firstAttribute->next; + w->firstAttribute->next = NULL; + w->firstAttribute = t; + } + + w->lastAttribute = NULL; + } + w->status = GENX_SUCCESS; w->sequence = SEQUENCE_NO_DOC; @@ -685,6 +713,24 @@ int genxGetPrettyPrint(genxWriter w) } /* + * get/set canonicalization. + */ +genxStatus genxSetCanonical(genxWriter w, int flag) +{ + if (w->sequence == SEQUENCE_NO_DOC) + w->canonical = flag; + else + w->status = GENX_SEQUENCE_ERROR; + + return w->status; +} + +int genxGetCanonical(genxWriter w) +{ + return w->canonical; +} + +/* * get/set allocator */ void genxSetAlloc(genxWriter w, genxAlloc alloc) @@ -712,7 +758,7 @@ genxDealloc genxGetDealloc(genxWriter w) */ void genxDispose(genxWriter w) { - int i; + size_t i; genxNamespace * nn = (genxNamespace *) w->namespaces.pointers; genxElement * ee = (genxElement *) w->elements.pointers; genxAttribute * aa = (genxAttribute *) w->attributes.pointers; @@ -1084,7 +1130,8 @@ static genxAttribute declareAttribute(genxWriter w, genxNamespace ns, } /* attribute list has to be kept sorted per c14n rules */ - high = w->attributes.count; low = -1; + high = (int) w->attributes.count; + low = -1; while (high - low > 1) { int probe = (high + low) / 2; @@ -1110,6 +1157,7 @@ static genxAttribute declareAttribute(genxWriter w, genxNamespace ns, a->ns = ns; a->provided = False; a->atype = w->arec.atype; + a->next = NULL; if ((a->name = copy(w, name)) == NULL) { @@ -1124,7 +1172,7 @@ static genxAttribute declareAttribute(genxWriter w, genxNamespace ns, if ((w->status = collectString(w, &a->value, valuestr)) != GENX_SUCCESS) goto busted; - w->status = listInsert(&w->attributes, a, high); + w->status = listInsert(&w->attributes, a, (size_t) high); if (w->status != GENX_SUCCESS) goto busted; @@ -1171,7 +1219,7 @@ static genxStatus sendxBounded(genxWriter w, constUtf8 start, constUtf8 end) return GENX_IO_ERROR; } -#define SendCheck(w,s) if ((w->status=sendx(w,(utf8)s))!=GENX_SUCCESS) return w->status; +#define SendCheck(w,s) if ((w->status=sendx(w,(constUtf8)s))!=GENX_SUCCESS) return w->status /******************************* * XML writing routines. The semantics of the externally-facing ones are @@ -1212,6 +1260,32 @@ static genxStatus writeIndentation(genxWriter w) } /* + * Output attribute. + */ +static genxStatus writeAttribute(genxAttribute a) +{ + genxWriter w = a->writer; + + if (a->ns && a->ns->baroque && a->ns->declaration == w->xmlnsEquals) + return w->status = GENX_ATTRIBUTE_IN_DEFAULT_NAMESPACE; + + SendCheck(w, " "); + + if (a->ns) + { + SendCheck(w, a->ns->declaration->name + STRLEN_XMLNS_COLON); + SendCheck(w, ":"); + } + + SendCheck(w, a->name); + SendCheck(w, "=\""); + SendCheck(w, a->value.buf); + SendCheck(w, "\""); + + return w->status; +} + +/* * Write out the attributes we've been gathering up for an element. We save * them until we've gathered them all so they can be writen in canonical * order. @@ -1220,9 +1294,9 @@ static genxStatus writeIndentation(genxWriter w) * we build it, then as each attribute is added, we fill in its value and * mark the fact that it's been added, in the "provided" field. */ -static genxStatus writeStartTag(genxWriter w) +static genxStatus writeStartTag(genxWriter w, Boolean close) { - int i; + size_t i; genxAttribute * aa = (genxAttribute *) w->attributes.pointers; genxElement e = w->nowStarting; @@ -1242,8 +1316,11 @@ static genxStatus writeStartTag(genxWriter w) if (writeIndentation (w) != GENX_SUCCESS) return w->status; - w->ppDepth++; - w->ppSimple = True; + if (!close) + { + w->ppDepth++; + w->ppSimple = True; + } } SendCheck(w, "<"); @@ -1254,27 +1331,42 @@ static genxStatus writeStartTag(genxWriter w) } SendCheck(w, e->type); - for (i = 0; i < w->attributes.count; i++) + /* If we are canonicalizing, then write sorted attributes. Otherwise + write them in the order specified. */ + if (w->canonical) { - if (aa[i]->provided) + for (i = 0; i < w->attributes.count; i++) { - if (aa[i]->ns && aa[i]->ns->baroque && - aa[i]->ns->declaration == w->xmlnsEquals) - return w->status = GENX_ATTRIBUTE_IN_DEFAULT_NAMESPACE; - - SendCheck(w, " "); - - if (aa[i]->ns) + if (aa[i]->provided) { - SendCheck(w, aa[i]->ns->declaration->name + STRLEN_XMLNS_COLON) - SendCheck(w, ":"); + if (writeAttribute (aa[i]) != GENX_SUCCESS) + return w->status; + + aa[i]->provided = False; } - SendCheck(w, aa[i]->name); - SendCheck(w, "=\""); - SendCheck(w, aa[i]->value.buf); - SendCheck(w, "\""); } } + else + { + /* Keep the chain consistent even if we bail out mid way because of + an error. This way we will still be able to clear it in reset().*/ + while (w->firstAttribute != NULL) + { + genxAttribute t = w->firstAttribute->next; + + if (writeAttribute (w->firstAttribute) != GENX_SUCCESS) + return w->status; + + w->firstAttribute->provided = False; + w->firstAttribute->next = NULL; + w->firstAttribute = t; + } + + w->lastAttribute = NULL; + } + + if (close) + SendCheck(w, "/"); SendCheck(w, ">"); return GENX_SUCCESS; } @@ -1288,7 +1380,7 @@ static genxStatus unsetDefaultNamespace(genxWriter w) Boolean found = False; /* don't put it in if not needed */ - i = w->stack.count - 1; + i = (int) (w->stack.count) - 1; while (found == False && i > 0) { while (w->stack.pointers[i] != NULL) @@ -1346,7 +1438,6 @@ genxStatus genxUnsetDefaultNamespace(genxWriter w) genxStatus genxStartElement(genxElement e) { genxWriter w = e->writer; - int i; switch (w->sequence) { @@ -1356,7 +1447,7 @@ genxStatus genxStartElement(genxElement e) return w->status = GENX_SEQUENCE_ERROR; case SEQUENCE_START_TAG: case SEQUENCE_ATTRIBUTES: - if ((w->status = writeStartTag(w)) != GENX_SUCCESS) + if ((w->status = writeStartTag(w, False)) != GENX_SUCCESS) return w->status; break; case SEQUENCE_PRE_DOC: @@ -1366,10 +1457,6 @@ genxStatus genxStartElement(genxElement e) w->sequence = SEQUENCE_START_TAG; - /* clear provided attributes */ - for (i = 0; i < w->attributes.count; i++) - ((genxAttribute) w->attributes.pointers[i])->provided = 0; - /* * push the stack. We push a NULL after a pointer to this element * because the stack will also contain pointers to the namespace @@ -1438,7 +1525,7 @@ static genxStatus addNamespace(genxNamespace ns, constUtf8 prefix) * case it's a no-op; or, if there's another declaration for this * prefix on another namespace, in which case we have to over-ride */ - i = w->stack.count - 1; + i = (int) (w->stack.count) - 1; while (i > 0) { while (w->stack.pointers[i] != NULL) @@ -1474,7 +1561,7 @@ static genxStatus addNamespace(genxNamespace ns, constUtf8 prefix) * If this namespace is already declared on * this element (with different prefix/decl) which is an error. */ - i = w->stack.count - 1; + i = (int) (w->stack.count) - 1; while (w->stack.pointers[i] != NULL) { genxNamespace otherNs; @@ -1596,7 +1683,17 @@ static genxStatus addAttribute(genxAttribute a, constUtf8 valuestr) if (valuestr && a->provided) return w->status = GENX_DUPLICATE_ATTRIBUTE; - a->provided = 1; + + a->provided = True; + + /* Add the attribute to the ordered list if not canonical. */ + if (!w->canonical) + { + if (w->lastAttribute != NULL) + w->lastAttribute = w->lastAttribute->next = a; + else + w->lastAttribute = w->firstAttribute = a; + } return GENX_SUCCESS; } @@ -1653,15 +1750,24 @@ genxStatus genxEndAttribute(genxWriter w) if (a->provided) return w->status = GENX_DUPLICATE_ATTRIBUTE; - a->provided = 1; + a->provided = True; + + /* Add the attribute to the ordered list if not canonical. */ + if (!w->canonical) + { + if (w->lastAttribute != NULL) + w->lastAttribute = w->lastAttribute->next = a; + else + w->lastAttribute = w->firstAttribute = a; + } return GENX_SUCCESS; } genxStatus genxEndElement(genxWriter w) { - genxElement e; int i; + Boolean close = True; switch (w->sequence) { @@ -1672,42 +1778,54 @@ genxStatus genxEndElement(genxWriter w) return w->status = GENX_SEQUENCE_ERROR; case SEQUENCE_START_TAG: case SEQUENCE_ATTRIBUTES: - if ((w->status = writeStartTag(w)) != GENX_SUCCESS) + if ((w->status = writeStartTag(w, !w->canonical)) != GENX_SUCCESS) return w->status; + close = w->canonical; break; case SEQUENCE_CONTENT: break; } /* - * first peek into the stack to find the right namespace declaration - * (if any) so we can properly prefix the end-tag. Have to do this - * before unwinding the stack because that might reset some xmlns - * prefixes to the context in the parent element + * Output the closing tag. */ - for (i = w->stack.count - 1; w->stack.pointers[i] != NULL; i -= 2) - ; - e = (genxElement) w->stack.pointers[--i]; - - if (w->ppIndent) + if (close) { - w->ppDepth--; + genxElement e; - if (!w->ppSimple) - if (writeIndentation (w) != GENX_SUCCESS) - return w->status; + /* + * first peek into the stack to find the right namespace declaration + * (if any) so we can properly prefix the end-tag. Have to do this + * before unwinding the stack because that might reset some xmlns + * prefixes to the context in the parent element + */ + for (i = (int) (w->stack.count) - 1; + w->stack.pointers[i] != NULL; + i -= 2) + ; + e = (genxElement) w->stack.pointers[--i]; - w->ppSimple = False; - } + if (w->ppIndent) + { + w->ppDepth--; - SendCheck(w, "ns && e->ns->declaration != w->xmlnsEquals) - { - SendCheck(w, e->ns->declaration->name + STRLEN_XMLNS_COLON); - SendCheck(w, ":"); + if (!w->ppSimple) + if (writeIndentation (w) != GENX_SUCCESS) + return w->status; + } + + SendCheck(w, "ns && e->ns->declaration != w->xmlnsEquals) + { + SendCheck(w, e->ns->declaration->name + STRLEN_XMLNS_COLON); + SendCheck(w, ":"); + } + SendCheck(w, e->type); + SendCheck(w, ">"); } - SendCheck(w, e->type); - SendCheck(w, ">"); + + if (w->ppIndent) + w->ppSimple = False; /* * pop zero or more namespace declarations, then a null, then the @@ -1729,7 +1847,7 @@ genxStatus genxEndElement(genxWriter w) */ if (ns->baroque) { - i = w->stack.count; + i = (int) w->stack.count; while (i > 0) { while (w->stack.pointers[i] != NULL) @@ -1756,9 +1874,9 @@ genxStatus genxEndElement(genxWriter w) } /* pop the NULL */ - --w->stack.count; - if (w->stack.count < 0) + if (w->stack.count == 0) return w->status = GENX_NO_START_TAG; + --w->stack.count; if (w->stack.count == 0) w->sequence = SEQUENCE_POST_DOC; @@ -1828,7 +1946,7 @@ genxStatus genxAddText(genxWriter w, constUtf8 start) if (w->sequence == SEQUENCE_START_TAG || w->sequence == SEQUENCE_ATTRIBUTES) { - if ((w->status = writeStartTag(w)) != GENX_SUCCESS) + if ((w->status = writeStartTag(w, False)) != GENX_SUCCESS) return w->status; w->sequence = SEQUENCE_CONTENT; } @@ -1861,7 +1979,7 @@ genxStatus genxAddBoundedText(genxWriter w, constUtf8 start, constUtf8 end) if (w->sequence == SEQUENCE_START_TAG || w->sequence == SEQUENCE_ATTRIBUTES) { - if ((w->status = writeStartTag(w)) != GENX_SUCCESS) + if ((w->status = writeStartTag(w, False)) != GENX_SUCCESS) return w->status; w->sequence = SEQUENCE_CONTENT; } @@ -1886,7 +2004,7 @@ genxStatus genxAddBoundedText(genxWriter w, constUtf8 start, constUtf8 end) return w->status = GENX_SEQUENCE_ERROR; } -genxStatus genxAddCountedText(genxWriter w, constUtf8 start, int byteCount) +genxStatus genxAddCountedText(genxWriter w, constUtf8 start, size_t byteCount) { utf8 end = (utf8) (start + byteCount); @@ -1901,7 +2019,7 @@ genxStatus genxAddCharacter(genxWriter w, int c) if (w->sequence == SEQUENCE_START_TAG || w->sequence == SEQUENCE_ATTRIBUTES) { - if ((w->status = writeStartTag(w)) != GENX_SUCCESS) + if ((w->status = writeStartTag(w, False)) != GENX_SUCCESS) return w->status; w->sequence = SEQUENCE_CONTENT; } @@ -1998,6 +2116,9 @@ genxStatus genxEndDocument(genxWriter w) if (w->sequence != SEQUENCE_POST_DOC) return w->status = GENX_SEQUENCE_ERROR; + /* Write a newline after the closing tag. */ + /* Disabled for xsde SendCheck (w, "\n");*/ + if ((w->status = (*w->sender->flush)(w->userData)) != GENX_SUCCESS) return w->status; @@ -2005,9 +2126,46 @@ genxStatus genxEndDocument(genxWriter w) return GENX_SUCCESS; } +genxStatus genxXmlDeclaration(genxWriter w, + constUtf8 ver, + constUtf8 enc, + constUtf8 stl) +{ + if (w->sequence != SEQUENCE_PRE_DOC) + return w->status = GENX_SEQUENCE_ERROR; + + if ((w->status = genxCheckText(w, ver)) != GENX_SUCCESS) + return w->status; + + if (enc != NULL && (w->status = genxCheckText(w, enc)) != GENX_SUCCESS) + return w->status; + + if (stl != NULL && (w->status = genxCheckText(w, stl)) != GENX_SUCCESS) + return w->status; + + SendCheck (w, "\n"); + + return GENX_SUCCESS; +} + genxStatus genxComment(genxWriter w, constUtf8 text) { - int i; + size_t i; if (w->sequence == SEQUENCE_NO_DOC || w->sequence == SEQUENCE_START_ATTR) @@ -2026,7 +2184,7 @@ genxStatus genxComment(genxWriter w, constUtf8 text) if (w->sequence == SEQUENCE_START_TAG || w->sequence == SEQUENCE_ATTRIBUTES) { - if ((w->status = writeStartTag(w)) != GENX_SUCCESS) + if ((w->status = writeStartTag(w, False)) != GENX_SUCCESS) return w->status; w->sequence = SEQUENCE_CONTENT; } @@ -2051,7 +2209,7 @@ genxStatus genxComment(genxWriter w, constUtf8 text) genxStatus genxPI(genxWriter w, constUtf8 target, constUtf8 text) { - int i; + size_t i; if (w->sequence == SEQUENCE_NO_DOC || w->sequence == SEQUENCE_START_ATTR) @@ -2079,7 +2237,7 @@ genxStatus genxPI(genxWriter w, constUtf8 target, constUtf8 text) if (w->sequence == SEQUENCE_START_TAG || w->sequence == SEQUENCE_ATTRIBUTES) { - if ((w->status = writeStartTag(w)) != GENX_SUCCESS) + if ((w->status = writeStartTag(w, False)) != GENX_SUCCESS) return w->status; w->sequence = SEQUENCE_CONTENT; } diff --git a/libxsde/xsde/c/genx/genx.h b/libxsde/xsde/c/genx/genx.h index 2b04806..bdaeee1 100644 --- a/libxsde/xsde/c/genx/genx.h +++ b/libxsde/xsde/c/genx/genx.h @@ -3,7 +3,7 @@ */ /* - * Copyright (c) 2007-2014 Code Synthesis Tools CC. + * Copyright (c) 2007-2013 Code Synthesis Tools CC. * Copyright (c) 2004 by Tim Bray and Sun Microsystems. * * For copying permission, see the accompanying COPYING file. @@ -12,6 +12,8 @@ #ifndef GENX_H #define GENX_H +#include /* size_t */ + #ifdef __cplusplus extern "C" { #endif @@ -71,7 +73,7 @@ typedef struct genxNamespace_rec * genxNamespace; typedef struct genxElement_rec * genxElement; typedef struct genxAttribute_rec * genxAttribute; -typedef void * (*genxAlloc) (void * userData, int bytes); +typedef void * (*genxAlloc) (void * userData, size_t bytes); typedef void (*genxDealloc) (void * userData, void* data); /* @@ -116,6 +118,13 @@ genxStatus genxSetPrettyPrint(genxWriter w, int indentation); int genxGetPrettyPrint(genxWriter w); /* + * Set/get canonicalization. If true, then output explicit closing + * tags and sort attributes. Default is false. + */ +genxStatus genxSetCanonical(genxWriter w, int flag); +int genxGetCanonical(genxWriter w); + +/* * User-provided memory allocator, if desired. For example, if you were * in an Apache module, you could arrange for genx to use ap_palloc by * making the pool accessible via the userData call. @@ -188,6 +197,14 @@ genxStatus genxStartDocSender(genxWriter w, genxSender * sender); genxStatus genxEndDocument(genxWriter w); /* + * Write XML declaration. If encoding or standalone are NULL, then those + * attributes are omitted. + */ +genxStatus genxXmlDeclaration(genxWriter w, + constUtf8 version, + constUtf8 encoding, + constUtf8 standalone); +/* * Write a comment */ genxStatus genxComment(genxWriter w, constUtf8 text); @@ -260,10 +277,10 @@ genxStatus genxEndElement(genxWriter w); /* * Write some text * You can't write any text outside the root element, except with - * genxComment and genxPI + * genxComment and genxPI. */ genxStatus genxAddText(genxWriter w, constUtf8 start); -genxStatus genxAddCountedText(genxWriter w, constUtf8 start, int byteCount); +genxStatus genxAddCountedText(genxWriter w, constUtf8 start, size_t byteCount); genxStatus genxAddBoundedText(genxWriter w, constUtf8 start, constUtf8 end); /* diff --git a/tests/cxx/hybrid/binary/cdr/test-000.std b/tests/cxx/hybrid/binary/cdr/test-000.std index f36f755..420a5b5 100644 --- a/tests/cxx/hybrid/binary/cdr/test-000.std +++ b/tests/cxx/hybrid/binary/cdr/test-000.std @@ -1,2 +1,2 @@ -1 2 3abcleftaaaaaabbbcccccc123abcdef12.34false6566-22257005-570053735928559-21474836482147483647-2147483648-214748364821474836472147483647-2147483648true1234.1212345678.12345681234567812345678stringnormalized stringone two threenamename-tokenname tokensncnameen-usxsi:schemaLocationelements1elements2elements1elements1 elements2http://www.codesynthesis.comYmFzZTY0IGJpbmFyeQ== +1 2 3abcleftaaaaaabbbcccccc123abcdef12.34false6566-22257005-570053735928559-21474836482147483647-2147483648-214748364821474836472147483647-2147483648true1234.1212345678.12345681234567812345678stringnormalized stringone two threenamename-tokenname tokensncnameen-usxsi:schemaLocationelements1elements2elements1elements1 elements2http://www.codesynthesis.comYmFzZTY0IGJpbmFyeQ== 6865782052696E6172792001-10-26+02:002001-10-26T21:32:52+02:00P1Y2M3DT5H20M30S---01+02:00--11+02:00--02-11+02:002001+02:002001-11+02:00 \ No newline at end of file diff --git a/tests/cxx/hybrid/binary/custom/test-000.std b/tests/cxx/hybrid/binary/custom/test-000.std index f36f755..420a5b5 100644 --- a/tests/cxx/hybrid/binary/custom/test-000.std +++ b/tests/cxx/hybrid/binary/custom/test-000.std @@ -1,2 +1,2 @@ -1 2 3abcleftaaaaaabbbcccccc123abcdef12.34false6566-22257005-570053735928559-21474836482147483647-2147483648-214748364821474836472147483647-2147483648true1234.1212345678.12345681234567812345678stringnormalized stringone two threenamename-tokenname tokensncnameen-usxsi:schemaLocationelements1elements2elements1elements1 elements2http://www.codesynthesis.comYmFzZTY0IGJpbmFyeQ== +1 2 3abcleftaaaaaabbbcccccc123abcdef12.34false6566-22257005-570053735928559-21474836482147483647-2147483648-214748364821474836472147483647-2147483648true1234.1212345678.12345681234567812345678stringnormalized stringone two threenamename-tokenname tokensncnameen-usxsi:schemaLocationelements1elements2elements1elements1 elements2http://www.codesynthesis.comYmFzZTY0IGJpbmFyeQ== 6865782052696E6172792001-10-26+02:002001-10-26T21:32:52+02:00P1Y2M3DT5H20M30S---01+02:00--11+02:00--02-11+02:002001+02:002001-11+02:00 \ No newline at end of file diff --git a/tests/cxx/hybrid/binary/xdr/test-000.std b/tests/cxx/hybrid/binary/xdr/test-000.std index f36f755..420a5b5 100644 --- a/tests/cxx/hybrid/binary/xdr/test-000.std +++ b/tests/cxx/hybrid/binary/xdr/test-000.std @@ -1,2 +1,2 @@ -1 2 3abcleftaaaaaabbbcccccc123abcdef12.34false6566-22257005-570053735928559-21474836482147483647-2147483648-214748364821474836472147483647-2147483648true1234.1212345678.12345681234567812345678stringnormalized stringone two threenamename-tokenname tokensncnameen-usxsi:schemaLocationelements1elements2elements1elements1 elements2http://www.codesynthesis.comYmFzZTY0IGJpbmFyeQ== +1 2 3abcleftaaaaaabbbcccccc123abcdef12.34false6566-22257005-570053735928559-21474836482147483647-2147483648-214748364821474836472147483647-2147483648true1234.1212345678.12345681234567812345678stringnormalized stringone two threenamename-tokenname tokensncnameen-usxsi:schemaLocationelements1elements2elements1elements1 elements2http://www.codesynthesis.comYmFzZTY0IGJpbmFyeQ== 6865782052696E6172792001-10-26+02:002001-10-26T21:32:52+02:00P1Y2M3DT5H20M30S---01+02:00--11+02:00--02-11+02:002001+02:002001-11+02:00 \ No newline at end of file diff --git a/tests/cxx/hybrid/built-in/test-000.std b/tests/cxx/hybrid/built-in/test-000.std index c9a79c7..345c603 100644 --- a/tests/cxx/hybrid/built-in/test-000.std +++ b/tests/cxx/hybrid/built-in/test-000.std @@ -1,5 +1,5 @@ - + 123 abc diff --git a/tests/cxx/hybrid/choice/test-000.std b/tests/cxx/hybrid/choice/test-000.std index b299e90..50770ac 100644 --- a/tests/cxx/hybrid/choice/test-000.std +++ b/tests/cxx/hybrid/choice/test-000.std @@ -1 +1 @@ -123abcdef1.23123truefalseabc1.231231.231231.231234.564561.23true1.23true123truefalseabc1.23true1231.23truefalseabctrue1.23true1.23true123truefalseabc1.23true1231.23truefalseabctruetruetrue \ No newline at end of file +123abcdef1.23123truefalseabc1.231231.231231.231234.564561.23true1.23true123truefalseabc1.23true1231.23truefalseabctrue1.23true1.23true123truefalseabc1.23true1231.23truefalseabctruetruetrue \ No newline at end of file diff --git a/tests/cxx/hybrid/clone/test-000.std b/tests/cxx/hybrid/clone/test-000.std index f50ea2f..f0eaa71 100644 --- a/tests/cxx/hybrid/clone/test-000.std +++ b/tests/cxx/hybrid/clone/test-000.std @@ -1,5 +1,5 @@ - + 123 abc def ghq 123 diff --git a/tests/cxx/hybrid/default/test-000.std b/tests/cxx/hybrid/default/test-000.std index 8d41894..6da97af 100644 --- a/tests/cxx/hybrid/default/test-000.std +++ b/tests/cxx/hybrid/default/test-000.std @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/tests/cxx/hybrid/polymorphism/any-type/test-000.std b/tests/cxx/hybrid/polymorphism/any-type/test-000.std index 0c40a51..b57b9ea 100644 --- a/tests/cxx/hybrid/polymorphism/any-type/test-000.std +++ b/tests/cxx/hybrid/polymorphism/any-type/test-000.std @@ -1,11 +1,11 @@ - - + + 123 abc - + 123 abc 9 diff --git a/tests/cxx/hybrid/polymorphism/enumeration/test-000.std b/tests/cxx/hybrid/polymorphism/enumeration/test-000.std index ecb1b29..62ab1f8 100644 --- a/tests/cxx/hybrid/polymorphism/enumeration/test-000.std +++ b/tests/cxx/hybrid/polymorphism/enumeration/test-000.std @@ -1 +1 @@ -ababbcc \ No newline at end of file +ababbcc \ No newline at end of file diff --git a/tests/cxx/hybrid/recursive/test-000.std b/tests/cxx/hybrid/recursive/test-000.std index 6b89789..65834de 100644 --- a/tests/cxx/hybrid/recursive/test-000.std +++ b/tests/cxx/hybrid/recursive/test-000.std @@ -1 +1 @@ -123123123123123123123123123abca1123abca1456defb2123abca1456defb2789ghic3123abc123abc123abc123abc123abcdef123abcdefghi \ No newline at end of file +123123123123123123123123123abca1123abca1456defb2123abca1456defb2789ghic3123abc123abc123abc123abc123abcdef123abcdefghi \ No newline at end of file diff --git a/tests/cxx/serializer/all/test-000.std b/tests/cxx/serializer/all/test-000.std index ec04b95..d63f7ae 100644 --- a/tests/cxx/serializer/all/test-000.std +++ b/tests/cxx/serializer/all/test-000.std @@ -1 +1 @@ -123234123234 \ No newline at end of file +123234123234 \ No newline at end of file diff --git a/tests/cxx/serializer/built-in/test-001.std b/tests/cxx/serializer/built-in/test-001.std index b0f36cc..9ad2dc1 100644 --- a/tests/cxx/serializer/built-in/test-001.std +++ b/tests/cxx/serializer/built-in/test-001.std @@ -1,5 +1,5 @@ hellohellotruefalse-128-12301270123255-32768-1234503276701234565535-2147483648-123456789002147483647012345678904294967295-9223372036854775808-12345678901234567890922337203685477580701234567890123456789018446744073709551615-2147483648-123456789002147483647-2147483648-1234567890-2147483648-1234567890012345678904294967295012345678904294967295INF-INFNaN01-1123.567-1.23567e+07-4.5e-06INF-INFNaN01-1123.56789-12356789000-4.5e-0601-1123.567890000000006-123.567890000000006 test - string test normalized stringtest tokenas123:345-.abs1as123:345-.absoneone two threeas123_345-.absas123_345-.absonetwothreeas123_345-.absonetwo threeen-ushttp://www.example.com/foo#barg1:qnameqnameMTIzNDVhYmNqaw== + string test normalized stringtest tokenas123:345-.abs1as123:345-.absoneone two threeas123_345-.absas123_345-.absonetwothreeas123_345-.absonetwo threeen-ushttp://www.example.com/foo#barg1:qnameqnameMTIzNDVhYmNqaw== YQ== YWI= YWJj @@ -10,4 +10,4 @@ q6ytrq+wsbKztLW2t7i5uru8vb6/wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t/g4eLj 5OXm5+jp6uvs7e7v8PHy8/T19vf4+fr7/P3+/wABAgMEBQYHCAkKCwwNDg8QERITFBUWFxgZGhsc HR4fICEiIyQlJicoKSorLC0uLzAxMjM0NTY3ODk6Ozw9Pj9AQUJDREVGR0hJSktMTU5PUFFSU1RV VldY -31323334356162636A6B000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F808182838485868788898A8B8C8D8E8F909192939495969798999A9B9C9D9E9FA0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBCBDBEBFC0C1C2C3C4C5C6C7C8C9CACBCCCDCECFD0D1D2D3D4D5D6D7D8D9DADBDCDDDEDFE0E1E2E3E4E5E6E7E8E9EAEBECEDEEEFF0F1F2F3F4F5F6F7F8F9FAFBFCFDFEFF000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445464748494A4B4C4D4E4F505152535455565758---23---31+02:30---15Z--06--12+02:302007-2007-02:30--06-15--12-31+02:302007-10-2007-12-02:302007-06-15-2007-12-31-02:302007-06-15T12:30:30-2007-12-31T23:59:59.55-02:30P1Y-P1MP1D-PT1HPT1M-PT1.1SP1Y2M3DT4H5M6.7S \ No newline at end of file +31323334356162636A6B000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F808182838485868788898A8B8C8D8E8F909192939495969798999A9B9C9D9E9FA0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBCBDBEBFC0C1C2C3C4C5C6C7C8C9CACBCCCDCECFD0D1D2D3D4D5D6D7D8D9DADBDCDDDEDFE0E1E2E3E4E5E6E7E8E9EAEBECEDEEEFF0F1F2F3F4F5F6F7F8F9FAFBFCFDFEFF000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445464748494A4B4C4D4E4F505152535455565758---23---31+02:30---15Z--06--12+02:302007-2007-02:30--06-15--12-31+02:302007-10-2007-12-02:302007-06-15-2007-12-31-02:302007-06-15T12:30:30-2007-12-31T23:59:59.55-02:30P1Y-P1MP1D-PT1HPT1M-PT1.1SP1Y2M3DT4H5M6.7S \ No newline at end of file diff --git a/tests/cxx/serializer/choice/test-000.std b/tests/cxx/serializer/choice/test-000.std index 78a615a..87c22c0 100644 --- a/tests/cxx/serializer/choice/test-000.std +++ b/tests/cxx/serializer/choice/test-000.std @@ -1 +1 @@ -123234123234123234123234123234345456 \ No newline at end of file +123234123234123234123234123234345456 \ No newline at end of file diff --git a/tests/cxx/serializer/list/test-000.std b/tests/cxx/serializer/list/test-000.std index c1ef004..3d36007 100644 --- a/tests/cxx/serializer/list/test-000.std +++ b/tests/cxx/serializer/list/test-000.std @@ -1 +1 @@ -11 2 311 2 3 \ No newline at end of file +11 2 311 2 3 \ No newline at end of file diff --git a/tests/cxx/serializer/recursive/test-000.std b/tests/cxx/serializer/recursive/test-000.std index 717654f..99f0dcc 100644 --- a/tests/cxx/serializer/recursive/test-000.std +++ b/tests/cxx/serializer/recursive/test-000.std @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/tests/cxx/serializer/restriction/test-000.std b/tests/cxx/serializer/restriction/test-000.std index 6cb29b4..8b274d8 100644 --- a/tests/cxx/serializer/restriction/test-000.std +++ b/tests/cxx/serializer/restriction/test-000.std @@ -1 +1 @@ -12352727 \ No newline at end of file +12352727 \ No newline at end of file diff --git a/tests/cxx/serializer/sequence/test-000.std b/tests/cxx/serializer/sequence/test-000.std index a76f191..1185cc0 100644 --- a/tests/cxx/serializer/sequence/test-000.std +++ b/tests/cxx/serializer/sequence/test-000.std @@ -1 +1 @@ -123234123123234124235125236126237123234346457347458348459 \ No newline at end of file +123234123123234124235125236126237123234346457347458348459 \ No newline at end of file diff --git a/tests/cxx/serializer/wildcard/test-000.std b/tests/cxx/serializer/wildcard/test-000.std index a55bc57..c853a12 100644 --- a/tests/cxx/serializer/wildcard/test-000.std +++ b/tests/cxx/serializer/wildcard/test-000.std @@ -1 +1 @@ -321012bar#b \ No newline at end of file +321012bar#b \ No newline at end of file -- cgit v1.1