lib/xap.c File Reference

#include "common.h"
#include "xap.h"
#include "errabort.h"
#include "xp.h"

Include dependency graph for xap.c:

Go to the source code of this file.

Functions

void xapError (struct xap *xap, char *format,...)
static void xapStartTag (void *userData, char *name, char **atts)
static void xapEndTag (void *userData, char *name, char *text)
static int xapRead (void *userData, char *buf, int bufSize)
xapxapNew (void *(*startHandler)(struct xap *xap, char *name, char **atts), void(*endHandler)(struct xap *xap, char *name), char *fileName)
void xapFree (struct xap **pXp)
void xapParseFile (struct xap *xap, char *fileName)
void xapIndent (int count, FILE *f)
void xapSkip (struct xap *xap)
void xapParseAny (char *fileName, char *type, void *(*startHandler)(struct xap *xap, char *name, char **atts), void(*endHandler)(struct xap *xap, char *name), char **retType, void *retObj)
xapxapOpen (char *fileName, void *(*startHandler)(struct xap *xap, char *name, char **atts), void(*endHandler)(struct xap *xap, char *name))
void * xapNext (struct xap *xap, char *tag)

Variables

static char const rcsid [] = "$Id: xap.c,v 1.11 2005/12/19 05:18:26 kent Exp $"


Function Documentation

static void xapEndTag ( void *  userData,
char *  name,
char *  text 
) [static]

Definition at line 48 of file xap.c.

References dyStringAppend(), dyStringClear, xap::endHandler, xap::endStack, xap::skipDepth, xap::stack, xap::stackDepth, xapStack::text, and xapError().

Referenced by xapNew().

00050 {
00051 struct xap *xap = userData;
00052 struct xapStack *stack;
00053 
00054 dyStringAppend(xap->stack->text, text);
00055 if (xap->skipDepth == 0 || xap->skipDepth <= xap->stackDepth)
00056     {
00057     xap->skipDepth = 0;
00058     if (xap->endHandler)
00059         xap->endHandler(xap, (char*)name);
00060     }
00061 stack = xap->stack++;
00062 if (xap->stack > xap->endStack)
00063     xapError(xap, "xap stack underflow");
00064 --xap->stackDepth;
00065 dyStringClear(stack->text);
00066 }

Here is the call graph for this function:

Here is the caller graph for this function:

void xapError ( struct xap xap,
char *  format,
  ... 
)

Definition at line 15 of file xap.c.

References errAbort(), xap::fileName, vaWarn(), xap::xp, and xpLineIx().

Referenced by xapEndTag(), xapParseAny(), and xapStartTag().

00017 {
00018 va_list args;
00019 va_start(args, format);
00020 vaWarn(format, args);
00021 errAbort("line %d of %s", xpLineIx(xap->xp), xap->fileName);
00022 va_end(args);
00023 }

Here is the call graph for this function:

Here is the caller graph for this function:

void xapFree ( struct xap **  pXp  ) 

Definition at line 99 of file xap.c.

References xap::fileName, freeDyString(), freeMem(), freez(), xap::stackBuf, xapStack::text, xap::topType, xap::xp, and xpFree().

Referenced by xapParseAny().

00101 {
00102 struct xap *xap = *pXp;
00103 if (xap != NULL)
00104     {
00105     struct xapStack *stack;
00106     for (stack = xap->stackBuf; stack < xap->endStack; ++stack)
00107         {
00108         if (stack->text != NULL)
00109            freeDyString(&stack->text);
00110         }
00111     xpFree(&xap->xp);
00112     freeMem(xap->fileName);
00113     freeMem(xap->topType);
00114     freez(pXp);
00115     }
00116 }

Here is the call graph for this function:

Here is the caller graph for this function:

void xapIndent ( int  count,
FILE *  f 
)

Definition at line 126 of file xap.c.

00128 {
00129 int i;
00130 for (i=0; i<count; ++i)
00131     {
00132     fputc(' ', f);
00133     }
00134 }

struct xap* xapNew ( void *(*)(struct xap *xap, char *name, char **atts)  startHandler,
void(*)(struct xap *xap, char *name endHandler,
char *  fileName 
) [read]

Definition at line 85 of file xap.c.

References AllocVar, ArraySize, cloneString(), xap::endHandler, xap::endStack, xap::fileName, xap::stack, xap::stackBuf, xap::startHandler, xapEndTag(), xapRead(), xapStartTag(), xap::xp, and xpNew().

Referenced by xapOpen(), and xapParseAny().

00088 {
00089 struct xap *xap;
00090 AllocVar(xap);
00091 xap->endStack = xap->stack = xap->stackBuf + ArraySize(xap->stackBuf) - 1;
00092 xap->startHandler = startHandler;
00093 xap->endHandler = endHandler;
00094 xap->xp = xpNew(xap, xapStartTag, xapEndTag, xapRead, fileName);
00095 xap->fileName = cloneString(fileName);
00096 return xap;
00097 }

Here is the call graph for this function:

Here is the caller graph for this function:

void* xapNext ( struct xap xap,
char *  tag 
)

Definition at line 174 of file xap.c.

References errAbort(), sameString, xap::topObject, xap::topType, xap::xp, and xpParseNext().

00176 {
00177 if (!xpParseNext(xap->xp, tag))
00178     return NULL;
00179 if (!sameString(xap->topType, tag))
00180     errAbort("Expecting %s tag, got %s tag", tag, xap->topType);
00181 return xap->topObject;
00182 }

Here is the call graph for this function:

struct xap* xapOpen ( char *  fileName,
void *(*)(struct xap *xap, char *name, char **atts)  startHandler,
void(*)(struct xap *xap, char *name endHandler 
) [read]

Definition at line 162 of file xap.c.

References xap::f, mustOpen(), and xapNew().

00168 {
00169 struct xap *xap = xapNew(startHandler, endHandler, fileName);
00170 xap->f =  mustOpen(fileName, "r");
00171 return xap;
00172 }

Here is the call graph for this function:

void xapParseAny ( char *  fileName,
char *  type,
void *(*)(struct xap *xap, char *name, char **atts)  startHandler,
void(*)(struct xap *xap, char *name endHandler,
char **  retType,
void *  retObj 
)

Definition at line 142 of file xap.c.

References cloneString(), sameString, xap::topType, xapError(), xapFree(), xapNew(), and xapParseFile().

00148           :
00149  *     xapParseAny("file.xml", "das", dasStartHandler, dasEndHandler, &type, &obj); */
00150 {
00151 struct xap *xap = xapNew(startHandler, endHandler, fileName);
00152 void **pObj = retObj;
00153 xapParseFile(xap, fileName);
00154 if (type != NULL && !sameString(xap->topType, type))
00155     xapError(xap, "Got %s, expected %s\n", xap->topType, type);
00156 if (retType != NULL)
00157     *retType = cloneString(xap->topType);
00158 *pObj = xap->topObject;
00159 xapFree(&xap);
00160 }

Here is the call graph for this function:

void xapParseFile ( struct xap xap,
char *  fileName 
)

Definition at line 118 of file xap.c.

References carefulClose(), xap::f, mustOpen(), xap::xp, and xpParse().

Referenced by xapParseAny().

00120 {
00121 xap->f = mustOpen(fileName, "r");
00122 xpParse(xap->xp);
00123 carefulClose(&xap->f);
00124 }

Here is the call graph for this function:

Here is the caller graph for this function:

static int xapRead ( void *  userData,
char *  buf,
int  bufSize 
) [static]

Definition at line 78 of file xap.c.

References xap::f.

Referenced by xapNew().

00080 {
00081 struct xap *xap = userData;
00082 return fread(buf, 1, bufSize, xap->f);
00083 }

Here is the caller graph for this function:

void xapSkip ( struct xap xap  ) 

Definition at line 136 of file xap.c.

References xap::skipDepth, and xap::stackDepth.

00138 {
00139 xap->skipDepth = xap->stackDepth;
00140 }

static void xapStartTag ( void *  userData,
char *  name,
char **  atts 
) [static]

Definition at line 25 of file xap.c.

References cloneString(), xapStack::elName, freeMem(), newDyString(), xapStack::object, xap::stack, xapStack::text, and xapError().

Referenced by xapNew().

00027 {
00028 struct xap *xap = userData;
00029 struct xapStack *stack;
00030 
00031 stack = --xap->stack;
00032 if (stack < xap->stackBuf)
00033     xapError(xap, "xap stack overflow");
00034 ++xap->stackDepth;
00035 if (stack->text == NULL)
00036     stack->text = newDyString(256);
00037 stack->elName = (char*)name;
00038 if (xap->skipDepth == 0)
00039     stack->object = xap->startHandler(xap, (char*)name, (char**)atts);
00040 if (xap->stackDepth == 1)
00041     {
00042     freeMem(xap->topType);
00043     xap->topType = cloneString(stack->elName);
00044     xap->topObject = stack->object;
00045     }
00046 }

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

char const rcsid[] = "$Id: xap.c,v 1.11 2005/12/19 05:18:26 kent Exp $" [static]

Definition at line 13 of file xap.c.


Generated on Tue Dec 25 20:23:24 2007 for blat by  doxygen 1.5.2