inc/xp.h File Reference

#include "dystring.h"

Include dependency graph for xp.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  xpStack
struct  xp

Functions

xpxpNew (void *userData, void(*atStartTag)(void *userData, char *name, char **atts), void(*atEndTag)(void *userData, char *name, char *text), int(*read)(void *userData, char *buf, int bufSize), char *fileName)
void xpFree (struct xp **pXp)
int xpLineIx (struct xp *xp)
char * xpFileName (struct xp *xp)
int xpReadFromFile (void *userData, char *buf, int bufSize)
void xpError (struct xp *xp, char *format,...)
boolean xpParseNext (struct xp *xp, char *tag)
void xpParse (struct xp *xp)


Function Documentation

void xpError ( struct xp xp,
char *  format,
  ... 
)

Definition at line 113 of file xp.c.

References errAbort(), vaWarn(), xpFileName(), and xpLineIx().

Referenced by xpEatComment(), xpForceMatch(), xpLookup(), xpParseEndTag(), xpParseNext(), xpParseStartTag(), and xpUnexpectedEof().

00115 {
00116 va_list args;
00117 va_start(args, format);
00118 vaWarn(format, args);
00119 errAbort("line %d of %s", xpLineIx(xp), xpFileName(xp));
00120 va_end(args);
00121 }

Here is the call graph for this function:

Here is the caller graph for this function:

char* xpFileName ( struct xp xp  ) 

Definition at line 107 of file xp.c.

References xp::fileName.

Referenced by xpError().

00109 {
00110 return xp->fileName;
00111 }

Here is the caller graph for this function:

void xpFree ( struct xp **  pXp  ) 

Definition at line 73 of file xp.c.

References ArraySize, xp::attDyBuf, xp::endTag, xp::fileName, freeDyString(), freeMem(), freez(), hashFree, xp::stackBuf, xp::stackBufEnd, xp::symHash, xpStack::tag, and xpStack::text.

Referenced by xapFree().

00075 {
00076 int i;
00077 struct xp *xp = *pXp;
00078 if (xp != NULL)
00079     {
00080     struct xpStack *stack;
00081     for (stack = xp->stackBufEnd; --stack >= xp->stackBuf; )
00082         {
00083         if (stack->tag == NULL)
00084             break;
00085         freeDyString(&stack->tag);
00086         freeDyString(&stack->text);
00087         }
00088     for (i=0; i<ArraySize(xp->attDyBuf); ++i)
00089         {
00090         if (xp->attDyBuf[i] == NULL)
00091             break;
00092         freeDyString(&xp->attDyBuf[i]);
00093         }
00094     freeDyString(&xp->endTag);
00095     freeMem(xp->fileName);
00096     hashFree(&xp->symHash);
00097     freez(pXp);
00098     }
00099 }

Here is the call graph for this function:

Here is the caller graph for this function:

int xpLineIx ( struct xp xp  ) 

Definition at line 101 of file xp.c.

References xp::lineIx.

Referenced by xapError(), and xpError().

00103 {
00104 return xp->lineIx;
00105 }

Here is the caller graph for this function:

struct xp* xpNew ( void *  userData,
void(*)(void *userData, char *name, char **atts)  atStartTag,
void(*)(void *userData, char *name, char *text)  atEndTag,
int(*)(void *userData, char *buf, int bufSize)  read,
char *  fileName 
) [read]

Definition at line 38 of file xp.c.

References AllocVar, ArraySize, xp::atEndTag, xp::atStartTag, cloneString(), xp::endTag, xp::fileName, xp::in, xp::inBuf, xp::inBufEnd, xp::lineIx, newDyString(), xp::read, xp::stack, xp::stackBuf, xp::stackBufEnd, xp::symHash, xp::userData, and xmlEscapeSymHash().

Referenced by xapNew().

00045 {
00046 struct xp *xp;
00047 AllocVar(xp);
00048 xp->stack = xp->stackBufEnd = xp->stackBuf + ArraySize(xp->stackBuf);
00049 xp->userData = userData;
00050 xp->atStartTag = atStartTag;
00051 xp->atEndTag = atEndTag;
00052 xp->read = read;
00053 xp->lineIx = 1;
00054 xp->endTag = newDyString(64);
00055 if (fileName)
00056     xp->fileName = cloneString(fileName);
00057 else
00058     xp->fileName = cloneString("XML");
00059 xp->inBufEnd = xp->in = xp->inBuf;              
00060 xp->symHash = xmlEscapeSymHash();
00061 return xp;
00062 }

Here is the call graph for this function:

Here is the caller graph for this function:

void xpParse ( struct xp xp  ) 

Definition at line 549 of file xp.c.

References xpParseNext().

Referenced by xapParseFile().

00551 {
00552 xpParseNext(xp, NULL);
00553 }

Here is the call graph for this function:

Here is the caller graph for this function:

boolean xpParseNext ( struct xp xp,
char *  tag 
)

Definition at line 449 of file xp.c.

References ArraySize, xp::atEndTag, dyStringAppendC(), dyStringClear, xp::endTag, FALSE, xp::lineIx, newDyString(), sameString, xp::stack, xp::stackBufEnd, dyString::string, xpStack::tag, xpStack::text, TRUE, xp::userData, xpEatComment(), xpError(), xpGetChar, xpLookup(), xpParseEndTag(), xpParseStartTag(), and xpUngetChar.

Referenced by xapNext(), and xpParse().

00455 {
00456 char c;
00457 int i, attCount = 0;
00458 struct dyString *text = NULL;
00459 boolean isClosed;
00460 boolean inside = (tag == NULL);
00461 struct xpStack *initialStack = xp->stack;
00462 
00463 for (;;)
00464     {
00465     /* Load up text until next tag. */
00466     for (;;)
00467         {
00468         if ((c = xpGetChar(xp)) == 0)
00469             return FALSE;
00470         if (c == '<')
00471             break;
00472         if (c == '&')
00473            xpLookup(xp, xp->endTag, text);
00474         else 
00475             {
00476             if (c == '\n')
00477                 ++xp->lineIx;
00478             if (text != NULL)
00479                 dyStringAppendC(text, c);
00480             }
00481         }
00482 
00483     /* Get next character to figure out what type of tag. */
00484     c = xpGetChar(xp);
00485     if (c == 0)
00486        xpError(xp, "End of file inside tag");
00487     else if (c == '?' || c == '!')
00488         xpEatComment(xp, c);
00489     else if (c == '/')  /* Closing tag. */
00490         {
00491         struct xpStack *stack = xp->stack;
00492         if (stack >= xp->stackBufEnd)
00493             xpError(xp, "Extra end tag");
00494         xpParseEndTag(xp, stack->tag->string);
00495         if (inside)
00496             xp->atEndTag(xp->userData, stack->tag->string, stack->text->string);
00497         xp->stack += 1;
00498         if (xp->stack == initialStack)
00499             return TRUE;
00500         }
00501     else        /* Start tag. */
00502         {
00503         /* Push new frame on stack and check for overflow and unallocated strings. */
00504         struct xpStack *stack = --xp->stack;
00505         if (stack < xp->stackBuf)
00506             xpError(xp, "Stack overflow");
00507         if (stack->tag == NULL)
00508             stack->tag = newDyString(32);
00509         else
00510             dyStringClear(stack->tag);
00511         if (stack->text == NULL)
00512             stack->text = newDyString(256);
00513         else
00514             dyStringClear(stack->text);
00515         text = stack->text;
00516 
00517         /* Parse the start tag. */
00518         xpUngetChar(xp);
00519         xpParseStartTag(xp, ArraySize(xp->attDyBuf), stack->tag, 
00520                 &attCount, xp->attDyBuf, &isClosed);
00521 
00522         if (!inside && sameString(stack->tag->string, tag))
00523             {
00524             inside = TRUE;
00525             initialStack = xp->stack + 1;
00526             }
00527 
00528         /* Call user start function, and if closed tag, end function too. */
00529         if (inside)
00530             {
00531             /* Unpack attributes into simple array of strings. */
00532             for (i=0; i<attCount; ++i)
00533                 xp->attBuf[i] = xp->attDyBuf[i]->string;
00534             xp->attBuf[attCount] = NULL;
00535             xp->atStartTag(xp->userData, stack->tag->string, xp->attBuf);
00536             }
00537         if (isClosed)
00538             {
00539             if (inside)
00540                 xp->atEndTag(xp->userData, stack->tag->string, stack->text->string);
00541             xp->stack += 1;
00542             if (xp->stack == initialStack)
00543                 return TRUE;
00544             }
00545         }
00546     }
00547 }

Here is the call graph for this function:

Here is the caller graph for this function:

int xpReadFromFile ( void *  userData,
char *  buf,
int  bufSize 
)

Definition at line 64 of file xp.c.

00066 {
00067 FILE *f = userData;
00068 return fread(buf, 1, bufSize, f);
00069 }


Generated on Tue Dec 25 19:20:54 2007 for blat by  doxygen 1.5.2