inc/xp.h

Go to the documentation of this file.
00001 /* xp - A minimal non-verifying xml parser.  It's
00002  * stream oriented much like expat.
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 XP_H
00008 #define XP_H
00009 
00010 #ifndef DYSTRING_H
00011 #include "dystring.h"
00012 #endif
00013 
00014 struct xpStack
00015 /* A context stack for parser. */
00016     {
00017     struct dyString *tag;   /* Name of tag. */
00018     struct dyString *text;  /* Contains text if any. */
00019     };
00020 
00021 struct xp
00022 /* A minimal non-verifying xml parser. */
00023     {
00024     struct xp *next;    /* Next in list. */
00025     struct xpStack *stack;              /* Current top of stack. */
00026     struct xpStack stackBuf[64];        /* Stack buffer and start of stack. */
00027     struct xpStack *stackBufEnd;        /* End of stack buffer. */
00028     struct dyString *attDyBuf[128];     /* Attribute buffer as dynamic string. */
00029     char *attBuf[128];                  /* Attribute buffer as regular string. */
00030     struct dyString *endTag;            /* Buffer for an end tag. */
00031     void *userData;                     /* Pointer to user's data structure. */
00032     void (*atStartTag)(void *userData, char *name, char **atts);  /* Got start and attributes. */
00033     void (*atEndTag)(void *userData, char *name, char *text);   /* Got end. */
00034     int (*read)(void *userData, char *buf, int bufSize);   /* Read some more. */
00035     char *fileName;                     /* File name. */
00036     int lineIx;                         /* Number of current line. */
00037     char inBuf[16*1024];                /* Text input buffer. */
00038     char *inBufEnd;                     /* Pointer to end of input buffer. */
00039     char *in;                           /* Next character to parse. */
00040     struct hash *symHash;               /* Hash of > < etc. */
00041     };
00042 
00043 struct xp *xpNew(void *userData, 
00044    void (*atStartTag)(void *userData, char *name, char **atts),
00045    void (*atEndTag)(void *userData, char *name, char *text),
00046    int (*read)(void *userData, char *buf, int bufSize),
00047    char *fileName);
00048 /* Form a new xp parser.  File name may be NULL - just used for
00049  * error reporting. */
00050 
00051 void xpFree(struct xp **pXp);
00052 /* Free up an xp parser. */
00053 
00054 int xpLineIx(struct xp *xp);
00055 /* Return current line number. */
00056 
00057 char *xpFileName(struct xp *xp);
00058 /* Return current file name. */
00059 
00060 int xpReadFromFile(void *userData, char *buf, int bufSize);
00061 /* This is a function you can pass to xpNew as a read handler.
00062  * It assumes you've passed an open FILE in as userData. */
00063 
00064 void xpError(struct xp *xp, char *format, ...);
00065 /* Output an error message with filename and line number included. */
00066 
00067 boolean xpParseNext(struct xp *xp, char *tag);
00068 /* Skip through file until get given tag.  Then parse out the
00069  * tag and all of it's children (calling atStartTag/atEndTag).
00070  * You can call this repeatedly to process all of a given tag
00071  * in file. */
00072 
00073 void xpParse(struct xp *xp);
00074 /* Parse from start tag to end tag.  Throw error if a problem.
00075  * Returns FALSE if nothing left to parse. */
00076 
00077 #endif /* XP_H */
00078 

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