inc/xap.h

Go to the documentation of this file.
00001 /* xap - XML Automatic Parser - together with autoXml this helps automatically
00002  * read in automatically generated data structures. 
00003  *
00004  * This file is copyright 2002 Jim Kent, but license is hereby
00005  * granted for all use - public, private or commercial. */
00006 
00007 #ifndef XAP_H
00008 #define XAP_H
00009 
00010 #ifndef DYSTRING_H
00011 #include "dystring.h"
00012 #endif
00013 
00014 struct xapStack
00015 /* An element of parse stack. */
00016    {
00017    void *object;        /* Object being parsed. */
00018    char *elName;        /* Name of tag. */
00019    struct dyString *text;       /* The text section. */
00020    };
00021 
00022 struct xap
00023 /* A parser with a stack built in and other conveniences. */
00024    {
00025    struct xapStack *stack;                      /* Top of stack of open tags. */
00026    struct xapStack stackBuf[128];               /* Stack buffer. */
00027    struct xapStack *endStack;                   /* End of stack. */
00028    int stackDepth;                              /* Number of elements in stack. */
00029    int skipDepth;                               /* Depth beneath which we skip. */
00030    void *(*startHandler)(struct xap *xap, char *name, char **atts);     /* Handler for start tags. */
00031    void (*endHandler)(struct xap *xap, char *name);     /* Handler for end tags. */
00032    struct xp *xp;                                       /* Pointer to lower level parser. */
00033    char *fileName;                              /* Name of file being parsed - valid after xapParse. */
00034    char *topType;                               /* Top level type name - valid after xapParse. */
00035    void *topObject;                             /* Top level object - valid after xapParse. */
00036    FILE *f;                                     /* File. */
00037    };
00038 
00039 struct xap *xapNew(void *(*startHandler)(struct xap *xap, char *name, char **atts),
00040         void (*endHandler)(struct xap *xap, char *name) ,
00041         char *fileName);
00042 /* Create a new parse stack.  FileName may be NULL. */
00043 
00044 void xapFree(struct xap **pXp);
00045 /* Free up a parse stack. */
00046 
00047 void xapParseFile(struct xap *xap, char *fileName);
00048 /* Open up file and parse it all. */
00049 
00050 void xapError(struct xap *xap, char *format, ...);
00051 /* Issue an error message and abort*/
00052 
00053 void xapIndent(int count, FILE *f);
00054 /* Write out some spaces. */
00055 
00056 void xapSkip(struct xap *xap);
00057 /* Skip current tag and any children.  Called from startHandler. */
00058 
00059 void xapParseAny(char *fileName, char *type, 
00060         void *(*startHandler)(struct xap *xap, char *name, char **atts),
00061         void (*endHandler)(struct xap *xap, char *name),
00062         char **retType, void *retObj);
00063 /* Parse any object out of an XML file. 
00064  * If type parameter is non-NULL, force type.
00065  * example:
00066  *     xapParseAny("file.xml", "das", dasStartHandler, dasEndHandler, &type, &obj); */
00067 
00068 struct xap *xapOpen(char *fileName, 
00069         void *(*startHandler)(struct xap *xap, char *name, char **atts),
00070         void (*endHandler)(struct xap *xap, char *name));
00071 /* Open up an xml file, but don't start parsing it yet.
00072  * Instead call xapNext to get the elements you want out of
00073  * the file.  When all done call xapFree. */
00074 
00075 void *xapNext(struct xap *xap, char *tag);
00076 /* Return next item matching tag (and all of it's children). */
00077 #endif /* XAP_H */
00078 

Generated on Tue Dec 25 18:39:29 2007 for blat by  doxygen 1.5.2