[opendemo-cvs] CVS: opendemo/tools/odcut/odfile_expat odfile_expat_intern.c,1.3,1.4
Status: Beta
Brought to you by:
girlich
From: Uwe G. <gi...@us...> - 2004-03-30 08:18:39
|
Update of /cvsroot/opendemo/opendemo/tools/odcut/odfile_expat In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3379 Modified Files: odfile_expat_intern.c Log Message: first time, forst sequence implemented _getAttribute for easier XML attribute handling snapshotc implemented last offset stored (nneded for footer) Index: odfile_expat_intern.c =================================================================== RCS file: /cvsroot/opendemo/opendemo/tools/odcut/odfile_expat/odfile_expat_intern.c,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** odfile_expat_intern.c 29 Mar 2004 19:40:13 -0000 1.3 --- odfile_expat_intern.c 30 Mar 2004 08:07:03 -0000 1.4 *************** *** 11,16 **** ! /* library include */ ! #include <expat.h> /* for all XML_*() routines */ --- 11,16 ---- ! /* private includes */ ! #include "odfile_expat_intern.h" *************** *** 27,38 **** - /* private includes */ - #include "odfile_expat_intern.h" - - #define CFREE(x) { if ((x)!=NULL) free(x) ; (x) = NULL; } #define OFE_DONE(x) { if ((x)!=NULL) ofe_done(x); (x) = NULL; } /* XML file parse handlers */ void XMLCALL _HandleXMLDecl(void *userData, const XML_Char *version, --- 27,48 ---- #define CFREE(x) { if ((x)!=NULL) free(x) ; (x) = NULL; } #define OFE_DONE(x) { if ((x)!=NULL) ofe_done(x); (x) = NULL; } + /* XML attribute handle functions */ + const char* + _getAttribute(const XML_Char **atts, char *key) + { + int i; + for (i=0;atts[i]!=NULL;i+=2) { + if (strcmp(atts[i],key) == 0) { + return atts[i+1]; + } + } + return NULL; + } + + /* XML file parse handlers */ void XMLCALL _HandleXMLDecl(void *userData, const XML_Char *version, *************** *** 69,79 **** odfile_expat* self = (odfile_expat*)userData; if (strcmp(name, "map") == 0) { ! int i; ! for (i=0;atts[i]!=NULL;i+=2) { ! if (strcmp(atts[i],"name") == 0) { ! ofe_set_mapname(self, atts[i+1]); ! break; ! } } } --- 79,93 ---- odfile_expat* self = (odfile_expat*)userData; if (strcmp(name, "map") == 0) { ! ofe_set_mapname(self, _getAttribute(atts, "name")); ! } ! else if (strcmp(name, "snapshot") == 0) { ! if (self->snap == 0) { ! /* first snapshot */ ! self->snap = 1; ! ofe_set_firstTime(self, atoi(_getAttribute(atts,"time"))); ! ofe_set_firstSequence(self, atoi(_getAttribute(atts,"sequence"))); ! self->snapshotc = 0; } + self->snapshotc++; } *************** *** 81,84 **** --- 95,109 ---- + void XMLCALL _HandleEndElement(void *userData, const XML_Char *name) + { + odfile_expat* self = (odfile_expat*)userData; + if (strcmp(name, "snapshot") == 0) { + self->last_snap_offset = XML_GetCurrentByteIndex(self->parser) + + 11; + /* + 1 + 1 + strlen("snapshot") + 1; */ + } + } + + /* object methods */ odfile_expat* *************** *** 111,114 **** --- 136,142 ---- } + /* memorize parser */ + self->parser = p; + /* every handler get the odfile_expat pointer */ XML_SetUserData(p, self); *************** *** 118,127 **** XML_SetStartDoctypeDeclHandler (p, _HandleDoctype); XML_SetStartElementHandler (p, _HandleStartElement); /* open the file for reading */ ! docfd = open(ofe_get_name(self), O_RDONLY); if (docfd<0) { fprintf(stderr,"%s: could note open '%s' for reading: %s\n", ! fname, ofe_get_name(self), strerror(errno)); OFE_DONE(self); goto out; --- 146,156 ---- XML_SetStartDoctypeDeclHandler (p, _HandleDoctype); XML_SetStartElementHandler (p, _HandleStartElement); + XML_SetEndElementHandler (p, _HandleEndElement); /* open the file for reading */ ! docfd = open(ofe_name(self), O_RDONLY); if (docfd<0) { fprintf(stderr,"%s: could note open '%s' for reading: %s\n", ! fname, ofe_name(self), strerror(errno)); OFE_DONE(self); goto out; *************** *** 145,149 **** if (bytes_read < 0) { fprintf(stderr,"%s: could not read in %d bytes from %s: %s\n", ! fname, OFE_BUFFER_SIZE, ofe_get_name(self), strerror(errno)); OFE_DONE(self); goto out; --- 174,178 ---- if (bytes_read < 0) { fprintf(stderr,"%s: could not read in %d bytes from %s: %s\n", ! fname, OFE_BUFFER_SIZE, ofe_name(self), strerror(errno)); OFE_DONE(self); goto out; *************** *** 176,182 **** if (self != 0) { ! fprintf(stderr, "%s%s", ! self->xmldecl, self->doctype); ! fprintf(stderr, "<map name=\"%s\">", ofe_mapname(self)); } --- 205,212 ---- if (self != 0) { ! /* post process */ ! /* ! fprintf(stderr,"last pos = %d\n", self->last_snap_offset); ! */ } *************** *** 187,191 **** char* ! ofe_get_name(odfile_expat *self) { return self->infile; --- 217,221 ---- char* ! ofe_name(odfile_expat *self) { return self->infile; *************** *** 193,196 **** --- 223,261 ---- + int + ofe_snapshotc(odfile_expat *self) + { + return self->snapshotc; + } + + + void + ofe_set_firstTime(odfile_expat *self, int firstTime) + { + self->firstTime = firstTime; + } + + + int + ofe_firstTime(odfile_expat *self) + { + return self->firstTime; + } + + + void + ofe_set_firstSequence(odfile_expat *self, int firstSequence) + { + self->firstSequence = firstSequence; + } + + + int + ofe_firstSequence(odfile_expat *self) + { + return self->firstSequence; + } + + void ofe_set_mapname(odfile_expat *self, const char *mapname) |