TwiceAsNice  2019-02-18
Classes | Macros | Enumerations | Functions | Variables
lilxml.c File Reference
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "lilxml.h"
Include dependency graph for lilxml.c:

Classes

struct  String
 
struct  _LilXML
 
struct  _xml_ele
 
struct  _xml_att
 

Macros

#define MINMEM   64 /* starting string length */
 
#define PRINDENT   4 /* sample print indent each level */
 

Enumerations

enum  State {
  LOOK4START = 0, LOOK4TAG, INTAG, LOOK4ATTRN,
  INATTRN, LOOK4ATTRV, SAWSLASH, INATTRV,
  ENTINATTRV, LOOK4CON, INCON, ENTINCON,
  SAWLTINCON, LOOK4CLOSETAG, INCLOSETAG
}
 

Functions

static int oneXMLchar (LilXML *lp, int c, char ynot[])
 
static void initParser (LilXML *lp)
 
static void pushXMLEle (LilXML *lp)
 
static void popXMLEle (LilXML *lp)
 
static void resetEndTag (LilXML *lp)
 
static XMLAttgrowAtt (XMLEle *e)
 
static XMLElegrowEle (XMLEle *pe)
 
static void freeAtt (XMLAtt *a)
 
static int isTokenChar (int start, int c)
 
static void growString (String *sp, int c)
 
static void appendString (String *sp, const char *str)
 
static void freeString (String *sp)
 
static void newString (String *sp)
 
static void * moremem (void *old, int n)
 
void lilxmlMalloc (void *(*newmalloc)(size_t size), void *(*newrealloc)(void *ptr, size_t size), void(*newfree)(void *ptr))
 
LilXMLnewLilXML ()
 Create a new lilxml parser. More...
 
void delLilXML (LilXML *lp)
 Delete a lilxml parser. More...
 
void delXMLEle (XMLEle *ep)
 Delete an XML element. More...
 
XMLEle ** parseXMLChunk (LilXML *lp, char *buf, int size, char ynot[])
 Process an XML chunk. More...
 
XMLElereadXMLEle (LilXML *lp, int newc, char ynot[])
 Process an XML one char at a time. More...
 
XMLEleparseXML (char buf[], char ynot[])
 
XMLElecloneXMLEle (XMLEle *ep)
 
XMLAttfindXMLAtt (XMLEle *ep, const char *name)
 Find an XML attribute within an XML element. More...
 
XMLElefindXMLEle (XMLEle *ep, const char *tag)
 Find an XML element within an XML element. More...
 
XMLElenextXMLEle (XMLEle *ep, int init)
 Iterate an XML element for a list of nesetd XML elements. More...
 
XMLAttnextXMLAtt (XMLEle *ep, int init)
 Iterate an XML element for a list of XML attributes. More...
 
XMLEleparentXMLEle (XMLEle *ep)
 Return the parent of an XML element. More...
 
XMLEleparentXMLAtt (XMLAtt *ap)
 Return the parent of an XML attribute. More...
 
char * tagXMLEle (XMLEle *ep)
 Return the tag of an XML element. More...
 
char * pcdataXMLEle (XMLEle *ep)
 Return the pcdata of an XML element. More...
 
int pcdatalenXMLEle (XMLEle *ep)
 Return the number of characters in pcdata in an XML element. More...
 
char * nameXMLAtt (XMLAtt *ap)
 Return the name of an XML attribute. More...
 
char * valuXMLAtt (XMLAtt *ap)
 Return the value of an XML attribute. More...
 
int nXMLEle (XMLEle *ep)
 Return the number of nested XML elements in a parent XML element. More...
 
int nXMLAtt (XMLEle *ep)
 Return the number of XML attributes in a parent XML element. More...
 
const char * findXMLAttValu (XMLEle *ep, const char *name)
 Find an XML element's attribute value. More...
 
XMLElereadXMLFile (FILE *fp, LilXML *lp, char ynot[])
 Handy wrapper to read one xml file. More...
 
XMLEleaddXMLEle (XMLEle *parent, const char *tag)
 add an element with the given tag to the given element. More...
 
void appXMLEle (XMLEle *ep, XMLEle *newep)
 
void editXMLEle (XMLEle *ep, const char *pcdata)
 set the pcdata of the given element More...
 
XMLAttaddXMLAtt (XMLEle *ep, const char *name, const char *valu)
 Add an XML attribute to an existing XML element. More...
 
void rmXMLAtt (XMLEle *ep, const char *name)
 Remove an XML attribute from an XML element. More...
 
void editXMLAtt (XMLAtt *ap, const char *str)
 change the value of an attribute to str. More...
 
void prXMLEle (FILE *fp, XMLEle *ep, int level)
 Print an XML element. More...
 
int sprXMLEle (char *s, XMLEle *ep, int level)
 sample print ep to string s. More...
 
int sprlXMLEle (XMLEle *ep, int level)
 return number of bytes in a string guaranteed able to hold result of sprXLMEle(ep) (sans trailing \0@). More...
 
char * entityXML (char *s)
 return a string with all xml-sensitive characters within the passed string replaced with their entity sequence equivalents. More...
 
static int decodeEntity (char *ent, int *cp)
 

Variables

static char entities [] = "&<>'\""
 
static void *(* mymalloc )(size_t size) = malloc
 
static void *(* myrealloc )(void *ptr, size_t size) = realloc
 
static void(* myfree )(void *ptr) = free
 

Macro Definition Documentation

◆ MINMEM

#define MINMEM   64 /* starting string length */

◆ PRINDENT

#define PRINDENT   4 /* sample print indent each level */

Enumeration Type Documentation

◆ State

enum State
Enumerator
LOOK4START 
LOOK4TAG 
INTAG 
LOOK4ATTRN 
INATTRN 
LOOK4ATTRV 
SAWSLASH 
INATTRV 
ENTINATTRV 
LOOK4CON 
INCON 
ENTINCON 
SAWLTINCON 
LOOK4CLOSETAG 
INCLOSETAG 

Function Documentation

◆ appendString()

static void appendString ( String sp,
const char *  str 
)
static

◆ appXMLEle()

void appXMLEle ( XMLEle ep,
XMLEle newep 
)

◆ cloneXMLEle()

XMLEle* cloneXMLEle ( XMLEle ep)

◆ decodeEntity()

static int decodeEntity ( char *  ent,
int *  cp 
)
static

◆ freeAtt()

static void freeAtt ( XMLAtt a)
static

◆ freeString()

static void freeString ( String sp)
static

◆ growAtt()

static XMLAtt * growAtt ( XMLEle e)
static

◆ growEle()

static XMLEle * growEle ( XMLEle pe)
static

◆ growString()

static void growString ( String sp,
int  c 
)
static

◆ initParser()

static void initParser ( LilXML lp)
static

◆ isTokenChar()

static int isTokenChar ( int  start,
int  c 
)
static

◆ lilxmlMalloc()

void lilxmlMalloc ( void *(*)(size_t size)  newmalloc,
void *(*)(void *ptr, size_t size)  newrealloc,
void(*)(void *ptr)  newfree 
)

◆ moremem()

static void * moremem ( void *  old,
int  n 
)
static

◆ newString()

static void newString ( String sp)
static

◆ oneXMLchar()

static int oneXMLchar ( LilXML lp,
int  c,
char  ynot[] 
)
static

◆ parseXML()

XMLEle* parseXML ( char  buf[],
char  ynot[] 
)

◆ popXMLEle()

static void popXMLEle ( LilXML lp)
static

◆ pushXMLEle()

static void pushXMLEle ( LilXML lp)
static

◆ resetEndTag()

static void resetEndTag ( LilXML lp)
static

Variable Documentation

◆ entities

char entities[] = "&<>'\""
static

◆ myfree

void(* myfree) (void *ptr) = free
static

◆ mymalloc

void*(* mymalloc) (size_t size) = malloc
static

◆ myrealloc

void*(* myrealloc) (void *ptr, size_t size) = realloc
static