From 2ed145e7e58503119bf37ec2c634f6cde84ee50c Mon Sep 17 00:00:00 2001 From: snowdrop Date: Thu, 3 Jun 2004 13:14:35 +0000 Subject: fixed some little bugs --- xsd2c/Makefile.am | 16 ++++++++-------- xsd2c/TODO | 14 +++++++++++--- xsd2c/formatter.c | 18 +++++++++++++----- xsd2c/main.c | 12 +++++++++++- xsd2c/xsd2c.c | 45 ++++++++++++++++++++++++++++----------------- 5 files changed, 71 insertions(+), 34 deletions(-) diff --git a/xsd2c/Makefile.am b/xsd2c/Makefile.am index 1475ad0..800892e 100755 --- a/xsd2c/Makefile.am +++ b/xsd2c/Makefile.am @@ -1,8 +1,8 @@ -bin_PROGRAMS=xsd2c - -INCLUDES=$(LIBXML_CFLAGS) -LDFLAGS=$(LIBXML_LIBS) - -xsd2c_SOURCES=tr.c util.c obj.c formatter.c xsd2c.c main.c -xsd2c_LDFLAGS=$(LDFLAGS) - +bin_PROGRAMS=xsd2c + +INCLUDES=$(LIBXML_CFLAGS) +LDFLAGS=$(LIBXML_LIBS) + +xsd2c_SOURCES=tr.c util.c obj.c formatter.c xsd2c.c main.c +xsd2c_LDFLAGS=$(LDFLAGS) + diff --git a/xsd2c/TODO b/xsd2c/TODO index 5cf2916..d89ae79 100644 --- a/xsd2c/TODO +++ b/xsd2c/TODO @@ -5,8 +5,11 @@ PROJECT: xsd2c CREATED: 30.03.2003 WRITTEN BY: Ferhat Ayaz -------------------------------------------------------- -$Id: TODO,v 1.1 2004/06/02 11:17:03 snowdrop Exp $ +$Id: TODO,v 1.2 2004/06/03 13:14:35 snowdrop Exp $ $Log: TODO,v $ +Revision 1.2 2004/06/03 13:14:35 snowdrop +fixed some little bugs + Revision 1.1 2004/06/02 11:17:03 snowdrop initial import @@ -15,7 +18,12 @@ initial import -------------------------------------------------------- -+ Add extension base functionality -+ Add deserialize functionality +# Urls to test +# http://webservices.wolfram.com/services/Integrator/Integrate.m?wsdl +# + ++ Add extension base functionality OK ++ Add deserialize functionality OK + Add simpleTypes (list, restriction?, ...) ++ List free must use ( _Free(..->value) ) instead of ( free() ) diff --git a/xsd2c/formatter.c b/xsd2c/formatter.c index 80b96cf..50b81f9 100644 --- a/xsd2c/formatter.c +++ b/xsd2c/formatter.c @@ -1,5 +1,5 @@ /****************************************************************** - * $Id: formatter.c,v 1.1 2004/06/02 11:17:03 snowdrop Exp $ + * $Id: formatter.c,v 1.2 2004/06/03 13:14:35 snowdrop Exp $ * * CSOAP Project: A SOAP client/server library in C * Copyright (C) 2003 Ferhat Ayaz @@ -91,14 +91,14 @@ void writeComplexTypeHeaderFile(FILE* f, HCOMPLEXTYPE obj) { if (trGetBuildInFlag(field->type) == 0) { - fprintf(f, "#include \"%s_xsd.h\"\n", field->type); + fprintf(f, "#include \"%s.h\"\n", field->type); /* _xsd*/ } field = field->next; } if (obj->base_type != NULL) { - fprintf(f, "#include \"%s_xsd.h\"\n", obj->base_type); + fprintf(f, "#include \"%s.h\"\n", obj->base_type);/* _xsd*/ } /* include libxml library */ @@ -446,7 +446,7 @@ void writeComplexTypeSourceFile(FILE* f, HCOMPLEXTYPE obj) fprintf(f, "#include \n", obj->type); fprintf(f, "#include \n", obj->type); fprintf(f, "#include \n", obj->type); - fprintf(f, "#include \"%s_xsd.h\"\n\n\n", obj->type); + fprintf(f, "#include \"%s.h\"\n\n\n", obj->type); /* _xsd*/ if (obj->base_type != NULL) @@ -890,6 +890,7 @@ static void writeCodeSaxSerialize(FILE* f, HCOMPLEXTYPE obj) } else { + fprintf(f, "\tif (%s_cur->value)\n", field->name); sprintf(buffer, "%s_Sax_Serialize(%s_cur->value, \"%s\", OnStartElement, OnCharacters, OnEndElement, userData);\n", field->type, field->name, field->name); fprintf(f, "\t\t%s\n", buffer); @@ -926,6 +927,7 @@ static void writeCodeSaxSerialize(FILE* f, HCOMPLEXTYPE obj) } else { + fprintf(f, "\tif (obj->%s)\n", field->name); sprintf(buffer, "%s_Sax_Serialize(obj->%s, \"%s\", OnStartElement, OnCharacters, OnEndElement, userData);", field->type, field->name, field->name); fprintf(f, "\t%s\n", buffer ); @@ -1038,6 +1040,7 @@ static void writeCodeBaseOnEndElement(FILE* f, HCOMPLEXTYPE obj) } else { + fprintf(f, "\tif (%s_cur->value)\n", field->name); sprintf(buffer, "%s_Sax_Serialize(%s_cur->value, \"%s\", bsce->OnStartElement, bsce->OnCharacters, bsce->OnEndElement, bsce->userData);\n", field->type, field->name, field->name); fprintf(f, "\t\t%s\n", buffer); @@ -1074,6 +1077,7 @@ static void writeCodeBaseOnEndElement(FILE* f, HCOMPLEXTYPE obj) } else { + fprintf(f, "\tif (obj->%s)\n", field->name); sprintf(buffer, "%s_Sax_Serialize(obj->%s, \"%s\", bsce->OnStartElement, bsce->OnCharacters, bsce->OnEndElement, bsce->userData);", field->type, field->name, field->name); fprintf(f, "\t%s\n", buffer ); @@ -1212,7 +1216,11 @@ static void writeCodeDeserialize(FILE* f, HCOMPLEXTYPE obj) } else { - fprintf(f, "\t\t\tobj->%s = %s_Deserialize(cur);\n", field->name, field->name); + if (field->maxOccurs > 1 || field->maxOccurs == -1) { + fprintf(f, "\t\t\t%s_Add_%s( obj, %s_Deserialize(cur) );\n", field->parentObj->type, field->name, field->type); + } else { + fprintf(f, "\t\t\t%s_Set_%s( obj, %s_Deserialize(cur) );\n", field->parentObj->type, field->name, field->type); + } } fprintf(f, "\t\t}\n"); diff --git a/xsd2c/main.c b/xsd2c/main.c index 6e866c6..ada134a 100755 --- a/xsd2c/main.c +++ b/xsd2c/main.c @@ -1,5 +1,7 @@ #include "xsd2c.h" #include "formatter.h" +#include "tr.h" +#include "obj.h" #include @@ -45,7 +47,15 @@ int main(int argc, char *argv[]) return 1; } - xsdEngineRun(xsdNode, outDir); + + if (!xsdInitTrModule(xsdNode)) + return 1; + + if (!xsdInitObjModule(xsdNode)) + return 1; + + + xsdEngineRun(xsdNode, outDir); xmlFreeDoc(xsdNode->doc); diff --git a/xsd2c/xsd2c.c b/xsd2c/xsd2c.c index d870f7c..8c61bba 100644 --- a/xsd2c/xsd2c.c +++ b/xsd2c/xsd2c.c @@ -1,5 +1,5 @@ /****************************************************************** - * $Id: xsd2c.c,v 1.4 2004/06/03 08:53:34 snowdrop Exp $ + * $Id: xsd2c.c,v 1.5 2004/06/03 13:14:35 snowdrop Exp $ * * CSOAP Project: A SOAP client/server library in C * Copyright (C) 2003 Ferhat Ayaz @@ -590,7 +590,7 @@ int declareStructs(HCOMPLEXTYPE ct) char fname[255]; FILE* f; - sprintf(fname, "%s/%s_xsd.h", outDir, ct->type); + sprintf(fname, "%s/%s.h", outDir, ct->type); /* _xsd*/ printf("Generating file '%s' ...\n", fname); f = fopen(fname, "w"); if (f == NULL) @@ -603,14 +603,14 @@ int declareStructs(HCOMPLEXTYPE ct) fclose(f); return 1; -} +} int writeSource(HCOMPLEXTYPE ct) { char fname[255]; FILE* f; - sprintf(fname, "%s/%s_xsd.c", outDir, ct->type); + sprintf(fname, "%s/%s.c", outDir, ct->type); /* _xsd*/ printf("Generating file '%s' ...\n", fname); f = fopen(fname, "w"); if (f == NULL) @@ -631,20 +631,31 @@ int xsdInitTrModule(xmlNodePtr xsdNode) xmlNsPtr ns = NULL; if (xsdNode != NULL) { - ns = xmlSearchNsByHref(xsdNode->doc, xsdNode, "http://www.w3.org/2001/XMLSchema"); - if (ns == NULL) { - fprintf(stderr, "XML Schema namespace not found!\n"); - return 0; - } - - if (ns->prefix == NULL) { - fprintf(stderr, "XML Schema namespace not found!\n"); - return 0; - } - fprintf(stdout, "XMLSchema namespace prefix: '%s'\n", ns->prefix); - trInitModule(ns->prefix); + + ns = xmlSearchNsByHref(xsdNode->doc, xsdNode, "http://www.w3.org/2001/XMLSchema"); + + if (ns != NULL && ns->prefix != NULL) { + fprintf(stdout, "XMLSchema namespace prefix: '%s'\n", ns->prefix); + trInitModule(ns->prefix); + } else { + /* + Search for: + + + + ... + */ + ns = xmlSearchNsByHref(xsdNode->doc, xmlDocGetRootElement(xsdNode->doc), "http://www.w3.org/2001/XMLSchema"); + if (ns != NULL && ns->prefix != NULL) { + fprintf(stdout, "XMLSchema namespace prefix: '%s'\n", ns->prefix); + trInitModule(ns->prefix); + } else { + trInitModule("xs"); + } + } + } else { - trInitModule("ts"); + trInitModule("xs"); } return 1; -- cgit v1.1-32-gdbae