/* 4 space tabs filename: xp.h package: common utils/xml parser description: xml routine headers for xp.c author: ydnar version history date user description ---------------------------------------------------------------------------- 02.21.2001 ydnar initial version for ia32 linux 02.22.2001 ydnar stack manipulations */ /* fingerprint */ #ifndef XP_H #define XP_H #endif /* includes */ #ifndef CT_H #include "ct.h" /* common types */ #endif #ifndef UU_H #include "uu.h" /* unicode utilities */ #endif #ifndef XT_H #include "xt.h" /* xml tokenizer */ #endif /* types */ /* character range struct */ typedef struct XPCharRange XPCharRange; struct XPCharRange { UCS4Char min, max; }; /* xml element struct */ typedef struct XPElement XPElement; struct XPElement { UInt32 type; /* see enumerated types below */ UInt32 dataAlloc, dataUsed, dataLen; UTF8String data; /* tag name, char data, etc */ UInt32 attAlloc, attCount; UInt32 *attNames; /* tag attribute name vectors */ UInt32 *attValues; /* tag attribute value vectors */ }; /* element types */ enum { XP_ELEMENT_NONE, XP_ELEMENT_START_TAG, XP_ELEMENT_EMPTY_TAG, XP_ELEMENT_END_TAG, XP_ELEMENT_CHAR_DATA, XP_ELEMENT_COUNT }; /* element names (must match up with above) */ #ifndef XP_C extern UTF8String xpElementNames[ XP_ELEMENT_COUNT ]; #else UTF8String xpElementNames[ XP_ELEMENT_COUNT ] = { "XP_ELEMENT_NONE", "XP_ELEMENT_START_TAG", "XP_ELEMENT_EMPTY_TAG", "XP_ELEMENT_END_TAG", "XP_ELEMENT_CHAR_DATA" }; #endif /* element allocation increments */ enum { XP_DATA_ALLOC = 4096, /* should be enough... */ XP_ATT_ALLOC = 16 }; /* stack delimiter */ #define XP_STACK_DELIMITER '/' /* xml parser struct */ typedef struct XPParser XPParser; struct XPParser { UInt32 status, lastStatus; UInt32 stackAlloc, stackLen, stackCount; /* for matching tags well-formedness */ UInt32 stackLast; /* offset into string */ UTF8String stack; /* '>' delimited string of tag names */ XPElement e; XTTokenizer t; /* token source */ }; /* xml parser status codes */ enum { XP_STATUS_ERROR = -1, XP_STATUS_FOUND_ELEMENT = 0, XP_STATUS_WORKING = 1, XP_STATUS_WANT_DATA = -100 }; /* parser allocation increments */ enum { XP_STACK_ALLOC = 1024 /* should be enough */ }; /* public function prototypes */ Error xpOpenParser( XPParser *p ); Error xpCloseParser( XPParser *p ); Error xpFillParser( XPParser *p, UInt32 bufLen, Char *buf ); Error xpPushStack( XPParser *p, UInt32 nameLen, UTF8String name ); Error xpPopStack( XPParser *p, UInt32 nameLen, UTF8String name ); Error xpInitElement( XPElement *e ); Error xpFreeElement( XPElement *e ); Error xpClearElement( XPElement *e ); Error xpAddElementData( XPElement *e, UInt32 dataLen, UTF8String data ); Error xpAddElementAttribute( XPElement *e, UInt32 nameLen, UTF8String name, UInt32 valueLen, UTF8String value ); Error xpDecRefToUTF8( UInt32 refLen, UTF8String ref, UInt32 *u8Len, UTF8String u8 ); Error xpHexRefToUTF8( UInt32 refLen, UTF8String ref, UInt32 *u8Len, UTF8String u8 ); Error xpReadNextElement( XPParser *p );