xml.c File Reference

XML IO implementation. More...

#include <stdio.h>
#include "ctl/ctldef.h"
#include "ctl/debug.h"
#include "ctl/xml.h"

Include dependency graph for xml.c:

Go to the source code of this file.

Defines

#define DECL_DEF(type, unused)
 Template: Write a scalar of whatever type.
#define DECL_DEF(type, unused)
 Template: Write a scalar of whatever type.
#define DECL_DEF(type, unused)
 Template: Write a scalar of whatever type.
#define DECL_DEF(type, unused)
 Template: Write a scalar of whatever type.

Functions

bool ctl_xmlwrite_begin (ctl_xmlwrite *self, ctl_mstring_char_grow *stringbuff)
 Open an XML stream for writing, setting everything up for its output.
bool ctl_xmlwrite_create (ctl_xmlwrite *self, const char *szPath)
 Open an XML stream for writing, setting everything up for its output.
void ctl_xmlwrite_close (ctl_xmlwrite *self)
 Finish an XML stream for writing.
void ctl_xmlwrite_addheader (ctl_xmlwrite *self)
 Slap a header onto (presumably the start) of an XML file.
void ctl_xmlwrite_newline (ctl_xmlwrite *self)
 Write a newline into pretty-printed file.
void ctl_xmlwrite_indent (ctl_xmlwrite *self)
 Write a newline and indent following blocks.
void ctl_xmlwrite_outdent (ctl_xmlwrite *self)
 Write a newline and remove one level of indent from following blocks.
void ctl_xmlwrite_generaltag (ctl_xmlwrite *self, const char *type, const char *label)
 Write our most common tag opening for single members.
void ctl_xmlwrite_containertag (ctl_xmlwrite *self, const char *type, size_t count, const char *label)
 Write our most common tag opening for containers.
void ctl_xmlwrite_endtag (ctl_xmlwrite *self, const char *type, const char *label)
 Close our most common tag for containers or members.
void ctl_xmlwrite_string_char (ctl_xmlwrite *self, const char *begin, const char *end)
 Write a string of characters, translating escaped things.
void ctl_xmlwrite_string_wchar_t (ctl_xmlwrite *self, const wchar_t *begin, const wchar_t *end)
 Write a string of characters, translating escaped things.
const char * ctl_xmlread_translate_char (const ctl_xmlread *self, char *begin, const char *end, bool bEatWhite)
 Translate a string of text in-place in its own buffer.
const wchar_t * ctl_xmlread_translate_wchar_t (const ctl_xmlread *self, wchar_t *begin, const wchar_t *end, bool bEatWhite)
 Translate a string of text in-place in its own buffer.
size_t ctl_xmlread_string (const ctl_xmlread *self, ctl_mstring_char_grow *str, const char *begin, const char *end, bool bEatWhite)
bool ctl_xmlread_init (ctl_xmlread *self, const char *begin, const char *end, ctl_xmlread_exception except, void *exceptParam)
 Initialize an XML reader given begin/end string pointers.
void ctl_xmlread_rewind (ctl_xmlread *self)
 Set XML read point to beginning.
bool ctl_xmlread_next (ctl_xmlread *self)
 Set XML read point to next block.
bool ctl_xmlread_find (ctl_xmlread *self, const char *type)
 Search this block for a particular kind of tag.
bool ctl_xmlread_findnext (ctl_xmlread *self, const char *type)
 Search this block for a particular kind of tag, starting after current one.
bool ctl_xmlread_canrecurse (ctl_xmlread *self)
 Tell us if this block contains more blocks.
bool ctl_xmlread_recurse (ctl_xmlread *newself, const ctl_xmlread *self)
 Initialize a new XML parser to parse inside the current block.
bool ctl_xmlread_getname (const ctl_xmlread *self, ctl_mstring_char_grow *str)
 Get the name of the current tag.
bool ctl_xmlread_is (const ctl_xmlread *self, const char *str)
 See if the name of the current tag matches a NUL terminated string.
bool ctl_xmlread_getattribute (ctl_xmlread *self, ctl_mstring_char_grow *str, const char *label)
 Get an attribute.
bool ctl_xmlread_getcontent (const ctl_xmlread *self, ctl_mstring_char_grow *str, bool eatWhite)
 Get the content;.
bool ctl_xmlread_gettextbefore (const ctl_xmlread *self, ctl_mstring_char_grow *str, bool eatWhite)
 Get text before the current block;.
bool ctl_xmlread_gettextafter (const ctl_xmlread *self, ctl_mstring_char_grow *str, bool eatWhite)
 Get text after the current block;.
bool ctl_xmlread_rawname (const ctl_xmlread *self, ctl_sconst_char *str)
 Get the name of the current tag.
bool ctl_xmlread_rawattribute (ctl_xmlread *self, ctl_sconst_char *str, const char *label)
 Get an attribute.
bool ctl_xmlread_getattribute_int (ctl_xmlread *self, const char *label, int32 *value)
 Get an attribute known to be an integer of some sort.
bool ctl_xmlread_rawcontent (const ctl_xmlread *self, ctl_sconst_char *str, bool eatWhite)
 Get the content;.
bool ctl_xmlread_rawtextbefore (const ctl_xmlread *self, ctl_sconst_char *str, bool eatWhite)
 Get text after the current block;.
bool ctl_xmlread_rawtextafter (const ctl_xmlread *self, ctl_sconst_char *str, bool eatWhite)
 Get text after the current block;.
void char_xml_write_string (const char *buff, size_t size, ctl_xmlwrite *xml, const char *label)
 Write a string of unicode characters.
void wchar_t_xml_write_string (const wchar_t *buff, size_t size, ctl_xmlwrite *xml, const char *label)
 Write a string of unicode characters.
bool char_xml_read_string (char *buff, size_t size, ctl_xmlread *self, const char *label)
 Read a string into fixed length C string buffer.
bool wchar_t_xml_read_string (wchar_t *buff, size_t size, ctl_xmlread *self, const char *label)
 Read a string into fixed length C string buffer.
bool char_xml_read_gstring (ctl_mstring_char_grow *str, ctl_xmlread *self, const char *label)
 Read a string into fixed length C string buffer.
bool wchar_t_xml_read_gstring (ctl_mstring_wchar_t_grow *str, ctl_xmlread *self, const char *label)
 Read a string into fixed length C string buffer.
void raw_xml_writebytes (const ctl_serial *serial, ctl_xmlwrite *self, const char *label)
 Write raw serial data as XML record.
bool raw_xml_readbytes (ctl_serial *serial, ctl_xmlread *self, const char *label)
 Read raw serial data from XML record.


Detailed Description

XML IO implementation.

Author:
David Mace

Definition in file xml.c.


Function Documentation

size_t ctl_xmlread_string ( const ctl_xmlread self,
ctl_mstring_char_grow *  str,
const char *  begin,
const char *  end,
bool  bEatWhite 
)

Get a character, translating if escaped

Parameters:
self XML reader we're operating on
str Where to put the data we decoded
begin Text we're translating
end Points at the end of the string
bEatWhite True if you want this to skip white space
Returns:
Size of resulting string

Definition at line 846 of file xml.c.

References assert, assertconst, assertobjconst, assertobjptr, ctl_gstring_size, ctl_gstring_strncpy, and ctl_xmlread_translate_char().

Referenced by ctl_xmlread_getattribute(), ctl_xmlread_getcontent(), ctl_xmlread_gettextafter(), and ctl_xmlread_gettextbefore().

00847 {
00848     assertobjconst(self);
00849     assertobjptr( str );
00850     assertconst( begin,1 );
00851     assertconst( end,1 );
00852     assert( end >= begin );
00853     ctl_gstring_strncpy( char, str, begin, end-begin );
00854     str->end = (char*)ctl_xmlread_translate_char( self, str->begin, str->end, bEatWhite );
00855     return ctl_gstring_size(char, str );
00856 }

Here is the call graph for this function:

bool raw_xml_readbytes ( ctl_serial serial,
ctl_xmlread self,
const char *  label 
)

Read raw serial data from XML record.

Parameters:
serial Points at ctl_serial to receive data
self XML reader to get it from
label What the record was called
Returns:
false if label is not found, or other error

Definition at line 1688 of file xml.c.

References assertconst, assertobjptr, ctl_sconst, ctl_sconst_getxuint8, ctl_serial_alloc, ctl_xmlread_find(), ctl_xmlread_getattribute_int(), ctl_xmlread_rawcontent(), and uint8_serial_write().

01689 {
01690     int32 size;
01691     assertobjptr(serial);/* Inputs should be valid-looking */
01692     assertobjptr(self);
01693     assertconst( label,1 );
01694     if( ctl_xmlread_find( self, label ) )
01695     {
01696         if( ctl_xmlread_getattribute_int( self, CTL_LABEL_COUNT, &size ) )
01697         {
01698             ctl_sconst(char) body;
01699             ctl_xmlread_rawcontent( self, &body, true );
01700             ctl_serial_alloc( serial, size );
01701             {
01702                 uint8 v;
01703                 while( ctl_sconst_getxuint8(char, &body, &v ) )
01704                     uint8_serial_write( &v, serial );
01705             }
01706             return true;
01707         }
01708     }
01709     return false;
01710 }

Here is the call graph for this function:

void raw_xml_writebytes ( const ctl_serial serial,
ctl_xmlwrite self,
const char *  label 
)

Write raw serial data as XML record.

Parameters:
serial Points at raw data to write
self XML writer to write it to
label What to call the record

Definition at line 1658 of file xml.c.

References assertconst, assertobjconst, assertobjptr, ctl_serial::begin, ctl_serial_total, ctl_xmlwrite_containertag(), ctl_xmlwrite_endtag(), ctl_xmlwrite_indent(), ctl_xmlwrite_newline(), and ctl_xmlwrite_outdent().

01659 {
01660     size_t count;
01661     assertobjconst(serial);/* Inputs should be valid-looking */
01662     assertobjptr(self);
01663     assertconst( label,1 );
01664     count = ctl_serial_total( serial );
01665     ctl_xmlwrite_containertag( self, "raw", count, label );
01666     ctl_xmlwrite_indent( self );
01667     {
01668         const uint8* p = serial->begin;
01669         while( p < serial->end )
01670         {
01671             if( 0 == ((p-serial->begin)&0xf) )
01672                 ctl_xmlwrite_newline( self );
01673             xml_printf( self, " %02x", (unsigned)*p );
01674             p++;
01675         }
01676     }
01677     ctl_xmlwrite_outdent( self );
01678     ctl_xmlwrite_endtag( self, "raw", label );
01679 
01680 }

Here is the call graph for this function:


Generated on Fri Jan 2 15:28:36 2009 for Squat by  doxygen 1.5.6