69 #define MAX_POPLIST_LENGTH 99
83 #define X(str) XString(str).unicode_str()
84 #define S(str) str.c_str()
86 using namespace xercesc;
94 <<
" hddm-c [-v | -o <filename>] {HDDM file}\n\n"
96 <<
" -v validate only\n"
97 <<
" -o <filename> write to <filename>.h, <filename>.c"
131 void checkConsistency(DOMElement* el, DOMElement* elref);
132 void writeHeader(DOMElement* el);
133 void constructGroup(DOMElement* el);
134 void constructConstructors();
135 void constructUnpackers();
136 void constructReadFunc(DOMElement* topEl);
137 void constructSkipFunc();
138 void constructPackers();
139 void constructFlushFunc(DOMElement* el);
141 void constructOpenFunc(DOMElement* el);
142 void constructInitFunc(DOMElement* el);
143 void constructCloseFunc(DOMElement* el);
144 void constructDocument(DOMElement* el);
151 int main(
int argC,
char* argV[])
155 XMLPlatformUtils::Initialize();
157 catch (
const XMLException* toCatch)
159 XtString msg(toCatch->getMessage());
161 <<
"hddm-c: Error during initialization! :\n"
171 else if ((argC == 2) && (strcmp(argV[1],
"-?") == 0))
179 bool verifyOnly =
false;
181 for (argInd = 1; argInd < argC; argInd++)
183 if (argV[argInd][0] !=
'-')
187 if (strcmp(argV[argInd],
"-v") == 0)
191 else if (strcmp(argV[argInd],
"-o") == 0)
193 hFilename =
XtString(argV[++argInd]);
198 <<
"Unknown option \'" << argV[argInd]
199 <<
"\', ignoring it\n" << std::endl;
203 if (argInd != argC - 1)
210 #if defined OLD_STYLE_XERCES_PARSER
218 <<
"hddm-c : Error parsing HDDM document, "
219 <<
"cannot continue" << std::endl;
223 DOMElement* rootEl = document->getDocumentElement();
224 XtString rootS(rootEl->getTagName());
228 <<
"hddm-c error: root element of input document is "
229 <<
"\"" << rootS <<
"\", expected \"HDDM\""
234 XtString classS(rootEl->getAttribute(
X(
"class")));
242 else if (hFilename.size())
244 hname = hFilename +
".h";
248 hname =
"hddm_" + classPrefix +
".h";
252 builder.
hFile.open(hname.c_str());
253 if (! builder.
hFile.is_open())
256 <<
"hddm-c error: unable to open output file "
257 << hname << std::endl;
266 else if (hFilename.size())
268 cname = hFilename +
".c";
272 cname =
"hddm_" + classPrefix +
".c";
275 builder.
cFile.open(cname.c_str());
276 if (! builder.
cFile.is_open())
279 <<
"hddm-c error: unable to open output file "
280 << cname << std::endl;
286 <<
" * " << hname <<
" - DO NOT EDIT THIS FILE" << std::endl
288 <<
" * This file was generated automatically by hddm-c"
289 <<
" from the file" << std::endl
290 <<
" * " << xmlFile << std::endl
292 <<
" * This header file defines the c structures that"
293 <<
" hold the data" << std::endl
294 <<
" * described in the data model"
295 <<
" (from " << xmlFile <<
"). " << std::endl
297 <<
" * The hddm data model tool set was written by" << std::endl
298 <<
" * Richard Jones, University of Connecticut." << std::endl
300 <<
" * For more information see the following web site"<< std::endl
302 <<
" * http://zeus.phys.uconn.edu/halld/datamodel/doc" << std::endl
304 <<
" */" << std::endl
309 <<
" * " << cname <<
" - DO NOT EDIT THIS FILE" << std::endl
311 <<
" * This file was generated automatically by hddm-c"
312 <<
" from the file" << std::endl
313 <<
" * " << xmlFile << std::endl
315 <<
" * This c file contains the i/o interface to"
316 <<
" the c structures" << std::endl
317 <<
" * described in the data model"
318 <<
" (from " << xmlFile <<
"). " << std::endl
320 <<
" * The hddm data model tool set was written by" << std::endl
321 <<
" * Richard Jones, University of Connecticut." << std::endl
323 <<
" * For more information see the following web site"<< std::endl
325 <<
" * http://zeus.phys.uconn.edu/halld/datamodel/doc" << std::endl
326 <<
" */" << std::endl
330 <<
"#include <stdlib.h>" << std::endl
331 <<
"#include <stdio.h>" << std::endl
332 <<
"#include <errno.h>" << std::endl
333 <<
"#include <rpc/rpc.h>" << std::endl
334 <<
"#include <string.h>" << std::endl
335 <<
"#include <strings.h>" << std::endl
336 <<
"#include <particleType.h>" << std::endl
338 <<
"typedef char* string_t; "
339 <<
"// use this alias for string-valued attributes" << std::endl
341 <<
"/* Note to users: The option MALLOC_FREE_WITH_MEMCHECK" << std::endl
342 <<
" * was created for debugging this hddm library, but it" << std::endl
343 <<
" * is also useful for finding memory leaks in user" << std::endl
344 <<
" * code. To use it, replace malloc(n) everywhere in" << std::endl
345 <<
" * your code with MALLOC(n,\"some descriptive string\")" << std::endl
346 <<
" * and free(p) with FREE(p) and include this header" << std::endl
347 <<
" * and compile with -DMALLOC_FREE_WITH_MEMCHECK set." << std::endl
348 <<
" * Any attempt to malloc memory already malloc'ed or" << std::endl
349 <<
" * to free memory that has not yet been malloc'ed is" << std::endl
350 <<
" * immediately flagged with an error message. A call" << std::endl
351 <<
" * to checkpoint() anywhere in the user code reports" << std::endl
352 <<
" * any memory that has been malloc'ed not freed." << std::endl
353 <<
" */" << std::endl
354 <<
"#if defined MALLOC_FREE_WITH_MEMCHECK" << std::endl
355 <<
"# include <memcheck.h>" << std::endl
356 <<
"# define MALLOC(N,S) (checkin(malloc(N),S))" << std::endl
357 <<
"# define CHECK(P,S) (checkin(P,S))" << std::endl
358 <<
"# define FREE(P) (checkout(P),free(P))" << std::endl
359 <<
"#else" << std::endl
360 <<
"# define MALLOC(N,S) malloc(N)" << std::endl
361 <<
"# define CHECK(P,S) assert(1 == 1)" << std::endl
362 <<
"# define FREE(P) free(P)" << std::endl
363 <<
"#endif" << std::endl;
366 <<
"int hddm_" + classPrefix +
"_nullTarget=0;" << std::endl
367 <<
"#define HDDM_NULL (void*)&hddm_" + classPrefix +
"_nullTarget"
370 <<
"#include \"" << hname <<
"\"" << std::endl
371 <<
"#include <assert.h>" << std::endl
373 <<
"int hddm_" + classPrefix +
"_buffersize = 1000000;"
375 <<
"int hddm_" + classPrefix +
"_stringsize = 1000000;"
377 <<
"int hddm_" + classPrefix +
"_headersize = 1000000;"
380 <<
"void set_" + classPrefix +
"_HDDM_buffersize(int size)"
383 <<
" hddm_" + classPrefix +
"_buffersize = size;" << std::endl
386 <<
"int get_" + classPrefix +
"_HDDM_buffersize()" << std::endl
388 <<
" return hddm_" + classPrefix +
"_buffersize;" << std::endl
391 <<
"void set_" + classPrefix +
"_HDDM_stringsize(int size)"
394 <<
" hddm_" + classPrefix +
"_stringsize = size;" << std::endl
397 <<
"int get_" + classPrefix +
"_HDDM_stringsize()" << std::endl
399 <<
" return hddm_" + classPrefix +
"_stringsize;" << std::endl
402 <<
"void set_" + classPrefix +
"_HDDM_headersize(int size)"
405 <<
" hddm_" + classPrefix +
"_headersize = size;" << std::endl
408 <<
"int get_" + classPrefix +
"_HDDM_headersize()" << std::endl
410 <<
" return hddm_" + classPrefix +
"_headersize;" << std::endl
413 <<
"static int XDRerror()" << std::endl
415 <<
" fprintf(stderr,\"hddm xdr library error - \"" << std::endl
416 <<
" \"data buffering has failed for some reason,\"" << std::endl
417 <<
" \" probably buffer overflow.\\n\"" << std::endl
418 <<
" \"Try increasing the size of the hddm i/o\"" << std::endl
419 <<
" \" buffers or maximum string size.\\n\");" << std::endl
420 <<
" exit(9);" << std::endl
421 <<
" return 0;" << std::endl
426 builder.
hFile << std::endl
427 <<
"#ifdef __cplusplus" << std::endl
428 <<
"extern \"C\" {" << std::endl
429 <<
"#endif" << std::endl;
431 builder.
hFile << std::endl
432 <<
"#ifdef __cplusplus" << std::endl
434 <<
"#endif" << std::endl;
436 builder.
hFile << std::endl
437 <<
"#ifndef " << classPrefix <<
"_DocumentString" << std::endl
438 <<
"#define " << classPrefix <<
"_DocumentString" << std::endl
441 <<
"char HDDM_" << classPrefix <<
"_DocumentString[];" << std::endl
443 <<
"#ifdef INLINE_PREPEND_UNDERSCORES" << std::endl
444 <<
"#define inline __inline" << std::endl
445 <<
"#endif" << std::endl
447 <<
"#endif /* " << classPrefix <<
"_DocumentString */" << std::endl;
449 builder.
cFile << std::endl
450 <<
"char HDDM_" << classPrefix <<
"_DocumentString[]"
451 <<
" = " << std::endl;
453 builder.
cFile <<
";" << std::endl;
455 builder.
hFile << std::endl
456 <<
"#ifndef HDDM_STREAM_INPUT" << std::endl
457 <<
"#define HDDM_STREAM_INPUT -91" << std::endl
458 <<
"#define HDDM_STREAM_OUTPUT -92" << std::endl
460 <<
"struct popNode_s {" << std::endl
461 <<
" void* (*unpacker)(XDR*, struct popNode_s*);" << std::endl
462 <<
" int inParent;" << std::endl
463 <<
" int popListLength;" << std::endl
464 <<
" struct popNode_s* popList["
467 <<
"typedef struct popNode_s popNode;" << std::endl
469 <<
"typedef struct {" << std::endl
470 <<
" FILE* fd;" << std::endl
471 <<
" int iomode;" << std::endl
472 <<
" int lerrno;" << std::endl
473 <<
" char* filename;" << std::endl
474 <<
" XDR* xdrs;" << std::endl
475 <<
" popNode* popTop;" << std::endl
476 <<
" char* iobuffer;" << std::endl
477 <<
" int iobuffer_size;" << std::endl
478 <<
"} " << classPrefix <<
"_iostream_t;" << std::endl
480 <<
"#endif /* HDDM_STREAM_INPUT */" << std::endl;
482 builder.
cFile << std::endl
483 <<
"#ifndef _FILE_OFFSET_BITS" << std::endl
484 <<
"# define _FILE_OFFSET_BITS 64" << std::endl
485 <<
"#endif" << std::endl
487 <<
"static off_t xdr_getpos64(XDR *xdrs)" << std::endl
489 <<
" if (xdrs->x_base == 0) {" << std::endl
490 <<
" return ftello((FILE *)xdrs->x_private);" << std::endl
492 <<
" off_t pos = xdr_getpos(xdrs);" << std::endl
493 <<
" return pos;" << std::endl
496 <<
"static bool_t xdr_setpos64(XDR *xdrs, off_t pos) " << std::endl
498 <<
" if (xdrs->x_base == 0) {" << std::endl
499 <<
" return ((fseeko((FILE *)xdrs->x_private, pos, 0) < 0)? FALSE : TRUE);"
502 <<
" return xdr_setpos(xdrs,pos);" << std::endl
507 builder.
hFile << std::endl
508 <<
"#ifdef __cplusplus" << std::endl
509 <<
"extern \"C\" {" << std::endl
510 <<
"#endif" << std::endl
512 <<
"void set_" + classPrefix +
"_HDDM_buffersize(int size);"
514 <<
"int get_" + classPrefix +
"_HDDM_buffersize();" << std::endl
515 <<
"void set_" + classPrefix +
"_HDDM_stringsize(int size);"
517 <<
"int get_" + classPrefix +
"_HDDM_stringsize();" << std::endl
518 <<
"void set_" + classPrefix +
"_HDDM_headersize(int size);"
520 <<
"int get_" + classPrefix +
"_HDDM_headersize();" << std::endl;
527 builder.
hFile << std::endl
528 <<
"#ifdef __cplusplus" << std::endl
530 <<
"#endif" << std::endl
532 <<
"#if !defined HDDM_NULL" << std::endl
533 <<
"extern int hddm_" + classPrefix +
"_nullTarget;" << std::endl
534 <<
"# define HDDM_NULL (void*)&hddm_" + classPrefix +
"_nullTarget"
536 <<
"#endif" << std::endl;
538 XMLPlatformUtils::Terminate();
545 XtString::size_type len = p.size();
546 if (len > 3 && p.substr(len-3,3) ==
"tum")
548 p.replace(len-3,3,
"ta");
550 else if (len > 1 && p.substr(len-3,3) ==
"ies")
552 p.replace(len-3,3,
"iesList");
554 else if (len > 2 && p.substr(len-2,2) ==
"ex")
556 p.replace(len-2,2,
"ices");
558 else if (len > 2 && p.substr(len-2,2) ==
"sh")
560 p.replace(len-2,2,
"shes");
562 else if (len > 1 && p.substr(len-1,1) ==
"s")
564 p.replace(len-1,1,
"ses");
579 p[0] = toupper(p[0]);
590 r[0] = toupper(r[0]);
601 if (el->getParentNode() == elref->getParentNode())
604 <<
"hddm-cpp error: tag " <<
"\"" << tagS
605 <<
"\" is duplicated within one context in xml document."
610 DOMNamedNodeMap* oldAttr = elref->getAttributes();
611 DOMNamedNodeMap* newAttr = el->getAttributes();
612 unsigned int listLength = oldAttr->getLength();
613 for (
unsigned int n = 0; n < listLength; n++)
615 XtString nameS(oldAttr->item(n)->getNodeName());
616 XtString oldS(elref->getAttribute(
X(nameS)));
617 XtString newS(el->getAttribute(
X(nameS)));
618 if (nameS ==
"minOccurs")
622 else if (nameS ==
"maxOccurs")
624 int maxold = (oldS ==
"unbounded")? INT_MAX : atoi(
S(oldS));
625 int maxnew = (newS ==
"unbounded")? INT_MAX : atoi(
S(newS));
626 if ((maxold < 2 && maxnew > 1) || (maxold > 1 && maxnew < 2))
629 <<
"hddm-c error: inconsistent maxOccurs usage by tag "
630 <<
"\"" << tagS <<
"\" in xml document." << std::endl;
634 else if (newS != oldS)
637 <<
"hddm-c error: inconsistent usage of attribute "
638 <<
"\"" << nameS <<
"\" in tag "
639 <<
"\"" << tagS <<
"\" in xml document." << std::endl;
643 listLength = newAttr->getLength();
644 for (
unsigned int n = 0; n < listLength; n++)
646 XtString nameS(newAttr->item(n)->getNodeName());
647 XtString oldS(elref->getAttribute(
X(nameS)));
648 XtString newS(el->getAttribute(
X(nameS)));
649 if (nameS ==
"minOccurs")
653 else if (nameS ==
"maxOccurs")
655 int maxold = (oldS ==
"unbounded")? INT_MAX : atoi(
S(oldS));
656 int maxnew = (newS ==
"unbounded")? INT_MAX : atoi(
S(newS));
657 if ((maxold < 2 && maxnew > 1) || (maxold > 1 && maxnew < 2))
660 <<
"hddm-c error: inconsistent maxOccurs usage by tag "
661 <<
"\"" << tagS <<
"\" in xml document." << std::endl;
665 else if (newS != oldS)
668 <<
"hddm-c error: inconsistent usage of attribute "
669 <<
"\"" << nameS <<
"\" in tag "
670 <<
"\"" << tagS <<
"\" in xml document." << std::endl;
674 DOMNodeList* oldList = elref->getChildNodes();
675 DOMNodeList* newList = el->getChildNodes();
676 listLength = oldList->getLength();
677 if (newList->getLength() != listLength)
680 <<
"hddm-c error: inconsistent usage of tag "
681 <<
"\"" << tagS <<
"\" in xml document." << std::endl;
684 for (
unsigned int n = 0; n < listLength; n++)
686 DOMNode* cont = oldList->item(n);
687 XtString nameS(cont->getNodeName());
688 short type = cont->getNodeType();
689 if (type == DOMNode::ELEMENT_NODE)
691 DOMNodeList* contList = el->getElementsByTagName(
X(nameS));
692 if (contList->getLength() != 1)
695 <<
"hddm-c error: inconsistent usage of tag "
696 <<
"\"" << tagS <<
"\" in xml document." << std::endl;
710 <<
"#ifndef SAW_" << ctypeDef << std::endl
711 <<
"#define SAW_" << ctypeDef << std::endl
713 <<
"typedef struct {" << std::endl;
715 DOMNamedNodeMap* varList = el->getAttributes();
716 int varCount = varList->getLength();
717 for (
int v = 0; v < varCount; v++)
719 DOMNode* var = varList->item(v);
720 XtString typeS(var->getNodeValue());
724 hFile <<
" int32_t " << nameS <<
";" << std::endl;
726 else if (typeS ==
"long")
728 hFile <<
" int64_t " << nameS <<
";" << std::endl;
730 else if (typeS ==
"float")
732 hFile <<
" float " << nameS <<
";" << std::endl;
734 else if (typeS ==
"double")
736 hFile <<
" double " << nameS <<
";" << std::endl;
738 else if (typeS ==
"boolean")
740 hFile <<
" bool_t " << nameS <<
";" << std::endl;
742 else if (typeS ==
"string")
744 hFile <<
" string_t " << nameS <<
";" << std::endl;
746 else if (typeS ==
"anyURI")
748 hFile <<
" string_t " << nameS <<
";" << std::endl;
750 else if (typeS ==
"Particle_t")
752 hFile <<
" Particle_t " << nameS <<
";" << std::endl;
760 DOMNodeList* contList = el->getChildNodes();
761 int contLength = contList->getLength();
762 for (
int c = 0;
c < contLength;
c++)
764 DOMNode* cont = contList->item(
c);
765 XtString nameS(cont->getNodeName());
766 short type = cont->getNodeType();
767 if (type == DOMNode::ELEMENT_NODE)
769 DOMElement* contEl = (DOMElement*) cont;
770 XtString repS(contEl->getAttribute(
X(
"maxOccurs")));
771 int rep = (repS ==
"unbounded")? INT_MAX : atoi(
S(repS));
774 XtString::size_type clen = ctypeRef.size();
776 hFile <<
" " << ctypeRef <<
"* ";
777 for (
int i = 0; i < 19-(int)clen; i++)
781 hFile << ((rep > 1) ? nameS.
plural() : nameS) <<
";" << std::endl;
785 hFile <<
"} " << ctypeDef <<
";" << std::endl;
787 XtString repS(el->getAttribute(
X(
"maxOccurs")));
788 int rep = (repS ==
"unbounded")? INT_MAX : atoi(
S(repS));
792 hFile << std::endl <<
"typedef struct {" << std::endl
793 <<
" unsigned int mult;" << std::endl
794 <<
" " << ctypeDef <<
" in[1];" << std::endl
795 <<
"} " << ctypeRef <<
";" << std::endl;
798 hFile <<
"#endif /* " << ctypeDef <<
" */" << std::endl;
807 std::vector<DOMElement*>::iterator iter;
808 for (iter = tagList.begin(); iter != tagList.end(); iter++)
810 XtString targS((*iter)->getTagName());
813 checkConsistency(el,*iter);
818 tagList.push_back(el);
820 DOMNodeList* contList = el->getChildNodes();
821 int contLength = contList->getLength();
822 for (
int c = 0;
c < contLength;
c++)
824 DOMNode* cont = contList->item(
c);
825 short type = cont->getNodeType();
826 if (type == DOMNode::ELEMENT_NODE)
828 DOMElement* contEl = (DOMElement*) cont;
829 constructGroup(contEl);
840 std::vector<DOMElement*>::iterator iter;
841 for (iter = tagList.begin(); iter != tagList.end(); iter++)
843 DOMElement* tagEl = *iter;
851 XtString repS = tagEl->getAttribute(
X(
"maxOccurs"));
852 int rep = (repS ==
"unbounded")? INT_MAX : atoi(
S(repS));
855 hFile << listType <<
"* ";
856 cFile << listType <<
"* ";
858 listT.erase(listT.rfind(
'_'));
859 hFile <<
"make_" << listT;
860 cFile <<
"make_" << listT;
861 hFile <<
"(int n);" << std::endl;
862 cFile <<
"(int n)" << std::endl
864 <<
" int i;" << std::endl
865 <<
" int rep = (n > 1) ? n-1 : 0;" << std::endl
866 <<
" int size = sizeof(" << listType
867 <<
") + rep * sizeof(" << simpleType <<
");" << std::endl
869 <<
"* p = (" << listType <<
"*)MALLOC(size,\""
870 << listType <<
"\");" << std::endl
871 <<
" p->mult = 0;" << std::endl
872 <<
" for (i=0; i<n; i++) {" << std::endl
873 <<
" " << simpleType <<
"* pp = &p->in[i];" << std::endl;
874 DOMNamedNodeMap* varList = tagEl->getAttributes();
875 int varCount = varList->getLength();
876 for (
int v = 0; v < varCount; v++)
878 DOMNode* var = varList->item(v);
879 XtString typeS(var->getNodeValue());
881 if (typeS ==
"string" ||
884 cFile <<
" pp->" << nameS
885 <<
" = (string_t)&hddm_" +
classPrefix +
"_nullTarget;"
888 else if (typeS ==
"int" ||
894 cFile <<
" pp->" << nameS <<
" = 0;" << std::endl;
896 else if (typeS ==
"Particle_t")
898 cFile <<
" pp->" << nameS
899 <<
" = (Particle_t)0;" << std::endl;
902 DOMNodeList* contList = tagEl->getChildNodes();
903 for (
unsigned int c = 0;
c < contList->getLength();
c++)
905 DOMNode* cont = contList->item(
c);
906 short ctype = cont->getNodeType();
907 if (ctype == DOMNode::ELEMENT_NODE)
909 DOMElement* contEl = (DOMElement*) cont;
910 XtString cnameS(contEl->getTagName());
911 XtString crepS(contEl->getAttribute(
X(
"maxOccurs")));
912 int crep = (crepS ==
"unbounded")? INT_MAX : atoi(
S(crepS));
915 cFile <<
" pp->" << cnameS.
plural()
922 cFile <<
" pp->" << cnameS
923 <<
" = (" << cnameS.simpleType()
929 cFile <<
" }" << std::endl;
933 hFile << simpleType <<
"* ";
934 cFile << simpleType <<
"* ";
936 simpleT.erase(simpleT.rfind(
'_'));
937 hFile <<
"make_" << simpleT;
938 cFile <<
"make_" << simpleT;
939 hFile <<
"();" << std::endl;
940 cFile <<
"()" << std::endl
942 <<
" int size = sizeof(" << simpleType <<
");" << std::endl
943 <<
" " << simpleType <<
"* p = "
944 <<
"(" << simpleType <<
"*)MALLOC(size,\""
945 << simpleType <<
"\");" << std::endl;
946 DOMNamedNodeMap* varList = tagEl->getAttributes();
947 int varCount = varList->getLength();
948 for (
int v = 0; v < varCount; v++)
950 DOMNode* var = varList->item(v);
951 XtString typeS(var->getNodeValue());
953 if (typeS ==
"string" ||
956 cFile <<
" p->" << nameS
957 <<
" = (string_t)&hddm_" +
classPrefix +
"_nullTarget;"
960 else if (typeS ==
"int" ||
966 cFile <<
" p->" << nameS <<
" = 0;" << std::endl;
968 else if (typeS ==
"Particle_t")
970 cFile <<
" p->" << nameS
971 <<
" = (Particle_t)0;" << std::endl;
974 DOMNodeList* contList = tagEl->getChildNodes();
975 for (
unsigned int c = 0;
c < contList->getLength();
c++)
977 DOMNode* cont = contList->item(
c);
978 short ctype = cont->getNodeType();
979 if (ctype == DOMNode::ELEMENT_NODE)
981 DOMElement* contEl = (DOMElement*) cont;
982 XtString cnameS(contEl->getTagName());
983 XtString crepS(contEl->getAttribute(
X(
"maxOccurs")));
984 int crep = (crepS ==
"unbounded")? INT_MAX : atoi(
S(crepS));
987 cFile <<
" p->" << cnameS.
plural()
994 cFile <<
" p->" << cnameS
995 <<
" = (" << cnameS.simpleType()
1002 cFile <<
" return p;" << std::endl
1003 <<
"}" << std::endl;
1012 std::vector<DOMElement*>::iterator iter;
1013 for (iter = tagList.begin(); iter != tagList.end(); iter++)
1015 DOMElement* tagEl = *iter;
1016 XtString tagS(tagEl->getTagName());
1020 cFile << std::endl <<
"static ";
1023 XtString repS = tagEl->getAttribute(
X(
"maxOccurs"));
1024 int rep = (repS ==
"unbounded")? INT_MAX : atoi(
S(repS));
1034 tagT.erase(tagT.rfind(
'_'));
1035 cFile << tagType <<
"* unpack_" << tagT
1036 <<
"(XDR* xdrs, popNode* pop)"
1039 <<
" " << tagType <<
"* this1 = (" << tagType
1040 <<
"*)HDDM_NULL;" << std::endl
1041 <<
" unsigned int size;" << std::endl
1042 <<
" if (! xdr_u_int(xdrs,&size))" << std::endl
1043 <<
" {" << std::endl
1044 <<
" return this1;" << std::endl
1045 <<
" }" << std::endl
1046 <<
" else if (size > 0)" << std::endl
1047 <<
" {" << std::endl
1048 <<
" off_t start = xdr_getpos64(xdrs);" << std::endl;
1052 cFile <<
" int m;" << std::endl
1053 <<
" unsigned int mult;" << std::endl
1054 <<
" if (! xdr_u_int(xdrs,&mult))" << std::endl
1055 <<
" XDRerror();" << std::endl;
1056 cFile <<
" this1 = make_" << tagT <<
"(mult);" << std::endl;
1058 cFile <<
" this1->mult = mult;" << std::endl
1059 <<
" for (m = 0; m < mult; m++ )" << std::endl
1060 <<
" {" << std::endl;
1064 cFile <<
" this1 = make_" << tagT <<
"();" << std::endl
1065 <<
" {" << std::endl;
1068 int hasContents = 0;
1069 DOMNodeList* contList = tagEl->getChildNodes();
1070 for (
unsigned int c = 0;
c < contList->getLength();
c++)
1072 DOMNode* cont = contList->item(
c);
1073 short type = cont->getNodeType();
1074 if (type == DOMNode::ELEMENT_NODE)
1077 DOMElement* contEl = (DOMElement*) cont;
1078 XtString nameS(contEl->getTagName());
1079 XtString reS(contEl->getAttribute(
X(
"maxOccurs")));
1080 int re = (reS ==
"unbounded")? INT_MAX : atoi(
S(reS));
1081 cFile <<
" int p;" << std::endl
1082 <<
" void* (*ptr) = (void**) &this1->"
1083 << ((rep > 1) ?
"in[m]." :
"" )
1084 << ((re > 1) ? nameS.plural() : nameS) <<
";" << std::endl;
1089 DOMNamedNodeMap* attList = tagEl->getAttributes();
1090 for (
unsigned int a = 0; a < attList->getLength(); a++)
1092 DOMNode* att = attList->item(a);
1093 XtString typeS(att->getNodeValue());
1094 XtString nameS(att->getNodeName());
1098 nameStr =
"in[m]." + nameS;
1102 cFile <<
" if (! xdr_int(xdrs,&this1->"
1103 << nameStr <<
"))" << std::endl
1104 <<
" XDRerror();" << std::endl;
1106 else if (typeS ==
"long")
1108 cFile <<
"#ifndef XDR_LONGLONG_MISSING" << std::endl
1109 <<
" if (! xdr_longlong_t(xdrs,&this1->"
1110 << nameStr <<
"))" << std::endl
1111 <<
" XDRerror();" << std::endl
1112 <<
"#else" << std::endl
1113 <<
" {" << std::endl
1114 <<
" int* " << nameStr <<
"_ = "
1115 <<
"(int*)&this1->" << nameStr <<
";" << std::endl
1116 <<
"# if __BIG_ENDIAN__" << std::endl
1117 <<
" if (! xdr_int(xdrs,&"
1118 << nameStr <<
"_[0]))" << std::endl
1119 <<
" XDRerror();" << std::endl
1120 <<
" if (! xdr_int(xdrs,&"
1121 << nameStr <<
"_[1]))" << std::endl
1122 <<
" XDRerror();" << std::endl
1123 <<
"# else" << std::endl
1124 <<
" if (! xdr_int(xdrs,&"
1125 << nameStr <<
"_[1]))" << std::endl
1126 <<
" XDRerror();" << std::endl
1127 <<
" if (! xdr_int(xdrs,&"
1128 << nameStr <<
"_[0]))" << std::endl
1129 <<
" XDRerror();" << std::endl
1130 <<
"# endif" << std::endl
1131 <<
" }" << std::endl
1132 <<
"#endif" << std::endl;
1134 else if (typeS ==
"float")
1136 cFile <<
" if (! xdr_float(xdrs,&this1->"
1137 << nameStr <<
"))" << std::endl
1138 <<
" XDRerror();" << std::endl;
1140 else if (typeS ==
"double")
1142 cFile <<
" if (! xdr_double(xdrs,&this1->"
1143 << nameStr <<
"))" << std::endl
1144 <<
" XDRerror();" << std::endl;
1146 else if (typeS ==
"boolean")
1148 cFile <<
" if (! xdr_bool(xdrs,&this1->"
1149 << nameStr <<
"))" << std::endl
1150 <<
" XDRerror();" << std::endl;
1152 else if (typeS ==
"Particle_t")
1154 cFile <<
" if (! xdr_int(xdrs,(int*)&this1->"
1155 << nameStr <<
"))" << std::endl
1156 <<
" XDRerror();" << std::endl;
1158 else if (typeS ==
"string")
1160 cFile <<
" this1->" << nameStr <<
" = 0;" << std::endl
1161 <<
" if (! xdr_string(xdrs, &this1->"
1163 <<
"_stringsize))" << std::endl
1164 <<
" XDRerror();" << std::endl;
1165 cFile <<
" CHECK(this1->" << nameStr <<
","
1166 <<
"\"string_t\");" << std::endl;
1168 else if (typeS ==
"anyURI")
1170 cFile <<
" this1->" << nameStr <<
" = 0;" << std::endl
1171 <<
" if (! xdr_string(xdrs, &this1->"
1173 <<
"_stringsize))" << std::endl
1174 <<
" XDRerror();" << std::endl;
1175 cFile <<
" CHECK(this1->" << nameStr <<
","
1176 <<
"\"string_t\");" << std::endl;
1186 cFile <<
" for (p = 0; p < pop->popListLength; p++)" << std::endl
1187 <<
" {" << std::endl
1188 <<
" popNode* pnode = pop->popList[p];" << std::endl
1189 <<
" if (pnode)" << std::endl
1190 <<
" {" << std::endl
1191 <<
" int kid = pnode->inParent;" << std::endl
1192 <<
" ptr[kid] = pnode->unpacker(xdrs,pnode);"
1194 <<
" }" << std::endl
1195 <<
" else" << std::endl
1196 <<
" {" << std::endl
1197 <<
" unsigned int skip;" << std::endl
1198 <<
" if (! xdr_u_int(xdrs,&skip))" << std::endl
1199 <<
" XDRerror();" << std::endl
1200 <<
" xdr_setpos64(xdrs,xdr_getpos64(xdrs)+skip);"
1202 <<
" }" << std::endl
1203 <<
" }" << std::endl;
1205 cFile <<
" }" << std::endl
1206 <<
" xdr_setpos64(xdrs,start+size);" << std::endl
1207 <<
" }" << std::endl
1208 <<
" return this1;" << std::endl
1209 <<
"}" << std::endl;
1217 XtString topS(topEl->getTagName());
1220 topT.erase(topT.rfind(
'_'));
1222 << topType <<
"* read_" << topT
1223 <<
"(" <<
classPrefix <<
"_iostream_t* fp" <<
");" << std::endl;
1226 << topType <<
"* read_" << topT
1227 <<
"(" <<
classPrefix <<
"_iostream_t* fp" <<
")" << std::endl
1229 <<
" off_t base;" << std::endl
1230 <<
" unsigned int size;" << std::endl
1231 <<
" xdrmem_create(fp->xdrs,fp->iobuffer,fp->iobuffer_size,XDR_DECODE);"
1233 <<
" base = xdr_getpos64(fp->xdrs);" << std::endl
1234 <<
" if (fread(fp->iobuffer,1,4,fp->fd) != 4 || ! xdr_u_int(fp->xdrs,&size))"
1236 <<
" {" << std::endl
1237 <<
" xdr_destroy(fp->xdrs);" << std::endl
1238 <<
" return 0;" << std::endl
1239 <<
" }" << std::endl
1240 <<
" else if (size == 1)" << std::endl
1241 <<
" {" << std::endl
1242 <<
" fprintf(stderr,\"hddm error - \"" << std::endl
1243 <<
" \"stream compression and/or integrity checks"
1244 " found in input stream.\\n\"" << std::endl
1245 <<
" \"These features are not supported by the"
1246 " hddm c i/o interface.\\n\");" << std::endl
1247 <<
" fprintf(stderr,\"You must use the c++ interface"
1248 " to read this file.\\n\");" << std::endl
1249 <<
" exit(9);" << std::endl
1250 <<
" }" << std::endl
1251 <<
" else if (size + 4 > fp->iobuffer_size)" << std::endl
1252 <<
" {" << std::endl
1253 <<
" xdr_destroy(fp->xdrs);" << std::endl
1254 <<
" char *newbuf = (char*)malloc(fp->iobuffer_size *= 2);"
1256 <<
" memcpy(newbuf,fp->iobuffer,4);" << std::endl
1257 <<
" free(fp->iobuffer);" << std::endl
1258 <<
" fp->iobuffer = newbuf;" << std::endl
1259 <<
" xdrmem_create(fp->xdrs,fp->iobuffer,fp->iobuffer_size,XDR_DECODE);"
1261 <<
" base = xdr_getpos64(fp->xdrs);" << std::endl
1262 <<
" }" << std::endl
1263 <<
" if (fread(fp->iobuffer+4,1,size,fp->fd) != size)" << std::endl
1264 <<
" {" << std::endl
1265 <<
" fprintf(stderr,\"hddm error - \"" << std::endl
1266 <<
" \"read failed on input hddm stream, \"" << std::endl
1267 <<
" \"cannot continue.\\n\");" << std::endl
1268 <<
" exit(9);" << std::endl
1269 <<
" }" << std::endl
1270 <<
" xdr_setpos64(fp->xdrs,base);" << std::endl
1271 <<
" " << topType <<
"* nextEvent = "
1272 <<
"unpack_" << topT <<
"(fp->xdrs,fp->popTop);" << std::endl
1273 <<
" xdr_destroy(fp->xdrs);" << std::endl
1274 <<
" return (nextEvent == HDDM_NULL)? 0 : nextEvent;" << std::endl
1275 <<
"}" << std::endl;
1284 <<
"(" <<
classPrefix <<
"_iostream_t* fp, int nskip);" << std::endl;
1288 <<
"(" <<
classPrefix <<
"_iostream_t* fp, int nskip)" << std::endl
1290 <<
" int skipped;" << std::endl
1291 <<
" for (skipped=0; skipped < nskip; ++skipped)" << std::endl
1292 <<
" {" << std::endl
1293 <<
" unsigned int size;" << std::endl
1294 <<
" xdrmem_create(fp->xdrs,fp->iobuffer,fp->iobuffer_size,XDR_DECODE);"
1296 <<
" if (fread(fp->iobuffer,1,4,fp->fd) != 4 || ! xdr_u_int(fp->xdrs,&size))"
1298 <<
" {" << std::endl
1299 <<
" break;" << std::endl
1300 <<
" }" << std::endl
1301 <<
" else if (size == 1)" << std::endl
1302 <<
" {" << std::endl
1303 <<
" fprintf(stderr,\"hddm error - \"" << std::endl
1304 <<
" \"stream compression and/or integrity "
1305 "checks found in input stream.\\n\"" << std::endl
1306 <<
" \"These features are not supported "
1307 "by the hddm c i/o interface.\\n\");" << std::endl
1308 <<
" fprintf(stderr,\"You must use the c++ "
1309 <<
"interface to read this file.\\n\");" << std::endl
1310 <<
" exit(9);" << std::endl
1311 <<
" }" << std::endl
1312 <<
" else if (size + 4 > fp->iobuffer_size)" << std::endl
1313 <<
" {" << std::endl
1314 <<
" xdr_destroy(fp->xdrs);" << std::endl
1315 <<
" char *newbuf = (char*)malloc(fp->iobuffer_size *= 2);"
1317 <<
" memcpy(newbuf,fp->iobuffer,4);" << std::endl
1318 <<
" free(fp->iobuffer);" << std::endl
1319 <<
" fp->iobuffer = newbuf;" << std::endl
1320 <<
" xdrmem_create(fp->xdrs,fp->iobuffer,fp->iobuffer_size,XDR_DECODE);"
1322 <<
" }" << std::endl
1323 <<
" if (fread(fp->iobuffer+4,1,size,fp->fd) != size)" << std::endl
1324 <<
" {" << std::endl
1325 <<
" fprintf(stderr,\"hddm error - \"" << std::endl
1326 <<
" \"read failed on input hddm stream, \"" << std::endl
1327 <<
" \"cannot continue.\\n\");" << std::endl
1328 <<
" exit(9);" << std::endl
1329 <<
" }" << std::endl
1330 <<
" }" << std::endl
1331 <<
" xdr_destroy(fp->xdrs);" << std::endl
1332 <<
" return skipped;" << std::endl
1333 <<
"}" << std::endl;
1343 std::vector<DOMElement*>::iterator iter;
1344 for (iter = tagList.begin(); iter != tagList.end(); iter++)
1346 DOMElement* tagEl = *iter;
1347 XtString tagS(tagEl->getTagName());
1354 XtString repS(tagEl->getAttribute(
X(
"maxOccurs")));
1355 int rep = (repS ==
"unbounded")? INT_MAX : atoi(
S(repS));
1362 tagType = simpleType;
1365 tagT.erase(tagT.rfind(
'_'));
1366 cFile <<
"int pack_" << tagT <<
"(XDR* xdrs, "
1367 << tagType <<
"* this1);" << std::endl;
1370 for (iter = tagList.begin(); iter != tagList.end(); iter++)
1372 DOMElement* tagEl = *iter;
1373 XtString tagS(tagEl->getTagName());
1377 cFile << std::endl <<
"static ";
1380 XtString repS(tagEl->getAttribute(
X(
"maxOccurs")));
1381 int rep = (repS ==
"unbounded")? INT_MAX : atoi(
S(repS));
1388 tagType = simpleType;
1391 tagT.erase(tagT.rfind(
'_'));
1392 cFile <<
"int pack_" << tagT <<
"(XDR* xdrs, "
1393 << tagType <<
"* this1)" << std::endl
1394 <<
"{" << std::endl;
1397 cFile <<
" int m=0;" << std::endl;
1399 cFile <<
" unsigned int size=0;" << std::endl
1400 <<
" off_t base,start,end;" << std::endl
1401 <<
" base = xdr_getpos64(xdrs);" << std::endl;
1402 if (tagT.find(
"_HDDM") != tagT.npos)
1405 <<
" if (base == -1)" << std::endl
1406 <<
" {" << std::endl
1407 <<
" fprintf(stderr,\"hddm error - \"" << std::endl
1408 <<
" \"stream offset request failed "
1409 "on output hddm stream, \"" << std::endl
1410 <<
" \"cannot continue.\\n\");" << std::endl
1411 <<
" return -1;" << std::endl
1412 <<
" }" << std::endl;
1414 cFile <<
" if (! xdr_u_int(xdrs,&size))" << std::endl
1415 <<
" XDRerror();" << std::endl
1416 <<
" start = xdr_getpos64(xdrs);" << std::endl
1420 cFile <<
" if (! xdr_u_int(xdrs,&this1->mult))" << std::endl
1421 <<
" XDRerror();" << std::endl
1422 <<
" for (m = 0; m < this1->mult; m++)" << std::endl
1423 <<
" {" << std::endl;
1427 cFile <<
" {" << std::endl;
1430 DOMNamedNodeMap* attList = tagEl->getAttributes();
1431 for (
unsigned int a = 0; a < attList->getLength(); a++)
1433 DOMNode* att = attList->item(a);
1434 XtString typeS(att->getNodeValue());
1435 XtString nameS(att->getNodeName());
1439 nameStr =
"in[m]." + nameS;
1443 cFile <<
" if (! xdr_int(xdrs,&this1->"
1444 << nameStr <<
"))" << std::endl
1445 <<
" XDRerror();" << std::endl;
1447 if (typeS ==
"long")
1449 cFile <<
"#ifndef XDR_LONGLONG_MISSING" << std::endl
1450 <<
" if (! xdr_longlong_t(xdrs,&this1->"
1451 << nameStr <<
"))" << std::endl
1452 <<
" XDRerror();" << std::endl
1453 <<
"#else" << std::endl
1454 <<
" {" << std::endl
1455 <<
" int* " << nameStr <<
"_ = "
1456 <<
"(int*)&this1->" << nameStr <<
";" << std::endl
1457 <<
"# if __BIG_ENDIAN__" << std::endl
1458 <<
" if (! xdr_int(xdrs,&"
1459 << nameStr <<
"_[0]))" << std::endl
1460 <<
" XDRerror();" << std::endl
1461 <<
" if (! xdr_int(xdrs,&"
1462 << nameStr <<
"_[1]))" << std::endl
1463 <<
" XDRerror();" << std::endl
1464 <<
"# else" << std::endl
1465 <<
" if (! xdr_int(xdrs,&"
1466 << nameStr <<
"_[1]))" << std::endl
1467 <<
" XDRerror();" << std::endl
1468 <<
" if (! xdr_int(xdrs,&"
1469 << nameStr <<
"_[0]))" << std::endl
1470 <<
" XDRerror();" << std::endl
1471 <<
"# endif" << std::endl
1472 <<
" }" << std::endl
1473 <<
"#endif" << std::endl;
1475 else if (typeS ==
"float")
1477 cFile <<
" if (! xdr_float(xdrs,&this1->"
1478 << nameStr <<
"))" << std::endl
1479 <<
" XDRerror();" << std::endl;
1481 else if (typeS ==
"double")
1483 cFile <<
" if (! xdr_double(xdrs,&this1->"
1484 << nameStr <<
"))" << std::endl
1485 <<
" XDRerror();" << std::endl;
1487 else if (typeS ==
"boolean")
1489 cFile <<
" if (! xdr_bool(xdrs,&this1->"
1490 << nameStr <<
"))" << std::endl
1491 <<
" XDRerror();" << std::endl;
1493 else if (typeS ==
"Particle_t")
1495 cFile <<
" if (! xdr_int(xdrs,(int*)&this1->"
1496 << nameStr <<
"))" << std::endl
1497 <<
" XDRerror();" << std::endl;
1499 else if (typeS ==
"string")
1501 cFile <<
" if (! xdr_string(xdrs,&this1->"
1503 <<
"_stringsize))" << std::endl
1504 <<
" XDRerror();" << std::endl;
1505 cFile <<
" FREE(this1->" << nameStr <<
");" << std::endl;
1507 else if (typeS ==
"anyURI")
1509 cFile <<
" if (! xdr_string(xdrs,&this1->"
1511 <<
"_stringsize))" << std::endl
1512 <<
" XDRerror();" << std::endl;
1513 cFile <<
" FREE(this1->" << nameStr <<
");" << std::endl;
1521 DOMNodeList* contList = tagEl->getChildNodes();
1522 for (
unsigned int c = 0;
c < contList->getLength();
c++)
1524 DOMNode* cont = contList->item(
c);
1525 short type = cont->getNodeType();
1526 if (type == DOMNode::ELEMENT_NODE)
1528 DOMElement* contEl = (DOMElement*) cont;
1529 XtString nameS(contEl->getTagName());
1530 XtString reS(contEl->getAttribute(
X(
"maxOccurs")));
1531 int re = (reS ==
"unbounded")? INT_MAX : atoi(
S(reS));
1542 contT.erase(contT.rfind(
'_'));
1543 cFile <<
" if (this1->"
1544 << ((rep > 1)?
"in[m]." :
"")
1545 << ((re > 1)? nameS.plural(): nameS) <<
" != ("
1546 << contType <<
"*)&hddm_" +
classPrefix +
"_nullTarget)"
1548 <<
" {" << std::endl
1550 <<
" if (pack_" << contT <<
"(xdrs,this1->"
1551 << ((rep > 1)?
"in[m]." :
"")
1552 << ((re > 1)? nameS.plural() : nameS) <<
") < 0) {"
1554 <<
" return -1;" << std::endl
1555 <<
" }" << std::endl
1556 <<
" }" << std::endl
1557 <<
" else" << std::endl
1558 <<
" {" << std::endl
1559 <<
" int zero=0;" << std::endl
1560 <<
" if (! xdr_int(xdrs,&zero))" << std::endl
1561 <<
" XDRerror();" << std::endl
1562 <<
" }" << std::endl;
1566 cFile <<
" }" << std::endl
1567 <<
" end = xdr_getpos64(xdrs);" << std::endl
1568 <<
" xdr_setpos64(xdrs,base);" << std::endl
1569 <<
" size = end-start;" << std::endl;
1570 if (tagT.find(
"_HDDM") != tagT.npos)
1573 <<
" if (size + 4 > hddm_" +
classPrefix +
"_buffersize) {"
1575 <<
" fprintf(stderr,\"hddm error - \"" << std::endl
1576 <<
" \"output buffer overflow on hddm stream,"
1577 " cannot continue.\\n\");" << std::endl
1578 <<
" fprintf(stderr,\"Please increase buffer"
1579 " size using \"" << std::endl
1580 <<
" \"set_" +
classPrefix +
"_HDDM_buffersize(s) with"
1581 " s > %d.\", hddm_" +
classPrefix +
"_buffersize);"
1583 <<
" exit(9);" << std::endl
1584 <<
" }" << std::endl;
1586 cFile <<
" if (! xdr_u_int(xdrs,&size))" << std::endl
1587 <<
" XDRerror();" << std::endl
1588 <<
" xdr_setpos64(xdrs,end);" << std::endl
1589 <<
" FREE(this1);" << std::endl
1590 <<
" return size;" << std::endl
1591 <<
"}" << std::endl;
1599 DOMElement* topEl = tagList[0];
1600 XtString topS(topEl->getTagName());
1603 topT.erase(topT.rfind(
'_'));
1608 <<
"int flush_" << topT <<
"(" << topType <<
"* this1,"
1609 <<
classPrefix <<
"_iostream_t* fp" <<
");" << std::endl;
1612 <<
"int flush_" << topT <<
"(" << topType <<
"* this1,"
1613 <<
classPrefix <<
"_iostream_t* fp" <<
")" << std::endl
1615 <<
" if (this1 == 0)" << std::endl
1616 <<
" {" << std::endl
1617 <<
" return 0;" << std::endl
1618 <<
" }" << std::endl
1619 <<
" else if (fp == 0)" << std::endl
1620 <<
" {" << std::endl
1621 <<
" XDR* xdrs = (XDR*)malloc(sizeof(XDR));" << std::endl
1622 <<
" char* dump = (char*)malloc(hddm_"
1624 <<
" xdrmem_create(xdrs,dump,hddm_"
1625 +
classPrefix +
"_buffersize,XDR_ENCODE);" << std::endl
1626 <<
" pack_" << topT <<
"(xdrs,this1);" << std::endl
1627 <<
" xdr_destroy(xdrs);" << std::endl
1628 <<
" free(xdrs);" << std::endl
1629 <<
" free(dump);" << std::endl
1630 <<
" }" << std::endl
1631 <<
" else if (fp->iomode == HDDM_STREAM_OUTPUT)" << std::endl
1632 <<
" {" << std::endl
1633 <<
" int size;" << std::endl
1634 <<
" xdrmem_create(fp->xdrs,fp->iobuffer,"
1635 "fp->iobuffer_size,XDR_ENCODE);" << std::endl
1636 <<
" size = pack_" +
classPrefix +
"_HDDM(fp->xdrs,this1);"
1638 <<
" if (size < 0)" << std::endl
1639 <<
" {" << std::endl
1640 <<
" fp->lerrno = errno;" << std::endl
1641 <<
" xdr_destroy(fp->xdrs);" << std::endl
1642 <<
" return -1;" << std::endl
1643 <<
" }" << std::endl
1644 <<
" else if (size > 0)" << std::endl
1645 <<
" {" << std::endl
1646 <<
" int wsize = fwrite(fp->iobuffer,1,size+4,fp->fd);"
1648 <<
" if (wsize != size + 4)" << std::endl
1649 <<
" {" << std::endl
1650 <<
" fprintf(stderr,\"HDDM Error: error writing to \""
1652 <<
" \"output hddm file.\\n\");" << std::endl
1653 <<
" fprintf(stderr,\"%d bytes of %d "
1654 "actually written.\\n\"," << std::endl
1655 <<
" wsize, size+4);" << std::endl
1656 <<
" exit(9);" << std::endl
1657 <<
" }" << std::endl
1658 <<
" }" << std::endl
1659 <<
" xdr_destroy(fp->xdrs);" << std::endl
1660 <<
" }" << std::endl
1661 <<
" return 0;" << std::endl
1662 <<
"}" << std::endl;
1684 <<
"static int getTag(char* d, char* tag)" << std::endl
1686 <<
" int level;" << std::endl
1687 <<
" char* token;" << std::endl
1688 <<
" char line[500];" << std::endl
1689 <<
" strncpy(line,d,500);" << std::endl
1690 <<
" line[499] = 0;" << std::endl
1691 <<
" level = index(line,'<')-line;" << std::endl
1692 <<
" if (level < 500 &&" << std::endl
1693 <<
" (token = strtok(line+level+1,\" >\")))" << std::endl
1694 <<
" {" << std::endl
1695 <<
" strncpy(tag,token,500);" << std::endl
1696 <<
" return level/2;" << std::endl
1697 <<
" }" << std::endl
1698 <<
" return -1;" << std::endl
1701 <<
"static char* getEndTag(char* d, char* tag)" << std::endl
1703 <<
" char line[500];" << std::endl
1704 <<
" char endTag[510];" << std::endl
1705 <<
" strncpy(line,d,500);" << std::endl
1706 <<
" line[499] = 0;" << std::endl
1707 <<
" if (strstr(strtok(line,\"\\n\"),\"/>\") == 0)" << std::endl
1708 <<
" {" << std::endl
1709 <<
" sprintf(endTag,\"</%s>\",tag);" << std::endl
1710 <<
" }" << std::endl
1711 <<
" else" << std::endl
1712 <<
" {" << std::endl
1713 <<
" strcpy(endTag,\"/>\");" << std::endl
1714 <<
" }" << std::endl
1715 <<
" return strstr(d,endTag);" << std::endl
1718 <<
"static void collide(char* b, char* c)" << std::endl
1720 <<
" char btag[500];" << std::endl
1721 <<
" getTag(b,btag);" << std::endl
1722 <<
" b = index(b,'<');" << std::endl
1723 <<
" c = index(c,'<');" << std::endl
1724 <<
" *(index(b,'\\n')) = 0;" << std::endl
1725 <<
" *(index(c,'\\n')) = 0;" << std::endl
1726 <<
" fprintf(stderr,\"HDDM warning: \");" << std::endl
1727 <<
" fprintf(stderr,\"tag %s in input file \", btag);" << std::endl
1728 <<
" fprintf(stderr,\"does not match c header hddm_"
1730 <<
" fprintf(stderr,\" input file: %s\\n\", b);" << std::endl
1731 <<
" fprintf(stderr,\" c header: %s\\n\", c);" << std::endl
1732 <<
" fprintf(stderr,\" === Tag %s will be ignored,\", btag);"
1734 <<
" fprintf(stderr,\" rebuild to cure the problem ===\\n\");"
1736 <<
" *(index(b,0)) = '\\n';" << std::endl
1737 <<
" *(index(c,0)) = '\\n';" << std::endl
1740 <<
"static int tag_strncmp(char* a, char* b, int len)" << std::endl
1742 <<
" if (strncmp(a,b,len) == 0) {" << std::endl
1743 <<
" return 0;" << std::endl
1744 <<
" }" << std::endl
1745 <<
" else {" << std::endl
1746 <<
" for (; *a == *b; ++a, ++b, --len) {}" << std::endl
1747 <<
" for (; *a == ' '; ++a, --len) {}" << std::endl
1748 <<
" for (; *a == '/'; ++a, --len) {}" << std::endl
1749 <<
" for (; *b == ' '; ++b) {}" << std::endl
1750 <<
" for (; *b == '/'; ++b) {}" << std::endl
1751 <<
" return strncmp(a,b,len);" << std::endl
1752 <<
" }" << std::endl
1755 <<
"static popNode* matches(char* b, char* c)" << std::endl
1757 <<
" char btag[500];" << std::endl
1758 <<
" char ctag[500];" << std::endl
1759 <<
" int blevel, clevel;" << std::endl
1760 <<
" int ptrSeqNo = 0;" << std::endl
1761 <<
" blevel = getTag(b,btag);" << std::endl
1762 <<
" while ((clevel = getTag(c,ctag)) == blevel)" << std::endl
1763 <<
" {" << std::endl
1765 <<
"((clevel == blevel) && (strcmp(ctag,btag) == 0))" << std::endl
1766 <<
" {" << std::endl
1767 <<
" popNode* this1 = "
1768 <<
"(popNode*)malloc(sizeof(popNode));" << std::endl
1769 <<
" int len = index(c+1,'\\n') - c;" << std::endl
1770 <<
" if (tag_strncmp(c,b,len) != 0)" << std::endl
1771 <<
" {" << std::endl
1772 <<
" collide(b,c);" << std::endl
1773 <<
" free(this1);" << std::endl
1774 <<
" return 0;" << std::endl
1775 <<
" }" << std::endl;
1777 std::vector<DOMElement*>::iterator iter;
1778 for (iter = tagList.begin(); iter != tagList.end(); iter++)
1780 XtString tagS((*iter)->getTagName());
1781 XtString repS((*iter)->getAttribute(
X(
"maxOccurs")));
1782 int rep = (repS ==
"unbounded")? INT_MAX : atoi(
S(repS));
1793 tagT.erase(tagT.rfind(
'_'));
1795 cFile <<
" else if "
1796 <<
"(strcmp(btag,\"" << tagS <<
"\") == 0)" << std::endl
1797 <<
" {" << std::endl
1798 <<
" this1->unpacker = "
1799 <<
"(void*(*)(XDR*,popNode*))"
1800 <<
"unpack_" << tagT <<
";" << std::endl
1801 <<
" }" << std::endl;
1804 cFile <<
" this1->inParent = ptrSeqNo;" << std::endl
1805 <<
" this1->popListLength = 0;" << std::endl
1806 <<
" c = index(c+1,'\\n');" << std::endl
1807 <<
" b = index(b+1,'\\n');" << std::endl
1808 <<
" while (getTag(b,btag) > blevel)" << std::endl
1809 <<
" {" << std::endl
1810 <<
" this1->popList[this1->popListLength++] = matches(b,c);"
1812 <<
" if (this1->popListLength > "
1814 <<
" {" << std::endl
1815 <<
" fprintf(stderr,"
1816 <<
"\"hddm error - popList overflow.\\n\");" << std::endl
1817 <<
" fprintf(stderr,"
1818 <<
"\"Increase MAX_POPLIST_LENGTH and recompile.\\n\");" << std::endl
1819 <<
" exit(9);" << std::endl
1820 <<
" }" << std::endl
1821 <<
" b = getEndTag(b,btag);" << std::endl
1822 <<
" b = index(b+1,'\\n');" << std::endl
1823 <<
" }" << std::endl
1824 <<
" return this1;" << std::endl
1825 <<
" }" << std::endl
1826 <<
" else" << std::endl
1827 <<
" {" << std::endl
1828 <<
" c = getEndTag(c,ctag);" << std::endl
1829 <<
" c = index(c+1,'\\n');" << std::endl
1830 <<
" ++ptrSeqNo;" << std::endl
1831 <<
" }" << std::endl
1832 <<
" }" << std::endl
1833 <<
" return 0;" << std::endl
1834 <<
"}" << std::endl;
1844 tagT.erase(tagT.rfind(
'_'));
1847 <<
"open_" << tagT <<
"(char* filename);" << std::endl;
1853 <<
"open_" << tagT <<
"(char* filename)" << std::endl
1857 <<
"malloc(sizeof(" <<
classPrefix <<
"_iostream_t));" << std::endl
1858 <<
" char* p;" << std::endl
1859 <<
" char* head;" << std::endl
1860 <<
" char* nullfilename=(char*)\"\";" << std::endl
1861 <<
" if (filename)" << std::endl
1862 <<
" {" << std::endl
1863 <<
" fp->fd = fopen(filename,\"r\");" << std::endl
1864 <<
" }" << std::endl
1865 <<
" else" << std::endl
1866 <<
" {" << std::endl
1867 <<
" fp->fd = fdopen(0,\"r\");" << std::endl
1868 <<
" filename = nullfilename;" << std::endl
1869 <<
" }" << std::endl
1870 <<
" if (fp->fd == 0)" << std::endl
1871 <<
" {" << std::endl
1872 <<
" free(fp);" << std::endl
1873 <<
" return 0;" << std::endl
1874 <<
" }" << std::endl
1875 <<
" fp->iomode = HDDM_STREAM_INPUT;" << std::endl
1876 <<
" head = (char*)malloc(hddm_" +
classPrefix +
"_headersize);"
1878 <<
" if ((fgets(head,7,fp->fd) != 0) &&" << std::endl
1879 <<
" (strstr(head,\"<HDDM \") != head))" << std::endl
1880 <<
" {" << std::endl
1881 <<
" fprintf(stderr,\"HDDM Error: input file \");" << std::endl
1882 <<
" fprintf(stderr,\"file does not have a \");" << std::endl
1883 <<
" fprintf(stderr,\"valid HDDM header.\");" << std::endl
1884 <<
" fprintf(stderr,\" Please check.\\n\");" << std::endl
1885 <<
" exit(9);" << std::endl
1886 <<
" }" << std::endl
1887 <<
" for (p = head+6;" << std::endl
1888 <<
" strstr(head,\"</HDDM>\") == 0;" << std::endl
1889 <<
" p += strlen(p))" << std::endl
1890 <<
" {" << std::endl
1891 <<
" if (p-head + 10 > hddm_" +
classPrefix +
"_headersize)"
1893 <<
" {" << std::endl
1894 <<
" fprintf(stderr,\"HDDM Error: \");" << std::endl
1895 <<
" fprintf(stderr,\"input template model overflows \""
1897 <<
" \"the hddm header input buffer, cannot continue.\\n\");"
1899 <<
" fprintf(stderr,\"Please increase header"
1900 " buffer size using \"" << std::endl
1901 <<
" \"set_" +
classPrefix +
"_HDDM_headersize(s) with "
1902 "s > %d.\\n\", hddm_" +
classPrefix +
"_headersize);"
1904 <<
" exit(9);" << std::endl
1905 <<
" }" << std::endl
1906 <<
" if (fgets(p,1000,fp->fd) == 0)" << std::endl
1907 <<
" {" << std::endl
1908 <<
" break;" << std::endl
1909 <<
" }" << std::endl
1910 <<
" }" << std::endl
1911 <<
" fp->popTop = matches(head,HDDM_" <<
classPrefix
1912 <<
"_DocumentString);" << std::endl
1913 <<
" free(head);" << std::endl
1914 <<
" if (fp->popTop == 0"
1915 <<
" || fp->popTop->popListLength == 0)" << std::endl
1916 <<
" {" << std::endl
1917 <<
" fprintf(stderr,\"HDDM Error: \");" << std::endl
1918 <<
" fprintf(stderr,\"input template model \");" << std::endl
1919 <<
" fprintf(stderr,\"does not match c header.\");" << std::endl
1920 <<
" fprintf(stderr,\" Please recompile.\\n\");" << std::endl
1921 <<
" exit(9);" << std::endl
1922 <<
" }" << std::endl
1923 <<
" fp->filename = "
1924 <<
"(char*)malloc(strlen(filename) + 1);" << std::endl
1925 <<
" strcpy(fp->filename,filename);" << std::endl
1926 <<
" fp->xdrs = (XDR*)malloc(sizeof(XDR));" << std::endl
1927 <<
" fp->iobuffer = (char*)malloc(fp->iobuffer_size"
1928 " = hddm_" +
classPrefix +
"_buffersize);" << std::endl
1929 <<
" return fp;" << std::endl
1930 <<
"}" << std::endl;
1940 tagT.erase(tagT.rfind(
'_'));
1943 <<
"init_" << tagT <<
"(char* filename);" << std::endl;
1946 <<
"init_" << tagT <<
"(char* filename)" << std::endl
1948 <<
" int len;" << std::endl
1949 <<
" char* head;" << std::endl
1950 <<
" char* nullfilename=(char*)\"\";" << std::endl
1953 <<
"malloc(sizeof(" <<
classPrefix <<
"_iostream_t));" << std::endl
1954 <<
" if (filename)" << std::endl
1955 <<
" {" << std::endl
1956 <<
" fp->fd = fopen(filename,\"w\");" << std::endl
1957 <<
" }" << std::endl
1958 <<
" else" << std::endl
1959 <<
" {" << std::endl
1960 <<
" fp->fd = fdopen(1,\"w\");" << std::endl
1961 <<
" filename = nullfilename;" << std::endl
1962 <<
" }" << std::endl
1963 <<
" if (fp->fd == 0)" << std::endl
1964 <<
" {" << std::endl
1965 <<
" free(fp);" << std::endl
1966 <<
" return 0;" << std::endl
1967 <<
" }" << std::endl
1968 <<
" fp->iomode = HDDM_STREAM_OUTPUT;" << std::endl
1969 <<
" len = strlen(HDDM_"
1970 <<
classPrefix <<
"_DocumentString);" << std::endl
1971 <<
" head = (char*)malloc(len+1);" << std::endl
1972 <<
" strcpy(head,HDDM_"
1973 <<
classPrefix <<
"_DocumentString);" << std::endl
1974 <<
" if (fwrite(head,1,len,fp->fd) != len)" << std::endl
1975 <<
" {" << std::endl
1976 <<
" fprintf(stderr,\"HDDM Error: \");" << std::endl
1977 <<
" fprintf(stderr,\"error writing to \");" << std::endl
1978 <<
" fprintf(stderr,\"output file %s\\n\",filename);" << std::endl
1979 <<
" exit(9);" << std::endl
1980 <<
" }" << std::endl
1981 <<
" fp->filename = "
1982 <<
"(char*)malloc(strlen(filename) + 1);" << std::endl
1983 <<
" strcpy(fp->filename,filename);" << std::endl
1984 <<
" fp->popTop = 0;" << std::endl
1985 <<
" fp->xdrs = (XDR*)malloc(sizeof(XDR));" << std::endl
1986 <<
" fp->iobuffer = (char*)malloc(fp->iobuffer_size"
1987 " = hddm_" +
classPrefix +
"_buffersize);" << std::endl
1988 <<
" free(head);" << std::endl
1989 <<
" return fp;" << std::endl
1990 <<
"}" << std::endl;
2000 tagT.erase(tagT.rfind(
'_'));
2002 <<
"void close_" << tagT <<
"("
2003 <<
classPrefix <<
"_iostream_t* fp);" << std::endl;
2006 <<
"static void popaway(popNode* p)" << std::endl
2008 <<
" if (p)" << std::endl
2009 <<
" {" << std::endl
2010 <<
" int n;" << std::endl
2011 <<
" for (n = 0; n < p->popListLength; n++)" << std::endl
2012 <<
" {" << std::endl
2013 <<
" popaway(p->popList[n]);" << std::endl
2014 <<
" }" << std::endl
2015 <<
" free(p);" << std::endl
2016 <<
" }" << std::endl
2019 <<
"void close_" << tagT
2020 <<
"(" <<
classPrefix <<
"_iostream_t* fp)" << std::endl
2022 <<
" free(fp->xdrs);" << std::endl
2023 <<
" free(fp->iobuffer);" << std::endl
2024 <<
" fclose(fp->fd);" << std::endl
2025 <<
" free(fp->filename);" << std::endl
2026 <<
" popaway(fp->popTop);" << std::endl
2027 <<
" free(fp);" << std::endl
2028 <<
"}" << std::endl;
2035 static int indent = 0;
2037 for (
int n = 0; n < indent; n++)
2043 cFile <<
"<" << tagS;
2044 DOMNamedNodeMap* attrList = el->getAttributes();
2045 int attrListLength = attrList->getLength();
2046 for (
int a = 0; a < attrListLength; a++)
2048 DOMNode* node = attrList->item(a);
2049 XtString nameS(node->getNodeName());
2050 XtString valueS(node->getNodeValue());
2051 cFile <<
" " << nameS <<
"=\\\"" << valueS <<
"\\\"";
2054 DOMNodeList* contList = el->getChildNodes();
2055 int contListLength = contList->getLength();
2056 if (contListLength > 0)
2058 cFile <<
">\\n\"" << std::endl;
2060 for (
int c = 0;
c < contListLength;
c++)
2062 DOMNode* node = contList->item(
c);
2063 if (node->getNodeType() == DOMNode::ELEMENT_NODE)
2065 DOMElement* contEl = (DOMElement*) node;
2066 constructDocument(contEl);
2071 for (
int n = 0; n < indent; n++)
2075 cFile <<
"</" << tagS <<
">\\n\"" << std::endl;
2079 cFile <<
" />\\n\"" << std::endl;
void constructGroup(DOMElement *el)
#define MAX_POPLIST_LENGTH
void constructConstructors()
xercesc::DOMDocument * buildDOMDocument(const XString &xmlFile, bool keep)
void checkConsistency(DOMElement *el, DOMElement *elref)
XtString(const XString &x)
void constructCloseFunc(DOMElement *el)
std::vector< DOMElement * > tagList
xercesc::DOMDocument * parseInputDocument(const XString &xmlFile, bool keep)
void constructOpenFunc(DOMElement *el)
XtString(const XtString &t)
void constructReadFunc(DOMElement *topEl)
void constructInitFunc(DOMElement *el)
void constructUnpackers()
void constructDocument(DOMElement *el)
void constructFlushFunc(DOMElement *el)
XtString(const std::string &s)
void writeHeader(DOMElement *el)
int main(int argc, char *argv[])