slexpat-0.5.0/0000755000175000017500000000000010745703452011667 5ustar paulpaulslexpat-0.5.0/Makefile0000644000175000017500000000522310745703342013327 0ustar paulpaul#--------------------------------------------------------------------------- # Installation Directories #--------------------------------------------------------------------------- prefix = /usr/local exec_prefix = ${prefix} MODULE_INSTALL_DIR = ${exec_prefix}/lib/slang/v2/modules SL_FILES_INSTALL_DIR = ${prefix}/share/slsh/local-packages HLP_FILES_INSTALL_DIR = $(SL_FILES_INSTALL_DIR)/help #--------------------------------------------------------------------------- # DESTDIR is designed to facilitate making packages. Normally it is empty #--------------------------------------------------------------------------- DESTDIR = DEST_MODULE_INSTALL_DIR = $(DESTDIR)$(MODULE_INSTALL_DIR) DEST_SL_FILES_INSTALL_DIR = $(DESTDIR)$(SL_FILES_INSTALL_DIR) DEST_HLP_FILES_INSTALL_DIR = $(DESTDIR)$(HLP_FILES_INSTALL_DIR) #--------------------------------------------------------------------------- # Location of the S-Lang library and its include file #--------------------------------------------------------------------------- SLANG_INC = -I/usr/local/include SLANG_LIB = -L/usr/local/lib -lslang #--------------------------------------------------------------------------- # C Compiler to create a shared library #--------------------------------------------------------------------------- CC_SHARED = $(CC) $(CFLAGS) -shared -Wall -fPIC #--------------------------------------------------------------------------- # Misc Programs required for installation #--------------------------------------------------------------------------- INSTALL = /usr/bin/install -m 644 MKINSDIR = /usr/bin/install -d #--------------------------------------------------------------------------- # You shouldn't need to edit anything below this line #--------------------------------------------------------------------------- LIBS = $(SLANG_LIB) -lm -lexpat INCS = $(SLANG_INC) all: expat-module.so expat-module.so: expat-module.c $(CC_SHARED) $(INCS) expat-module.c -o expat-module.so $(LIBS) expat.hlp: expatfuns.tm tmexpand -Mslhlp expatfuns.tm expat.hlp clean: rm -f expat-module.so *.o #--------------------------------------------------------------------------- # Installation Rules #--------------------------------------------------------------------------- install_directories: $(MKINSDIR) $(DEST_MODULE_INSTALL_DIR) $(MKINSDIR) $(DEST_SL_FILES_INSTALL_DIR) $(MKINSDIR) $(DEST_HLP_FILES_INSTALL_DIR) install_modules: $(INSTALL) expat-module.so $(DEST_MODULE_INSTALL_DIR) install_slfiles: $(INSTALL) expat.sl $(DEST_SL_FILES_INSTALL_DIR) install_hlpfiles: $(INSTALL) expat.hlp $(DEST_HLP_FILES_INSTALL_DIR) install: all install_directories install_modules install_slfiles install_hlpfiles slexpat-0.5.0/CHANGES0000644000175000017500000000041111020510130012626 0ustar paulpaulChanges since 0.4.0 1. Fixed two double free bugs (John E. Davis) 2. Removed some useless SLang_free_mmt calls Changes since 0.3.0 1. Use SLerr_throw to throw the expat object with exceptions 2. Use void argument in functions that take no arguments (John E. Davis) slexpat-0.5.0/COPYING0000644000175000017500000004312710745703342012727 0ustar paulpaul GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19yy name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Library General Public License instead of this License. slexpat-0.5.0/expat.sl0000644000175000017500000000024710745703342013351 0ustar paulpaulimport ("expat"); $1 = path_concat (path_concat (path_dirname (__FILE__), "help"), "expat.hlp"); if (NULL != stat_file ($1)) add_doc_file ($1); provide ("expat"); slexpat-0.5.0/outline.sl0000755000175000017500000000162710745703342013715 0ustar paulpaul#!/usr/bin/env slsh require("expat"); define startElement(p, name, atts) { variable i; ()=printf("%*s%s\n", p.userdata, "", name); foreach i (atts) { ()=printf("%*s%s=%s;\n", p.userdata, "", i.name, i.value); } p.userdata++; } define endElement (p, name) { p.userdata--; } define slsh_main() { !if (__argc) { () = fprintf (stderr, "Usage: %s [xml file]\n", __argv[0]); exit (1); } variable file = __argv[1]; variable xml_parser = xml_new(); variable data; xml_set_user_data(xml_parser, 0); xml_parser.startelementhandler = &startElement; xml_parser.endelementhandler = &endElement; variable fp = fopen(file, "r"); if (fp == NULL) verror("could not open XML input"); while (-1 != fread_bytes(&data, 4096, fp)) xml_parse(xml_parser, data, feof(fp)); } slexpat-0.5.0/expat-module.c0000644000175000017500000006706711020510065014436 0ustar paulpaul/* expat-module.c * S-Lang bindings for the expat library. * This was tested with expat versions 1.95.8 and 2.0. * * $Id: expat-module.c,v 1.6 2008/06/01 12:02:34 paul Exp paul $ * * Copyright (c) 2006-2008 Paul Boekholt. * Released under the terms of the GNU GPL (version 2 or later). */ #include #include #include SLANG_MODULE(expat); #define MODULE_MAJOR_VERSION 0 #define MODULE_MINOR_VERSION 5 #define MODULE_PATCH_LEVEL 0 static char *Module_Version_String = "0.5.0"; #define MODULE_VERSION_NUMBER \ (MODULE_MAJOR_VERSION*10000+MODULE_MINOR_VERSION*100+MODULE_PATCH_LEVEL) /*{{{ expat type */ static int Expat_Type_Id=0; typedef struct { XML_Parser p; SLang_MMT_Type *mmt; /* parent MMT */ SLang_Any_Type *userdata; SLang_Name_Type *startelement_callback; SLang_Name_Type *endelement_callback; SLang_Name_Type *characterdata_callback; SLang_Name_Type *default_callback; SLang_Name_Type *startnamespacedecl_callback; SLang_Name_Type *endnamespacedecl_callback; } expat_type; #define DUMMY_EXPAT_TYPE 255 static void free_expat_type (expat_type *pt) { XML_ParserFree(pt->p); SLang_free_anytype(pt->userdata); /* SLang_free_function is just a placeholder for SLang 3 */ SLfree ((char *)pt); } static SLang_MMT_Type *allocate_expat_type (XML_Parser p) { expat_type *pt; SLang_MMT_Type *mmt; pt = (expat_type *) SLmalloc (sizeof (expat_type)); if (pt == NULL) return NULL; memset ((char *) pt, 0, sizeof (expat_type)); pt->p = p; if (NULL == (mmt = SLang_create_mmt (Expat_Type_Id, (VOID_STAR) pt))) { free_expat_type (pt); return NULL; } pt->mmt = mmt; return mmt; } static void destroy_expat (SLtype type, VOID_STAR f) { (void) type; free_expat_type ((expat_type *) f); } /*}}}*/ /*{{{ exceptions*/ static int Expat_Error = 0; static int XML_No_Memory_Error, XML_Syntax_Error, XML_No_Elements_Error, XML_Invalid_Token_Error, XML_Unclosed_Token_Error, XML_Partial_Char_Error, XML_Tag_Mismatch_Error, XML_Duplicate_Attribute_Error, XML_Junk_After_Doc_Element_Error, XML_Param_Entity_Ref_Error, XML_Undefined_Entity_Error, XML_Recursive_Entity_Ref_Error, XML_Async_Entity_Error, XML_Bad_Char_Ref_Error, XML_Binary_Entity_Ref_Error, XML_Attribute_External_Entity_Ref_Error, XML_Misplaced_Xml_Pi_Error, XML_Unknown_Encoding_Error, XML_Incorrect_Encoding_Error, XML_Unclosed_Cdata_Section_Error, XML_External_Entity_Handling_Error, XML_Not_Standalone_Error, XML_Unexpected_State_Error, XML_Entity_Declared_In_Pe_Error, XML_Feature_Requires_Xml_Dtd_Error, XML_Cant_Change_Feature_Once_Parsing_Error, XML_Unbound_Prefix_Error, XML_Undeclaring_Prefix_Error, XML_Incomplete_Pe_Error, XML_Xml_Decl_Error, XML_Text_Decl_Error, XML_Publicid_Error, XML_Suspended_Error, XML_Not_Suspended_Error, XML_Aborted_Error, XML_Finished_Error, XML_Suspend_Pe_Error; typedef struct { int error_code; int *errcode_ptr; char *name; char *description; } Expat_Exception_Table_Type; static const Expat_Exception_Table_Type Expat_Exception_Table [] = { { XML_ERROR_NO_MEMORY, &XML_No_Memory_Error, "ExpatNoMemoryError", "out of memory"}, { XML_ERROR_SYNTAX, &XML_Syntax_Error, "ExpatSyntaxError", "syntax error"}, { XML_ERROR_NO_ELEMENTS, &XML_No_Elements_Error, "ExpatNoElementsError", "no element found"}, { XML_ERROR_INVALID_TOKEN, &XML_Invalid_Token_Error, "ExpatInvalidTokenError", "not well-formed (invalid token)"}, { XML_ERROR_UNCLOSED_TOKEN, &XML_Unclosed_Token_Error, "ExpatUnclosedTokenError", "unclosed token"}, { XML_ERROR_PARTIAL_CHAR, &XML_Partial_Char_Error, "ExpatPartialCharError", "partial character"}, { XML_ERROR_TAG_MISMATCH, &XML_Tag_Mismatch_Error, "ExpatTagMismatchError", "mismatched tag"}, { XML_ERROR_DUPLICATE_ATTRIBUTE, &XML_Duplicate_Attribute_Error, "ExpatDuplicateAttributeError", "duplicate attribute"}, { XML_ERROR_JUNK_AFTER_DOC_ELEMENT, &XML_Junk_After_Doc_Element_Error, "ExpatJunkAfterDocElementError", "junk after document element"}, { XML_ERROR_PARAM_ENTITY_REF, &XML_Param_Entity_Ref_Error, "ExpatParamEntityRefError", "illegal parameter entity reference"}, { XML_ERROR_UNDEFINED_ENTITY, &XML_Undefined_Entity_Error, "ExpatUndefinedEntityError", "undefined entity"}, { XML_ERROR_RECURSIVE_ENTITY_REF, &XML_Recursive_Entity_Ref_Error, "ExpatRecursiveEntityRefError", "recursive entity reference"}, { XML_ERROR_ASYNC_ENTITY, &XML_Async_Entity_Error, "ExpatAsyncEntityError", "asynchronous entity"}, { XML_ERROR_BAD_CHAR_REF, &XML_Bad_Char_Ref_Error, "ExpatBadCharRefError", "reference to invalid character number"}, { XML_ERROR_BINARY_ENTITY_REF, &XML_Binary_Entity_Ref_Error, "ExpatBinaryEntityRefError", "reference to binary entity"}, { XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF, &XML_Attribute_External_Entity_Ref_Error, "ExpatAttributeExternalEntityRefError", "reference to external entity in attribute"}, { XML_ERROR_MISPLACED_XML_PI, &XML_Misplaced_Xml_Pi_Error, "ExpatMisplacedXmlPiError", "XML or text declaration not at start of entity"}, { XML_ERROR_UNKNOWN_ENCODING, &XML_Unknown_Encoding_Error, "ExpatUnknownEncodingError", "unknown encoding"}, { XML_ERROR_INCORRECT_ENCODING, &XML_Incorrect_Encoding_Error, "ExpatIncorrectEncodingError", "encoding specified in XML declaration is incorrect"}, { XML_ERROR_UNCLOSED_CDATA_SECTION, &XML_Unclosed_Cdata_Section_Error, "ExpatUnclosedCdataSectionError", "unclosed CDATA section"}, { XML_ERROR_EXTERNAL_ENTITY_HANDLING, &XML_External_Entity_Handling_Error, "ExpatExternalEntityHandlingError", "error in processing external entity reference"}, { XML_ERROR_NOT_STANDALONE, &XML_Not_Standalone_Error, "ExpatNotStandaloneError", "document is not standalone"}, { XML_ERROR_UNEXPECTED_STATE, &XML_Unexpected_State_Error, "ExpatUnexpectedStateError", "unexpected parser state - please send a bug report"}, { XML_ERROR_ENTITY_DECLARED_IN_PE, &XML_Entity_Declared_In_Pe_Error, "ExpatEntityDeclaredInPeError", "entity declared in parameter entity"}, { XML_ERROR_FEATURE_REQUIRES_XML_DTD, &XML_Feature_Requires_Xml_Dtd_Error, "ExpatFeatureRequiresXmlDtdError", "requested feature requires XML_DTD support in Expat"}, { XML_ERROR_CANT_CHANGE_FEATURE_ONCE_PARSING, &XML_Cant_Change_Feature_Once_Parsing_Error, "ExpatCantChangeFeatureOnceParsingError", "cannot change setting once parsing has begun"}, { XML_ERROR_UNBOUND_PREFIX, &XML_Unbound_Prefix_Error, "ExpatUnboundPrefixError", "unbound prefix"}, { XML_ERROR_UNDECLARING_PREFIX, &XML_Undeclaring_Prefix_Error, "ExpatUndeclaringPrefixError", "must not undeclare prefix"}, { XML_ERROR_INCOMPLETE_PE, &XML_Incomplete_Pe_Error, "ExpatIncompletePeError", "incomplete markup in parameter entity"}, { XML_ERROR_XML_DECL, &XML_Xml_Decl_Error, "ExpatXmlDeclError", "XML declaration not well-formed"}, { XML_ERROR_TEXT_DECL, &XML_Text_Decl_Error, "ExpatTextDeclError", "text declaration not well-formed"}, { XML_ERROR_PUBLICID, &XML_Publicid_Error, "ExpatPublicidError", "illegal character(s) in public id"}, { XML_ERROR_SUSPENDED, &XML_Suspended_Error, "ExpatSuspendedError", "parser suspended"}, { XML_ERROR_NOT_SUSPENDED, &XML_Not_Suspended_Error, "ExpatNotSuspendedError", "parser not suspended"}, { XML_ERROR_ABORTED, &XML_Aborted_Error, "ExpatAbortedError", "parsing aborted"}, { XML_ERROR_FINISHED, &XML_Finished_Error, "ExpatFinishedError", "parsing finished"}, { XML_ERROR_SUSPEND_PE, &XML_Suspend_Pe_Error, "ExpatSuspendPeError", "cannot suspend in external parameter entity"}, { XML_ERROR_NONE, 0, 0, 0} }; static int translate_error (int error_code) { const Expat_Exception_Table_Type *b; if (error_code == XML_ERROR_NONE) return 0; b = Expat_Exception_Table; while (b->errcode_ptr != NULL) { if (b->error_code == error_code) break; b++; } if (b->errcode_ptr == NULL) return Expat_Error; else return *(b->errcode_ptr); } static int check_error (XML_Parser p, SLang_MMT_Type *mmt) { int error_code; int error; error_code = XML_GetErrorCode(p); if ((error = translate_error(error_code))) { SLerr_throw(error, (char *) XML_ErrorString(error_code), Expat_Type_Id, &mmt); return 1; } return 0; } /*}}}*/ /*{{{ parser creation */ static void slxml_new(void) { SLang_MMT_Type *mmt; XML_Parser p; expat_type *parser; if (NULL == (p = XML_ParserCreate(NULL)) || (NULL == (mmt = allocate_expat_type (p)))) { SLang_verror (SL_RunTime_Error, "xml_new failed"); XML_ParserFree(p); return; } parser = SLang_object_from_mmt (mmt); XML_SetUserData(p, (void *)parser); if (-1 == SLang_push_mmt (mmt)) { SLang_free_mmt (mmt); (void) SLang_push_null(); } } static void slxml_new_ns(const char *sep) { SLang_MMT_Type *mmt; XML_Parser p; expat_type *parser; if (NULL == (p = XML_ParserCreateNS(NULL, *sep)) || (NULL == (mmt = allocate_expat_type (p)))) { SLang_verror (SL_RunTime_Error, "xml_new_ns failed"); XML_ParserFree(p); return; } parser = SLang_object_from_mmt (mmt); XML_SetUserData(p, (void *)parser); if (-1 == SLang_push_mmt (mmt)) { SLang_free_mmt (mmt); (void) SLang_push_null(); } } /*}}}*/ /*{{{ parsing */ static void slxml_parse(const char *s, int *isfinal) { expat_type *parser; SLang_MMT_Type *mmt; if (NULL == (mmt = SLang_pop_mmt (Expat_Type_Id))) { return; } parser = SLang_object_from_mmt (mmt); if (XML_STATUS_OK != XML_Parse(parser->p, s, strlen(s), *isfinal)) { check_error(parser->p, mmt); } SLang_free_mmt (mmt); } static void slxml_stop_parser(int *resumable) { expat_type *parser; SLang_MMT_Type *mmt; if (NULL == (mmt = SLang_pop_mmt (Expat_Type_Id))) { return; } parser = SLang_object_from_mmt (mmt); if (XML_STATUS_OK != XML_StopParser(parser->p, *resumable)) { check_error(parser->p, mmt); } SLang_free_mmt (mmt); } static void slxml_resume_parser (void) { expat_type *parser; SLang_MMT_Type *mmt; if (NULL == (mmt = SLang_pop_mmt (Expat_Type_Id))) { return; } parser = SLang_object_from_mmt (mmt); if (XML_STATUS_OK != XML_ResumeParser(parser->p)) { check_error(parser->p, mmt); } SLang_free_mmt (mmt); } /*}}}*/ /*{{{ userdata */ static void slxml_setuserdata(void) { SLang_MMT_Type *mmt; expat_type *parser; SLang_Any_Type *userdata; (void) SLang_pop_anytype (&userdata); if (NULL == (mmt = SLang_pop_mmt (Expat_Type_Id))) { return; } parser = SLang_object_from_mmt (mmt); SLang_free_anytype (parser->userdata); parser->userdata = NULL; parser->userdata = userdata; } static void slxml_getuserdata(void) { SLang_MMT_Type *mmt; expat_type *parser; if (NULL == (mmt = SLang_pop_mmt (Expat_Type_Id))) { SLang_push_null(); return; } parser = SLang_object_from_mmt (mmt); (void) SLang_push_anytype (parser->userdata); } /*}}}*/ /*{{{ callbacks */ /*{{{ startelementhandler */ /*{{{ attribute structure */ typedef struct { const char *name; const char *value; } Attribute_Type; static SLang_CStruct_Field_Type Attribute_Type_Layout [] = { MAKE_CSTRUCT_FIELD(Attribute_Type, name, "name", SLANG_STRING_TYPE, 0), MAKE_CSTRUCT_FIELD(Attribute_Type, value, "value", SLANG_STRING_TYPE, 0), SLANG_END_CSTRUCT_TABLE }; static int push_attributes (const char **attributes) { SLindex_Type size; SLang_Array_Type *at; SLang_Struct_Type *st; int ww; const char **attribute = attributes; for (size = 0; *attribute; size++) attribute +=2; if (NULL == (at = SLang_create_array (SLANG_STRUCT_TYPE, 0, NULL, &size, 1))) return -1; attribute = attributes; for (ww = 0; ww < size; ww++) { /* Is this correct? */ Attribute_Type si; si.name = *attribute; attribute++; si.value = *attribute; attribute++; if ((-1 == SLang_push_cstruct ((VOID_STAR)&si, Attribute_Type_Layout)) || (-1 == SLang_pop_struct (&st)) || (-1 == SLang_set_array_element (at, &ww, &st))) { SLang_free_array (at); return -1; } SLang_free_struct(st); } return SLang_push_array(at,1); } /*}}}*/ static void startelementhandler(void *userData, const char *name, const char **atts) { if ((-1 == SLang_start_arg_list ()) || (-1 == SLang_push_mmt(((expat_type *)userData)->mmt)) || (-1 == SLang_push_string ((char *)name)) || (-1 == push_attributes(atts)) || (-1 == SLang_end_arg_list ())) { SLang_verror(SL_RunTime_Error, "startelementhandler failed"); XML_StopParser(((expat_type *)userData)->p, XML_FALSE); return; } (void) SLexecute_function (((expat_type *)userData)->startelement_callback); if (SLang_get_error()) { XML_StopParser(((expat_type *)userData)->p, XML_FALSE); } } static int pop_function_or_null(SLang_Name_Type **func) { if (SLang_peek_at_stack () == SLANG_NULL_TYPE) { (void) SLang_pop_null (); *func = NULL; } else if (NULL == (*func = SLang_pop_function ())) return 0; return 1; } static void slxml_set_start_element_handler (void) { SLang_MMT_Type *mmt; expat_type *parser; SLang_Name_Type *func; if (!pop_function_or_null(&func)) return; if (NULL == (mmt = SLang_pop_mmt (Expat_Type_Id))) { return; } parser = SLang_object_from_mmt (mmt); parser->startelement_callback = func; XML_SetStartElementHandler(parser->p, (func ? startelementhandler : NULL)); } /*}}}*/ /*{{{ endelementhandler */ static void endelementhandler(void *userData, const char *name) { if ((-1 == SLang_start_arg_list ()) || (-1 == SLang_push_mmt(((expat_type *)userData)->mmt)) || (-1 == SLang_push_string ((char *)name)) || (-1 == SLang_end_arg_list ())) { SLang_verror(SL_RunTime_Error, "endelementhandler failed"); XML_StopParser(((expat_type *)userData)->p, XML_FALSE); return; } (void) SLexecute_function (((expat_type *)userData)->endelement_callback); if (SLang_get_error()) { XML_StopParser(((expat_type *)userData)->p, XML_FALSE); } } static void slxml_set_end_element_handler (void) { SLang_MMT_Type *mmt; expat_type *parser; SLang_Name_Type *func; if (!pop_function_or_null(&func)) return; if (NULL == (mmt = SLang_pop_mmt (Expat_Type_Id))) { return; } parser = SLang_object_from_mmt (mmt); parser->endelement_callback = func; XML_SetEndElementHandler(parser->p, (func ? endelementhandler : NULL)); } /*}}}*/ /*{{{ characterdata handler */ static void characterdatahandler(void *userData, const char *s, const int len) { char *str; if ((-1 == SLang_start_arg_list ()) || (NULL == (str = SLang_create_nslstring ((char *)s, len))) || (-1 == SLang_push_mmt(((expat_type *)userData)->mmt)) || (-1 == SLang_push_string(str)) || (-1 == SLang_end_arg_list ())) { SLang_verror(SL_RunTime_Error, "characterdatahandler failed"); XML_StopParser(((expat_type *)userData)->p, XML_FALSE); return; } (void) SLexecute_function (((expat_type *)userData)->characterdata_callback); if (SLang_get_error()) { XML_StopParser(((expat_type *)userData)->p, XML_FALSE); } SLang_free_slstring(str); } static void slxml_set_character_data_handler (void) { SLang_MMT_Type *mmt; expat_type *parser; SLang_Name_Type *func; if (!pop_function_or_null(&func)) return; if (NULL == (mmt = SLang_pop_mmt (Expat_Type_Id))) { return; } parser = SLang_object_from_mmt (mmt); parser->characterdata_callback = func; XML_SetCharacterDataHandler(parser->p, (func ? characterdatahandler : NULL)); } /*}}}*/ /*{{{ startnamespace handler */ static void startnamespacedeclhandler(void *userData, const char *prefix, const char *uri) { if ((-1 == SLang_start_arg_list ()) || (-1 == SLang_push_mmt(((expat_type *)userData)->mmt)) || (-1 == SLang_push_string((char *)prefix)) || (-1 == SLang_push_string((char *)uri)) || (-1 == SLang_end_arg_list ())) { SLang_verror(SL_RunTime_Error, "startnamespacedeclhandler failed"); XML_StopParser(((expat_type *)userData)->p, XML_FALSE); return; } (void) SLexecute_function (((expat_type *)userData)->startnamespacedecl_callback); if (SLang_get_error()) { XML_StopParser(((expat_type *)userData)->p, XML_FALSE); } } static void slxml_set_start_namespace_decl_handler (void) { SLang_MMT_Type *mmt; expat_type *parser; SLang_Name_Type *func; if (!pop_function_or_null(&func)) return; if (NULL == (mmt = SLang_pop_mmt (Expat_Type_Id))) { return; } parser = SLang_object_from_mmt (mmt); parser->startnamespacedecl_callback = func; XML_SetStartNamespaceDeclHandler(parser->p, (func ? startnamespacedeclhandler : NULL)); } /*}}}*/ /*{{{ endnamespace handler */ static void endnamespacedeclhandler(void *userData, const char *prefix) { if ((-1 == SLang_start_arg_list ()) || (-1 == SLang_push_mmt(((expat_type *)userData)->mmt)) || (-1 == (SLang_push_string((char *)prefix))) || (-1 == SLang_end_arg_list ())) { SLang_verror(SL_RunTime_Error, "endnamespacedeclhandler failed"); XML_StopParser(((expat_type *)userData)->p, XML_FALSE); return; } (void) SLexecute_function (((expat_type *)userData)->endnamespacedecl_callback); if (SLang_get_error()) { XML_StopParser(((expat_type *)userData)->p, XML_FALSE); } } static void slxml_set_end_namespace_decl_handler (void) { SLang_MMT_Type *mmt; expat_type *parser; SLang_Name_Type *func; if (!pop_function_or_null(&func)) return; if (NULL == (mmt = SLang_pop_mmt (Expat_Type_Id))) { return; } parser = SLang_object_from_mmt (mmt); parser->endnamespacedecl_callback = func; XML_SetEndNamespaceDeclHandler(parser->p, (func ? endnamespacedeclhandler : NULL)); } /*}}}*/ /*{{{ default handler */ static void defaulthandler(void *userData, const char *s, const int len) { char *str; if ((-1 == SLang_start_arg_list ()) || (NULL == (str = SLang_create_nslstring ((char *)s, len))) || (-1 == SLang_push_mmt(((expat_type *)userData)->mmt)) || (-1 == SLang_push_string(str)) || (-1 == SLang_end_arg_list ())) { SLang_verror(SL_RunTime_Error, "defaulthandler failed"); XML_StopParser(((expat_type *)userData)->p, XML_FALSE); return; } (void) SLexecute_function (((expat_type *)userData)->default_callback); if (SLang_get_error()) { XML_StopParser(((expat_type *)userData)->p, XML_FALSE); } SLang_free_slstring(str); } static void slxml_set_default_handler (void) { SLang_MMT_Type *mmt; expat_type *parser; SLang_Name_Type *func; if (!pop_function_or_null(&func)) return; if (NULL == (mmt = SLang_pop_mmt (Expat_Type_Id))) { return; } parser = SLang_object_from_mmt (mmt); parser->default_callback = func; XML_SetDefaultHandler(parser->p, (func ? defaulthandler : NULL)); } /*}}}*/ /*}}}*/ /*{{{ sget */ static SLang_CStruct_Field_Type Status_Type_Layout [] = { MAKE_CSTRUCT_FIELD(XML_ParsingStatus, parsing, "parsing", SLANG_INT_TYPE, 0), MAKE_CSTRUCT_FIELD(XML_ParsingStatus, finalBuffer, "finalbuffer", SLANG_INT_TYPE, 0), SLANG_END_CSTRUCT_TABLE }; /* * sget function. * It's possible to call the handlers as methods of an expat object - e.g. * parser.characterdatahandler("hello world"); * This will give an error if parser.characterdatahandler is NULL. */ static int expat_sget (SLtype type, char *name) { SLang_MMT_Type *mmt; expat_type *parser; int status = 0; (void) type; if (NULL == (mmt = SLang_pop_mmt (Expat_Type_Id))) return -1; parser = SLang_object_from_mmt (mmt); switch(*name) { case 'u': if (!strcmp (name, "userdata")) { status = SLang_push_anytype (parser->userdata); break; } case 's': if (!strcmp(name, "startelementhandler")) { status = SLang_push_function (parser->startelement_callback); break; } else if (!strcmp(name, "startnamespacedeclhandler")) { status = SLang_push_function (parser->startnamespacedecl_callback); break; } case 'e': if (!strcmp(name, "endelementhandler")) { status = SLang_push_function (parser->endelement_callback); break; } else if (!strcmp(name, "endnamespacedeclhandler")) { status = SLang_push_function (parser->endnamespacedecl_callback); break; } else if (!strcmp(name, "errorcode")) { status = SLang_push_integer(translate_error(XML_GetErrorCode(parser->p))); break; } else if (!strcmp(name, "errorstring")) { status = SLang_push_string((char *)XML_ErrorString(XML_GetErrorCode(parser->p))); break; } case 'c': if (!strcmp(name, "characterdatahandler")) { status = SLang_push_function (parser->characterdata_callback); break; } else if (!strcmp(name, "currentbyteindex")) { #ifdef XML_LARGE_SIZE status = SLang_push_long_long(XML_GetCurrentByteIndex(parser->p)); #else status = SLang_push_long(XML_GetCurrentByteIndex(parser->p)); #endif break; } else if (!strcmp(name, "currentline")) { #ifdef XML_LARGE_SIZE status = SLang_push_ulong_long((unsigned long long)XML_GetCurrentLineNumber(parser->p)); #else status = SLang_push_ulong((unsigned long)XML_GetCurrentLineNumber(parser->p)); #endif break; } else if (!strcmp(name, "currentcolumn")) { #ifdef XML_LARGE_SIZE status = SLang_push_ulong_long((unsigned long long)XML_GetCurrentColumnNumber(parser->p)); #else status = SLang_push_ulong((unsigned long)XML_GetCurrentColumnNumber(parser->p)); #endif break; } case 'p': { if (!strcmp(name, "parsingstatus")) { XML_ParsingStatus parsingstatus; XML_GetParsingStatus(parser->p, &parsingstatus); status = SLang_push_cstruct ((VOID_STAR)&parsingstatus, Status_Type_Layout); break; } } case 'd': if (!strcmp(name, "defaulthandler")) { status = SLang_push_function (parser->default_callback); break; } default: status = -1; SLang_verror (SL_NOT_IMPLEMENTED, "Expat_Type.%s is invalid", name); } SLang_free_mmt (mmt); return status; } /*}}}*/ /*{{{ sput */ static int expat_sput (SLtype type, char *name) { SLang_MMT_Type *mmt; expat_type *parser; int status = 0; SLang_Name_Type *func; (void) type; if (NULL == (mmt = SLang_pop_mmt (Expat_Type_Id))) return -1; parser = SLang_object_from_mmt (mmt); switch (*name) { case 'u': if (!strcmp (name, "userdata")) { SLang_Any_Type *userdata; (void) SLang_pop_anytype (&userdata); SLang_free_anytype (parser->userdata); parser->userdata = NULL; parser->userdata = userdata; break; } case 's': if (!strcmp (name, "startelementhandler")) { if (!pop_function_or_null(&func)) return -1; parser->startelement_callback = func; XML_SetStartElementHandler(parser->p, (func ? startelementhandler : NULL)); break; } else if (!strcmp (name, "startnamespacedeclhandler")) { if (!pop_function_or_null(&func)) return -1; parser->startnamespacedecl_callback = func; XML_SetStartNamespaceDeclHandler(parser->p, (func ? startnamespacedeclhandler : NULL)); break; } case 'e': if (!strcmp (name, "endelementhandler")) { if (!pop_function_or_null(&func)) return -1; parser->endelement_callback = func; XML_SetEndElementHandler(parser->p, (func ? endelementhandler : NULL)); break; } else if (!strcmp (name, "endnamespacedeclhandler")) { if (!pop_function_or_null(&func)) return -1; parser->endnamespacedecl_callback = func; XML_SetEndNamespaceDeclHandler(parser->p, (func ? endnamespacedeclhandler : NULL)); break; } case 'c': if (!strcmp (name, "characterdatahandler")) { if (!pop_function_or_null(&func)) return -1; parser->characterdata_callback = func; XML_SetCharacterDataHandler(parser->p, (func ? characterdatahandler : NULL)); break; } case 'd': if (!strcmp (name, "defaulthandler")) { if (!pop_function_or_null(&func)) return -1; parser->default_callback = func; XML_SetDefaultHandler(parser->p, (func ? defaulthandler : NULL)); break; } default: status = -1; SLang_verror (SL_NOT_IMPLEMENTED, "Expat_Type.%s is invalid", name); } SLang_free_mmt (mmt); return status; } /*}}}*/ /*{{{ intrinsics */ static SLang_Intrin_Fun_Type Module_Intrinsics [] = { MAKE_INTRINSIC_0("xml_new", slxml_new, SLANG_VOID_TYPE), MAKE_INTRINSIC_1("xml_new_ns", slxml_new_ns, SLANG_VOID_TYPE, SLANG_CHAR_TYPE), MAKE_INTRINSIC_SI("xml_parse", slxml_parse, SLANG_VOID_TYPE), MAKE_INTRINSIC_I("xml_stop_parser", slxml_stop_parser, SLANG_VOID_TYPE), MAKE_INTRINSIC_0("xml_resume_parser", slxml_resume_parser, SLANG_VOID_TYPE), MAKE_INTRINSIC_0("xml_set_user_data", slxml_setuserdata, SLANG_VOID_TYPE), MAKE_INTRINSIC_0("xml_get_user_data", slxml_getuserdata, SLANG_VOID_TYPE), MAKE_INTRINSIC_0("xml_set_start_element_handler", slxml_set_start_element_handler, SLANG_VOID_TYPE), MAKE_INTRINSIC_0("xml_set_end_element_handler", slxml_set_end_element_handler, SLANG_VOID_TYPE), MAKE_INTRINSIC_0("xml_set_character_data_handler", slxml_set_character_data_handler, SLANG_VOID_TYPE), MAKE_INTRINSIC_0("xml_set_default_handler", slxml_set_default_handler, SLANG_VOID_TYPE), MAKE_INTRINSIC_0("xml_set_start_namespace_decl_handler", slxml_set_start_namespace_decl_handler, SLANG_VOID_TYPE), MAKE_INTRINSIC_0("xml_set_end_namespace_decl_handler", slxml_set_end_namespace_decl_handler, SLANG_VOID_TYPE), SLANG_END_INTRIN_FUN_TABLE }; static SLang_Intrin_Var_Type Module_Variables [] = { MAKE_VARIABLE("_expat_module_version_string", &Module_Version_String, SLANG_STRING_TYPE, 1), SLANG_END_INTRIN_VAR_TABLE }; static SLang_IConstant_Type Module_Constants [] = { MAKE_ICONSTANT("_expat_module_version", MODULE_VERSION_NUMBER), MAKE_ICONSTANT("XML_INITIALIZED", XML_INITIALIZED), MAKE_ICONSTANT("XML_PARSING", XML_PARSING), MAKE_ICONSTANT("XML_FINISHED", XML_FINISHED), MAKE_ICONSTANT("XML_SUSPENDED", XML_SUSPENDED), SLANG_END_ICONST_TABLE }; /*}}}*/ /*{{{ register class */ static int register_expat_type (void) { SLang_Class_Type *cl; if (Expat_Type_Id) return 0; if ((NULL == (cl = SLclass_allocate_class ("Expat_Type"))) || (-1 == SLclass_set_destroy_function (cl, destroy_expat)) || (-1 == SLclass_set_sget_function (cl, expat_sget)) || (-1 == SLclass_set_sput_function(cl, expat_sput)) || (-1 == SLclass_register_class (cl, SLANG_VOID_TYPE, sizeof (expat_type), SLANG_CLASS_TYPE_MMT))) return -1; Expat_Type_Id = SLclass_get_class_id (cl); if (Expat_Error == 0) { const Expat_Exception_Table_Type *b; b = Expat_Exception_Table; if (-1 == (Expat_Error = SLerr_new_exception (SL_RunTime_Error, "ExpatError", "Expat error"))) return -1; b++; while (b->errcode_ptr != NULL) { *b->errcode_ptr = SLerr_new_exception (Expat_Error, b->name, b->description); if (*b->errcode_ptr == -1) return -1; b++; } } return 0; } /*}}}*/ /*{{{ init */ int init_expat_module_ns (char *ns_name) { SLang_NameSpace_Type *ns = SLns_create_namespace (ns_name); if ((ns == NULL) || (-1 == register_expat_type ()) || (-1 == SLns_add_intrin_fun_table (ns, Module_Intrinsics, NULL)) || (-1 == SLns_add_intrin_var_table (ns, Module_Variables, NULL)) || (-1 == SLns_add_iconstant_table (ns, Module_Constants, NULL))) return -1; return 0; } /*}}}*/ slexpat-0.5.0/expatfuns.tm0000644000175000017500000001702110745703342014245 0ustar paulpaul#s+ custom_variable("tm_format", "slhlp"); if (tm_format == "html") { tm_add_macro("vdt", "\\dtdd{\\code{$1}}{$2}", 2, 2); tm_add_macro("n", "\\newline", 0, 0); tm_add_macro("link", "\\href{#$1}{$1}", 1, 1); } else { tm_add_macro("dl", "$1", 1, 1); tm_add_macro("vdt", "\\var{$1}: $2\\__newline__", 2, 2); tm_add_macro("n", "", 0, 0); tm_add_macro("link", "$1", 1, 1); } #s- \function{xml_new} \synopsis{Instantiate a new Expat_Type object} \usage{Expat_Type xml_new()} \description This function instantiates and returns an \dtype{Expat_Type}. The \dtype{Expat_Type} is an opaque type, but its internals can be accessed with the dot operator like in a structure: \dl{ \vdt{.userdata}{see \ifun{\link{xml_set_user_data}}} \vdt{.startelementhandler}{see \ifun{\link{xml_set_start_element_handler}}} \vdt{.endelementhandler}{see \ifun{\link{xml_set_end_element_handler}}} \vdt{.characterdatahandler}{see \ifun{\link{xml_set_character_data_handler}}} \vdt{.defaulthandler}{see \ifun{\link{xml_set_default_handler}}} } The following properties do nothing unless the Expat parser was created with \ifun{\link{xml_new_ns}}: \dl{ \vdt{.startnamespacedeclhandler}{ see \ifun{\link{xml_set_start_namespace_decl_handler}}} \vdt{.endnamespacedeclhandler}{ see \ifun{\link{xml_set_end_namespace_decl_handler}}} } The following properties are read-only and correspond to the C functions XML_GetErrorCode etc: \dl{ \vdt{.errorcode}{the error status of the parser. This will be \exc{ExpatError} or a subclass thereof, not expat's internal error code.} \vdt{.errorstring}{the description of the error status.} \vdt{.currentbyteindex}{the byte offset of the position.} \vdt{.currentline}{ the line number of the position. The first line is reported as 1.} \vdt{.currentcolumn}{the offset, from the beginning of the current line, of the position.} \vdt{.parsingstatus}{a struct {\dtype{Int_Type} parsing, \dtype{Int_Type} finalbuffer}. \var{.parsing.parsingstatus} can take on four values: #v+ XML_INITIALIZED XML_PARSING XML_FINISHED XML_SUSPENDED #v- \var{.parsing.finalbuffer} is one if the final buffer is being processed - that is, when \ifun{xml_parse} was called with the third argument 1. }} \seealso{xml_parse, xml_new_ns} \done \function{xml_new_ns} \synopsis{Instantiate an Expat_Type object with namespace processing} \usage{Expat_Type xml_new_ns(Char_Type sep)} \description Constructs a new parser that has namespace processing in effect. Namespace expanded element names and attribute names are returned as a concatenation of the namespace URI, sep, and the local part of the name. This means that you should pick a character for sep that can't be part of a legal URI. \seealso{xml_parse, xml_new} \done \function{xml_parse} \synopsis{parse part of and xml document} \usage{xml_parse(Expat_Type p, String_Type s, Int_Type isFinal)} \description Parse some more of the document. The string s is a buffer containing part (or perhaps all) of the document. The isFinal parameter informs the parser that this is the last piece of the document. Frequently, the last piece is empty (i.e. len is zero). If a parse error occurred, an \exc{ExpatError} is thrown. \seealso{xml_new, xml_stop_parser} \done \function{xml_stop_parser} \synopsis{stop parsing} \usage{xml_stop_parser(Expat_Type p, Int_Type resumable)} \description Stops parsing, causing \ifun{xml_parse} to return. Must be called from within a call-back handler, except when aborting (when resumable is 0) an already suspended parser. \seealso{xml_new, xml_resume_parser} \done \function{xml_resume_parser} \synopsis{resume parsing} \usage{xml_resume_parser(Expat_Type p)} \description Resumes parsing after it has been suspended with \ifun{xml_stop_parser}. Must not be called from within a handler call-back. \seealso{xml_new, xml_stop_parser} \done \function{xml_set_start_element_handler} \synopsis{set the start element handler} \usage{xml_set_start_element_handler(Expat_Type p, Ref_Type handler)} \description Set the handler for start elements. The handler should have the prototype #v+ handler(p, name, atttributes) Expat_Type p; String_Type name; Array_Type[Struct_Type{name, value}] atttributes; #v- The handler can acces the parser's userdata with \exmp{xml_get_user_data(p)} or as p.userdata. \notes To unset the handler, set it to \NULL \seealso{xml_new, xml_parse} \done \function{xml_set_end_element_handler} \synopsis{set the end element handler} \usage{xml_set_end_element_handler(Expat_Type p, Ref_Type handler)} \description Set the handler for end elements. The handler should have the prototype #v+ handler(p, name) Expat_Type p; String_Type name; #v- The handler can acces the parser's userdata with \exmp{xml_get_user_data(p)} or as p.userdata. \notes To unset the handler, set it to \NULL \seealso{xml_new, xml_parse} \done \function{xml_set_start_namespace_decl_handler} \synopsis{set the start namespace_decl handler} \usage{xml_set_start_namespace_decl_handler(Expat_Type p, Ref_Type handler)} \description Set a handler to be called when a namespace is declared. Namespace declarations occur inside start tags. But the namespace declaration start handler is called before the start tag handler for each namespace declared in that start tag. The handler should have the prototype #v+ handler(p, prefix, uri) Expat_Type p; String_Type or NULL prefix; String_Type or NULL uri; #v- \notes To unset the handler, set it to \NULL \seealso{xml_new_ns, xml_parse} \done \function{xml_set_end_namespace_decl_handler} \synopsis{set the end namespace_decl handler} \usage{xml_set_end_namespace_decl_handler(Expat_Type p, Ref_Type handler)} \description Set a handler to be called when leaving the scope of a namespace declaration. This will be called, for each namespace declaration, after the handler for the end tag of the element in which the namespace was declared. The handler should have the prototype #v+ handler(p, prefix) Expat_Type p; String_Type or NULL prefix; #v- \notes To unset the handler, set it to \NULL \seealso{xml_new_ns, xml_parse} \done \function{xml_set_character_data_handler} \synopsis{set the character data handler} \usage{xml_set_character_data_handler(Expat_Type p, Ref_Type handler)} \description Set the handler for character data. The handler should have the prototype #v+ handler(p, data) Expat_Type p; String_Type data; #v- The handler can acces the parser's userdata with \exmp{xml_get_user_data(p)} or as p.userdata. \notes To unset the handler, set it to \NULL \seealso{xml_new, xml_parse} \done \function{xml_set_default_handler} \synopsis{set the character data handler} \usage{xml_set_default_handler(Expat_Type p, Ref_Type handler)} \description Sets a handler for any characters in the document which wouldn't otherwise be handled. The handler should have the prototype #v+ handler(p, data) Expat_Type p; String_Type data; #v- \notes To unset the handler, set it to \NULL \seealso{xml_new, xml_parse} \done \function{xml_set_user_data} \synopsis{Set the user data associated with an XML parser} \usage{xml_set_user_data(Expat_Type p, AnyType data)} \description This sets the user data pointer that gets passed to handlers. \seealso{xml_new, xml_get_user_data} \done \function{xml_get_user_data} \synopsis{Get the user data associated with an XML parser} \usage{AnyType xml_get_user_data(Expat_Type p)} \description This gets the user data pointer that gets passed to handlers. \seealso{xml_new, xml_set_user_data} \done slexpat-0.5.0/expat.hlp0000644000175000017500000001705310745703342013521 0ustar paulpaulxml_new SYNOPSIS Instantiate a new Expat_Type object USAGE Expat_Type xml_new() DESCRIPTION This function instantiates and returns an Expat_Type. The Expat_Type is an opaque type, but its internals can be accessed with the dot operator like in a structure: `.userdata': see `xml_set_user_data' `.startelementhandler': see `xml_set_start_element_handler' `.endelementhandler': see `xml_set_end_element_handler' `.characterdatahandler': see `xml_set_character_data_handler' `.defaulthandler': see `xml_set_default_handler' The following properties do nothing unless the Expat parser was created with `xml_new_ns': `.startnamespacedeclhandler': see `xml_set_start_namespace_decl_handler' `.endnamespacedeclhandler': see `xml_set_end_namespace_decl_handler' The following properties are read-only and correspond to the C functions XML_GetErrorCode etc: `.errorcode': the error status of the parser. This will be `ExpatError' or a subclass thereof, not expat's internal error code. `.errorstring': the description of the error status. `.currentbyteindex': the byte offset of the position. `.currentline': the line number of the position. The first line is reported as 1. `.currentcolumn': the offset, from the beginning of the current line, of the position. `.parsingstatus': a struct {Int_Type parsing, Int_Type finalbuffer}. `.parsing.parsingstatus' can take on four values: XML_INITIALIZED XML_PARSING XML_FINISHED XML_SUSPENDED `.parsing.finalbuffer' is one if the final buffer is being processed - that is, when `xml_parse' was called with the third argument 1. SEE ALSO xml_parse, xml_new_ns -------------------------------------------------------------- xml_new_ns SYNOPSIS Instantiate an Expat_Type object with namespace processing USAGE Expat_Type xml_new_ns(Char_Type sep) DESCRIPTION Constructs a new parser that has namespace processing in effect. Namespace expanded element names and attribute names are returned as a concatenation of the namespace URI, sep, and the local part of the name. This means that you should pick a character for sep that can't be part of a legal URI. SEE ALSO xml_parse, xml_new -------------------------------------------------------------- xml_parse SYNOPSIS parse part of and xml document USAGE xml_parse(Expat_Type p, String_Type s, Int_Type isFinal) DESCRIPTION Parse some more of the document. The string s is a buffer containing part (or perhaps all) of the document. The isFinal parameter informs the parser that this is the last piece of the document. Frequently, the last piece is empty (i.e. len is zero). If a parse error occurred, an `ExpatError' is thrown. SEE ALSO xml_new, xml_stop_parser -------------------------------------------------------------- xml_stop_parser SYNOPSIS stop parsing USAGE xml_stop_parser(Expat_Type p, Int_Type resumable) DESCRIPTION Stops parsing, causing `xml_parse' to return. Must be called from within a call-back handler, except when aborting (when resumable is 0) an already suspended parser. SEE ALSO xml_new, xml_resume_parser -------------------------------------------------------------- xml_resume_parser SYNOPSIS resume parsing USAGE xml_resume_parser(Expat_Type p) DESCRIPTION Resumes parsing after it has been suspended with `xml_stop_parser'. Must not be called from within a handler call-back. SEE ALSO xml_new, xml_stop_parser -------------------------------------------------------------- xml_set_start_element_handler SYNOPSIS set the start element handler USAGE xml_set_start_element_handler(Expat_Type p, Ref_Type handler) DESCRIPTION Set the handler for start elements. The handler should have the prototype handler(p, name, atttributes) Expat_Type p; String_Type name; Array_Type[Struct_Type{name, value}] atttributes; The handler can acces the parser's userdata with `xml_get_user_data(p)' or as p.userdata. NOTES To unset the handler, set it to NULL SEE ALSO xml_new, xml_parse -------------------------------------------------------------- xml_set_end_element_handler SYNOPSIS set the end element handler USAGE xml_set_end_element_handler(Expat_Type p, Ref_Type handler) DESCRIPTION Set the handler for end elements. The handler should have the prototype handler(p, name) Expat_Type p; String_Type name; The handler can acces the parser's userdata with `xml_get_user_data(p)' or as p.userdata. NOTES To unset the handler, set it to NULL SEE ALSO xml_new, xml_parse -------------------------------------------------------------- xml_set_start_namespace_decl_handler SYNOPSIS set the start namespace_decl handler USAGE xml_set_start_namespace_decl_handler(Expat_Type p, Ref_Type handler) DESCRIPTION Set a handler to be called when a namespace is declared. Namespace declarations occur inside start tags. But the namespace declaration start handler is called before the start tag handler for each namespace declared in that start tag. The handler should have the prototype handler(p, prefix, uri) Expat_Type p; String_Type or NULL prefix; String_Type or NULL uri; NOTES To unset the handler, set it to NULL SEE ALSO xml_new_ns, xml_parse -------------------------------------------------------------- xml_set_end_namespace_decl_handler SYNOPSIS set the end namespace_decl handler USAGE xml_set_end_namespace_decl_handler(Expat_Type p, Ref_Type handler) DESCRIPTION Set a handler to be called when leaving the scope of a namespace declaration. This will be called, for each namespace declaration, after the handler for the end tag of the element in which the namespace was declared. The handler should have the prototype handler(p, prefix) Expat_Type p; String_Type or NULL prefix; NOTES To unset the handler, set it to NULL SEE ALSO xml_new_ns, xml_parse -------------------------------------------------------------- xml_set_character_data_handler SYNOPSIS set the character data handler USAGE xml_set_character_data_handler(Expat_Type p, Ref_Type handler) DESCRIPTION Set the handler for character data. The handler should have the prototype handler(p, data) Expat_Type p; String_Type data; The handler can acces the parser's userdata with `xml_get_user_data(p)' or as p.userdata. NOTES To unset the handler, set it to NULL SEE ALSO xml_new, xml_parse -------------------------------------------------------------- xml_set_default_handler SYNOPSIS set the character data handler USAGE xml_set_default_handler(Expat_Type p, Ref_Type handler) DESCRIPTION Sets a handler for any characters in the document which wouldn't otherwise be handled. The handler should have the prototype handler(p, data) Expat_Type p; String_Type data; NOTES To unset the handler, set it to NULL SEE ALSO xml_new, xml_parse -------------------------------------------------------------- xml_set_user_data SYNOPSIS Set the user data associated with an XML parser USAGE xml_set_user_data(Expat_Type p, AnyType data) DESCRIPTION This sets the user data pointer that gets passed to handlers. SEE ALSO xml_new, xml_get_user_data -------------------------------------------------------------- xml_get_user_data SYNOPSIS Get the user data associated with an XML parser USAGE AnyType xml_get_user_data(Expat_Type p) DESCRIPTION This gets the user data pointer that gets passed to handlers. SEE ALSO xml_new, xml_set_user_data --------------------------------------------------------------