pug Namespace Reference
Classes | |
| struct | t_xml_attribute_struct |
| struct | t_xml_node_struct |
| class | pointer_array |
| class | indent_stack |
| class | xml_iterator |
| class | xml_tree_walker |
| class | xml_attribute |
| class | forward_class |
| class | xml_node |
| class | xml_parser |
| class | xml_node_list |
Typedefs | |
| typedef char | TCHAR |
| typedef char | _TCHAR |
| typedef pug::t_xml_attribute_struct | xml_attribute_struct |
| typedef enum pug::t_xml_node_type | xml_node_type |
| typedef pug::t_xml_node_struct | xml_node_struct |
Enumerations | |
| enum | t_xml_node_type { node_null, node_document, node_element, node_pcdata, node_cdata, node_comment, node_pi, node_include, node_doctype, node_dtd_entity, node_dtd_attlist, node_dtd_element, node_dtd_notation } |
Functions | |
| static unsigned long | lib_variant () |
| static unsigned long | lib_version () |
| static bool | strcatgrow (TCHAR **lhs, const TCHAR *rhs) |
| static bool | chartype_symbol (TCHAR c) |
| static bool | chartype_space (TCHAR c) |
| static bool | chartype_enter (TCHAR c) |
| static bool | chartype_leave (TCHAR c) |
| static bool | chartype_close (TCHAR c) |
| static bool | chartype_equals (TCHAR c) |
| static bool | chartype_special (TCHAR c) |
| static bool | chartype_pi (TCHAR c) |
| static bool | chartype_dash (TCHAR c) |
| static bool | chartype_quote (TCHAR c) |
| static bool | chartype_lbracket (TCHAR c) |
| static bool | chartype_rbracket (TCHAR c) |
| static bool | strwtrim (TCHAR **s) |
| static bool | strwnorm (TCHAR **s) |
| static bool | strcpyinsitu (TCHAR **dest, const TCHAR *src, bool *insitu) |
| int | strcmpwild_cset (const TCHAR **src, const TCHAR **dst) |
| int | strcmpwild_impl (const TCHAR *src, const TCHAR *dst) |
| int | strcmpwild_astr (const TCHAR **src, const TCHAR **dst) |
| int | strcmpwild (const TCHAR *src, const TCHAR *dst) |
| static xml_attribute_struct * | new_attribute (void) |
| static xml_node_struct * | new_node (xml_node_type type=node_element) |
| static xml_node_struct * | append_node (xml_node_struct *parent, const int grow, const xml_node_type type=node_element, xml_node_struct *xns_child=NULL) |
| static xml_attribute_struct * | append_attribute (xml_node_struct *node, long grow) |
| static void | free_node (xml_node_struct *node) |
| static void | free_node_recursive (xml_node_struct *root) |
| static bool | load_file (const TCHAR *path, TCHAR **buffer, unsigned long *size, unsigned long tempsize=4096) |
| static void | outer_xml (std::ostream &os, indent_stack &indent, xml_node_struct *node, bool breaks=true) |
Variables | |
| static const unsigned long | parse_grow = 4 |
| static const unsigned long | parse_minimal = 0x00000000 |
| static const unsigned long | parse_pi = 0x00000002 |
| static const unsigned long | parse_doctype = 0x00000004 |
| static const unsigned long | parse_comments = 0x00000008 |
| static const unsigned long | parse_cdata = 0x00000010 |
| static const unsigned long | parse_escapes = 0x00000020 |
| static const unsigned long | parse_trim_pcdata = 0x00000040 |
| static const unsigned long | parse_trim_attribute = 0x00000080 |
| static const unsigned long | parse_trim_cdata = 0x00000100 |
| static const unsigned long | parse_trim_entity = 0x00000200 |
| static const unsigned long | parse_trim_doctype = 0x00000400 |
| static const unsigned long | parse_trim_comment = 0x00000800 |
| static const unsigned long | parse_wnorm = 0x00001000 |
| static const unsigned long | parse_dtd = 0x00002000 |
| static const unsigned long | parse_dtd_only = 0x00004000 |
| static const unsigned long | parse_default = 0x0000FFFF |
| static const unsigned long | parse_noset = 0x80000000 |
Typedef Documentation
| typedef char pug::_TCHAR |
| typedef char pug::TCHAR |
| typedef struct pug::t_xml_attribute_struct pug::xml_attribute_struct |
| typedef struct pug::t_xml_node_struct pug::xml_node_struct |
| typedef enum pug::t_xml_node_type pug::xml_node_type |
Enumeration Type Documentation
| enum pug::t_xml_node_type |
- Enumerator:
-
node_null node_document node_element node_pcdata node_cdata node_comment node_pi node_include node_doctype node_dtd_entity node_dtd_attlist node_dtd_element node_dtd_notation
Definition at line 216 of file pugxml.h.
00217 { 00218 node_null, //An undifferentiated entity. 00219 node_document, //A document tree's absolute root. 00220 node_element, //E.g. '<...>' 00221 node_pcdata, //E.g. '>...<' 00222 node_cdata, //E.g. '<![CDATA[...]]>' 00223 node_comment, //E.g. '<!--...-->' 00224 node_pi, //E.g. '<?...?>' 00225 node_include, //E.g. '<![INCLUDE[...]]>' 00226 node_doctype, //E.g. '<!DOCTYPE ...>'. 00227 node_dtd_entity, //E.g. '<!ENTITY ...>'. 00228 node_dtd_attlist, //E.g. '<!ATTLIST ...>'. 00229 node_dtd_element, //E.g. '<!ELEMENT ...>'. 00230 node_dtd_notation //E.g. '<!NOTATION ...>'. 00231 } xml_node_type;
Function Documentation
| static xml_attribute_struct* pug::append_attribute | ( | xml_node_struct * | node, | |
| long | grow | |||
| ) | [inline, static] |
Definition at line 784 of file pugxml.h.
References pug::t_xml_node_struct::attribute, pug::t_xml_node_struct::attribute_space, pug::t_xml_node_struct::attributes, and new_attribute().
Referenced by pug::xml_node::append_attribute(), pug::xml_node::attribute(), and pug::xml_parser::parse().
00785 { 00786 if(!node) return NULL; 00787 xml_attribute_struct* a = new_attribute(); 00788 if(!a) return NULL; 00789 if(node->attributes == node->attribute_space) //Out of space, so grow. 00790 { 00791 xml_attribute_struct** t = 00792 (xml_attribute_struct**)realloc(node->attribute, 00793 sizeof(xml_node_struct*)*(node->attribute_space+grow)); 00794 if(t) 00795 { 00796 node->attribute = t; 00797 node->attribute_space += grow; 00798 } 00799 } 00800 node->attribute[node->attributes] = a; 00801 node->attributes++; 00802 return a; 00803 }
Here is the call graph for this function:

| static xml_node_struct* pug::append_node | ( | xml_node_struct * | parent, | |
| const int | grow, | |||
| const xml_node_type | type = node_element, |
|||
| xml_node_struct * | xns_child = NULL | |||
| ) | [inline, static] |
Definition at line 747 of file pugxml.h.
References pug::t_xml_node_struct::child, pug::t_xml_node_struct::child_space, pug::t_xml_node_struct::children, new_node(), and pug::t_xml_node_struct::parent.
Referenced by pug::xml_node::append_child(), pug::xml_node::insert_child(), and pug::xml_parser::parse().
00750 { 00751 if(!parent) 00752 return NULL; //Must have a parent. 00753 00754 if(parent->children == parent->child_space) //Out of pointer space. 00755 { 00756 //Grow pointer space. 00757 xml_node_struct** t = 00758 (xml_node_struct**)realloc(parent->child, 00759 sizeof(xml_node_struct*)*(parent->child_space+grow)); 00760 if(t) //Reallocation succeeded. 00761 { 00762 parent->child = t; 00763 parent->child_space += grow; //Update the available space. 00764 } 00765 else // NF 26 Jun 2003 00766 { 00767 assert( t ); 00768 return NULL; 00769 } 00770 } 00771 xml_node_struct* child = xns_child != NULL ? xns_child : new_node( type ); //Allocate a new child. 00772 child->parent = parent; //Set it's parent pointer. 00773 parent->child[parent->children] = child; //Set the parent's child pointer. 00774 parent->children++; //One more child. 00775 return child; 00776 }
Here is the call graph for this function:

| static bool pug::chartype_close | ( | TCHAR | c | ) | [inline, static] |
Definition at line 355 of file pugxml.h.
References _T.
Referenced by pug::xml_parser::parse().
00356 { return (c==_T('/')); }
| static bool pug::chartype_dash | ( | TCHAR | c | ) | [inline, static] |
Definition at line 363 of file pugxml.h.
References _T.
Referenced by pug::xml_parser::parse().
00364 { return (c==_T('-')); }
| static bool pug::chartype_enter | ( | TCHAR | c | ) | [inline, static] |
Definition at line 351 of file pugxml.h.
References _T.
Referenced by pug::xml_parser::parse().
00352 { return (c==_T('<')); }
| static bool pug::chartype_equals | ( | TCHAR | c | ) | [inline, static] |
Definition at line 357 of file pugxml.h.
References _T.
Referenced by pug::xml_parser::parse().
00358 { return (c==_T('=')); }
| static bool pug::chartype_lbracket | ( | TCHAR | c | ) | [inline, static] |
Definition at line 367 of file pugxml.h.
References _T.
Referenced by pug::xml_parser::parse().
00368 { return (c==_T('[')); }
| static bool pug::chartype_leave | ( | TCHAR | c | ) | [inline, static] |
Definition at line 353 of file pugxml.h.
References _T.
Referenced by pug::xml_parser::parse().
00354 { return (c==_T('>')); }
| static bool pug::chartype_pi | ( | TCHAR | c | ) | [inline, static] |
Definition at line 361 of file pugxml.h.
References _T.
Referenced by pug::xml_parser::parse().
00362 { return (c==_T('?')); }
| static bool pug::chartype_quote | ( | TCHAR | c | ) | [inline, static] |
| static bool pug::chartype_rbracket | ( | TCHAR | c | ) | [inline, static] |
Definition at line 369 of file pugxml.h.
References _T.
Referenced by pug::xml_parser::parse().
00370 { return (c==_T(']')); }
| static bool pug::chartype_space | ( | TCHAR | c | ) | [inline, static] |
Definition at line 349 of file pugxml.h.
References _T.
Referenced by pug::xml_parser::parse().
00350 { return (c>0 && c<_T('!')); }
| static bool pug::chartype_special | ( | TCHAR | c | ) | [inline, static] |
Definition at line 359 of file pugxml.h.
References _T.
Referenced by pug::xml_parser::parse().
00360 { return (c==_T('!')); }
| static bool pug::chartype_symbol | ( | TCHAR | c | ) | [inline, static] |
| static void pug::free_node | ( | xml_node_struct * | node | ) | [inline, static] |
Definition at line 813 of file pugxml.h.
References pug::t_xml_node_struct::attributes, pug::t_xml_node_struct::child, and pug::t_xml_node_struct::children.
Referenced by pug::xml_parser::clear(), pug::xml_node::remove_child(), and pug::xml_parser::~xml_parser().
00814 { 00815 if(!node) return; 00816 00817 /* register */ xml_node_struct* cursor = node; 00818 00819 //Free all children of children. 00820 do 00821 { 00822 LOC_STEP_INTO: 00823 //Free each child in turn; 'children' keeps count while we jump around. 00824 for(; cursor->children>0; --cursor->children) 00825 { 00826 /* register */ xml_node_struct* t = cursor->child[cursor->children-1]; //Take a pointer to the child. 00827 if(t && t->children) //If the child has children. 00828 { 00829 cursor = t; //Step in. 00830 goto LOC_STEP_INTO; //Step into this node. 00831 } 00832 else if(t) 00833 { 00834 if(t->attributes) //Child has attributes. 00835 { 00836 /* register */ unsigned int n = t->attributes; //Free each attribute. 00837 for(/* register */ unsigned int i=0; i<n; ++i) 00838 { 00839 if(t->attribute[i]->name && !t->attribute[i]->name_insitu) 00840 free(t->attribute[i]->name); 00841 if(t->attribute[i]->value && !t->attribute[i]->value_insitu) 00842 free(t->attribute[i]->value); 00843 free(t->attribute[i]); 00844 } 00845 } 00846 if(t->attribute) free(t->attribute); //Free attribute pointer space. 00847 if(t->child) free(t->child); //Free child pointer space. 00848 if(t->name && !t->name_insitu) free(t->name); 00849 if(t->value && !t->value_insitu) free(t->value); 00850 free(t); //Free the child node. 00851 } 00852 } 00853 cursor = cursor->parent; //Step out. 00854 } 00855 while(cursor->children); //While there are children. 00856 //Finally, free the root's children & the root itself. 00857 if(cursor->attributes) 00858 { 00859 /* register */ unsigned int n = cursor->attributes; 00860 for(/* register */ unsigned int i=0; i<n; ++i) 00861 { 00862 if(cursor->attribute[i]->name && !cursor->attribute[i]->name_insitu) 00863 free(cursor->attribute[i]->name); 00864 if(cursor->attribute[i]->value && !cursor->attribute[i]->value_insitu) 00865 free(cursor->attribute[i]->value); 00866 free(cursor->attribute[i]); 00867 } 00868 } 00869 if(cursor->attribute) free(cursor->attribute); //Free attribute pointer space. 00870 if(cursor->child) free(cursor->child); //Free child pointer space. 00871 if(cursor->name && !cursor->name_insitu) free(cursor->name); //Free name & data. 00872 if(cursor->value && !cursor->value_insitu) free(cursor->value); 00873 free(cursor); //Free the root itself. 00874 }
| static void pug::free_node_recursive | ( | xml_node_struct * | root | ) | [inline, static] |
Definition at line 879 of file pugxml.h.
References pug::t_xml_node_struct::attribute, pug::t_xml_node_struct::attributes, pug::t_xml_node_struct::child, pug::t_xml_node_struct::children, pug::t_xml_node_struct::name, pug::t_xml_attribute_struct::name, pug::t_xml_node_struct::name_insitu, pug::t_xml_attribute_struct::name_insitu, pug::t_xml_node_struct::value, pug::t_xml_attribute_struct::value, pug::t_xml_node_struct::value_insitu, and pug::t_xml_attribute_struct::value_insitu.
00880 { 00881 if(root) 00882 { 00883 unsigned int n = root->attributes; 00884 /* register */ unsigned int i; 00885 for(i=0; i<n; i++) 00886 { 00887 if(root->attribute[i]->name && !root->attribute[i]->name_insitu) 00888 free(root->attribute[i]->name); 00889 if(root->attribute[i]->value && !root->attribute[i]->value_insitu) 00890 free(root->attribute[i]->value); 00891 free(root->attribute[i]); 00892 } 00893 free(root->attribute); 00894 n = root->children; 00895 for(i=0; i<n; i++) 00896 free_node_recursive(root->child[i]); 00897 free(root->child); 00898 if(root->name && !root->name_insitu) free(root->name); 00899 if(root->value && !root->value_insitu) free(root->value); 00900 free(root); 00901 } 00902 }
| static unsigned long pug::lib_variant | ( | ) | [inline, static] |
Definition at line 181 of file pugxml.h.
References PUGAPI_INTERNAL_VARIANT.
00181 { return PUGAPI_INTERNAL_VARIANT; }
| static unsigned long pug::lib_version | ( | ) | [inline, static] |
Definition at line 185 of file pugxml.h.
References PUGAPI_INTERNAL_VERSION.
00185 { return PUGAPI_INTERNAL_VERSION; }
| static bool pug::load_file | ( | const TCHAR * | path, | |
| TCHAR ** | buffer, | |||
| unsigned long * | size, | |||
| unsigned long | tempsize = 4096 | |||
| ) | [inline, static] |
Definition at line 930 of file pugxml.h.
References strcatgrow().
Referenced by pug::xml_parser::parse_file().
00932 { 00933 if(!path || !buffer || !size) return false; 00934 *size = 0; 00935 *buffer = 0; 00936 #ifdef WIN32 00937 HANDLE file_handle = CreateFile(path, GENERIC_READ, FILE_SHARE_READ, NULL, 00938 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); 00939 if(file_handle == INVALID_HANDLE_VALUE) return false; 00940 TCHAR* temp = (TCHAR*) malloc(sizeof(TCHAR)*tempsize); 00941 if(!temp) return false; 00942 unsigned long read_bytes = 0; 00943 ZeroMemory(temp,sizeof(TCHAR)*tempsize); 00944 while(ReadFile(file_handle,(void*)temp,tempsize-sizeof(TCHAR),&read_bytes,0) && 00945 read_bytes && strcatgrow(buffer,temp)) { 00946 *size += read_bytes; 00947 ZeroMemory(temp,sizeof(TCHAR)*tempsize); 00948 } 00949 CloseHandle(file_handle); 00950 #else 00951 FILE* fname = fopen(path, "r"); 00952 if(fname == NULL) return false; 00953 00954 clearerr(fname); 00955 TCHAR* temp = (TCHAR*) malloc(sizeof(TCHAR)*tempsize); 00956 if(!temp) return false; 00957 // HARI unsigned long read_bytes = 0; 00958 bzero(temp, sizeof(TCHAR)*tempsize); 00959 size_t read_items = 0; 00960 while(!feof(fname) && !ferror(fname)) { 00961 read_items = fread((void*) temp, sizeof(TCHAR), tempsize-sizeof(TCHAR), fname); 00962 if(read_items > 0 && !ferror(fname)) { 00963 strcatgrow(buffer, temp); 00964 *size += read_items; 00965 bzero(temp, sizeof(TCHAR)*tempsize); 00966 } 00967 } 00968 fclose(fname); 00969 #endif 00970 free(temp); 00971 return (*size) ? true : false; 00972 }
Here is the call graph for this function:

| static xml_attribute_struct* pug::new_attribute | ( | void | ) | [inline, static] |
Definition at line 678 of file pugxml.h.
References pug::t_xml_attribute_struct::name, pug::t_xml_attribute_struct::name_insitu, pug::t_xml_attribute_struct::value, and pug::t_xml_attribute_struct::value_insitu.
Referenced by append_attribute().
00679 { 00680 //Allocate one attribute. 00681 xml_attribute_struct* p = (xml_attribute_struct*)malloc(sizeof(xml_attribute_struct)); 00682 if(p) //If allocation succeeded. 00683 { 00684 p->name = p->value = 0; //No name or value. 00685 #ifdef PUGOPT_NONSEG 00686 p->name_size = p->value_size = 0; //Lengths of zero. 00687 #endif 00688 p->name_insitu = p->value_insitu = true; //Default to being in-situ of the parse string. 00689 } 00690 return p; 00691 }
| static xml_node_struct* pug::new_node | ( | xml_node_type | type = node_element |
) | [inline, static] |
Definition at line 697 of file pugxml.h.
References pug::t_xml_node_struct::attribute, pug::t_xml_node_struct::attribute_space, pug::t_xml_node_struct::attributes, pug::t_xml_node_struct::child, pug::t_xml_node_struct::child_space, pug::t_xml_node_struct::children, pug::t_xml_node_struct::name, pug::t_xml_node_struct::name_insitu, node_cdata, node_comment, node_doctype, node_document, node_element, node_include, node_pcdata, pug::t_xml_node_struct::type, pug::t_xml_node_struct::value, and pug::t_xml_node_struct::value_insitu.
Referenced by append_node(), pug::xml_parser::create(), Tree< T >::insert(), Tree< T >::insert_after(), pug::xml_parser::parse(), and pug::xml_parser::parse_file().
00698 { 00699 xml_node_struct* p = (xml_node_struct*)malloc(sizeof(xml_node_struct)); //Allocate one node. 00700 if(p) //If allocation succeeded. 00701 { 00702 p->name = p->value = 0; //No name or data. 00703 #ifdef PUGOPT_NONSEG 00704 p->name_size = p->value_size = 0; 00705 #endif 00706 p->type = type; //Set the desired type. 00707 p->attributes = p->children = 0; //No attributes or children. 00708 p->name_insitu = p->value_insitu = true; //Default to being in-situ of the parse string. 00709 if 00710 ( 00711 type != node_document && //None of these will have attributes. 00712 type != node_pcdata && 00713 type != node_cdata && 00714 type != node_include && 00715 type != node_comment 00716 ) 00717 //Allocate one attribute. 00718 p->attribute = (xml_attribute_struct**)malloc(sizeof(xml_attribute_struct*)); 00719 else p->attribute = NULL; 00720 p->attribute_space = (p->attribute) ? 1 : 0; 00721 if 00722 ( 00723 type == node_element || //Only these will have children. 00724 type == node_doctype || 00725 type == node_document 00726 ) 00727 p->child = (xml_node_struct**)malloc(sizeof(xml_node_struct*)); //Allocate one child. 00728 else p->child = NULL; 00729 p->child_space = (p->child) ? 1 : 0; 00730 #ifdef PUGOPT_NODE_FLAGS 00731 p->flags = 0x00; // NF 19 Mar 2003 00732 p->set_visible_children( 1 ); // 17 Apr 2003 00733 #endif 00734 } 00735 return p; 00736 }
| static void pug::outer_xml | ( | std::ostream & | os, | |
| indent_stack & | indent, | |||
| xml_node_struct * | node, | |||
| bool | breaks = true | |||
| ) | [inline, static] |
Definition at line 1140 of file pugxml.h.
References _T, pug::t_xml_node_struct::attribute, pug::t_xml_node_struct::attributes, pug::t_xml_node_struct::child, pug::t_xml_node_struct::children, pug::indent_stack::depth(), pug::t_xml_attribute_struct::name, pug::t_xml_node_struct::name, node_cdata, node_comment, node_doctype, node_dtd_attlist, node_dtd_element, node_dtd_entity, node_dtd_notation, node_element, node_include, node_pcdata, node_pi, pug::indent_stack::pop(), pug::indent_stack::push(), pug::t_xml_node_struct::type, pug::t_xml_attribute_struct::value, and pug::t_xml_node_struct::value.
Referenced by pug::xml_node::outer_xml().
01145 { 01146 if(node && os.good()) //There is a node and ostream is OK. 01147 { 01148 /* register */ unsigned int n, i; 01149 os << indent.depth(); 01150 switch(node->type) 01151 { 01152 case node_dtd_attlist: 01153 if(node->name) 01154 { 01155 #ifdef PUGOPT_NONSEG 01156 os << _T("<!ATTLIST "); 01157 os.write( node->name, node->name_size ); 01158 #else 01159 os << _T("<!ATTLIST ") << node->name; 01160 #endif 01161 if(node->value) 01162 #ifdef PUGOPT_NONSEG 01163 { 01164 os << _T(" "); 01165 os.write( node->value, node->value_size ); 01166 } 01167 #else 01168 os << _T(" ") << node->value; 01169 #endif 01170 01171 os << _T(">"); 01172 } 01173 break; 01174 case node_dtd_element: 01175 if(node->name) 01176 { 01177 #ifdef PUGOPT_NONSEG 01178 os << _T("<!ELEMENT "); 01179 os.write( node->name, node->name_size ); 01180 if(node->value) 01181 { 01182 os << _T(" "); 01183 os.write( node->value, node->value_size ); 01184 } 01185 #else 01186 os << _T("<!ELEMENT ") << node->name; 01187 if(node->value) os << _T(" ") << node->value; 01188 #endif 01189 os << _T(">"); 01190 } 01191 break; 01192 case node_dtd_entity: 01193 if(node->name) 01194 { 01195 #ifdef PUGOPT_NONSEG 01196 os << _T("<!ENTITY "); 01197 os.write( node->name, node->name_size ); 01198 if(node->value) 01199 { 01200 os << _T(" "); 01201 os.write( node->value, node->value_size ); 01202 } 01203 #else 01204 os << _T("<!ENTITY ") << node->name; 01205 if(node->value) os << _T(" ") << node->value; 01206 #endif 01207 os << _T(">"); 01208 } 01209 break; 01210 case node_dtd_notation: 01211 if(node->name) 01212 { 01213 #ifdef PUGOPT_NONSEG 01214 os << _T("<!NOTATION "); 01215 os.write( node->name, node->name_size ); 01216 if(node->value) 01217 { 01218 os << _T(" "); 01219 os.write( node->value, node->value_size ); 01220 } 01221 #else 01222 os << _T("<!NOTATION ") << node->name; 01223 if(node->value) os << _T(" ") << node->value; 01224 #endif 01225 os << _T(">"); 01226 } 01227 break; 01228 case node_doctype: 01229 os << _T("<!DOCTYPE"); 01230 n = node->attributes; 01231 for(i=0; i<n; ++i) 01232 { 01233 os << _T(" "); 01234 if(node->attribute[i]->name) 01235 #ifdef PUGOPT_NONSEG 01236 os.write( node->attribute[i]->name, node->attribute[i]->name_size ); 01237 #else 01238 os << node->attribute[i]->name; 01239 #endif 01240 else if(node->attribute[i]->value) 01241 #ifdef PUGOPT_NONSEG 01242 { 01243 os << _T("\""); 01244 os.write( node->attribute[i]->value, node->attribute[i]->value_size ); 01245 os << _T("\""); 01246 } 01247 #else 01248 os << _T("\"") << node->attribute[i]->value << _T("\""); 01249 #endif 01250 } 01251 if(node->children) 01252 { 01253 if(breaks) os << std::endl; 01254 else os << _T(" "); 01255 os << _T("["); 01256 if(breaks) os << std::endl; 01257 else os << _T(" "); 01258 n = node->children; 01259 indent.push(); //Push the indent stack. 01260 for(i=0; i<n; ++i) 01261 { 01262 if 01263 ( 01264 node->child[i] && //There is a child at i. 01265 ( 01266 node->child[i]->type == node_dtd_attlist || //Skip all other types. 01267 node->child[i]->type == node_dtd_element || 01268 node->child[i]->type == node_dtd_entity || 01269 node->child[i]->type == node_dtd_notation 01270 ) 01271 ) 01272 outer_xml(os,indent,node->child[i],breaks); 01273 } 01274 indent.pop(); //Pop the indent stack. 01275 os << _T("]"); 01276 } 01277 else if(node->value) 01278 #ifdef PUGOPT_NONSEG 01279 { 01280 os << _T(" ["); 01281 os.write(node->value,node->value_size); 01282 os << _T("]"); 01283 } 01284 #else 01285 os << _T(" [") << node->value << _T("]"); 01286 #endif 01287 os << _T(">"); 01288 break; 01289 case node_pcdata: 01290 #ifdef PUGOPT_NONSEG 01291 if(node->value) os.write(node->value,node->value_size); 01292 #else 01293 if(node->value) os << node->value; 01294 #endif 01295 break; 01296 case node_cdata: 01297 #ifdef PUGOPT_NONSEG 01298 if(node->value) 01299 { 01300 os << _T("<![CDATA["); 01301 os.write(node->value,node->value_size); 01302 os << _T("]]>"); 01303 } 01304 #else 01305 if(node->value) os << _T("<![CDATA[") << node->value << _T("]]>"); 01306 #endif 01307 break; 01308 case node_include: 01309 #ifdef PUGOPT_NONSEG 01310 if(node->value) 01311 { 01312 os << _T("<![INCLUDE["); 01313 os.write(node->value, node->value_size); 01314 os << _T("]]>"); 01315 } 01316 #else 01317 if(node->value) os << _T("<![INCLUDE[") << node->value << _T("]]>"); 01318 #endif 01319 break; 01320 case node_comment: 01321 #ifdef PUGOPT_NONSEG 01322 if(node->value) 01323 { 01324 os << _T("<!--"); 01325 os.write(node->value, node->value_size); 01326 os << _T("-->"); 01327 } 01328 #else 01329 if(node->value) os << _T("<!--") << node->value << _T("-->"); 01330 #endif 01331 break; 01332 case node_element: 01333 case node_pi: 01334 os << _T("<"); 01335 if(node->type==node_pi) os << _T("?"); 01336 if(node->name) 01337 #ifdef PUGOPT_NONSEG 01338 os.write(node->name,node->name_size); 01339 #else 01340 os << node->name; 01341 #endif 01342 else os << _T("anonymous"); 01343 n = node->attributes; 01344 for(i=0; i<n; ++i) 01345 { 01346 if(node->attribute[i] && node->attribute[i]->name) 01347 { 01348 #ifdef PUGOPT_NONSEG 01349 os << _T(" "); 01350 os.write(node->attribute[i]->name,node->attribute[i]->name_size); 01351 if(node->attribute[i]->value) 01352 { 01353 os << _T("=\""); 01354 os.write(node->attribute[i]->value,node->attribute[i]->value_size); 01355 os << _T("\""); 01356 } 01357 #else 01358 os << _T(" ") << node->attribute[i]->name; 01359 if(node->attribute[i]->value) os << _T("=\"") << node->attribute[i]->value << _T("\""); 01360 #endif 01361 } 01362 } 01363 n = node->children; 01364 if(n && node->type == node_element) 01365 { 01366 os << _T(">"); 01367 if(n == 1 && node->child[0]->type == node_pcdata) 01368 { 01369 if(node->child[0] && node->child[0]->value) 01370 #ifdef PUGOPT_NONSEG 01371 os.write(node->child[0]->value,node->child[0]->value_size); 01372 #else 01373 os << node->child[0]->value; 01374 #endif 01375 } 01376 else 01377 { 01378 if(breaks) os << std::endl; 01379 indent.push(); 01380 for(i=0; i<n; ++i) pug::outer_xml(os,indent,node->child[i],breaks); 01381 indent.pop(); 01382 os << indent.depth(); 01383 } 01384 os << _T("</"); 01385 #ifdef PUGOPT_NONSEG 01386 if(node->name) 01387 os.write(node->name, node->name_size); 01388 #else 01389 if(node->name) os << node->name; 01390 #endif 01391 os << _T(">"); 01392 } 01393 else 01394 { 01395 if(node->type==node_pi) os << _T("?>"); 01396 else os << _T("/>"); 01397 } 01398 break; 01399 default: break; 01400 } 01401 if(breaks) os << std::endl; 01402 os.flush(); 01403 } 01404 }
Here is the call graph for this function:

| static bool pug::strcatgrow | ( | TCHAR ** | lhs, | |
| const TCHAR * | rhs | |||
| ) | [inline, static] |
Definition at line 329 of file pugxml.h.
References _tcslen.
Referenced by pug::xml_node::append_attribute(), pug::xml_node::first_element_by_path(), load_file(), pug::xml_node::path(), and strcpyinsitu().
00330 { 00331 if(!*lhs) //Null, so first allocate. 00332 { 00333 *lhs = (TCHAR*) malloc(1UL*sizeof(TCHAR)); 00334 **lhs = 0; //Zero-terminate. 00335 } 00336 size_t ulhs = _tcslen(*lhs); 00337 size_t urhs = _tcslen(rhs); 00338 TCHAR* temp = (TCHAR*) realloc(*lhs,(ulhs+urhs+1UL)*sizeof(TCHAR)); 00339 if(!temp) return false; //Realloc failed. 00340 memcpy(temp+ulhs,rhs,urhs*sizeof(TCHAR)); //Concatenate. 00341 temp[ulhs+urhs] = 0; //Terminate it. 00342 *lhs = temp; 00343 return true; 00344 }
| int pug::strcmpwild | ( | const TCHAR * | src, | |
| const TCHAR * | dst | |||
| ) | [inline] |
Definition at line 669 of file pugxml.h.
References strcmpwild_impl().
Referenced by pug::xml_node::has_name(), pug::xml_node::matches_attribute_name(), pug::t_xml_attribute_struct::matches_attribute_name_value(), pug::xml_node::matches_child_name(), pug::xml_node::matches_name(), pug::xml_node::matches_value(), pug::xml_node::moveto_child(), and pug::xml_node::moveto_first_sibling().
00670 { 00671 if(!src || !dst) return -1; 00672 return (strcmpwild_impl(src,dst)==1)?0:1; 00673 }
Here is the call graph for this function:

| int pug::strcmpwild_astr | ( | const TCHAR ** | src, | |
| const TCHAR ** | dst | |||
| ) | [inline] |
Definition at line 605 of file pugxml.h.
References _T, and strcmpwild_impl().
Referenced by strcmpwild_impl().
00606 { 00607 int find = 1; 00608 ++(*src); 00609 while((**dst != 0 && **src == _T('?')) || **src == _T('*')) 00610 { 00611 if(**src == _T('?')) ++(*dst); 00612 ++(*src); 00613 } 00614 while(**src == _T('*')) ++(*src); 00615 if(**dst == 0 && **src != 0) return 0; 00616 if(**dst == 0 && **src == 0) return 1; 00617 else 00618 { 00619 if(strcmpwild_impl(*src,*dst) == 0) 00620 { 00621 do 00622 { 00623 ++(*dst); 00624 while(**src != **dst && **src != _T('[') && **dst != 0) 00625 ++(*dst); 00626 } 00627 while((**dst != 0) ? strcmpwild_impl(*src,*dst) == 0 : 0 != (find=0)); 00628 } 00629 if(**dst == 0 && **src == 0) find = 1; 00630 return find; 00631 } 00632 }
Here is the call graph for this function:

| int pug::strcmpwild_cset | ( | const TCHAR ** | src, | |
| const TCHAR ** | dst | |||
| ) | [inline] |
Definition at line 565 of file pugxml.h.
References _T.
Referenced by strcmpwild_impl().
00566 { 00567 int find = 0; 00568 int excl = 0; 00569 int star = 1; 00570 if(**src == _T('!')) 00571 { 00572 excl = 1; 00573 ++(*src); 00574 } 00575 while(**src != _T(']') || star == 1) 00576 { 00577 if(find == 0) 00578 { 00579 if(**src == _T('-') && *(*src-1) < *(*src+1) && *(*src+1) != _T(']') && star == 0) 00580 { 00581 if(**dst >= *(*src-1) && **dst <= *(*src+1)) 00582 { 00583 find = 1; 00584 ++(*src); 00585 } 00586 } 00587 else if(**src == **dst) find = 1; 00588 } 00589 ++(*src); 00590 star = 0; 00591 } 00592 if(excl == 1) find = (1 - find); 00593 if(find == 1) ++(*dst); 00594 return find; 00595 }
| int pug::strcmpwild_impl | ( | const TCHAR * | src, | |
| const TCHAR * | dst | |||
| ) | [inline] |
Definition at line 639 of file pugxml.h.
References _T, strcmpwild_astr(), and strcmpwild_cset().
Referenced by strcmpwild(), and strcmpwild_astr().
00640 { 00641 int find = 1; 00642 for(; *src != 0 && find == 1 && *dst != 0; ++src) 00643 { 00644 switch(*src) 00645 { 00646 case _T('?'): ++dst; break; 00647 case _T('['): ++src; find = strcmpwild_cset(&src,&dst); break; 00648 case _T('*'): find = strcmpwild_astr(&src,&dst); --src; break; 00649 default : find = (int) (*src == *dst); ++dst; 00650 } 00651 } 00652 while(*src == _T('*') && find == 1) ++src; 00653 return (int) (find == 1 && *dst == 0 && *src == 0); 00654 }
Here is the call graph for this function:

| static bool pug::strcpyinsitu | ( | TCHAR ** | dest, | |
| const TCHAR * | src, | |||
| bool * | insitu | |||
| ) | [inline, static] |
Definition at line 524 of file pugxml.h.
References _tcscpy, _tcslen, strcatgrow(), and TRUE.
Referenced by pug::xml_node::name(), pug::xml_attribute::name(), pug::xml_node::value(), and pug::xml_attribute::value().
00533 { 00534 if(!dest || !src || !insitu) return false; //Bad argument(s), so fail. 00535 #ifndef PUGOPT_NONSEG //Always use heap for our r/o string. 00536 size_t l = (*dest) ? _tcslen(*dest) : 0; //How long is destination? 00537 if(l >= _tcslen(src)) //Destination is large enough, so just copy. 00538 { 00539 _tcscpy(*dest,src); //Copy. 00540 return TRUE; //Success. 00541 } 00542 else //Destination is too small. 00543 #endif 00544 { 00545 if(*dest && !*insitu) free(*dest); //If destination is not in-situ, then free it. 00546 *dest = NULL; //Mark destination as NULL, forcing 'StrCatGrow' to 'malloc. 00547 #ifdef PUGOPT_NONSEG 00548 if(strcatgrown(dest,src,destlen)) //Allocate & copy source to destination 00549 #else 00550 if(strcatgrow(dest,src)) //Allocate & copy source to destination 00551 #endif 00552 { 00553 *insitu = false; //Mark as no longer being in-situ, so we can free it later. 00554 return TRUE; //Success. 00555 } 00556 } 00557 return false; //Failure. 00558 }
Here is the call graph for this function:

| static bool pug::strwnorm | ( | TCHAR ** | s | ) | [inline, static] |
Definition at line 470 of file pugxml.h.
References _T, _tcsncpy, and claraty::norm().
Referenced by pug::xml_parser::parse().
00471 { 00472 if(!s || !*s) return false; //No string to normalize. 00473 while(**s > 0 && **s < _T('!')) ++(*s); //As long as we hit whitespace, increment the string pointer. 00474 const TCHAR* temp = *s; 00475 while(0 != *temp++); //Find the terminating null. 00476 long n = (long)(temp-*s-1); 00477 TCHAR* norm = (TCHAR*)malloc(sizeof(TCHAR)*(n+1)); //Allocate a temporary normalization buffer. 00478 if(!norm) return false; //Allocation failed. 00479 memset(norm,0,sizeof(TCHAR)*(n+1)); //Zero it. 00480 long j = 1; 00481 long i; 00482 norm[0] = (*s)[0]; 00483 for(i=1; i<n; ++i) //For each character, starting at offset 1. 00484 { 00485 if((*s)[i] < _T('!')) //Whitespace-like. 00486 { 00487 if((*s)[i-1] >= _T('!')) //Previous was not whitespace-like. 00488 { 00489 norm[j] = _T(' '); //Convert to a space TCHAR. 00490 ++j; //Normalization buffer grew by one TCHAR. 00491 } 00492 } 00493 else { norm[j] = (*s)[i]; ++j; } //Not whitespace, so just copy over. 00494 } 00495 if(j < n) //Normalization buffer is actually different that input. 00496 { 00497 _tcsncpy(*s,norm,j); //So, copy it back to input. 00498 (*s)[j] = 0; //Zero-terminate. 00499 } 00500 free(norm); //Don't need this anymore. 00501 --n; //Start from the last string TCHAR. 00502 for(i=n; (i > -1) && (*s)[i] > 0 && (*s)[i] < _T('!'); --i); //Find the first non-whitespace from the end. 00503 if(i<n) (*s)[i+1] = 0; //Truncate it. 00504 return true; 00505 00506 }
Here is the call graph for this function:

| static bool pug::strwtrim | ( | TCHAR ** | s | ) | [inline, static] |
Definition at line 450 of file pugxml.h.
References _T.
Referenced by pug::xml_parser::parse().
00451 { 00452 if(!s || !*s) return false; 00453 while(**s > 0 && **s < _T('!')) ++*s; //As long as we hit whitespace, increment the string pointer. 00454 const TCHAR* temp = *s; 00455 while(0 != *temp++); //Find the terminating null. 00456 long i, n = (long)(temp-*s-1); 00457 --n; //Start from the last string TCHAR. 00458 for(i=n; (i > -1) && (*s)[i] > 0 && (*s)[i] < _T('!'); --i); //As long as we hit whitespace, decrement. 00459 if(i<n) (*s)[i+1] = 0; //Zero-terminate. 00460 return true; 00461 }
Variable Documentation
const unsigned long pug::parse_cdata = 0x00000010 [static] |
const unsigned long pug::parse_comments = 0x00000008 [static] |
Definition at line 241 of file pugxml.h.
Referenced by claraty::Parameter_Parser::Parameter_Parser(), and pug::xml_parser::parse().
const unsigned long pug::parse_default = 0x0000FFFF [static] |
const unsigned long pug::parse_doctype = 0x00000004 [static] |
Definition at line 240 of file pugxml.h.
Referenced by claraty::Parameter_Parser::Parameter_Parser(), and pug::xml_parser::parse().
const unsigned long pug::parse_dtd = 0x00002000 [static] |
const unsigned long pug::parse_dtd_only = 0x00004000 [static] |
const unsigned long pug::parse_escapes = 0x00000020 [static] |
const unsigned long pug::parse_grow = 4 [static] |
const unsigned long pug::parse_minimal = 0x00000000 [static] |
const unsigned long pug::parse_noset = 0x80000000 [static] |
Definition at line 254 of file pugxml.h.
Referenced by pug::xml_parser::parse(), and pug::xml_parser::parse_file().
const unsigned long pug::parse_pi = 0x00000002 [static] |
Definition at line 239 of file pugxml.h.
Referenced by claraty::Parameter_Parser::Parameter_Parser(), and pug::xml_parser::parse().
const unsigned long pug::parse_trim_attribute = 0x00000080 [static] |
Definition at line 245 of file pugxml.h.
Referenced by claraty::Parameter_Parser::Parameter_Parser(), and pug::xml_parser::parse().
const unsigned long pug::parse_trim_cdata = 0x00000100 [static] |
const unsigned long pug::parse_trim_comment = 0x00000800 [static] |
Definition at line 249 of file pugxml.h.
Referenced by claraty::Parameter_Parser::Parameter_Parser(), and pug::xml_parser::parse().
const unsigned long pug::parse_trim_doctype = 0x00000400 [static] |
const unsigned long pug::parse_trim_entity = 0x00000200 [static] |
const unsigned long pug::parse_trim_pcdata = 0x00000040 [static] |
Definition at line 244 of file pugxml.h.
Referenced by claraty::Parameter_Parser::Parameter_Parser(), and pug::xml_parser::parse().
const unsigned long pug::parse_wnorm = 0x00001000 [static] |
Definition at line 250 of file pugxml.h.
Referenced by claraty::Parameter_Parser::Parameter_Parser(), pug::xml_parser::parse(), and pug::xml_parser::parse_file().