Index: CHANGES ================================================================== --- CHANGES +++ CHANGES @@ -1,5 +1,31 @@ +2020-08-21 Rolf Ade + + Added -onlyContents and -breakLines to asHTML. + +2020-08-17 Rolf Ade + + Updated TEA. + +2020-07-23 Rolf Ade + + Added -indent value "tab" to asXML and asJSON. + +2020-07-03 Rolf Ade + + User configurable separator character between namespace URI + and local name for XML namespace-aware SAX parser: Added the + option -namespaceseparator to the expat command. + +2020-05-14 Rolf Ade + + Added method clearString to the dom command. + +2019-12-31 Rolf Ade + + Updated to expat 2.2.9. + 2018-10-12 Rolf Ade Updated to expat 2.2.6. 2018-08-08 Rolf Ade DELETED README Index: README ================================================================== --- README +++ /dev/null @@ -1,120 +0,0 @@ - - - tDOM - a XML/DOM/XPath/XSLT/HTML/JSON implementation for Tcl - (Version 0.9.2) - - -This directory contains a freely distributable thread-safe extension -to Tcl/Tk called tDOM. - -tDOM contains: - - * for convenience expat 2.2.5, the XML parser originated from - James Clark, although you're able to link tDOM with other - expat versions or the library provided by the system. - - * building a DOM tree from XML in one go implemented in C for - maximum performance and minimum memory usage, and DOM I and II - methods to work on such a tree using either a OO-like or a - handle syntax. - - * a Tcl interface to expat for event-like (SAX-like) XML parsing. - - * a complete, compliant and fast XPath implementation in C - following the November 99 W3C recommendation for navigating and - data extraction. - - * a fast XSLT implementation in C following the W3C Recommendation - 16 November 1999. - - * optional DTD validation. - - * a JSON parser which parses any possible JSON input into a DOM - tree without losing information. - - * an efficient and Tcl'ish way to create XML and HTML documents - and JSON string. - - * as build option an interface to the gumbo HTML5 parser, which - also digests almost any other HTML. - - * an even faster simple XML parser for trusted XML input. - - * A slim Tcl interface to use expat as pull-parser. - - * additional convenience methods. - - * and more. - - -DOCUMENTATION - - The documentation is included into the source distribution in HTML - and man format. Alternatively, read it online starting at - http://tdom.org/index.html/doc/trunk/doc/index.html - - -GETTING THE CODE - - The development repository is hosted at http://tdom.org and is - mirrored at http://core.tcl.tk/tdom. You are encouraged to use - trunk. - - If you insist on using an older tDOM with lesser features and - probably more bugs, you should use the latest release 0.9.1. Get - the source code release from - http://tdom.org/downloads/tdom-0.9.1-src.tgz or - http://tdom.org/downloads/tdom-0.9.1-src.zip - - Windows binaries (32 bit as well as 64 bit) of the 0.9.1 release - are also available. Get it from - http://tdom.org/downloads/tdom-0.9.1-windows-x64.zip and - http://tdom.org/downloads/tdom-0.9.1-windows-x86.zip - - The provided windows binaries include (statically linked) the - HTML5 parser. - - -COMPILING tDOM - - Depending on your platform (unix/mac or win), go to the - corresponding directory and invoke the configure script: - - ../configure - make - make test - make install - - Alternatively, you can build the tDOM package in just about any - directory elsewhere on the filesystem (since TEA-compatible). - - You might also want to do "../configure --help" to get a list of - all supported options of the configure script. In the "unix" - directory there is a "CONFIG" file containing some examples on how - to invoke the "configure" script for some common cases. You can - peek there. This file also includes a short description of the - tDOM specific configure options. - - Since tDOM is TEA-compatible you should be able to build it using - the MinGW build environment for Windows. There is also the MSVC - nmake file so you can compile the package with Microsoft tools. - Refer to the README in the win directory for more details about - building on Windows. - - The compile process will build the tDOM shared library suitable for - loading into the Tcl shell using standard "package require" mechanism. - - -REPORTING BUGS - - Please head to http://tdom.org/index.html/ticket and click on "New - Ticket". Log in as anonymous and report your findings. If you - prefer to have an individual login write Rolf a mail. - - -HISTORY - - tDOM was started by Jochen Loewer (loewerj@hotmail.com) and - developed by Jochen and Rolf Ade (rolf@pointsman.de) with - contributions by Zoran Vasiljevic (zv@archiware.com). Since more - than a dozen years it is maintained and developed by Rolf Ade. ADDED README.md Index: README.md ================================================================== --- /dev/null +++ README.md @@ -0,0 +1,124 @@ + +## tDOM - a XML / DOM / XPath / XSLT / HTML / JSON implementation for Tcl Version 0.9.2 + +### tDOM contains: + + * for convenience expat 2.2.9, the XML parser originated from + James Clark, although you're able to link tDOM with other + expat versions or the library provided by the system. + + * building a DOM tree from XML in one go implemented in C for + maximum performance and minimum memory usage, and DOM I and II + methods to work on such a tree using either a OO-like or a + handle syntax. + + * a Tcl interface to expat for event-like (SAX-like) XML parsing. + + * a complete, compliant and fast XPath implementation in C + following the November 99 W3C recommendation for navigating and + data extraction. + + * a fast XSLT implementation in C following the W3C Recommendation + 16 November 1999. + + * optional DTD validation. + + * a rich and Tcl'ish language to describe structures and to + validate XML data or DOM trees or other forms of hierarchically + data with that. + + * a JSON parser which parses any possible JSON input into a DOM + tree without losing information. + + * an efficient and Tcl'ish way to create XML and HTML documents + and JSON strings. + + * as build option an interface to the gumbo HTML5 parser, which + also digests almost any other HTML. + + * an even faster simple XML parser for trusted XML input. + + * a slim Tcl interface to use expat as pull-parser. + + * a secure way to share DOM trees by threads + + * additional convenience methods. + + * and more. + + +### Documentation + +The documentation is included into the source distribution in HTML and +man format. Alternatively, read it +[online](http://tdom.org/index.html/doc/trunk/doc/index.html). + + +### Getting the code + +The development repository is hosted at and is +mirrored at . You are invited to use trunk +which you get as +[tarball](http://tdom.org/index.html/tarball/trunk/tdom-trunk.tar.gz) +or as [zip archive](http://tdom.org/index.html/zip/trunk/tdom-trunk.zip) + +The latest release is 0.9.2. Get the source code as +[tarball](http://tdom.org/downloads/tdom-0.9.2-src.tgz) or +as [zip archive](http://tdom.org/downloads/tdom-0.9.2-src.zip). + +Windows binaries of the 0.9.2 release are also available. Get it for +[64 bit](http://tdom.org/downloads/tdom-0.9.2-windows-x64.zip) or [32 +bit](http://tdom.org/downloads/tdom-0.9.2-windows-x86.zip). + +The provided windows binaries include (statically linked) the +HTML5 parser. + + +### Compiling tdom + +Depending on your platform (unix/mac or win), go to the +corresponding directory and invoke the configure script: + + ../configure + make + make test + make install + +Alternatively, you can build the tDOM package in just about any +directory elsewhere on the filesystem (since TEA-compatible). + +You might also want to do "../configure --help" to get a list of +all supported options of the configure script. In the "unix" +directory there is a "CONFIG" file containing some examples on how +to invoke the "configure" script for some common cases. You can +peek there. This file also includes a short description of the +tDOM specific configure options. + +Since tDOM is TEA-compatible you should be able to build it using +the MinGW build environment for Windows. There is also the MSVC +nmake file so you can compile the package with Microsoft tools. +Refer to the README in the win directory for more details about +building on Windows. + +The compile process will build the tDOM shared library suitable for +loading into the Tcl shell using standard "package require" mechanism. + + +### Reporting bugs + +Open a [ticket](http://tdom.org/index.html/ticket). Log in as +anonymous and report your findings. If you prefer to have an +individual login write Rolf a mail. + + +### History + +tDOM was started by Jochen Loewer (loewerj@hotmail.com) and +developed by Jochen and Rolf Ade (rolf@pointsman.de) with +contributions by Zoran Vasiljevic (zv@archiware.com). Since more +than a dozen years it is maintained and developed by Rolf Ade. + + +### ... ahh, Licensing!! + +Sigh. See LICENSE file. ADDED apps/toschema.tcl Index: apps/toschema.tcl ================================================================== --- /dev/null +++ apps/toschema.tcl @@ -0,0 +1,270 @@ + +package require tdom +package require uri + +variable dtdStart "" +variable dtdFinished 0 +variable indent 4 + +proc indent {} { + variable indent + upvar level level + return [string repeat " " [expr {$indent * $level}]] +} + +proc fromDTD_serialize {level type quant name content} { + variable nslookup + + switch $type { + "NAME" { + set parts [split $name :] + if {[llength $parts] == 2 && [info exists nslookup([lindex $parts 0])]} { + puts "[indent]namespace $nslookup([lindex $parts 0]) {" + incr level + puts "[indent]element [lindex $parts 1] $quant" + incr level -1 + puts "[indent]}" + } else { + puts "[indent]element $name $quant" + } + return + } + "MIXED" { + if {[llength $content] == 0} { + puts "[indent]text" + return + } + puts "[indent]mixed \{" + } + "EMPTY" { + return + } + "ANY" { + puts "[indent]ANY\}" + return + } + "SEQ" { + if {$level == 1 && $quant eq ""} { + # At least directly below defelement there isn't any + # need to wrap a ! SEQ into a group container - + # defelement childs are already processed as sequence + # while validating. + foreach cp $content { + fromDTD_serialize $level {*}$cp + } + return + } else { + puts "[indent]group $quant \{" + } + } + "CHOICE" { + puts "[indent]choice $quant \{" + } + } + foreach cp $content { + fromDTD_serialize [expr {$level +1}] {*}$cp + } + puts "[indent]\}" +} + +proc fromDTD_generate {} { + variable dtdStart + variable dtdElements + variable dtdAttributes + variable nslookup + + if {$dtdStart ne ""} { + if {![info exists dtdElements($dtdStart)]} { + puts "Document element not defined." + exit 1 + } + puts "start $dtdStart" + } + set elements [lsort [array names dtdElements]] + set startInd [lsearch -exact $elements $dtdStart] + set elements [lreplace $elements $startInd $startInd] + set elements [linsert $elements 0 $dtdStart] + set level 1 + foreach name $elements { + # First round over attributes to get possible namespace + # declarations + foreach {attkey attDef} [array get dtdAttributes $name,*] { + lassign $attDef attname type default isRequired + if {$attname eq "xmlns"} { + if {$default ne ""} { + set nslookup(:default) $default + } + } else { + set parts [split $attname ":"] + if {[llength $parts] == 2} { + switch [lindex $parts 0] { + "xml" { + set nslookup(xml) "http://www.w3.org/XML/1998/namespace" + } + "xmlns" { + if {$default ne ""} { + set nslookup([lindex $parts 1]) $default + } + } + } + } + } + } + # Heuristic to get namespace right + set namespace "" + if {[info exists nslookup(:default)] && $nslookup(:default) ne ""} { + set namespace $nslookup(:default) + } + set parts [split $name ":"] + set schemaName $name + if {[llength $parts] == 2} { + set prefix [lindex $parts 0] + if {[info exists nslookup($prefix)]} { + set namespace $nslookup($prefix) + set schemaName [lindex $parts 1] + } else { + # Hmmm. Either dtd error or the namespace is + # defined somewhere on the ancestors. To be + # handled. TODO + } + } + if {$namespace ne ""} { + puts "defelement $schemaName $namespace \{" + } else { + puts "defelement $schemaName \{" + } + # Second round over attributes for the actualy attribute + # declarations. + foreach {attkey attDef} [array get dtdAttributes $name,*] { + lassign $attDef attname type default isRequired + set parts [split $attname ":"] + if {[llength $parts] == 2} { + set prefix [lindex $parts 0] + if {![info exists nslookup($prefix)]} { + # Hmmm. Either dtd error or the namespace is + # defined somewhere on the ancestors. To be + # handled. TODO + set cmd "attribute $attname" + } else { + set cmd "nsattribute [lindex $parts 1] $nslookup($prefix)" + } + } else { + set cmd "attribute $attname" + } + if {$isRequired && $default != ""} { + puts "[indent]$cmd ? {[list "fixed" $default]}" + continue + } + switch $type { + "ENTITY" - + "ENTITIES" - + "NOTATION" { + # All above to be done + puts "[indent]$cmd [expr {$isRequired ? "" : "?"}]" + } + "NMTOKEN" { + puts "[indent]$cmd [expr {$isRequired ? "" : "?"}] \{nmtoken\}" + } + "ID" { + puts "[indent]$cmd [expr {$isRequired ? "" : "?"}] \{nmtoken;id\}" + } + "IDREF" { + puts "[indent]$cmd [expr {$isRequired ? "" : "?"}] \{idref\}" + } + "IDREFS" { + puts "[indent]$cmd [expr {$isRequired ? "" : "?"}] \{split \{idref\}\}" + } + "NMTOKENS" { + puts "[indent]$cmd [expr {$isRequired ? "" : "?"}] \{nmtokens\}" + } + "CDATA" { + puts "[indent]$cmd [expr {$isRequired ? "" : "?"}]" + } + default { + if {[string index $type 0] ne "("} { + # Ups. Should not happen. + error "Unexpeced (invalid) attribute type '$type'" + } + puts "[indent]$cmd [expr {$isRequired ? "" : "?"}] {enumeration {[split [string trim $type "()"] "|"]}}" + } + } + } + fromDTD_serialize 1 {*}$dtdElements($name) + puts "\}" + } +} + +proc fromDTD_startDoctypeDecl {name systemID publicID hasInternalSubset} { + variable dtdStart $name + variable dtdFinished 0 +} + +proc fromDTD_endDoctypeDecl {args} { + variable dtdFinished 1 + + fromDTD_generate +} + +proc fromDTD_elementDecl {name content} { + variable dtdElements + + set dtdElements($name) $content +} + +proc fromDTD_attlistDecl {elname name type default isRequired} { + variable dtdAttributes + + set dtdAttributes($elname,$name) [list $name $type $default $isRequired] +} + +proc fromDTD {file} { + + ::xml::parser p \ + -baseurl [tdom::baseURL $file] \ + -paramentityparsing always \ + -externalentitycommand tdom::extRefHandler \ + -startdoctypedeclcommand fromDTD_startDoctypeDecl \ + -enddoctypedeclcommand fromDTD_endDoctypeDecl \ + -elementdeclcommand fromDTD_elementDecl \ + -attlistdeclcommand fromDTD_attlistDecl + + p parse [tdom::xmlReadFile $file] +} + +proc usage {} { + puts "$argv0 ?options? file" +} + +proc run {args} { + if {[llength $args] == 1} { + set file [lindex $args 0] + if {![file readable $file] || ![file isfile $file]} { + puts stderr "Can't open '$file'" + exit 1 + } + set needToGuess 0 + switch [file extension $file] { + ".xml" { + fromDTD $file + } + default { + set needToGuess 1 + } + } + if {$needToGuess} { + # Just probe everything we have in no specific order + foreach reader { + fromDTD + } { + if {![catch {$reader $file}]} { + return + } + } + } + return + } + usage +} + +run {*}$argv + Index: configure ================================================================== --- configure +++ configure @@ -617,11 +617,10 @@ #ifdef HAVE_UNISTD_H # include #endif" ac_subst_vars='LTLIBOBJS -LIBOBJS PKG_STUB_LIB_PATH PKG_BUILD_STUB_LIB_PATH PKG_STUB_LIB_SPEC PKG_BUILD_STUB_LIB_SPEC TDOMSHELL @@ -631,29 +630,31 @@ RANLIB_STUB MAKE_STUB_LIB MAKE_STATIC_LIB MAKE_SHARED_LIB MAKE_LIB -TCL_DBGX LDFLAGS_DEFAULT CFLAGS_DEFAULT TDOM_LD_SEARCH_FLAGS LD_LIBRARY_PATH_VAR SHLIB_CFLAGS SHLIB_LD_LIBS SHLIB_LD STLIB_LD +LDFLAGS_OPTIMIZE +LDFLAGS_DEBUG CFLAGS_WARNING CFLAGS_OPTIMIZE CFLAGS_DEBUG +LIBOBJS RC -CELIB_DIR AR STUBS_BUILD SHARED_BUILD TCL_THREADS TCL_INCLUDES +PKG_CONFIG PKG_OBJECTS PKG_SOURCES EGREP GREP RANLIB @@ -715,10 +716,11 @@ htmldir infodir docdir oldincludedir includedir +runstatedir localstatedir sharedstatedir sysconfdir datadir datarootdir @@ -749,18 +751,17 @@ enable_shared enable_stubs enable_64bit enable_64bit_vis enable_rpath -enable_wince -with_celib enable_symbols enable_dtd enable_ns enable_ucmd enable_tdomalloc enable_lessns +enable_schema ' ac_precious_vars='build_alias host_alias target_alias CC @@ -805,10 +806,11 @@ datarootdir='${prefix}/share' datadir='${datarootdir}' sysconfdir='${prefix}/etc' sharedstatedir='${prefix}/com' localstatedir='${prefix}/var' +runstatedir='${localstatedir}/run' includedir='${prefix}/include' oldincludedir='/usr/include' docdir='${datarootdir}/doc/${PACKAGE_TARNAME}' infodir='${datarootdir}/info' htmldir='${docdir}' @@ -1056,10 +1058,19 @@ psdir=$ac_optarg ;; -q | -quiet | --quiet | --quie | --qui | --qu | --q \ | -silent | --silent | --silen | --sile | --sil) silent=yes ;; + + -runstatedir | --runstatedir | --runstatedi | --runstated \ + | --runstate | --runstat | --runsta | --runst | --runs \ + | --run | --ru | --r) + ac_prev=runstatedir ;; + -runstatedir=* | --runstatedir=* | --runstatedi=* | --runstated=* \ + | --runstate=* | --runstat=* | --runsta=* | --runst=* | --runs=* \ + | --run=* | --ru=* | --r=*) + runstatedir=$ac_optarg ;; -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb) ac_prev=sbindir ;; -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \ | --sbi=* | --sb=*) @@ -1194,11 +1205,11 @@ # Check all directory arguments for consistency. for ac_var in exec_prefix prefix bindir sbindir libexecdir datarootdir \ datadir sysconfdir sharedstatedir localstatedir includedir \ oldincludedir docdir infodir htmldir dvidir pdfdir psdir \ - libdir localedir mandir + libdir localedir mandir runstatedir do eval ac_val=\$$ac_var # Remove trailing slashes. case $ac_val in */ ) @@ -1347,10 +1358,11 @@ --sbindir=DIR system admin executables [EPREFIX/sbin] --libexecdir=DIR program executables [EPREFIX/libexec] --sysconfdir=DIR read-only single-machine data [PREFIX/etc] --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com] --localstatedir=DIR modifiable single-machine data [PREFIX/var] + --runstatedir=DIR modifiable per-process data [LOCALSTATEDIR/run] --libdir=DIR object code libraries [EPREFIX/lib] --includedir=DIR C header files [PREFIX/include] --oldincludedir=DIR C header files for non-gcc [/usr/include] --datarootdir=DIR read-only arch.-independent data root [PREFIX/share] --datadir=DIR read-only architecture-independent data [DATAROOTDIR] @@ -1384,18 +1396,18 @@ --enable-stubs build and link with stub libraries. Always true for shared builds (default: on) --enable-64bit enable 64bit support (default: off) --enable-64bit-vis enable 64bit Sparc VIS support (default: off) --disable-rpath disable rpath support (default: on) - --enable-wince enable Win/CE support (where applicable) --enable-symbols build with debugging symbols (default: off) --enable-dtd build with dtd support (default: on) --enable-ns build with XML namespace support (default: on) --enable-unknown enable built-in unknown command (default: off) --enable-tdomalloc build with the tDOM allocator (default: off) --enable-lessns build with lower limit for XML ns declarations (default: off) + --enable-schema build with valiation features (default: on) Optional Packages: --with-PACKAGE[=ARG] use PACKAGE [ARG=yes] --without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no) --with-tcl directory containing tcl configuration @@ -1402,11 +1414,10 @@ (tclConfig.sh) --with-aolserver directory with AOLserver distribution --with-expat directory with expat installation --with-entropy source of entropy to use --with-tclinclude directory containing the public Tcl header files - --with-celib=DIR use Windows/CE support library from DIR Some influential environment variables: CC C compiler command CFLAGS C compiler flags LDFLAGS linker flags, e.g. -L if you have libraries in a @@ -1754,10 +1765,151 @@ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 $as_echo "$ac_res" >&6; } eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno } # ac_fn_c_check_func + +# ac_fn_c_check_type LINENO TYPE VAR INCLUDES +# ------------------------------------------- +# Tests whether TYPE exists after having included INCLUDES, setting cache +# variable VAR accordingly. +ac_fn_c_check_type () +{ + as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 +$as_echo_n "checking for $2... " >&6; } +if eval \${$3+:} false; then : + $as_echo_n "(cached) " >&6 +else + eval "$3=no" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +$4 +int +main () +{ +if (sizeof ($2)) + return 0; + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +$4 +int +main () +{ +if (sizeof (($2))) + return 0; + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + +else + eval "$3=yes" +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +eval ac_res=\$$3 + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +$as_echo "$ac_res" >&6; } + eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno + +} # ac_fn_c_check_type + +# ac_fn_c_check_header_mongrel LINENO HEADER VAR INCLUDES +# ------------------------------------------------------- +# Tests whether HEADER exists, giving a warning if it cannot be compiled using +# the include files in INCLUDES and setting the cache variable VAR +# accordingly. +ac_fn_c_check_header_mongrel () +{ + as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + if eval \${$3+:} false; then : + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 +$as_echo_n "checking for $2... " >&6; } +if eval \${$3+:} false; then : + $as_echo_n "(cached) " >&6 +fi +eval ac_res=\$$3 + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +$as_echo "$ac_res" >&6; } +else + # Is the header compilable? +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking $2 usability" >&5 +$as_echo_n "checking $2 usability... " >&6; } +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +$4 +#include <$2> +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_header_compiler=yes +else + ac_header_compiler=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_header_compiler" >&5 +$as_echo "$ac_header_compiler" >&6; } + +# Is the header present? +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking $2 presence" >&5 +$as_echo_n "checking $2 presence... " >&6; } +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include <$2> +_ACEOF +if ac_fn_c_try_cpp "$LINENO"; then : + ac_header_preproc=yes +else + ac_header_preproc=no +fi +rm -f conftest.err conftest.i conftest.$ac_ext +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_header_preproc" >&5 +$as_echo "$ac_header_preproc" >&6; } + +# So? What about this header? +case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in #(( + yes:no: ) + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: accepted by the compiler, rejected by the preprocessor!" >&5 +$as_echo "$as_me: WARNING: $2: accepted by the compiler, rejected by the preprocessor!" >&2;} + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: proceeding with the compiler's result" >&5 +$as_echo "$as_me: WARNING: $2: proceeding with the compiler's result" >&2;} + ;; + no:yes:* ) + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: present but cannot be compiled" >&5 +$as_echo "$as_me: WARNING: $2: present but cannot be compiled" >&2;} + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: check for missing prerequisite headers?" >&5 +$as_echo "$as_me: WARNING: $2: check for missing prerequisite headers?" >&2;} + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: see the Autoconf documentation" >&5 +$as_echo "$as_me: WARNING: $2: see the Autoconf documentation" >&2;} + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: section \"Present But Cannot Be Compiled\"" >&5 +$as_echo "$as_me: WARNING: $2: section \"Present But Cannot Be Compiled\"" >&2;} + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: proceeding with the compiler's result" >&5 +$as_echo "$as_me: WARNING: $2: proceeding with the compiler's result" >&2;} + ;; +esac + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 +$as_echo_n "checking for $2... " >&6; } +if eval \${$3+:} false; then : + $as_echo_n "(cached) " >&6 +else + eval "$3=\$ac_header_compiler" +fi +eval ac_res=\$$3 + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +$as_echo "$ac_res" >&6; } +fi + eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno + +} # ac_fn_c_check_header_mongrel cat >config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. It was created by tdom $as_me 0.9.2, which was @@ -2132,11 +2284,11 @@ if test "${CFLAGS+set}" != "set" ; then CFLAGS="" fi case "`uname -s`" in - *win32*|*WIN32*|*MINGW32_*|*MINGW64_*) + *win32*|*WIN32*|*MINGW32_*|*MINGW64_*|*MSYS_*) # Extract the first word of "cygpath", so it can be a program name with args. set dummy cygpath; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_prog_CYGPATH+:} false; then : @@ -2251,10 +2403,13 @@ $as_echo "$as_me: WARNING: can't find uname command" >&2;} tcl_cv_sys_version=unknown else if test "`uname -s`" = "AIX" ; then tcl_cv_sys_version=AIX-`uname -v`.`uname -r` + fi + if test "`uname -s`" = "NetBSD" -a -f /etc/debian_version ; then + tcl_cv_sys_version=NetBSD-Debian fi fi fi fi @@ -2381,11 +2536,10 @@ # on Darwin, check in Framework installation locations if test "`uname -s`" = "Darwin" -a x"${ac_cv_c_tclconfig}" = x ; then for i in `ls -d ~/Library/Frameworks 2>/dev/null` \ `ls -d /Library/Frameworks 2>/dev/null` \ `ls -d /Network/Library/Frameworks 2>/dev/null` \ - `ls -d /System/Library/Frameworks 2>/dev/null` \ `ls -d /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/Library/Frameworks/Tcl.framework 2>/dev/null` \ `ls -d /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/Network/Library/Frameworks/Tcl.framework 2>/dev/null` \ `ls -d /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/Tcl.framework 2>/dev/null` \ ; do if test -f "$i/Tcl.framework/tclConfig.sh" ; then @@ -3266,14 +3420,10 @@ else { $as_echo "$as_me:${as_lineno-$LINENO}: result: could not find ${TCL_BIN_DIR}/tclConfig.sh" >&5 $as_echo "could not find ${TCL_BIN_DIR}/tclConfig.sh" >&6; } fi - # eval is required to do the TCL_DBGX substitution - eval "TCL_LIB_FILE=\"${TCL_LIB_FILE}\"" - eval "TCL_STUB_LIB_FILE=\"${TCL_STUB_LIB_FILE}\"" - # If the TCL_BIN_DIR is the build directory (not the install directory), # then set the common variable name to the value of the build variables. # For example, the variable TCL_LIB_SPEC will be set to the value # of TCL_BUILD_LIB_SPEC. An extension should make use of TCL_LIB_SPEC # instead of TCL_BUILD_LIB_SPEC since it will work with both an @@ -3303,16 +3453,10 @@ fi ;; esac fi - # eval is required to do the TCL_DBGX substitution - eval "TCL_LIB_FLAG=\"${TCL_LIB_FLAG}\"" - eval "TCL_LIB_SPEC=\"${TCL_LIB_SPEC}\"" - eval "TCL_STUB_LIB_FLAG=\"${TCL_STUB_LIB_FLAG}\"" - eval "TCL_STUB_LIB_SPEC=\"${TCL_STUB_LIB_SPEC}\"" - @@ -3342,11 +3486,12 @@ return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : - TEA_PLATFORM="unix" + # first test we've already retrieved platform (cross-compile), fallback to unix otherwise: + TEA_PLATFORM="${TEA_PLATFORM-unix}" CYGPATH=echo else TEA_PLATFORM="windows" @@ -4927,12 +5072,11 @@ { $as_echo "$as_me:${as_lineno-$LINENO}: result: Using bundled expat distribution" >&5 $as_echo "Using bundled expat distribution" >&6; } vars="expat/xmlrole.c \ expat/xmltok.c \ - expat/xmlparse.c \ - expat/loadlibrary.c" + expat/xmlparse.c" for i in $vars; do case $i in \$*) # allow $-var names PKG_SOURCES="$PKG_SOURCES $i" @@ -4987,11 +5131,11 @@ vars="-lexpat" for i in $vars; do if test "${TEA_PLATFORM}" = "windows" -a "$GCC" = "yes" ; then # Convert foo.lib to -lfoo for GCC. No-op if not *.lib - i=`echo "$i" | sed -e 's/^\([^-].*\)\.lib$/-l\1/i'` + i=`echo "$i" | sed -e 's/^\([^-].*\)\.[lL][iI][bB]$/-l\1/'` fi PKG_LIBS="$PKG_LIBS $i" done @@ -5180,15 +5324,171 @@ ;; *) as_fn_error $? "${with_entropy} not known." "$LINENO" 5 esac + +#-------------------------------------------------------------------- +# We need the UINT2PTR and PTR2UINT macros, so make sure that intptr_t +# is defined. +#-------------------------------------------------------------------- + +ac_fn_c_check_type "$LINENO" "uintptr_t" "ac_cv_type_uintptr_t" "$ac_includes_default" +if test "x$ac_cv_type_uintptr_t" = xyes; then : + + +$as_echo "#define HAVE_UINTPTR_T 1" >>confdefs.h + +else + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for pointer-size unsigned integer type" >&5 +$as_echo_n "checking for pointer-size unsigned integer type... " >&6; } +if ${tcl_cv_uintptr_t+:} false; then : + $as_echo_n "(cached) " >&6 +else + + for tcl_cv_uintptr_t in "unsigned int" "unsigned long" "unsigned long long" \ + none; do + if test "$tcl_cv_uintptr_t" != none; then + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +$ac_includes_default +int +main () +{ +static int test_array [1 - 2 * !(sizeof (void *) <= sizeof ($tcl_cv_uintptr_t))]; +test_array [0] = 0; +return test_array [0]; + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + tcl_ok=yes +else + tcl_ok=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + test "$tcl_ok" = yes && break; fi + done +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_uintptr_t" >&5 +$as_echo "$tcl_cv_uintptr_t" >&6; } + if test "$tcl_cv_uintptr_t" != none; then + +cat >>confdefs.h <<_ACEOF +#define uintptr_t $tcl_cv_uintptr_t +_ACEOF + + fi + +fi + #-------------------------------------------------------------------- # Add HTML5 parsing support. #-------------------------------------------------------------------- + + if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}pkg-config", so it can be a program name with args. +set dummy ${ac_tool_prefix}pkg-config; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_path_PKG_CONFIG+:} false; then : + $as_echo_n "(cached) " >&6 +else + case $PKG_CONFIG in + [\\/]* | ?:[\\/]*) + ac_cv_path_PKG_CONFIG="$PKG_CONFIG" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_path_PKG_CONFIG="$as_dir/$ac_word$ac_exec_ext" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + + ;; +esac +fi +PKG_CONFIG=$ac_cv_path_PKG_CONFIG +if test -n "$PKG_CONFIG"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $PKG_CONFIG" >&5 +$as_echo "$PKG_CONFIG" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_path_PKG_CONFIG"; then + ac_pt_PKG_CONFIG=$PKG_CONFIG + # Extract the first word of "pkg-config", so it can be a program name with args. +set dummy pkg-config; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_path_ac_pt_PKG_CONFIG+:} false; then : + $as_echo_n "(cached) " >&6 +else + case $ac_pt_PKG_CONFIG in + [\\/]* | ?:[\\/]*) + ac_cv_path_ac_pt_PKG_CONFIG="$ac_pt_PKG_CONFIG" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_path_ac_pt_PKG_CONFIG="$as_dir/$ac_word$ac_exec_ext" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + + ;; +esac +fi +ac_pt_PKG_CONFIG=$ac_cv_path_ac_pt_PKG_CONFIG +if test -n "$ac_pt_PKG_CONFIG"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_pt_PKG_CONFIG" >&5 +$as_echo "$ac_pt_PKG_CONFIG" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_pt_PKG_CONFIG" = x; then + PKG_CONFIG="" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + PKG_CONFIG=$ac_pt_PKG_CONFIG + fi +else + PKG_CONFIG="$ac_cv_path_PKG_CONFIG" +fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to enable support for HTML5 parsing (using gumbo)" >&5 $as_echo_n "checking whether to enable support for HTML5 parsing (using gumbo)... " >&6; } # Check whether --enable-html5 was given. if test "${enable_html5+set}" = set; then : @@ -5206,30 +5506,28 @@ fi HTML5_LIBS="" HTML5_INCLUDES="" if test "$tcl_ok" = "yes" ; then # Check if pkg-config is available - PKGCONFIG=no - pkg-config --version > /dev/null 2>&1 && PKGCONFIG=yes - if test "$PKGCONFIG" = no; then + if test "x$PKG_CONFIG" = x; then tcl_ok=no as_fn_error $? "cannot find pkg-config needed for --enable-html5." "$LINENO" 5 fi fi if test "$tcl_ok" = "yes" ; then - HAVEGUMBO=`pkg-config --exists gumbo && echo "1"` + HAVEGUMBO=`$PKG_CONFIG --exists gumbo && echo "1"` if test "$HAVEGUMBO" = "1" ; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 $as_echo "yes" >&6; } $as_echo "#define TDOM_HAVE_GUMBO 1" >>confdefs.h if test "${TEA_PLATFORM}" = "windows" ; then - HTML5_LIBS="-Wl,-Bstatic `pkg-config --static --libs gumbo` -Wl,-Bdynamic" + HTML5_LIBS="-Wl,-Bstatic `$PKG_CONFIG --static --libs gumbo` -Wl,-Bdynamic" else - HTML5_LIBS="`pkg-config --libs gumbo`" + HTML5_LIBS="`$PKG_CONFIG --libs gumbo`" fi - HTML5_INCLUDES="`pkg-config --cflags gumbo`" + HTML5_INCLUDES="`$PKG_CONFIG --cflags gumbo`" else as_fn_error $? "The required lib gumbo not found" "$LINENO" 5 fi else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 @@ -5259,11 +5557,11 @@ generic/tcldom.c \ generic/nodecmd.c \ generic/tdominit.c \ generic/tclexpat.c \ generic/tclpull.c \ - generic/structure.c \ + generic/schema.c \ generic/tdomStubInit.c" for i in $vars; do case $i in \$*) # allow $-var names @@ -5317,11 +5615,11 @@ vars="${AOL_LIBS} ${HTML5_LIBS}" for i in $vars; do if test "${TEA_PLATFORM}" = "windows" -a "$GCC" = "yes" ; then # Convert foo.lib to -lfoo for GCC. No-op if not *.lib - i=`echo "$i" | sed -e 's/^\([^-].*\)\.lib$/-l\1/i'` + i=`echo "$i" | sed -e 's/^\([^-].*\)\.[lL][iI][bB]$/-l\1/'` fi PKG_LIBS="$PKG_LIBS $i" done @@ -5800,22 +6098,10 @@ $as_echo "$as_me: WARNING: Building ${PACKAGE_NAME} without threads enabled, but building against Tcl that IS thread-enabled. It is recommended to use --enable-threads." >&2;} fi ;; - *) - if test "${TCL_THREADS}" = "1"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: - --enable-threads requested, but building against a Tcl that is NOT - thread-enabled. This is an OK configuration that will also run in - a thread-enabled core." >&5 -$as_echo "$as_me: WARNING: - --enable-threads requested, but building against a Tcl that is NOT - thread-enabled. This is an OK configuration that will also run in - a thread-enabled core." >&2;} - fi - ;; esac #-------------------------------------------------------------------- @@ -6083,28 +6369,10 @@ fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $doRpath" >&5 $as_echo "$doRpath" >&6; } - # TEA specific: Cross-compiling options for Windows/CE builds? - - if test "${TEA_PLATFORM}" = windows; then : - - { $as_echo "$as_me:${as_lineno-$LINENO}: checking if Windows/CE build is requested" >&5 -$as_echo_n "checking if Windows/CE build is requested... " >&6; } - # Check whether --enable-wince was given. -if test "${enable_wince+set}" = set; then : - enableval=$enable_wince; doWince=$enableval -else - doWince=no -fi - - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $doWince" >&5 -$as_echo "$doWince" >&6; } - -fi - # Set the variable "system" to hold the name and version number # for the system. { $as_echo "$as_me:${as_lineno-$LINENO}: checking system version" >&5 @@ -6123,10 +6391,13 @@ $as_echo "$as_me: WARNING: can't find uname command" >&2;} tcl_cv_sys_version=unknown else if test "`uname -s`" = "AIX" ; then tcl_cv_sys_version=AIX-`uname -v`.`uname -r` + fi + if test "`uname -s`" = "NetBSD" -a -f /etc/debian_version ; then + tcl_cv_sys_version=NetBSD-Debian fi fi fi fi @@ -6267,161 +6538,20 @@ SHLIB_VERSION=".$SHLIB_VERSION" fi case $system in # TEA specific: windows) - # This is a 2-stage check to make sure we have the 64-bit SDK - # We have to know where the SDK is installed. - # This magic is based on MS Platform SDK for Win2003 SP1 - hobbs - # MACHINE is IX86 for LINK, but this is used by the manifest, - # which requires x86|amd64|ia64. MACHINE="X86" if test "$do64bit" != "no" ; then - if test "x${MSSDK}x" = "xx" ; then - MSSDK="C:/Progra~1/Microsoft Platform SDK" - fi - MSSDK=`echo "$MSSDK" | sed -e 's!\\\!/!g'` - PATH64="" case "$do64bit" in amd64|x64|yes) MACHINE="AMD64" ; # default to AMD64 64-bit build - PATH64="${MSSDK}/Bin/Win64/x86/AMD64" ;; ia64) MACHINE="IA64" - PATH64="${MSSDK}/Bin/Win64" ;; esac - if test "$GCC" != "yes" -a ! -d "${PATH64}" ; then - { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Could not find 64-bit $MACHINE SDK to enable 64bit mode" >&5 -$as_echo "$as_me: WARNING: Could not find 64-bit $MACHINE SDK to enable 64bit mode" >&2;} - { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Ensure latest Platform SDK is installed" >&5 -$as_echo "$as_me: WARNING: Ensure latest Platform SDK is installed" >&2;} - do64bit="no" - else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: Using 64-bit $MACHINE mode" >&5 -$as_echo " Using 64-bit $MACHINE mode" >&6; } - do64bit_ok="yes" - fi - fi - - if test "$doWince" != "no" ; then - if test "$do64bit" != "no" ; then - as_fn_error $? "Windows/CE and 64-bit builds incompatible" "$LINENO" 5 - fi - if test "$GCC" = "yes" ; then - as_fn_error $? "Windows/CE and GCC builds incompatible" "$LINENO" 5 - fi - - # First, look for one uninstalled. - # the alternative search directory is invoked by --with-celib - - if test x"${no_celib}" = x ; then - # we reset no_celib in case something fails here - no_celib=true - -# Check whether --with-celib was given. -if test "${with_celib+set}" = set; then : - withval=$with_celib; with_celibconfig=${withval} -fi - - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for Windows/CE celib directory" >&5 -$as_echo_n "checking for Windows/CE celib directory... " >&6; } - if ${ac_cv_c_celibconfig+:} false; then : - $as_echo_n "(cached) " >&6 -else - - # First check to see if --with-celibconfig was specified. - if test x"${with_celibconfig}" != x ; then - if test -d "${with_celibconfig}/inc" ; then - ac_cv_c_celibconfig=`(cd ${with_celibconfig}; pwd)` - else - as_fn_error $? "${with_celibconfig} directory doesn't contain inc directory" "$LINENO" 5 - fi - fi - - # then check for a celib library - if test x"${ac_cv_c_celibconfig}" = x ; then - for i in \ - ../celib-palm-3.0 \ - ../celib \ - ../../celib-palm-3.0 \ - ../../celib \ - `ls -dr ../celib-*3.[0-9]* 2>/dev/null` \ - ${srcdir}/../celib-palm-3.0 \ - ${srcdir}/../celib \ - `ls -dr ${srcdir}/../celib-*3.[0-9]* 2>/dev/null` \ - ; do - if test -d "$i/inc" ; then - ac_cv_c_celibconfig=`(cd $i; pwd)` - break - fi - done - fi - -fi - - if test x"${ac_cv_c_celibconfig}" = x ; then - as_fn_error $? "Cannot find celib support library directory" "$LINENO" 5 - else - no_celib= - CELIB_DIR=${ac_cv_c_celibconfig} - CELIB_DIR=`echo "$CELIB_DIR" | sed -e 's!\\\!/!g'` - { $as_echo "$as_me:${as_lineno-$LINENO}: result: found $CELIB_DIR" >&5 -$as_echo "found $CELIB_DIR" >&6; } - fi - fi - - # Set defaults for common evc4/PPC2003 setup - # Currently Tcl requires 300+, possibly 420+ for sockets - CEVERSION=420; # could be 211 300 301 400 420 ... - TARGETCPU=ARMV4; # could be ARMV4 ARM MIPS SH3 X86 ... - ARCH=ARM; # could be ARM MIPS X86EM ... - PLATFORM="Pocket PC 2003"; # or "Pocket PC 2002" - if test "$doWince" != "yes"; then - # If !yes then the user specified something - # Reset ARCH to allow user to skip specifying it - ARCH= - eval `echo $doWince | awk -F, '{ \ - if (length($1)) { printf "CEVERSION=\"%s\"\n", $1; \ - if ($1 < 400) { printf "PLATFORM=\"Pocket PC 2002\"\n" } }; \ - if (length($2)) { printf "TARGETCPU=\"%s\"\n", toupper($2) }; \ - if (length($3)) { printf "ARCH=\"%s\"\n", toupper($3) }; \ - if (length($4)) { printf "PLATFORM=\"%s\"\n", $4 }; \ - }'` - if test "x${ARCH}" = "x" ; then - ARCH=$TARGETCPU; - fi - fi - OSVERSION=WCE$CEVERSION; - if test "x${WCEROOT}" = "x" ; then - WCEROOT="C:/Program Files/Microsoft eMbedded C++ 4.0" - if test ! -d "${WCEROOT}" ; then - WCEROOT="C:/Program Files/Microsoft eMbedded Tools" - fi - fi - if test "x${SDKROOT}" = "x" ; then - SDKROOT="C:/Program Files/Windows CE Tools" - if test ! -d "${SDKROOT}" ; then - SDKROOT="C:/Windows CE Tools" - fi - fi - WCEROOT=`echo "$WCEROOT" | sed -e 's!\\\!/!g'` - SDKROOT=`echo "$SDKROOT" | sed -e 's!\\\!/!g'` - if test ! -d "${SDKROOT}/${OSVERSION}/${PLATFORM}/Lib/${TARGETCPU}" \ - -o ! -d "${WCEROOT}/EVC/${OSVERSION}/bin"; then - as_fn_error $? "could not find PocketPC SDK or target compiler to enable WinCE mode $CEVERSION,$TARGETCPU,$ARCH,$PLATFORM" "$LINENO" 5 - doWince="no" - else - # We could PATH_NOSPACE these, but that's not important, - # as long as we quote them when used. - CEINCLUDE="${SDKROOT}/${OSVERSION}/${PLATFORM}/include" - if test -d "${CEINCLUDE}/${TARGETCPU}" ; then - CEINCLUDE="${CEINCLUDE}/${TARGETCPU}" - fi - CELIBPATH="${SDKROOT}/${OSVERSION}/${PLATFORM}/Lib/${TARGETCPU}" - fi fi if test "$GCC" != "yes" ; then if test "${SHARED_BUILD}" = "0" ; then runtime=-MT @@ -6434,11 +6564,11 @@ vars="ucrt.lib" for i in $vars; do if test "${TEA_PLATFORM}" = "windows" -a "$GCC" = "yes" ; then # Convert foo.lib to -lfoo for GCC. No-op if not *.lib - i=`echo "$i" | sed -e 's/^\([^-].*\)\.lib$/-l\1/i'` + i=`echo "$i" | sed -e 's/^\([^-].*\)\.[lL][iI][bB]$/-l\1/'` fi PKG_LIBS="$PKG_LIBS $i" done @@ -6446,69 +6576,29 @@ *) ;; esac if test "$do64bit" != "no" ; then - # All this magic is necessary for the Win64 SDK RC1 - hobbs - CC="\"${PATH64}/cl.exe\"" - CFLAGS="${CFLAGS} -I\"${MSSDK}/Include\" -I\"${MSSDK}/Include/crt\" -I\"${MSSDK}/Include/crt/sys\"" - RC="\"${MSSDK}/bin/rc.exe\"" - lflags="${lflags} -nologo -MACHINE:${MACHINE} -LIBPATH:\"${MSSDK}/Lib/${MACHINE}\"" - LINKBIN="\"${PATH64}/link.exe\"" + CC="cl.exe" + RC="rc.exe" + lflags="${lflags} -nologo -MACHINE:${MACHINE} " + LINKBIN="link.exe" CFLAGS_DEBUG="-nologo -Zi -Od -W3 ${runtime}d" CFLAGS_OPTIMIZE="-nologo -O2 -W2 ${runtime}" # Avoid 'unresolved external symbol __security_cookie' # errors, c.f. http://support.microsoft.com/?id=894573 vars="bufferoverflowU.lib" for i in $vars; do if test "${TEA_PLATFORM}" = "windows" -a "$GCC" = "yes" ; then # Convert foo.lib to -lfoo for GCC. No-op if not *.lib - i=`echo "$i" | sed -e 's/^\([^-].*\)\.lib$/-l\1/i'` + i=`echo "$i" | sed -e 's/^\([^-].*\)\.[lL][iI][bB]$/-l\1/'` fi PKG_LIBS="$PKG_LIBS $i" done - elif test "$doWince" != "no" ; then - CEBINROOT="${WCEROOT}/EVC/${OSVERSION}/bin" - if test "${TARGETCPU}" = "X86"; then - CC="\"${CEBINROOT}/cl.exe\"" - else - CC="\"${CEBINROOT}/cl${ARCH}.exe\"" - fi - CFLAGS="$CFLAGS -I\"${CELIB_DIR}/inc\" -I\"${CEINCLUDE}\"" - RC="\"${WCEROOT}/Common/EVC/bin/rc.exe\"" - arch=`echo ${ARCH} | awk '{print tolower($0)}'` - defs="${ARCH} _${ARCH}_ ${arch} PALM_SIZE _MT _WINDOWS" - if test "${SHARED_BUILD}" = "1" ; then - # Static CE builds require static celib as well - defs="${defs} _DLL" - fi - for i in $defs ; do - -cat >>confdefs.h <<_ACEOF -#define $i 1 -_ACEOF - - done - -cat >>confdefs.h <<_ACEOF -#define _WIN32_WCE $CEVERSION -_ACEOF - - -cat >>confdefs.h <<_ACEOF -#define UNDER_CE $CEVERSION -_ACEOF - - CFLAGS_DEBUG="-nologo -Zi -Od" - CFLAGS_OPTIMIZE="-nologo -Ox" - lversion=`echo ${CEVERSION} | sed -e 's/\(.\)\(..\)/\1\.\2/'` - lflags="${lflags} -MACHINE:${ARCH} -LIBPATH:\"${CELIBPATH}\" -subsystem:windowsce,${lversion} -nologo" - LINKBIN="\"${CEBINROOT}/link.exe\"" - else RC="rc" lflags="${lflags} -nologo" LINKBIN="link" CFLAGS_DEBUG="-nologo -Z7 -Od -W3 -WX ${runtime}d" @@ -6648,18 +6738,18 @@ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_cross" >&5 $as_echo "$ac_cv_cross" >&6; } if test "$ac_cv_cross" = "yes"; then case "$do64bit" in amd64|x64|yes) - CC="x86_64-w64-mingw32-gcc" + CC="x86_64-w64-mingw32-${CC}" LD="x86_64-w64-mingw32-ld" AR="x86_64-w64-mingw32-ar" RANLIB="x86_64-w64-mingw32-ranlib" RC="x86_64-w64-mingw32-windres" ;; *) - CC="i686-w64-mingw32-gcc" + CC="i686-w64-mingw32-${CC}" LD="i686-w64-mingw32-ld" AR="i686-w64-mingw32-ar" RANLIB="i686-w64-mingw32-ranlib" RC="i686-w64-mingw32-windres" ;; @@ -6677,26 +6767,21 @@ # and also # http://msdn2.microsoft.com/en-us/library/y0zzbyt4%28VS.80%29.aspx # This essentially turns it all on. LDFLAGS_DEBUG="-debug -debugtype:cv" LDFLAGS_OPTIMIZE="-release" - if test "$doWince" != "no" ; then - LDFLAGS_CONSOLE="-link ${lflags}" - LDFLAGS_WINDOW=${LDFLAGS_CONSOLE} - else - LDFLAGS_CONSOLE="-link -subsystem:console ${lflags}" - LDFLAGS_WINDOW="-link -subsystem:windows ${lflags}" - fi + LDFLAGS_CONSOLE="-link -subsystem:console ${lflags}" + LDFLAGS_WINDOW="-link -subsystem:windows ${lflags}" fi SHLIB_SUFFIX=".dll" SHARED_LIB_SUFFIX='${TCL_TRIM_DOTS}.dll' TCL_LIB_VERSIONS_OK=nodots ;; AIX-*) - if test "${TCL_THREADS}" = "1" -a "$GCC" != "yes"; then : + if test "$GCC" != "yes"; then : # AIX requires the _r compiler when gcc isn't being used case "${CC}" in *_r|*_r\ *) # ok ... @@ -6741,18 +6826,18 @@ # AIX-5 uses ELF style dynamic libraries on IA-64, but not PPC SHLIB_LD="/usr/ccs/bin/ld -G -z text" if test "$GCC" = yes; then : - CC_SEARCH_FLAGS='-Wl,-R,${LIB_RUNTIME_DIR}' + CC_SEARCH_FLAGS='"-Wl,-R,${LIB_RUNTIME_DIR}"' else - CC_SEARCH_FLAGS='-R${LIB_RUNTIME_DIR}' + CC_SEARCH_FLAGS='"-R${LIB_RUNTIME_DIR}"' fi - LD_SEARCH_FLAGS='-R ${LIB_RUNTIME_DIR}' + LD_SEARCH_FLAGS='-R "${LIB_RUNTIME_DIR}"' else if test "$GCC" = yes; then : @@ -6763,11 +6848,11 @@ SHLIB_LD="/bin/ld -bhalt:4 -bM:SRE -bexpall -H512 -T512 -bnoentry" LDFLAGS="$LDFLAGS -brtl" fi SHLIB_LD="${SHLIB_LD} ${SHLIB_LD_FLAGS}" - CC_SEARCH_FLAGS='-L${LIB_RUNTIME_DIR}' + CC_SEARCH_FLAGS='"-L${LIB_RUNTIME_DIR}"' LD_SEARCH_FLAGS=${CC_SEARCH_FLAGS} fi ;; BeOS*) @@ -6819,10 +6904,17 @@ if test "x$ac_cv_lib_bind_inet_ntoa" = xyes; then : LIBS="$LIBS -lbind -lsocket" fi ;; + BSD/OS-2.1*|BSD/OS-3*) + SHLIB_CFLAGS="" + SHLIB_LD="shlicc -r" + SHLIB_SUFFIX=".so" + CC_SEARCH_FLAGS="" + LD_SEARCH_FLAGS="" + ;; BSD/OS-4.*) SHLIB_CFLAGS="-export-dynamic -fPIC" SHLIB_LD='${CC} -shared' SHLIB_SUFFIX=".so" LDFLAGS="$LDFLAGS -export-dynamic" @@ -6830,14 +6922,22 @@ LD_SEARCH_FLAGS="" ;; CYGWIN_*) SHLIB_CFLAGS="" SHLIB_LD='${CC} -shared' - SHLIB_LD_LIBS="${SHLIB_LD_LIBS} -Wl,--out-implib,\$@.a" SHLIB_SUFFIX=".dll" + SHLIB_LD_LIBS="${SHLIB_LD_LIBS} -Wl,--out-implib,\$@.a" EXEEXT=".exe" do64bit_ok=yes + CC_SEARCH_FLAGS="" + LD_SEARCH_FLAGS="" + ;; + dgux*) + SHLIB_CFLAGS="-K PIC" + SHLIB_LD='${CC} -G' + SHLIB_LD_LIBS="" + SHLIB_SUFFIX=".so" CC_SEARCH_FLAGS="" LD_SEARCH_FLAGS="" ;; Haiku*) LDFLAGS="$LDFLAGS -Wl,--export-dynamic" @@ -6895,14 +6995,10 @@ #LIBS="$LIBS -lxnet" # Use the XOPEN network library if test "`uname -m`" = ia64; then : SHLIB_SUFFIX=".so" - # Use newer C++ library for C++ extensions - #if test "$GCC" != "yes" ; then - # CPPFLAGS="-AA" - #fi else SHLIB_SUFFIX=".sl" @@ -6949,13 +7045,15 @@ tcl_ok=no fi if test "$tcl_ok" = yes; then : + SHLIB_CFLAGS="+z" + SHLIB_LD="ld -b" LDFLAGS="$LDFLAGS -Wl,-E" - CC_SEARCH_FLAGS='-Wl,+s,+b,${LIB_RUNTIME_DIR}:.' - LD_SEARCH_FLAGS='+s +b ${LIB_RUNTIME_DIR}:.' + CC_SEARCH_FLAGS='"-Wl,+s,+b,${LIB_RUNTIME_DIR}:."' + LD_SEARCH_FLAGS='+s +b "${LIB_RUNTIME_DIR}:."' LD_LIBRARY_PATH_VAR="SHLIB_PATH" fi if test "$GCC" = yes; then : @@ -6963,14 +7061,10 @@ LD_SEARCH_FLAGS=${CC_SEARCH_FLAGS} else CFLAGS="$CFLAGS -z" - # Users may want PA-RISC 1.1/2.0 portable code - needs HP cc - #CFLAGS="$CFLAGS +DAportable" - SHLIB_CFLAGS="+z" - SHLIB_LD="ld -b" fi # Check to enable 64-bit flags for compiler/linker if test "$do64bit" = "yes"; then : @@ -6982,11 +7076,11 @@ # 64-bit gcc in use. Fix flags for GNU ld. do64bit_ok=yes SHLIB_LD='${CC} -shared' if test $doRpath = yes; then : - CC_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}' + CC_SEARCH_FLAGS='"-Wl,-rpath,${LIB_RUNTIME_DIR}"' fi LD_SEARCH_FLAGS=${CC_SEARCH_FLAGS} ;; *) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: 64bit mode not supported with GCC on $system" >&5 @@ -7001,18 +7095,89 @@ LDFLAGS_ARCH="+DD64" fi fi ;; + HP-UX-*.08.*|HP-UX-*.09.*|HP-UX-*.10.*) + SHLIB_SUFFIX=".sl" + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for shl_load in -ldld" >&5 +$as_echo_n "checking for shl_load in -ldld... " >&6; } +if ${ac_cv_lib_dld_shl_load+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-ldld $LIBS" +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char shl_load (); +int +main () +{ +return shl_load (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + ac_cv_lib_dld_shl_load=yes +else + ac_cv_lib_dld_shl_load=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dld_shl_load" >&5 +$as_echo "$ac_cv_lib_dld_shl_load" >&6; } +if test "x$ac_cv_lib_dld_shl_load" = xyes; then : + tcl_ok=yes +else + tcl_ok=no +fi + + if test "$tcl_ok" = yes; then : + + SHLIB_CFLAGS="+z" + SHLIB_LD="ld -b" + SHLIB_LD_LIBS="" + LDFLAGS="$LDFLAGS -Wl,-E" + CC_SEARCH_FLAGS='"-Wl,+s,+b,${LIB_RUNTIME_DIR}:."' + LD_SEARCH_FLAGS='+s +b "${LIB_RUNTIME_DIR}:."' + LD_LIBRARY_PATH_VAR="SHLIB_PATH" + +fi ;; + IRIX-5.*) + SHLIB_CFLAGS="" + SHLIB_LD="ld -shared -rdata_shared" + SHLIB_SUFFIX=".so" + case " $LIBOBJS " in + *" mkstemp.$ac_objext "* ) ;; + *) LIBOBJS="$LIBOBJS mkstemp.$ac_objext" + ;; +esac + + if test $doRpath = yes; then : + + CC_SEARCH_FLAGS='"-Wl,-rpath,${LIB_RUNTIME_DIR}"' + LD_SEARCH_FLAGS='-rpath "${LIB_RUNTIME_DIR}"' +fi + ;; IRIX-6.*) SHLIB_CFLAGS="" SHLIB_LD="ld -n32 -shared -rdata_shared" SHLIB_SUFFIX=".so" if test $doRpath = yes; then : - CC_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}' - LD_SEARCH_FLAGS='-rpath ${LIB_RUNTIME_DIR}' + CC_SEARCH_FLAGS='"-Wl,-rpath,${LIB_RUNTIME_DIR}"' + LD_SEARCH_FLAGS='-rpath "${LIB_RUNTIME_DIR}"' fi if test "$GCC" = yes; then : CFLAGS="$CFLAGS -mabi=n32" LDFLAGS="$LDFLAGS -mabi=n32" @@ -7036,12 +7201,12 @@ SHLIB_CFLAGS="" SHLIB_LD="ld -n32 -shared -rdata_shared" SHLIB_SUFFIX=".so" if test $doRpath = yes; then : - CC_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}' - LD_SEARCH_FLAGS='-rpath ${LIB_RUNTIME_DIR}' + CC_SEARCH_FLAGS='"-Wl,-rpath,${LIB_RUNTIME_DIR}"' + LD_SEARCH_FLAGS='-rpath "${LIB_RUNTIME_DIR}"' fi # Check to enable 64-bit flags for compiler/linker if test "$do64bit" = yes; then : @@ -7060,23 +7225,36 @@ fi fi ;; - Linux*|GNU*|NetBSD-Debian) + Linux*|GNU*|NetBSD-Debian|DragonFly-*|FreeBSD-*) SHLIB_CFLAGS="-fPIC" SHLIB_SUFFIX=".so" # TEA specific: CFLAGS_OPTIMIZE="-O2 -fomit-frame-pointer" # TEA specific: use LDFLAGS_DEFAULT instead of LDFLAGS SHLIB_LD='${CC} ${CFLAGS} ${LDFLAGS_DEFAULT} -shared' LDFLAGS="$LDFLAGS -Wl,--export-dynamic" + + case $system in + DragonFly-*|FreeBSD-*) + if test "${TCL_THREADS}" = "1"; then : + + # The -pthread needs to go in the LDFLAGS, not LIBS + LIBS=`echo $LIBS | sed s/-pthread//` + CFLAGS="$CFLAGS $PTHREAD_CFLAGS" + LDFLAGS="$LDFLAGS $PTHREAD_LIBS" +fi + ;; + esac + if test $doRpath = yes; then : - CC_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}' + CC_SEARCH_FLAGS='"-Wl,-rpath,${LIB_RUNTIME_DIR}"' fi LD_SEARCH_FLAGS=${CC_SEARCH_FLAGS} if test "`uname -m`" = "alpha"; then : CFLAGS="$CFLAGS -mieee" fi @@ -7137,12 +7315,12 @@ CFLAGS_OPTIMIZE=-02 SHLIB_LD='${CC} -shared' LD_FLAGS="-Wl,--export-dynamic" if test $doRpath = yes; then : - CC_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}' - LD_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}' + CC_SEARCH_FLAGS='"-Wl,-rpath,${LIB_RUNTIME_DIR}"' + LD_SEARCH_FLAGS='"-Wl,-rpath,${LIB_RUNTIME_DIR}"' fi ;; OpenBSD-*) arch=`arch -s` case "$arch" in @@ -7155,24 +7333,20 @@ esac SHLIB_LD='${CC} ${SHLIB_CFLAGS} -shared' SHLIB_SUFFIX=".so" if test $doRpath = yes; then : - CC_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}' + CC_SEARCH_FLAGS='"-Wl,-rpath,${LIB_RUNTIME_DIR}"' fi LD_SEARCH_FLAGS=${CC_SEARCH_FLAGS} SHARED_LIB_SUFFIX='${TCL_TRIM_DOTS}.so${SHLIB_VERSION}' - LDFLAGS="-Wl,-export-dynamic" + LDFLAGS="$LDFLAGS -Wl,-export-dynamic" CFLAGS_OPTIMIZE="-O2" - if test "${TCL_THREADS}" = "1"; then : - - # On OpenBSD: Compile with -pthread - # Don't link with -lpthread - LIBS=`echo $LIBS | sed s/-lpthread//` - CFLAGS="$CFLAGS -pthread" - -fi + # On OpenBSD: Compile with -pthread + # Don't link with -lpthread + LIBS=`echo $LIBS | sed s/-lpthread//` + CFLAGS="$CFLAGS -pthread" # OpenBSD doesn't do version numbers with dots. UNSHARED_LIB_SUFFIX='${TCL_TRIM_DOTS}.a' TCL_LIB_VERSIONS_OK=nodots ;; NetBSD-*) @@ -7181,50 +7355,17 @@ SHLIB_LD='${CC} ${SHLIB_CFLAGS} -shared' SHLIB_SUFFIX=".so" LDFLAGS="$LDFLAGS -export-dynamic" if test $doRpath = yes; then : - CC_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}' + CC_SEARCH_FLAGS='"-Wl,-rpath,${LIB_RUNTIME_DIR}"' fi LD_SEARCH_FLAGS=${CC_SEARCH_FLAGS} - if test "${TCL_THREADS}" = "1"; then : - - # The -pthread needs to go in the CFLAGS, not LIBS - LIBS=`echo $LIBS | sed s/-pthread//` - CFLAGS="$CFLAGS -pthread" - LDFLAGS="$LDFLAGS -pthread" - -fi - ;; - FreeBSD-*) - # This configuration from FreeBSD Ports. - SHLIB_CFLAGS="-fPIC" - SHLIB_LD="${CC} -shared" - SHLIB_LD_LIBS="${SHLIB_LD_LIBS} -Wl,-soname,\$@" - SHLIB_SUFFIX=".so" - LDFLAGS="" - if test $doRpath = yes; then : - - CC_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}' - LD_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}' -fi - if test "${TCL_THREADS}" = "1"; then : - - # The -pthread needs to go in the LDFLAGS, not LIBS - LIBS=`echo $LIBS | sed s/-pthread//` - CFLAGS="$CFLAGS $PTHREAD_CFLAGS" - LDFLAGS="$LDFLAGS $PTHREAD_LIBS" -fi - case $system in - FreeBSD-3.*) - # Version numbers are dot-stripped by system policy. - TCL_TRIM_DOTS=`echo ${PACKAGE_VERSION} | tr -d .` - UNSHARED_LIB_SUFFIX='${TCL_TRIM_DOTS}.a' - SHARED_LIB_SUFFIX='${TCL_TRIM_DOTS}\$\{DBGX\}.so.1' - TCL_LIB_VERSIONS_OK=nodots - ;; - esac + # The -pthread needs to go in the CFLAGS, not LIBS + LIBS=`echo $LIBS | sed s/-pthread//` + CFLAGS="$CFLAGS -pthread" + LDFLAGS="$LDFLAGS -pthread" ;; Darwin-*) CFLAGS_OPTIMIZE="-Os" SHLIB_CFLAGS="-fno-common" # To avoid discrepancies between what headers configure sees during @@ -7367,16 +7508,10 @@ fi # TEA specific: link shlib with current and compatibility version flags vers=`echo ${PACKAGE_VERSION} | sed -e 's/^\([0-9]\{1,5\}\)\(\(\.[0-9]\{1,3\}\)\{0,2\}\).*$/\1\2/p' -e d` SHLIB_LD="${SHLIB_LD} -current_version ${vers:-0} -compatibility_version ${vers:-0}" SHLIB_SUFFIX=".dylib" - # Don't use -prebind when building for Mac OS X 10.4 or later only: - if test "`echo "${MACOSX_DEPLOYMENT_TARGET}" | awk -F '10\\.' '{print int($2)}'`" -lt 4 -a \ - "`echo "${CPPFLAGS}" | awk -F '-mmacosx-version-min=10\\.' '{print int($2)}'`" -lt 4; then : - - LDFLAGS="$LDFLAGS -prebind" -fi LDFLAGS="$LDFLAGS -headerpad_max_install_names" { $as_echo "$as_me:${as_lineno-$LINENO}: checking if ld accepts -search_paths_first flag" >&5 $as_echo_n "checking if ld accepts -search_paths_first flag... " >&6; } if ${tcl_cv_ld_search_paths_first+:} false; then : $as_echo_n "(cached) " >&6 @@ -7536,35 +7671,31 @@ fi SHLIB_SUFFIX=".so" if test $doRpath = yes; then : - CC_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}' + CC_SEARCH_FLAGS='"-Wl,-rpath,${LIB_RUNTIME_DIR}"' LD_SEARCH_FLAGS='-rpath ${LIB_RUNTIME_DIR}' fi if test "$GCC" = yes; then : CFLAGS="$CFLAGS -mieee" else CFLAGS="$CFLAGS -DHAVE_TZSET -std1 -ieee" fi # see pthread_intro(3) for pthread support on osf1, k.furukawa - if test "${TCL_THREADS}" = 1; then : - - CFLAGS="$CFLAGS -DHAVE_PTHREAD_ATTR_SETSTACKSIZE" - CFLAGS="$CFLAGS -DTCL_THREAD_STACK_MIN=PTHREAD_STACK_MIN*64" - LIBS=`echo $LIBS | sed s/-lpthreads//` - if test "$GCC" = yes; then : - - LIBS="$LIBS -lpthread -lmach -lexc" + CFLAGS="$CFLAGS -DHAVE_PTHREAD_ATTR_SETSTACKSIZE" + CFLAGS="$CFLAGS -DTCL_THREAD_STACK_MIN=PTHREAD_STACK_MIN*64" + LIBS=`echo $LIBS | sed s/-lpthreads//` + if test "$GCC" = yes; then : + + LIBS="$LIBS -lpthread -lmach -lexc" else - CFLAGS="$CFLAGS -pthread" - LDFLAGS="$LDFLAGS -pthread" - -fi + CFLAGS="$CFLAGS -pthread" + LDFLAGS="$LDFLAGS -pthread" fi ;; QNX-6*) # QNX RTP @@ -7610,17 +7741,17 @@ SHLIB_CFLAGS="-KPIC" SHLIB_SUFFIX=".so" if test "$GCC" = yes; then : SHLIB_LD='${CC} -shared' - CC_SEARCH_FLAGS='-Wl,-R,${LIB_RUNTIME_DIR}' + CC_SEARCH_FLAGS='"-Wl,-R,${LIB_RUNTIME_DIR}"' LD_SEARCH_FLAGS=${CC_SEARCH_FLAGS} else SHLIB_LD="/usr/ccs/bin/ld -G -z text" - CC_SEARCH_FLAGS='-R ${LIB_RUNTIME_DIR}' + CC_SEARCH_FLAGS='-R "${LIB_RUNTIME_DIR}"' LD_SEARCH_FLAGS=${CC_SEARCH_FLAGS} fi ;; SunOS-5*) @@ -7716,11 +7847,11 @@ SHLIB_SUFFIX=".so" if test "$GCC" = yes; then : SHLIB_LD='${CC} -shared' - CC_SEARCH_FLAGS='-Wl,-R,${LIB_RUNTIME_DIR}' + CC_SEARCH_FLAGS='"-Wl,-R,${LIB_RUNTIME_DIR}"' LD_SEARCH_FLAGS=${CC_SEARCH_FLAGS} if test "$do64bit_ok" = yes; then : if test "$arch" = "sparcv9 sparc"; then : @@ -7753,12 +7884,12 @@ # TEA specific: use LDFLAGS_DEFAULT instead of LDFLAGS SHLIB_LD='${CC} -G -z text ${LDFLAGS_DEFAULT}';; *) SHLIB_LD='/usr/ccs/bin/ld -G -z text';; esac - CC_SEARCH_FLAGS='-Wl,-R,${LIB_RUNTIME_DIR}' - LD_SEARCH_FLAGS='-R ${LIB_RUNTIME_DIR}' + CC_SEARCH_FLAGS='"-Wl,-R,${LIB_RUNTIME_DIR}"' + LD_SEARCH_FLAGS='-R "${LIB_RUNTIME_DIR}"' fi ;; UNIX_SV* | UnixWare-5*) SHLIB_CFLAGS="-KPIC" @@ -7827,13 +7958,13 @@ if test "$GCC" = yes; then : case $system in AIX-*) ;; BSD/OS*) ;; - CYGWIN_*|MINGW32_*|MINGW64_*) ;; + CYGWIN_*|MINGW32_*|MINGW64_*|MSYS_*) ;; IRIX*) ;; - NetBSD-*|FreeBSD-*|OpenBSD-*) ;; + NetBSD-*|DragonFly-*|FreeBSD-*|OpenBSD-*) ;; Darwin-*) ;; SCO_SV-3.2*) ;; windows) ;; *) SHLIB_CFLAGS="-fPIC" ;; esac @@ -8032,10 +8163,21 @@ $as_echo "#define HAVE_CAST_TO_UNION 1" >>confdefs.h fi + ac_fn_c_check_header_mongrel "$LINENO" "stdbool.h" "ac_cv_header_stdbool_h" "$ac_includes_default" +if test "x$ac_cv_header_stdbool_h" = xyes; then : + +$as_echo "#define HAVE_STDBOOL_H 1" >>confdefs.h + +fi + + + + + @@ -8225,11 +8367,11 @@ tcl_type_64bit=__int64 else tcl_type_64bit="long long" fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext - # See if we should use long anyway Note that we substitute in the + # See if we could use long anyway Note that we substitute in the # type that is our current guess for a 64-bit type inside this check # program, so it should be modified only carefully... cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ @@ -8251,12 +8393,12 @@ if test "${tcl_cv_type_64bit}" = none ; then $as_echo "#define TCL_WIDE_INT_IS_LONG 1" >>confdefs.h - { $as_echo "$as_me:${as_lineno-$LINENO}: result: using long" >&5 -$as_echo "using long" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } elif test "${tcl_cv_type_64bit}" = "__int64" \ -a "${TEA_PLATFORM}" = "windows" ; then # TEA specific: We actually want to use the default tcl.h checks in # this case to handle both TCL_WIDE_INT_TYPE and TCL_LL_MODIFIER* { $as_echo "$as_me:${as_lineno-$LINENO}: result: using Tcl header defaults" >&5 @@ -8300,10 +8442,44 @@ $as_echo "$tcl_cv_struct_dirent64" >&6; } if test "x${tcl_cv_struct_dirent64}" = "xyes" ; then $as_echo "#define HAVE_STRUCT_DIRENT64 1" >>confdefs.h + fi + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for DIR64" >&5 +$as_echo_n "checking for DIR64... " >&6; } +if ${tcl_cv_DIR64+:} false; then : + $as_echo_n "(cached) " >&6 +else + + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +#include +int +main () +{ +struct dirent64 *p; DIR64 d = opendir64("."); + p = readdir64(d); rewinddir64(d); closedir64(d); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + tcl_cv_DIR64=yes +else + tcl_cv_DIR64=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_DIR64" >&5 +$as_echo "$tcl_cv_DIR64" >&6; } + if test "x${tcl_cv_DIR64}" = "xyes" ; then + +$as_echo "#define HAVE_DIR64 1" >>confdefs.h + fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for struct stat64" >&5 $as_echo_n "checking for struct stat64... " >&6; } if ${tcl_cv_struct_stat64+:} false; then : @@ -8407,11 +8583,10 @@ enableval=$enable_symbols; tcl_ok=$enableval else tcl_ok=no fi - DBGX="" if test "$tcl_ok" = "no"; then CFLAGS_DEFAULT="${CFLAGS_OPTIMIZE} -DNDEBUG" LDFLAGS_DEFAULT="${LDFLAGS_OPTIMIZE}" { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } @@ -8421,15 +8596,10 @@ if test "$tcl_ok" = "yes"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes (standard debugging)" >&5 $as_echo "yes (standard debugging)" >&6; } fi fi - # TEA specific: - if test "${TEA_PLATFORM}" != "windows" ; then - LDFLAGS_DEFAULT="${LDFLAGS}" - fi - if test "$tcl_ok" = "mem" -o "$tcl_ok" = "all"; then @@ -8455,11 +8625,11 @@ #-------------------------------------------------------------------- if test "${TEA_PLATFORM}" = "windows" -a "$GCC" != "yes"; then MAKE_STATIC_LIB="\${STLIB_LD} -out:\$@ \$(PKG_OBJECTS)" - MAKE_SHARED_LIB="\${SHLIB_LD} \${SHLIB_LD_LIBS} \${LDFLAGS_DEFAULT} -out:\$@ \$(PKG_OBJECTS)" + MAKE_SHARED_LIB="\${SHLIB_LD} \${LDFLAGS} \${LDFLAGS_DEFAULT} -out:\$@ \$(PKG_OBJECTS) \${SHLIB_LD_LIBS}" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #if defined(_MSC_VER) && _MSC_VER >= 1400 print("manifest needed") @@ -8481,11 +8651,11 @@ rm -f conftest* MAKE_STUB_LIB="\${STLIB_LD} -nodefaultlib -out:\$@ \$(PKG_STUB_OBJECTS)" else MAKE_STATIC_LIB="\${STLIB_LD} \$@ \$(PKG_OBJECTS)" - MAKE_SHARED_LIB="\${SHLIB_LD} -o \$@ \$(PKG_OBJECTS) \${SHLIB_LD_LIBS}" + MAKE_SHARED_LIB="\${SHLIB_LD} \${LDFLAGS} \${LDFLAGS_DEFAULT} -o \$@ \$(PKG_OBJECTS) \${SHLIB_LD_LIBS}" MAKE_STUB_LIB="\${STLIB_LD} \$@ \$(PKG_STUB_OBJECTS)" fi if test "${SHARED_BUILD}" = "1" ; then MAKE_LIB="${MAKE_SHARED_LIB} " @@ -8569,28 +8739,28 @@ { $as_echo "$as_me:${as_lineno-$LINENO}: checking for tclsh" >&5 $as_echo_n "checking for tclsh... " >&6; } if test -f "${TCL_BIN_DIR}/Makefile" ; then # tclConfig.sh is in Tcl build directory if test "${TEA_PLATFORM}" = "windows"; then - if test -f "${TCL_BIN_DIR}/tclsh${TCL_MAJOR_VERSION}${TCL_MINOR_VERSION}${TCL_DBGX}${EXEEXT}" ; then - TCLSH_PROG="${TCL_BIN_DIR}/tclsh${TCL_MAJOR_VERSION}${TCL_MINOR_VERSION}${TCL_DBGX}${EXEEXT}" - elif test -f "${TCL_BIN_DIR}/tclsh${TCL_MAJOR_VERSION}${TCL_MINOR_VERSION}${TCL_DBGX}s${EXEEXT}" ; then - TCLSH_PROG="${TCL_BIN_DIR}/tclsh${TCL_MAJOR_VERSION}${TCL_MINOR_VERSION}${TCL_DBGX}s${EXEEXT}" - elif test -f "${TCL_BIN_DIR}/tclsh${TCL_MAJOR_VERSION}${TCL_MINOR_VERSION}${TCL_DBGX}t${EXEEXT}" ; then - TCLSH_PROG="${TCL_BIN_DIR}/tclsh${TCL_MAJOR_VERSION}${TCL_MINOR_VERSION}${TCL_DBGX}t${EXEEXT}" - elif test -f "${TCL_BIN_DIR}/tclsh${TCL_MAJOR_VERSION}${TCL_MINOR_VERSION}${TCL_DBGX}st${EXEEXT}" ; then - TCLSH_PROG="${TCL_BIN_DIR}/tclsh${TCL_MAJOR_VERSION}${TCL_MINOR_VERSION}${TCL_DBGX}st${EXEEXT}" + if test -f "${TCL_BIN_DIR}/tclsh${TCL_MAJOR_VERSION}${TCL_MINOR_VERSION}${EXEEXT}" ; then + TCLSH_PROG="${TCL_BIN_DIR}/tclsh${TCL_MAJOR_VERSION}${TCL_MINOR_VERSION}${EXEEXT}" + elif test -f "${TCL_BIN_DIR}/tclsh${TCL_MAJOR_VERSION}${TCL_MINOR_VERSION}s${EXEEXT}" ; then + TCLSH_PROG="${TCL_BIN_DIR}/tclsh${TCL_MAJOR_VERSION}${TCL_MINOR_VERSION}s${EXEEXT}" + elif test -f "${TCL_BIN_DIR}/tclsh${TCL_MAJOR_VERSION}${TCL_MINOR_VERSION}t${EXEEXT}" ; then + TCLSH_PROG="${TCL_BIN_DIR}/tclsh${TCL_MAJOR_VERSION}${TCL_MINOR_VERSION}t${EXEEXT}" + elif test -f "${TCL_BIN_DIR}/tclsh${TCL_MAJOR_VERSION}${TCL_MINOR_VERSION}st${EXEEXT}" ; then + TCLSH_PROG="${TCL_BIN_DIR}/tclsh${TCL_MAJOR_VERSION}${TCL_MINOR_VERSION}st${EXEEXT}" fi else TCLSH_PROG="${TCL_BIN_DIR}/tclsh" fi else # tclConfig.sh is in install location if test "${TEA_PLATFORM}" = "windows"; then - TCLSH_PROG="tclsh${TCL_MAJOR_VERSION}${TCL_MINOR_VERSION}${TCL_DBGX}${EXEEXT}" + TCLSH_PROG="tclsh${TCL_MAJOR_VERSION}${TCL_MINOR_VERSION}${EXEEXT}" else - TCLSH_PROG="tclsh${TCL_MAJOR_VERSION}.${TCL_MINOR_VERSION}${TCL_DBGX}" + TCLSH_PROG="tclsh${TCL_MAJOR_VERSION}.${TCL_MINOR_VERSION}" fi list="`ls -d ${TCL_BIN_DIR}/../bin 2>/dev/null` \ `ls -d ${TCL_BIN_DIR}/.. 2>/dev/null` \ `ls -d ${TCL_PREFIX}/bin 2>/dev/null`" for i in $list ; do @@ -8784,10 +8954,38 @@ else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to enable valiation features" >&5 +$as_echo_n "checking whether to enable valiation features... " >&6; } + # Check whether --enable-schema was given. +if test "${enable_schema+set}" = set; then : + enableval=$enable_schema; tcl_ok=$enableval +else + tcl_ok=yes +fi + + + if test "${enable_schema+set}" = set; then + enableval="$enable_schema" + tcl_ok=$enableval + else + tcl_ok=yes + fi + + if test "$tcl_ok" = "no" ; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + $as_echo "#define TDOM_NO_SCHEMA 1" >>confdefs.h + + else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + fi + TDOMSHELL=tcldomsh Index: configure.ac ================================================================== --- configure.ac +++ configure.ac @@ -77,10 +77,32 @@ # Add shared expat includes and expat entropy #-------------------------------------------------------------------- TDOM_PATH_EXPAT TDOM_EXPAT_ENTROPY + +#-------------------------------------------------------------------- +# We need the UINT2PTR and PTR2UINT macros, so make sure that intptr_t +# is defined. +#-------------------------------------------------------------------- + +AC_CHECK_TYPE([uintptr_t], [ + AC_DEFINE([HAVE_UINTPTR_T], 1, [Do we have the uintptr_t type?])], [ + AC_CACHE_CHECK([for pointer-size unsigned integer type], tcl_cv_uintptr_t, [ + for tcl_cv_uintptr_t in "unsigned int" "unsigned long" "unsigned long long" \ + none; do + if test "$tcl_cv_uintptr_t" != none; then + AC_COMPILE_IFELSE([AC_LANG_BOOL_COMPILE_TRY([AC_INCLUDES_DEFAULT], + [[sizeof (void *) <= sizeof ($tcl_cv_uintptr_t)]])], + [tcl_ok=yes], [tcl_ok=no]) + test "$tcl_ok" = yes && break; fi + done]) + if test "$tcl_cv_uintptr_t" != none; then + AC_DEFINE_UNQUOTED([uintptr_t], [$tcl_cv_uintptr_t], [Unsigned integer + type wide enough to hold a pointer.]) + fi +]) #-------------------------------------------------------------------- # Add HTML5 parsing support. #-------------------------------------------------------------------- @@ -107,11 +129,11 @@ generic/tcldom.c \ generic/nodecmd.c \ generic/tdominit.c \ generic/tclexpat.c \ generic/tclpull.c \ - generic/structure.c \ + generic/schema.c \ generic/tdomStubInit.c]) TEA_ADD_HEADERS([generic/tdom.h]) TEA_ADD_INCLUDES([-I${srcdir}/generic ${AOL_INCLUDES} ${HTML5_INCLUDES}]) TEA_ADD_LIBS([${AOL_LIBS} ${HTML5_LIBS}]) TEA_ADD_CFLAGS([]) @@ -218,10 +240,11 @@ TDOM_ENABLE_DTD TDOM_ENABLE_NS TDOM_ENABLE_UNKNOWN TDOM_ENABLE_TDOMALLOC TDOM_ENABLE_LESS_NS +TDOM_ENABLE_SCHEMA TDOMSHELL=tcldomsh AC_SUBST(TDOMSHELL) TDOM_EXPORT_CONFIG Index: doc/INDEX.MAP ================================================================== --- doc/INDEX.MAP +++ doc/INDEX.MAP @@ -38,14 +38,18 @@ - - - - + + + + + + + + Index: doc/category-index.html ================================================================== --- doc/category-index.html +++ doc/category-index.html @@ -6,11 +6,11 @@

tDOM manual: Index

Index: doc/pullparser.html ================================================================== --- doc/pullparser.html +++ doc/pullparser.html @@ -2,22 +2,22 @@ tDOM manual: pullparser
-

NAME

+

NAME

tdom::pullparser -
Create an XML pull parser command

-

SYNOPSIS

package require tdom
+  

SYNOPSIS

package require tdom
 
     tdom::pullparser cmdName  ? -ignorewhitecdata ? 
     
-

DESCRIPTION

This command creates XML pull parser commands with a simple +

DESCRIPTION

This command creates XML pull parser commands with a simple API, along the lines of a simple StAX parser. After creation, you've to set an input source, to do anything useful with the pull parser. For this see the methods input, inputchannel and inputfile.

The parser has always a state. You start parsing the XML data until some next state, do what has to be done and skip again @@ -173,13 +173,13 @@ and TEXT. It returns the offset, from the beginning of the current line, of the parsing position. -

KEYWORDS

+

KEYWORDS

XML, pull, parsing

ADDED doc/schema.html Index: doc/schema.html ================================================================== --- /dev/null +++ doc/schema.html @@ -0,0 +1,1516 @@ + + +tDOM manual: schema + +
+

NAME

+tdom::schema -
Create a schema validation command

+ +

SYNOPSIS

package require tdom
+
+tdom::schema ?create? cmdName
+    
+ +

DESCRIPTION

Every call of this command creates a new validation command. A + validation command has methods to define a schema and is able + to validate XML data or to post-validate a tDOM DOM tree (and to + some degree other kind of hierarchical data) against this + schema.

Additionally, a validation command may be used as argument to + the -validateCmd option of the dom parse and the + expat commands to enable validation additional to what they + do otherwise.

The methods of created commands are:

+ +
+prefixns ?prefixUriList? +
+
This method gives control to a prefix (or + abbreviation) to namespace URI mapping. Wherever a namespace + argument is expected in the schema command methods you may + use the "prefix" pointing to the namespace URI in + the current prefixUriList, set by this method. If the list + maps the same prefix to different namespace URIs, the first + one win. If there is no such a prefix the namespace argument + is used literally as namespace URI. If the method is called + without argument it returns the current prefixUriList. If + the method is called with the empty string any namespace URI + arguments are used literally. This is the default. +
+ + + +
+defelement name ?namespace? <definition script> +
+
This method defines the element name (optional in + the namespace namespace) in the schema. The + definition script is evaluated and defines the content + model of the element. If the namespace argument is + given, any element or ref references in the + definition script not wrapped inside a namespace + command are resolved in that namespace. If there is already a + element definition for the name/namespace combination the + command raises error.
+ + + +
+defelementtype typename name ?namespace? <definition script> +
+
This method defines the element type typename + (optional in the namespace namespace) in the schema. If + the element type is used in a definition script with the + schema command elementtype, the validation engine expects an + element named name (in the namespace namespace, + if given) and the content model definition script. + Defining element types seems only sensible if you really have + elements with the same name and namespace but different + content models. The definition script is evaluated and + defines the content model of the element. If the + namespace argument is given, any element or + ref references in the definition script not wrapped + inside a namespace command are resolved in that + namespace. If there is already a elementtype definition for + the name/namespace combination the command raises error. The + document element of any XML to validate cannot be a + defelementtype defined element.
+ + + +
+defpattern name ?namespace? <definition script> +
+
This method defines a (maybe complex) content particle + with the name (optional in the namespace + namespace) in the schema, to be used in other + definition scripts with the definition command ref. The + definition script is evaluated and defines the content + model of the content particle. If the namespace + argument is given, any element or ref references + in the definition script not wrapped inside a namespace + command are resolved in that namespace. If there is already a + pattern definition for the name/namespace combination the + command raises error.
+ + + +
+deftexttype name <constraint script> +
+
This method defines a bundle of text constraints that + can be referred to by name while defining constrains on + text element or attribute values. If there is already a text + type definition with this name, the command raises error. A + text type must be defined before it can be used in schema + definition scripts.
+ + + +
+start documentElement ?namespace? +
+
This method defines the name and namespace of the root + element of a tree to validate. If this method is used, then + the root element must match for validity. If start is + not used, any element defined by defelement may be the + root of a valid document. The start method may be used + several times with varying arguments during the lifetime of a + validation command. If the command is called with just the + empty string (and no namespace argument), the validation + constraint for the root element is removed and any defined + element will be valid as root of a tree to validate.
+ + + +
+define <definition script> +
+
This method allows to define several elements or pattern + or a whole schema with one call. All schema command methods so + far (prefixns, defelement, + defelementtype, defpattern, deftexttype and + start) are allowed top level in the definition + script. The define method itself isn't allowed + recursively.
+ + + +
+event (start|end|text) ?event specific data? +
+
This method allows to validate hierarchical data against + the content constrains of the validation command. + +
+ +
+start name ?attributes? ?namespace? +
+ +
Checks if the current validation state allows the + element name in the namespace to start here. + It raises error if not.
+ + + +
end
+
Checks if the current innermost open element may end + here in the current state without violation of validation + constrains. It raises error if not.
+ + + +
+text text +
+ +
Checks if the current validation state allows the + given text content. It raises error if not.
+ +
+
+ + + +
+validate <XML string> ?objVar? +
+
Returns true if the <XML string> is valid or + false otherwise. If validation has failed and the optional + objVar argument is given, the variable with that + name is set to a validation error message. If the XML string + is valid and the optional objVar argument is given, + the variable with that name is set to the empty string.
+ + + +
+validatefile filename ?objVar? +
+
Returns true if the content of filename is valid + or false otherwise. The given file is feeded as binary stream + to expat, therefore only US-ASCII, ISO-8859-1, UTF-8 or UTF-16 + encoded data will work with this method. If validation failed + and the optional objVar argument is given, the variable + with that name is set to a validation error message. If the + XML string is valid and the optional objVar argument is + given, the variable with that name is set to the empty + string.
+ + + +
+validatechannel channel ?objVar? +
+
Returns true if the content read from the Tcl channel + channel is valid or false otherwise. Since data read + out of a Tcl channel is UTF-8 encoded, any misleading encoding + declaration at the beginning of the data will lead to errors. + If the validation fails and the optional objVar + argument is given, the variable with that name is set to a + validation error message. If the XML string is valid and the + optional objVar argument is given, the variable with + that name is set to the empty string.
+ + + +
+domvalidate domNode ?objVar? +
+
Returns true if the first argument is a valid tree or + false otherwise. If validation failed and the optional + objVar argument is given, the variable with that name + is set to a validation error message. If the dom tree is valid + and the optional objVar argument is given, the variable + with that name is set to the empty string.
+ + + +
+reportcmd ?cmd? +
+
This method expects the name of a Tcl command to be + called in case of validation error. This command will be + called with two arguments appended: the schema command which + raises the validation error, and a validation error code. + +

The possible error codes are:

+
+
MISSING_ELEMENT
+
MISSING_TEXT
+
UNEXPECTED_ELEMENT
+
UNEXPECTED_ROOT_ELEMENT
+
UNEXPECTED_TEXT
+
UNKNOWN_ROOT_ELEMENT
+
UNKNOWN_ATTRIBUTE
+
MISSING_ATTRIBUTE
+
INVALID_ATTRIBUTE_VALUE
+
DOM_KEYCONSTRAINT
+
DOM_XPATH_BOOLEAN
+
INVALID_KEYREF
+
INVALID_VALUE
+
UNKOWN_GLOBAL_ID
+
UNKOWN_ID
+
+

For more detailed information see section Recovering.

+
+ + + +
delete
+
This method deletes the validation command.
+ + + +
+info ?args? +
+
This method bundles methods to query the state of and + details about the schema command. +
+ +
validationstate
+
This method returns the state of the validation command + with respect to validation state. The possible return values + and their meanings are: +
+
READY
The validation command is ready to start + validation
+
VALIDATING
The validation command is in the + process of validating input.
+
FINISHED
The validation has finished, no further + events are expected.
+
+
+ + +
vstate
+
This method is a shorter alias for validationstate; see there.
+ + +
line
+
If the schema command is currently validating, + this method returns the line part of the parsing + position information and the empty string in all + other cases. If the schema command is currently + post-validating a DOM tree there may be no position + information stored at some or all nodes. The + empty string is returned in these cases.
+ + +
column
+
If the schema command is currently validating + this method returns the column part of the parsing + position information and the empty string in all + other cases. If the schema command is currently + post-validating a DOM tree there may be no position + information stored at some or all nodes. The + empty string is returned in these cases.
+ + +
domNode
+
If the schema command isn't currently + post-validating a DOM tree this method returns the + empty string. Otherwise, if the schema command waits + for the reportcmd script to finish while recovering + from a validation error it returns the node on which + the validation engine is currently looking at in + case the node is an ELEMENT_NODE or, if not, its + parent node. It is recommended that you do not use + this method. Or at least leave the DOM tree alone, + use it read-only.
+ + +
nrForwardDefinitions
+
Returns how much element, elementtype and ref + pattern are referenced that aren't defined so far + (summed together).
+ + +
definedElements
+
Returns in no particular order the defined + elements in the grammar as list. If an element is + namespaced its list entry will be itself a list with + two elements, with the name as first and the + namespace as second element.
+ + +
definedElementtypes
+
Returns in no particular order the defined + element types in the grammar as list. If an element + type is namespaced its list entry will be itself a + list with two elements, with the name as first and + the namespace as second element.
+ + +
definedPatterns
+
Returns in no particular order the defined + named pattern in the grammar as list. If a named + pattern is namespaced its list entry will be itself + a list with two elements, with the name as first and + the namespace as second element.
+ + +
expected
+
Returns in no particular order all possible + next events (since the last successful event match, + if there was one) as a list. If an element is + namespaced its list entry will be itself a list with + two elements, with the name as first and the + namespace as second element. If text is a possible + next event the list entry will be a two elements + list, with #text as first element and the empty + space as second. If an any element constraint is + possible the list entry will be a two elements list, + with <any> as first element and the empty space + as second. If an any element in a certain namespace + constraint is possible the list entry will be a two + elements list, with <any> as first element and + the namespace as second. If element end is a + possible event the list entry will be a two elements + list with <elementend> as first element and the + empty string as second element.
+ + +
definition name ?namespace?
+
Returns the code that defines the given + element. The command raises error if there isn't a + definition of that element. +
+ + +
typedefinition name ?namespace?
+
Returns the code that defines the given + element type definition. The command raises error if + there isn't a definition of that element. +
+ + +
patterndefinition name ?namespace?
+
Returns the code that defines the given + pattern definition. The command raises error if + there isn't a definition of a pattern with that name + and, if given, namespace. +
+ + +
vaction ?name|namespace|text?
+
+

This method returns useful information only if + the schema command waits for the reportcmd script to + finish while recovering from a validation error. + Otherwise it returns NONE.

+

If the command is called without the optional + argument the possible return values and their + meanings are:

+
+
NONE
The schema command currently + doesn't recover from a validation event.
+
MATCH_ELEMENT_START
Element start event, which includes looking for missing or unknown attributes.
+
MATCH_ELEMENT_END
Element end event.
+
MATCH_TEXT
Validating text between tags.
+
MATCH_ATTRIBUTE_TEXT
Attribute text value constraint check
+
MATCH_GLOBAL
Checking global IDs
+
MATCH_DOM_KEYCONSTRAINT
Checking domunique constraint
+
MATCH_DOM_XPATH_BOOLEAN
Checking domxpathboolean constant
+
+

If called with one of the possible optional + arguments, the command returns detail information + depending on current action.

+
+
name
Returns the name of the element + that has to match in case of + MATCH_ELEMENT_START. Return the name of the + closed element in case of MATCH_ELEMENT_END. + Returns the name of the attribute in case of + MATCH_ATTRIBUTE_TEXT. Return the name of the + parent element in case of MATCH_TEXT.
+ +
namespace
Returns the namespace of + the element that has to match in case of + MATCH_ELEMENT_START. Return the namespace of the + closed element in case of MATCH_ELEMENT_END. + Returns the namespace of the attribute in case + of MATCH_ATTRIBUTE_TEXT. Return the namespace of + the parent element in case of MATCH_TEXT.
+ +
text
Returns the text to match in + case of MATCH_TEXT. Returns the value of the + attribute in case of MATCH_ATTRIBUTE_TEXT.
+
+
+ + +
stack top|inside|associated
+
In Tcl scripts evaluated by validation this method + provides information about the current validation stack. + Called outside this context the method returns the empty + string. +
+ +
top
+
Returns the element whose content is currently + checked (the open element tag at this moment). +
+ + + +
inside
+
Returns all currently open elements as a list.
+ + + +
associated
+
Returns the data associated with the + current top most stack content particle or + the empty string it there isn't any. +
+ +
+
+ +
+
+ + + +
reset
+
This method resets the validation command into state + READY (while preserving the defined grammar).
+ + +
+ +

Schema definition scripts

Schema definition scripts are ordinary Tcl scripts evaluated in + the namespace tdom::schema. The schema definition commands listed + below in this Tcl namespace allow to define a wide variety of + document structures. Every schema definition command establishes a + validation constraint on the content which has to match or must be + optional to qualify the content as valid. It is a validation error + if there is additional (not matched) content. White space only + text (in the XML sense of white space) between any different tags + is ignored, with the exception of text only elements (for which + even white space only text will be considered as significant + content).

The schema definition commands are:

+ +
+element name ?quant? ?<definition script>? +
+
If the optional argument definition script is not + given this command refers to the element defined with + defelement with the name name in the current + context namespace. If the defelement script argument is + given, then the validation constraint expects an element with + the name name in the current namespace with content + "locally" defined by the definition script. Forward + references to so far not defined elements or patterns or other + local definitions of the same name inside the definition + script are allowed. If a forward referenced element is not + defined until validation then only an empty element with name + name and namespace namespace and no attributes + matches.
+ + + +
+elementtype name ?quant? +
+
This command refers to the element defined with + defelementtype with the type name name in the + current context namespace. Forward references to so far not + defined element types or recursive references are allowed. If + a forward referenced element type is not defined until + validation any empty element without attributes will be + accepted.
+ + + +
+ref name ?quant? +
+
This command refers to the content particle defined with + defpattern with the name name in the current + context namespace. Forward references to a so far not defined + pattern and recursive references are allowed. If a forward + referenced pattern is not defined until validation no content + whatsoever is expected ("empty match").
+ + + +
+group ?quant? <definition script> +
+
This method allows to group a sequence of content + particles defined by the definition script>, which have + to match in this sequence order.
+ + + +
+choice ?quant? <definition script> +
+
This schema constraint match if one of the top level + content particles defined by the definition script> + matches. If one of this top level content particle is optional + this constraint matches the "empty match". +
+ + + +
+interleave ?quant? <definition script> +
+
This schema constraint match after every of the required + top level content particles defined by the definition + script> have matched (and, optional, some or all other) in + any arbitrary order.
+ + + +
+mixed ?quant? <definition script> +
+
This schema constraint matches for any text (including the + empty one) and every top level content particle defined by the + definition script> with default quantifier *.
+ + + +
+text ?<constraint script>|"type" typename? +
+
Without the optional constraint script this validation + constraint matches every string (including the empty one). + With constraint script or with a given text type + argument a text matching this script or the text type is + expected.
+ + + +
+any ?namespace? ?quant? +
+
The any command matches every element (in the namespace + namespace, if that is given) (with whatever attributes) + or subtree, no matter if known within the schema or not. + Please note that in case of no namespace argument is + given that means that the quantifier * and + will eat up any + elements until the enclosing element ends. If you really have + a namespace that looks like a valid tDOM schema quantifier + you will have to spell out always both arguments.
+ + + +
+attribute name ?quant? (?<constraint script>|"type" typename?) +
+
The attribute command defines an attribute (in no + namespace) to the enclosing element. The first definition of + name inside an element definition wins; later + definitions of the same name are silently ignored. After the + name argument there may be one of the quantifiers ? or + !. If there is, it will be used. Otherwise the attribute will + be required (must be present in the XML source). If there is + one argument more this argument is evaluated as constraint + script, defining the value constrains of the attribute. + Otherwise, if there are two more arguments and the first of + them is the bare-word "type" the following argument is used as + a text type name. This command is only allowed at top level in + the definition script of an defelement/element script.
+ + + +
+nsattribute name namespace ?quant? (?<constraint script>|"type" typename?) +
+
This command does the same as the command + attribute, for the attribute name in the + namespace namespace.
+ + + +
+namespace URI <definition script> +
+
Evaluates the definition script with context + namespace URI. Every element, element type or ref + command name will be looked up in the namespace URI, + and local defined elements will be in that namespace. An + empty string as URI means no namespace.
+ + + +
+tcl tclcmd ?arg arg ...? +
+
Evaluates the Tcl script tclcmd arg arg ... . + This validation command is only allowed in strict sequential + context (not in choice, mixed and interleave). If the return + code is something else than 0 (TCL_OK) this is an error (which + is not catched and reported by reportcmd).
+ + + +
self
+
Returns the schema command.
+ + + +
+associate data +
+
This command is only allowed top-level inside definition + scripts of the element, elementtype, pattern or interleave + content particles. Associates the data given as argument + with the currently defined content particle and may be + requested in scripts evaluated while validating the content of + that particle with the schema command method call info + stack associated.
+ + + +
+domunique selector fieldlist ?name? ?"IGNORE_EMPTY_FIELD_SET"|("EMPTY_FIELD_SET_VALUE" emptyFieldSetValue)? +
+
If not postvalidating a DOM tree with domvalidate + this constraint always matches. If postvalidating this + constraint resembles the xsd key/keyref mechanism. The + selector argument may be any valid XPath expression + (without the xsd limits). Several domunique commands + within one element definition are allowed. They are checked in + definition order. The argument name is available in the + recovering script per info vaction name. If the + fieldlist doesn't select something for a node of the + result set of the selector the key value will be the + empty string by default. If the arguments + EMPTY_FIELD_SET_VALUE <value> are given an empty + node set will have the key value value. If instead the + flag IGNORE_EMPTY_FIELD_SET flag is given an empty + node set result will not have any key value.
+ + + +
+domxpathboolean XPath_expr ?name? +
+
+

If not postvalidating a DOM tree with + domvalidate this constraint always matches. If + postvalidating the XPath_expr argument is evaluated + (with the node matching the schema parent of the + domxpathboolean command as context node). The + constraint maches if the result of this XPath expression, + converted to boolean by XPath rules, is true. Several + domxpathboolean commands within one element definition + are allowed. They are checked in definition order.

+ +

This enables checks depending on more than one element. Consider

+ +
+tdom::schema s
+s define {
+    defelement doc {
+        element a ! text
+        element b ! text
+        element c ! text
+        domxpathboolean "a * b * c >= 20000" volume
+        domxpathboolean "a > b and b > c" sequence
+    }
+}
+        
+
+ + + +
+prefixns ?prefixUriList? +
+
This defines a prefix to namespace URI mapping exactly + as a schemacmd prefixns call. This is meant as top-level + command of a schemacmd define script. This command is + not allowed nested in another definition script command and + will raise error, if you call it there.
+ + + +
+defelement name ?namespace? <definition script> +
+
This defines an element exactly as a schemacmd + defelement call. This is meant as top-level command of a + schemacmd define script. This command is not allowed + nested in another definition script command and will raise + error, if you call it there.
+ + + +
+defelementtype name ?namespace? <definition script> +
+
This defines an elementtype exactly as a schemacmd + defelementtype call. This is meant as top-level command of a + schemacmd define script. This command is not allowed + nested in another definition script command and will raise + error, if you call it there.
+ + + +
+defpattern name ?namespace? <definition script> +
+
This defines a named pattern exactly as a schemacmd + defpattern call. This is meant as top-level command of a + schemacmd define script. This command is not allowed + nested in another definition script command and will raise + error, if you call it there.
+ + + +
+deftexttype name <constraint script> +
+
This defines a named bundle of text constraints exactly + as a schemacmd deftexttype call. This is meant as top-level + command of a schemacmd define script. This command is + not allowed nested in another definition script command and + will raise error, if you call it there.
+ + + +
+start name ?namespace? +
+
This command works exactly as a schemacmd start + call. This is meant as top-level command of a schemacmd + define script. This command is not allowed nested in + another definition script command and will raise error, if you + call it there.
+ +
+ +

Quantity specifier

Several schema definition commands expects a quantifier as + one of their arguments, which determines how often the content + particle specified by the command is expected. The valid values + for a quant argument are:

+ +
!
+
The content particle must occur exactly once in valid + documents.
+ + + +
?
+
The content particle must occur at most once in valid + documents.
+ + + +
*
+
The content particle may occur zero or more times in a + row in valid documents.
+ + + +
+
+
The content particle may occur one or more times in a + row in valid documents.
+ + + +
n
+
The content particle must occur n times in a row in + valid documents. The quantifier must be an integer greater + zero.
+ + + +
{n m}
The content particle must occur + n to m times (both inclusive) in a row in valid documents. The + quantifier must be a Tcl list with two elements. Both elements + must be integers, with n >= 0 and n < m.
+ +

If an optional quantifier is not given then it defaults to * in + case of the mixed command and to ! for all other commands.

+ +

Text constraint scripts

Text - parsed character data, as XML calls it - must sometimes + be of a certain kind, must comply to some rules etc to be valid. + The text constraint script arguments to the text, attribute, + nsattribute and deftexttype commands are evaluated in the Tcl + namespace tdom::schema::text namespace and allow the + following text constraint commands to check text for certain + properties. The commands are defined in the Tcl namespace + tdom::schema::text. They raise error in case they are + called outside of a text constraint script.

A few of the following text type commands are exposed as + general Tcl commands. They are defined in the namespace tdom::type + and are called as documented below with the text to check appended + to the argument list. They return a logical value. Please note, + that the commands may not accept starting or ending white space. It + is noted with the command documentation, if the command is + available in the tdom::type namespace. +

+

The tcl text constraint command

+

The tcl text constraint command dispatches the check + to an arbitrary Tcl command, thus enable any programmable + decision rules.

+
+ +
+tcl tclcmd ?arg arg ...? +
+
Evaluates the Tcl script tclcmd arg arg ... and + the text to validate appended to the argument list. The return + value of the Tcl command is interpreted as a boolean.
+ +
+ +

Basic XML types

+
+ +
name
+
This text constraint match if the text value match the + XML name production + https://www.w3.org/TR/xml/#NT-Name. This means the + text value must start with a letter, underscore (_), or colon (:), + and may contain only letters, digits, underscores (_), colons + (:), hyphens (-), and periods (.).
+ + +
ncname
+
This text constraint match if the text value match the + XML ncname production + https://www.w3.org/TR/xml-names/#NT-NCName. This + means the text value must start with a letter or underscore (_), + and may contain only letters, digits, underscores (_), hyphens + (-), and periods (.) (The only difference to the name + constraint is that colons are not permitted.)
+ + +
qname
+
This text constraint match if the text value match the + XML qname production + https://www.w3.org/TR/xml-names/#NT-QName. This + means the text value is either a ncname or two ncnames joined + by a colon (:).
+ + +
nmtoken
+
This text constraint match if the text value match the + XML nmtoken production + https://www.w3.org/TR/xml/#NT-Nmtoken +
+ + +
nmtokens
+
This text constraint match if the text value match the + XML nmtokens production + https://www.w3.org/TR/xml/#NT-Nmtokens +
+ +
+ +

Basic type tests

+

+

+
+ +
+integer ?(xsd|tcl)? +
+
This text constraint match if the text value could be + parsed as an integer. If the optional argument to the command + is tcl everything that returns TCL_OK if feeded into + Tcl_GetInt() matches. If the optional argument to the command + is xsd then the constraint match if the value is a + valid xsd:integer. Without argument xsd is the + default.
+ + + +
+negativeInteger ?(xsd|tcl)? +
+
This text constraint match the same text values as the + integer text constraint (see there) with the additional + constraint that the value must be < zero.
+ + + +
+nonNegativeInteger ?(xsd|tcl)? +
+
This text constraint match the same text values as the + integer text constraint (see there) with the additional + constraint that the value must be >= zero.
+ + + +
+nonPositiveInteger ?(xsd|tcl)? +
+
This text constraint match the same text values as the + integer text constraint (see there) with the additional + constraint that the value must be <= zero.
+ + + +
+positiveInteger ?(xsd|tcl)? +
+
This text constraint match the same text values as the + integer text constraint (see there) with the additional + constraint that the value must be > zero.
+ + + +
+number ?(xsd|tcl)? +
+
This text constraint match if the text value could be + parsed as a number. If the optional argument to the command is + tcl everything that returns TCL_OK if feeded into + Tcl_GetDouble() matches. If the optional argument to the command + is xsd then the constraint match if the value is a + valid xsd:decimal. Without argument xsd is the + default.
+ + +
+boolean ?(xsd|tcl)? +
+
This text constraint match if the text value could be + parsed as a boolean. If the optional argument to the command is + tcl everything that returns TCL_OK if feeded into + Tcl_GetBoolean() matches. If the optional argument to the command + is xsd then the constraint match if the value is a + valid xsd:boolean. Without argument xsd is the + default.
+ + +
date
+
This text constraint match if the text value is + a xsd:date. This is basically like an ISO 8601 date of + the form YYYY-MM-DD, with optional time zone part + (either the letter Z or plus (+) or minus (-) followed + by hh:mm and with maximum allowed positive or negative + time zone 14:00). It follows the date rules of the + Gregorian calendar for all dates. A preceding minus + sign for bce dates is allowed. There is no year 0. The + year may have more than 4 digits, but only if needed + (no extra leading zeros). This is available as common + Tcl command tdom::type::date.
+ + +
time
+
This text constraint match if the text value is + a xsd:time. This is basically like an ISO 8601 time of + the form hh:mm:ss with optional time zone part. The + time zone part follow the rules of the date + command; see there. All three parts of the time value + (hours, minutes, seconds) must be spelled out with 2 + digits. Additional fractional seconds (with a point + ('.') as separator) are allowed, but not just a + dangling point. The time value 24:00:00 (without + fractional part) is allowed. This is available as + common Tcl command tdom::type::time.
+ + +
dateTime
+
This text constraint match if the text value is + a xsd:dateTime. This is basically like an ISO 8601 + date time of the form YYYY-MM-DDThh:mm:ss with + optional time zone part. The date and time zone parts + follow the rules of the date command; see + there. The time part (including the signaling 'T' + character) is mandatory and follow the rules of the + time command, see there. This is available as + common Tcl command tdom::type::dateTime.
+ + +
duration
+
This text constraint match if the text value is + a xsd:duration. This is basically like an ISO 8601 + duration of the form PnYnMnDTnHnMnS. All parts other + then the starting P and - if one of H, M or S is given + - T are optional. In case the following sign letter is + S n may be a decimal (with at least one digit before + and after the dot), otherwise it must be a (positive) + integer. This is available as common Tcl command + tdom::type::duration.
+ + +
base64
+
This text constraint match if text is valid according to + RFC 4648.
+ + +
hexBinary
+
This text constraint match if text is a sequence of + binary octets in hexadecimal encoding, where each binary octet + is a two-character hexadecimal number. Lowercase and uppercase + letters A through F are permitted.
+ + +
unsignedByte
+
This text constraint match if the text value is a + xsd:unsignedByte. This is an integer between 0 and 255, both + included, optionally preceded by a + sign and leading + zeros.
+ + +
unsignedShort
+
This text constraint match if the text value is a + xsd:unsignedShort. This is an integer between 0 and 65535, + both included, optionally preceded by a + sign and leading + zeros.
+ + +
unsignedInt
+
This text constraint match if the text value is a + xsd:unsignedInt. This is an integer between 0 and 4294967295, + both included, optionally preceded by a + sign and leading + zeros.
+ + +
unsignedLong
+
This text constraint match if the text value is a + xsd:unsignedLong. This is an integer between 0 and + 18446744073709551615, both included, optionally preceded by a + + sign and leading zeros.
+ +
+ +

Logical constructs

+
+ +
+oneOf <constraint script> +
+
This text constraint match if one of the text + constraints defined in the argument constraint script + match the text. It stops after the first match and probes the + text constraints in the order of definition.
+ + +
+allOf <constraint script> +
+
This text constraint match if all of the text + constraints defined in the argument constraint script + match the text. It stops after the first match failure and + probes the text constraints in the order of definition. Since + the schema definition command text also expects all + text constraints to match the text constraint allOf is + useful mostly together with the oneOf text constraint + command.
+ + +
+not <constraint script> +
+
This text constraint match if none of the text + constraints defined in the argument constraint + script match the text. It stops after the first + matching constraint in the constraint script and + reports validation error. The text constraints in the + constraint script are probed in the order of + definition.
+ +
+ +

Constraints on processed text value

+
+ +
+whitespace (preserve|replace|collapse) <constraint script> +
+
This text constraint command does white-space (#x20 + (space, ' '), #x9 (tab, \t), #xA (linefeed, \n), and #xD + (carriage return, \r) normalization to the text value and + checks the resulting text with the text constraints of the + constraint script argument. The normalization method + preserve keeps everything as it is; this is another way + to say allOf. The replace normalization method + replaces any single white-space character (as above) to a + space. The collapse normalization method removes all + leading and trailing white-space and all the other sequences of + contiguous white-space are replaced by a single space.
+ + +
+split ?type ?args??<constraint script> +
+
+

This text constraint command splits the text to test + into a list of values and tests all elements of that list for + the text constraints in the evaluated constraint + script>.

+

The available types are:

+
+
whitespace
The text to split is striped of all + white space at start and end splited into a list at any + successive white space.
+
tcl tclcmd ?arg ...?
The text to split is + handed to the tclcmd, which is evaluated on global + level, appended with every given arg and the text to split + as last argument. This call must return a valid Tcl list, + which elements are tested.
+
+

The default in case no split type argument is given is + whitespace.

+
+ + +
+strip <constraint script> +
+
This text constraint command tests all text constraints + in the evaluated constraint script> with the text to + test striped of all white space at start and end.
+ +
+ +

Various other string properties

+
+ +
+fixed value +
+
The text constraint only match if the text value is + string equal to the given value.
+ + + +
+enumeration list +
+
This text constraint match if the text value is equal to + one element (respecting case and any white-space) of the + argument list, which has to be a valid Tcl list. +
+ + +
+match ?-nocase? glob_style_match_pattern> +
+
This text constraint match if the text value match the + glob style pattern given as argument. It follows the rules of + the Tcl [string match] command, see + https://www.tcl.tk/man/tcl8.6/TclCmd/string.htm#M35.
+ + +
+regexp expression +
+
This text constraint match if the text value match the + regular expression given as argument. https://www.tcl.tk/man/tcl8.6/TclCmd/re_syntax.htm describes the regular expression syntax
+ + +
+length length +
+
This text constraint match if the length of the text + value (in characters, not bytes) is length. The + length argument must be a positive integer or zero.
+ + +
+maxLength length +
+
This text constraint match if the length of the text + value (in characters, not bytes) is at most length. The + length argument must be an integer greater zero.
+ + +
+minLength length +
+
This text constraint match if the length of the text + value (in characters, not bytes) is at least length. + The length argument must be an integer greater zero.
+ + +
+id ?keySpace? +
+
This text constraint command marks the text as a + document wide ID (to be referenced by an idref). Every ID + value within a document must be unique. It isn't an error if + the ID isn't actually referenced within the document. The + optional argument keySpace does all this for a named + key space. The key space "" (the empty sting) is another key + space as the id command without keySpace + argument.
+ + +
+idref ?keySpace? +
+
This text constraint command expects the text to be a + reference to an ID within the document. The referenced ID may + be later in the document, that the reference. Several + references within the document to one ID are possible.
+ +
+ + +

Local key constraints

Document wide uniqueness and foreign key constraints are + available with the text constraint commands id and idref. + Keyspaces allow for sub-tree local uniqueness and foreign key + constraints.

+ +
+keyspace <names list> <constraint script> +
+
Any number of keyspaces are possible. A keyspace is + either active or not. An inside a constraint + script called keyspace with the same name does + nothing.
+ +

This text constraint commands work with keyspaces:

+ +
+key <name> +
+
If the keyspace with the name <name> is not + active always matches. If the keyspace is active then + reports error if there is already a key with the value. + Otherwise, stores the value as key in this keyspace and + matches.
+ + +
+keyref <name> +
+
If the keyspace with the name <name> is not + active always matches. If the keyspace is active then + reports error if there is still no key as the value at the + end of the keyspace <name>. Otherwise it + matches.
+ +
+ +

Recovering

By default the validation engine stops at the first detected + validation violation and report that finding. It does so by + return false (and set, if given, the result variable with an + error message) in case the schema command itself is used to + validate input. If the schema command is used by a SAX parser or + the DOM parser it does so by throwing error.

If a reportcmd is set this command is called on global + level appended with the schema command and an error type as + arguments if a validation violation is detected. Then the + validation recovers from the error and continues. For some + validation errors the recover strategy can be determined with + the script result of the reportcmd.

With a reportcmd (which doesen&t throw error if + called) the validation engine will never report validation + failure to its caller. The validation engine recovers, continues + and report the next error, if one happen and so until the end of + the input. The schema command will return true and the SAX + parser and DOM builder will process normally until the end of + the input, as if there would not have been validation.

Please note, that this happens only for validation errors. It + isn't possible to recover from well-formedness errors. If the + input isn't well-formed the schema command returns false and + set, if given, the result variable with an error message about + the well-formedness error.

If the reportcmd throws error while called by the + validation engine then validation stops and the schema command + throws error with the error message of the script.

While validating basically three events happen: an element + start tag has to match, a piece of text has to match or an + element end tag has to match. The method info vaction + called in the recovering script or any script code called from + there returns, which event triggered the error report + (MATCH_ELEMENT_START, MATCH_TEXT, MATCH_ELEMENT_END, + respectively). While the command walks throu the schema looking + if the event matches other, data driven events (as, for example + checking, if any keyref within a keyspace exists).

Several of the validation error codes appended as second + argument to the reportcmd calls may happen at more than + one kind of validation event. The info vaction method and + its subcommands provide information about the current validation + event and the +

If a structural validation error happens, the default + recovering strategy is to ignore any following (or missing) + content within the current subtree and to continue with the + element end event of the subtree.

Returning "ignore" from the recovering script in case of + error type MISSING_ELEMENT recovers by ignoring the failed + contraint and continues to match the event further against the + schema.

Returing "vanish" from the recover script In case of the + error types MISSING_ELEMENT and UNEXPECTED_ELEMENT recovers by + ignoring the event.

+ +

Examples

The XML Schema Part 0: Primer Second Edition + (https://www.w3.org/TR/xmlschema-0/) starts with this + example schema:

+<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
+
+  <xsd:annotation>
+    <xsd:documentation xml:lang="en">
+     Purchase order schema for Example.com.
+     Copyright 2000 Example.com. All rights reserved.
+    </xsd:documentation>
+  </xsd:annotation>
+
+  <xsd:element name="purchaseOrder" type="PurchaseOrderType"/>
+
+  <xsd:element name="comment" type="xsd:string"/>
+
+  <xsd:complexType name="PurchaseOrderType">
+    <xsd:sequence>
+      <xsd:element name="shipTo" type="USAddress"/>
+      <xsd:element name="billTo" type="USAddress"/>
+      <xsd:element ref="comment" minOccurs="0"/>
+      <xsd:element name="items"  type="Items"/>
+    </xsd:sequence>
+    <xsd:attribute name="orderDate" type="xsd:date"/>
+  </xsd:complexType>
+
+  <xsd:complexType name="USAddress">
+    <xsd:sequence>
+      <xsd:element name="name"   type="xsd:string"/>
+      <xsd:element name="street" type="xsd:string"/>
+      <xsd:element name="city"   type="xsd:string"/>
+      <xsd:element name="state"  type="xsd:string"/>
+      <xsd:element name="zip"    type="xsd:decimal"/>
+    </xsd:sequence>
+    <xsd:attribute name="country" type="xsd:NMTOKEN"
+                   fixed="US"/>
+  </xsd:complexType>
+
+  <xsd:complexType name="Items">
+    <xsd:sequence>
+      <xsd:element name="item" minOccurs="0" maxOccurs="unbounded">
+        <xsd:complexType>
+          <xsd:sequence>
+            <xsd:element name="productName" type="xsd:string"/>
+            <xsd:element name="quantity">
+              <xsd:simpleType>
+                <xsd:restriction base="xsd:positiveInteger">
+                  <xsd:maxExclusive value="100"/>
+                </xsd:restriction>
+              </xsd:simpleType>
+            </xsd:element>
+            <xsd:element name="USPrice"  type="xsd:decimal"/>
+            <xsd:element ref="comment"   minOccurs="0"/>
+            <xsd:element name="shipDate" type="xsd:date" minOccurs="0"/>
+          </xsd:sequence>
+          <xsd:attribute name="partNum" type="SKU" use="required"/>
+        </xsd:complexType>
+      </xsd:element>
+    </xsd:sequence>
+  </xsd:complexType>
+
+  <!-- Stock Keeping Unit, a code for identifying products -->
+  <xsd:simpleType name="SKU">
+    <xsd:restriction base="xsd:string">
+      <xsd:pattern value="\d{3}-[A-Z]{2}"/>
+    </xsd:restriction>
+  </xsd:simpleType>
+
+</xsd:schema>
+    

A somewhat one-to-one translation of that into a tDOM schema + definition script would be:

+tdom::schema schema      
+schema define {
+
+    # Purchase order schema for Example.com.
+    # Copyright 2000 Example.com. All rights reserved.
+
+    defelement purchaseOrder {ref PurchaseOrderType}
+
+    foreach elm {comment name street city state product} {
+        defelement $elm text
+    }
+
+    defpattern PurchaseOrderType {
+        element shipTo ! {ref USAddress}
+        element billTo ! {ref USAddress}
+        element comment ?
+        element items
+        attribute orderDate date
+    }
+
+    defpattern USAddress {
+        element name
+        element street
+        element city
+        element state
+        element zip ! {text number}
+        attribute country ! {fixed "US"}
+    }
+
+    defelement items {
+        element item * {
+            element product
+            element quantity ! {text integer}
+            element USPrice ! {text number}
+            element comment
+            element shipDate ? {text date}
+            attribute partNum ! {pattern "^\d{3}-[A-Z]{2}$"}
+        }
+    }
+}
+      
+    

The RELAX NG Tutorial + (http://relaxng.org/tutorial-20011203.html) starts with + this example:

+Consider a simple XML representation of an email address book:
+
+<addressBook>
+  <card>
+    <name>John Smith</name>
+    <email>js@example.com</email>
+  </card>
+  <card>
+    <name>Fred Bloggs</name>
+    <email>fb@example.net</email>
+  </card>
+</addressBook>
+
+The DTD would be as follows:
+
+<!DOCTYPE addressBook [
+<!ELEMENT addressBook (card*)>
+<!ELEMENT card (name, email)>
+<!ELEMENT name (#PCDATA)>
+<!ELEMENT email (#PCDATA)>
+]>
+
+A RELAX NG pattern for this could be written as follows:
+
+<element name="addressBook" xmlns="http://relaxng.org/ns/structure/1.0">
+  <zeroOrMore>
+    <element name="card">
+      <element name="name">
+        <text/>
+      </element>
+      <element name="email">
+        <text/>
+      </element>
+    </element>
+  </zeroOrMore>
+</element>
+      
+    

This schema definition script will do the same:

+tdom::schema schema      
+schema define {
+    defelement addressBook {
+        element card *
+    }
+    defelement card {
+        element name
+        element email
+    }
+    foreach e {name email} {
+        defelement $e text
+    }
+}
+      
+    
+ +

KEYWORDS

+Validation, Postvalidation, DOM, SAX +

+
+ + ADDED doc/schema.n Index: doc/schema.n ================================================================== --- /dev/null +++ doc/schema.n @@ -0,0 +1,1408 @@ +'\" +'\" Generated from schema.xml +'\" +'\" BEGIN man.macros +.if t .wh -1.3i ^B +.nr ^l \n(.l +.ad b +.de AP +.ie !"\\$4"" .TP \\$4 +.el \{\ +. ie !"\\$2"" .TP \\n()Cu +. el .TP 15 +.\} +.ta \\n()Au \\n()Bu +.ie !"\\$3"" \{\ +\&\\$1 \\fI\\$2\\fP (\\$3) +.\".b +.\} +.el \{\ +.br +.ie !"\\$2"" \{\ +\&\\$1 \\fI\\$2\\fP +.\} +.el \{\ +\&\\fI\\$1\\fP +.\} +.\} +.. +.de AS +.nr )A 10n +.if !"\\$1"" .nr )A \\w'\\$1'u+3n +.nr )B \\n()Au+15n +.\" +.if !"\\$2"" .nr )B \\w'\\$2'u+\\n()Au+3n +.nr )C \\n()Bu+\\w'(in/out)'u+2n +.. +.AS Tcl_Interp Tcl_CreateInterp in/out +.de BS +.br +.mk ^y +.nr ^b 1u +.if n .nf +.if n .ti 0 +.if n \l'\\n(.lu\(ul' +.if n .fi +.. +.de BE +.nf +.ti 0 +.mk ^t +.ie n \l'\\n(^lu\(ul' +.el \{\ +.\" Draw four-sided box normally, but don't draw top of +.\" box if the box started on an earlier page. +.ie !\\n(^b-1 \{\ +\h'-1.5n'\L'|\\n(^yu-1v'\l'\\n(^lu+3n\(ul'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul' +.\} +.el \}\ +\h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul' +.\} +.\} +.fi +.br +.nr ^b 0 +.. +.de VS +.if !"\\$2"" .br +.mk ^Y +.ie n 'mc \s12\(br\s0 +.el .nr ^v 1u +.. +.de VE +.ie n 'mc +.el \{\ +.ev 2 +.nf +.ti 0 +.mk ^t +\h'|\\n(^lu+3n'\L'|\\n(^Yu-1v\(bv'\v'\\n(^tu+1v-\\n(^Yu'\h'-|\\n(^lu+3n' +.sp -1 +.fi +.ev +.\} +.nr ^v 0 +.. +.de ^B +.ev 2 +'ti 0 +'nf +.mk ^t +.if \\n(^b \{\ +.\" Draw three-sided box if this is the box's first page, +.\" draw two sides but no top otherwise. +.ie !\\n(^b-1 \h'-1.5n'\L'|\\n(^yu-1v'\l'\\n(^lu+3n\(ul'\L'\\n(^tu+1v-\\n(^yu'\h'|0u'\c +.el \h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\h'|0u'\c +.\} +.if \\n(^v \{\ +.nr ^x \\n(^tu+1v-\\n(^Yu +\kx\h'-\\nxu'\h'|\\n(^lu+3n'\ky\L'-\\n(^xu'\v'\\n(^xu'\h'|0u'\c +.\} +.bp +'fi +.ev +.if \\n(^b \{\ +.mk ^y +.nr ^b 2 +.\} +.if \\n(^v \{\ +.mk ^Y +.\} +.. +.de DS +.RS +.nf +.sp +.. +.de DE +.fi +.RE +.sp +.. +.de SO +.SH "STANDARD OPTIONS" +.LP +.nf +.ta 5.5c 11c +.ft B +.. +.de SE +.fi +.ft R +.LP +See the \\fBoptions\\fR manual entry for details on the standard options. +.. +.de OP +.LP +.nf +.ta 4c +Command-Line Name: \\fB\\$1\\fR +Database Name: \\fB\\$2\\fR +Database Class: \\fB\\$3\\fR +.fi +.IP +.. +.de CS +.RS +.nf +.ta .25i .5i .75i 1i +.if t .ft C +.. +.de CE +.fi +.if t .ft R +.RE +.. +.de UL +\\$1\l'|0\(ul'\\$2 +.. +'\" END man.macros +.TH schema n "" Tcl "" +.BS +.SH NAME +tdom::schema \- Create a schema validation command +.SH SYNOPSIS +.nf +package require tdom + +\&\fBtdom::schema\fP \fI?create?\fR \fIcmdName\fR + +.fi +.BE +.SH "DESCRIPTION " +.PP +This command creates validation commands with a simple API. The +validation commands have methods to define a schema and are able +to validate XML data or to post-validate a tDOM DOM tree (and to +some degree other kind of hierarchical data) against this +schema. +.PP +Additionally, a validation command may be used as argument to +the \fI-validateCmd\fR option of the \fIdom parse\fR and the +\&\fIexpat\fR commands to enable validation additional to what they +otherwise do. +.PP +The methods of the created commands are: +.TP +\&\fB\fBprefixns\fP \fI?prefixUriList?\fB +\&\fRThis method gives control to a prefix (or +abbreviation) to namespace URI mapping. Everywhere a +namespace argument is expected in the schema command methods +you may use the "prefix" pointing to the namespace +URI in the current prefixUriList, set by this method. If the +list map the same prefix to different namespace URIs the +first one win. If there isn't such a prefix the namespace +argument is used literally as namespace URI. If the method +is called without argument it returns the current +prefixUriList. If the method is called with the empty string +any namespace URI arguments are used literally. This is the +default. +.TP +\&\fB\fBdefelement\fP \fIname\fB \fI?namespace?\fB \fI\fB +\&\fRThis method defines the element \fIname\fR (optional in +the namespace \fInamespace\fR) in the schema. The +\&\fIdefinition script\fR is evaluated and defines the content +model of the element. If the \fInamespace\fR argument is +given, any \fIelement\fR or \fIref\fR references in the +definition script not wrapped inside a \fInamespace\fR +command are resolved in that namespace. If there is already a +element definition for the name/namespace combination the +command raises error. +.TP +\&\fB\fBdefelementtype\fP \fItypename\fB \fIname\fB \fI?namespace?\fB \fI\fB +\&\fRThis method defines the element type \fItypename\fR +(optional in the namespace \fInamespace\fR) in the schema. If +the element type is referred in a definition script with the +schema command elementtype the validation engine expects an +element named \fIname\fR (in the namespace \fInamespace\fR, +if given) and the content model \fIdefinition script\fR. +Defining element types seems only sensible if you really have +elements with the same name and namespace but different +content models. The \fIdefinition script\fR is evaluated and +defines the content model of the element. If the +\&\fInamespace\fR argument is given, any \fIelement\fR or +\&\fIref\fR references in the definition script not wrapped +inside a \fInamespace\fR command are resolved in that +namespace. If there is already a elementtype definition for +the name/namespace combination the command raises error. The +document element of any XML to validate cannot be a +\&\fIdefelementtype\fR defined element. +.TP +\&\fB\fBdefpattern\fP \fIname\fB \fI?namespace?\fB \fI\fB +\&\fRThis method defines a (maybe complex) content particle +with the \fIname\fR (optional in the namespace +\&\fInamespace\fR) in the schema, to be referenced in other +definition scripts with the definition command \fIref\fR. The +\&\fIdefinition script\fR is evaluated and defines the content +model of the content particle. If the \fInamespace\fR +argument is given, any \fIelement\fR or \fIref\fR references +in the definition script not wrapped inside a \fInamespace\fR +command are resolved in that namespace. If there is already a +pattern definition for the name/namespace combination the +command raises error. +.TP +\&\fB\fBdeftexttype\fP \fIname\fB \fI\fB +\&\fRThis method defines a bundle of text constraints, that +can be referred by \fIname\fR while defining constrains on +text element or attribute values. If there is already a text +type definition with this name, the command raises error. A +text type must be defined before it can be used in schema +definition scripts. +.TP +\&\fB\fBstart\fP \fIdocumentElement\fB \fI?namespace?\fB +\&\fRThis method defines the name and namespace of the root +element of a tree to validate. If this method is used then the +root element must match for validity. If \fIstart\fR isn't +used, any with \fIdefelement\fR defined element may be the +root of a valid document. The \fIstart\fR method may be used +several times with varying arguments during the lifetime of a +validation command. If the command is called with just the +empty string (and no namespace argument), the validation +constrain for the root element is removed and any defined +element will be valid as root of a tree to validate. +.TP +\&\fB\fBdefine\fP \fI\fB +\&\fRThis method allows to define several elements or pattern +or a whole schema with one call. All schema command methods so +far (\fIprefixns\fR, \fIdefelement\fR, +\&\fIdefelementtype\fR, \fIdefpattern\fR, \fIdeftexttype\fR and +\&\fIstart\fR) are allowed top level in the \fIdefinition +script\fR. The \fIdefine\fR method itself isn't allowed +recursively. +.TP +\&\fB\fBevent\fP \fI(start|end|text)\fB \fI?event specific data?\fB +\&\fRThis method allows to validate hierarchical data against +the content constrains of the validation command. +.RS +.IP "\fBstart \fIname ?attributes? ?namespace? \fP\fR" +Checks if the current validation state allows the +element \fIname\fR in the \fInamespace\fR to start here. +It raises error, if not. +.IP "\fBend\fR" +Checks if the current innermost open element may end +here in the current state without violate validation +constrains. It raises error, if not. +.IP "\fBtext \fItext\fP\fR" +Checks if the current validation state allows the +given text content. It raises error, if not. +.RE +.TP +\&\fB\fBvalidate\fP \fI\fB \fI?objVar?\fB +\&\fRReturns true if the \fI\fR is valid or +false otherwise. If validation failed and the optional +\&\fIobjVar\fR argument is given, then the variable with that +name is set to a validation error message. If the XML string +is valid and the optional \fIobjVar\fR argument is given, +then the variable with that name is set to the empty string. +.TP +\&\fB\fBvalidatefile\fP \fIfilename\fB \fI?objVar?\fB +\&\fRReturns true if the content of \fIfilename\fR is valid +or false otherwise. The given file is feeded as binary stream +to expat, therefor only US-ASCII, ISO-8859-1, UTF-8 or UTF-16 +encoded data will work with this method. If validation failed +and the optional \fIobjVar\fR argument is given, then the +variable with that name is set to a validation error message. +If the XML string is valid and the optional \fIobjVar\fR +argument is given, then the variable with that name is set to +the empty string. +.TP +\&\fB\fBvalidatechannel\fP \fIchannel\fB \fI?objVar?\fB +\&\fRReturns true if the content read out of the tcl channel +\&\fIchannel\fR is valid or false otherwise. Since data read +out of a tcl channel is UTF-8 encoded any misleading encoding +declaration at the beginning of the data will lead to errors. +If the validation failed and the optional \fIobjVar\fR +argument is given, then the variable with that name is set to +a validation error message. If the XML string is valid and the +optional \fIobjVar\fR argument is given, then the variable +with that name is set to the empty string. +.TP +\&\fB\fBdomvalidate\fP \fIdomNode\fB \fI?objVar?\fB +\&\fRReturns true if the first argument is a valid tree or +false otherwise. If validation failed and the optional +\&\fIobjVar\fR argument is given, then the variable with that +name is set to a validation error message. If the dom tree is +valid and the optional \fIobjVar\fR argument is given, then +the variable with that name is set to the empty string. +.TP +\&\fB\fBreportcmd\fP \fI?cmd?\fB +\&\fRThis method expects the name of a tcl command to be +called in case of validation error. This command will be +called with two arguments appended: the schema command, that +raises the validation error, and a validation error code. +For more detailed information see Recovering.The possible error codes +are: +.RS +.TP +MISSING_ELEMENT +.TP +MISSING_TEXT +.TP +UNEXPECTED_ELEMENT +.TP +UNEXPECTED_ROOT_ELEMENT +.TP +UNEXPECTED_TEXT +.TP +UNKNOWN_ROOT_ELEMENT +.TP +UNKNOWN_ATTRIBUTE +.TP +MISSING_ATTRIBUTE +.TP +INVALID_ATTRIBUTE_VALUE +.TP +DOM_KEYCONSTRAINT +.TP +DOM_XPATH_BOOLEAN +.TP +INVALID_KEYREF +.TP +INVALID_VALUE +.TP +UNKOWN_GLOBAL_ID +.TP +UNKOWN_ID +.PP +For more detailed information see section Recovering. +.RE +.TP +\&\fB\fBdelete\fP +\&\fRThis method deletes the validation command. +.TP +\&\fB\fBinfo\fP \fI?args?\fB +\&\fRThis method bundles methods to query the state of and +details about the schema command. +.RS +.IP "\fBvalidationstate\fR" +This method returns the state of the validation command +with respect to validation state. The possible return values +and their meanings are: +.RS +.TP +READY +The validation command is ready to start +validation +.TP +VALIDATING +The validation command is in the +process of validating input. +.TP +FINISHED +The validation has finished, no further +events are expected. +.RE +.IP "\fBvstate\fR" +This method is a shorter alias for validationstate; see there. +.IP "\fBline\fR" +If the schema command is currently validating +this method returns the line part of the parsing +position information and the empty string in all +other cases. If the schema command is currently +post-validating a DOM tree there may be no position +information stored at certain or all nodes. The +empty string is returned in this cases. +.IP "\fBcolumn\fR" +If the schema command is currently validating +this method returns the column part of the parsing +position information and the empty string in all +other cases. If the schema command is currently +post-validating a DOM tree there may be no position +information stored at certain or all nodes. The +empty string is returned in this cases. +.IP "\fBdomNode\fR" +If the schema command isn't currently +post-validating a DOM tree this method returns the +empty string. Otherwise, if the schema command waits +for the reportcmd script to finish while recovering +from a validation error it returns the node on which +the validation engine is currently looking at in +case, the node is an ELEMENT_NODE or the parent +node, if not. It is recommended that you don't use +this method. Or at least leave the DOM tree alone, +use it read-only. +.IP "\fBnrForwardDefinitions\fR" +Returns how much element, elementtype and ref +pattern are referenced that aren't defined so far +(summed together). +.IP "\fBdefinedElements\fR" +Returns in no particular order the defined +elements in the grammar as list. If an element is +namespaced its list entry will be itself a list with +two elements, with the name as first and the +namespace as second element. +.IP "\fBdefinedElementtypes\fR" +Returns in no particular order the defined +element types in the grammar as list. If an element +type is namespaced its list entry will be itself a +list with two elements, with the name as first and +the namespace as second element. +.IP "\fBdefinedPatterns\fR" +Returns in no particular order the defined +named pattern in the grammar as list. If a named +pattern is namespaced its list entry will be itself +a list with two elements, with the name as first and +the namespace as second element. +.IP "\fBexpected\fR" +Returns in no particular order all possible +next events (since the last successful event match, +if there was one) as a list. If an element is +namespaced its list entry will be itself a list with +two elements, with the name as first and the +namespace as second element. If text is a possible +next event the list entry will be a two elements +list, with #text as first element and the empty +space as second. If an any element constraint is +possible the list entry will be a two elements list, +with as first element and the empty space +as second. If an any element in a certain namespace +constraint is possible the list entry will be a two +elements list, with as first element and +the namespace as second. If element end is a +possible event the list entry will be a two elements +list with as first element and the +empty string as second element. +.IP "\fBdefinition name ?namespace?\fR" +Returns the code that defines the given +element. The command raises error if there isn't a +definition of that element. +.IP "\fBtypedefinition name ?namespace?\fR" +Returns the code that defines the given +element type definition. The command raises error if +there isn't a definition of that element. +.IP "\fBpatterndefinition name ?namespace?\fR" +Returns the code that defines the given +pattern definition. The command raises error if +there isn't a definition of a pattern with that name +and, if given, namespace. +.IP "\fBvaction ?name|namespace|text?\fR" +.RS +.PP +This method returns useful information only if +the schema command waits for the reportcmd script to +finish while recovering from a validation error. +Otherwise it returns NONE. +.PP +If the command is called without the optional +argument the possible return values and their +meanings are: +.TP +NONE +The schema command currently +doesn't recover from a validation event. +.TP +MATCH_ELEMENT_START +Element start event, which includes looking for missing or unknown attributes. +.TP +MATCH_ELEMENT_END +Element end event. +.TP +MATCH_TEXT +Validating text between tags. +.TP +MATCH_ATTRIBUTE_TEXT +Attribute text value constraint check +.TP +MATCH_GLOBAL +Checking global IDs +.TP +MATCH_DOM_KEYCONSTRAINT +Checking domunique constraint +.TP +MATCH_DOM_XPATH_BOOLEAN +Checking domxpathboolean constant +.PP +If called with one of the possible optional +arguments the command returns detail information +depending on current action. +.TP +name +Return the name of the element +that has to match in case of +MATCH_ELEMENT_START. Return the name of the +closed element in case of MATCH_ELEMENT_END. +Returns the name of the attribute in case of +MATCH_ATTRIBUTE_TEXT. Return the name of the +parent element in case of MATCH_TEXT. +.TP +namespace +Return the namespace of +the element that has to match in case of +MATCH_ELEMENT_START. Return the namespace of the +closed element in case of MATCH_ELEMENT_END. +Returns the namespace of the attribute in case +of MATCH_ATTRIBUTE_TEXT. Return the namespace of +the parent element in case of MATCH_TEXT. +.TP +text +Return the text to match in +case of MATCH_TEXT. Returns the value of the +attribute in case of MATCH_ATTRIBUTE_TEXT. +.RE +.IP "\fBstack top|inside|associated\fR" +In Tcl scripts evaluated by validation this method +provides information about the current validation stack. +Called outside this context the method returns the empty +string. +.RS +.IP "\fBtop\fR" +Returns the element which content is currently +checked (the at the moment open element tag). +.IP "\fBinside\fR" +Returns all currently open elements as a list. +.IP "\fBassociated\fR" +Returns the data associated with the current top +most stack content particle or the empty string it there isn't. +.RE +.RE +.TP +\&\fB\fBreset\fP +\&\fRThis method resets the validation command into state +READY (while preserving the defined grammar). +.SH "Schema definition scripts" +.PP +Schema definition scripts are ordinary Tcl scripts that are +evaluated in the namespace tdom::schema. The below listed schema +definition commands in this tcl namespace allow to define a wide +variety of document structures. Every schema definition command +establish a validation constraint on the content which has to +match or must be optional to qualify the content as valid. It is a +validation error if there is additional (not matched) content. +White space only text (in the XML sense of white space) between +any different tags is ignored, with the exception of text only +elements (for which even white space only text will be considered +as significant content). +.PP +The schema definition commands are: +.TP +\&\fB\fBelement\fP \fIname\fB \fI?quant?\fB \fI??\fB +\&\fRIf the optional argument \fIdefinition script\fR isn't +given this command refers to the element defined with +\&\fIdefelement\fR with the name \fIname\fR in the current +context namespace. If the \fIdefelement script\fR argument is +given, then the validation constraint expects an element with +the name \fIname\fR in the current namespace with content +"locally" defined by the \fIdefinition script\fR. Forward +references to so far not defined elements or pattern or other +local definitions of the same name inside the \fIdefinition +script\fR are allowed. If a forward referenced element isn't +defined until validation then only an empty element with name +\&\fIname\fR and namespace \fInamespace\fR and no attributes +matches. +.TP +\&\fB\fBelementtype\fP \fIname\fB \fI?quant?\fB +\&\fRThis command refers to the element defined with +\&\fIdefelementtype\fR with the type name \fIname\fR in the +current context namespace. Forward references to a so far not +defined element types or recursive references are allowed. If +a forward referenced element type isn't defined until +validation no content or attributes are expected. +.TP +\&\fB\fBref\fP \fIname\fB \fI?quant?\fB +\&\fRThis command refers to the content particle defined with +\&\fIdefpattern\fR with the name \fIname\fR in the current +context namespace. Forward references to a so far not defined +pattern or recursive references are allowed. If a forward +referenced pattern isn't defined until validation no content +whatsoever is expected ("empty match"). +.TP +\&\fB\fBgroup\fP \fI?quant?\fB \fI\fB +\&\fRThis method allows to group a sequence of content +particle, defined by the \fIdefinition script>\fR, that have +to match in this sequence order. +.TP +\&\fB\fBchoice\fP \fI?quant?\fB \fI\fB +\&\fRThis schema constraint match if one of the top level +content particle defined by the \fIdefinition script>\fR +match. If one of this top level content particle is optional +this constraint matches the "empty match". +.TP +\&\fB\fBinterleave\fP \fI?quant?\fB \fI\fB +\&\fRThis schema constraint match after every of the top +level content particle with quant must defined by the +\&\fIdefinition script>\fR have matched in any arbitrary +order. +.TP +\&\fB\fBmixed\fP \fI?quant?\fB \fI\fB +\&\fRThis schema constraint match for any text (including the +empty one) and every top level content particle defined by the +\&\fIdefinition script>\fR with default quantifier *. +.TP +\&\fB\fBtext\fP \fI?|\*(lqtype\*(lq typename?\fB +\&\fRWithout the optional constraint script this validation +constraint matches every string (including the empty one). +With \fIconstraint script\fR or with a given text type +argument a text matching this script or the text type is +expected. +.TP +\&\fB\fBany\fP \fI?namespace?\fB \fI?quant?\fB +\&\fRThe any command matches every element (in the namespace +\&\fInamespace\fR, if that is given) (with whatever attributes) +or subtree, no matter if known within the schema or not. +Please notice, that in case of no \fInamespace\fR argument is +given this mean the quantifier * and + will eat up any +elements until the enclosing element ends. If you really have +a namespace that looks like a valid tDOM schema quantifier +you'll have to spell out always all two arguments. +.TP +\&\fB\fBattribute\fP \fIname\fB \fI?quant?\fB \fI(?|\*(lqtype\*(lq typename?)\fB +\&\fRThe attribute command defines a attribute (in no +namespace) to the enclosing element. The first definition of +\&\fIname\fR inside an element definition wins; later +definitions of the same name are silently ignored. After the +\&\fIname\fR argument there may be one of the quantifiers ? or +!. If there is, this will be used. Otherwise the attribute +will be required (must be present in the XML source). If there +is one argument more this argument is evaluated as constraint +script, defining the value constrains of the attribute. +Otherwise, if there are two more arguments and the first of +them is the bare-word "type" then the following is used as a +text type name. This command is only allowed at top level in +the definition script of an defelement/element script. +.TP +\&\fB\fBnsattribute\fP \fIname\fB \fInamespace\fB \fI?quant?\fB \fI(?|\*(lqtype\*(lq typename?)\fB +\&\fRThis command does the same as the command +\&\fIattribute\fR, just for the attribute \fIname\fR in the +namespace \fInamespace\fR. +.TP +\&\fB\fBnamespace\fP \fIURI\fB \fI\fB +\&\fREvaluates the \fIdefinition script\fR with context +namespace \fIURI\fR. Every element, element type or ref +command name will be looked up in the namespace \fIURI\fR and +local defined element will be in that namespace. The empty +string as \fIURI\fR means no namespace. +.TP +\&\fB\fBtcl\fP \fItclcmd\fB \fI?arg arg ...?\fB +\&\fREvaluates the Tcl script \fItclcmd arg arg ... \fR. This +validation command is only allowed in strict sequential +context (not in choice, mixed and interleave). If the return +code is something else than 0 (TCL_OK) then this is an +error (which isn't catched and reported by reportcmd). +.TP +\&\fB\fBself\fP +\&\fRReturns the schema command. +.TP +\&\fB\fBassociate\fP \fIdata\fB +\&\fRThis command is only allowed top-level inside the +definition scripts of the element, elementtype, pattern or +interleave content particle. Associate the as argument given +\&\fIdata\fR with the currently defined content particle and +may be requested in scripts evaluated while validating the +content of that particle with the schema command method call +\&\fIinfo stack associated\fR. +.TP +\&\fB\fBdomunique\fP \fIselector\fB \fIfieldlist\fB \fI?name?\fB \fI?\*(lqIGNORE_EMPTY_FIELD_SET\*(lq|(\*(lqEMPTY_FIELD_SET_VALUE\*(lq emptyFieldSetValue)?\fB +\&\fRIf not postvalidating a DOM tree with \fIdomvalidate\fR +this constraint always match. If postvalidating this +constraint resembles the xsd key/keyref mechanism. The +\&\fIselector\fR argument may be any valid XPath expression +(without the xsd limits). Several \fIdomunique\fR command +within one element definition are allowed. They are checked in +definition order. The argument name is available in the +recovering script per \fIinfo vaction name\fR. If the +\&\fIfieldlist\fR doesn't select something for a node of the +result set of the \fIselector\fR then the key value will be +the empty string, by default. If the arguments +\&\fIEMPTY_FIELD_SET_VALUE \fR are given a empty node +set will have the key value \fIvalue\fR. If instead the flag +\&\fIIGNORE_EMPTY_FIELD_SET\fR flag is given then an empty node +set result will not have any key value. +.TP +\&\fB\fBdomxpathboolean\fP \fIXPath_expr\fB \fI?name?\fB +\&\fR +.RS +.PP +If not postvalidating a DOM tree with +\&\fIdomvalidate\fR this constraint always match. If +postvalidating this constraint matches if the result of the +\&\fIXPath_expr\fR argument (with the node matching the schema +parent of the \fIdomxpathboolean\fR command as context node) +- converted to a boolean by XPath rules - is true. Several +\&\fIdomxpathboolean\fR command within one element definition +are allowed. They are checked in definition order. +.PP +This enables if-then checks depending on more than one element. Consider + + + +.CS + +tdom::schema s +s define { + defelement doc { + element a ! text + element b ! text + element c ! text + domxpathboolean "a * b * c >= 20000" volume + domxpathboolean "a > b and b > c" sequence + } +} + +.CE +.RE +.TP +\&\fB\fBprefixns\fP \fI?prefixUriList?\fB +\&\fRThis defines a prefix to namespace URI mapping exactly +as a \fIschemacmd prefixns\fR call. This is meant as top-level +command of a \fIschemacmd define\fR script. This command is +not allowed nested in an other definition script command and +will raise error, if you call it there. +.TP +\&\fB\fBdefelement\fP \fIname\fB \fI?namespace?\fB \fI\fB +\&\fRThis defines an element exactly as a \fIschemacmd +defelement\fR call. This is meant as top-level command of a +\&\fIschemacmd define\fR script. This command is not allowed +nested in an other definition script command and will raise +error, if you call it there. +.TP +\&\fB\fBdefelementtype\fP \fIname\fB \fI?namespace?\fB \fI\fB +\&\fRThis defines an elementtype exactly as a \fIschemacmd +defelementtype\fR call. This is meant as top-level command of a +\&\fIschemacmd define\fR script. This command is not allowed +nested in an other definition script command and will raise +error, if you call it there. +.TP +\&\fB\fBdefpattern\fP \fIname\fB \fI?namespace?\fB \fI\fB +\&\fRThis defines a named pattern exactly as a \fIschemacmd +defpattern\fR call. This is meant as top-level command of a +\&\fIschemacmd define\fR script. This command is not allowed +nested in an other definition script command and will raise +error, if you call it there. +.TP +\&\fB\fBdeftexttype\fP \fIname\fB \fI\fB +\&\fRThis defines a named bundle of text constraints exactly +as a \fIschemacmd deftexttype\fR call. This is meant as top-level +command of a \fIschemacmd define\fR script. This command is +not allowed nested in an other definition script command and +will raise error, if you call it there. +.TP +\&\fB\fBstart\fP \fIname\fB \fI?namespace?\fB +\&\fRThis command works exactly as a \fIschemacmd start\fR +call. This is meant as top-level command of a \fIschemacmd +define\fR script. This command is not allowed nested in an +other definition script command and will raise error, if you +call it there. +.SH "Quantity specifier" +.PP +Several schema definition commands expects a quantifier as +one of their arguments, which specifies how often the content +particle specified by the command is expected. The valid values +for a \fIquant\fR argument are: +.IP "\fB!\fR" +The content particle must occur exactly once in valid +documents. +.IP "\fB?\fR" +The content particle must occur at most once in valid +documents. +.IP "\fB*\fR" +The content particle may occur zero or more times in a +row in valid documents. +.IP "\fB+\fR" +The content particle may occur one or more times in a +row in valid documents. +.IP "\fBn\fR" +The content particle must occur n times in a row in +valid documents. The quantifier must be an integer greater +zero. +.IP "\fB{n m}\fR" +The content particle must occur +n to m times (both inclusive) in a row in valid documents. The +quantifier must be a tcl list with two elements. Both elements +must be integers, with n >= 0 and n < m. +.PP +If an optional quantifier is not given then it defaults to * in +case of the \fImixed\fR command and to ! for all other commands. +.SH "Text constraint scripts" +.PP +Text - parsed character data, as XML calls it - must sometimes +be of a certain kind, must comply to some rules etc to be valid. +The text constraint script arguments to the text, attribute, +nsattribute and deftexttype commands are evaluated in the Tcl +namespace \fItdom::schema::text\fR namespace and allow the +following text constraint commands to check text for certain +properties. The commands are defined in the Tcl namespace +\&\fItdom::schema::text\fR. They raise error in case they are +called outside of a text constraint script. +.PP +A few of the following text type commands are exposed as +general Tcl commands. They are defined in the namespace tdom::type +and are called as documented below with the text to check appended +to the argument list. They return a logical value. Please note, +that the commands may not accept starting or ending white space. It +is noted with the command documentation, if the command is +available in the tdom::type namespace. +.SS "The tcl text constraint command" +.PP +The \fItcl\fR text constraint command dispatches the check +to an arbitrary Tcl command, thus enable any programmable +decision rules. +.TP +\&\fB\fBtcl\fP \fItclcmd\fB \fI?arg arg ...?\fB +\&\fREvaluates the tcl script \fItclcmd arg arg ... \fR and +the text to validate appended to the argument list. The return +value of the tcl command is interpreted as a boolean. +.SS "Basic XML types" +.TP +\&\fB\fBname\fP +.UR "https://www.w3.org/TR/xml/#NT-Name" + +.UE +\&\fRThis text constraint match if the text value match the +XML name production +\&. This means the +text value must start with a letter, underscore (_), or colon (:), +and may contain only letters, digits, underscores (_), colons +(:), hyphens (-), and periods (.). +.TP +\&\fB\fBncname\fP +.UR "https://www.w3.org/TR/xml-names/#NT-NCName" + +.UE +\&\fRThis text constraint match if the text value match the +XML ncname production +\&. This +means the text value must start with a letter or underscore (_), +and may contain only letters, digits, underscores (_), hyphens +(-), and periods (.) (The only difference to the name +constraint is that colons are not permitted.) +.TP +\&\fB\fBqname\fP +.UR "https://www.w3.org/TR/xml-names/#NT-QName" + +.UE +\&\fRThis text constraint match if the text value match the +XML qname production +\&. This +means the text value is either a ncname or two ncnames joined +by a colon (:). +.TP +\&\fB\fBnmtoken\fP +.UR "https://www.w3.org/TR/xml/#NT-Nmtoken" + +.UE +\&\fRThis text constraint match if the text value match the +XML nmtoken production +.TP +\&\fB\fBnmtokens\fP +.UR "https://www.w3.org/TR/xml/#NT-Nmtokens" + +.UE +\&\fRThis text constraint match if the text value match the +XML nmtokens production +.SS "Basic type tests" +.PP +.TP +\&\fB\fBinteger\fP \fI?(xsd|tcl)?\fB +\&\fRThis text constraint match if the text value could be +parsed as an integer. If the optional argument to the command +is \fItcl\fR everything that returns TCL_OK if feeded into +Tcl_GetInt() matches. If the optional argument to the command +is \fIxsd\fR then the constraint match if the value is a +valid xsd:integer. Without argument \fIxsd\fR is the +default. +.TP +\&\fB\fBnegativeInteger\fP \fI?(xsd|tcl)?\fB +\&\fRThis text constraint match the same text values as the +\&\fIinteger\fR text constraint (see there) with the additional +constraint that the value must be < zero. +.TP +\&\fB\fBnonNegativeInteger\fP \fI?(xsd|tcl)?\fB +\&\fRThis text constraint match the same text values as the +\&\fIinteger\fR text constraint (see there) with the additional +constraint that the value must be >= zero. +.TP +\&\fB\fBnonPositiveInteger\fP \fI?(xsd|tcl)?\fB +\&\fRThis text constraint match the same text values as the +\&\fIinteger\fR text constraint (see there) with the additional +constraint that the value must be <= zero. +.TP +\&\fB\fBpositiveInteger\fP \fI?(xsd|tcl)?\fB +\&\fRThis text constraint match the same text values as the +\&\fIinteger\fR text constraint (see there) with the additional +constraint that the value must be > zero. +.TP +\&\fB\fBnumber\fP \fI?(xsd|tcl)?\fB +\&\fRThis text constraint match if the text value could be +parsed as a number. If the optional argument to the command is +\&\fItcl\fR everything that returns TCL_OK if feeded into +Tcl_GetDouble() matches. If the optional argument to the command +is \fIxsd\fR then the constraint match if the value is a +valid xsd:decimal. Without argument \fIxsd\fR is the +default. +.TP +\&\fB\fBboolean\fP \fI?(xsd|tcl)?\fB +\&\fRThis text constraint match if the text value could be +parsed as a boolean. If the optional argument to the command is +\&\fItcl\fR everything that returns TCL_OK if feeded into +Tcl_GetBoolean() matches. If the optional argument to the command +is \fIxsd\fR then the constraint match if the value is a +valid xsd:boolean. Without argument \fIxsd\fR is the +default. +.TP +\&\fB\fBdate\fP +\&\fRThis text constraint match if the text value is +a xsd:date. This is basically like an ISO 8601 date of +the form YYYY-MM-DD, with optional time zone part +(either the letter Z or plus (+) or minus (-) followed +by hh:mm and with maximum allowed positive or negative +time zone 14:00). It follows the date rules of the +Gregorian calendar for all dates. A preceding minus +sign for bce dates is allowed. There is no year 0. The +year may have more than 4 digits, but only if needed +(no extra leading zeros). This is available as common +tcl command tdom::type::date. +.TP +\&\fB\fBtime\fP +\&\fRThis text constraint match if the text value is +a xsd:time. This is basically like an ISO 8601 time of +the form hh:mm:ss with optional time zone part. The +time zone part follow the rules of the \fIdate\fR +command; see there. All three parts of the time value +(hours, minutes, seconds) must be spelled out with 2 +digits. Additional fractional seconds (with a point +('.') as separator) are allowed, but not just a +dangling point. The time value 24:00:00 (without +fractional part) is allowed. This is available as +common tcl command tdom::type::time. +.TP +\&\fB\fBdateTime\fP +\&\fRThis text constraint match if the text value is +a xsd:dateTime. This is basically like an ISO 8601 +date time of the form YYYY-MM-DDThh:mm:ss with +optional time zone part. The date and time zone parts +follow the rules of the \fIdate\fR command; see +there. The time part (including the signaling 'T' +character) is mandatory and follow the rules of the +\&\fItime\fR command, see there. This is available as +common tcl command tdom::type::dateTime. +.TP +\&\fB\fBduration\fP +\&\fRThis text constraint match if the text value is +a xsd:duration. This is basically like an ISO 8601 +duration of the form PnYnMnDTnHnMnS. All parts other +then the starting P and - if one of H, M or S is given +- T are optional. In case the following sign letter is +S n may be a decimal (with at least one digit before +and after the dot), otherwise it must be a (positive) +integer. This is available as common tcl command +tdom::type::duration. +.TP +\&\fB\fBbase64\fP +\&\fRThis text constraint match if text is valid according to +RFC 4648. +.TP +\&\fB\fBhexBinary\fP +\&\fRThis text constraint match if text is a sequence of +binary octets in hexadecimal encoding, where each binary octet +is a two-character hexadecimal number. Lowercase and uppercase +letters A through F are permitted. +.TP +\&\fB\fBunsignedByte\fP +\&\fRThis text constraint match if the text value is a +xsd:unsignedByte. This is an integer between 0 and 255, both +included, optionally preceded by a + sign and leading +zeros. +.TP +\&\fB\fBunsignedShort\fP +\&\fRThis text constraint match if the text value is a +xsd:unsignedShort. This is an integer between 0 and 65535, +both included, optionally preceded by a + sign and leading +zeros. +.TP +\&\fB\fBunsignedInt\fP +\&\fRThis text constraint match if the text value is a +xsd:unsignedInt. This is an integer between 0 and 4294967295, +both included, optionally preceded by a + sign and leading +zeros. +.TP +\&\fB\fBunsignedLong\fP +\&\fRThis text constraint match if the text value is a +xsd:unsignedLong. This is an integer between 0 and +18446744073709551615, both included, optionally preceded by a ++ sign and leading zeros. +.SS "Logical constructs" +.TP +\&\fB\fBoneOf\fP \fI\fB +\&\fRThis text constraint match if one of the text +constraints defined in the argument \fIconstraint script\fR +match the text. It stops after the first match and probes the +text constraints in the order of definition. +.TP +\&\fB\fBallOf\fP \fI\fB +\&\fRThis text constraint match if all of the text +constraints defined in the argument \fIconstraint script\fR +match the text. It stops after the first match failure and +probes the text constraints in the order of definition. Since +the schema definition command \fItext\fR also expects all +text constraints to match the text constraint \fIallOf\fR is +useful mostly together with the \fIoneOf\fR text constraint +command. +.TP +\&\fB\fBnot\fP \fI\fB +\&\fRThis text constraint match if none of the text +constraints defined in the argument \fIconstraint +script\fR match the text. It stops after the first +matching constraint in the \fIconstraint script\fR and +reports validation error. The text constraints in the +\&\fIconstraint script\fR are probed in the order of +definition. +.SS "Constraints on processed text value" +.TP +\&\fB\fBwhitespace\fP \fI(preserve|replace|collapse)\fB \fI\fB +\&\fRThis text constraint command does white-space (#x20 +(space, ' '), #x9 (tab, \et), #xA (linefeed, \en), and #xD +(carriage return, \er) normalization to the text value and +checks the resulting text with the text constraints of the +constraint script argument. The normalization method +\&\fIpreserve\fR keeps everything as it is; this is another way +to say \fIallOf\fR. The \fIreplace\fR normalization method +replaces any single white-space character (as above) to a +space. The \fIcollapse\fR normalization method removes all +leading and trailing white-space and all the other sequences of +contiguous white-space are replaced by a single space. +.TP +\&\fB\fBsplit\fP \fI?type ?args??\fB\fI\fB +\&\fR +.RS +.PP +This text constraint command splits the text to test +into a list of values and tests all elements of that list for +the text constraints in the evaluated \fIconstraint +script>\fR. +.PP +The available types are: +.TP +whitespace +The text to split is striped of all +white space at start and end splited into a list at any +successive white space. +.TP +tcl tclcmd ?arg ...? +The text to split is +handed to the \fItclcmd\fR, which is evaluated on global +level, appended with every given arg and the text to split +as last argument. This call must return a valid tcl list, +which elements are tested. +.PP +The default in case no split type argument is given is +\&\fIwhitespace\fR. +.RE +.TP +\&\fB\fBstrip\fP \fI\fB +\&\fRThis text constraint command tests all text constraints +in the evaluated \fIconstraint script>\fR with the text to +test striped of all white space at start and end. +.SS "Various other string properties" +.TP +\&\fB\fBfixed\fP \fIvalue\fB +\&\fRThe text constraint only match if the text value is +string equal to the given value. +.TP +\&\fB\fBenumeration\fP \fIlist\fB +\&\fRThis text constraint match if the text value is equal to +one element (respecting case and any white-space) of the +argument \fIlist\fR, which has to be a valid Tcl list. +.TP +\&\fB\fBmatch\fP \fI?-nocase?\fB \fIglob_style_match_pattern>\fB +.UR "https://www.tcl.tk/man/tcl8.6/TclCmd/string.htm#M35" + +.UE +\&\fRThis text constraint match if the text value match the +glob style pattern given as argument. It follows the rules of +the Tcl [string match] command, see +\&. +.TP +\&\fB\fBregexp\fP \fIexpression\fB +.UR "https://www.tcl.tk/man/tcl8.6/TclCmd/re_syntax.htm" + +.UE +\&\fRThis text constraint match if the text value match the +regular expression given as argument. describes the regular expression syntax +.TP +\&\fB\fBlength\fP \fIlength\fB +\&\fRThis text constraint match if the length of the text +value (in characters, not bytes) is \fIlength\fR. The +length argument must be a positive integer or zero. +.TP +\&\fB\fBmaxLength\fP \fIlength\fB +\&\fRThis text constraint match if the length of the text +value (in characters, not bytes) is at most \fIlength\fR. The +length argument must be an integer greater zero. +.TP +\&\fB\fBminLength\fP \fIlength\fB +\&\fRThis text constraint match if the length of the text +value (in characters, not bytes) is at least \fIlength\fR. +The length argument must be an integer greater zero. +.TP +\&\fB\fBid\fP \fI?keySpace?\fB +\&\fRThis text constraint command marks the text as a +document wide ID (to be referenced by an idref). Every ID +value within a document must be unique. It isn't an error if +the ID isn't actually referenced within the document. The +optional argument \fIkeySpace\fR does all this for a named +key space. The key space "" (the empty sting) is another key +space as the \fIid\fR command without keySpace +argument. +.TP +\&\fB\fBidref\fP \fI?keySpace?\fB +\&\fRThis text constraint command expects the text to be a +reference to an ID within the document. The referenced ID may +be later in the document, that the reference. Several +references within the document to one ID are possible. +.SH "Local key constraints" +.PP +Document wide uniqueness and foreign key constraints are +available with the text constraint commands id and idref. +Keyspaces allow for sub-tree local uniqueness and foreign key +constraints. +.TP +\&\fB\fBkeyspace\fP \fI\fB \fI\fB +\&\fRAny number of keyspaces are possible. A keyspace is +either active or not. An inside a \fIconstraint +script\fR called keyspace with the same name does +nothing. +.PP +This text constraint commands work with keyspaces: +.TP +\&\fB\fBkey\fP \fI\fB +\&\fRIf the keyspace with the name \fI\fR is not +active always matches. If the keyspace is active then +reports error if there is already a key with the value. +Otherwise, stores the value as key in this keyspace and +matches. +.TP +\&\fB\fBkeyref\fP \fI\fB +\&\fRIf the keyspace with the name \fI\fR is not +active always matches. If the keyspace is active then +reports error if there is still no key as the value at the +end of the keyspace \fI\fR. Otherwise it +matches. +.SH Recovering +.PP +By default the validation engine stops at the first detected +validation violation and report that finding. It does so by +return false (and set, if given, the result variable with an +error message) in case the schema command itself is used to +validate input. If the schema command is used by a SAX parser or +the DOM parser it does so by throwing error. +.PP +If a \fIreportcmd\fR is set this command is called on global +level appended with the schema command and an error type as +arguments if a validation violation is detected. Then the +validation recovers from the error and continues. For some +validation errors the recover strategy can be determined with +the script result of the reportcmd. +.PP +With a \fIreportcmd\fR (which doesen&t throw error if +called) the validation engine will never report validation +failure to its caller. The validation engine recovers, continues +and report the next error, if one happen and so until the end of +the input. The schema command will return true and the SAX +parser and DOM builder will process normally until the end of +the input, as if there would not have been validation. +.PP +Please note, that this happens only for validation errors. It +isn't possible to recover from well-formedness errors. If the +input isn't well-formed the schema command returns false and +set, if given, the result variable with an error message about +the well-formedness error. +.PP +If the \fIreportcmd\fR throws error while called by the +validation engine then validation stops and the schema command +throws error with the error message of the script. +.SH Examples +.PP +.UR "https://www.w3.org/TR/xmlschema-0/" + +.UE +The XML Schema Part 0: Primer Second Edition +() starts with this +example schema: +.CS + + + + + + Purchase order schema for Example.com. + Copyright 2000 Example.com. All rights reserved. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +.CE +.PP +A somewhat one-to-one translation of that into a tDOM schema +definition script would be: +.CS + +tdom::schema schema +schema define { + + # Purchase order schema for Example.com. + # Copyright 2000 Example.com. All rights reserved. + + defelement purchaseOrder {ref PurchaseOrderType} + + foreach elm {comment name street city state product} { + defelement $elm text + } + + defpattern PurchaseOrderType { + element shipTo ! {ref USAddress} + element billTo ! {ref USAddress} + element comment ? + element items + attribute orderDate date + } + + defpattern USAddress { + element name + element street + element city + element state + element zip ! {text number} + attribute country ! {fixed "US"} + } + + defelement items { + element item * { + element product + element quantity ! {text integer} + element USPrice ! {text number} + element comment + element shipDate ? {text date} + attribute partNum ! {pattern "^\ed{3}-[A-Z]{2}$"} + } + } +} + + +.CE +.PP +.UR "http://relaxng.org/tutorial-20011203.html" + +.UE +The RELAX NG Tutorial +() starts with +this example: +.CS + +Consider a simple XML representation of an email address book: + + + + John Smith + js@example.com + + + Fred Bloggs + fb@example.net + + + +The DTD would be as follows: + + + + + +]> + +A RELAX NG pattern for this could be written as follows: + + + + + + + + + + + + + + + +.CE +.PP +This schema definition script will do the same: +.CS + +tdom::schema schema +schema define { + defelement addressBook { + element card * + } + defelement card { + element name + element email + } + foreach e {name email} { + defelement $e {text} + } +} + + +.CE +.SH KEYWORDS +Validation, Postvalidation, DOM, SAX ADDED doc/schema.xml Index: doc/schema.xml ================================================================== --- /dev/null +++ doc/schema.xml @@ -0,0 +1,1476 @@ + + + + tdom::schema + Create a schema validation command + + + + package require tdom + +tdom::schema ?create? cmdName + + + +
+ DESCRIPTION + +

Every call of this command creates a new validation command. A + validation command has methods to define a schema and is able + to validate XML data or to post-validate a tDOM DOM tree (and to + some degree other kind of hierarchical data) against this + schema.

+ +

Additionally, a validation command may be used as argument to + the -validateCmd option of the dom parse and the + expat commands to enable validation additional to what they + do otherwise.

+ +

The methods of created commands are:

+ + + + prefixns ?prefixUriList? + This method gives control to a prefix (or + abbreviation) to namespace URI mapping. Wherever a namespace + argument is expected in the schema command methods you may + use the "prefix" pointing to the namespace URI in + the current prefixUriList, set by this method. If the list + maps the same prefix to different namespace URIs, the first + one win. If there is no such a prefix the namespace argument + is used literally as namespace URI. If the method is called + without argument it returns the current prefixUriList. If + the method is called with the empty string any namespace URI + arguments are used literally. This is the default. + + + + + defelement name ?namespace? <definition script> + This method defines the element name (optional in + the namespace namespace) in the schema. The + definition script is evaluated and defines the content + model of the element. If the namespace argument is + given, any element or ref references in the + definition script not wrapped inside a namespace + command are resolved in that namespace. If there is already a + element definition for the name/namespace combination the + command raises error. + + + + defelementtype typename name ?namespace? <definition script> + This method defines the element type typename + (optional in the namespace namespace) in the schema. If + the element type is used in a definition script with the + schema command elementtype, the validation engine expects an + element named name (in the namespace namespace, + if given) and the content model definition script. + Defining element types seems only sensible if you really have + elements with the same name and namespace but different + content models. The definition script is evaluated and + defines the content model of the element. If the + namespace argument is given, any element or + ref references in the definition script not wrapped + inside a namespace command are resolved in that + namespace. If there is already a elementtype definition for + the name/namespace combination the command raises error. The + document element of any XML to validate cannot be a + defelementtype defined element. + + + + defpattern name ?namespace? <definition script> + This method defines a (maybe complex) content particle + with the name (optional in the namespace + namespace) in the schema, to be used in other + definition scripts with the definition command ref. The + definition script is evaluated and defines the content + model of the content particle. If the namespace + argument is given, any element or ref references + in the definition script not wrapped inside a namespace + command are resolved in that namespace. If there is already a + pattern definition for the name/namespace combination the + command raises error. + + + + deftexttype name <constraint script> + This method defines a bundle of text constraints that + can be referred to by name while defining constrains on + text element or attribute values. If there is already a text + type definition with this name, the command raises error. A + text type must be defined before it can be used in schema + definition scripts. + + + + start documentElement ?namespace? + This method defines the name and namespace of the root + element of a tree to validate. If this method is used, then + the root element must match for validity. If start is + not used, any element defined by defelement may be the + root of a valid document. The start method may be used + several times with varying arguments during the lifetime of a + validation command. If the command is called with just the + empty string (and no namespace argument), the validation + constraint for the root element is removed and any defined + element will be valid as root of a tree to validate. + + + + define <definition script> + This method allows to define several elements or pattern + or a whole schema with one call. All schema command methods so + far (prefixns, defelement, + defelementtype, defpattern, deftexttype and + start) are allowed top level in the definition + script. The define method itself isn't allowed + recursively. + + + + event (start|end|text) ?event specific data? + This method allows to validate hierarchical data against + the content constrains of the validation command. + + + + start + name ?attributes? ?namespace? + Checks if the current validation state allows the + element name in the namespace to start here. + It raises error if not. + + + + end + Checks if the current innermost open element may end + here in the current state without violation of validation + constrains. It raises error if not. + + + + text + text + Checks if the current validation state allows the + given text content. It raises error if not. + + + + + + + validate <XML string> ?objVar? + Returns true if the <XML string> is valid or + false otherwise. If validation has failed and the optional + objVar argument is given, the variable with that + name is set to a validation error message. If the XML string + is valid and the optional objVar argument is given, + the variable with that name is set to the empty string. + + + + validatefile filename ?objVar? + Returns true if the content of filename is valid + or false otherwise. The given file is feeded as binary stream + to expat, therefore only US-ASCII, ISO-8859-1, UTF-8 or UTF-16 + encoded data will work with this method. If validation failed + and the optional objVar argument is given, the variable + with that name is set to a validation error message. If the + XML string is valid and the optional objVar argument is + given, the variable with that name is set to the empty + string. + + + + validatechannel channel ?objVar? + Returns true if the content read from the Tcl channel + channel is valid or false otherwise. Since data read + out of a Tcl channel is UTF-8 encoded, any misleading encoding + declaration at the beginning of the data will lead to errors. + If the validation fails and the optional objVar + argument is given, the variable with that name is set to a + validation error message. If the XML string is valid and the + optional objVar argument is given, the variable with + that name is set to the empty string. + + + + domvalidate domNode ?objVar? + Returns true if the first argument is a valid tree or + false otherwise. If validation failed and the optional + objVar argument is given, the variable with that name + is set to a validation error message. If the dom tree is valid + and the optional objVar argument is given, the variable + with that name is set to the empty string. + + + + reportcmd ?cmd? + This method expects the name of a Tcl command to be + called in case of validation error. This command will be + called with two arguments appended: the schema command which + raises the validation error, and a validation error code. + +

The possible error codes are:

+
+
MISSING_ELEMENT
+
MISSING_TEXT
+
UNEXPECTED_ELEMENT
+
UNEXPECTED_ROOT_ELEMENT
+
UNEXPECTED_TEXT
+
UNKNOWN_ROOT_ELEMENT
+
UNKNOWN_ATTRIBUTE
+
MISSING_ATTRIBUTE
+
INVALID_ATTRIBUTE_VALUE
+
DOM_KEYCONSTRAINT
+
DOM_XPATH_BOOLEAN
+
INVALID_KEYREF
+
INVALID_VALUE
+
UNKOWN_GLOBAL_ID
+
UNKOWN_ID
+
+

For more detailed information see section Recovering.

+
+
+ + + delete + This method deletes the validation command. + + + + info ?args? + This method bundles methods to query the state of and + details about the schema command. + + + validationstate + This method returns the state of the validation command + with respect to validation state. The possible return values + and their meanings are: +
+
READY
The validation command is ready to start + validation
+
VALIDATING
The validation command is in the + process of validating input.
+
FINISHED
The validation has finished, no further + events are expected.
+
+
+
+ + vstate + This method is a shorter alias for validationstate; see there. + + + line + If the schema command is currently validating, + this method returns the line part of the parsing + position information and the empty string in all + other cases. If the schema command is currently + post-validating a DOM tree there may be no position + information stored at some or all nodes. The + empty string is returned in these cases. + + + column + If the schema command is currently validating + this method returns the column part of the parsing + position information and the empty string in all + other cases. If the schema command is currently + post-validating a DOM tree there may be no position + information stored at some or all nodes. The + empty string is returned in these cases. + + + domNode + If the schema command isn't currently + post-validating a DOM tree this method returns the + empty string. Otherwise, if the schema command waits + for the reportcmd script to finish while recovering + from a validation error it returns the node on which + the validation engine is currently looking at in + case the node is an ELEMENT_NODE or, if not, its + parent node. It is recommended that you do not use + this method. Or at least leave the DOM tree alone, + use it read-only. + + + nrForwardDefinitions + Returns how much element, elementtype and ref + pattern are referenced that aren't defined so far + (summed together). + + + definedElements + Returns in no particular order the defined + elements in the grammar as list. If an element is + namespaced its list entry will be itself a list with + two elements, with the name as first and the + namespace as second element. + + + definedElementtypes + Returns in no particular order the defined + element types in the grammar as list. If an element + type is namespaced its list entry will be itself a + list with two elements, with the name as first and + the namespace as second element. + + + definedPatterns + Returns in no particular order the defined + named pattern in the grammar as list. If a named + pattern is namespaced its list entry will be itself + a list with two elements, with the name as first and + the namespace as second element. + + + expected + Returns in no particular order all possible + next events (since the last successful event match, + if there was one) as a list. If an element is + namespaced its list entry will be itself a list with + two elements, with the name as first and the + namespace as second element. If text is a possible + next event the list entry will be a two elements + list, with #text as first element and the empty + space as second. If an any element constraint is + possible the list entry will be a two elements list, + with <any> as first element and the empty space + as second. If an any element in a certain namespace + constraint is possible the list entry will be a two + elements list, with <any> as first element and + the namespace as second. If element end is a + possible event the list entry will be a two elements + list with <elementend> as first element and the + empty string as second element. + + + definition name ?namespace? + Returns the code that defines the given + element. The command raises error if there isn't a + definition of that element. + + + + typedefinition name ?namespace? + Returns the code that defines the given + element type definition. The command raises error if + there isn't a definition of that element. + + + + patterndefinition name ?namespace? + Returns the code that defines the given + pattern definition. The command raises error if + there isn't a definition of a pattern with that name + and, if given, namespace. + + + + vaction ?name|namespace|text? +

This method returns useful information only if + the schema command waits for the reportcmd script to + finish while recovering from a validation error. + Otherwise it returns NONE.

+

If the command is called without the optional + argument the possible return values and their + meanings are:

+
+
NONE
The schema command currently + doesn't recover from a validation event.
+
MATCH_ELEMENT_START
Element start event, which includes looking for missing or unknown attributes.
+
MATCH_ELEMENT_END
Element end event.
+
MATCH_TEXT
Validating text between tags.
+
MATCH_ATTRIBUTE_TEXT
Attribute text value constraint check
+
MATCH_GLOBAL
Checking global IDs
+
MATCH_DOM_KEYCONSTRAINT
Checking domunique constraint
+
MATCH_DOM_XPATH_BOOLEAN
Checking domxpathboolean constant
+
+

If called with one of the possible optional + arguments, the command returns detail information + depending on current action.

+
+
name
Returns the name of the element + that has to match in case of + MATCH_ELEMENT_START. Return the name of the + closed element in case of MATCH_ELEMENT_END. + Returns the name of the attribute in case of + MATCH_ATTRIBUTE_TEXT. Return the name of the + parent element in case of MATCH_TEXT.
+ +
namespace
Returns the namespace of + the element that has to match in case of + MATCH_ELEMENT_START. Return the namespace of the + closed element in case of MATCH_ELEMENT_END. + Returns the namespace of the attribute in case + of MATCH_ATTRIBUTE_TEXT. Return the namespace of + the parent element in case of MATCH_TEXT.
+ +
text
Returns the text to match in + case of MATCH_TEXT. Returns the value of the + attribute in case of MATCH_ATTRIBUTE_TEXT.
+
+
+
+ + stack top|inside|associated + In Tcl scripts evaluated by validation this method + provides information about the current validation stack. + Called outside this context the method returns the empty + string. + + + top + Returns the element whose content is currently + checked (the open element tag at this moment). + + + + + inside + Returns all currently open elements as a list. + + + + associated + Returns the data associated with the + current top most stack content particle or + the empty string it there isn't any. + + + + + +
+
+
+ + + reset + This method resets the validation command into state + READY (while preserving the defined grammar). + + +
+
+ +
+ Schema definition scripts + +

Schema definition scripts are ordinary Tcl scripts evaluated in + the namespace tdom::schema. The schema definition commands listed + below in this Tcl namespace allow to define a wide variety of + document structures. Every schema definition command establishes a + validation constraint on the content which has to match or must be + optional to qualify the content as valid. It is a validation error + if there is additional (not matched) content. White space only + text (in the XML sense of white space) between any different tags + is ignored, with the exception of text only elements (for which + even white space only text will be considered as significant + content).

+ +

The schema definition commands are:

+ + + + element name ?quant? ?<definition script>? + If the optional argument definition script is not + given this command refers to the element defined with + defelement with the name name in the current + context namespace. If the defelement script argument is + given, then the validation constraint expects an element with + the name name in the current namespace with content + "locally" defined by the definition script. Forward + references to so far not defined elements or patterns or other + local definitions of the same name inside the definition + script are allowed. If a forward referenced element is not + defined until validation then only an empty element with name + name and namespace namespace and no attributes + matches. + + + + elementtype name ?quant? + This command refers to the element defined with + defelementtype with the type name name in the + current context namespace. Forward references to so far not + defined element types or recursive references are allowed. If + a forward referenced element type is not defined until + validation any empty element without attributes will be + accepted. + + + + ref name ?quant? + This command refers to the content particle defined with + defpattern with the name name in the current + context namespace. Forward references to a so far not defined + pattern and recursive references are allowed. If a forward + referenced pattern is not defined until validation no content + whatsoever is expected ("empty match"). + + + + group ?quant? <definition script> + This method allows to group a sequence of content + particles defined by the definition script>, which have + to match in this sequence order. + + + + choice ?quant? <definition script> + This schema constraint match if one of the top level + content particles defined by the definition script> + matches. If one of this top level content particle is optional + this constraint matches the "empty match". + + + + + interleave ?quant? <definition script> + This schema constraint match after every of the required + top level content particles defined by the definition + script> have matched (and, optional, some or all other) in + any arbitrary order. + + + + mixed ?quant? <definition script> + This schema constraint matches for any text (including the + empty one) and every top level content particle defined by the + definition script> with default quantifier *. + + + + text ?<constraint script>|"type" typename? + Without the optional constraint script this validation + constraint matches every string (including the empty one). + With constraint script or with a given text type + argument a text matching this script or the text type is + expected. + + + + any ?namespace? ?quant? + The any command matches every element (in the namespace + namespace, if that is given) (with whatever attributes) + or subtree, no matter if known within the schema or not. + Please note that in case of no namespace argument is + given that means that the quantifier * and + will eat up any + elements until the enclosing element ends. If you really have + a namespace that looks like a valid tDOM schema quantifier + you will have to spell out always both arguments. + + + + attribute name ?quant? (?<constraint script>|"type" typename?) + The attribute command defines an attribute (in no + namespace) to the enclosing element. The first definition of + name inside an element definition wins; later + definitions of the same name are silently ignored. After the + name argument there may be one of the quantifiers ? or + !. If there is, it will be used. Otherwise the attribute will + be required (must be present in the XML source). If there is + one argument more this argument is evaluated as constraint + script, defining the value constrains of the attribute. + Otherwise, if there are two more arguments and the first of + them is the bare-word "type" the following argument is used as + a text type name. This command is only allowed at top level in + the definition script of an defelement/element script. + + + + nsattribute name namespace ?quant? (?<constraint script>|"type" typename?) + This command does the same as the command + attribute, for the attribute name in the + namespace namespace. + + + + namespace URI <definition script> + Evaluates the definition script with context + namespace URI. Every element, element type or ref + command name will be looked up in the namespace URI, + and local defined elements will be in that namespace. An + empty string as URI means no namespace. + + + + tcl tclcmd ?arg arg ...? + Evaluates the Tcl script tclcmd arg arg ... . + This validation command is only allowed in strict sequential + context (not in choice, mixed and interleave). If the return + code is something else than 0 (TCL_OK) this is an error (which + is not catched and reported by reportcmd). + + + + self + Returns the schema command. + + + + associate data + This command is only allowed top-level inside definition + scripts of the element, elementtype, pattern or interleave + content particles. Associates the data given as argument + with the currently defined content particle and may be + requested in scripts evaluated while validating the content of + that particle with the schema command method call info + stack associated. + + + + domunique selector fieldlist ?name? ?"IGNORE_EMPTY_FIELD_SET"|("EMPTY_FIELD_SET_VALUE" emptyFieldSetValue)? + If not postvalidating a DOM tree with domvalidate + this constraint always matches. If postvalidating this + constraint resembles the xsd key/keyref mechanism. The + selector argument may be any valid XPath expression + (without the xsd limits). Several domunique commands + within one element definition are allowed. They are checked in + definition order. The argument name is available in the + recovering script per info vaction name. If the + fieldlist doesn't select something for a node of the + result set of the selector the key value will be the + empty string by default. If the arguments + EMPTY_FIELD_SET_VALUE <value> are given an empty + node set will have the key value value. If instead the + flag IGNORE_EMPTY_FIELD_SET flag is given an empty + node set result will not have any key value. + + + + domxpathboolean XPath_expr ?name? +

If not postvalidating a DOM tree with + domvalidate this constraint always matches. If + postvalidating the XPath_expr argument is evaluated + (with the node matching the schema parent of the + domxpathboolean command as context node). The + constraint maches if the result of this XPath expression, + converted to boolean by XPath rules, is true. Several + domxpathboolean commands within one element definition + are allowed. They are checked in definition order.

+ +

This enables checks depending on more than one element. Consider

+ + +tdom::schema s +s define { + defelement doc { + element a ! text + element b ! text + element c ! text + domxpathboolean "a * b * c >= 20000" volume + domxpathboolean "a > b and b > c" sequence + } +} + +
+
+ + + prefixns ?prefixUriList? + This defines a prefix to namespace URI mapping exactly + as a schemacmd prefixns call. This is meant as top-level + command of a schemacmd define script. This command is + not allowed nested in another definition script command and + will raise error, if you call it there. + + + + defelement name ?namespace? <definition script> + This defines an element exactly as a schemacmd + defelement call. This is meant as top-level command of a + schemacmd define script. This command is not allowed + nested in another definition script command and will raise + error, if you call it there. + + + + defelementtype name ?namespace? <definition script> + This defines an elementtype exactly as a schemacmd + defelementtype call. This is meant as top-level command of a + schemacmd define script. This command is not allowed + nested in another definition script command and will raise + error, if you call it there. + + + + defpattern name ?namespace? <definition script> + This defines a named pattern exactly as a schemacmd + defpattern call. This is meant as top-level command of a + schemacmd define script. This command is not allowed + nested in another definition script command and will raise + error, if you call it there. + + + + deftexttype name <constraint script> + This defines a named bundle of text constraints exactly + as a schemacmd deftexttype call. This is meant as top-level + command of a schemacmd define script. This command is + not allowed nested in another definition script command and + will raise error, if you call it there. + + + + start name ?namespace? + This command works exactly as a schemacmd start + call. This is meant as top-level command of a schemacmd + define script. This command is not allowed nested in + another definition script command and will raise error, if you + call it there. + +
+ +
+ +
+ Quantity specifier + +

Several schema definition commands expects a quantifier as + one of their arguments, which determines how often the content + particle specified by the command is expected. The valid values + for a quant argument are:

+ + + + ! + The content particle must occur exactly once in valid + documents. + + + + ? + The content particle must occur at most once in valid + documents. + + + + * + The content particle may occur zero or more times in a + row in valid documents. + + + + + + The content particle may occur one or more times in a + row in valid documents. + + + + n + The content particle must occur n times in a row in + valid documents. The quantifier must be an integer greater + zero. + + + + {n m} The content particle must occur + n to m times (both inclusive) in a row in valid documents. The + quantifier must be a Tcl list with two elements. Both elements + must be integers, with n >= 0 and n < m. + + + +

If an optional quantifier is not given then it defaults to * in + case of the mixed command and to ! for all other commands.

+
+ +
+ Text constraint scripts + +

Text - parsed character data, as XML calls it - must sometimes + be of a certain kind, must comply to some rules etc to be valid. + The text constraint script arguments to the text, attribute, + nsattribute and deftexttype commands are evaluated in the Tcl + namespace tdom::schema::text namespace and allow the + following text constraint commands to check text for certain + properties. The commands are defined in the Tcl namespace + tdom::schema::text. They raise error in case they are + called outside of a text constraint script.

+ +

A few of the following text type commands are exposed as + general Tcl commands. They are defined in the namespace tdom::type + and are called as documented below with the text to check appended + to the argument list. They return a logical value. Please note, + that the commands may not accept starting or ending white space. It + is noted with the command documentation, if the command is + available in the tdom::type namespace. +

+ + + The tcl text constraint command +

The tcl text constraint command dispatches the check + to an arbitrary Tcl command, thus enable any programmable + decision rules.

+ + + tcl tclcmd ?arg arg ...? + Evaluates the Tcl script tclcmd arg arg ... and + the text to validate appended to the argument list. The return + value of the Tcl command is interpreted as a boolean. + + +
+ + + Basic XML types + + + name + This text constraint match if the text value match the + XML name production + https://www.w3.org/TR/xml/#NT-Name. This means the + text value must start with a letter, underscore (_), or colon (:), + and may contain only letters, digits, underscores (_), colons + (:), hyphens (-), and periods (.). + + + ncname + This text constraint match if the text value match the + XML ncname production + https://www.w3.org/TR/xml-names/#NT-NCName. This + means the text value must start with a letter or underscore (_), + and may contain only letters, digits, underscores (_), hyphens + (-), and periods (.) (The only difference to the name + constraint is that colons are not permitted.) + + + qname + This text constraint match if the text value match the + XML qname production + https://www.w3.org/TR/xml-names/#NT-QName. This + means the text value is either a ncname or two ncnames joined + by a colon (:). + + + nmtoken + This text constraint match if the text value match the + XML nmtoken production + https://www.w3.org/TR/xml/#NT-Nmtoken + + + nmtokens + This text constraint match if the text value match the + XML nmtokens production + https://www.w3.org/TR/xml/#NT-Nmtokens + + + + + + Basic type tests +

+

+ + + integer ?(xsd|tcl)? + This text constraint match if the text value could be + parsed as an integer. If the optional argument to the command + is tcl everything that returns TCL_OK if feeded into + Tcl_GetInt() matches. If the optional argument to the command + is xsd then the constraint match if the value is a + valid xsd:integer. Without argument xsd is the + default. + + + + negativeInteger ?(xsd|tcl)? + This text constraint match the same text values as the + integer text constraint (see there) with the additional + constraint that the value must be < zero. + + + + nonNegativeInteger ?(xsd|tcl)? + This text constraint match the same text values as the + integer text constraint (see there) with the additional + constraint that the value must be >= zero. + + + + nonPositiveInteger ?(xsd|tcl)? + This text constraint match the same text values as the + integer text constraint (see there) with the additional + constraint that the value must be <= zero. + + + + positiveInteger ?(xsd|tcl)? + This text constraint match the same text values as the + integer text constraint (see there) with the additional + constraint that the value must be > zero. + + + + number ?(xsd|tcl)? + This text constraint match if the text value could be + parsed as a number. If the optional argument to the command is + tcl everything that returns TCL_OK if feeded into + Tcl_GetDouble() matches. If the optional argument to the command + is xsd then the constraint match if the value is a + valid xsd:decimal. Without argument xsd is the + default. + + + boolean ?(xsd|tcl)? + This text constraint match if the text value could be + parsed as a boolean. If the optional argument to the command is + tcl everything that returns TCL_OK if feeded into + Tcl_GetBoolean() matches. If the optional argument to the command + is xsd then the constraint match if the value is a + valid xsd:boolean. Without argument xsd is the + default. + + + date + This text constraint match if the text value is + a xsd:date. This is basically like an ISO 8601 date of + the form YYYY-MM-DD, with optional time zone part + (either the letter Z or plus (+) or minus (-) followed + by hh:mm and with maximum allowed positive or negative + time zone 14:00). It follows the date rules of the + Gregorian calendar for all dates. A preceding minus + sign for bce dates is allowed. There is no year 0. The + year may have more than 4 digits, but only if needed + (no extra leading zeros). This is available as common + Tcl command tdom::type::date. + + + time + This text constraint match if the text value is + a xsd:time. This is basically like an ISO 8601 time of + the form hh:mm:ss with optional time zone part. The + time zone part follow the rules of the date + command; see there. All three parts of the time value + (hours, minutes, seconds) must be spelled out with 2 + digits. Additional fractional seconds (with a point + ('.') as separator) are allowed, but not just a + dangling point. The time value 24:00:00 (without + fractional part) is allowed. This is available as + common Tcl command tdom::type::time. + + + dateTime + This text constraint match if the text value is + a xsd:dateTime. This is basically like an ISO 8601 + date time of the form YYYY-MM-DDThh:mm:ss with + optional time zone part. The date and time zone parts + follow the rules of the date command; see + there. The time part (including the signaling 'T' + character) is mandatory and follow the rules of the + time command, see there. This is available as + common Tcl command tdom::type::dateTime. + + + duration + This text constraint match if the text value is + a xsd:duration. This is basically like an ISO 8601 + duration of the form PnYnMnDTnHnMnS. All parts other + then the starting P and - if one of H, M or S is given + - T are optional. In case the following sign letter is + S n may be a decimal (with at least one digit before + and after the dot), otherwise it must be a (positive) + integer. This is available as common Tcl command + tdom::type::duration. + + + base64 + This text constraint match if text is valid according to + RFC 4648. + + + hexBinary + This text constraint match if text is a sequence of + binary octets in hexadecimal encoding, where each binary octet + is a two-character hexadecimal number. Lowercase and uppercase + letters A through F are permitted. + + + unsignedByte + This text constraint match if the text value is a + xsd:unsignedByte. This is an integer between 0 and 255, both + included, optionally preceded by a + sign and leading + zeros. + + + unsignedShort + This text constraint match if the text value is a + xsd:unsignedShort. This is an integer between 0 and 65535, + both included, optionally preceded by a + sign and leading + zeros. + + + unsignedInt + This text constraint match if the text value is a + xsd:unsignedInt. This is an integer between 0 and 4294967295, + both included, optionally preceded by a + sign and leading + zeros. + + + unsignedLong + This text constraint match if the text value is a + xsd:unsignedLong. This is an integer between 0 and + 18446744073709551615, both included, optionally preceded by a + + sign and leading zeros. + + +
+ + + Logical constructs + + + oneOf <constraint script> + This text constraint match if one of the text + constraints defined in the argument constraint script + match the text. It stops after the first match and probes the + text constraints in the order of definition. + + + allOf <constraint script> + This text constraint match if all of the text + constraints defined in the argument constraint script + match the text. It stops after the first match failure and + probes the text constraints in the order of definition. Since + the schema definition command text also expects all + text constraints to match the text constraint allOf is + useful mostly together with the oneOf text constraint + command. + + + not <constraint script> + This text constraint match if none of the text + constraints defined in the argument constraint + script match the text. It stops after the first + matching constraint in the constraint script and + reports validation error. The text constraints in the + constraint script are probed in the order of + definition. + + + + + + Constraints on processed text value + + + whitespace (preserve|replace|collapse) <constraint script> + This text constraint command does white-space (#x20 + (space, ' '), #x9 (tab, \t), #xA (linefeed, \n), and #xD + (carriage return, \r) normalization to the text value and + checks the resulting text with the text constraints of the + constraint script argument. The normalization method + preserve keeps everything as it is; this is another way + to say allOf. The replace normalization method + replaces any single white-space character (as above) to a + space. The collapse normalization method removes all + leading and trailing white-space and all the other sequences of + contiguous white-space are replaced by a single space. + + + split ?type ?args??<constraint script> +

This text constraint command splits the text to test + into a list of values and tests all elements of that list for + the text constraints in the evaluated constraint + script>.

+

The available types are:

+
+
whitespace
The text to split is striped of all + white space at start and end splited into a list at any + successive white space.
+
tcl tclcmd ?arg ...?
The text to split is + handed to the tclcmd, which is evaluated on global + level, appended with every given arg and the text to split + as last argument. This call must return a valid Tcl list, + which elements are tested.
+
+

The default in case no split type argument is given is + whitespace.

+
+ + strip <constraint script> + This text constraint command tests all text constraints + in the evaluated constraint script> with the text to + test striped of all white space at start and end. + +
+
+ + + Various other string properties + + + fixed value + The text constraint only match if the text value is + string equal to the given value. + + + + enumeration list + This text constraint match if the text value is equal to + one element (respecting case and any white-space) of the + argument list, which has to be a valid Tcl list. + + + + match ?-nocase? glob_style_match_pattern> + This text constraint match if the text value match the + glob style pattern given as argument. It follows the rules of + the Tcl [string match] command, see + https://www.tcl.tk/man/tcl8.6/TclCmd/string.htm#M35. + + + regexp expression + This text constraint match if the text value match the + regular expression given as argument. https://www.tcl.tk/man/tcl8.6/TclCmd/re_syntax.htm describes the regular expression syntax + + + length length + This text constraint match if the length of the text + value (in characters, not bytes) is length. The + length argument must be a positive integer or zero. + + + maxLength length + This text constraint match if the length of the text + value (in characters, not bytes) is at most length. The + length argument must be an integer greater zero. + + + minLength length + This text constraint match if the length of the text + value (in characters, not bytes) is at least length. + The length argument must be an integer greater zero. + + + id ?keySpace? + This text constraint command marks the text as a + document wide ID (to be referenced by an idref). Every ID + value within a document must be unique. It isn't an error if + the ID isn't actually referenced within the document. The + optional argument keySpace does all this for a named + key space. The key space "" (the empty sting) is another key + space as the id command without keySpace + argument. + + + idref ?keySpace? + This text constraint command expects the text to be a + reference to an ID within the document. The referenced ID may + be later in the document, that the reference. Several + references within the document to one ID are possible. + + + +
+ +
+ Local key constraints + +

Document wide uniqueness and foreign key constraints are + available with the text constraint commands id and idref. + Keyspaces allow for sub-tree local uniqueness and foreign key + constraints.

+ + + + keyspace <names list> <constraint script> + Any number of keyspaces are possible. A keyspace is + either active or not. An inside a constraint + script called keyspace with the same name does + nothing. + + + +

This text constraint commands work with keyspaces:

+ + + + key <name> + If the keyspace with the name <name> is not + active always matches. If the keyspace is active then + reports error if there is already a key with the value. + Otherwise, stores the value as key in this keyspace and + matches. + + + keyref <name> + If the keyspace with the name <name> is not + active always matches. If the keyspace is active then + reports error if there is still no key as the value at the + end of the keyspace <name>. Otherwise it + matches. + + + +
+ +
+ Recovering + +

By default the validation engine stops at the first detected + validation violation and report that finding. It does so by + return false (and set, if given, the result variable with an + error message) in case the schema command itself is used to + validate input. If the schema command is used by a SAX parser or + the DOM parser it does so by throwing error.

+ +

If a reportcmd is set this command is called on global + level appended with the schema command and an error type as + arguments if a validation violation is detected. Then the + validation recovers from the error and continues. For some + validation errors the recover strategy can be determined with + the script result of the reportcmd.

+ +

With a reportcmd (which doesen&t throw error if + called) the validation engine will never report validation + failure to its caller. The validation engine recovers, continues + and report the next error, if one happen and so until the end of + the input. The schema command will return true and the SAX + parser and DOM builder will process normally until the end of + the input, as if there would not have been validation.

+ +

Please note, that this happens only for validation errors. It + isn't possible to recover from well-formedness errors. If the + input isn't well-formed the schema command returns false and + set, if given, the result variable with an error message about + the well-formedness error.

+ +

If the reportcmd throws error while called by the + validation engine then validation stops and the schema command + throws error with the error message of the script.

+ +

While validating basically three events happen: an element + start tag has to match, a piece of text has to match or an + element end tag has to match. The method info vaction + called in the recovering script or any script code called from + there returns, which event triggered the error report + (MATCH_ELEMENT_START, MATCH_TEXT, MATCH_ELEMENT_END, + respectively). While the command walks throu the schema looking + if the event matches other, data driven events (as, for example + checking, if any keyref within a keyspace exists).

+ +

Several of the validation error codes appended as second + argument to the reportcmd calls may happen at more than + one kind of validation event. The info vaction method and + its subcommands provide information about the current validation + event and the +

+ +

If a structural validation error happens, the default + recovering strategy is to ignore any following (or missing) + content within the current subtree and to continue with the + element end event of the subtree.

+ +

Returning "ignore" from the recovering script in case of + error type MISSING_ELEMENT recovers by ignoring the failed + contraint and continues to match the event further against the + schema.

+ +

Returing "vanish" from the recover script In case of the + error types MISSING_ELEMENT and UNEXPECTED_ELEMENT recovers by + ignoring the event.

+ +
+ +
+ Examples + +

The XML Schema Part 0: Primer Second Edition + (https://www.w3.org/TR/xmlschema-0/) starts with this + example schema:

+ + +<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> + + <xsd:annotation> + <xsd:documentation xml:lang="en"> + Purchase order schema for Example.com. + Copyright 2000 Example.com. All rights reserved. + </xsd:documentation> + </xsd:annotation> + + <xsd:element name="purchaseOrder" type="PurchaseOrderType"/> + + <xsd:element name="comment" type="xsd:string"/> + + <xsd:complexType name="PurchaseOrderType"> + <xsd:sequence> + <xsd:element name="shipTo" type="USAddress"/> + <xsd:element name="billTo" type="USAddress"/> + <xsd:element ref="comment" minOccurs="0"/> + <xsd:element name="items" type="Items"/> + </xsd:sequence> + <xsd:attribute name="orderDate" type="xsd:date"/> + </xsd:complexType> + + <xsd:complexType name="USAddress"> + <xsd:sequence> + <xsd:element name="name" type="xsd:string"/> + <xsd:element name="street" type="xsd:string"/> + <xsd:element name="city" type="xsd:string"/> + <xsd:element name="state" type="xsd:string"/> + <xsd:element name="zip" type="xsd:decimal"/> + </xsd:sequence> + <xsd:attribute name="country" type="xsd:NMTOKEN" + fixed="US"/> + </xsd:complexType> + + <xsd:complexType name="Items"> + <xsd:sequence> + <xsd:element name="item" minOccurs="0" maxOccurs="unbounded"> + <xsd:complexType> + <xsd:sequence> + <xsd:element name="productName" type="xsd:string"/> + <xsd:element name="quantity"> + <xsd:simpleType> + <xsd:restriction base="xsd:positiveInteger"> + <xsd:maxExclusive value="100"/> + </xsd:restriction> + </xsd:simpleType> + </xsd:element> + <xsd:element name="USPrice" type="xsd:decimal"/> + <xsd:element ref="comment" minOccurs="0"/> + <xsd:element name="shipDate" type="xsd:date" minOccurs="0"/> + </xsd:sequence> + <xsd:attribute name="partNum" type="SKU" use="required"/> + </xsd:complexType> + </xsd:element> + </xsd:sequence> + </xsd:complexType> + + <!-- Stock Keeping Unit, a code for identifying products --> + <xsd:simpleType name="SKU"> + <xsd:restriction base="xsd:string"> + <xsd:pattern value="\d{3}-[A-Z]{2}"/> + </xsd:restriction> + </xsd:simpleType> + +</xsd:schema> + + +

A somewhat one-to-one translation of that into a tDOM schema + definition script would be:

+ + +tdom::schema schema +schema define { + + # Purchase order schema for Example.com. + # Copyright 2000 Example.com. All rights reserved. + + defelement purchaseOrder {ref PurchaseOrderType} + + foreach elm {comment name street city state product} { + defelement $elm text + } + + defpattern PurchaseOrderType { + element shipTo ! {ref USAddress} + element billTo ! {ref USAddress} + element comment ? + element items + attribute orderDate date + } + + defpattern USAddress { + element name + element street + element city + element state + element zip ! {text number} + attribute country ! {fixed "US"} + } + + defelement items { + element item * { + element product + element quantity ! {text integer} + element USPrice ! {text number} + element comment + element shipDate ? {text date} + attribute partNum ! {pattern "^\d{3}-[A-Z]{2}$"} + } + } +} + + + +

The RELAX NG Tutorial + (http://relaxng.org/tutorial-20011203.html) starts with + this example:

+ + +Consider a simple XML representation of an email address book: + +<addressBook> + <card> + <name>John Smith</name> + <email>js@example.com</email> + </card> + <card> + <name>Fred Bloggs</name> + <email>fb@example.net</email> + </card> +</addressBook> + +The DTD would be as follows: + +<!DOCTYPE addressBook [ +<!ELEMENT addressBook (card*)> +<!ELEMENT card (name, email)> +<!ELEMENT name (#PCDATA)> +<!ELEMENT email (#PCDATA)> +]> + +A RELAX NG pattern for this could be written as follows: + +<element name="addressBook" xmlns="http://relaxng.org/ns/structure/1.0"> + <zeroOrMore> + <element name="card"> + <element name="name"> + <text/> + </element> + <element name="email"> + <text/> + </element> + </element> + </zeroOrMore> +</element> + + + +

This schema definition script will do the same:

+ + +tdom::schema schema +schema define { + defelement addressBook { + element card * + } + defelement card { + element name + element email + } + foreach e {name email} { + defelement $e text + } +} + + +
+ + + Validation + Postvalidation + DOM + SAX + +
DELETED doc/structure.html Index: doc/structure.html ================================================================== --- doc/structure.html +++ /dev/null @@ -1,478 +0,0 @@ - - -tDOM manual: structure - -
-

NAME

-tdom::structure -
Create an XML structure validation command

- -

SYNOPSIS

package require tdom
-
-    tdom::structure cmdName
-    
- -

DESCRIPTION

This command creates validation commands with a simple API. The - validation commands have methods to define an XML grammer and are - able to validate XML or DOM trees against this grammer.

Additionaly, a validation command may be used as argument to - the -validateCmd option of the dom parse and the - expat commands to enable validation additional to what they - otherwise do.

The valid methods of the created commands are:

- -
-defelement name ?namespace? <definition script> -
-
This method defines the element name (optional in - the namespace namespace) in the grammar. The - definition script is evaluated and defines the content - model of the element. If the namespace argument is - given, any element or ref references in the - definition script not wrapped inside a namespace - command are resolved in that namespace. If there is already a - element definition for the name/namespace combination the - command raises error.
- - - -
-defpattern name <definition script> -
-
This method defines a (maybe complex) content particle - with the name (optional in the namespace - namespace) in the grammar, to be referenced in other - definition scripts with the definition command ref. The - definition script is evaluated and defines the content - model of the content particle. If the namespace - argument is given, any element or ref references - in the definition script not wrapped inside a namespace - command are resolved in that namespace. If there is already a - pattern definition for the name/namespace combination the - command raises error.
- - - -
-define <definition script> -
-
This method allows to define several elements or pattern - or a whole grammar with one call.
- - - -
-start documentElement ?namespace? -
-
This method defines the name and namespace of the root - element of a tree to validate. If this method is used then the - root element must match for validity. If start isn't - used, any with defelement defined element may be the - root of a valid document. The start method may be used - serveral times with varying arguments during the lifetime of a - validation command. If the command is called with just the - empty string (and no namespace argument), the validation - constrain for the root element is removed and any defined - element will be valid as root of a tree to validate.
- - - -
-event (start|end|text) ?event specific data? -
-
This method allows to validate hierarchical data against - the so far defined content constrains of the validation - command. - -
- -
-start name ?attributes? ?namespace? -
- -
Checks if the current validation state allows the - element name in the namespace is allowed to - start here. It raises error, if not.
- - - -
end
-
Checks if the current innermost open element may be - end here in the current state without violate validation - constrains. It raises error, if not.
- - - -
-text text -
- -
Checks if the current validation state allows the - given text content. It raises error, if not.
- - -
-
- - - -
-validate <XML string> ?objVar? -
-
Returns true if the <XML string> is valid or - false otherwise. If validation failed and the optional - objVar argument is given, then the variable with that - name is set to a validation error message.
- - - -
delete
-
This method deletes the validation command.
- - - -
state
-
This method returns the state of the validation command with respect to validation state. The possible return values and their meanings are: -
-
READY
The validation command is ready to start - validation
-
VALIDATING
The validation command is in the - process of validating input.
-
FINISHED
The validation has finished, no futher - events are expected.
-
-
- - - -
reset
-
This method resets the validation command into state - READY (while preserving the defined grammer).
- - -
- -

Structure definition scripts

Structure definition scripts are ordinary Tcl scripts that are - evaluatend in the namespace tdom::structure. Several structure - definition commands in this tcl namespace allow to define a wide - variety of document structures. Every structure definition command - establish a validation constrain on the content which all has to - match, leaving no unmatched content to render the content as - valid.

The structure definition commands are:

- -
-element name ?quant? ?<definition script>? -
-
This command refers to the element defined with - defelement with the name name in the current context - namespace. Forward references to a so far not defined element - or recursive references are allowed.
- - - -
-ref name ?quant? -
-
This command refers to the content particle defined with - defpattern with the name name in the current context - namespace. Forward references to a so far not defined pattern - or recursive references are allowed.
- - - -
-group ?quant? <definition script> -
-
- - - -
-choice ?quant? <definition script> -
-
- - - -
-interleave ?quant? <definition script> -
-
- - - -
-mixed ?quant? <definition script> -
-
- - - -
-text <definition script> -
-
- - - -
any
-
- - - -
-attribute <definition script> -
-
- - - -
-namespace <definition script> -
-
- - - -
empty
-
- - - -
-defelement name ?namespace? <definition script> -
-
- - - -
-defpattern name ?namespace? <definition script> -
-
- - - -
-start name ?namespace? -
-
- -
- -

Quantity specifier

Serveral structure definition commands expects a quantifier as - one of their arguments, which specifies how often the content - particle specified by the command is expected. The valid values - for a quant argument are:

- -
!
-
The content particle must occur exactly once in valid - documents.
- - - -
?
-
The content particle must occur at most once in valid - documents.
- - - -
*
-
The content particle may occur zero or more times in a - row in valid documents.
- - - -
+
-
The content particle may occur one or more times in a - row in valid documents.
- - - -
n
-
The content particle must occur n times in a row in - valid documents. The quantifier must be an integer greater - zero.
- - - -
{n m}
The content particle must occur - n to m times (both inclusive) in a row in valid documents. The - quantifier must be a tcl list with two elements. Both elements - must be integers, with n >= 0 and n < m.
- -

If an optional quantifier is missing then it defaults to ! - - the content particle must occur exactly once in valid - documents.

- -

Exampels

The XML Schema Part 0: Primer Second Edition - https://www.w3.org/TR/xmlschema-0/ starts with this example schema - or grammar or Structure definition:

-<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
-
-  <xsd:annotation>
-    <xsd:documentation xml:lang="en">
-     Purchase order schema for Example.com.
-     Copyright 2000 Example.com. All rights reserved.
-    </xsd:documentation>
-  </xsd:annotation>
-
-  <xsd:element name="purchaseOrder" type="PurchaseOrderType"/>
-
-  <xsd:element name="comment" type="xsd:string"/>
-
-  <xsd:complexType name="PurchaseOrderType">
-    <xsd:sequence>
-      <xsd:element name="shipTo" type="USAddress"/>
-      <xsd:element name="billTo" type="USAddress"/>
-      <xsd:element ref="comment" minOccurs="0"/>
-      <xsd:element name="items"  type="Items"/>
-    </xsd:sequence>
-    <xsd:attribute name="orderDate" type="xsd:date"/>
-  </xsd:complexType>
-
-  <xsd:complexType name="USAddress">
-    <xsd:sequence>
-      <xsd:element name="name"   type="xsd:string"/>
-      <xsd:element name="street" type="xsd:string"/>
-      <xsd:element name="city"   type="xsd:string"/>
-      <xsd:element name="state"  type="xsd:string"/>
-      <xsd:element name="zip"    type="xsd:decimal"/>
-    </xsd:sequence>
-    <xsd:attribute name="country" type="xsd:NMTOKEN"
-                   fixed="US"/>
-  </xsd:complexType>
-
-  <xsd:complexType name="Items">
-    <xsd:sequence>
-      <xsd:element name="item" minOccurs="0" maxOccurs="unbounded">
-        <xsd:complexType>
-          <xsd:sequence>
-            <xsd:element name="productName" type="xsd:string"/>
-            <xsd:element name="quantity">
-              <xsd:simpleType>
-                <xsd:restriction base="xsd:positiveInteger">
-                  <xsd:maxExclusive value="100"/>
-                </xsd:restriction>
-              </xsd:simpleType>
-            </xsd:element>
-            <xsd:element name="USPrice"  type="xsd:decimal"/>
-            <xsd:element ref="comment"   minOccurs="0"/>
-            <xsd:element name="shipDate" type="xsd:date" minOccurs="0"/>
-          </xsd:sequence>
-          <xsd:attribute name="partNum" type="SKU" use="required"/>
-        </xsd:complexType>
-      </xsd:element>
-    </xsd:sequence>
-  </xsd:complexType>
-
-  <!-- Stock Keeping Unit, a code for identifying products -->
-  <xsd:simpleType name="SKU">
-    <xsd:restriction base="xsd:string">
-      <xsd:pattern value="\d{3}-[A-Z]{2}"/>
-    </xsd:restriction>
-  </xsd:simpleType>
-
-</xsd:schema>
-    

A somewhat one-to-one translation of that into a tDOM structure - defintion script would be:

-tdom::structure grammar      
-grammar define {
-
-    # Purchase order schema for Example.com.
-    # Copyright 2000 Example.com. All rights reserved.
-
-    element purchaseOrder {ref PurchaseOrderType}
-
-    element comment {text}
-
-    defpattern PurchaseOrderType {
-        element shipTo {ref USAddress}
-        element billTo {ref USAddress}
-        element comment ?
-        element items
-        attribute orderDate
-    }
-
-    defpattern USAddress {
-        element name ! {text}
-        element street ! {text}
-        element city ! {text}
-        element state ! {text}
-        element zip ! {text isNumber}
-        attribute country ! {text {fixed "US"}}
-    }
-
-    defelement items {
-        element item * {
-            element product ! {text}
-            element quntity ! {text {maxExcluse 100}}
-            element USPrice ! {text isNumber}
-            element comment
-            element shipDate ? {text isDate}
-            attribute partNum ! {text {pattern "\d{3}-[A-Z]{2}"}}
-        }
-    }
-}
-      
-    

The RELAX NG Tutorial http://relaxng.org/tutorial-20011203.html - starts with this example:

-Consider a simple XML representation of an email address book:
-
-<addressBook>
-  <card>
-    <name>John Smith</name>
-    <email>js@example.com</email>
-  </card>
-  <card>
-    <name>Fred Bloggs</name>
-    <email>fb@example.net</email>
-  </card>
-</addressBook>
-
-The DTD would be as follows:
-
-<!DOCTYPE addressBook [
-<!ELEMENT addressBook (card*)>
-<!ELEMENT card (name, email)>
-<!ELEMENT name (#PCDATA)>
-<!ELEMENT email (#PCDATA)>
-]>
-
-A RELAX NG pattern for this could be written as follows:
-
-<element name="addressBook" xmlns="http://relaxng.org/ns/structure/1.0">
-  <zeroOrMore>
-    <element name="card">
-      <element name="name">
-        <text/>
-      </element>
-      <element name="email">
-        <text/>
-      </element>
-    </element>
-  </zeroOrMore>
-</element>
-      
-    

This structure definition script will do the same:

-tdom::structure grammar      
-grammar define {
-    defelement addressBook {
-        element card *
-    }
-    defelement card {
-        element name
-        element email
-    }
-    foreach e {name email} {
-        defelement $e {text}
-    }
-}
-      
-    
-
- - DELETED doc/structure.n Index: doc/structure.n ================================================================== --- doc/structure.n +++ /dev/null @@ -1,547 +0,0 @@ -'\" -'\" Generated from structure.xml -'\" -'\" BEGIN man.macros -.if t .wh -1.3i ^B -.nr ^l \n(.l -.ad b -.de AP -.ie !"\\$4"" .TP \\$4 -.el \{\ -. ie !"\\$2"" .TP \\n()Cu -. el .TP 15 -.\} -.ta \\n()Au \\n()Bu -.ie !"\\$3"" \{\ -\&\\$1 \\fI\\$2\\fP (\\$3) -.\".b -.\} -.el \{\ -.br -.ie !"\\$2"" \{\ -\&\\$1 \\fI\\$2\\fP -.\} -.el \{\ -\&\\fI\\$1\\fP -.\} -.\} -.. -.de AS -.nr )A 10n -.if !"\\$1"" .nr )A \\w'\\$1'u+3n -.nr )B \\n()Au+15n -.\" -.if !"\\$2"" .nr )B \\w'\\$2'u+\\n()Au+3n -.nr )C \\n()Bu+\\w'(in/out)'u+2n -.. -.AS Tcl_Interp Tcl_CreateInterp in/out -.de BS -.br -.mk ^y -.nr ^b 1u -.if n .nf -.if n .ti 0 -.if n \l'\\n(.lu\(ul' -.if n .fi -.. -.de BE -.nf -.ti 0 -.mk ^t -.ie n \l'\\n(^lu\(ul' -.el \{\ -.\" Draw four-sided box normally, but don't draw top of -.\" box if the box started on an earlier page. -.ie !\\n(^b-1 \{\ -\h'-1.5n'\L'|\\n(^yu-1v'\l'\\n(^lu+3n\(ul'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul' -.\} -.el \}\ -\h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul' -.\} -.\} -.fi -.br -.nr ^b 0 -.. -.de VS -.if !"\\$2"" .br -.mk ^Y -.ie n 'mc \s12\(br\s0 -.el .nr ^v 1u -.. -.de VE -.ie n 'mc -.el \{\ -.ev 2 -.nf -.ti 0 -.mk ^t -\h'|\\n(^lu+3n'\L'|\\n(^Yu-1v\(bv'\v'\\n(^tu+1v-\\n(^Yu'\h'-|\\n(^lu+3n' -.sp -1 -.fi -.ev -.\} -.nr ^v 0 -.. -.de ^B -.ev 2 -'ti 0 -'nf -.mk ^t -.if \\n(^b \{\ -.\" Draw three-sided box if this is the box's first page, -.\" draw two sides but no top otherwise. -.ie !\\n(^b-1 \h'-1.5n'\L'|\\n(^yu-1v'\l'\\n(^lu+3n\(ul'\L'\\n(^tu+1v-\\n(^yu'\h'|0u'\c -.el \h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\h'|0u'\c -.\} -.if \\n(^v \{\ -.nr ^x \\n(^tu+1v-\\n(^Yu -\kx\h'-\\nxu'\h'|\\n(^lu+3n'\ky\L'-\\n(^xu'\v'\\n(^xu'\h'|0u'\c -.\} -.bp -'fi -.ev -.if \\n(^b \{\ -.mk ^y -.nr ^b 2 -.\} -.if \\n(^v \{\ -.mk ^Y -.\} -.. -.de DS -.RS -.nf -.sp -.. -.de DE -.fi -.RE -.sp -.. -.de SO -.SH "STANDARD OPTIONS" -.LP -.nf -.ta 5.5c 11c -.ft B -.. -.de SE -.fi -.ft R -.LP -See the \\fBoptions\\fR manual entry for details on the standard options. -.. -.de OP -.LP -.nf -.ta 4c -Command-Line Name: \\fB\\$1\\fR -Database Name: \\fB\\$2\\fR -Database Class: \\fB\\$3\\fR -.fi -.IP -.. -.de CS -.RS -.nf -.ta .25i .5i .75i 1i -.if t .ft C -.. -.de CE -.fi -.if t .ft R -.RE -.. -.de UL -\\$1\l'|0\(ul'\\$2 -.. -'\" END man.macros -.TH structure n "" Tcl "" -.BS -.SH NAME -tdom::structure \- Create an XML structure validation command -.SH SYNOPSIS -.nf -package require tdom - - \fBtdom::structure\fP \fIcmdName\fR - -.fi -.BE -.SH "DESCRIPTION " -.PP -This command creates validation commands with a simple API. The -validation commands have methods to define an XML grammer and are -able to validate XML or DOM trees against this grammer. -.PP -Additionaly, a validation command may be used as argument to -the \fI-validateCmd\fR option of the \fIdom parse\fR and the -\&\fIexpat\fR commands to enable validation additional to what they -otherwise do. -.PP -The valid methods of the created commands are: -.TP -\&\fB\fBdefelement\fP \fIname\fB \fI?namespace?\fB \fI\fB -\&\fRThis method defines the element \fIname\fR (optional in -the namespace \fInamespace\fR) in the grammar. The -\&\fIdefinition script\fR is evaluated and defines the content -model of the element. If the \fInamespace\fR argument is -given, any \fIelement\fR or \fIref\fR references in the -definition script not wrapped inside a \fInamespace\fR -command are resolved in that namespace. If there is already a -element definition for the name/namespace combination the -command raises error. -.TP -\&\fB\fBdefpattern\fP \fIname\fB \fI\fB -\&\fRThis method defines a (maybe complex) content particle -with the \fIname\fR (optional in the namespace -\&\fInamespace\fR) in the grammar, to be referenced in other -definition scripts with the definition command \fIref\fR. The -\&\fIdefinition script\fR is evaluated and defines the content -model of the content particle. If the \fInamespace\fR -argument is given, any \fIelement\fR or \fIref\fR references -in the definition script not wrapped inside a \fInamespace\fR -command are resolved in that namespace. If there is already a -pattern definition for the name/namespace combination the -command raises error. -.TP -\&\fB\fBdefine\fP \fI\fB -\&\fRThis method allows to define several elements or pattern -or a whole grammar with one call. -.TP -\&\fB\fBstart\fP \fIdocumentElement\fB \fI?namespace?\fB -\&\fRThis method defines the name and namespace of the root -element of a tree to validate. If this method is used then the -root element must match for validity. If \fIstart\fR isn't -used, any with \fIdefelement\fR defined element may be the -root of a valid document. The \fIstart\fR method may be used -serveral times with varying arguments during the lifetime of a -validation command. If the command is called with just the -empty string (and no namespace argument), the validation -constrain for the root element is removed and any defined -element will be valid as root of a tree to validate. -.TP -\&\fB\fBevent\fP \fI(start|end|text)\fB \fI?event specific data?\fB -\&\fRThis method allows to validate hierarchical data against -the so far defined content constrains of the validation -command. -.RS -.IP "\fBstart \fIname ?attributes? ?namespace? \fP\fR" -Checks if the current validation state allows the -element \fIname\fR in the \fInamespace\fR is allowed to -start here. It raises error, if not. -.IP "\fBend\fR" -Checks if the current innermost open element may be -end here in the current state without violate validation -constrains. It raises error, if not. -.IP "\fBtext \fItext\fP\fR" -Checks if the current validation state allows the -given text content. It raises error, if not. -.RE -.TP -\&\fB\fBvalidate\fP \fI\fB \fI?objVar?\fB -\&\fRReturns true if the \fI\fR is valid or -false otherwise. If validation failed and the optional -\&\fIobjVar\fR argument is given, then the variable with that -name is set to a validation error message. -.TP -\&\fB\fBdelete\fP -\&\fRThis method deletes the validation command. -.TP -\&\fB\fBstate\fP -\&\fRThis method returns the state of the validation command with respect to validation state. The possible return values and their meanings are: -.RS -.TP -READY -The validation command is ready to start -validation -.TP -VALIDATING -The validation command is in the -process of validating input. -.TP -FINISHED -The validation has finished, no futher -events are expected. -.RE -.TP -\&\fB\fBreset\fP -\&\fRThis method resets the validation command into state -READY (while preserving the defined grammer). -.SH "Structure definition scripts" -.PP -Structure definition scripts are ordinary Tcl scripts that are -evaluatend in the namespace tdom::structure. Several structure -definition commands in this tcl namespace allow to define a wide -variety of document structures. Every structure definition command -establish a validation constrain on the content which all has to -match, leaving no unmatched content to render the content as -valid. -.PP -The structure definition commands are: -.TP -\&\fB\fBelement\fP \fIname\fB \fI?quant?\fB \fI??\fB -\&\fRThis command refers to the element defined with -\&\fIdefelement\fR with the name \fIname\fR in the current context -namespace. Forward references to a so far not defined element -or recursive references are allowed. -.TP -\&\fB\fBref\fP \fIname\fB \fI?quant?\fB -\&\fRThis command refers to the content particle defined with -\&\fIdefpattern\fR with the name \fIname\fR in the current context -namespace. Forward references to a so far not defined pattern -or recursive references are allowed. -.TP -\&\fB\fBgroup\fP \fI?quant?\fB \fI\fB -\&\fR -.TP -\&\fB\fBchoice\fP \fI?quant?\fB \fI\fB -\&\fR -.TP -\&\fB\fBinterleave\fP \fI?quant?\fB \fI\fB -\&\fR -.TP -\&\fB\fBmixed\fP \fI?quant?\fB \fI\fB -\&\fR -.TP -\&\fB\fBtext\fP \fI\fB -\&\fR -.TP -\&\fB\fBany\fP -\&\fR -.TP -\&\fB\fBattribute\fP \fI\fB -\&\fR -.TP -\&\fB\fBnamespace\fP \fI\fB -\&\fR -.TP -\&\fB\fBempty\fP -\&\fR -.TP -\&\fB\fBdefelement\fP \fIname\fB \fI?namespace?\fB \fI\fB -\&\fR -.TP -\&\fB\fBdefpattern\fP \fIname\fB \fI?namespace?\fB \fI\fB -\&\fR -.TP -\&\fB\fBstart\fP \fIname\fB \fI?namespace?\fB -\&\fR -.SH "Quantity specifier" -.PP -Serveral structure definition commands expects a quantifier as -one of their arguments, which specifies how often the content -particle specified by the command is expected. The valid values -for a \fIquant\fR argument are: -.IP "\fB!\fR" -The content particle must occur exactly once in valid -documents. -.IP "\fB?\fR" -The content particle must occur at most once in valid -documents. -.IP "\fB*\fR" -The content particle may occur zero or more times in a -row in valid documents. -.IP "\fB+\fR" -The content particle may occur one or more times in a -row in valid documents. -.IP "\fBn\fR" -The content particle must occur n times in a row in -valid documents. The quantifier must be an integer greater -zero. -.IP "\fB{n m}\fR" -The content particle must occur -n to m times (both inclusive) in a row in valid documents. The -quantifier must be a tcl list with two elements. Both elements -must be integers, with n >= 0 and n < m. -.PP -If an optional quantifier is missing then it defaults to ! - -the content particle must occur exactly once in valid -documents. -.SH Exampels -.PP -The XML Schema Part 0: Primer Second Edition -https://www.w3.org/TR/xmlschema-0/ starts with this example schema -or grammar or Structure definition: -.CS - - - - - - Purchase order schema for Example.com. - Copyright 2000 Example.com. All rights reserved. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -.CE -.PP -A somewhat one-to-one translation of that into a tDOM structure -defintion script would be: -.CS - -tdom::structure grammar -grammar define { - - # Purchase order schema for Example.com. - # Copyright 2000 Example.com. All rights reserved. - - element purchaseOrder {ref PurchaseOrderType} - - element comment {text} - - defpattern PurchaseOrderType { - element shipTo {ref USAddress} - element billTo {ref USAddress} - element comment ? - element items - attribute orderDate - } - - defpattern USAddress { - element name ! {text} - element street ! {text} - element city ! {text} - element state ! {text} - element zip ! {text isNumber} - attribute country ! {text {fixed "US"}} - } - - defelement items { - element item * { - element product ! {text} - element quntity ! {text {maxExcluse 100}} - element USPrice ! {text isNumber} - element comment - element shipDate ? {text isDate} - attribute partNum ! {text {pattern "\ed{3}-[A-Z]{2}"}} - } - } -} - - -.CE -.PP -The RELAX NG Tutorial http://relaxng.org/tutorial-20011203.html -starts with this example: -.CS - -Consider a simple XML representation of an email address book: - - - - John Smith - js@example.com - - - Fred Bloggs - fb@example.net - - - -The DTD would be as follows: - - - - - -]> - -A RELAX NG pattern for this could be written as follows: - - - - - - - - - - - - - - - -.CE -.PP -This structure definition script will do the same: -.CS - -tdom::structure grammar -grammar define { - defelement addressBook { - element card * - } - defelement card { - element name - element email - } - foreach e {name email} { - defelement $e {text} - } -} - - -.CE - DELETED doc/structure.xml Index: doc/structure.xml ================================================================== --- doc/structure.xml +++ /dev/null @@ -1,478 +0,0 @@ - - - tdom::structure - Create a structure validation command - - - - package require tdom - - tdom::structure cmdName - - - -
- DESCRIPTION - -

This command creates validation commands with a simple API. The - validation commands have methods to define a grammer and are able - to validate XML or DOM trees (and to some degree other kind of - hierarchical data) against this grammer.

- -

Additionally, a validation command may be used as argument to - the -validateCmd option of the dom parse and the - expat commands to enable validation additional to what they - otherwise do.

- -

The valid methods of the created commands are:

- - - - defelement name ?namespace? <definition script> - This method defines the element name (optional in - the namespace namespace) in the grammar. The - definition script is evaluated and defines the content - model of the element. If the namespace argument is - given, any element or ref references in the - definition script not wrapped inside a namespace - command are resolved in that namespace. If there is already a - element definition for the name/namespace combination the - command raises error. - - - - defpattern name <definition script> - This method defines a (maybe complex) content particle - with the name (optional in the namespace - namespace) in the grammar, to be referenced in other - definition scripts with the definition command ref. The - definition script is evaluated and defines the content - model of the content particle. If the namespace - argument is given, any element or ref references - in the definition script not wrapped inside a namespace - command are resolved in that namespace. If there is already a - pattern definition for the name/namespace combination the - command raises error. - - - - define <definition script> - This method allows to define several elements or pattern - or a whole grammar with one call. - - - - start documentElement ?namespace? - This method defines the name and namespace of the root - element of a tree to validate. If this method is used then the - root element must match for validity. If start isn't - used, any with defelement defined element may be the - root of a valid document. The start method may be used - serveral times with varying arguments during the lifetime of a - validation command. If the command is called with just the - empty string (and no namespace argument), the validation - constrain for the root element is removed and any defined - element will be valid as root of a tree to validate. - - - - event (start|end|text) ?event specific data? - This method allows to validate hierarchical data against - the so far defined content constrains of the validation - command. - - - - start - name ?attributes? ?namespace? - Checks if the current validation state allows the - element name in the namespace is allowed to - start here. It raises error, if not. - - - - end - Checks if the current innermost open element may end - here in the current state without violate validation - constrains. It raises error, if not. - - - - text - text - Checks if the current validation state allows the - given text content. It raises error, if not. - - - - - - - - validate <XML string> ?objVar? - Returns true if the <XML string> is valid or - false otherwise. If validation failed and the optional - objVar argument is given, then the variable with that - name is set to a validation error message. - - - - delete - This method deletes the validation command. - - - - state - This method returns the state of the validation command with respect to validation state. The possible return values and their meanings are: -
-
READY
The validation command is ready to start - validation
-
VALIDATING
The validation command is in the - process of validating input.
-
FINISHED
The validation has finished, no futher - events are expected.
-
-
-
- - - reset - This method resets the validation command into state - READY (while preserving the defined grammer). - - -
-
- -
- Structure definition scripts - -

Structure definition scripts are ordinary Tcl scripts that are - evaluatend in the namespace tdom::structure. Several structure - definition commands in this tcl namespace allow to define a wide - variety of document structures. Every structure definition command - establish a validation constrain on the content which all has to - match, leaving no unmatched content to render the content as - valid.

- -

The structure definition commands are:

- - - - element name ?quant? ?<definition script>? - This command refers to the element defined with - defelement with the name name in the current context - namespace. Forward references to a so far not defined element - or recursive references are allowed. - - - - ref name ?quant? - This command refers to the content particle defined with - defpattern with the name name in the current context - namespace. Forward references to a so far not defined pattern - or recursive references are allowed. - - - - group ?quant? <definition script> - - - - - choice ?quant? <definition script> - - - - - interleave ?quant? <definition script> - - - - - mixed ?quant? <definition script> - - - - - text <definition script> - - - - - any - - - - - attribute <definition script> - - - - - namespace <definition script> - - - - - empty - - - - - defelement name ?namespace? <definition script> - - - - - defpattern name ?namespace? <definition script> - - - - - start name ?namespace? - - - - -
- -
- Quantity specifier - -

Serveral structure definition commands expects a quantifier as - one of their arguments, which specifies how often the content - particle specified by the command is expected. The valid values - for a quant argument are:

- - - - ! - The content particle must occur exactly once in valid - documents. - - - - ? - The content particle must occur at most once in valid - documents. - - - - * - The content particle may occur zero or more times in a - row in valid documents. - - - - + - The content particle may occur one or more times in a - row in valid documents. - - - - n - The content particle must occur n times in a row in - valid documents. The quantifier must be an integer greater - zero. - - - - {n m} The content particle must occur - n to m times (both inclusive) in a row in valid documents. The - quantifier must be a tcl list with two elements. Both elements - must be integers, with n >= 0 and n < m. - - - -

If an optional quantifier is missing then it defaults to ! - - the content particle must occur exactly once in valid - documents.

- -
- -
- Exampels - -

The XML Schema Part 0: Primer Second Edition - (https://www.w3.org/TR/xmlschema-0/) starts with this - example schema:

- - -<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> - - <xsd:annotation> - <xsd:documentation xml:lang="en"> - Purchase order schema for Example.com. - Copyright 2000 Example.com. All rights reserved. - </xsd:documentation> - </xsd:annotation> - - <xsd:element name="purchaseOrder" type="PurchaseOrderType"/> - - <xsd:element name="comment" type="xsd:string"/> - - <xsd:complexType name="PurchaseOrderType"> - <xsd:sequence> - <xsd:element name="shipTo" type="USAddress"/> - <xsd:element name="billTo" type="USAddress"/> - <xsd:element ref="comment" minOccurs="0"/> - <xsd:element name="items" type="Items"/> - </xsd:sequence> - <xsd:attribute name="orderDate" type="xsd:date"/> - </xsd:complexType> - - <xsd:complexType name="USAddress"> - <xsd:sequence> - <xsd:element name="name" type="xsd:string"/> - <xsd:element name="street" type="xsd:string"/> - <xsd:element name="city" type="xsd:string"/> - <xsd:element name="state" type="xsd:string"/> - <xsd:element name="zip" type="xsd:decimal"/> - </xsd:sequence> - <xsd:attribute name="country" type="xsd:NMTOKEN" - fixed="US"/> - </xsd:complexType> - - <xsd:complexType name="Items"> - <xsd:sequence> - <xsd:element name="item" minOccurs="0" maxOccurs="unbounded"> - <xsd:complexType> - <xsd:sequence> - <xsd:element name="productName" type="xsd:string"/> - <xsd:element name="quantity"> - <xsd:simpleType> - <xsd:restriction base="xsd:positiveInteger"> - <xsd:maxExclusive value="100"/> - </xsd:restriction> - </xsd:simpleType> - </xsd:element> - <xsd:element name="USPrice" type="xsd:decimal"/> - <xsd:element ref="comment" minOccurs="0"/> - <xsd:element name="shipDate" type="xsd:date" minOccurs="0"/> - </xsd:sequence> - <xsd:attribute name="partNum" type="SKU" use="required"/> - </xsd:complexType> - </xsd:element> - </xsd:sequence> - </xsd:complexType> - - <!-- Stock Keeping Unit, a code for identifying products --> - <xsd:simpleType name="SKU"> - <xsd:restriction base="xsd:string"> - <xsd:pattern value="\d{3}-[A-Z]{2}"/> - </xsd:restriction> - </xsd:simpleType> - -</xsd:schema> - - -

A somewhat one-to-one translation of that into a tDOM structure - defintion script would be:

- - -tdom::structure grammar -grammar define { - - # Purchase order schema for Example.com. - # Copyright 2000 Example.com. All rights reserved. - - element purchaseOrder {ref PurchaseOrderType} - - element comment {text} - - defpattern PurchaseOrderType { - element shipTo {ref USAddress} - element billTo {ref USAddress} - element comment ? - element items - attribute orderDate - } - - defpattern USAddress { - element name ! {text} - element street ! {text} - element city ! {text} - element state ! {text} - element zip ! {text isNumber} - attribute country ! {text {fixed "US"}} - } - - defelement items { - element item * { - element product ! {text} - element quntity ! {text {maxExcluse 100}} - element USPrice ! {text isNumber} - element comment - element shipDate ? {text isDate} - attribute partNum ! {text {pattern "\d{3}-[A-Z]{2}"}} - } - } -} - - - -

The RELAX NG Tutorial - (http://relaxng.org/tutorial-20011203.html) starts with - this example:

- - -Consider a simple XML representation of an email address book: - -<addressBook> - <card> - <name>John Smith</name> - <email>js@example.com</email> - </card> - <card> - <name>Fred Bloggs</name> - <email>fb@example.net</email> - </card> -</addressBook> - -The DTD would be as follows: - -<!DOCTYPE addressBook [ -<!ELEMENT addressBook (card*)> -<!ELEMENT card (name, email)> -<!ELEMENT name (#PCDATA)> -<!ELEMENT email (#PCDATA)> -]> - -A RELAX NG pattern for this could be written as follows: - -<element name="addressBook" xmlns="http://relaxng.org/ns/structure/1.0"> - <zeroOrMore> - <element name="card"> - <element name="name"> - <text/> - </element> - <element name="email"> - <text/> - </element> - </element> - </zeroOrMore> -</element> - - - -

This structure definition script will do the same:

- - -tdom::structure grammar -grammar define { - defelement addressBook { - element card * - } - defelement card { - element name - element email - } - foreach e {name email} { - defelement $e {text} - } -} - - -
-
Index: doc/tDOM.xml ================================================================== --- doc/tDOM.xml +++ doc/tDOM.xml @@ -3,11 +3,11 @@ - + ]> tDOM manual @@ -22,13 +22,13 @@ &expatapi; &pullparser; -&structure; +&schema; &tdomcmd; &tnc; Index: doc/tdomcmd.html ================================================================== --- doc/tdomcmd.html +++ doc/tdomcmd.html @@ -2,25 +2,25 @@ tDOM manual: tdom
-

NAME

+

NAME

tdom -
tdom is an expat parser object extension to create an in-memory DOM tree from the input while parsing.

-

SYNOPSIS

package require tdom
+  

SYNOPSIS

package require tdom
 
 set parser [expat]
 
 tdom $parser enable
-

DESCRIPTION

+

DESCRIPTION

tdom adds the C handler set "tdom" to an tcl expat parser obj. This handler set builds an in-memory DOM tree out of the input, parsed by the parser. A DOM tree created this way behave exactly like a DOM tree created by the "dom" command (see there). In fact, tdom is only another interface to the same functionality; it uses the code behind the @@ -75,16 +75,16 @@

-

SEE ALSO

dom, expat

+

SEE ALSO

dom, expat

-

KEYWORDS

+

KEYWORDS

DOM, SAX, C handler set

ADDED doc/tmml.schema Index: doc/tmml.schema ================================================================== --- /dev/null +++ doc/tmml.schema @@ -0,0 +1,816 @@ +start manpage +defelement manpage { + attribute version ? + attribute title + attribute id + attribute cat + attribute package ? + element head ? + element namesection + element synopsis ? + element section * + element seealso ? + element keywords ? +} +defelement DEF { + attribute cat ? + attribute name + attribute package ? + attribute subpart ? + attribute manpage ? +} +defelement INDEX { + attribute package ? + attribute standalone ? + attribute title + element head ? + choice * { + element MAN + element DEF + element KWD + } +} +defelement KWD { + attribute manpage ? + attribute name +} +defelement MAN { + attribute id + attribute title +} +defelement argdef { + attribute version ? + element argtype + element name + element argmode ? + element desc +} +defelement arglist { + element argdef + +} +defelement argmode { + text +} +defelement argtype { + text +} +defelement b { + attribute cat ? + mixed { + element emph + element ref + element url + element samp + element command + element new + element m + element l + element o + element i + element b + element br + element term + element cmd + element variable + element method + element option + element file + element syscmd + element fun + element widget + element package + element type + element class + } +} +defelement br { +} +defelement categories { + element category + +} +defelement category { + attribute title ? + attribute id +} +defelement class { + text +} +defelement cmd { + text +} +defelement command { + mixed { + element new + element m + element l + element o + element i + element b + element br + element term + element cmd + element variable + element method + element option + element file + element syscmd + element fun + element widget + element package + element type + element class + } +} +defelement commanddef { + attribute version ? + element command + element desc +} +defelement commandlist { + element commanddef + +} +defelement dbclass { + text +} +defelement dbname { + text +} +defelement dd { + mixed { + element emph + element ref + element url + element samp + element command + element new + element m + element l + element o + element i + element b + element br + element term + element cmd + element variable + element method + element option + element file + element syscmd + element fun + element widget + element package + element type + element class + element p + element ul + element ol + element dl + element sl + element xl + element example + element syntax + element commandlist + element optlist + } +} +defelement desc { + mixed { + element emph + element ref + element url + element samp + element command + element new + element m + element l + element o + element i + element b + element br + element term + element cmd + element variable + element method + element option + element file + element syscmd + element fun + element widget + element package + element type + element class + element p + element ul + element ol + element dl + element sl + element xl + element example + element syntax + element commandlist + element optlist + } +} +defelement division { + element title + choice { + element division * + choice * { + element manpage + element subdoc + element extref + } + } +} +defelement dl { + attribute cat ? + attribute scope ? {enumeration {local global}} + choice + { + element dle + group { + element dt + element dd + } + } +} +defelement dle { + attribute version ? + element dt + + element dd +} +defelement dt { + mixed { + element emph + element ref + element url + element samp + element command + element new + element m + element l + element o + element i + element b + element br + element term + element cmd + element variable + element method + element option + element file + element syscmd + element fun + element widget + element package + element type + element class + } +} +defelement emph { + mixed { + element emph + element ref + element url + element samp + element command + element new + element m + element l + element o + element i + element b + element br + element term + element cmd + element variable + element method + element option + element file + element syscmd + element fun + element widget + element package + element type + element class + } +} +defelement example { + mixed { + element new + element m + element l + element o + element i + element b + element br + element term + element cmd + element variable + element method + element option + element file + element syscmd + element fun + element widget + element package + element type + element class + } +} +defelement extension { + attribute gi + attribute tmml +} +defelement extensions { + choice * { + element extension + element xlh + } +} +defelement extref { + attribute title + attribute href + attribute type +} +defelement file { + text +} +defelement fun { + text +} +defelement head { + choice * { + element extensions + element info + element link + element category + } +} +defelement i { + attribute cat ? + mixed { + element emph + element ref + element url + element samp + element command + element new + element m + element l + element o + element i + element b + element br + element term + element cmd + element variable + element method + element option + element file + element syscmd + element fun + element widget + element package + element type + element class + } +} +defelement info { + attribute key + attribute value +} +defelement keyword { + text +} +defelement keywords { + element keyword + +} +defelement l { + text +} +defelement li { + attribute version ? + mixed { + element emph + element ref + element url + element samp + element command + element new + element m + element l + element o + element i + element b + element br + element term + element cmd + element variable + element method + element option + element file + element syscmd + element fun + element widget + element package + element type + element class + element p + element ul + element ol + element dl + element sl + element xl + element example + element syntax + element commandlist + element optlist + } +} +defelement link { + attribute href + attribute rel +} +defelement m { + text +} +defelement manual { + attribute version ? + attribute package + element title + element head ? + choice { + element division * + choice * { + element manpage + element subdoc + element extref + } + } +} +defelement method { + text +} +defelement name { + attribute cat ? + attribute name ? + text +} +defelement namesection { + choice { + element name + + group { + element title + element name * + } + } + element desc +} +defelement new { + attribute version + mixed { + element emph + element ref + element url + element samp + element command + element new + element m + element l + element o + element i + element b + element br + element term + element cmd + element variable + element method + element option + element file + element syscmd + element fun + element widget + element package + element type + element class + } +} +defelement o { + mixed { + element new + element m + element l + element o + element i + element b + element br + element term + element cmd + element variable + element method + element option + element file + element syscmd + element fun + element widget + element package + element type + element class + } +} +defelement ol { + element li + +} +defelement optarg { + text +} +defelement optdef { + element optname + element optarg ? + element desc +} +defelement option { + text +} +defelement optiondef { + attribute version ? + element name + element dbname + element dbclass + element desc +} +defelement optionlist { + attribute cat ? + attribute scope ? {enumeration {local global}} + element optiondef + +} +defelement optlist { + element optdef + +} +defelement optname { + text +} +defelement p { + attribute version ? + mixed { + element emph + element ref + element url + element samp + element command + element new + element m + element l + element o + element i + element b + element br + element term + element cmd + element variable + element method + element option + element file + element syscmd + element fun + element widget + element package + element type + element class + } +} +defelement package { + text +} +defelement ref { + attribute cat ? + attribute href ? + attribute refid ? + mixed { + element emph + element ref + element url + element samp + element command + element new + element m + element l + element o + element i + element b + element br + element term + element cmd + element variable + element method + element option + element file + element syscmd + element fun + element widget + element package + element type + element class + } +} +defelement samp { + mixed { + element new + element m + element l + element o + element i + element b + element br + element term + element cmd + element variable + element method + element option + element file + element syscmd + element fun + element widget + element package + element type + element class + } +} +defelement section { + attribute id ? + attribute version ? + element title + choice * { + element p + element ul + element ol + element dl + element sl + element xl + element example + element syntax + element commandlist + element optlist + element arglist + element optionlist + } + element subsection * +} +defelement seealso { + choice + { + element ref + element url + } +} +defelement sl { + attribute cols ? + attribute cat ? + element li + +} +defelement subdoc { + attribute href +} +defelement subsection { + attribute id ? + attribute version ? + element title + choice * { + element p + element ul + element ol + element dl + element sl + element xl + element example + element syntax + element commandlist + element optlist + element arglist + element optionlist + } +} +defelement synopsis { + choice + { + element syntax + element example + } +} +defelement syntax { + attribute name ? + attribute scope ? {enumeration {local global}} + attribute cat ? + mixed { + element new + element m + element l + element o + element i + element b + element br + element term + element cmd + element variable + element method + element option + element file + element syscmd + element fun + element widget + element package + element type + element class + } +} +defelement syscmd { + text +} +defelement term { + attribute cat ? + text +} +defelement title { + text +} +defelement type { + text +} +defelement ul { + element li + +} +defelement url { + text +} +defelement variable { + text +} +defelement widget { + text +} +defelement xh { + mixed { + element emph + element ref + element url + element samp + element command + element new + element m + element l + element o + element i + element b + element br + element term + element cmd + element variable + element method + element option + element file + element syscmd + element fun + element widget + element package + element type + element class + } +} +defelement xl { + element xlh ? + element xle + +} +defelement xle { + element xt + + element desc ? +} +defelement xlh { + attribute gi ? + element xh + +} +defelement xt { + mixed { + element emph + element ref + element url + element samp + element command + element new + element m + element l + element o + element i + element b + element br + element term + element cmd + element variable + element method + element option + element file + element syscmd + element fun + element widget + element package + element type + element class + } +} Index: doc/tnc.html ================================================================== --- doc/tnc.html +++ doc/tnc.html @@ -2,25 +2,25 @@ tDOM manual: tnc
-

NAME

+

NAME

tnc -
tnc is an expat parser object extension, that validates the XML stream against the document DTD while parsing.

-

SYNOPSIS

package require tdom
+  

SYNOPSIS

package require tdom
 package require tnc
 
 set parser [expat]
 
 tnc $parser enable
-

DESCRIPTION

+

DESCRIPTION

tnc adds the C handler set "tnc" to a tcl expat parser obj. This handler set is a simple DTD validator. If the validator detects a validation error, it sets the interp result, signals error and stops parsing. There isn't any validation error recovering. As a consequence, only valid documents are completely parsed.

This handler set has only three methods:

@@ -118,23 +118,23 @@
-

BUGS

The validation error reports could be much more informative and +

BUGS

The validation error reports could be much more informative and user-friendly.

The validator doesn't detect ambiguous content models (see XML recomendation Section 3.2.1 and Appendix E). Most Java validators also doesn't, but handle such content models right anyhow. Tnc does not; if your DTD has such ambiguous content models, tnc can not used to validate documents against such (not completely XML spec compliant) DTDs.

It isn't possible to validate XML documents with standalone="yes" in the XML Declaration

Violations of the validity constraints Proper Group/PE Nesting and Proper Conditional Section/PE Nesting are not detected. They could only happen inside a invalid DTD, not in the content of a document.

-

KEYWORDS

+

KEYWORDS

Validation, DTD

Index: expat/Changes ================================================================== --- expat/Changes +++ expat/Changes @@ -1,8 +1,211 @@ NOTE: We are looking for help with a few things: https://github.com/libexpat/libexpat/labels/help%20wanted If you can help, please get in touch. Thanks! + +Release 2.2.9 Wed Septemper 25 2019 + Other changes: + examples: Drop executable bits from elements.c + #349 Windows: Change the name of the Windows DLLs from expat*.dll + to libexpat*.dll once more (regression from 2.2.8, first + fixed in 1.95.3, issue #61 on SourceForge today, + was issue #432456 back then); needs a fix due + case-insensitive file systems on Windows and the fact that + Perl's XML::Parser::Expat compiles into Expat.dll. + #347 Windows: Only define _CRT_RAND_S if not defined + Version info bumped from 7:10:6 to 7:11:6 + + Special thanks to: + Ben Wagner + +Release 2.2.8 Fri Septemper 13 2019 + Security fixes: + #317 #318 CVE-2019-15903 -- Fix heap overflow triggered by + XML_GetCurrentLineNumber (or XML_GetCurrentColumnNumber), + and deny internal entities closing the doctype; + fixed in commit c20b758c332d9a13afbbb276d30db1d183a85d43 + + Bug fixes: + #240 Fix cases where XML_StopParser did not have any effect + when called from inside of an end element handler + #341 xmlwf: Fix exit code for operation without "-d DIRECTORY"; + previously, only "-d DIRECTORY" would give you a proper + exit code: + # xmlwf -d . <<<'' 2>/dev/null ; echo $? + 2 + # xmlwf <<<'' 2>/dev/null ; echo $? + 0 + Now both cases return exit code 2. + + Other changes: + #299 #302 Windows: Replace LoadLibrary hack to access + unofficial API function SystemFunction036 (RtlGenRandom) + by using official API function rand_s (needs WinXP+) + #325 Windows: Drop support for Visual Studio <=7.1/2003 + and document supported compilers in README.md + #286 Windows: Remove COM code from xmlwf; in case it turns + out needed later, there will be a dedicated repository + below https://github.com/libexpat/ for that code + #322 Windows: Remove explicit MSVC solution and project files. + You can generate Visual Studio solution files through + CMake, e.g.: cmake -G"Visual Studio 15 2017" . + #338 xmlwf: Make "xmlwf -h" help output more friendly + #339 examples: Improve elements.c + #244 #264 Autotools: Add argument --enable-xml-attr-info + #239 #301 Autotools: Add arguments + --with-getrandom + --without-getrandom + --with-sys-getrandom + --without-sys-getrandom + #312 #343 Autotools: Fix linking issues with "./configure LD=clang" + Autotools: Fix "make run-xmltest" for out-of-source builds + #329 #336 CMake: Pull all options from Expat <=2.2.7 into namespace + prefix EXPAT_ with the exception of DOCBOOK_TO_MAN: + - BUILD_doc -> EXPAT_BUILD_DOCS (plural) + - BUILD_examples -> EXPAT_BUILD_EXAMPLES + - BUILD_shared -> EXPAT_SHARED_LIBS + - BUILD_tests -> EXPAT_BUILD_TESTS + - BUILD_tools -> EXPAT_BUILD_TOOLS + - DOCBOOK_TO_MAN -> DOCBOOK_TO_MAN (unchanged) + - INSTALL -> EXPAT_ENABLE_INSTALL + - MSVC_USE_STATIC_CRT -> EXPAT_MSVC_STATIC_CRT + - USE_libbsd -> EXPAT_WITH_LIBBSD + - WARNINGS_AS_ERRORS -> EXPAT_WARNINGS_AS_ERRORS + - XML_CONTEXT_BYTES -> EXPAT_CONTEXT_BYTES + - XML_DEV_URANDOM -> EXPAT_DEV_URANDOM + - XML_DTD -> EXPAT_DTD + - XML_NS -> EXPAT_NS + - XML_UNICODE -> EXPAT_CHAR_TYPE=ushort (!) + - XML_UNICODE_WCHAR_T -> EXPAT_CHAR_TYPE=wchar_t (!) + #244 #264 CMake: Add argument -DEXPAT_ATTR_INFO=(ON|OFF), + default OFF + #326 CMake: Add argument -DEXPAT_LARGE_SIZE=(ON|OFF), + default OFF + #328 CMake: Add argument -DEXPAT_MIN_SIZE=(ON|OFF), + default OFF + #239 #277 CMake: Add arguments + -DEXPAT_WITH_GETRANDOM=(ON|OFF|AUTO), default AUTO + -DEXPAT_WITH_SYS_GETRANDOM=(ON|OFF|AUTO), default AUTO + #326 CMake: Install expat_config.h to include directory + #326 CMake: Generate and install configuration files for + future find_package(expat [..] CONFIG [..]) + CMake: Now produces a summary of applied configuration + CMake: Require C++ compiler only when tests are enabled + #330 CMake: Fix compilation for 16bit character types, + i.e. ex -DXML_UNICODE=ON (and ex -DXML_UNICODE_WCHAR_T=ON) + #265 CMake: Fix linking with MinGW + #330 CMake: Add full support for MinGW; to enable, use + -DCMAKE_TOOLCHAIN_FILE=[expat]/cmake/mingw-toolchain.cmake + #330 CMake: Port "make run-xmltest" from GNU Autotools to CMake + #316 CMake: Windows: Make binary postfix match MSVC + Old: expat[d].lib + New: expat[w][d][MD|MT].lib + CMake: Migrate files from Windows to Unix line endings + #308 CMake: Integrate OSS-Fuzz fuzzers, option + -DEXPAT_BUILD_FUZZERS=(ON|OFF), default OFF + #14 Drop an OpenVMS support leftover + #235 #268 .. + #270 #310 .. + #313 #331 #333 Address compiler warnings + #282 #283 .. + #284 #285 Address cppcheck warnings + #294 #295 Address Clang Static Analyzer warnings + #24 #293 Mass-apply clang-format 9 (and ensure conformance during CI) + Version info bumped from 7:9:6 to 7:10:6 + + Special thanks to: + David Loffredo + Joonun Jang + Khajapasha Mohammed + Kishore Kunche + Marco Maggi + Mitch Phillips + Rolf Ade + xantares + Zhongyuan Zhou + +Release 2.2.7 Wed June 19 2019 + Security fixes: + #186 #262 CVE-2018-20843 -- Fix extraction of namespace prefixes from + XML names; XML names with multiple colons could end up in + the wrong namespace, and take a high amount of RAM and CPU + resources while processing, opening the door to + use for denial-of-service attacks + + Other changes: + #195 #197 Autotools/CMake: Utilize -fvisibility=hidden to stop + exporting non-API symbols + #227 Autotools: Add --without-examples and --without-tests + #228 Autotools: Modernize configure.ac + #245 #246 Autotools: Fix check for -fvisibility=hidden for Clang + #247 #248 Autotools: Fix compilation for lack of docbook2x-man + #236 #258 Autotools: Produce .tar.{gz,lz,xz} release archives + #212 CMake: Make libdir of pkgconfig expat.pc support multilib + #158 #263 CMake: Build man page in PROJECT_BINARY_DIR not _SOURCE_DIR + #219 Remove fallback to bcopy, assume that memmove(3) exists + #257 Use portable "/usr/bin/env bash" shebang (e.g. for OpenBSD) + #243 Windows: Fix syntax of .def module definition files + Version info bumped from 7:8:6 to 7:9:6 + + Special thanks to: + Benjamin Peterson + Caolán McNamara + Hanno Böck + KangLin + Kishore Kunche + Marco Maggi + Rhodri James + Sebastian Dröge + userwithuid + Yury Gribov + +Release 2.2.6 Sun August 12 2018 + Bug fixes: + #170 #206 Avoid doing arithmetic with NULL pointers in XML_GetBuffer + #204 #205 Fix 2.2.5 regression with suspend-resume while parsing + a document like '' + + Other changes: + #165 #168 Autotools: Fix docbook-related configure syntax error + #166 Autotools: Avoid grep option `-q` for Solaris + #167 Autotools: Support + ./configure DOCBOOK_TO_MAN="xmlto man --skip-validation" + #159 #167 Autotools: Support DOCBOOK_TO_MAN command which produces + xmlwf.1 rather than XMLWF.1; also covers case insensitive + file systems + #181 Autotools: Drop -rpath option passed to libtool + #188 Autotools: Detect and deny SGML docbook2man as ours is XML + #188 Autotools/CMake: Support command db2x_docbook2man as well + #174 CMake: Introduce option WARNINGS_AS_ERRORS, defaults to OFF + #184 #185 CMake: Introduce option MSVC_USE_STATIC_CRT, defaults to OFF + #207 #208 CMake: Introduce option XML_UNICODE and XML_UNICODE_WCHAR_T, + both defaulting to OFF + #175 CMake: Prefer check_symbol_exists over check_function_exists + #176 CMake: Create the same pkg-config file as with GNU Autotools + #178 #179 CMake: Use GNUInstallDirs module to set proper defaults for + install directories + #208 CMake: Utilize expat_config.h.cmake for XML_DEV_URANDOM + #180 Windows: Fix compilation of test suite for Visual Studio 2008 + #131 #173 #202 Address compiler warnings + #187 #190 #200 Fix miscellaneous typos + Version info bumped from 7:7:6 to 7:8:6 + + Special thanks to: + Anton Maklakov + Benjamin Peterson + Brad King + Franek Korta + Frank Rast + Joe Orton + luzpaz + Pedro Vicente + Rainer Jung + Rhodri James + Rolf Ade + Rolf Eike Beer + Thomas Beutlich + Tomasz Kłoczko Release 2.2.5 Tue October 31 2017 Bug fixes: #8 If the parser runs out of memory, make sure its internal state reflects the memory it actually has, not the memory @@ -20,10 +223,11 @@ #106 xmlwf: Add argument -N adding notation declarations #75 #106 Test suite: Resolve expected failure cases where xmlwf output was incomplete #127 Windows: Fix test suite compilation #126 #127 Windows: Fix compilation for Visual Studio 2012 + Windows: Upgrade shipped project files to Visual Studio 2017 #33 #132 tests: Mass-fix compilation for XML_UNICODE_WCHAR_T #129 examples: Fix compilation for XML_UNICODE_WCHAR_T #130 benchmark: Fix compilation for XML_UNICODE_WCHAR_T #144 xmlwf: Fix compilation for XML_UNICODE_WCHAR_T; still needs Windows or MinGW for 2-byte wchar_t Index: expat/README.md ================================================================== --- expat/README.md +++ expat/README.md @@ -1,18 +1,24 @@ [![Travis CI Build Status](https://travis-ci.org/libexpat/libexpat.svg?branch=master)](https://travis-ci.org/libexpat/libexpat) [![AppVeyor Build Status](https://ci.appveyor.com/api/projects/status/github/libexpat/libexpat?svg=true)](https://ci.appveyor.com/project/libexpat/libexpat) +[![Packaging status](https://repology.org/badge/tiny-repos/expat.svg)](https://repology.org/metapackage/expat/versions) -# Expat, Release 2.2.5 +# Expat, Release 2.2.9 This is Expat, a C library for parsing XML, started by [James Clark](https://en.wikipedia.org/wiki/James_Clark_(programmer)) in 1997. Expat is a stream-oriented XML parser. This means that you register handlers with the parser before starting the parse. These handlers are called when the parser discovers the associated structures in the document being parsed. A start tag is an example of the kind of structures for which you may register handlers. + +Expat supports the following compilers: +- GNU GCC >=4.5 +- LLVM Clang >=3.5 +- Microsoft Visual Studio >=8.0/2005 Windows users should use the [`expat_win32` package](https://sourceforge.net/projects/expat/files/expat_win32/), which includes both precompiled libraries and executables, and source code for developers. @@ -122,5 +128,61 @@ include Expat. See the comments at the top of that file for more information. A reference manual is available in the file `doc/reference.html` in this distribution. + + +The CMake build system is still *experimental* and will replace the primary +build system based on GNU Autotools at some point when it is ready. +For an idea of the available (non-advanced) options for building with CMake: + +```console +# rm -f CMakeCache.txt ; cmake -D_EXPAT_HELP=ON -LH . | grep -B1 ':.*=' | sed 's,^--$,,' +// Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel ... +CMAKE_BUILD_TYPE:STRING= + +// Install path prefix, prepended onto install directories. +CMAKE_INSTALL_PREFIX:PATH=/usr/local + +// Path to a program. +DOCBOOK_TO_MAN:FILEPATH=/usr/bin/docbook2x-man + +// build man page for xmlwf +EXPAT_BUILD_DOCS:BOOL=ON + +// build the examples for expat library +EXPAT_BUILD_EXAMPLES:BOOL=ON + +// build fuzzers for the expat library +EXPAT_BUILD_FUZZERS:BOOL=OFF + +// build the tests for expat library +EXPAT_BUILD_TESTS:BOOL=ON + +// build the xmlwf tool for expat library +EXPAT_BUILD_TOOLS:BOOL=ON + +// Character type to use (char|ushort|wchar_t) [default=char] +EXPAT_CHAR_TYPE:STRING=char + +// install expat files in cmake install target +EXPAT_ENABLE_INSTALL:BOOL=ON + +// Use /MT flag (static CRT) when compiling in MSVC +EXPAT_MSVC_STATIC_CRT:BOOL=OFF + +// build a shared expat library +EXPAT_SHARED_LIBS:BOOL=ON + +// Treat all compiler warnings as errors +EXPAT_WARNINGS_AS_ERRORS:BOOL=OFF + +// Make use of getrandom function (ON|OFF|AUTO) [default=AUTO] +EXPAT_WITH_GETRANDOM:STRING=AUTO + +// utilize libbsd (for arc4random_buf) +EXPAT_WITH_LIBBSD:BOOL=OFF + +// Make use of syscall SYS_getrandom (ON|OFF|AUTO) [default=AUTO] +EXPAT_WITH_SYS_GETRANDOM:STRING=AUTO +``` Index: expat/VERSION ================================================================== --- expat/VERSION +++ expat/VERSION @@ -1,1 +1,1 @@ -expat-2.2.5 +expat-2.2.9 Index: expat/asciitab.h ================================================================== --- expat/asciitab.h +++ expat/asciitab.h @@ -29,36 +29,36 @@ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* 0x00 */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML, -/* 0x04 */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML, -/* 0x08 */ BT_NONXML, BT_S, BT_LF, BT_NONXML, -/* 0x0C */ BT_NONXML, BT_CR, BT_NONXML, BT_NONXML, -/* 0x10 */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML, -/* 0x14 */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML, -/* 0x18 */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML, -/* 0x1C */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML, -/* 0x20 */ BT_S, BT_EXCL, BT_QUOT, BT_NUM, -/* 0x24 */ BT_OTHER, BT_PERCNT, BT_AMP, BT_APOS, -/* 0x28 */ BT_LPAR, BT_RPAR, BT_AST, BT_PLUS, -/* 0x2C */ BT_COMMA, BT_MINUS, BT_NAME, BT_SOL, -/* 0x30 */ BT_DIGIT, BT_DIGIT, BT_DIGIT, BT_DIGIT, -/* 0x34 */ BT_DIGIT, BT_DIGIT, BT_DIGIT, BT_DIGIT, -/* 0x38 */ BT_DIGIT, BT_DIGIT, BT_COLON, BT_SEMI, -/* 0x3C */ BT_LT, BT_EQUALS, BT_GT, BT_QUEST, -/* 0x40 */ BT_OTHER, BT_HEX, BT_HEX, BT_HEX, -/* 0x44 */ BT_HEX, BT_HEX, BT_HEX, BT_NMSTRT, -/* 0x48 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, -/* 0x4C */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, -/* 0x50 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, -/* 0x54 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, -/* 0x58 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_LSQB, -/* 0x5C */ BT_OTHER, BT_RSQB, BT_OTHER, BT_NMSTRT, -/* 0x60 */ BT_OTHER, BT_HEX, BT_HEX, BT_HEX, -/* 0x64 */ BT_HEX, BT_HEX, BT_HEX, BT_NMSTRT, -/* 0x68 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, -/* 0x6C */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, -/* 0x70 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, -/* 0x74 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, -/* 0x78 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_OTHER, -/* 0x7C */ BT_VERBAR, BT_OTHER, BT_OTHER, BT_OTHER, + /* 0x04 */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML, + /* 0x08 */ BT_NONXML, BT_S, BT_LF, BT_NONXML, + /* 0x0C */ BT_NONXML, BT_CR, BT_NONXML, BT_NONXML, + /* 0x10 */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML, + /* 0x14 */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML, + /* 0x18 */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML, + /* 0x1C */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML, + /* 0x20 */ BT_S, BT_EXCL, BT_QUOT, BT_NUM, + /* 0x24 */ BT_OTHER, BT_PERCNT, BT_AMP, BT_APOS, + /* 0x28 */ BT_LPAR, BT_RPAR, BT_AST, BT_PLUS, + /* 0x2C */ BT_COMMA, BT_MINUS, BT_NAME, BT_SOL, + /* 0x30 */ BT_DIGIT, BT_DIGIT, BT_DIGIT, BT_DIGIT, + /* 0x34 */ BT_DIGIT, BT_DIGIT, BT_DIGIT, BT_DIGIT, + /* 0x38 */ BT_DIGIT, BT_DIGIT, BT_COLON, BT_SEMI, + /* 0x3C */ BT_LT, BT_EQUALS, BT_GT, BT_QUEST, + /* 0x40 */ BT_OTHER, BT_HEX, BT_HEX, BT_HEX, + /* 0x44 */ BT_HEX, BT_HEX, BT_HEX, BT_NMSTRT, + /* 0x48 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, + /* 0x4C */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, + /* 0x50 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, + /* 0x54 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, + /* 0x58 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_LSQB, + /* 0x5C */ BT_OTHER, BT_RSQB, BT_OTHER, BT_NMSTRT, + /* 0x60 */ BT_OTHER, BT_HEX, BT_HEX, BT_HEX, + /* 0x64 */ BT_HEX, BT_HEX, BT_HEX, BT_NMSTRT, + /* 0x68 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, + /* 0x6C */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, + /* 0x70 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, + /* 0x74 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, + /* 0x78 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_OTHER, + /* 0x7C */ BT_VERBAR, BT_OTHER, BT_OTHER, BT_OTHER, Index: expat/expat.h ================================================================== --- expat/expat.h +++ expat/expat.h @@ -31,19 +31,10 @@ */ #ifndef Expat_INCLUDED #define Expat_INCLUDED 1 -#ifdef __VMS -/* 0 1 2 3 0 1 2 3 - 1234567890123456789012345678901 1234567890123456789012345678901 */ -#define XML_SetProcessingInstructionHandler XML_SetProcessingInstrHandler -#define XML_SetUnparsedEntityDeclHandler XML_SetUnparsedEntDeclHandler -#define XML_SetStartNamespaceDeclHandler XML_SetStartNamespcDeclHandler -#define XML_SetExternalEntityRefHandlerArg XML_SetExternalEntRefHandlerArg -#endif - #include #include "expat_external.h" #ifdef __cplusplus extern "C" { @@ -51,12 +42,12 @@ struct XML_ParserStruct; typedef struct XML_ParserStruct *XML_Parser; typedef unsigned char XML_Bool; -#define XML_TRUE ((XML_Bool) 1) -#define XML_FALSE ((XML_Bool) 0) +#define XML_TRUE ((XML_Bool)1) +#define XML_FALSE ((XML_Bool)0) /* The XML_Status enum gives the possible return values for several API functions. The preprocessor #defines are included so this stanza can be added to code that still needs to support older versions of Expat 1.95.x: @@ -162,67 +153,58 @@ */ typedef struct XML_cp XML_Content; struct XML_cp { - enum XML_Content_Type type; - enum XML_Content_Quant quant; - XML_Char * name; - unsigned int numchildren; - XML_Content * children; + enum XML_Content_Type type; + enum XML_Content_Quant quant; + XML_Char *name; + unsigned int numchildren; + XML_Content *children; }; - /* This is called for an element declaration. See above for description of the model argument. It's the caller's responsibility to free model when finished with it. */ -typedef void (XMLCALL *XML_ElementDeclHandler) (void *userData, - const XML_Char *name, - XML_Content *model); +typedef void(XMLCALL *XML_ElementDeclHandler)(void *userData, + const XML_Char *name, + XML_Content *model); XMLPARSEAPI(void) -XML_SetElementDeclHandler(XML_Parser parser, - XML_ElementDeclHandler eldecl); +XML_SetElementDeclHandler(XML_Parser parser, XML_ElementDeclHandler eldecl); /* The Attlist declaration handler is called for *each* attribute. So a single Attlist declaration with multiple attributes declared will generate multiple calls to this handler. The "default" parameter may be NULL in the case of the "#IMPLIED" or "#REQUIRED" keyword. The "isrequired" parameter will be true and the default value will be NULL in the case of "#REQUIRED". If "isrequired" is true and default is non-NULL, then this is a "#FIXED" default. */ -typedef void (XMLCALL *XML_AttlistDeclHandler) ( - void *userData, - const XML_Char *elname, - const XML_Char *attname, - const XML_Char *att_type, - const XML_Char *dflt, - int isrequired); +typedef void(XMLCALL *XML_AttlistDeclHandler)( + void *userData, const XML_Char *elname, const XML_Char *attname, + const XML_Char *att_type, const XML_Char *dflt, int isrequired); XMLPARSEAPI(void) -XML_SetAttlistDeclHandler(XML_Parser parser, - XML_AttlistDeclHandler attdecl); +XML_SetAttlistDeclHandler(XML_Parser parser, XML_AttlistDeclHandler attdecl); /* The XML declaration handler is called for *both* XML declarations and text declarations. The way to distinguish is that the version parameter will be NULL for text declarations. The encoding parameter may be NULL for XML declarations. The standalone parameter will be -1, 0, or 1 indicating respectively that there was no standalone parameter in the declaration, that it was given as no, or that it was given as yes. */ -typedef void (XMLCALL *XML_XmlDeclHandler) (void *userData, - const XML_Char *version, - const XML_Char *encoding, - int standalone); +typedef void(XMLCALL *XML_XmlDeclHandler)(void *userData, + const XML_Char *version, + const XML_Char *encoding, + int standalone); XMLPARSEAPI(void) -XML_SetXmlDeclHandler(XML_Parser parser, - XML_XmlDeclHandler xmldecl); - +XML_SetXmlDeclHandler(XML_Parser parser, XML_XmlDeclHandler xmldecl); typedef struct { void *(*malloc_fcn)(size_t size); void *(*realloc_fcn)(void *ptr, size_t size); void (*free_fcn)(void *ptr); @@ -245,11 +227,10 @@ It is a programming error to use the separator '\0' with namespace triplets (see XML_SetReturnNSTriplet). */ XMLPARSEAPI(XML_Parser) XML_ParserCreateNS(const XML_Char *encoding, XML_Char namespaceSeparator); - /* Constructs a new parser using the memory management suite referred to by memsuite. If memsuite is NULL, then use the standard library memory suite. If namespaceSeparator is non-NULL it creates a parser with namespace processing as described above. The character pointed at @@ -276,35 +257,31 @@ XML_ParserReset(XML_Parser parser, const XML_Char *encoding); /* atts is array of name/value pairs, terminated by 0; names and values are 0 terminated. */ -typedef void (XMLCALL *XML_StartElementHandler) (void *userData, - const XML_Char *name, - const XML_Char **atts); +typedef void(XMLCALL *XML_StartElementHandler)(void *userData, + const XML_Char *name, + const XML_Char **atts); -typedef void (XMLCALL *XML_EndElementHandler) (void *userData, - const XML_Char *name); - +typedef void(XMLCALL *XML_EndElementHandler)(void *userData, + const XML_Char *name); /* s is not 0 terminated. */ -typedef void (XMLCALL *XML_CharacterDataHandler) (void *userData, - const XML_Char *s, - int len); +typedef void(XMLCALL *XML_CharacterDataHandler)(void *userData, + const XML_Char *s, int len); /* target and data are 0 terminated */ -typedef void (XMLCALL *XML_ProcessingInstructionHandler) ( - void *userData, - const XML_Char *target, - const XML_Char *data); +typedef void(XMLCALL *XML_ProcessingInstructionHandler)(void *userData, + const XML_Char *target, + const XML_Char *data); /* data is 0 terminated */ -typedef void (XMLCALL *XML_CommentHandler) (void *userData, - const XML_Char *data); +typedef void(XMLCALL *XML_CommentHandler)(void *userData, const XML_Char *data); -typedef void (XMLCALL *XML_StartCdataSectionHandler) (void *userData); -typedef void (XMLCALL *XML_EndCdataSectionHandler) (void *userData); +typedef void(XMLCALL *XML_StartCdataSectionHandler)(void *userData); +typedef void(XMLCALL *XML_EndCdataSectionHandler)(void *userData); /* This is called for any characters in the XML document for which there is no applicable handler. This includes both characters that are part of markup which is of a kind that is not reported (comments, markup declarations), or characters that are part of a @@ -315,29 +292,27 @@ character is not passed to the default handler. There are no guarantees about how characters are divided between calls to the default handler: for example, a comment might be split between multiple calls. */ -typedef void (XMLCALL *XML_DefaultHandler) (void *userData, - const XML_Char *s, - int len); +typedef void(XMLCALL *XML_DefaultHandler)(void *userData, const XML_Char *s, + int len); /* This is called for the start of the DOCTYPE declaration, before any DTD or internal subset is parsed. */ -typedef void (XMLCALL *XML_StartDoctypeDeclHandler) ( - void *userData, - const XML_Char *doctypeName, - const XML_Char *sysid, - const XML_Char *pubid, - int has_internal_subset); +typedef void(XMLCALL *XML_StartDoctypeDeclHandler)(void *userData, + const XML_Char *doctypeName, + const XML_Char *sysid, + const XML_Char *pubid, + int has_internal_subset); /* This is called for the start of the DOCTYPE declaration when the closing > is encountered, but after processing any external subset. */ -typedef void (XMLCALL *XML_EndDoctypeDeclHandler)(void *userData); +typedef void(XMLCALL *XML_EndDoctypeDeclHandler)(void *userData); /* This is called for entity declarations. The is_parameter_entity argument will be non-zero if the entity is a parameter entity, zero otherwise. @@ -353,24 +328,18 @@ non-NULL value only for unparsed entity declarations. Note that is_parameter_entity can't be changed to XML_Bool, since that would break binary compatibility. */ -typedef void (XMLCALL *XML_EntityDeclHandler) ( - void *userData, - const XML_Char *entityName, - int is_parameter_entity, - const XML_Char *value, - int value_length, - const XML_Char *base, - const XML_Char *systemId, - const XML_Char *publicId, - const XML_Char *notationName); +typedef void(XMLCALL *XML_EntityDeclHandler)( + void *userData, const XML_Char *entityName, int is_parameter_entity, + const XML_Char *value, int value_length, const XML_Char *base, + const XML_Char *systemId, const XML_Char *publicId, + const XML_Char *notationName); XMLPARSEAPI(void) -XML_SetEntityDeclHandler(XML_Parser parser, - XML_EntityDeclHandler handler); +XML_SetEntityDeclHandler(XML_Parser parser, XML_EntityDeclHandler handler); /* OBSOLETE -- OBSOLETE -- OBSOLETE This handler has been superseded by the EntityDeclHandler above. It is provided here for backward compatibility. @@ -377,43 +346,37 @@ This is called for a declaration of an unparsed (NDATA) entity. The base argument is whatever was set by XML_SetBase. The entityName, systemId and notationName arguments will never be NULL. The other arguments may be. */ -typedef void (XMLCALL *XML_UnparsedEntityDeclHandler) ( - void *userData, - const XML_Char *entityName, - const XML_Char *base, - const XML_Char *systemId, - const XML_Char *publicId, - const XML_Char *notationName); +typedef void(XMLCALL *XML_UnparsedEntityDeclHandler)( + void *userData, const XML_Char *entityName, const XML_Char *base, + const XML_Char *systemId, const XML_Char *publicId, + const XML_Char *notationName); /* This is called for a declaration of notation. The base argument is whatever was set by XML_SetBase. The notationName will never be NULL. The other arguments can be. */ -typedef void (XMLCALL *XML_NotationDeclHandler) ( - void *userData, - const XML_Char *notationName, - const XML_Char *base, - const XML_Char *systemId, - const XML_Char *publicId); +typedef void(XMLCALL *XML_NotationDeclHandler)(void *userData, + const XML_Char *notationName, + const XML_Char *base, + const XML_Char *systemId, + const XML_Char *publicId); /* When namespace processing is enabled, these are called once for each namespace declaration. The call to the start and end element handlers occur between the calls to the start and end namespace declaration handlers. For an xmlns attribute, prefix will be NULL. For an xmlns="" attribute, uri will be NULL. */ -typedef void (XMLCALL *XML_StartNamespaceDeclHandler) ( - void *userData, - const XML_Char *prefix, - const XML_Char *uri); - -typedef void (XMLCALL *XML_EndNamespaceDeclHandler) ( - void *userData, - const XML_Char *prefix); +typedef void(XMLCALL *XML_StartNamespaceDeclHandler)(void *userData, + const XML_Char *prefix, + const XML_Char *uri); + +typedef void(XMLCALL *XML_EndNamespaceDeclHandler)(void *userData, + const XML_Char *prefix); /* This is called if the document is not standalone, that is, it has an external subset or a reference to a parameter entity, but does not have standalone="yes". If this handler returns XML_STATUS_ERROR, then processing will not continue, and the parser will return a @@ -420,11 +383,11 @@ XML_ERROR_NOT_STANDALONE error. If parameter entity parsing is enabled, then in addition to the conditions above this handler will only be called if the referenced entity was actually read. */ -typedef int (XMLCALL *XML_NotStandaloneHandler) (void *userData); +typedef int(XMLCALL *XML_NotStandaloneHandler)(void *userData); /* This is called for a reference to an external parsed general entity. The referenced entity is not automatically parsed. The application can parse it immediately or later using XML_ExternalEntityParserCreate. @@ -456,16 +419,15 @@ XML_ERROR_EXTERNAL_ENTITY_HANDLING error. Note that unlike other handlers the first argument is the parser, not userData. */ -typedef int (XMLCALL *XML_ExternalEntityRefHandler) ( - XML_Parser parser, - const XML_Char *context, - const XML_Char *base, - const XML_Char *systemId, - const XML_Char *publicId); +typedef int(XMLCALL *XML_ExternalEntityRefHandler)(XML_Parser parser, + const XML_Char *context, + const XML_Char *base, + const XML_Char *systemId, + const XML_Char *publicId); /* This is called in two situations: 1) An entity reference is encountered for which no declaration has been read *and* this is not an error. 2) An internal entity reference is read, but not expanded, because @@ -473,14 +435,13 @@ Note: skipped parameter entities in declarations and skipped general entities in attribute values cannot be reported, because the event would be out of sync with the reporting of the declarations or attribute values */ -typedef void (XMLCALL *XML_SkippedEntityHandler) ( - void *userData, - const XML_Char *entityName, - int is_parameter_entity); +typedef void(XMLCALL *XML_SkippedEntityHandler)(void *userData, + const XML_Char *entityName, + int is_parameter_entity); /* This structure is filled in by the XML_UnknownEncodingHandler to provide information to the parser about encodings that are unknown to the parser. @@ -533,12 +494,12 @@ sequence of bytes. */ typedef struct { int map[256]; void *data; - int (XMLCALL *convert)(void *data, const char *s); - void (XMLCALL *release)(void *data); + int(XMLCALL *convert)(void *data, const char *s); + void(XMLCALL *release)(void *data); } XML_Encoding; /* This is called for an encoding that is unknown to the parser. The encodingHandlerData argument is that which was passed as the @@ -552,38 +513,33 @@ Otherwise it must return XML_STATUS_ERROR. If info does not describe a suitable encoding, then the parser will return an XML_UNKNOWN_ENCODING error. */ -typedef int (XMLCALL *XML_UnknownEncodingHandler) ( - void *encodingHandlerData, - const XML_Char *name, - XML_Encoding *info); +typedef int(XMLCALL *XML_UnknownEncodingHandler)(void *encodingHandlerData, + const XML_Char *name, + XML_Encoding *info); XMLPARSEAPI(void) -XML_SetElementHandler(XML_Parser parser, - XML_StartElementHandler start, +XML_SetElementHandler(XML_Parser parser, XML_StartElementHandler start, XML_EndElementHandler end); XMLPARSEAPI(void) -XML_SetStartElementHandler(XML_Parser parser, - XML_StartElementHandler handler); +XML_SetStartElementHandler(XML_Parser parser, XML_StartElementHandler handler); XMLPARSEAPI(void) -XML_SetEndElementHandler(XML_Parser parser, - XML_EndElementHandler handler); +XML_SetEndElementHandler(XML_Parser parser, XML_EndElementHandler handler); XMLPARSEAPI(void) XML_SetCharacterDataHandler(XML_Parser parser, XML_CharacterDataHandler handler); XMLPARSEAPI(void) XML_SetProcessingInstructionHandler(XML_Parser parser, XML_ProcessingInstructionHandler handler); XMLPARSEAPI(void) -XML_SetCommentHandler(XML_Parser parser, - XML_CommentHandler handler); +XML_SetCommentHandler(XML_Parser parser, XML_CommentHandler handler); XMLPARSEAPI(void) XML_SetCdataSectionHandler(XML_Parser parser, XML_StartCdataSectionHandler start, XML_EndCdataSectionHandler end); @@ -599,41 +555,36 @@ /* This sets the default handler and also inhibits expansion of internal entities. These entity references will be passed to the default handler, or to the skipped entity handler, if one is set. */ XMLPARSEAPI(void) -XML_SetDefaultHandler(XML_Parser parser, - XML_DefaultHandler handler); +XML_SetDefaultHandler(XML_Parser parser, XML_DefaultHandler handler); /* This sets the default handler but does not inhibit expansion of internal entities. The entity reference will not be passed to the default handler. */ XMLPARSEAPI(void) -XML_SetDefaultHandlerExpand(XML_Parser parser, - XML_DefaultHandler handler); +XML_SetDefaultHandlerExpand(XML_Parser parser, XML_DefaultHandler handler); XMLPARSEAPI(void) -XML_SetDoctypeDeclHandler(XML_Parser parser, - XML_StartDoctypeDeclHandler start, +XML_SetDoctypeDeclHandler(XML_Parser parser, XML_StartDoctypeDeclHandler start, XML_EndDoctypeDeclHandler end); XMLPARSEAPI(void) XML_SetStartDoctypeDeclHandler(XML_Parser parser, XML_StartDoctypeDeclHandler start); XMLPARSEAPI(void) -XML_SetEndDoctypeDeclHandler(XML_Parser parser, - XML_EndDoctypeDeclHandler end); +XML_SetEndDoctypeDeclHandler(XML_Parser parser, XML_EndDoctypeDeclHandler end); XMLPARSEAPI(void) XML_SetUnparsedEntityDeclHandler(XML_Parser parser, XML_UnparsedEntityDeclHandler handler); XMLPARSEAPI(void) -XML_SetNotationDeclHandler(XML_Parser parser, - XML_NotationDeclHandler handler); +XML_SetNotationDeclHandler(XML_Parser parser, XML_NotationDeclHandler handler); XMLPARSEAPI(void) XML_SetNamespaceDeclHandler(XML_Parser parser, XML_StartNamespaceDeclHandler start, XML_EndNamespaceDeclHandler end); @@ -657,12 +608,11 @@ /* If a non-NULL value for arg is specified here, then it will be passed as the first argument to the external entity ref handler instead of the parser object. */ XMLPARSEAPI(void) -XML_SetExternalEntityRefHandlerArg(XML_Parser parser, - void *arg); +XML_SetExternalEntityRefHandlerArg(XML_Parser parser, void *arg); XMLPARSEAPI(void) XML_SetSkippedEntityHandler(XML_Parser parser, XML_SkippedEntityHandler handler); @@ -738,11 +688,10 @@ Note: If parser == NULL, returns XML_ERROR_INVALID_ARGUMENT. */ XMLPARSEAPI(enum XML_Error) XML_UseForeignDTD(XML_Parser parser, XML_Bool useDTD); - /* Sets the base to be used for resolving relative URIs in system identifiers in declarations. Resolving relative identifiers is left to the application: this value will be passed through as the base argument to the XML_ExternalEntityRefHandler, XML_NotationDeclHandler and XML_UnparsedEntityDeclHandler. The base @@ -778,14 +727,14 @@ The value indices are exclusive of surrounding quotes; thus in a UTF-8 source file an attribute value of "blah" will yield: info->valueEnd - info->valueStart = 4 bytes. */ typedef struct { - XML_Index nameStart; /* Offset to beginning of the attribute name. */ - XML_Index nameEnd; /* Offset after the attribute name's last byte. */ - XML_Index valueStart; /* Offset to beginning of the attribute value. */ - XML_Index valueEnd; /* Offset after the attribute value's last byte. */ + XML_Index nameStart; /* Offset to beginning of the attribute name. */ + XML_Index nameEnd; /* Offset after the attribute name's last byte. */ + XML_Index valueStart; /* Offset to beginning of the attribute value. */ + XML_Index valueEnd; /* Offset after the attribute value's last byte. */ } XML_AttrInfo; /* Returns an array of XML_AttrInfo structures for the attribute/value pairs passed in last call to the XML_StartElementHandler that were specified in the start-tag rather than defaulted. Each attribute/value pair counts @@ -817,24 +766,24 @@ /* Stops parsing, causing XML_Parse() or XML_ParseBuffer() to return. Must be called from within a call-back handler, except when aborting (resumable = 0) an already suspended parser. Some call-backs may still follow because they would otherwise get lost. Examples: - endElementHandler() for empty elements when stopped in - startElementHandler(), - - endNameSpaceDeclHandler() when stopped in endElementHandler(), + startElementHandler(), + - endNameSpaceDeclHandler() when stopped in endElementHandler(), and possibly others. Can be called from most handlers, including DTD related call-backs, except when parsing an external parameter entity and resumable != 0. Returns XML_STATUS_OK when successful, XML_STATUS_ERROR otherwise. - Possible error codes: + Possible error codes: - XML_ERROR_SUSPENDED: when suspending an already suspended parser. - XML_ERROR_FINISHED: when the parser has already finished. - XML_ERROR_SUSPEND_PE: when suspending while parsing an external PE. - When resumable != 0 (true) then parsing is suspended, that is, - XML_Parse() and XML_ParseBuffer() return XML_STATUS_SUSPENDED. + When resumable != 0 (true) then parsing is suspended, that is, + XML_Parse() and XML_ParseBuffer() return XML_STATUS_SUSPENDED. Otherwise, parsing is aborted, that is, XML_Parse() and XML_ParseBuffer() return XML_STATUS_ERROR with error code XML_ERROR_ABORTED. *Note*: This will be applied to the current parser instance only, that is, if @@ -841,19 +790,19 @@ there is a parent parser then it will continue parsing when the externalEntityRefHandler() returns. It is up to the implementation of the externalEntityRefHandler() to call XML_StopParser() on the parent parser (recursively), if one wants to stop parsing altogether. - When suspended, parsing can be resumed by calling XML_ResumeParser(). + When suspended, parsing can be resumed by calling XML_ResumeParser(). */ XMLPARSEAPI(enum XML_Status) XML_StopParser(XML_Parser parser, XML_Bool resumable); /* Resumes parsing after it has been suspended with XML_StopParser(). Must not be called from within a handler call-back. Returns same status codes as XML_Parse() or XML_ParseBuffer(). - Additional error code XML_ERROR_NOT_SUSPENDED possible. + Additional error code XML_ERROR_NOT_SUSPENDED possible. *Note*: This must be called on the most deeply nested child parser instance first, and on its parent parser only after the child parser has finished, to be applied recursively until the document entity's parser is restarted. @@ -861,16 +810,11 @@ application to call XML_ResumeParser() on it at the appropriate moment. */ XMLPARSEAPI(enum XML_Status) XML_ResumeParser(XML_Parser parser); -enum XML_Parsing { - XML_INITIALIZED, - XML_PARSING, - XML_FINISHED, - XML_SUSPENDED -}; +enum XML_Parsing { XML_INITIALIZED, XML_PARSING, XML_FINISHED, XML_SUSPENDED }; typedef struct { enum XML_Parsing parsing; XML_Bool finalBuffer; } XML_ParsingStatus; @@ -898,12 +842,11 @@ safely be used in a separate thread. The handlers and userData are initialized from the parser argument. Returns NULL if out of memory. Otherwise returns a new XML_Parser object. */ XMLPARSEAPI(XML_Parser) -XML_ExternalEntityParserCreate(XML_Parser parser, - const XML_Char *context, +XML_ExternalEntityParserCreate(XML_Parser parser, const XML_Char *context, const XML_Char *encoding); enum XML_ParamEntityParsing { XML_PARAM_ENTITY_PARSING_NEVER, XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONE, @@ -943,12 +886,11 @@ function behavior. This must be called before parsing is started. Returns 1 if successful, 0 when called after parsing has started. Note: If parser == NULL, the function will do nothing and return 0. */ XMLPARSEAPI(int) -XML_SetHashSalt(XML_Parser parser, - unsigned long hash_salt); +XML_SetHashSalt(XML_Parser parser, unsigned long hash_salt); /* If XML_Parse or XML_ParseBuffer have returned XML_STATUS_ERROR, then XML_GetErrorCode returns information about the error. */ XMLPARSEAPI(enum XML_Error) @@ -961,11 +903,11 @@ called from callbacks generated by declarations in the document prologue, the location identified isn't as neatly defined, but will be within the relevant markup. When called outside of the callback functions, the position indicated will be just past the last parse event (regardless of whether there was an associated callback). - + They may also be called after returning from a call to XML_Parse or XML_ParseBuffer. If the return value is XML_STATUS_ERROR then the location is the location of the character at which the error was detected; otherwise the location is the location of the last parse event, as described above. @@ -993,18 +935,16 @@ NOTE: The character pointer returned should not be used outside the handler that makes the call. */ XMLPARSEAPI(const char *) -XML_GetInputContext(XML_Parser parser, - int *offset, - int *size); +XML_GetInputContext(XML_Parser parser, int *offset, int *size); /* For backwards compatibility with previous versions. */ -#define XML_GetErrorLineNumber XML_GetCurrentLineNumber +#define XML_GetErrorLineNumber XML_GetCurrentLineNumber #define XML_GetErrorColumnNumber XML_GetCurrentColumnNumber -#define XML_GetErrorByteIndex XML_GetCurrentByteIndex +#define XML_GetErrorByteIndex XML_GetCurrentByteIndex /* Frees the content model passed to the element declaration handler */ XMLPARSEAPI(void) XML_FreeContentModel(XML_Parser parser, XML_Content *model); @@ -1060,26 +1000,25 @@ XML_FEATURE_ATTR_INFO /* Additional features must be added to the end of this enum. */ }; typedef struct { - enum XML_FeatureEnum feature; - const XML_LChar *name; - long int value; + enum XML_FeatureEnum feature; + const XML_LChar *name; + long int value; } XML_Feature; XMLPARSEAPI(const XML_Feature *) XML_GetFeatureList(void); - /* Expat follows the semantic versioning convention. See http://semver.org. */ #define XML_MAJOR_VERSION 2 #define XML_MINOR_VERSION 2 -#define XML_MICRO_VERSION 6 +#define XML_MICRO_VERSION 9 #ifdef __cplusplus } #endif #endif /* not Expat_INCLUDED */ Index: expat/expat_external.h ================================================================== --- expat/expat_external.h +++ expat/expat_external.h @@ -33,14 +33,10 @@ #ifndef Expat_External_INCLUDED #define Expat_External_INCLUDED 1 /* External API definitions */ -#if defined(_MSC_EXTENSIONS) && !defined(__BEOS__) && !defined(__CYGWIN__) -# define XML_USE_MSC_EXTENSIONS 1 -#endif - /* Expat tries very hard to make the API boundary very specifically defined. There are two macros defined to control this boundary; each of these can be defined before including this header to achieve some different behavior, but doing so it not recommended or tested frequently. @@ -60,15 +56,15 @@ Note that on at least some Unix versions, the Expat library must be compiled with the cdecl calling convention as the default since system headers may assume the cdecl convention. */ #ifndef XMLCALL -# if defined(_MSC_VER) -# define XMLCALL __cdecl -# elif defined(__GNUC__) && defined(__i386) && !defined(__INTEL_COMPILER) -# define XMLCALL __attribute__((cdecl)) -# else +# if defined(_MSC_VER) +# define XMLCALL __cdecl +# elif defined(__GNUC__) && defined(__i386) && ! defined(__INTEL_COMPILER) +# define XMLCALL __attribute__((cdecl)) +# else /* For any platform which uses this definition and supports more than one calling convention, we need to extend this definition to declare the convention used on that platform, if it's possible to do so. @@ -75,83 +71,83 @@ If this is the case for your platform, please file a bug report with information on how to identify your platform via the C pre-processor and how to specify the same calling convention as the platform's malloc() implementation. */ -# define XMLCALL -# endif -#endif /* not defined XMLCALL */ +# define XMLCALL +# endif +#endif /* not defined XMLCALL */ - -#if !defined(XML_STATIC) && !defined(XMLIMPORT) -# ifndef XML_BUILDING_EXPAT +#if ! defined(XML_STATIC) && ! defined(XMLIMPORT) +# ifndef XML_BUILDING_EXPAT /* using Expat from an application */ -# ifdef XML_USE_MSC_EXTENSIONS -# define XMLIMPORT __declspec(dllimport) +# if defined(_MSC_EXTENSIONS) && ! defined(__BEOS__) && ! defined(__CYGWIN__) +# define XMLIMPORT __declspec(dllimport) +# endif + # endif +#endif /* not defined XML_STATIC */ -# endif -#endif /* not defined XML_STATIC */ +#ifndef XML_ENABLE_VISIBILITY +# define XML_ENABLE_VISIBILITY 0 +#endif -#if !defined(XMLIMPORT) && defined(__GNUC__) && (__GNUC__ >= 4) -# define XMLIMPORT __attribute__ ((visibility ("default"))) +#if ! defined(XMLIMPORT) && XML_ENABLE_VISIBILITY +# define XMLIMPORT __attribute__((visibility("default"))) #endif /* If we didn't define it above, define it away: */ #ifndef XMLIMPORT -# define XMLIMPORT +# define XMLIMPORT #endif -#if defined(__GNUC__) && (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)) -# define XML_ATTR_MALLOC __attribute__((__malloc__)) +#if defined(__GNUC__) \ + && (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)) +# define XML_ATTR_MALLOC __attribute__((__malloc__)) #else -# define XML_ATTR_MALLOC +# define XML_ATTR_MALLOC #endif -#if defined(__GNUC__) && ((__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)) -# define XML_ATTR_ALLOC_SIZE(x) __attribute__((__alloc_size__(x))) +#if defined(__GNUC__) \ + && ((__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)) +# define XML_ATTR_ALLOC_SIZE(x) __attribute__((__alloc_size__(x))) #else -# define XML_ATTR_ALLOC_SIZE(x) +# define XML_ATTR_ALLOC_SIZE(x) #endif #define XMLPARSEAPI(type) XMLIMPORT type XMLCALL #ifdef __cplusplus extern "C" { #endif #ifdef XML_UNICODE_WCHAR_T -# ifndef XML_UNICODE -# define XML_UNICODE -# endif -# if defined(__SIZEOF_WCHAR_T__) && (__SIZEOF_WCHAR_T__ != 2) -# error "sizeof(wchar_t) != 2; Need -fshort-wchar for both Expat and libc" -# endif +# ifndef XML_UNICODE +# define XML_UNICODE +# endif +# if defined(__SIZEOF_WCHAR_T__) && (__SIZEOF_WCHAR_T__ != 2) +# error "sizeof(wchar_t) != 2; Need -fshort-wchar for both Expat and libc" +# endif #endif -#ifdef XML_UNICODE /* Information is UTF-16 encoded. */ -# ifdef XML_UNICODE_WCHAR_T +#ifdef XML_UNICODE /* Information is UTF-16 encoded. */ +# ifdef XML_UNICODE_WCHAR_T typedef wchar_t XML_Char; typedef wchar_t XML_LChar; -# else +# else typedef unsigned short XML_Char; typedef char XML_LChar; -# endif /* XML_UNICODE_WCHAR_T */ -#else /* Information is UTF-8 encoded. */ +# endif /* XML_UNICODE_WCHAR_T */ +#else /* Information is UTF-8 encoded. */ typedef char XML_Char; typedef char XML_LChar; -#endif /* XML_UNICODE */ +#endif /* XML_UNICODE */ -#ifdef XML_LARGE_SIZE /* Use large integers for file/stream positions. */ -# if defined(XML_USE_MSC_EXTENSIONS) && _MSC_VER < 1400 -typedef __int64 XML_Index; -typedef unsigned __int64 XML_Size; -# else +#ifdef XML_LARGE_SIZE /* Use large integers for file/stream positions. */ typedef long long XML_Index; typedef unsigned long long XML_Size; -# endif #else typedef long XML_Index; typedef unsigned long XML_Size; #endif /* XML_LARGE_SIZE */ Index: expat/iasciitab.h ================================================================== --- expat/iasciitab.h +++ expat/iasciitab.h @@ -30,36 +30,36 @@ USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* Like asciitab.h, except that 0xD has code BT_S rather than BT_CR */ /* 0x00 */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML, -/* 0x04 */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML, -/* 0x08 */ BT_NONXML, BT_S, BT_LF, BT_NONXML, -/* 0x0C */ BT_NONXML, BT_S, BT_NONXML, BT_NONXML, -/* 0x10 */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML, -/* 0x14 */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML, -/* 0x18 */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML, -/* 0x1C */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML, -/* 0x20 */ BT_S, BT_EXCL, BT_QUOT, BT_NUM, -/* 0x24 */ BT_OTHER, BT_PERCNT, BT_AMP, BT_APOS, -/* 0x28 */ BT_LPAR, BT_RPAR, BT_AST, BT_PLUS, -/* 0x2C */ BT_COMMA, BT_MINUS, BT_NAME, BT_SOL, -/* 0x30 */ BT_DIGIT, BT_DIGIT, BT_DIGIT, BT_DIGIT, -/* 0x34 */ BT_DIGIT, BT_DIGIT, BT_DIGIT, BT_DIGIT, -/* 0x38 */ BT_DIGIT, BT_DIGIT, BT_COLON, BT_SEMI, -/* 0x3C */ BT_LT, BT_EQUALS, BT_GT, BT_QUEST, -/* 0x40 */ BT_OTHER, BT_HEX, BT_HEX, BT_HEX, -/* 0x44 */ BT_HEX, BT_HEX, BT_HEX, BT_NMSTRT, -/* 0x48 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, -/* 0x4C */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, -/* 0x50 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, -/* 0x54 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, -/* 0x58 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_LSQB, -/* 0x5C */ BT_OTHER, BT_RSQB, BT_OTHER, BT_NMSTRT, -/* 0x60 */ BT_OTHER, BT_HEX, BT_HEX, BT_HEX, -/* 0x64 */ BT_HEX, BT_HEX, BT_HEX, BT_NMSTRT, -/* 0x68 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, -/* 0x6C */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, -/* 0x70 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, -/* 0x74 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, -/* 0x78 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_OTHER, -/* 0x7C */ BT_VERBAR, BT_OTHER, BT_OTHER, BT_OTHER, + /* 0x04 */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML, + /* 0x08 */ BT_NONXML, BT_S, BT_LF, BT_NONXML, + /* 0x0C */ BT_NONXML, BT_S, BT_NONXML, BT_NONXML, + /* 0x10 */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML, + /* 0x14 */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML, + /* 0x18 */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML, + /* 0x1C */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML, + /* 0x20 */ BT_S, BT_EXCL, BT_QUOT, BT_NUM, + /* 0x24 */ BT_OTHER, BT_PERCNT, BT_AMP, BT_APOS, + /* 0x28 */ BT_LPAR, BT_RPAR, BT_AST, BT_PLUS, + /* 0x2C */ BT_COMMA, BT_MINUS, BT_NAME, BT_SOL, + /* 0x30 */ BT_DIGIT, BT_DIGIT, BT_DIGIT, BT_DIGIT, + /* 0x34 */ BT_DIGIT, BT_DIGIT, BT_DIGIT, BT_DIGIT, + /* 0x38 */ BT_DIGIT, BT_DIGIT, BT_COLON, BT_SEMI, + /* 0x3C */ BT_LT, BT_EQUALS, BT_GT, BT_QUEST, + /* 0x40 */ BT_OTHER, BT_HEX, BT_HEX, BT_HEX, + /* 0x44 */ BT_HEX, BT_HEX, BT_HEX, BT_NMSTRT, + /* 0x48 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, + /* 0x4C */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, + /* 0x50 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, + /* 0x54 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, + /* 0x58 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_LSQB, + /* 0x5C */ BT_OTHER, BT_RSQB, BT_OTHER, BT_NMSTRT, + /* 0x60 */ BT_OTHER, BT_HEX, BT_HEX, BT_HEX, + /* 0x64 */ BT_HEX, BT_HEX, BT_HEX, BT_NMSTRT, + /* 0x68 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, + /* 0x6C */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, + /* 0x70 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, + /* 0x74 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, + /* 0x78 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_OTHER, + /* 0x7C */ BT_VERBAR, BT_OTHER, BT_OTHER, BT_OTHER, Index: expat/internal.h ================================================================== --- expat/internal.h +++ expat/internal.h @@ -47,22 +47,22 @@ DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#if defined(__GNUC__) && defined(__i386__) && !defined(__MINGW32__) +#if defined(__GNUC__) && defined(__i386__) && ! defined(__MINGW32__) /* We'll use this version by default only where we know it helps. regparm() generates warnings on Solaris boxes. See SF bug #692878. Instability reported with egcs on a RedHat Linux 7.3. Let's comment out: #define FASTCALL __attribute__((stdcall, regparm(3))) and let's try this: */ -#define FASTCALL __attribute__((regparm(3))) -#define PTRFASTCALL __attribute__((regparm(3))) +# define FASTCALL __attribute__((regparm(3))) +# define PTRFASTCALL __attribute__((regparm(3))) #endif /* Using __fastcall seems to have an unexpected negative effect under MS VC++, especially for function pointers, so we won't use it for now on that platform. It may be reconsidered for a future release @@ -72,53 +72,52 @@ */ /* Make sure all of these are defined if they aren't already. */ #ifndef FASTCALL -#define FASTCALL +# define FASTCALL #endif #ifndef PTRCALL -#define PTRCALL +# define PTRCALL #endif #ifndef PTRFASTCALL -#define PTRFASTCALL +# define PTRFASTCALL #endif #ifndef XML_MIN_SIZE -#if !defined(__cplusplus) && !defined(inline) -#ifdef __GNUC__ -#define inline __inline -#endif /* __GNUC__ */ -#endif +# if ! defined(__cplusplus) && ! defined(inline) +# ifdef __GNUC__ +# define inline __inline +# endif /* __GNUC__ */ +# endif #endif /* XML_MIN_SIZE */ #ifdef __cplusplus -#define inline inline +# define inline inline #else -#ifndef inline -#define inline -#endif +# ifndef inline +# define inline +# endif #endif #ifndef UNUSED_P -# ifdef __GNUC__ -# define UNUSED_P(p) UNUSED_ ## p __attribute__((__unused__)) -# else -# define UNUSED_P(p) UNUSED_ ## p -# endif +# define UNUSED_P(p) (void)p #endif - #ifdef __cplusplus extern "C" { #endif - +#ifdef XML_ENABLE_VISIBILITY +# if XML_ENABLE_VISIBILITY +__attribute__((visibility("default"))) +# endif +#endif void -_INTERNAL_trim_to_complete_utf8_characters(const char * from, const char ** fromLimRef); - +_INTERNAL_trim_to_complete_utf8_characters(const char *from, + const char **fromLimRef); #ifdef __cplusplus } #endif Index: expat/latin1tab.h ================================================================== --- expat/latin1tab.h +++ expat/latin1tab.h @@ -29,36 +29,36 @@ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* 0x80 */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER, -/* 0x84 */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER, -/* 0x88 */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER, -/* 0x8C */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER, -/* 0x90 */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER, -/* 0x94 */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER, -/* 0x98 */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER, -/* 0x9C */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER, -/* 0xA0 */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER, -/* 0xA4 */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER, -/* 0xA8 */ BT_OTHER, BT_OTHER, BT_NMSTRT, BT_OTHER, -/* 0xAC */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER, -/* 0xB0 */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER, -/* 0xB4 */ BT_OTHER, BT_NMSTRT, BT_OTHER, BT_NAME, -/* 0xB8 */ BT_OTHER, BT_OTHER, BT_NMSTRT, BT_OTHER, -/* 0xBC */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER, -/* 0xC0 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, -/* 0xC4 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, -/* 0xC8 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, -/* 0xCC */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, -/* 0xD0 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, -/* 0xD4 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_OTHER, -/* 0xD8 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, -/* 0xDC */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, -/* 0xE0 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, -/* 0xE4 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, -/* 0xE8 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, -/* 0xEC */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, -/* 0xF0 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, -/* 0xF4 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_OTHER, -/* 0xF8 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, -/* 0xFC */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, + /* 0x84 */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER, + /* 0x88 */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER, + /* 0x8C */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER, + /* 0x90 */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER, + /* 0x94 */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER, + /* 0x98 */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER, + /* 0x9C */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER, + /* 0xA0 */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER, + /* 0xA4 */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER, + /* 0xA8 */ BT_OTHER, BT_OTHER, BT_NMSTRT, BT_OTHER, + /* 0xAC */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER, + /* 0xB0 */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER, + /* 0xB4 */ BT_OTHER, BT_NMSTRT, BT_OTHER, BT_NAME, + /* 0xB8 */ BT_OTHER, BT_OTHER, BT_NMSTRT, BT_OTHER, + /* 0xBC */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER, + /* 0xC0 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, + /* 0xC4 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, + /* 0xC8 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, + /* 0xCC */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, + /* 0xD0 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, + /* 0xD4 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_OTHER, + /* 0xD8 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, + /* 0xDC */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, + /* 0xE0 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, + /* 0xE4 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, + /* 0xE8 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, + /* 0xEC */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, + /* 0xF0 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, + /* 0xF4 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_OTHER, + /* 0xF8 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, + /* 0xFC */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, DELETED expat/loadlibrary.c Index: expat/loadlibrary.c ================================================================== --- expat/loadlibrary.c +++ /dev/null @@ -1,143 +0,0 @@ -/*************************************************************************** - * _ _ ____ _ - * Project ___| | | | _ \| | - * / __| | | | |_) | | - * | (__| |_| | _ <| |___ - * \___|\___/|_| \_\_____| - * - * Copyright (C) 2016 - 2017, Steve Holme, . - * Copyright (C) 2017, Expat development team - * - * All rights reserved. - * Licensed under the MIT license: - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF - * THIRD PARTY RIGHTS. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF - * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH - * THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * Except as contained in this notice, the name of a copyright holder shall - * not be used in advertising or otherwise to promote the sale, use or other - * dealings in this Software without prior written authorization of the - * copyright holder. - * - ***************************************************************************/ - -#if defined(_WIN32) - -#include -#include - - -HMODULE _Expat_LoadLibrary(LPCTSTR filename); - - -#if !defined(LOAD_WITH_ALTERED_SEARCH_PATH) -#define LOAD_WITH_ALTERED_SEARCH_PATH 0x00000008 -#endif - -#if !defined(LOAD_LIBRARY_SEARCH_SYSTEM32) -#define LOAD_LIBRARY_SEARCH_SYSTEM32 0x00000800 -#endif - -/* We use our own typedef here since some headers might lack these */ -typedef HMODULE (APIENTRY *LOADLIBRARYEX_FN)(LPCTSTR, HANDLE, DWORD); - -/* See function definitions in winbase.h */ -#ifdef UNICODE -# ifdef _WIN32_WCE -# define LOADLIBARYEX L"LoadLibraryExW" -# else -# define LOADLIBARYEX "LoadLibraryExW" -# endif -#else -# define LOADLIBARYEX "LoadLibraryExA" -#endif - - -/* - * _Expat_LoadLibrary() - * - * This is used to dynamically load DLLs using the most secure method available - * for the version of Windows that we are running on. - * - * Parameters: - * - * filename [in] - The filename or full path of the DLL to load. If only the - * filename is passed then the DLL will be loaded from the - * Windows system directory. - * - * Returns the handle of the module on success; otherwise NULL. - */ -HMODULE _Expat_LoadLibrary(LPCTSTR filename) -{ - HMODULE hModule = NULL; - LOADLIBRARYEX_FN pLoadLibraryEx = NULL; - - /* Get a handle to kernel32 so we can access it's functions at runtime */ - HMODULE hKernel32 = GetModuleHandle(TEXT("kernel32")); - if(!hKernel32) - return NULL; /* LCOV_EXCL_LINE */ - - /* Attempt to find LoadLibraryEx() which is only available on Windows 2000 - and above */ - pLoadLibraryEx = (LOADLIBRARYEX_FN) GetProcAddress(hKernel32, LOADLIBARYEX); - - /* Detect if there's already a path in the filename and load the library if - there is. Note: Both back slashes and forward slashes have been supported - since the earlier days of DOS at an API level although they are not - supported by command prompt */ - if(_tcspbrk(filename, TEXT("\\/"))) { - /** !checksrc! disable BANNEDFUNC 1 **/ - hModule = pLoadLibraryEx ? - pLoadLibraryEx(filename, NULL, LOAD_WITH_ALTERED_SEARCH_PATH) : - LoadLibrary(filename); - } - /* Detect if KB2533623 is installed, as LOAD_LIBARY_SEARCH_SYSTEM32 is only - supported on Windows Vista, Windows Server 2008, Windows 7 and Windows - Server 2008 R2 with this patch or natively on Windows 8 and above */ - else if(pLoadLibraryEx && GetProcAddress(hKernel32, "AddDllDirectory")) { - /* Load the DLL from the Windows system directory */ - hModule = pLoadLibraryEx(filename, NULL, LOAD_LIBRARY_SEARCH_SYSTEM32); - } - else { - /* Attempt to get the Windows system path */ - UINT systemdirlen = GetSystemDirectory(NULL, 0); - if(systemdirlen) { - /* Allocate space for the full DLL path (Room for the null terminator - is included in systemdirlen) */ - size_t filenamelen = _tcslen(filename); - TCHAR *path = malloc(sizeof(TCHAR) * (systemdirlen + 1 + filenamelen)); - if(path && GetSystemDirectory(path, systemdirlen)) { - /* Calculate the full DLL path */ - _tcscpy(path + _tcslen(path), TEXT("\\")); - _tcscpy(path + _tcslen(path), filename); - - /* Load the DLL from the Windows system directory */ - /** !checksrc! disable BANNEDFUNC 1 **/ - hModule = pLoadLibraryEx ? - pLoadLibraryEx(path, NULL, LOAD_WITH_ALTERED_SEARCH_PATH) : - LoadLibrary(path); - - } - free(path); - } - } - - return hModule; -} - -#else /* defined(_WIN32) */ - -/* ISO C requires a translation unit to contain at least one declaration - [-Wempty-translation-unit] */ -typedef int _TRANSLATION_UNIT_LOAD_LIBRARY_C_NOT_EMTPY; - -#endif /* defined(_WIN32) */ Index: expat/nametab.h ================================================================== --- expat/nametab.h +++ expat/nametab.h @@ -29,154 +29,108 @@ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ static const unsigned namingBitmap[] = { -0x00000000, 0x00000000, 0x00000000, 0x00000000, -0x00000000, 0x00000000, 0x00000000, 0x00000000, -0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, -0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, -0x00000000, 0x04000000, 0x87FFFFFE, 0x07FFFFFE, -0x00000000, 0x00000000, 0xFF7FFFFF, 0xFF7FFFFF, -0xFFFFFFFF, 0x7FF3FFFF, 0xFFFFFDFE, 0x7FFFFFFF, -0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFE00F, 0xFC31FFFF, -0x00FFFFFF, 0x00000000, 0xFFFF0000, 0xFFFFFFFF, -0xFFFFFFFF, 0xF80001FF, 0x00000003, 0x00000000, -0x00000000, 0x00000000, 0x00000000, 0x00000000, -0xFFFFD740, 0xFFFFFFFB, 0x547F7FFF, 0x000FFFFD, -0xFFFFDFFE, 0xFFFFFFFF, 0xDFFEFFFF, 0xFFFFFFFF, -0xFFFF0003, 0xFFFFFFFF, 0xFFFF199F, 0x033FCFFF, -0x00000000, 0xFFFE0000, 0x027FFFFF, 0xFFFFFFFE, -0x0000007F, 0x00000000, 0xFFFF0000, 0x000707FF, -0x00000000, 0x07FFFFFE, 0x000007FE, 0xFFFE0000, -0xFFFFFFFF, 0x7CFFFFFF, 0x002F7FFF, 0x00000060, -0xFFFFFFE0, 0x23FFFFFF, 0xFF000000, 0x00000003, -0xFFF99FE0, 0x03C5FDFF, 0xB0000000, 0x00030003, -0xFFF987E0, 0x036DFDFF, 0x5E000000, 0x001C0000, -0xFFFBAFE0, 0x23EDFDFF, 0x00000000, 0x00000001, -0xFFF99FE0, 0x23CDFDFF, 0xB0000000, 0x00000003, -0xD63DC7E0, 0x03BFC718, 0x00000000, 0x00000000, -0xFFFDDFE0, 0x03EFFDFF, 0x00000000, 0x00000003, -0xFFFDDFE0, 0x03EFFDFF, 0x40000000, 0x00000003, -0xFFFDDFE0, 0x03FFFDFF, 0x00000000, 0x00000003, -0x00000000, 0x00000000, 0x00000000, 0x00000000, -0xFFFFFFFE, 0x000D7FFF, 0x0000003F, 0x00000000, -0xFEF02596, 0x200D6CAE, 0x0000001F, 0x00000000, -0x00000000, 0x00000000, 0xFFFFFEFF, 0x000003FF, -0x00000000, 0x00000000, 0x00000000, 0x00000000, -0x00000000, 0x00000000, 0x00000000, 0x00000000, -0x00000000, 0xFFFFFFFF, 0xFFFF003F, 0x007FFFFF, -0x0007DAED, 0x50000000, 0x82315001, 0x002C62AB, -0x40000000, 0xF580C900, 0x00000007, 0x02010800, -0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, -0x0FFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x03FFFFFF, -0x3F3FFFFF, 0xFFFFFFFF, 0xAAFF3F3F, 0x3FFFFFFF, -0xFFFFFFFF, 0x5FDFFFFF, 0x0FCF1FDC, 0x1FDC1FFF, -0x00000000, 0x00004C40, 0x00000000, 0x00000000, -0x00000007, 0x00000000, 0x00000000, 0x00000000, -0x00000080, 0x000003FE, 0xFFFFFFFE, 0xFFFFFFFF, -0x001FFFFF, 0xFFFFFFFE, 0xFFFFFFFF, 0x07FFFFFF, -0xFFFFFFE0, 0x00001FFF, 0x00000000, 0x00000000, -0x00000000, 0x00000000, 0x00000000, 0x00000000, -0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, -0xFFFFFFFF, 0x0000003F, 0x00000000, 0x00000000, -0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, -0xFFFFFFFF, 0x0000000F, 0x00000000, 0x00000000, -0x00000000, 0x07FF6000, 0x87FFFFFE, 0x07FFFFFE, -0x00000000, 0x00800000, 0xFF7FFFFF, 0xFF7FFFFF, -0x00FFFFFF, 0x00000000, 0xFFFF0000, 0xFFFFFFFF, -0xFFFFFFFF, 0xF80001FF, 0x00030003, 0x00000000, -0xFFFFFFFF, 0xFFFFFFFF, 0x0000003F, 0x00000003, -0xFFFFD7C0, 0xFFFFFFFB, 0x547F7FFF, 0x000FFFFD, -0xFFFFDFFE, 0xFFFFFFFF, 0xDFFEFFFF, 0xFFFFFFFF, -0xFFFF007B, 0xFFFFFFFF, 0xFFFF199F, 0x033FCFFF, -0x00000000, 0xFFFE0000, 0x027FFFFF, 0xFFFFFFFE, -0xFFFE007F, 0xBBFFFFFB, 0xFFFF0016, 0x000707FF, -0x00000000, 0x07FFFFFE, 0x0007FFFF, 0xFFFF03FF, -0xFFFFFFFF, 0x7CFFFFFF, 0xFFEF7FFF, 0x03FF3DFF, -0xFFFFFFEE, 0xF3FFFFFF, 0xFF1E3FFF, 0x0000FFCF, -0xFFF99FEE, 0xD3C5FDFF, 0xB080399F, 0x0003FFCF, -0xFFF987E4, 0xD36DFDFF, 0x5E003987, 0x001FFFC0, -0xFFFBAFEE, 0xF3EDFDFF, 0x00003BBF, 0x0000FFC1, -0xFFF99FEE, 0xF3CDFDFF, 0xB0C0398F, 0x0000FFC3, -0xD63DC7EC, 0xC3BFC718, 0x00803DC7, 0x0000FF80, -0xFFFDDFEE, 0xC3EFFDFF, 0x00603DDF, 0x0000FFC3, -0xFFFDDFEC, 0xC3EFFDFF, 0x40603DDF, 0x0000FFC3, -0xFFFDDFEC, 0xC3FFFDFF, 0x00803DCF, 0x0000FFC3, -0x00000000, 0x00000000, 0x00000000, 0x00000000, -0xFFFFFFFE, 0x07FF7FFF, 0x03FF7FFF, 0x00000000, -0xFEF02596, 0x3BFF6CAE, 0x03FF3F5F, 0x00000000, -0x03000000, 0xC2A003FF, 0xFFFFFEFF, 0xFFFE03FF, -0xFEBF0FDF, 0x02FE3FFF, 0x00000000, 0x00000000, -0x00000000, 0x00000000, 0x00000000, 0x00000000, -0x00000000, 0x00000000, 0x1FFF0000, 0x00000002, -0x000000A0, 0x003EFFFE, 0xFFFFFFFE, 0xFFFFFFFF, -0x661FFFFF, 0xFFFFFFFE, 0xFFFFFFFF, 0x77FFFFFF, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, + 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000, 0x04000000, + 0x87FFFFFE, 0x07FFFFFE, 0x00000000, 0x00000000, 0xFF7FFFFF, 0xFF7FFFFF, + 0xFFFFFFFF, 0x7FF3FFFF, 0xFFFFFDFE, 0x7FFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, + 0xFFFFE00F, 0xFC31FFFF, 0x00FFFFFF, 0x00000000, 0xFFFF0000, 0xFFFFFFFF, + 0xFFFFFFFF, 0xF80001FF, 0x00000003, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0xFFFFD740, 0xFFFFFFFB, 0x547F7FFF, 0x000FFFFD, + 0xFFFFDFFE, 0xFFFFFFFF, 0xDFFEFFFF, 0xFFFFFFFF, 0xFFFF0003, 0xFFFFFFFF, + 0xFFFF199F, 0x033FCFFF, 0x00000000, 0xFFFE0000, 0x027FFFFF, 0xFFFFFFFE, + 0x0000007F, 0x00000000, 0xFFFF0000, 0x000707FF, 0x00000000, 0x07FFFFFE, + 0x000007FE, 0xFFFE0000, 0xFFFFFFFF, 0x7CFFFFFF, 0x002F7FFF, 0x00000060, + 0xFFFFFFE0, 0x23FFFFFF, 0xFF000000, 0x00000003, 0xFFF99FE0, 0x03C5FDFF, + 0xB0000000, 0x00030003, 0xFFF987E0, 0x036DFDFF, 0x5E000000, 0x001C0000, + 0xFFFBAFE0, 0x23EDFDFF, 0x00000000, 0x00000001, 0xFFF99FE0, 0x23CDFDFF, + 0xB0000000, 0x00000003, 0xD63DC7E0, 0x03BFC718, 0x00000000, 0x00000000, + 0xFFFDDFE0, 0x03EFFDFF, 0x00000000, 0x00000003, 0xFFFDDFE0, 0x03EFFDFF, + 0x40000000, 0x00000003, 0xFFFDDFE0, 0x03FFFDFF, 0x00000000, 0x00000003, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0xFFFFFFFE, 0x000D7FFF, + 0x0000003F, 0x00000000, 0xFEF02596, 0x200D6CAE, 0x0000001F, 0x00000000, + 0x00000000, 0x00000000, 0xFFFFFEFF, 0x000003FF, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0xFFFFFFFF, 0xFFFF003F, 0x007FFFFF, 0x0007DAED, 0x50000000, + 0x82315001, 0x002C62AB, 0x40000000, 0xF580C900, 0x00000007, 0x02010800, + 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x0FFFFFFF, 0xFFFFFFFF, + 0xFFFFFFFF, 0x03FFFFFF, 0x3F3FFFFF, 0xFFFFFFFF, 0xAAFF3F3F, 0x3FFFFFFF, + 0xFFFFFFFF, 0x5FDFFFFF, 0x0FCF1FDC, 0x1FDC1FFF, 0x00000000, 0x00004C40, + 0x00000000, 0x00000000, 0x00000007, 0x00000000, 0x00000000, 0x00000000, + 0x00000080, 0x000003FE, 0xFFFFFFFE, 0xFFFFFFFF, 0x001FFFFF, 0xFFFFFFFE, + 0xFFFFFFFF, 0x07FFFFFF, 0xFFFFFFE0, 0x00001FFF, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0xFFFFFFFF, 0xFFFFFFFF, + 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x0000003F, 0x00000000, 0x00000000, + 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x0000000F, + 0x00000000, 0x00000000, 0x00000000, 0x07FF6000, 0x87FFFFFE, 0x07FFFFFE, + 0x00000000, 0x00800000, 0xFF7FFFFF, 0xFF7FFFFF, 0x00FFFFFF, 0x00000000, + 0xFFFF0000, 0xFFFFFFFF, 0xFFFFFFFF, 0xF80001FF, 0x00030003, 0x00000000, + 0xFFFFFFFF, 0xFFFFFFFF, 0x0000003F, 0x00000003, 0xFFFFD7C0, 0xFFFFFFFB, + 0x547F7FFF, 0x000FFFFD, 0xFFFFDFFE, 0xFFFFFFFF, 0xDFFEFFFF, 0xFFFFFFFF, + 0xFFFF007B, 0xFFFFFFFF, 0xFFFF199F, 0x033FCFFF, 0x00000000, 0xFFFE0000, + 0x027FFFFF, 0xFFFFFFFE, 0xFFFE007F, 0xBBFFFFFB, 0xFFFF0016, 0x000707FF, + 0x00000000, 0x07FFFFFE, 0x0007FFFF, 0xFFFF03FF, 0xFFFFFFFF, 0x7CFFFFFF, + 0xFFEF7FFF, 0x03FF3DFF, 0xFFFFFFEE, 0xF3FFFFFF, 0xFF1E3FFF, 0x0000FFCF, + 0xFFF99FEE, 0xD3C5FDFF, 0xB080399F, 0x0003FFCF, 0xFFF987E4, 0xD36DFDFF, + 0x5E003987, 0x001FFFC0, 0xFFFBAFEE, 0xF3EDFDFF, 0x00003BBF, 0x0000FFC1, + 0xFFF99FEE, 0xF3CDFDFF, 0xB0C0398F, 0x0000FFC3, 0xD63DC7EC, 0xC3BFC718, + 0x00803DC7, 0x0000FF80, 0xFFFDDFEE, 0xC3EFFDFF, 0x00603DDF, 0x0000FFC3, + 0xFFFDDFEC, 0xC3EFFDFF, 0x40603DDF, 0x0000FFC3, 0xFFFDDFEC, 0xC3FFFDFF, + 0x00803DCF, 0x0000FFC3, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0xFFFFFFFE, 0x07FF7FFF, 0x03FF7FFF, 0x00000000, 0xFEF02596, 0x3BFF6CAE, + 0x03FF3F5F, 0x00000000, 0x03000000, 0xC2A003FF, 0xFFFFFEFF, 0xFFFE03FF, + 0xFEBF0FDF, 0x02FE3FFF, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x1FFF0000, 0x00000002, + 0x000000A0, 0x003EFFFE, 0xFFFFFFFE, 0xFFFFFFFF, 0x661FFFFF, 0xFFFFFFFE, + 0xFFFFFFFF, 0x77FFFFFF, }; static const unsigned char nmstrtPages[] = { -0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x00, -0x00, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, -0x10, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x13, -0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x15, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, -0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, -0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, -0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, -0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, -0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, -0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, -0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, -0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, -0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, -0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x17, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, -0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, -0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, -0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, -0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, -0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x18, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x00, 0x00, 0x09, 0x0A, 0x0B, + 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x13, 0x00, 0x14, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x15, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x17, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x18, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, }; static const unsigned char namePages[] = { -0x19, 0x03, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x00, -0x00, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, -0x10, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x13, -0x26, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x27, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, -0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, -0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, -0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, -0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, -0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, -0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, -0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, -0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, -0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, -0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x17, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, -0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, -0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, -0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, -0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, -0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x18, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x19, 0x03, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x00, 0x00, 0x1F, 0x20, 0x21, + 0x22, 0x23, 0x24, 0x25, 0x10, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x13, 0x26, 0x14, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x27, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x17, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x18, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, }; Index: expat/siphash.h ================================================================== --- expat/siphash.h +++ expat/siphash.h @@ -9,10 +9,14 @@ * 1. https://www.131002.net/siphash/siphash24.c * 2. https://www.131002.net/siphash/ * -------------------------------------------------------------------------- * HISTORY: * + * 2019-08-03 (Sebastian Pipping) + * - Mark part of sip24_valid as to be excluded from clang-format + * - Re-format code using clang-format 9 + * * 2018-07-08 (Anton Maklakov) * - Add "fall through" markers for GCC's -Wimplicit-fallthrough * * 2017-11-03 (Sebastian Pipping) * - Hide sip_tobin and sip_binof unless SIPHASH_TOBIN macro is defined @@ -92,189 +96,189 @@ #define SIPHASH_H #include /* size_t */ #if defined(_WIN32) && defined(_MSC_VER) && (_MSC_VER < 1600) - /* For vs2003/7.1 up to vs2008/9.0; _MSC_VER 1600 is vs2010/10.0 */ - typedef unsigned __int8 uint8_t; - typedef unsigned __int32 uint32_t; - typedef unsigned __int64 uint64_t; +/* For vs2003/7.1 up to vs2008/9.0; _MSC_VER 1600 is vs2010/10.0 */ +typedef unsigned __int8 uint8_t; +typedef unsigned __int32 uint32_t; +typedef unsigned __int64 uint64_t; #else - #include /* uint64_t uint32_t uint8_t */ +# include /* uint64_t uint32_t uint8_t */ #endif - /* * Workaround to not require a C++11 compiler for using ULL suffix * if this code is included and compiled as C++; related GCC warning is: * warning: use of C++11 long long integer constant [-Wlong-long] */ -#define _SIP_ULL(high, low) (((uint64_t)high << 32) | low) - - -#define SIP_ROTL(x, b) (uint64_t)(((x) << (b)) | ( (x) >> (64 - (b)))) - -#define SIP_U32TO8_LE(p, v) \ - (p)[0] = (uint8_t)((v) >> 0); (p)[1] = (uint8_t)((v) >> 8); \ - (p)[2] = (uint8_t)((v) >> 16); (p)[3] = (uint8_t)((v) >> 24); - -#define SIP_U64TO8_LE(p, v) \ - SIP_U32TO8_LE((p) + 0, (uint32_t)((v) >> 0)); \ - SIP_U32TO8_LE((p) + 4, (uint32_t)((v) >> 32)); - -#define SIP_U8TO64_LE(p) \ - (((uint64_t)((p)[0]) << 0) | \ - ((uint64_t)((p)[1]) << 8) | \ - ((uint64_t)((p)[2]) << 16) | \ - ((uint64_t)((p)[3]) << 24) | \ - ((uint64_t)((p)[4]) << 32) | \ - ((uint64_t)((p)[5]) << 40) | \ - ((uint64_t)((p)[6]) << 48) | \ - ((uint64_t)((p)[7]) << 56)) - - -#define SIPHASH_INITIALIZER { 0, 0, 0, 0, { 0 }, 0, 0 } +#define _SIP_ULL(high, low) (((uint64_t)high << 32) | low) + +#define SIP_ROTL(x, b) (uint64_t)(((x) << (b)) | ((x) >> (64 - (b)))) + +#define SIP_U32TO8_LE(p, v) \ + (p)[0] = (uint8_t)((v) >> 0); \ + (p)[1] = (uint8_t)((v) >> 8); \ + (p)[2] = (uint8_t)((v) >> 16); \ + (p)[3] = (uint8_t)((v) >> 24); + +#define SIP_U64TO8_LE(p, v) \ + SIP_U32TO8_LE((p) + 0, (uint32_t)((v) >> 0)); \ + SIP_U32TO8_LE((p) + 4, (uint32_t)((v) >> 32)); + +#define SIP_U8TO64_LE(p) \ + (((uint64_t)((p)[0]) << 0) | ((uint64_t)((p)[1]) << 8) \ + | ((uint64_t)((p)[2]) << 16) | ((uint64_t)((p)[3]) << 24) \ + | ((uint64_t)((p)[4]) << 32) | ((uint64_t)((p)[5]) << 40) \ + | ((uint64_t)((p)[6]) << 48) | ((uint64_t)((p)[7]) << 56)) + +#define SIPHASH_INITIALIZER \ + { 0, 0, 0, 0, {0}, 0, 0 } struct siphash { - uint64_t v0, v1, v2, v3; + uint64_t v0, v1, v2, v3; - unsigned char buf[8], *p; - uint64_t c; + unsigned char buf[8], *p; + uint64_t c; }; /* struct siphash */ - #define SIP_KEYLEN 16 struct sipkey { - uint64_t k[2]; + uint64_t k[2]; }; /* struct sipkey */ -#define sip_keyof(k) sip_tokey(&(struct sipkey){ { 0 } }, (k)) - -static struct sipkey *sip_tokey(struct sipkey *key, const void *src) { - key->k[0] = SIP_U8TO64_LE((const unsigned char *)src); - key->k[1] = SIP_U8TO64_LE((const unsigned char *)src + 8); - return key; -} /* sip_tokey() */ - +#define sip_keyof(k) sip_tokey(&(struct sipkey){{0}}, (k)) + +static struct sipkey * +sip_tokey(struct sipkey *key, const void *src) { + key->k[0] = SIP_U8TO64_LE((const unsigned char *)src); + key->k[1] = SIP_U8TO64_LE((const unsigned char *)src + 8); + return key; +} /* sip_tokey() */ #ifdef SIPHASH_TOBIN -#define sip_binof(v) sip_tobin((unsigned char[8]){ 0 }, (v)) +# define sip_binof(v) sip_tobin((unsigned char[8]){0}, (v)) -static void *sip_tobin(void *dst, uint64_t u64) { - SIP_U64TO8_LE((unsigned char *)dst, u64); - return dst; +static void * +sip_tobin(void *dst, uint64_t u64) { + SIP_U64TO8_LE((unsigned char *)dst, u64); + return dst; } /* sip_tobin() */ -#endif /* SIPHASH_TOBIN */ - - -static void sip_round(struct siphash *H, const int rounds) { - int i; - - for (i = 0; i < rounds; i++) { - H->v0 += H->v1; - H->v1 = SIP_ROTL(H->v1, 13); - H->v1 ^= H->v0; - H->v0 = SIP_ROTL(H->v0, 32); - - H->v2 += H->v3; - H->v3 = SIP_ROTL(H->v3, 16); - H->v3 ^= H->v2; - - H->v0 += H->v3; - H->v3 = SIP_ROTL(H->v3, 21); - H->v3 ^= H->v0; - - H->v2 += H->v1; - H->v1 = SIP_ROTL(H->v1, 17); - H->v1 ^= H->v2; - H->v2 = SIP_ROTL(H->v2, 32); - } +#endif /* SIPHASH_TOBIN */ + +static void +sip_round(struct siphash *H, const int rounds) { + int i; + + for (i = 0; i < rounds; i++) { + H->v0 += H->v1; + H->v1 = SIP_ROTL(H->v1, 13); + H->v1 ^= H->v0; + H->v0 = SIP_ROTL(H->v0, 32); + + H->v2 += H->v3; + H->v3 = SIP_ROTL(H->v3, 16); + H->v3 ^= H->v2; + + H->v0 += H->v3; + H->v3 = SIP_ROTL(H->v3, 21); + H->v3 ^= H->v0; + + H->v2 += H->v1; + H->v1 = SIP_ROTL(H->v1, 17); + H->v1 ^= H->v2; + H->v2 = SIP_ROTL(H->v2, 32); + } } /* sip_round() */ - -static struct siphash *sip24_init(struct siphash *H, - const struct sipkey *key) { - H->v0 = _SIP_ULL(0x736f6d65U, 0x70736575U) ^ key->k[0]; - H->v1 = _SIP_ULL(0x646f7261U, 0x6e646f6dU) ^ key->k[1]; - H->v2 = _SIP_ULL(0x6c796765U, 0x6e657261U) ^ key->k[0]; - H->v3 = _SIP_ULL(0x74656462U, 0x79746573U) ^ key->k[1]; - - H->p = H->buf; - H->c = 0; - - return H; +static struct siphash * +sip24_init(struct siphash *H, const struct sipkey *key) { + H->v0 = _SIP_ULL(0x736f6d65U, 0x70736575U) ^ key->k[0]; + H->v1 = _SIP_ULL(0x646f7261U, 0x6e646f6dU) ^ key->k[1]; + H->v2 = _SIP_ULL(0x6c796765U, 0x6e657261U) ^ key->k[0]; + H->v3 = _SIP_ULL(0x74656462U, 0x79746573U) ^ key->k[1]; + + H->p = H->buf; + H->c = 0; + + return H; } /* sip24_init() */ - -#define sip_endof(a) (&(a)[sizeof (a) / sizeof *(a)]) - -static struct siphash *sip24_update(struct siphash *H, const void *src, - size_t len) { - const unsigned char *p = (const unsigned char *)src, *pe = p + len; - uint64_t m; - - do { - while (p < pe && H->p < sip_endof(H->buf)) - *H->p++ = *p++; - - if (H->p < sip_endof(H->buf)) - break; - - m = SIP_U8TO64_LE(H->buf); - H->v3 ^= m; - sip_round(H, 2); - H->v0 ^= m; - - H->p = H->buf; - H->c += 8; - } while (p < pe); - - return H; +#define sip_endof(a) (&(a)[sizeof(a) / sizeof *(a)]) + +static struct siphash * +sip24_update(struct siphash *H, const void *src, size_t len) { + const unsigned char *p = (const unsigned char *)src, *pe = p + len; + uint64_t m; + + do { + while (p < pe && H->p < sip_endof(H->buf)) + *H->p++ = *p++; + + if (H->p < sip_endof(H->buf)) + break; + + m = SIP_U8TO64_LE(H->buf); + H->v3 ^= m; + sip_round(H, 2); + H->v0 ^= m; + + H->p = H->buf; + H->c += 8; + } while (p < pe); + + return H; } /* sip24_update() */ - -static uint64_t sip24_final(struct siphash *H) { - const char left = (char)(H->p - H->buf); - uint64_t b = (H->c + left) << 56; - - switch (left) { - case 7: b |= (uint64_t)H->buf[6] << 48; - /* fall through */ - case 6: b |= (uint64_t)H->buf[5] << 40; - /* fall through */ - case 5: b |= (uint64_t)H->buf[4] << 32; - /* fall through */ - case 4: b |= (uint64_t)H->buf[3] << 24; - /* fall through */ - case 3: b |= (uint64_t)H->buf[2] << 16; - /* fall through */ - case 2: b |= (uint64_t)H->buf[1] << 8; - /* fall through */ - case 1: b |= (uint64_t)H->buf[0] << 0; - /* fall through */ - case 0: break; - } - - H->v3 ^= b; - sip_round(H, 2); - H->v0 ^= b; - H->v2 ^= 0xff; - sip_round(H, 4); - - return H->v0 ^ H->v1 ^ H->v2 ^ H->v3; +static uint64_t +sip24_final(struct siphash *H) { + const char left = (char)(H->p - H->buf); + uint64_t b = (H->c + left) << 56; + + switch (left) { + case 7: + b |= (uint64_t)H->buf[6] << 48; + /* fall through */ + case 6: + b |= (uint64_t)H->buf[5] << 40; + /* fall through */ + case 5: + b |= (uint64_t)H->buf[4] << 32; + /* fall through */ + case 4: + b |= (uint64_t)H->buf[3] << 24; + /* fall through */ + case 3: + b |= (uint64_t)H->buf[2] << 16; + /* fall through */ + case 2: + b |= (uint64_t)H->buf[1] << 8; + /* fall through */ + case 1: + b |= (uint64_t)H->buf[0] << 0; + /* fall through */ + case 0: + break; + } + + H->v3 ^= b; + sip_round(H, 2); + H->v0 ^= b; + H->v2 ^= 0xff; + sip_round(H, 4); + + return H->v0 ^ H->v1 ^ H->v2 ^ H->v3; } /* sip24_final() */ - -static uint64_t siphash24(const void *src, size_t len, - const struct sipkey *key) { - struct siphash state = SIPHASH_INITIALIZER; - return sip24_final(sip24_update(sip24_init(&state, key), src, len)); +static uint64_t +siphash24(const void *src, size_t len, const struct sipkey *key) { + struct siphash state = SIPHASH_INITIALIZER; + return sip24_final(sip24_update(sip24_init(&state, key), src, len)); } /* siphash24() */ - /* * SipHash-2-4 output with * k = 00 01 02 ... * and @@ -283,109 +287,112 @@ * in = 00 01 (2 bytes) * in = 00 01 02 (3 bytes) * ... * in = 00 01 02 ... 3e (63 bytes) */ -static int sip24_valid(void) { - static const unsigned char vectors[64][8] = { - { 0x31, 0x0e, 0x0e, 0xdd, 0x47, 0xdb, 0x6f, 0x72, }, - { 0xfd, 0x67, 0xdc, 0x93, 0xc5, 0x39, 0xf8, 0x74, }, - { 0x5a, 0x4f, 0xa9, 0xd9, 0x09, 0x80, 0x6c, 0x0d, }, - { 0x2d, 0x7e, 0xfb, 0xd7, 0x96, 0x66, 0x67, 0x85, }, - { 0xb7, 0x87, 0x71, 0x27, 0xe0, 0x94, 0x27, 0xcf, }, - { 0x8d, 0xa6, 0x99, 0xcd, 0x64, 0x55, 0x76, 0x18, }, - { 0xce, 0xe3, 0xfe, 0x58, 0x6e, 0x46, 0xc9, 0xcb, }, - { 0x37, 0xd1, 0x01, 0x8b, 0xf5, 0x00, 0x02, 0xab, }, - { 0x62, 0x24, 0x93, 0x9a, 0x79, 0xf5, 0xf5, 0x93, }, - { 0xb0, 0xe4, 0xa9, 0x0b, 0xdf, 0x82, 0x00, 0x9e, }, - { 0xf3, 0xb9, 0xdd, 0x94, 0xc5, 0xbb, 0x5d, 0x7a, }, - { 0xa7, 0xad, 0x6b, 0x22, 0x46, 0x2f, 0xb3, 0xf4, }, - { 0xfb, 0xe5, 0x0e, 0x86, 0xbc, 0x8f, 0x1e, 0x75, }, - { 0x90, 0x3d, 0x84, 0xc0, 0x27, 0x56, 0xea, 0x14, }, - { 0xee, 0xf2, 0x7a, 0x8e, 0x90, 0xca, 0x23, 0xf7, }, - { 0xe5, 0x45, 0xbe, 0x49, 0x61, 0xca, 0x29, 0xa1, }, - { 0xdb, 0x9b, 0xc2, 0x57, 0x7f, 0xcc, 0x2a, 0x3f, }, - { 0x94, 0x47, 0xbe, 0x2c, 0xf5, 0xe9, 0x9a, 0x69, }, - { 0x9c, 0xd3, 0x8d, 0x96, 0xf0, 0xb3, 0xc1, 0x4b, }, - { 0xbd, 0x61, 0x79, 0xa7, 0x1d, 0xc9, 0x6d, 0xbb, }, - { 0x98, 0xee, 0xa2, 0x1a, 0xf2, 0x5c, 0xd6, 0xbe, }, - { 0xc7, 0x67, 0x3b, 0x2e, 0xb0, 0xcb, 0xf2, 0xd0, }, - { 0x88, 0x3e, 0xa3, 0xe3, 0x95, 0x67, 0x53, 0x93, }, - { 0xc8, 0xce, 0x5c, 0xcd, 0x8c, 0x03, 0x0c, 0xa8, }, - { 0x94, 0xaf, 0x49, 0xf6, 0xc6, 0x50, 0xad, 0xb8, }, - { 0xea, 0xb8, 0x85, 0x8a, 0xde, 0x92, 0xe1, 0xbc, }, - { 0xf3, 0x15, 0xbb, 0x5b, 0xb8, 0x35, 0xd8, 0x17, }, - { 0xad, 0xcf, 0x6b, 0x07, 0x63, 0x61, 0x2e, 0x2f, }, - { 0xa5, 0xc9, 0x1d, 0xa7, 0xac, 0xaa, 0x4d, 0xde, }, - { 0x71, 0x65, 0x95, 0x87, 0x66, 0x50, 0xa2, 0xa6, }, - { 0x28, 0xef, 0x49, 0x5c, 0x53, 0xa3, 0x87, 0xad, }, - { 0x42, 0xc3, 0x41, 0xd8, 0xfa, 0x92, 0xd8, 0x32, }, - { 0xce, 0x7c, 0xf2, 0x72, 0x2f, 0x51, 0x27, 0x71, }, - { 0xe3, 0x78, 0x59, 0xf9, 0x46, 0x23, 0xf3, 0xa7, }, - { 0x38, 0x12, 0x05, 0xbb, 0x1a, 0xb0, 0xe0, 0x12, }, - { 0xae, 0x97, 0xa1, 0x0f, 0xd4, 0x34, 0xe0, 0x15, }, - { 0xb4, 0xa3, 0x15, 0x08, 0xbe, 0xff, 0x4d, 0x31, }, - { 0x81, 0x39, 0x62, 0x29, 0xf0, 0x90, 0x79, 0x02, }, - { 0x4d, 0x0c, 0xf4, 0x9e, 0xe5, 0xd4, 0xdc, 0xca, }, - { 0x5c, 0x73, 0x33, 0x6a, 0x76, 0xd8, 0xbf, 0x9a, }, - { 0xd0, 0xa7, 0x04, 0x53, 0x6b, 0xa9, 0x3e, 0x0e, }, - { 0x92, 0x59, 0x58, 0xfc, 0xd6, 0x42, 0x0c, 0xad, }, - { 0xa9, 0x15, 0xc2, 0x9b, 0xc8, 0x06, 0x73, 0x18, }, - { 0x95, 0x2b, 0x79, 0xf3, 0xbc, 0x0a, 0xa6, 0xd4, }, - { 0xf2, 0x1d, 0xf2, 0xe4, 0x1d, 0x45, 0x35, 0xf9, }, - { 0x87, 0x57, 0x75, 0x19, 0x04, 0x8f, 0x53, 0xa9, }, - { 0x10, 0xa5, 0x6c, 0xf5, 0xdf, 0xcd, 0x9a, 0xdb, }, - { 0xeb, 0x75, 0x09, 0x5c, 0xcd, 0x98, 0x6c, 0xd0, }, - { 0x51, 0xa9, 0xcb, 0x9e, 0xcb, 0xa3, 0x12, 0xe6, }, - { 0x96, 0xaf, 0xad, 0xfc, 0x2c, 0xe6, 0x66, 0xc7, }, - { 0x72, 0xfe, 0x52, 0x97, 0x5a, 0x43, 0x64, 0xee, }, - { 0x5a, 0x16, 0x45, 0xb2, 0x76, 0xd5, 0x92, 0xa1, }, - { 0xb2, 0x74, 0xcb, 0x8e, 0xbf, 0x87, 0x87, 0x0a, }, - { 0x6f, 0x9b, 0xb4, 0x20, 0x3d, 0xe7, 0xb3, 0x81, }, - { 0xea, 0xec, 0xb2, 0xa3, 0x0b, 0x22, 0xa8, 0x7f, }, - { 0x99, 0x24, 0xa4, 0x3c, 0xc1, 0x31, 0x57, 0x24, }, - { 0xbd, 0x83, 0x8d, 0x3a, 0xaf, 0xbf, 0x8d, 0xb7, }, - { 0x0b, 0x1a, 0x2a, 0x32, 0x65, 0xd5, 0x1a, 0xea, }, - { 0x13, 0x50, 0x79, 0xa3, 0x23, 0x1c, 0xe6, 0x60, }, - { 0x93, 0x2b, 0x28, 0x46, 0xe4, 0xd7, 0x06, 0x66, }, - { 0xe1, 0x91, 0x5f, 0x5c, 0xb1, 0xec, 0xa4, 0x6c, }, - { 0xf3, 0x25, 0x96, 0x5c, 0xa1, 0x6d, 0x62, 0x9f, }, - { 0x57, 0x5f, 0xf2, 0x8e, 0x60, 0x38, 0x1b, 0xe5, }, - { 0x72, 0x45, 0x06, 0xeb, 0x4c, 0x32, 0x8a, 0x95, } - }; - unsigned char in[64]; - struct sipkey k; - size_t i; - - sip_tokey(&k, "\000\001\002\003\004\005\006\007\010\011" - "\012\013\014\015\016\017"); - - for (i = 0; i < sizeof in; ++i) { - in[i] = (unsigned char)i; - - if (siphash24(in, i, &k) != SIP_U8TO64_LE(vectors[i])) - return 0; - } - - return 1; -} /* sip24_valid() */ - +static int +sip24_valid(void) { + /* clang-format off */ + static const unsigned char vectors[64][8] = { + { 0x31, 0x0e, 0x0e, 0xdd, 0x47, 0xdb, 0x6f, 0x72, }, + { 0xfd, 0x67, 0xdc, 0x93, 0xc5, 0x39, 0xf8, 0x74, }, + { 0x5a, 0x4f, 0xa9, 0xd9, 0x09, 0x80, 0x6c, 0x0d, }, + { 0x2d, 0x7e, 0xfb, 0xd7, 0x96, 0x66, 0x67, 0x85, }, + { 0xb7, 0x87, 0x71, 0x27, 0xe0, 0x94, 0x27, 0xcf, }, + { 0x8d, 0xa6, 0x99, 0xcd, 0x64, 0x55, 0x76, 0x18, }, + { 0xce, 0xe3, 0xfe, 0x58, 0x6e, 0x46, 0xc9, 0xcb, }, + { 0x37, 0xd1, 0x01, 0x8b, 0xf5, 0x00, 0x02, 0xab, }, + { 0x62, 0x24, 0x93, 0x9a, 0x79, 0xf5, 0xf5, 0x93, }, + { 0xb0, 0xe4, 0xa9, 0x0b, 0xdf, 0x82, 0x00, 0x9e, }, + { 0xf3, 0xb9, 0xdd, 0x94, 0xc5, 0xbb, 0x5d, 0x7a, }, + { 0xa7, 0xad, 0x6b, 0x22, 0x46, 0x2f, 0xb3, 0xf4, }, + { 0xfb, 0xe5, 0x0e, 0x86, 0xbc, 0x8f, 0x1e, 0x75, }, + { 0x90, 0x3d, 0x84, 0xc0, 0x27, 0x56, 0xea, 0x14, }, + { 0xee, 0xf2, 0x7a, 0x8e, 0x90, 0xca, 0x23, 0xf7, }, + { 0xe5, 0x45, 0xbe, 0x49, 0x61, 0xca, 0x29, 0xa1, }, + { 0xdb, 0x9b, 0xc2, 0x57, 0x7f, 0xcc, 0x2a, 0x3f, }, + { 0x94, 0x47, 0xbe, 0x2c, 0xf5, 0xe9, 0x9a, 0x69, }, + { 0x9c, 0xd3, 0x8d, 0x96, 0xf0, 0xb3, 0xc1, 0x4b, }, + { 0xbd, 0x61, 0x79, 0xa7, 0x1d, 0xc9, 0x6d, 0xbb, }, + { 0x98, 0xee, 0xa2, 0x1a, 0xf2, 0x5c, 0xd6, 0xbe, }, + { 0xc7, 0x67, 0x3b, 0x2e, 0xb0, 0xcb, 0xf2, 0xd0, }, + { 0x88, 0x3e, 0xa3, 0xe3, 0x95, 0x67, 0x53, 0x93, }, + { 0xc8, 0xce, 0x5c, 0xcd, 0x8c, 0x03, 0x0c, 0xa8, }, + { 0x94, 0xaf, 0x49, 0xf6, 0xc6, 0x50, 0xad, 0xb8, }, + { 0xea, 0xb8, 0x85, 0x8a, 0xde, 0x92, 0xe1, 0xbc, }, + { 0xf3, 0x15, 0xbb, 0x5b, 0xb8, 0x35, 0xd8, 0x17, }, + { 0xad, 0xcf, 0x6b, 0x07, 0x63, 0x61, 0x2e, 0x2f, }, + { 0xa5, 0xc9, 0x1d, 0xa7, 0xac, 0xaa, 0x4d, 0xde, }, + { 0x71, 0x65, 0x95, 0x87, 0x66, 0x50, 0xa2, 0xa6, }, + { 0x28, 0xef, 0x49, 0x5c, 0x53, 0xa3, 0x87, 0xad, }, + { 0x42, 0xc3, 0x41, 0xd8, 0xfa, 0x92, 0xd8, 0x32, }, + { 0xce, 0x7c, 0xf2, 0x72, 0x2f, 0x51, 0x27, 0x71, }, + { 0xe3, 0x78, 0x59, 0xf9, 0x46, 0x23, 0xf3, 0xa7, }, + { 0x38, 0x12, 0x05, 0xbb, 0x1a, 0xb0, 0xe0, 0x12, }, + { 0xae, 0x97, 0xa1, 0x0f, 0xd4, 0x34, 0xe0, 0x15, }, + { 0xb4, 0xa3, 0x15, 0x08, 0xbe, 0xff, 0x4d, 0x31, }, + { 0x81, 0x39, 0x62, 0x29, 0xf0, 0x90, 0x79, 0x02, }, + { 0x4d, 0x0c, 0xf4, 0x9e, 0xe5, 0xd4, 0xdc, 0xca, }, + { 0x5c, 0x73, 0x33, 0x6a, 0x76, 0xd8, 0xbf, 0x9a, }, + { 0xd0, 0xa7, 0x04, 0x53, 0x6b, 0xa9, 0x3e, 0x0e, }, + { 0x92, 0x59, 0x58, 0xfc, 0xd6, 0x42, 0x0c, 0xad, }, + { 0xa9, 0x15, 0xc2, 0x9b, 0xc8, 0x06, 0x73, 0x18, }, + { 0x95, 0x2b, 0x79, 0xf3, 0xbc, 0x0a, 0xa6, 0xd4, }, + { 0xf2, 0x1d, 0xf2, 0xe4, 0x1d, 0x45, 0x35, 0xf9, }, + { 0x87, 0x57, 0x75, 0x19, 0x04, 0x8f, 0x53, 0xa9, }, + { 0x10, 0xa5, 0x6c, 0xf5, 0xdf, 0xcd, 0x9a, 0xdb, }, + { 0xeb, 0x75, 0x09, 0x5c, 0xcd, 0x98, 0x6c, 0xd0, }, + { 0x51, 0xa9, 0xcb, 0x9e, 0xcb, 0xa3, 0x12, 0xe6, }, + { 0x96, 0xaf, 0xad, 0xfc, 0x2c, 0xe6, 0x66, 0xc7, }, + { 0x72, 0xfe, 0x52, 0x97, 0x5a, 0x43, 0x64, 0xee, }, + { 0x5a, 0x16, 0x45, 0xb2, 0x76, 0xd5, 0x92, 0xa1, }, + { 0xb2, 0x74, 0xcb, 0x8e, 0xbf, 0x87, 0x87, 0x0a, }, + { 0x6f, 0x9b, 0xb4, 0x20, 0x3d, 0xe7, 0xb3, 0x81, }, + { 0xea, 0xec, 0xb2, 0xa3, 0x0b, 0x22, 0xa8, 0x7f, }, + { 0x99, 0x24, 0xa4, 0x3c, 0xc1, 0x31, 0x57, 0x24, }, + { 0xbd, 0x83, 0x8d, 0x3a, 0xaf, 0xbf, 0x8d, 0xb7, }, + { 0x0b, 0x1a, 0x2a, 0x32, 0x65, 0xd5, 0x1a, 0xea, }, + { 0x13, 0x50, 0x79, 0xa3, 0x23, 0x1c, 0xe6, 0x60, }, + { 0x93, 0x2b, 0x28, 0x46, 0xe4, 0xd7, 0x06, 0x66, }, + { 0xe1, 0x91, 0x5f, 0x5c, 0xb1, 0xec, 0xa4, 0x6c, }, + { 0xf3, 0x25, 0x96, 0x5c, 0xa1, 0x6d, 0x62, 0x9f, }, + { 0x57, 0x5f, 0xf2, 0x8e, 0x60, 0x38, 0x1b, 0xe5, }, + { 0x72, 0x45, 0x06, 0xeb, 0x4c, 0x32, 0x8a, 0x95, } + }; + /* clang-format on */ + + unsigned char in[64]; + struct sipkey k; + size_t i; + + sip_tokey(&k, "\000\001\002\003\004\005\006\007\010\011" + "\012\013\014\015\016\017"); + + for (i = 0; i < sizeof in; ++i) { + in[i] = (unsigned char)i; + + if (siphash24(in, i, &k) != SIP_U8TO64_LE(vectors[i])) + return 0; + } + + return 1; +} /* sip24_valid() */ #ifdef SIPHASH_MAIN -#include - -int main(void) { - const int ok = sip24_valid(); - - if (ok) - puts("OK"); - else - puts("FAIL"); - - return !ok; +# include + +int +main(void) { + const int ok = sip24_valid(); + + if (ok) + puts("OK"); + else + puts("FAIL"); + + return ! ok; } /* main() */ #endif /* SIPHASH_MAIN */ - #endif /* SIPHASH_H */ Index: expat/utf8tab.h ================================================================== --- expat/utf8tab.h +++ expat/utf8tab.h @@ -29,36 +29,36 @@ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* 0x80 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL, -/* 0x84 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL, -/* 0x88 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL, -/* 0x8C */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL, -/* 0x90 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL, -/* 0x94 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL, -/* 0x98 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL, -/* 0x9C */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL, -/* 0xA0 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL, -/* 0xA4 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL, -/* 0xA8 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL, -/* 0xAC */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL, -/* 0xB0 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL, -/* 0xB4 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL, -/* 0xB8 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL, -/* 0xBC */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL, -/* 0xC0 */ BT_LEAD2, BT_LEAD2, BT_LEAD2, BT_LEAD2, -/* 0xC4 */ BT_LEAD2, BT_LEAD2, BT_LEAD2, BT_LEAD2, -/* 0xC8 */ BT_LEAD2, BT_LEAD2, BT_LEAD2, BT_LEAD2, -/* 0xCC */ BT_LEAD2, BT_LEAD2, BT_LEAD2, BT_LEAD2, -/* 0xD0 */ BT_LEAD2, BT_LEAD2, BT_LEAD2, BT_LEAD2, -/* 0xD4 */ BT_LEAD2, BT_LEAD2, BT_LEAD2, BT_LEAD2, -/* 0xD8 */ BT_LEAD2, BT_LEAD2, BT_LEAD2, BT_LEAD2, -/* 0xDC */ BT_LEAD2, BT_LEAD2, BT_LEAD2, BT_LEAD2, -/* 0xE0 */ BT_LEAD3, BT_LEAD3, BT_LEAD3, BT_LEAD3, -/* 0xE4 */ BT_LEAD3, BT_LEAD3, BT_LEAD3, BT_LEAD3, -/* 0xE8 */ BT_LEAD3, BT_LEAD3, BT_LEAD3, BT_LEAD3, -/* 0xEC */ BT_LEAD3, BT_LEAD3, BT_LEAD3, BT_LEAD3, -/* 0xF0 */ BT_LEAD4, BT_LEAD4, BT_LEAD4, BT_LEAD4, -/* 0xF4 */ BT_LEAD4, BT_NONXML, BT_NONXML, BT_NONXML, -/* 0xF8 */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML, -/* 0xFC */ BT_NONXML, BT_NONXML, BT_MALFORM, BT_MALFORM, + /* 0x84 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL, + /* 0x88 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL, + /* 0x8C */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL, + /* 0x90 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL, + /* 0x94 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL, + /* 0x98 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL, + /* 0x9C */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL, + /* 0xA0 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL, + /* 0xA4 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL, + /* 0xA8 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL, + /* 0xAC */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL, + /* 0xB0 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL, + /* 0xB4 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL, + /* 0xB8 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL, + /* 0xBC */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL, + /* 0xC0 */ BT_LEAD2, BT_LEAD2, BT_LEAD2, BT_LEAD2, + /* 0xC4 */ BT_LEAD2, BT_LEAD2, BT_LEAD2, BT_LEAD2, + /* 0xC8 */ BT_LEAD2, BT_LEAD2, BT_LEAD2, BT_LEAD2, + /* 0xCC */ BT_LEAD2, BT_LEAD2, BT_LEAD2, BT_LEAD2, + /* 0xD0 */ BT_LEAD2, BT_LEAD2, BT_LEAD2, BT_LEAD2, + /* 0xD4 */ BT_LEAD2, BT_LEAD2, BT_LEAD2, BT_LEAD2, + /* 0xD8 */ BT_LEAD2, BT_LEAD2, BT_LEAD2, BT_LEAD2, + /* 0xDC */ BT_LEAD2, BT_LEAD2, BT_LEAD2, BT_LEAD2, + /* 0xE0 */ BT_LEAD3, BT_LEAD3, BT_LEAD3, BT_LEAD3, + /* 0xE4 */ BT_LEAD3, BT_LEAD3, BT_LEAD3, BT_LEAD3, + /* 0xE8 */ BT_LEAD3, BT_LEAD3, BT_LEAD3, BT_LEAD3, + /* 0xEC */ BT_LEAD3, BT_LEAD3, BT_LEAD3, BT_LEAD3, + /* 0xF0 */ BT_LEAD4, BT_LEAD4, BT_LEAD4, BT_LEAD4, + /* 0xF4 */ BT_LEAD4, BT_NONXML, BT_NONXML, BT_NONXML, + /* 0xF8 */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML, + /* 0xFC */ BT_NONXML, BT_NONXML, BT_MALFORM, BT_MALFORM, Index: expat/winconfig.h ================================================================== --- expat/winconfig.h +++ expat/winconfig.h @@ -38,26 +38,19 @@ #undef WIN32_LEAN_AND_MEAN #include #include - -#if defined(HAVE_EXPAT_CONFIG_H) /* e.g. MinGW */ -# include -#else /* !defined(HAVE_EXPAT_CONFIG_H) */ - - -#define XML_NS 1 -#define XML_DTD 1 -#define XML_CONTEXT_BYTES 1024 +#if defined(HAVE_EXPAT_CONFIG_H) /* e.g. MinGW */ +# include +#else /* !defined(HAVE_EXPAT_CONFIG_H) */ + +# define XML_NS 1 +# define XML_DTD 1 +# define XML_CONTEXT_BYTES 1024 /* we will assume all Windows platforms are little endian */ -#define BYTEORDER 1234 - -/* Windows has memmove() available. */ -#define HAVE_MEMMOVE - +# define BYTEORDER 1234 #endif /* !defined(HAVE_EXPAT_CONFIG_H) */ - #endif /* ndef WINCONFIG_H */ Index: expat/xmlparse.c ================================================================== --- expat/xmlparse.c +++ expat/xmlparse.c @@ -1,6 +1,6 @@ -/* 19ac4776051591216f1874e34ee99b6a43a3784c8bd7d70efeb9258dd22b906a (2.2.6+) +/* f519f27c7c3b79fee55aeb8b1e53b7384b079d9118bf3a62eb3a60986a6742f2 (2.2.9+) __ __ _ ___\ \/ /_ __ __ _| |_ / _ \\ /| '_ \ / _` | __| | __// \| |_) | (_| | |_ \___/_/\_\ .__/ \__,_|\__| @@ -28,71 +28,76 @@ DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#if !defined(_GNU_SOURCE) -# define _GNU_SOURCE 1 /* syscall prototype */ +#if ! defined(_GNU_SOURCE) +# define _GNU_SOURCE 1 /* syscall prototype */ +#endif + +#ifdef _WIN32 +/* force stdlib to define rand_s() */ +# if ! defined(_CRT_RAND_S) +# define _CRT_RAND_S +# endif #endif #include -#include /* memset(), memcpy() */ +#include /* memset(), memcpy() */ #include -#include /* UINT_MAX */ -#include /* fprintf */ -#include /* getenv */ +#include /* UINT_MAX */ +#include /* fprintf */ +#include /* getenv, rand_s */ #ifdef _WIN32 -#define getpid GetCurrentProcessId +# define getpid GetCurrentProcessId #else -#include /* gettimeofday() */ -#include /* getpid() */ -#include /* getpid() */ -#include /* O_RDONLY */ -#include +# include /* gettimeofday() */ +# include /* getpid() */ +# include /* getpid() */ +# include /* O_RDONLY */ +# include #endif #define XML_BUILDING_EXPAT 1 #ifdef _WIN32 -#include "winconfig.h" +# include "winconfig.h" #elif defined(HAVE_EXPAT_CONFIG_H) -#include +# include #endif /* ndef _WIN32 */ #include "ascii.h" #include "expat.h" #include "siphash.h" #if defined(HAVE_GETRANDOM) || defined(HAVE_SYSCALL_GETRANDOM) -# if defined(HAVE_GETRANDOM) -# include /* getrandom */ -# else -# include /* syscall */ -# include /* SYS_getrandom */ -# endif -# if ! defined(GRND_NONBLOCK) -# define GRND_NONBLOCK 0x0001 -# endif /* defined(GRND_NONBLOCK) */ -#endif /* defined(HAVE_GETRANDOM) || defined(HAVE_SYSCALL_GETRANDOM) */ - -#if defined(HAVE_LIBBSD) \ +# if defined(HAVE_GETRANDOM) +# include /* getrandom */ +# else +# include /* syscall */ +# include /* SYS_getrandom */ +# endif +# if ! defined(GRND_NONBLOCK) +# define GRND_NONBLOCK 0x0001 +# endif /* defined(GRND_NONBLOCK) */ +#endif /* defined(HAVE_GETRANDOM) || defined(HAVE_SYSCALL_GETRANDOM) */ + +#if defined(HAVE_LIBBSD) \ && (defined(HAVE_ARC4RANDOM_BUF) || defined(HAVE_ARC4RANDOM)) -# include +# include #endif -#if defined(_WIN32) && !defined(LOAD_LIBRARY_SEARCH_SYSTEM32) -# define LOAD_LIBRARY_SEARCH_SYSTEM32 0x00000800 +#if defined(_WIN32) && ! defined(LOAD_LIBRARY_SEARCH_SYSTEM32) +# define LOAD_LIBRARY_SEARCH_SYSTEM32 0x00000800 #endif -#if !defined(HAVE_GETRANDOM) && !defined(HAVE_SYSCALL_GETRANDOM) \ - && !defined(HAVE_ARC4RANDOM_BUF) && !defined(HAVE_ARC4RANDOM) \ - && !defined(XML_DEV_URANDOM) \ - && !defined(_WIN32) \ - && !defined(XML_POOR_ENTROPY) -# error \ - You do not have support for any sources of high quality entropy \ +#if ! defined(HAVE_GETRANDOM) && ! defined(HAVE_SYSCALL_GETRANDOM) \ + && ! defined(HAVE_ARC4RANDOM_BUF) && ! defined(HAVE_ARC4RANDOM) \ + && ! defined(XML_DEV_URANDOM) && ! defined(_WIN32) \ + && ! defined(XML_POOR_ENTROPY) +# error You do not have support for any sources of high quality entropy \ enabled. For end user security, that is probably not what you want. \ \ Your options include: \ * Linux + glibc >=2.25 (getrandom): HAVE_GETRANDOM, \ * Linux + glibc <2.25 (syscall SYS_getrandom): HAVE_SYSCALL_GETRANDOM, \ @@ -99,81 +104,71 @@ * BSD / macOS >=10.7 (arc4random_buf): HAVE_ARC4RANDOM_BUF, \ * BSD / macOS <10.7 (arc4random): HAVE_ARC4RANDOM, \ * libbsd (arc4random_buf): HAVE_ARC4RANDOM_BUF + HAVE_LIBBSD, \ * libbsd (arc4random): HAVE_ARC4RANDOM + HAVE_LIBBSD, \ * Linux / BSD / macOS (/dev/urandom): XML_DEV_URANDOM \ - * Windows (RtlGenRandom): _WIN32. \ + * Windows (rand_s): _WIN32. \ \ If insist on not using any of these, bypass this error by defining \ XML_POOR_ENTROPY; you have been warned. \ \ If you have reasons to patch this detection code away or need changes \ to the build system, please open a bug. Thank you! #endif - -#ifdef XML_UNICODE -#define XML_ENCODE_MAX XML_UTF16_ENCODE_MAX -#define XmlConvert XmlUtf16Convert -#define XmlGetInternalEncoding XmlGetUtf16InternalEncoding -#define XmlGetInternalEncodingNS XmlGetUtf16InternalEncodingNS -#define XmlEncode XmlUtf16Encode -/* Using pointer subtraction to convert to integer type. */ -#define MUST_CONVERT(enc, s) (!(enc)->isUtf16 || (((char *)(s) - (char *)NULL) & 1)) -typedef unsigned short ICHAR; -#else -#define XML_ENCODE_MAX XML_UTF8_ENCODE_MAX -#define XmlConvert XmlUtf8Convert -#define XmlGetInternalEncoding XmlGetUtf8InternalEncoding -#define XmlGetInternalEncodingNS XmlGetUtf8InternalEncodingNS -#define XmlEncode XmlUtf8Encode -#define MUST_CONVERT(enc, s) (!(enc)->isUtf8) -typedef char ICHAR; -#endif - - -#ifndef XML_NS - -#define XmlInitEncodingNS XmlInitEncoding -#define XmlInitUnknownEncodingNS XmlInitUnknownEncoding -#undef XmlGetInternalEncodingNS -#define XmlGetInternalEncodingNS XmlGetInternalEncoding -#define XmlParseXmlDeclNS XmlParseXmlDecl - -#endif - -#ifdef XML_UNICODE - -#ifdef XML_UNICODE_WCHAR_T -#define XML_T(x) (const wchar_t)x -#define XML_L(x) L ## x -#else -#define XML_T(x) (const unsigned short)x -#define XML_L(x) x -#endif - -#else - -#define XML_T(x) x -#define XML_L(x) x - -#endif - -/* Round up n to be a multiple of sz, where sz is a power of 2. */ -#define ROUND_UP(n, sz) (((n) + ((sz) - 1)) & ~((sz) - 1)) - -/* Do safe (NULL-aware) pointer arithmetic */ -#define EXPAT_SAFE_PTR_DIFF(p, q) (((p) && (q)) ? ((p) - (q)) : 0) - -/* Handle the case where memmove() doesn't exist. */ -#ifndef HAVE_MEMMOVE -#ifdef HAVE_BCOPY -#define memmove(d,s,l) bcopy((s),(d),(l)) -#else -#error memmove does not exist on this platform, nor is a substitute available -#endif /* HAVE_BCOPY */ -#endif /* HAVE_MEMMOVE */ +#ifdef XML_UNICODE +# define XML_ENCODE_MAX XML_UTF16_ENCODE_MAX +# define XmlConvert XmlUtf16Convert +# define XmlGetInternalEncoding XmlGetUtf16InternalEncoding +# define XmlGetInternalEncodingNS XmlGetUtf16InternalEncodingNS +# define XmlEncode XmlUtf16Encode +/* Using pointer subtraction to convert to integer type. */ +# define MUST_CONVERT(enc, s) \ + (! (enc)->isUtf16 || (((char *)(s) - (char *)NULL) & 1)) +typedef unsigned short ICHAR; +#else +# define XML_ENCODE_MAX XML_UTF8_ENCODE_MAX +# define XmlConvert XmlUtf8Convert +# define XmlGetInternalEncoding XmlGetUtf8InternalEncoding +# define XmlGetInternalEncodingNS XmlGetUtf8InternalEncodingNS +# define XmlEncode XmlUtf8Encode +# define MUST_CONVERT(enc, s) (! (enc)->isUtf8) +typedef char ICHAR; +#endif + +#ifndef XML_NS + +# define XmlInitEncodingNS XmlInitEncoding +# define XmlInitUnknownEncodingNS XmlInitUnknownEncoding +# undef XmlGetInternalEncodingNS +# define XmlGetInternalEncodingNS XmlGetInternalEncoding +# define XmlParseXmlDeclNS XmlParseXmlDecl + +#endif + +#ifdef XML_UNICODE + +# ifdef XML_UNICODE_WCHAR_T +# define XML_T(x) (const wchar_t) x +# define XML_L(x) L##x +# else +# define XML_T(x) (const unsigned short)x +# define XML_L(x) x +# endif + +#else + +# define XML_T(x) x +# define XML_L(x) x + +#endif + +/* Round up n to be a multiple of sz, where sz is a power of 2. */ +#define ROUND_UP(n, sz) (((n) + ((sz)-1)) & ~((sz)-1)) + +/* Do safe (NULL-aware) pointer arithmetic */ +#define EXPAT_SAFE_PTR_DIFF(p, q) (((p) && (q)) ? ((p) - (q)) : 0) #include "internal.h" #include "xmltok.h" #include "xmlrole.h" @@ -189,35 +184,33 @@ size_t size; size_t used; const XML_Memory_Handling_Suite *mem; } HASH_TABLE; -static size_t -keylen(KEY s); +static size_t keylen(KEY s); -static void -copy_salt_to_sipkey(XML_Parser parser, struct sipkey * key); +static void copy_salt_to_sipkey(XML_Parser parser, struct sipkey *key); /* For probing (after a collision) we need a step size relative prime to the hash table size, which is a power of 2. We use double-hashing, since we can calculate a second hash value cheaply by taking those bits of the first hash value that were discarded (masked out) when the table index was calculated: index = hash & mask, where mask = table->size - 1. We limit the maximum step size to table->size / 4 (mask >> 2) and make it odd, since odd numbers are always relative prime to a power of 2. */ -#define SECOND_HASH(hash, mask, power) \ - ((((hash) & ~(mask)) >> ((power) - 1)) & ((mask) >> 2)) -#define PROBE_STEP(hash, mask, power) \ +#define SECOND_HASH(hash, mask, power) \ + ((((hash) & ~(mask)) >> ((power)-1)) & ((mask) >> 2)) +#define PROBE_STEP(hash, mask, power) \ ((unsigned char)((SECOND_HASH(hash, mask, power)) | 1)) typedef struct { NAMED **p; NAMED **end; } HASH_TABLE_ITER; -#define INIT_TAG_BUF_SIZE 32 /* must be a multiple of sizeof(XML_Char) */ +#define INIT_TAG_BUF_SIZE 32 /* must be a multiple of sizeof(XML_Char) */ #define INIT_DATA_BUF_SIZE 1024 #define INIT_ATTS_SIZE 16 #define INIT_ATTS_VERSION 0xFFFFFFFF #define INIT_BLOCK_SIZE 1024 #define INIT_BUFFER_SIZE 1024 @@ -260,24 +253,24 @@ A parser re-uses these structures, maintaining a list of allocated TAG objects in a free list. */ typedef struct tag { - struct tag *parent; /* parent of this element */ - const char *rawName; /* tagName in the original encoding */ + struct tag *parent; /* parent of this element */ + const char *rawName; /* tagName in the original encoding */ int rawNameLength; - TAG_NAME name; /* tagName in the API encoding */ - char *buf; /* buffer for name components */ - char *bufEnd; /* end of the buffer */ + TAG_NAME name; /* tagName in the API encoding */ + char *buf; /* buffer for name components */ + char *bufEnd; /* end of the buffer */ BINDING *bindings; } TAG; typedef struct { const XML_Char *name; const XML_Char *textPtr; - int textLen; /* length in XML_Chars */ - int processed; /* # of processed bytes - when suspended */ + int textLen; /* length in XML_Chars */ + int processed; /* # of processed bytes - when suspended */ const XML_Char *systemId; const XML_Char *base; const XML_Char *publicId; const XML_Char *notation; XML_Bool open; @@ -284,17 +277,17 @@ XML_Bool is_param; XML_Bool is_internal; /* true if declared in internal subset outside PE */ } ENTITY; typedef struct { - enum XML_Content_Type type; - enum XML_Content_Quant quant; - const XML_Char * name; - int firstchild; - int lastchild; - int childcnt; - int nextsib; + enum XML_Content_Type type; + enum XML_Content_Quant quant; + const XML_Char *name; + int firstchild; + int lastchild; + int childcnt; + int nextsib; } CONTENT_SCAFFOLD; #define INIT_SCAFFOLD_ELEMENTS 32 typedef struct block { @@ -378,14 +371,12 @@ ENTITY *entity; int startTagLevel; XML_Bool betweenDecl; /* WFC: PE Between Declarations */ } OPEN_INTERNAL_ENTITY; -typedef enum XML_Error PTRCALL Processor(XML_Parser parser, - const char *start, - const char *end, - const char **endPtr); +typedef enum XML_Error PTRCALL Processor(XML_Parser parser, const char *start, + const char *end, const char **endPtr); static Processor prologProcessor; static Processor prologInitProcessor; static Processor contentProcessor; static Processor cdataSectionProcessor; @@ -402,149 +393,129 @@ static Processor externalEntityInitProcessor2; static Processor externalEntityInitProcessor3; static Processor externalEntityContentProcessor; static Processor internalEntityProcessor; -static enum XML_Error -handleUnknownEncoding(XML_Parser parser, const XML_Char *encodingName); -static enum XML_Error -processXmlDecl(XML_Parser parser, int isGeneralTextEntity, - const char *s, const char *next); -static enum XML_Error -initializeEncoding(XML_Parser parser); -static enum XML_Error -doProlog(XML_Parser parser, const ENCODING *enc, const char *s, - const char *end, int tok, const char *next, const char **nextPtr, - XML_Bool haveMore); -static enum XML_Error -processInternalEntity(XML_Parser parser, ENTITY *entity, - XML_Bool betweenDecl); -static enum XML_Error -doContent(XML_Parser parser, int startTagLevel, const ENCODING *enc, - const char *start, const char *end, const char **endPtr, - XML_Bool haveMore); -static enum XML_Error -doCdataSection(XML_Parser parser, const ENCODING *, const char **startPtr, - const char *end, const char **nextPtr, XML_Bool haveMore); +static enum XML_Error handleUnknownEncoding(XML_Parser parser, + const XML_Char *encodingName); +static enum XML_Error processXmlDecl(XML_Parser parser, int isGeneralTextEntity, + const char *s, const char *next); +static enum XML_Error initializeEncoding(XML_Parser parser); +static enum XML_Error doProlog(XML_Parser parser, const ENCODING *enc, + const char *s, const char *end, int tok, + const char *next, const char **nextPtr, + XML_Bool haveMore, XML_Bool allowClosingDoctype); +static enum XML_Error processInternalEntity(XML_Parser parser, ENTITY *entity, + XML_Bool betweenDecl); +static enum XML_Error doContent(XML_Parser parser, int startTagLevel, + const ENCODING *enc, const char *start, + const char *end, const char **endPtr, + XML_Bool haveMore); +static enum XML_Error doCdataSection(XML_Parser parser, const ENCODING *, + const char **startPtr, const char *end, + const char **nextPtr, XML_Bool haveMore); #ifdef XML_DTD -static enum XML_Error -doIgnoreSection(XML_Parser parser, const ENCODING *, const char **startPtr, - const char *end, const char **nextPtr, XML_Bool haveMore); +static enum XML_Error doIgnoreSection(XML_Parser parser, const ENCODING *, + const char **startPtr, const char *end, + const char **nextPtr, XML_Bool haveMore); #endif /* XML_DTD */ -static void -freeBindings(XML_Parser parser, BINDING *bindings); -static enum XML_Error -storeAtts(XML_Parser parser, const ENCODING *, const char *s, - TAG_NAME *tagNamePtr, BINDING **bindingsPtr); -static enum XML_Error -addBinding(XML_Parser parser, PREFIX *prefix, const ATTRIBUTE_ID *attId, - const XML_Char *uri, BINDING **bindingsPtr); -static int -defineAttribute(ELEMENT_TYPE *type, ATTRIBUTE_ID *, XML_Bool isCdata, - XML_Bool isId, const XML_Char *dfltValue, XML_Parser parser); -static enum XML_Error -storeAttributeValue(XML_Parser parser, const ENCODING *, XML_Bool isCdata, - const char *, const char *, STRING_POOL *); -static enum XML_Error -appendAttributeValue(XML_Parser parser, const ENCODING *, XML_Bool isCdata, - const char *, const char *, STRING_POOL *); -static ATTRIBUTE_ID * -getAttributeId(XML_Parser parser, const ENCODING *enc, const char *start, - const char *end); -static int -setElementTypePrefix(XML_Parser parser, ELEMENT_TYPE *); -static enum XML_Error -storeEntityValue(XML_Parser parser, const ENCODING *enc, const char *start, - const char *end); -static int -reportProcessingInstruction(XML_Parser parser, const ENCODING *enc, - const char *start, const char *end); -static int -reportComment(XML_Parser parser, const ENCODING *enc, const char *start, - const char *end); -static void -reportDefault(XML_Parser parser, const ENCODING *enc, const char *start, - const char *end); - -static const XML_Char * getContext(XML_Parser parser); -static XML_Bool -setContext(XML_Parser parser, const XML_Char *context); +static void freeBindings(XML_Parser parser, BINDING *bindings); +static enum XML_Error storeAtts(XML_Parser parser, const ENCODING *, + const char *s, TAG_NAME *tagNamePtr, + BINDING **bindingsPtr); +static enum XML_Error addBinding(XML_Parser parser, PREFIX *prefix, + const ATTRIBUTE_ID *attId, const XML_Char *uri, + BINDING **bindingsPtr); +static int defineAttribute(ELEMENT_TYPE *type, ATTRIBUTE_ID *, XML_Bool isCdata, + XML_Bool isId, const XML_Char *dfltValue, + XML_Parser parser); +static enum XML_Error storeAttributeValue(XML_Parser parser, const ENCODING *, + XML_Bool isCdata, const char *, + const char *, STRING_POOL *); +static enum XML_Error appendAttributeValue(XML_Parser parser, const ENCODING *, + XML_Bool isCdata, const char *, + const char *, STRING_POOL *); +static ATTRIBUTE_ID *getAttributeId(XML_Parser parser, const ENCODING *enc, + const char *start, const char *end); +static int setElementTypePrefix(XML_Parser parser, ELEMENT_TYPE *); +static enum XML_Error storeEntityValue(XML_Parser parser, const ENCODING *enc, + const char *start, const char *end); +static int reportProcessingInstruction(XML_Parser parser, const ENCODING *enc, + const char *start, const char *end); +static int reportComment(XML_Parser parser, const ENCODING *enc, + const char *start, const char *end); +static void reportDefault(XML_Parser parser, const ENCODING *enc, + const char *start, const char *end); + +static const XML_Char *getContext(XML_Parser parser); +static XML_Bool setContext(XML_Parser parser, const XML_Char *context); static void FASTCALL normalizePublicId(XML_Char *s); -static DTD * dtdCreate(const XML_Memory_Handling_Suite *ms); +static DTD *dtdCreate(const XML_Memory_Handling_Suite *ms); /* do not call if m_parentParser != NULL */ static void dtdReset(DTD *p, const XML_Memory_Handling_Suite *ms); -static void -dtdDestroy(DTD *p, XML_Bool isDocEntity, const XML_Memory_Handling_Suite *ms); -static int -dtdCopy(XML_Parser oldParser, - DTD *newDtd, const DTD *oldDtd, const XML_Memory_Handling_Suite *ms); -static int -copyEntityTable(XML_Parser oldParser, - HASH_TABLE *, STRING_POOL *, const HASH_TABLE *); -static NAMED * -lookup(XML_Parser parser, HASH_TABLE *table, KEY name, size_t createSize); -static void FASTCALL -hashTableInit(HASH_TABLE *, const XML_Memory_Handling_Suite *ms); +static void dtdDestroy(DTD *p, XML_Bool isDocEntity, + const XML_Memory_Handling_Suite *ms); +static int dtdCopy(XML_Parser oldParser, DTD *newDtd, const DTD *oldDtd, + const XML_Memory_Handling_Suite *ms); +static int copyEntityTable(XML_Parser oldParser, HASH_TABLE *, STRING_POOL *, + const HASH_TABLE *); +static NAMED *lookup(XML_Parser parser, HASH_TABLE *table, KEY name, + size_t createSize); +static void FASTCALL hashTableInit(HASH_TABLE *, + const XML_Memory_Handling_Suite *ms); static void FASTCALL hashTableClear(HASH_TABLE *); static void FASTCALL hashTableDestroy(HASH_TABLE *); -static void FASTCALL -hashTableIterInit(HASH_TABLE_ITER *, const HASH_TABLE *); -static NAMED * FASTCALL hashTableIterNext(HASH_TABLE_ITER *); +static void FASTCALL hashTableIterInit(HASH_TABLE_ITER *, const HASH_TABLE *); +static NAMED *FASTCALL hashTableIterNext(HASH_TABLE_ITER *); -static void FASTCALL -poolInit(STRING_POOL *, const XML_Memory_Handling_Suite *ms); +static void FASTCALL poolInit(STRING_POOL *, + const XML_Memory_Handling_Suite *ms); static void FASTCALL poolClear(STRING_POOL *); static void FASTCALL poolDestroy(STRING_POOL *); -static XML_Char * -poolAppend(STRING_POOL *pool, const ENCODING *enc, - const char *ptr, const char *end); -static XML_Char * -poolStoreString(STRING_POOL *pool, const ENCODING *enc, - const char *ptr, const char *end); +static XML_Char *poolAppend(STRING_POOL *pool, const ENCODING *enc, + const char *ptr, const char *end); +static XML_Char *poolStoreString(STRING_POOL *pool, const ENCODING *enc, + const char *ptr, const char *end); static XML_Bool FASTCALL poolGrow(STRING_POOL *pool); -static const XML_Char * FASTCALL -poolCopyString(STRING_POOL *pool, const XML_Char *s); -static const XML_Char * -poolCopyStringN(STRING_POOL *pool, const XML_Char *s, int n); -static const XML_Char * FASTCALL -poolAppendString(STRING_POOL *pool, const XML_Char *s); +static const XML_Char *FASTCALL poolCopyString(STRING_POOL *pool, + const XML_Char *s); +static const XML_Char *poolCopyStringN(STRING_POOL *pool, const XML_Char *s, + int n); +static const XML_Char *FASTCALL poolAppendString(STRING_POOL *pool, + const XML_Char *s); static int FASTCALL nextScaffoldPart(XML_Parser parser); -static XML_Content * build_model(XML_Parser parser); -static ELEMENT_TYPE * -getElementType(XML_Parser parser, const ENCODING *enc, - const char *ptr, const char *end); +static XML_Content *build_model(XML_Parser parser); +static ELEMENT_TYPE *getElementType(XML_Parser parser, const ENCODING *enc, + const char *ptr, const char *end); static XML_Char *copyString(const XML_Char *s, const XML_Memory_Handling_Suite *memsuite); static unsigned long generate_hash_secret_salt(XML_Parser parser); static XML_Bool startParsing(XML_Parser parser); -static XML_Parser -parserCreate(const XML_Char *encodingName, - const XML_Memory_Handling_Suite *memsuite, - const XML_Char *nameSep, - DTD *dtd); - -static void -parserInit(XML_Parser parser, const XML_Char *encodingName); +static XML_Parser parserCreate(const XML_Char *encodingName, + const XML_Memory_Handling_Suite *memsuite, + const XML_Char *nameSep, DTD *dtd); + +static void parserInit(XML_Parser parser, const XML_Char *encodingName); #define poolStart(pool) ((pool)->start) #define poolEnd(pool) ((pool)->ptr) #define poolLength(pool) ((pool)->ptr - (pool)->start) #define poolChop(pool) ((void)--(pool->ptr)) #define poolLastChar(pool) (((pool)->ptr)[-1]) #define poolDiscard(pool) ((pool)->ptr = (pool)->start) #define poolFinish(pool) ((pool)->start = (pool)->ptr) -#define poolAppendChar(pool, c) \ - (((pool)->ptr == (pool)->end && !poolGrow(pool)) \ - ? 0 \ - : ((*((pool)->ptr)++ = c), 1)) +#define poolAppendChar(pool, c) \ + (((pool)->ptr == (pool)->end && ! poolGrow(pool)) \ + ? 0 \ + : ((*((pool)->ptr)++ = c), 1)) struct XML_ParserStruct { /* The first member must be m_userData so that the XML_GetUserData macro works. */ void *m_userData; @@ -591,11 +562,11 @@ XML_Bool m_ns; XML_Bool m_ns_triplets; void *m_unknownEncodingMem; void *m_unknownEncodingData; void *m_unknownEncodingHandlerData; - void (XMLCALL *m_unknownEncodingRelease)(void *); + void(XMLCALL *m_unknownEncodingRelease)(void *); PROLOG_STATE m_prologState; Processor *m_processor; enum XML_Error m_errorCode; const char *m_eventPtr; const char *m_eventEndPtr; @@ -645,61 +616,59 @@ enum XML_ParamEntityParsing m_paramEntityParsing; #endif unsigned long m_hash_secret_salt; }; -#define MALLOC(parser, s) (parser->m_mem.malloc_fcn((s))) -#define REALLOC(parser, p, s) (parser->m_mem.realloc_fcn((p),(s))) -#define FREE(parser, p) (parser->m_mem.free_fcn((p))) - +#define MALLOC(parser, s) (parser->m_mem.malloc_fcn((s))) +#define REALLOC(parser, p, s) (parser->m_mem.realloc_fcn((p), (s))) +#define FREE(parser, p) (parser->m_mem.free_fcn((p))) XML_Parser XMLCALL -XML_ParserCreate(const XML_Char *encodingName) -{ +XML_ParserCreate(const XML_Char *encodingName) { return XML_ParserCreate_MM(encodingName, NULL, NULL); } XML_Parser XMLCALL -XML_ParserCreateNS(const XML_Char *encodingName, XML_Char nsSep) -{ +XML_ParserCreateNS(const XML_Char *encodingName, XML_Char nsSep) { XML_Char tmp[2]; *tmp = nsSep; return XML_ParserCreate_MM(encodingName, NULL, tmp); } -static const XML_Char implicitContext[] = { - ASCII_x, ASCII_m, ASCII_l, ASCII_EQUALS, ASCII_h, ASCII_t, ASCII_t, ASCII_p, - ASCII_COLON, ASCII_SLASH, ASCII_SLASH, ASCII_w, ASCII_w, ASCII_w, - ASCII_PERIOD, ASCII_w, ASCII_3, ASCII_PERIOD, ASCII_o, ASCII_r, ASCII_g, - ASCII_SLASH, ASCII_X, ASCII_M, ASCII_L, ASCII_SLASH, ASCII_1, ASCII_9, - ASCII_9, ASCII_8, ASCII_SLASH, ASCII_n, ASCII_a, ASCII_m, ASCII_e, - ASCII_s, ASCII_p, ASCII_a, ASCII_c, ASCII_e, '\0' -}; - +static const XML_Char implicitContext[] + = {ASCII_x, ASCII_m, ASCII_l, ASCII_EQUALS, ASCII_h, + ASCII_t, ASCII_t, ASCII_p, ASCII_COLON, ASCII_SLASH, + ASCII_SLASH, ASCII_w, ASCII_w, ASCII_w, ASCII_PERIOD, + ASCII_w, ASCII_3, ASCII_PERIOD, ASCII_o, ASCII_r, + ASCII_g, ASCII_SLASH, ASCII_X, ASCII_M, ASCII_L, + ASCII_SLASH, ASCII_1, ASCII_9, ASCII_9, ASCII_8, + ASCII_SLASH, ASCII_n, ASCII_a, ASCII_m, ASCII_e, + ASCII_s, ASCII_p, ASCII_a, ASCII_c, ASCII_e, + '\0'}; /* To avoid warnings about unused functions: */ #if ! defined(HAVE_ARC4RANDOM_BUF) && ! defined(HAVE_ARC4RANDOM) -#if defined(HAVE_GETRANDOM) || defined(HAVE_SYSCALL_GETRANDOM) +# if defined(HAVE_GETRANDOM) || defined(HAVE_SYSCALL_GETRANDOM) /* Obtain entropy on Linux 3.17+ */ static int -writeRandomBytes_getrandom_nonblock(void * target, size_t count) { - int success = 0; /* full count bytes written? */ +writeRandomBytes_getrandom_nonblock(void *target, size_t count) { + int success = 0; /* full count bytes written? */ size_t bytesWrittenTotal = 0; const unsigned int getrandomFlags = GRND_NONBLOCK; do { - void * const currentTarget = (void*)((char*)target + bytesWrittenTotal); + void *const currentTarget = (void *)((char *)target + bytesWrittenTotal); const size_t bytesToWrite = count - bytesWrittenTotal; const int bytesWrittenMore = -#if defined(HAVE_GETRANDOM) +# if defined(HAVE_GETRANDOM) getrandom(currentTarget, bytesToWrite, getrandomFlags); -#else +# else syscall(SYS_getrandom, currentTarget, bytesToWrite, getrandomFlags); -#endif +# endif if (bytesWrittenMore > 0) { bytesWrittenTotal += bytesWrittenMore; if (bytesWrittenTotal >= count) success = 1; @@ -707,28 +676,27 @@ } while (! success && (errno == EINTR)); return success; } -#endif /* defined(HAVE_GETRANDOM) || defined(HAVE_SYSCALL_GETRANDOM) */ +# endif /* defined(HAVE_GETRANDOM) || defined(HAVE_SYSCALL_GETRANDOM) */ - -#if ! defined(_WIN32) && defined(XML_DEV_URANDOM) +# if ! defined(_WIN32) && defined(XML_DEV_URANDOM) /* Extract entropy from /dev/urandom */ static int -writeRandomBytes_dev_urandom(void * target, size_t count) { - int success = 0; /* full count bytes written? */ +writeRandomBytes_dev_urandom(void *target, size_t count) { + int success = 0; /* full count bytes written? */ size_t bytesWrittenTotal = 0; const int fd = open("/dev/urandom", O_RDONLY); if (fd < 0) { return 0; } do { - void * const currentTarget = (void*)((char*)target + bytesWrittenTotal); + void *const currentTarget = (void *)((char *)target + bytesWrittenTotal); const size_t bytesToWrite = count - bytesWrittenTotal; const ssize_t bytesWrittenMore = read(fd, currentTarget, bytesToWrite); if (bytesWrittenMore > 0) { @@ -740,113 +708,101 @@ close(fd); return success; } -#endif /* ! defined(_WIN32) && defined(XML_DEV_URANDOM) */ +# endif /* ! defined(_WIN32) && defined(XML_DEV_URANDOM) */ -#endif /* ! defined(HAVE_ARC4RANDOM_BUF) && ! defined(HAVE_ARC4RANDOM) */ +#endif /* ! defined(HAVE_ARC4RANDOM_BUF) && ! defined(HAVE_ARC4RANDOM) */ - -#if defined(HAVE_ARC4RANDOM) +#if defined(HAVE_ARC4RANDOM) && ! defined(HAVE_ARC4RANDOM_BUF) static void -writeRandomBytes_arc4random(void * target, size_t count) { +writeRandomBytes_arc4random(void *target, size_t count) { size_t bytesWrittenTotal = 0; while (bytesWrittenTotal < count) { const uint32_t random32 = arc4random(); size_t i = 0; for (; (i < sizeof(random32)) && (bytesWrittenTotal < count); - i++, bytesWrittenTotal++) { + i++, bytesWrittenTotal++) { + const uint8_t random8 = (uint8_t)(random32 >> (i * 8)); + ((uint8_t *)target)[bytesWrittenTotal] = random8; + } + } +} + +#endif /* defined(HAVE_ARC4RANDOM) && ! defined(HAVE_ARC4RANDOM_BUF) */ + +#ifdef _WIN32 + +/* Obtain entropy on Windows using the rand_s() function which + * generates cryptographically secure random numbers. Internally it + * uses RtlGenRandom API which is present in Windows XP and later. + */ +static int +writeRandomBytes_rand_s(void *target, size_t count) { + size_t bytesWrittenTotal = 0; + + while (bytesWrittenTotal < count) { + unsigned int random32 = 0; + size_t i = 0; + + if (rand_s(&random32)) + return 0; /* failure */ + + for (; (i < sizeof(random32)) && (bytesWrittenTotal < count); + i++, bytesWrittenTotal++) { const uint8_t random8 = (uint8_t)(random32 >> (i * 8)); ((uint8_t *)target)[bytesWrittenTotal] = random8; } } -} - -#endif /* defined(HAVE_ARC4RANDOM) */ - - -#ifdef _WIN32 - -typedef BOOLEAN (APIENTRY *RTLGENRANDOM_FUNC)(PVOID, ULONG); -HMODULE _Expat_LoadLibrary(LPCTSTR filename); /* see loadlibrary.c */ - -/* Obtain entropy on Windows XP / Windows Server 2003 and later. - * Hint on RtlGenRandom and the following article from libsodium. - * - * Michael Howard: Cryptographically Secure Random number on Windows without using CryptoAPI - * https://blogs.msdn.microsoft.com/michael_howard/2005/01/14/cryptographically-secure-random-number-on-windows-without-using-cryptoapi/ - */ -static int -writeRandomBytes_RtlGenRandom(void * target, size_t count) { - int success = 0; /* full count bytes written? */ - const HMODULE advapi32 = _Expat_LoadLibrary(TEXT("ADVAPI32.DLL")); - - if (advapi32) { - const RTLGENRANDOM_FUNC RtlGenRandom - = (RTLGENRANDOM_FUNC)GetProcAddress(advapi32, "SystemFunction036"); - if (RtlGenRandom) { - if (RtlGenRandom((PVOID)target, (ULONG)count) == TRUE) { - success = 1; - } - } - FreeLibrary(advapi32); - } - - return success; + return 1; /* success */ } #endif /* _WIN32 */ - #if ! defined(HAVE_ARC4RANDOM_BUF) && ! defined(HAVE_ARC4RANDOM) static unsigned long -gather_time_entropy(void) -{ -#ifdef _WIN32 +gather_time_entropy(void) { +# ifdef _WIN32 FILETIME ft; GetSystemTimeAsFileTime(&ft); /* never fails */ return ft.dwHighDateTime ^ ft.dwLowDateTime; -#else +# else struct timeval tv; int gettimeofday_res; gettimeofday_res = gettimeofday(&tv, NULL); -#if defined(NDEBUG) +# if defined(NDEBUG) (void)gettimeofday_res; -#else - assert (gettimeofday_res == 0); -#endif /* defined(NDEBUG) */ +# else + assert(gettimeofday_res == 0); +# endif /* defined(NDEBUG) */ /* Microseconds time is <20 bits entropy */ return tv.tv_usec; -#endif +# endif } -#endif /* ! defined(HAVE_ARC4RANDOM_BUF) && ! defined(HAVE_ARC4RANDOM) */ - +#endif /* ! defined(HAVE_ARC4RANDOM_BUF) && ! defined(HAVE_ARC4RANDOM) */ static unsigned long -ENTROPY_DEBUG(const char * label, unsigned long entropy) { - const char * const EXPAT_ENTROPY_DEBUG = getenv("EXPAT_ENTROPY_DEBUG"); +ENTROPY_DEBUG(const char *label, unsigned long entropy) { + const char *const EXPAT_ENTROPY_DEBUG = getenv("EXPAT_ENTROPY_DEBUG"); if (EXPAT_ENTROPY_DEBUG && ! strcmp(EXPAT_ENTROPY_DEBUG, "1")) { - fprintf(stderr, "Entropy: %s --> 0x%0*lx (%lu bytes)\n", - label, - (int)sizeof(entropy) * 2, entropy, - (unsigned long)sizeof(entropy)); + fprintf(stderr, "Entropy: %s --> 0x%0*lx (%lu bytes)\n", label, + (int)sizeof(entropy) * 2, entropy, (unsigned long)sizeof(entropy)); } return entropy; } static unsigned long -generate_hash_secret_salt(XML_Parser parser) -{ +generate_hash_secret_salt(XML_Parser parser) { unsigned long entropy; (void)parser; /* "Failproof" high quality providers: */ #if defined(HAVE_ARC4RANDOM_BUF) @@ -855,24 +811,24 @@ #elif defined(HAVE_ARC4RANDOM) writeRandomBytes_arc4random((void *)&entropy, sizeof(entropy)); return ENTROPY_DEBUG("arc4random", entropy); #else /* Try high quality providers first .. */ -#ifdef _WIN32 - if (writeRandomBytes_RtlGenRandom((void *)&entropy, sizeof(entropy))) { - return ENTROPY_DEBUG("RtlGenRandom", entropy); +# ifdef _WIN32 + if (writeRandomBytes_rand_s((void *)&entropy, sizeof(entropy))) { + return ENTROPY_DEBUG("rand_s", entropy); } -#elif defined(HAVE_GETRANDOM) || defined(HAVE_SYSCALL_GETRANDOM) +# elif defined(HAVE_GETRANDOM) || defined(HAVE_SYSCALL_GETRANDOM) if (writeRandomBytes_getrandom_nonblock((void *)&entropy, sizeof(entropy))) { return ENTROPY_DEBUG("getrandom", entropy); } -#endif -#if ! defined(_WIN32) && defined(XML_DEV_URANDOM) +# endif +# if ! defined(_WIN32) && defined(XML_DEV_URANDOM) if (writeRandomBytes_dev_urandom((void *)&entropy, sizeof(entropy))) { return ENTROPY_DEBUG("/dev/urandom", entropy); } -#endif /* ! defined(_WIN32) && defined(XML_DEV_URANDOM) */ +# endif /* ! defined(_WIN32) && defined(XML_DEV_URANDOM) */ /* .. and self-made low quality for backup: */ /* Process ID is 0 bits entropy if attacker has local access */ entropy = gather_time_entropy() ^ getpid(); @@ -879,11 +835,11 @@ /* Factors are 2^31-1 and 2^61-1 (Mersenne primes M31 and M61) */ if (sizeof(unsigned long) == 4) { return ENTROPY_DEBUG("fallback(4)", entropy * 2147483647); } else { return ENTROPY_DEBUG("fallback(8)", - entropy * (unsigned long)2305843009213693951ULL); + entropy * (unsigned long)2305843009213693951ULL); } #endif } static unsigned long @@ -891,53 +847,47 @@ if (parser->m_parentParser != NULL) return get_hash_secret_salt(parser->m_parentParser); return parser->m_hash_secret_salt; } -static XML_Bool /* only valid for root parser */ -startParsing(XML_Parser parser) -{ - /* hash functions must be initialized before setContext() is called */ - if (parser->m_hash_secret_salt == 0) - parser->m_hash_secret_salt = generate_hash_secret_salt(parser); - if (parser->m_ns) { - /* implicit context only set for root parser, since child - parsers (i.e. external entity parsers) will inherit it - */ - return setContext(parser, implicitContext); - } - return XML_TRUE; +static XML_Bool /* only valid for root parser */ +startParsing(XML_Parser parser) { + /* hash functions must be initialized before setContext() is called */ + if (parser->m_hash_secret_salt == 0) + parser->m_hash_secret_salt = generate_hash_secret_salt(parser); + if (parser->m_ns) { + /* implicit context only set for root parser, since child + parsers (i.e. external entity parsers) will inherit it + */ + return setContext(parser, implicitContext); + } + return XML_TRUE; } XML_Parser XMLCALL XML_ParserCreate_MM(const XML_Char *encodingName, const XML_Memory_Handling_Suite *memsuite, - const XML_Char *nameSep) -{ + const XML_Char *nameSep) { return parserCreate(encodingName, memsuite, nameSep, NULL); } static XML_Parser parserCreate(const XML_Char *encodingName, - const XML_Memory_Handling_Suite *memsuite, - const XML_Char *nameSep, - DTD *dtd) -{ + const XML_Memory_Handling_Suite *memsuite, const XML_Char *nameSep, + DTD *dtd) { XML_Parser parser; if (memsuite) { XML_Memory_Handling_Suite *mtemp; - parser = (XML_Parser) - memsuite->malloc_fcn(sizeof(struct XML_ParserStruct)); + parser = (XML_Parser)memsuite->malloc_fcn(sizeof(struct XML_ParserStruct)); if (parser != NULL) { mtemp = (XML_Memory_Handling_Suite *)&(parser->m_mem); mtemp->malloc_fcn = memsuite->malloc_fcn; mtemp->realloc_fcn = memsuite->realloc_fcn; mtemp->free_fcn = memsuite->free_fcn; } - } - else { + } else { XML_Memory_Handling_Suite *mtemp; parser = (XML_Parser)malloc(sizeof(struct XML_ParserStruct)); if (parser != NULL) { mtemp = (XML_Memory_Handling_Suite *)&(parser->m_mem); mtemp->malloc_fcn = malloc; @@ -944,31 +894,34 @@ mtemp->realloc_fcn = realloc; mtemp->free_fcn = free; } } - if (!parser) + if (! parser) return parser; parser->m_buffer = NULL; parser->m_bufferLim = NULL; parser->m_attsSize = INIT_ATTS_SIZE; - parser->m_atts = (ATTRIBUTE *)MALLOC(parser, parser->m_attsSize * sizeof(ATTRIBUTE)); + parser->m_atts + = (ATTRIBUTE *)MALLOC(parser, parser->m_attsSize * sizeof(ATTRIBUTE)); if (parser->m_atts == NULL) { FREE(parser, parser); return NULL; } #ifdef XML_ATTR_INFO - parser->m_attInfo = (XML_AttrInfo*)MALLOC(parser, parser->m_attsSize * sizeof(XML_AttrInfo)); + parser->m_attInfo = (XML_AttrInfo *)MALLOC( + parser, parser->m_attsSize * sizeof(XML_AttrInfo)); if (parser->m_attInfo == NULL) { FREE(parser, parser->m_atts); FREE(parser, parser); return NULL; } #endif - parser->m_dataBuf = (XML_Char *)MALLOC(parser, INIT_DATA_BUF_SIZE * sizeof(XML_Char)); + parser->m_dataBuf + = (XML_Char *)MALLOC(parser, INIT_DATA_BUF_SIZE * sizeof(XML_Char)); if (parser->m_dataBuf == NULL) { FREE(parser, parser->m_atts); #ifdef XML_ATTR_INFO FREE(parser, parser->m_attInfo); #endif @@ -1014,30 +967,28 @@ poolInit(&parser->m_tempPool, &(parser->m_mem)); poolInit(&parser->m_temp2Pool, &(parser->m_mem)); parserInit(parser, encodingName); - if (encodingName && !parser->m_protocolEncodingName) { + if (encodingName && ! parser->m_protocolEncodingName) { XML_ParserFree(parser); return NULL; } if (nameSep) { parser->m_ns = XML_TRUE; parser->m_internalEncoding = XmlGetInternalEncodingNS(); parser->m_namespaceSeparator = *nameSep; - } - else { + } else { parser->m_internalEncoding = XmlGetInternalEncoding(); } return parser; } static void -parserInit(XML_Parser parser, const XML_Char *encodingName) -{ +parserInit(XML_Parser parser, const XML_Char *encodingName) { parser->m_processor = prologInitProcessor; XmlPrologStateInit(&parser->m_prologState); if (encodingName != NULL) { parser->m_protocolEncodingName = copyString(encodingName, &(parser->m_mem)); } @@ -1106,28 +1057,26 @@ parser->m_hash_secret_salt = 0; } /* moves list of bindings to m_freeBindingList */ static void FASTCALL -moveToFreeBindingList(XML_Parser parser, BINDING *bindings) -{ +moveToFreeBindingList(XML_Parser parser, BINDING *bindings) { while (bindings) { BINDING *b = bindings; bindings = bindings->nextTagBinding; b->nextTagBinding = parser->m_freeBindingList; parser->m_freeBindingList = b; } } XML_Bool XMLCALL -XML_ParserReset(XML_Parser parser, const XML_Char *encodingName) -{ +XML_ParserReset(XML_Parser parser, const XML_Char *encodingName) { TAG *tStk; OPEN_INTERNAL_ENTITY *openEntityList; if (parser == NULL) - return XML_FALSE; + return XML_FALSE; if (parser->m_parentParser) return XML_FALSE; /* move m_tagStack to m_freeTagList */ tStk = parser->m_tagStack; @@ -1159,19 +1108,19 @@ dtdReset(parser->m_dtd, &parser->m_mem); return XML_TRUE; } enum XML_Status XMLCALL -XML_SetEncoding(XML_Parser parser, const XML_Char *encodingName) -{ +XML_SetEncoding(XML_Parser parser, const XML_Char *encodingName) { if (parser == NULL) - return XML_STATUS_ERROR; + return XML_STATUS_ERROR; /* Block after XML_Parse()/XML_ParseBuffer() has been called. XXX There's no way for the caller to determine which of the XXX possible error cases caused the XML_STATUS_ERROR return. */ - if (parser->m_parsingStatus.parsing == XML_PARSING || parser->m_parsingStatus.parsing == XML_SUSPENDED) + if (parser->m_parsingStatus.parsing == XML_PARSING + || parser->m_parsingStatus.parsing == XML_SUSPENDED) return XML_STATUS_ERROR; /* Get rid of any previous encoding name */ FREE(parser, (void *)parser->m_protocolEncodingName); @@ -1179,21 +1128,19 @@ /* No new encoding name */ parser->m_protocolEncodingName = NULL; else { /* Copy the new encoding name into allocated memory */ parser->m_protocolEncodingName = copyString(encodingName, &(parser->m_mem)); - if (!parser->m_protocolEncodingName) + if (! parser->m_protocolEncodingName) return XML_STATUS_ERROR; } return XML_STATUS_OK; } XML_Parser XMLCALL -XML_ExternalEntityParserCreate(XML_Parser oldParser, - const XML_Char *context, - const XML_Char *encodingName) -{ +XML_ExternalEntityParserCreate(XML_Parser oldParser, const XML_Char *context, + const XML_Char *encodingName) { XML_Parser parser = oldParser; DTD *newDtd = NULL; DTD *oldDtd; XML_StartElementHandler oldStartElementHandler; XML_EndElementHandler oldEndElementHandler; @@ -1213,11 +1160,11 @@ XML_UnknownEncodingHandler oldUnknownEncodingHandler; XML_ElementDeclHandler oldElementDeclHandler; XML_AttlistDeclHandler oldAttlistDeclHandler; XML_EntityDeclHandler oldEntityDeclHandler; XML_XmlDeclHandler oldXmlDeclHandler; - ELEMENT_TYPE * oldDeclElementType; + ELEMENT_TYPE *oldDeclElementType; void *oldUserData; void *oldHandlerArg; XML_Bool oldDefaultExpandInternalEntities; XML_Parser oldExternalEntityRefHandlerArg; @@ -1276,11 +1223,11 @@ to worry which hash secrets each table has. */ oldhash_secret_salt = parser->m_hash_secret_salt; #ifdef XML_DTD - if (!context) + if (! context) newDtd = oldDtd; #endif /* XML_DTD */ /* Note that the magical uses of the pre-processor to make field access look more like C++ require that `parser' be overwritten @@ -1289,16 +1236,15 @@ */ if (parser->m_ns) { XML_Char tmp[2]; *tmp = parser->m_namespaceSeparator; parser = parserCreate(encodingName, &parser->m_mem, tmp, newDtd); - } - else { + } else { parser = parserCreate(encodingName, &parser->m_mem, NULL, newDtd); } - if (!parser) + if (! parser) return NULL; parser->m_startElementHandler = oldStartElementHandler; parser->m_endElementHandler = oldEndElementHandler; parser->m_characterDataHandler = oldCharacterDataHandler; @@ -1334,25 +1280,24 @@ #ifdef XML_DTD parser->m_paramEntityParsing = oldParamEntityParsing; parser->m_prologState.inEntityValue = oldInEntityValue; if (context) { #endif /* XML_DTD */ - if (!dtdCopy(oldParser, parser->m_dtd, oldDtd, &parser->m_mem) - || !setContext(parser, context)) { + if (! dtdCopy(oldParser, parser->m_dtd, oldDtd, &parser->m_mem) + || ! setContext(parser, context)) { XML_ParserFree(parser); return NULL; } parser->m_processor = externalEntityInitProcessor; #ifdef XML_DTD - } - else { - /* The DTD instance referenced by parser->m_dtd is shared between the document's - root parser and external PE parsers, therefore one does not need to - call setContext. In addition, one also *must* not call setContext, - because this would overwrite existing prefix->binding pointers in - parser->m_dtd with ones that get destroyed with the external PE parser. - This would leave those prefixes with dangling pointers. + } else { + /* The DTD instance referenced by parser->m_dtd is shared between the + document's root parser and external PE parsers, therefore one does not + need to call setContext. In addition, one also *must* not call + setContext, because this would overwrite existing prefix->binding + pointers in parser->m_dtd with ones that get destroyed with the external + PE parser. This would leave those prefixes with dangling pointers. */ parser->m_isParamEntity = XML_TRUE; XmlPrologStateInitExternalEntity(&parser->m_prologState); parser->m_processor = externalParEntInitProcessor; } @@ -1359,25 +1304,23 @@ #endif /* XML_DTD */ return parser; } static void FASTCALL -destroyBindings(BINDING *bindings, XML_Parser parser) -{ +destroyBindings(BINDING *bindings, XML_Parser parser) { for (;;) { BINDING *b = bindings; - if (!b) + if (! b) break; bindings = b->nextTagBinding; FREE(parser, b->uri); FREE(parser, b); } } void XMLCALL -XML_ParserFree(XML_Parser parser) -{ +XML_ParserFree(XML_Parser parser) { TAG *tagList; OPEN_INTERNAL_ENTITY *entityList; if (parser == NULL) return; /* free m_tagStack and m_freeTagList */ @@ -1418,15 +1361,16 @@ FREE(parser, (void *)parser->m_protocolEncodingName); #ifdef XML_DTD /* external parameter entity parsers share the DTD structure parser->m_dtd with the root parser, so we must not destroy it */ - if (!parser->m_isParamEntity && parser->m_dtd) + if (! parser->m_isParamEntity && parser->m_dtd) #else if (parser->m_dtd) #endif /* XML_DTD */ - dtdDestroy(parser->m_dtd, (XML_Bool)!parser->m_parentParser, &parser->m_mem); + dtdDestroy(parser->m_dtd, (XML_Bool)! parser->m_parentParser, + &parser->m_mem); FREE(parser, (void *)parser->m_atts); #ifdef XML_ATTR_INFO FREE(parser, (void *)parser->m_attInfo); #endif FREE(parser, parser->m_groupConnector); @@ -1438,158 +1382,141 @@ parser->m_unknownEncodingRelease(parser->m_unknownEncodingData); FREE(parser, parser); } void XMLCALL -XML_UseParserAsHandlerArg(XML_Parser parser) -{ +XML_UseParserAsHandlerArg(XML_Parser parser) { if (parser != NULL) parser->m_handlerArg = parser; } enum XML_Error XMLCALL -XML_UseForeignDTD(XML_Parser parser, XML_Bool useDTD) -{ +XML_UseForeignDTD(XML_Parser parser, XML_Bool useDTD) { if (parser == NULL) return XML_ERROR_INVALID_ARGUMENT; #ifdef XML_DTD /* block after XML_Parse()/XML_ParseBuffer() has been called */ - if (parser->m_parsingStatus.parsing == XML_PARSING || parser->m_parsingStatus.parsing == XML_SUSPENDED) + if (parser->m_parsingStatus.parsing == XML_PARSING + || parser->m_parsingStatus.parsing == XML_SUSPENDED) return XML_ERROR_CANT_CHANGE_FEATURE_ONCE_PARSING; parser->m_useForeignDTD = useDTD; return XML_ERROR_NONE; #else return XML_ERROR_FEATURE_REQUIRES_XML_DTD; #endif } void XMLCALL -XML_SetReturnNSTriplet(XML_Parser parser, int do_nst) -{ +XML_SetReturnNSTriplet(XML_Parser parser, int do_nst) { if (parser == NULL) return; /* block after XML_Parse()/XML_ParseBuffer() has been called */ - if (parser->m_parsingStatus.parsing == XML_PARSING || parser->m_parsingStatus.parsing == XML_SUSPENDED) + if (parser->m_parsingStatus.parsing == XML_PARSING + || parser->m_parsingStatus.parsing == XML_SUSPENDED) return; parser->m_ns_triplets = do_nst ? XML_TRUE : XML_FALSE; } void XMLCALL -XML_SetUserData(XML_Parser parser, void *p) -{ +XML_SetUserData(XML_Parser parser, void *p) { if (parser == NULL) return; if (parser->m_handlerArg == parser->m_userData) parser->m_handlerArg = parser->m_userData = p; else parser->m_userData = p; } enum XML_Status XMLCALL -XML_SetBase(XML_Parser parser, const XML_Char *p) -{ +XML_SetBase(XML_Parser parser, const XML_Char *p) { if (parser == NULL) return XML_STATUS_ERROR; if (p) { p = poolCopyString(&parser->m_dtd->pool, p); - if (!p) + if (! p) return XML_STATUS_ERROR; parser->m_curBase = p; - } - else + } else parser->m_curBase = NULL; return XML_STATUS_OK; } -const XML_Char * XMLCALL -XML_GetBase(XML_Parser parser) -{ +const XML_Char *XMLCALL +XML_GetBase(XML_Parser parser) { if (parser == NULL) return NULL; return parser->m_curBase; } int XMLCALL -XML_GetSpecifiedAttributeCount(XML_Parser parser) -{ +XML_GetSpecifiedAttributeCount(XML_Parser parser) { if (parser == NULL) return -1; return parser->m_nSpecifiedAtts; } int XMLCALL -XML_GetIdAttributeIndex(XML_Parser parser) -{ +XML_GetIdAttributeIndex(XML_Parser parser) { if (parser == NULL) return -1; return parser->m_idAttIndex; } #ifdef XML_ATTR_INFO -const XML_AttrInfo * XMLCALL -XML_GetAttributeInfo(XML_Parser parser) -{ +const XML_AttrInfo *XMLCALL +XML_GetAttributeInfo(XML_Parser parser) { if (parser == NULL) return NULL; return parser->m_attInfo; } #endif void XMLCALL -XML_SetElementHandler(XML_Parser parser, - XML_StartElementHandler start, - XML_EndElementHandler end) -{ +XML_SetElementHandler(XML_Parser parser, XML_StartElementHandler start, + XML_EndElementHandler end) { if (parser == NULL) return; parser->m_startElementHandler = start; parser->m_endElementHandler = end; } void XMLCALL -XML_SetStartElementHandler(XML_Parser parser, - XML_StartElementHandler start) { +XML_SetStartElementHandler(XML_Parser parser, XML_StartElementHandler start) { if (parser != NULL) parser->m_startElementHandler = start; } void XMLCALL -XML_SetEndElementHandler(XML_Parser parser, - XML_EndElementHandler end) { +XML_SetEndElementHandler(XML_Parser parser, XML_EndElementHandler end) { if (parser != NULL) parser->m_endElementHandler = end; } void XMLCALL XML_SetCharacterDataHandler(XML_Parser parser, - XML_CharacterDataHandler handler) -{ + XML_CharacterDataHandler handler) { if (parser != NULL) parser->m_characterDataHandler = handler; } void XMLCALL XML_SetProcessingInstructionHandler(XML_Parser parser, - XML_ProcessingInstructionHandler handler) -{ + XML_ProcessingInstructionHandler handler) { if (parser != NULL) parser->m_processingInstructionHandler = handler; } void XMLCALL -XML_SetCommentHandler(XML_Parser parser, - XML_CommentHandler handler) -{ +XML_SetCommentHandler(XML_Parser parser, XML_CommentHandler handler) { if (parser != NULL) parser->m_commentHandler = handler; } void XMLCALL XML_SetCdataSectionHandler(XML_Parser parser, XML_StartCdataSectionHandler start, - XML_EndCdataSectionHandler end) -{ + XML_EndCdataSectionHandler end) { if (parser == NULL) return; parser->m_startCdataSectionHandler = start; parser->m_endCdataSectionHandler = end; } @@ -1607,34 +1534,28 @@ if (parser != NULL) parser->m_endCdataSectionHandler = end; } void XMLCALL -XML_SetDefaultHandler(XML_Parser parser, - XML_DefaultHandler handler) -{ +XML_SetDefaultHandler(XML_Parser parser, XML_DefaultHandler handler) { if (parser == NULL) return; parser->m_defaultHandler = handler; parser->m_defaultExpandInternalEntities = XML_FALSE; } void XMLCALL -XML_SetDefaultHandlerExpand(XML_Parser parser, - XML_DefaultHandler handler) -{ +XML_SetDefaultHandlerExpand(XML_Parser parser, XML_DefaultHandler handler) { if (parser == NULL) return; parser->m_defaultHandler = handler; parser->m_defaultExpandInternalEntities = XML_TRUE; } void XMLCALL -XML_SetDoctypeDeclHandler(XML_Parser parser, - XML_StartDoctypeDeclHandler start, - XML_EndDoctypeDeclHandler end) -{ +XML_SetDoctypeDeclHandler(XML_Parser parser, XML_StartDoctypeDeclHandler start, + XML_EndDoctypeDeclHandler end) { if (parser == NULL) return; parser->m_startDoctypeDeclHandler = start; parser->m_endDoctypeDeclHandler = end; } @@ -1645,37 +1566,32 @@ if (parser != NULL) parser->m_startDoctypeDeclHandler = start; } void XMLCALL -XML_SetEndDoctypeDeclHandler(XML_Parser parser, - XML_EndDoctypeDeclHandler end) { +XML_SetEndDoctypeDeclHandler(XML_Parser parser, XML_EndDoctypeDeclHandler end) { if (parser != NULL) parser->m_endDoctypeDeclHandler = end; } void XMLCALL XML_SetUnparsedEntityDeclHandler(XML_Parser parser, - XML_UnparsedEntityDeclHandler handler) -{ + XML_UnparsedEntityDeclHandler handler) { if (parser != NULL) parser->m_unparsedEntityDeclHandler = handler; } void XMLCALL -XML_SetNotationDeclHandler(XML_Parser parser, - XML_NotationDeclHandler handler) -{ +XML_SetNotationDeclHandler(XML_Parser parser, XML_NotationDeclHandler handler) { if (parser != NULL) parser->m_notationDeclHandler = handler; } void XMLCALL XML_SetNamespaceDeclHandler(XML_Parser parser, XML_StartNamespaceDeclHandler start, - XML_EndNamespaceDeclHandler end) -{ + XML_EndNamespaceDeclHandler end) { if (parser == NULL) return; parser->m_startNamespaceDeclHandler = start; parser->m_endNamespaceDeclHandler = end; } @@ -1694,27 +1610,24 @@ parser->m_endNamespaceDeclHandler = end; } void XMLCALL XML_SetNotStandaloneHandler(XML_Parser parser, - XML_NotStandaloneHandler handler) -{ + XML_NotStandaloneHandler handler) { if (parser != NULL) parser->m_notStandaloneHandler = handler; } void XMLCALL XML_SetExternalEntityRefHandler(XML_Parser parser, - XML_ExternalEntityRefHandler handler) -{ + XML_ExternalEntityRefHandler handler) { if (parser != NULL) parser->m_externalEntityRefHandler = handler; } void XMLCALL -XML_SetExternalEntityRefHandlerArg(XML_Parser parser, void *arg) -{ +XML_SetExternalEntityRefHandlerArg(XML_Parser parser, void *arg) { if (parser == NULL) return; if (arg) parser->m_externalEntityRefHandlerArg = (XML_Parser)arg; else @@ -1721,66 +1634,56 @@ parser->m_externalEntityRefHandlerArg = parser; } void XMLCALL XML_SetSkippedEntityHandler(XML_Parser parser, - XML_SkippedEntityHandler handler) -{ + XML_SkippedEntityHandler handler) { if (parser != NULL) parser->m_skippedEntityHandler = handler; } void XMLCALL XML_SetUnknownEncodingHandler(XML_Parser parser, - XML_UnknownEncodingHandler handler, - void *data) -{ + XML_UnknownEncodingHandler handler, void *data) { if (parser == NULL) return; parser->m_unknownEncodingHandler = handler; parser->m_unknownEncodingHandlerData = data; } void XMLCALL -XML_SetElementDeclHandler(XML_Parser parser, - XML_ElementDeclHandler eldecl) -{ +XML_SetElementDeclHandler(XML_Parser parser, XML_ElementDeclHandler eldecl) { if (parser != NULL) parser->m_elementDeclHandler = eldecl; } void XMLCALL -XML_SetAttlistDeclHandler(XML_Parser parser, - XML_AttlistDeclHandler attdecl) -{ +XML_SetAttlistDeclHandler(XML_Parser parser, XML_AttlistDeclHandler attdecl) { if (parser != NULL) parser->m_attlistDeclHandler = attdecl; } void XMLCALL -XML_SetEntityDeclHandler(XML_Parser parser, - XML_EntityDeclHandler handler) -{ +XML_SetEntityDeclHandler(XML_Parser parser, XML_EntityDeclHandler handler) { if (parser != NULL) parser->m_entityDeclHandler = handler; } void XMLCALL -XML_SetXmlDeclHandler(XML_Parser parser, - XML_XmlDeclHandler handler) { +XML_SetXmlDeclHandler(XML_Parser parser, XML_XmlDeclHandler handler) { if (parser != NULL) parser->m_xmlDeclHandler = handler; } int XMLCALL XML_SetParamEntityParsing(XML_Parser parser, - enum XML_ParamEntityParsing peParsing) -{ + enum XML_ParamEntityParsing peParsing) { if (parser == NULL) return 0; /* block after XML_Parse()/XML_ParseBuffer() has been called */ - if (parser->m_parsingStatus.parsing == XML_PARSING || parser->m_parsingStatus.parsing == XML_SUSPENDED) + if (parser->m_parsingStatus.parsing == XML_PARSING + || parser->m_parsingStatus.parsing == XML_SUSPENDED) return 0; #ifdef XML_DTD parser->m_paramEntityParsing = peParsing; return 1; #else @@ -1787,27 +1690,25 @@ return peParsing == XML_PARAM_ENTITY_PARSING_NEVER; #endif } int XMLCALL -XML_SetHashSalt(XML_Parser parser, - unsigned long hash_salt) -{ +XML_SetHashSalt(XML_Parser parser, unsigned long hash_salt) { if (parser == NULL) return 0; if (parser->m_parentParser) return XML_SetHashSalt(parser->m_parentParser, hash_salt); /* block after XML_Parse()/XML_ParseBuffer() has been called */ - if (parser->m_parsingStatus.parsing == XML_PARSING || parser->m_parsingStatus.parsing == XML_SUSPENDED) + if (parser->m_parsingStatus.parsing == XML_PARSING + || parser->m_parsingStatus.parsing == XML_SUSPENDED) return 0; parser->m_hash_secret_salt = hash_salt; return 1; } enum XML_Status XMLCALL -XML_Parse(XML_Parser parser, const char *s, int len, int isFinal) -{ +XML_Parse(XML_Parser parser, const char *s, int len, int isFinal) { if ((parser == NULL) || (len < 0) || ((s == NULL) && (len != 0))) { if (parser != NULL) parser->m_errorCode = XML_ERROR_INVALID_ARGUMENT; return XML_STATUS_ERROR; } @@ -1817,11 +1718,11 @@ return XML_STATUS_ERROR; case XML_FINISHED: parser->m_errorCode = XML_ERROR_FINISHED; return XML_STATUS_ERROR; case XML_INITIALIZED: - if (parser->m_parentParser == NULL && !startParsing(parser)) { + if (parser->m_parentParser == NULL && ! startParsing(parser)) { parser->m_errorCode = XML_ERROR_NO_MEMORY; return XML_STATUS_ERROR; } /* fall through */ default: @@ -1828,20 +1729,22 @@ parser->m_parsingStatus.parsing = XML_PARSING; } if (len == 0) { parser->m_parsingStatus.finalBuffer = (XML_Bool)isFinal; - if (!isFinal) + if (! isFinal) return XML_STATUS_OK; parser->m_positionPtr = parser->m_bufferPtr; parser->m_parseEndPtr = parser->m_bufferEnd; /* If data are left over from last buffer, and we now know that these data are the final chunk of input, then we have to check them again to detect errors based on that fact. */ - parser->m_errorCode = parser->m_processor(parser, parser->m_bufferPtr, parser->m_parseEndPtr, &parser->m_bufferPtr); + parser->m_errorCode + = parser->m_processor(parser, parser->m_bufferPtr, + parser->m_parseEndPtr, &parser->m_bufferPtr); if (parser->m_errorCode == XML_ERROR_NONE) { switch (parser->m_parsingStatus.parsing) { case XML_SUSPENDED: /* It is hard to be certain, but it seems that this case @@ -1854,11 +1757,12 @@ * Given the uncertainty, we retain the code but exclude it * from coverage tests. * * LCOV_EXCL_START */ - XmlUpdatePosition(parser->m_encoding, parser->m_positionPtr, parser->m_bufferPtr, &parser->m_position); + XmlUpdatePosition(parser->m_encoding, parser->m_positionPtr, + parser->m_bufferPtr, &parser->m_position); parser->m_positionPtr = parser->m_bufferPtr; return XML_STATUS_SUSPENDED; /* LCOV_EXCL_STOP */ case XML_INITIALIZED: case XML_PARSING: @@ -1877,27 +1781,27 @@ const char *end; int nLeftOver; enum XML_Status result; /* Detect overflow (a+b > MAX <==> b > MAX-a) */ if (len > ((XML_Size)-1) / 2 - parser->m_parseEndByteIndex) { - parser->m_errorCode = XML_ERROR_NO_MEMORY; - parser->m_eventPtr = parser->m_eventEndPtr = NULL; - parser->m_processor = errorProcessor; - return XML_STATUS_ERROR; + parser->m_errorCode = XML_ERROR_NO_MEMORY; + parser->m_eventPtr = parser->m_eventEndPtr = NULL; + parser->m_processor = errorProcessor; + return XML_STATUS_ERROR; } parser->m_parseEndByteIndex += len; parser->m_positionPtr = s; parser->m_parsingStatus.finalBuffer = (XML_Bool)isFinal; - parser->m_errorCode = parser->m_processor(parser, s, parser->m_parseEndPtr = s + len, &end); + parser->m_errorCode + = parser->m_processor(parser, s, parser->m_parseEndPtr = s + len, &end); if (parser->m_errorCode != XML_ERROR_NONE) { parser->m_eventEndPtr = parser->m_eventPtr; parser->m_processor = errorProcessor; return XML_STATUS_ERROR; - } - else { + } else { switch (parser->m_parsingStatus.parsing) { case XML_SUSPENDED: result = XML_STATUS_SUSPENDED; break; case XML_INITIALIZED: @@ -1910,14 +1814,16 @@ default: result = XML_STATUS_OK; } } - XmlUpdatePosition(parser->m_encoding, parser->m_positionPtr, end, &parser->m_position); + XmlUpdatePosition(parser->m_encoding, parser->m_positionPtr, end, + &parser->m_position); nLeftOver = s + len - end; if (nLeftOver) { - if (parser->m_buffer == NULL || nLeftOver > parser->m_bufferLim - parser->m_buffer) { + if (parser->m_buffer == NULL + || nLeftOver > parser->m_bufferLim - parser->m_buffer) { /* avoid _signed_ integer overflow */ char *temp = NULL; const int bytesToAllocate = (int)((unsigned)len * 2U); if (bytesToAllocate > 0) { temp = (char *)REALLOC(parser, parser->m_buffer, bytesToAllocate); @@ -1939,11 +1845,11 @@ parser->m_parseEndPtr = parser->m_bufferEnd; parser->m_eventPtr = parser->m_bufferPtr; parser->m_eventEndPtr = parser->m_bufferPtr; return result; } -#endif /* not defined XML_CONTEXT_BYTES */ +#endif /* not defined XML_CONTEXT_BYTES */ else { void *buff = XML_GetBuffer(parser, len); if (buff == NULL) return XML_STATUS_ERROR; else { @@ -1952,12 +1858,11 @@ } } } enum XML_Status XMLCALL -XML_ParseBuffer(XML_Parser parser, int len, int isFinal) -{ +XML_ParseBuffer(XML_Parser parser, int len, int isFinal) { const char *start; enum XML_Status result = XML_STATUS_OK; if (parser == NULL) return XML_STATUS_ERROR; @@ -1967,11 +1872,11 @@ return XML_STATUS_ERROR; case XML_FINISHED: parser->m_errorCode = XML_ERROR_FINISHED; return XML_STATUS_ERROR; case XML_INITIALIZED: - if (parser->m_parentParser == NULL && !startParsing(parser)) { + if (parser->m_parentParser == NULL && ! startParsing(parser)) { parser->m_errorCode = XML_ERROR_NO_MEMORY; return XML_STATUS_ERROR; } /* fall through */ default: @@ -1983,18 +1888,18 @@ parser->m_bufferEnd += len; parser->m_parseEndPtr = parser->m_bufferEnd; parser->m_parseEndByteIndex += len; parser->m_parsingStatus.finalBuffer = (XML_Bool)isFinal; - parser->m_errorCode = parser->m_processor(parser, start, parser->m_parseEndPtr, &parser->m_bufferPtr); + parser->m_errorCode = parser->m_processor( + parser, start, parser->m_parseEndPtr, &parser->m_bufferPtr); if (parser->m_errorCode != XML_ERROR_NONE) { parser->m_eventEndPtr = parser->m_eventPtr; parser->m_processor = errorProcessor; return XML_STATUS_ERROR; - } - else { + } else { switch (parser->m_parsingStatus.parsing) { case XML_SUSPENDED: result = XML_STATUS_SUSPENDED; break; case XML_INITIALIZED: @@ -2001,22 +1906,22 @@ case XML_PARSING: if (isFinal) { parser->m_parsingStatus.parsing = XML_FINISHED; return result; } - default: ; /* should not happen */ + default:; /* should not happen */ } } - XmlUpdatePosition(parser->m_encoding, parser->m_positionPtr, parser->m_bufferPtr, &parser->m_position); + XmlUpdatePosition(parser->m_encoding, parser->m_positionPtr, + parser->m_bufferPtr, &parser->m_position); parser->m_positionPtr = parser->m_bufferPtr; return result; } -void * XMLCALL -XML_GetBuffer(XML_Parser parser, int len) -{ +void *XMLCALL +XML_GetBuffer(XML_Parser parser, int len) { if (parser == NULL) return NULL; if (len < 0) { parser->m_errorCode = XML_ERROR_NO_MEMORY; return NULL; @@ -2026,58 +1931,64 @@ parser->m_errorCode = XML_ERROR_SUSPENDED; return NULL; case XML_FINISHED: parser->m_errorCode = XML_ERROR_FINISHED; return NULL; - default: ; + default:; } if (len > EXPAT_SAFE_PTR_DIFF(parser->m_bufferLim, parser->m_bufferEnd)) { #ifdef XML_CONTEXT_BYTES int keep; -#endif /* defined XML_CONTEXT_BYTES */ +#endif /* defined XML_CONTEXT_BYTES */ /* Do not invoke signed arithmetic overflow: */ - int neededSize = (int) ((unsigned)len + - (unsigned)EXPAT_SAFE_PTR_DIFF(parser->m_bufferEnd, - parser->m_bufferPtr)); + int neededSize = (int)((unsigned)len + + (unsigned)EXPAT_SAFE_PTR_DIFF( + parser->m_bufferEnd, parser->m_bufferPtr)); if (neededSize < 0) { parser->m_errorCode = XML_ERROR_NO_MEMORY; return NULL; } #ifdef XML_CONTEXT_BYTES keep = (int)EXPAT_SAFE_PTR_DIFF(parser->m_bufferPtr, parser->m_buffer); if (keep > XML_CONTEXT_BYTES) keep = XML_CONTEXT_BYTES; neededSize += keep; -#endif /* defined XML_CONTEXT_BYTES */ - if (neededSize <= EXPAT_SAFE_PTR_DIFF(parser->m_bufferLim, parser->m_buffer)) { +#endif /* defined XML_CONTEXT_BYTES */ + if (neededSize + <= EXPAT_SAFE_PTR_DIFF(parser->m_bufferLim, parser->m_buffer)) { #ifdef XML_CONTEXT_BYTES if (keep < EXPAT_SAFE_PTR_DIFF(parser->m_bufferPtr, parser->m_buffer)) { - int offset = (int)EXPAT_SAFE_PTR_DIFF(parser->m_bufferPtr, parser->m_buffer) - keep; - /* The buffer pointers cannot be NULL here; we have at least some bytes in the buffer */ - memmove(parser->m_buffer, &parser->m_buffer[offset], parser->m_bufferEnd - parser->m_bufferPtr + keep); + int offset + = (int)EXPAT_SAFE_PTR_DIFF(parser->m_bufferPtr, parser->m_buffer) + - keep; + /* The buffer pointers cannot be NULL here; we have at least some bytes + * in the buffer */ + memmove(parser->m_buffer, &parser->m_buffer[offset], + parser->m_bufferEnd - parser->m_bufferPtr + keep); parser->m_bufferEnd -= offset; parser->m_bufferPtr -= offset; } #else if (parser->m_buffer && parser->m_bufferPtr) { memmove(parser->m_buffer, parser->m_bufferPtr, EXPAT_SAFE_PTR_DIFF(parser->m_bufferEnd, parser->m_bufferPtr)); - parser->m_bufferEnd = parser->m_buffer + - EXPAT_SAFE_PTR_DIFF(parser->m_bufferEnd, parser->m_bufferPtr); + parser->m_bufferEnd + = parser->m_buffer + + EXPAT_SAFE_PTR_DIFF(parser->m_bufferEnd, parser->m_bufferPtr); parser->m_bufferPtr = parser->m_buffer; } -#endif /* not defined XML_CONTEXT_BYTES */ - } - else { +#endif /* not defined XML_CONTEXT_BYTES */ + } else { char *newBuf; - int bufferSize = (int)EXPAT_SAFE_PTR_DIFF(parser->m_bufferLim, parser->m_bufferPtr); + int bufferSize + = (int)EXPAT_SAFE_PTR_DIFF(parser->m_bufferLim, parser->m_bufferPtr); if (bufferSize == 0) bufferSize = INIT_BUFFER_SIZE; do { /* Do not invoke signed arithmetic overflow: */ - bufferSize = (int) (2U * (unsigned) bufferSize); + bufferSize = (int)(2U * (unsigned)bufferSize); } while (bufferSize < neededSize && bufferSize > 0); if (bufferSize <= 0) { parser->m_errorCode = XML_ERROR_NO_MEMORY; return NULL; } @@ -2087,50 +1998,48 @@ return NULL; } parser->m_bufferLim = newBuf + bufferSize; #ifdef XML_CONTEXT_BYTES if (parser->m_bufferPtr) { - int keep = (int)EXPAT_SAFE_PTR_DIFF(parser->m_bufferPtr, parser->m_buffer); - if (keep > XML_CONTEXT_BYTES) - keep = XML_CONTEXT_BYTES; memcpy(newBuf, &parser->m_bufferPtr[-keep], - EXPAT_SAFE_PTR_DIFF(parser->m_bufferEnd, parser->m_bufferPtr) + keep); + EXPAT_SAFE_PTR_DIFF(parser->m_bufferEnd, parser->m_bufferPtr) + + keep); FREE(parser, parser->m_buffer); parser->m_buffer = newBuf; - parser->m_bufferEnd = parser->m_buffer + - EXPAT_SAFE_PTR_DIFF(parser->m_bufferEnd, parser->m_bufferPtr) + keep; + parser->m_bufferEnd + = parser->m_buffer + + EXPAT_SAFE_PTR_DIFF(parser->m_bufferEnd, parser->m_bufferPtr) + + keep; parser->m_bufferPtr = parser->m_buffer + keep; - } - else { + } else { /* This must be a brand new buffer with no data in it yet */ parser->m_bufferEnd = newBuf; parser->m_bufferPtr = parser->m_buffer = newBuf; } #else if (parser->m_bufferPtr) { memcpy(newBuf, parser->m_bufferPtr, EXPAT_SAFE_PTR_DIFF(parser->m_bufferEnd, parser->m_bufferPtr)); FREE(parser, parser->m_buffer); - parser->m_bufferEnd = newBuf + - EXPAT_SAFE_PTR_DIFF(parser->m_bufferEnd, parser->m_bufferPtr); - } - else { + parser->m_bufferEnd + = newBuf + + EXPAT_SAFE_PTR_DIFF(parser->m_bufferEnd, parser->m_bufferPtr); + } else { /* This must be a brand new buffer with no data in it yet */ parser->m_bufferEnd = newBuf; } parser->m_bufferPtr = parser->m_buffer = newBuf; -#endif /* not defined XML_CONTEXT_BYTES */ +#endif /* not defined XML_CONTEXT_BYTES */ } parser->m_eventPtr = parser->m_eventEndPtr = NULL; parser->m_positionPtr = NULL; } return parser->m_bufferEnd; } enum XML_Status XMLCALL -XML_StopParser(XML_Parser parser, XML_Bool resumable) -{ +XML_StopParser(XML_Parser parser, XML_Bool resumable) { if (parser == NULL) return XML_STATUS_ERROR; switch (parser->m_parsingStatus.parsing) { case XML_SUSPENDED: if (resumable) { @@ -2149,20 +2058,18 @@ parser->m_errorCode = XML_ERROR_SUSPEND_PE; return XML_STATUS_ERROR; } #endif parser->m_parsingStatus.parsing = XML_SUSPENDED; - } - else + } else parser->m_parsingStatus.parsing = XML_FINISHED; } return XML_STATUS_OK; } enum XML_Status XMLCALL -XML_ResumeParser(XML_Parser parser) -{ +XML_ResumeParser(XML_Parser parser) { enum XML_Status result = XML_STATUS_OK; if (parser == NULL) return XML_STATUS_ERROR; if (parser->m_parsingStatus.parsing != XML_SUSPENDED) { @@ -2169,18 +2076,18 @@ parser->m_errorCode = XML_ERROR_NOT_SUSPENDED; return XML_STATUS_ERROR; } parser->m_parsingStatus.parsing = XML_PARSING; - parser->m_errorCode = parser->m_processor(parser, parser->m_bufferPtr, parser->m_parseEndPtr, &parser->m_bufferPtr); + parser->m_errorCode = parser->m_processor( + parser, parser->m_bufferPtr, parser->m_parseEndPtr, &parser->m_bufferPtr); if (parser->m_errorCode != XML_ERROR_NONE) { parser->m_eventEndPtr = parser->m_eventPtr; parser->m_processor = errorProcessor; return XML_STATUS_ERROR; - } - else { + } else { switch (parser->m_parsingStatus.parsing) { case XML_SUSPENDED: result = XML_STATUS_SUSPENDED; break; case XML_INITIALIZED: @@ -2187,150 +2094,141 @@ case XML_PARSING: if (parser->m_parsingStatus.finalBuffer) { parser->m_parsingStatus.parsing = XML_FINISHED; return result; } - default: ; + default:; } } - XmlUpdatePosition(parser->m_encoding, parser->m_positionPtr, parser->m_bufferPtr, &parser->m_position); + XmlUpdatePosition(parser->m_encoding, parser->m_positionPtr, + parser->m_bufferPtr, &parser->m_position); parser->m_positionPtr = parser->m_bufferPtr; return result; } void XMLCALL -XML_GetParsingStatus(XML_Parser parser, XML_ParsingStatus *status) -{ +XML_GetParsingStatus(XML_Parser parser, XML_ParsingStatus *status) { if (parser == NULL) return; assert(status != NULL); *status = parser->m_parsingStatus; } enum XML_Error XMLCALL -XML_GetErrorCode(XML_Parser parser) -{ +XML_GetErrorCode(XML_Parser parser) { if (parser == NULL) return XML_ERROR_INVALID_ARGUMENT; return parser->m_errorCode; } XML_Index XMLCALL -XML_GetCurrentByteIndex(XML_Parser parser) -{ +XML_GetCurrentByteIndex(XML_Parser parser) { if (parser == NULL) return -1; if (parser->m_eventPtr) - return (XML_Index)(parser->m_parseEndByteIndex - (parser->m_parseEndPtr - parser->m_eventPtr)); + return (XML_Index)(parser->m_parseEndByteIndex + - (parser->m_parseEndPtr - parser->m_eventPtr)); return -1; } int XMLCALL -XML_GetCurrentByteCount(XML_Parser parser) -{ +XML_GetCurrentByteCount(XML_Parser parser) { if (parser == NULL) return 0; if (parser->m_eventEndPtr && parser->m_eventPtr) return (int)(parser->m_eventEndPtr - parser->m_eventPtr); return 0; } -const char * XMLCALL -XML_GetInputContext(XML_Parser parser, int *offset, int *size) -{ +const char *XMLCALL +XML_GetInputContext(XML_Parser parser, int *offset, int *size) { #ifdef XML_CONTEXT_BYTES if (parser == NULL) return NULL; if (parser->m_eventPtr && parser->m_buffer) { if (offset != NULL) *offset = (int)(parser->m_eventPtr - parser->m_buffer); if (size != NULL) - *size = (int)(parser->m_bufferEnd - parser->m_buffer); + *size = (int)(parser->m_bufferEnd - parser->m_buffer); return parser->m_buffer; } #else (void)parser; (void)offset; (void)size; #endif /* defined XML_CONTEXT_BYTES */ - return (char *) 0; + return (char *)0; } XML_Size XMLCALL -XML_GetCurrentLineNumber(XML_Parser parser) -{ +XML_GetCurrentLineNumber(XML_Parser parser) { if (parser == NULL) return 0; if (parser->m_eventPtr && parser->m_eventPtr >= parser->m_positionPtr) { - XmlUpdatePosition(parser->m_encoding, parser->m_positionPtr, parser->m_eventPtr, &parser->m_position); + XmlUpdatePosition(parser->m_encoding, parser->m_positionPtr, + parser->m_eventPtr, &parser->m_position); parser->m_positionPtr = parser->m_eventPtr; } return parser->m_position.lineNumber + 1; } XML_Size XMLCALL -XML_GetCurrentColumnNumber(XML_Parser parser) -{ +XML_GetCurrentColumnNumber(XML_Parser parser) { if (parser == NULL) return 0; if (parser->m_eventPtr && parser->m_eventPtr >= parser->m_positionPtr) { - XmlUpdatePosition(parser->m_encoding, parser->m_positionPtr, parser->m_eventPtr, &parser->m_position); + XmlUpdatePosition(parser->m_encoding, parser->m_positionPtr, + parser->m_eventPtr, &parser->m_position); parser->m_positionPtr = parser->m_eventPtr; } return parser->m_position.columnNumber; } void XMLCALL -XML_FreeContentModel(XML_Parser parser, XML_Content *model) -{ +XML_FreeContentModel(XML_Parser parser, XML_Content *model) { if (parser != NULL) FREE(parser, model); } -void * XMLCALL -XML_MemMalloc(XML_Parser parser, size_t size) -{ +void *XMLCALL +XML_MemMalloc(XML_Parser parser, size_t size) { if (parser == NULL) return NULL; return MALLOC(parser, size); } -void * XMLCALL -XML_MemRealloc(XML_Parser parser, void *ptr, size_t size) -{ +void *XMLCALL +XML_MemRealloc(XML_Parser parser, void *ptr, size_t size) { if (parser == NULL) return NULL; return REALLOC(parser, ptr, size); } void XMLCALL -XML_MemFree(XML_Parser parser, void *ptr) -{ +XML_MemFree(XML_Parser parser, void *ptr) { if (parser != NULL) FREE(parser, ptr); } void XMLCALL -XML_DefaultCurrent(XML_Parser parser) -{ +XML_DefaultCurrent(XML_Parser parser) { if (parser == NULL) return; if (parser->m_defaultHandler) { if (parser->m_openInternalEntities) - reportDefault(parser, - parser->m_internalEncoding, + reportDefault(parser, parser->m_internalEncoding, parser->m_openInternalEntities->internalEventPtr, parser->m_openInternalEntities->internalEventEndPtr); else - reportDefault(parser, parser->m_encoding, parser->m_eventPtr, parser->m_eventEndPtr); + reportDefault(parser, parser->m_encoding, parser->m_eventPtr, + parser->m_eventEndPtr); } } -const XML_LChar * XMLCALL -XML_ErrorString(enum XML_Error code) -{ +const XML_LChar *XMLCALL +XML_ErrorString(enum XML_Error code) { switch (code) { case XML_ERROR_NONE: return NULL; case XML_ERROR_NO_MEMORY: return XML_L("out of memory"); @@ -2408,89 +2306,87 @@ return XML_L("parsing finished"); case XML_ERROR_SUSPEND_PE: return XML_L("cannot suspend in external parameter entity"); /* Added in 2.0.0. */ case XML_ERROR_RESERVED_PREFIX_XML: - return XML_L("reserved prefix (xml) must not be undeclared or bound to another namespace name"); + return XML_L( + "reserved prefix (xml) must not be undeclared or bound to another namespace name"); case XML_ERROR_RESERVED_PREFIX_XMLNS: return XML_L("reserved prefix (xmlns) must not be declared or undeclared"); case XML_ERROR_RESERVED_NAMESPACE_URI: - return XML_L("prefix must not be bound to one of the reserved namespace names"); + return XML_L( + "prefix must not be bound to one of the reserved namespace names"); /* Added in 2.2.5. */ - case XML_ERROR_INVALID_ARGUMENT: /* Constant added in 2.2.1, already */ + case XML_ERROR_INVALID_ARGUMENT: /* Constant added in 2.2.1, already */ return XML_L("invalid argument"); } return NULL; } -const XML_LChar * XMLCALL +const XML_LChar *XMLCALL XML_ExpatVersion(void) { - /* V1 is used to string-ize the version number. However, it would string-ize the actual version macro *names* unless we get them substituted before being passed to V1. CPP is defined to expand a macro, then rescan for more expansions. Thus, we use V2 to expand the version macros, then CPP will expand the resulting V1() macro with the correct numerals. */ /* ### I'm assuming cpp is portable in this respect... */ -#define V1(a,b,c) XML_L(#a)XML_L(".")XML_L(#b)XML_L(".")XML_L(#c) -#define V2(a,b,c) XML_L("expat_")V1(a,b,c) +#define V1(a, b, c) XML_L(#a) XML_L(".") XML_L(#b) XML_L(".") XML_L(#c) +#define V2(a, b, c) XML_L("expat_") V1(a, b, c) return V2(XML_MAJOR_VERSION, XML_MINOR_VERSION, XML_MICRO_VERSION); #undef V1 #undef V2 } XML_Expat_Version XMLCALL -XML_ExpatVersionInfo(void) -{ +XML_ExpatVersionInfo(void) { XML_Expat_Version version; version.major = XML_MAJOR_VERSION; version.minor = XML_MINOR_VERSION; version.micro = XML_MICRO_VERSION; return version; } -const XML_Feature * XMLCALL -XML_GetFeatureList(void) -{ - static const XML_Feature features[] = { - {XML_FEATURE_SIZEOF_XML_CHAR, XML_L("sizeof(XML_Char)"), - sizeof(XML_Char)}, - {XML_FEATURE_SIZEOF_XML_LCHAR, XML_L("sizeof(XML_LChar)"), - sizeof(XML_LChar)}, +const XML_Feature *XMLCALL +XML_GetFeatureList(void) { + static const XML_Feature features[] + = {{XML_FEATURE_SIZEOF_XML_CHAR, XML_L("sizeof(XML_Char)"), + sizeof(XML_Char)}, + {XML_FEATURE_SIZEOF_XML_LCHAR, XML_L("sizeof(XML_LChar)"), + sizeof(XML_LChar)}, #ifdef XML_UNICODE - {XML_FEATURE_UNICODE, XML_L("XML_UNICODE"), 0}, + {XML_FEATURE_UNICODE, XML_L("XML_UNICODE"), 0}, #endif #ifdef XML_UNICODE_WCHAR_T - {XML_FEATURE_UNICODE_WCHAR_T, XML_L("XML_UNICODE_WCHAR_T"), 0}, + {XML_FEATURE_UNICODE_WCHAR_T, XML_L("XML_UNICODE_WCHAR_T"), 0}, #endif #ifdef XML_DTD - {XML_FEATURE_DTD, XML_L("XML_DTD"), 0}, + {XML_FEATURE_DTD, XML_L("XML_DTD"), 0}, #endif #ifdef XML_CONTEXT_BYTES - {XML_FEATURE_CONTEXT_BYTES, XML_L("XML_CONTEXT_BYTES"), - XML_CONTEXT_BYTES}, + {XML_FEATURE_CONTEXT_BYTES, XML_L("XML_CONTEXT_BYTES"), + XML_CONTEXT_BYTES}, #endif #ifdef XML_MIN_SIZE - {XML_FEATURE_MIN_SIZE, XML_L("XML_MIN_SIZE"), 0}, + {XML_FEATURE_MIN_SIZE, XML_L("XML_MIN_SIZE"), 0}, #endif #ifdef XML_NS - {XML_FEATURE_NS, XML_L("XML_NS"), 0}, + {XML_FEATURE_NS, XML_L("XML_NS"), 0}, #endif #ifdef XML_LARGE_SIZE - {XML_FEATURE_LARGE_SIZE, XML_L("XML_LARGE_SIZE"), 0}, + {XML_FEATURE_LARGE_SIZE, XML_L("XML_LARGE_SIZE"), 0}, #endif #ifdef XML_ATTR_INFO - {XML_FEATURE_ATTR_INFO, XML_L("XML_ATTR_INFO"), 0}, + {XML_FEATURE_ATTR_INFO, XML_L("XML_ATTR_INFO"), 0}, #endif - {XML_FEATURE_END, NULL, 0} - }; + {XML_FEATURE_END, NULL, 0}}; return features; } /* Initially tag->rawName always points into the parse buffer; @@ -2497,12 +2393,11 @@ for those TAG instances opened while the current parse buffer was processed, and not yet closed, we need to store tag->rawName in a more permanent location, since the parse buffer is about to be discarded. */ static XML_Bool -storeRawNames(XML_Parser parser) -{ +storeRawNames(XML_Parser parser) { TAG *tag = parser->m_tagStack; while (tag) { int bufSize; int nameLen = sizeof(XML_Char) * (tag->name.strLen + 1); char *rawNameBuf = tag->buf + nameLen; @@ -2528,12 +2423,12 @@ tag->name.str = (XML_Char *)temp; /* if tag->name.localPart is set (when namespace processing is on) then update it as well, since it will always point into tag->buf */ if (tag->name.localPart) - tag->name.localPart = (XML_Char *)temp + (tag->name.localPart - - (XML_Char *)tag->buf); + tag->name.localPart + = (XML_Char *)temp + (tag->name.localPart - (XML_Char *)tag->buf); tag->buf = temp; tag->bufEnd = temp + bufSize; rawNameBuf = temp + nameLen; } memcpy(rawNameBuf, tag->rawName, tag->rawNameLength); @@ -2542,67 +2437,59 @@ } return XML_TRUE; } static enum XML_Error PTRCALL -contentProcessor(XML_Parser parser, - const char *start, - const char *end, - const char **endPtr) -{ - enum XML_Error result = doContent(parser, 0, parser->m_encoding, start, end, - endPtr, (XML_Bool)!parser->m_parsingStatus.finalBuffer); +contentProcessor(XML_Parser parser, const char *start, const char *end, + const char **endPtr) { + enum XML_Error result + = doContent(parser, 0, parser->m_encoding, start, end, endPtr, + (XML_Bool)! parser->m_parsingStatus.finalBuffer); if (result == XML_ERROR_NONE) { - if (!storeRawNames(parser)) + if (! storeRawNames(parser)) return XML_ERROR_NO_MEMORY; } return result; } static enum XML_Error PTRCALL -externalEntityInitProcessor(XML_Parser parser, - const char *start, - const char *end, - const char **endPtr) -{ +externalEntityInitProcessor(XML_Parser parser, const char *start, + const char *end, const char **endPtr) { enum XML_Error result = initializeEncoding(parser); if (result != XML_ERROR_NONE) return result; parser->m_processor = externalEntityInitProcessor2; return externalEntityInitProcessor2(parser, start, end, endPtr); } static enum XML_Error PTRCALL -externalEntityInitProcessor2(XML_Parser parser, - const char *start, - const char *end, - const char **endPtr) -{ +externalEntityInitProcessor2(XML_Parser parser, const char *start, + const char *end, const char **endPtr) { const char *next = start; /* XmlContentTok doesn't always set the last arg */ int tok = XmlContentTok(parser->m_encoding, start, end, &next); switch (tok) { case XML_TOK_BOM: /* If we are at the end of the buffer, this would cause the next stage, i.e. externalEntityInitProcessor3, to pass control directly to doContent (by detecting XML_TOK_NONE) without processing any xml text declaration - causing the error XML_ERROR_MISPLACED_XML_PI in doContent. */ - if (next == end && !parser->m_parsingStatus.finalBuffer) { + if (next == end && ! parser->m_parsingStatus.finalBuffer) { *endPtr = next; return XML_ERROR_NONE; } start = next; break; case XML_TOK_PARTIAL: - if (!parser->m_parsingStatus.finalBuffer) { + if (! parser->m_parsingStatus.finalBuffer) { *endPtr = start; return XML_ERROR_NONE; } parser->m_eventPtr = start; return XML_ERROR_UNCLOSED_TOKEN; case XML_TOK_PARTIAL_CHAR: - if (!parser->m_parsingStatus.finalBuffer) { + if (! parser->m_parsingStatus.finalBuffer) { *endPtr = start; return XML_ERROR_NONE; } parser->m_eventPtr = start; return XML_ERROR_PARTIAL_CHAR; @@ -2610,47 +2497,42 @@ parser->m_processor = externalEntityInitProcessor3; return externalEntityInitProcessor3(parser, start, end, endPtr); } static enum XML_Error PTRCALL -externalEntityInitProcessor3(XML_Parser parser, - const char *start, - const char *end, - const char **endPtr) -{ +externalEntityInitProcessor3(XML_Parser parser, const char *start, + const char *end, const char **endPtr) { int tok; const char *next = start; /* XmlContentTok doesn't always set the last arg */ parser->m_eventPtr = start; tok = XmlContentTok(parser->m_encoding, start, end, &next); parser->m_eventEndPtr = next; switch (tok) { - case XML_TOK_XML_DECL: - { - enum XML_Error result; - result = processXmlDecl(parser, 1, start, next); - if (result != XML_ERROR_NONE) - return result; - switch (parser->m_parsingStatus.parsing) { - case XML_SUSPENDED: - *endPtr = next; - return XML_ERROR_NONE; - case XML_FINISHED: - return XML_ERROR_ABORTED; - default: - start = next; - } - } - break; + case XML_TOK_XML_DECL: { + enum XML_Error result; + result = processXmlDecl(parser, 1, start, next); + if (result != XML_ERROR_NONE) + return result; + switch (parser->m_parsingStatus.parsing) { + case XML_SUSPENDED: + *endPtr = next; + return XML_ERROR_NONE; + case XML_FINISHED: + return XML_ERROR_ABORTED; + default: + start = next; + } + } break; case XML_TOK_PARTIAL: - if (!parser->m_parsingStatus.finalBuffer) { + if (! parser->m_parsingStatus.finalBuffer) { *endPtr = start; return XML_ERROR_NONE; } return XML_ERROR_UNCLOSED_TOKEN; case XML_TOK_PARTIAL_CHAR: - if (!parser->m_parsingStatus.finalBuffer) { + if (! parser->m_parsingStatus.finalBuffer) { *endPtr = start; return XML_ERROR_NONE; } return XML_ERROR_PARTIAL_CHAR; } @@ -2658,43 +2540,35 @@ parser->m_tagLevel = 1; return externalEntityContentProcessor(parser, start, end, endPtr); } static enum XML_Error PTRCALL -externalEntityContentProcessor(XML_Parser parser, - const char *start, - const char *end, - const char **endPtr) -{ - enum XML_Error result = doContent(parser, 1, parser->m_encoding, start, end, - endPtr, (XML_Bool)!parser->m_parsingStatus.finalBuffer); +externalEntityContentProcessor(XML_Parser parser, const char *start, + const char *end, const char **endPtr) { + enum XML_Error result + = doContent(parser, 1, parser->m_encoding, start, end, endPtr, + (XML_Bool)! parser->m_parsingStatus.finalBuffer); if (result == XML_ERROR_NONE) { - if (!storeRawNames(parser)) + if (! storeRawNames(parser)) return XML_ERROR_NO_MEMORY; } return result; } static enum XML_Error -doContent(XML_Parser parser, - int startTagLevel, - const ENCODING *enc, - const char *s, - const char *end, - const char **nextPtr, - XML_Bool haveMore) -{ +doContent(XML_Parser parser, int startTagLevel, const ENCODING *enc, + const char *s, const char *end, const char **nextPtr, + XML_Bool haveMore) { /* save one level of indirection */ - DTD * const dtd = parser->m_dtd; + DTD *const dtd = parser->m_dtd; const char **eventPP; const char **eventEndPP; if (enc == parser->m_encoding) { eventPP = &parser->m_eventPtr; eventEndPP = &parser->m_eventEndPtr; - } - else { + } else { eventPP = &(parser->m_openInternalEntities->internalEventPtr); eventEndPP = &(parser->m_openInternalEntities->internalEventEndPtr); } *eventPP = s; @@ -2710,12 +2584,11 @@ } *eventEndPP = end; if (parser->m_characterDataHandler) { XML_Char c = 0xA; parser->m_characterDataHandler(parser->m_handlerArg, &c, 1); - } - else if (parser->m_defaultHandler) + } else if (parser->m_defaultHandler) reportDefault(parser, enc, s, end); /* We are at the end of the final buffer, should we check for XML_SUSPENDED, XML_FINISHED? */ if (startTagLevel == 0) @@ -2749,189 +2622,182 @@ if (haveMore) { *nextPtr = s; return XML_ERROR_NONE; } return XML_ERROR_PARTIAL_CHAR; - case XML_TOK_ENTITY_REF: - { - const XML_Char *name; - ENTITY *entity; - XML_Char ch = (XML_Char) XmlPredefinedEntityName(enc, - s + enc->minBytesPerChar, - next - enc->minBytesPerChar); - if (ch) { - if (parser->m_characterDataHandler) - parser->m_characterDataHandler(parser->m_handlerArg, &ch, 1); - else if (parser->m_defaultHandler) - reportDefault(parser, enc, s, next); - break; - } - name = poolStoreString(&dtd->pool, enc, - s + enc->minBytesPerChar, - next - enc->minBytesPerChar); - if (!name) - return XML_ERROR_NO_MEMORY; - entity = (ENTITY *)lookup(parser, &dtd->generalEntities, name, 0); - poolDiscard(&dtd->pool); - /* First, determine if a check for an existing declaration is needed; - if yes, check that the entity exists, and that it is internal, - otherwise call the skipped entity or default handler. - */ - if (!dtd->hasParamEntityRefs || dtd->standalone) { - if (!entity) - return XML_ERROR_UNDEFINED_ENTITY; - else if (!entity->is_internal) - return XML_ERROR_ENTITY_DECLARED_IN_PE; - } - else if (!entity) { - if (parser->m_skippedEntityHandler) - parser->m_skippedEntityHandler(parser->m_handlerArg, name, 0); - else if (parser->m_defaultHandler) - reportDefault(parser, enc, s, next); - break; - } - if (entity->open) - return XML_ERROR_RECURSIVE_ENTITY_REF; - if (entity->notation) - return XML_ERROR_BINARY_ENTITY_REF; - if (entity->textPtr) { - enum XML_Error result; - if (!parser->m_defaultExpandInternalEntities) { - if (parser->m_skippedEntityHandler) - parser->m_skippedEntityHandler(parser->m_handlerArg, entity->name, 0); - else if (parser->m_defaultHandler) - reportDefault(parser, enc, s, next); - break; - } - result = processInternalEntity(parser, entity, XML_FALSE); - if (result != XML_ERROR_NONE) - return result; - } - else if (parser->m_externalEntityRefHandler) { - const XML_Char *context; - entity->open = XML_TRUE; - context = getContext(parser); - entity->open = XML_FALSE; - if (!context) - return XML_ERROR_NO_MEMORY; - if (!parser->m_externalEntityRefHandler(parser->m_externalEntityRefHandlerArg, - context, - entity->base, - entity->systemId, - entity->publicId)) - return XML_ERROR_EXTERNAL_ENTITY_HANDLING; - poolDiscard(&parser->m_tempPool); - } - else if (parser->m_defaultHandler) - reportDefault(parser, enc, s, next); - break; - } - case XML_TOK_START_TAG_NO_ATTS: - /* fall through */ - case XML_TOK_START_TAG_WITH_ATTS: - { - TAG *tag; - enum XML_Error result; - XML_Char *toPtr; - if (parser->m_freeTagList) { - tag = parser->m_freeTagList; - parser->m_freeTagList = parser->m_freeTagList->parent; - } - else { - tag = (TAG *)MALLOC(parser, sizeof(TAG)); - if (!tag) - return XML_ERROR_NO_MEMORY; - tag->buf = (char *)MALLOC(parser, INIT_TAG_BUF_SIZE); - if (!tag->buf) { - FREE(parser, tag); - return XML_ERROR_NO_MEMORY; - } - tag->bufEnd = tag->buf + INIT_TAG_BUF_SIZE; - } - tag->bindings = NULL; - tag->parent = parser->m_tagStack; - parser->m_tagStack = tag; - tag->name.localPart = NULL; - tag->name.prefix = NULL; - tag->rawName = s + enc->minBytesPerChar; - tag->rawNameLength = XmlNameLength(enc, tag->rawName); - ++parser->m_tagLevel; - { - const char *rawNameEnd = tag->rawName + tag->rawNameLength; - const char *fromPtr = tag->rawName; - toPtr = (XML_Char *)tag->buf; - for (;;) { - int bufSize; - int convLen; - const enum XML_Convert_Result convert_res = XmlConvert(enc, - &fromPtr, rawNameEnd, - (ICHAR **)&toPtr, (ICHAR *)tag->bufEnd - 1); - convLen = (int)(toPtr - (XML_Char *)tag->buf); - if ((fromPtr >= rawNameEnd) || (convert_res == XML_CONVERT_INPUT_INCOMPLETE)) { - tag->name.strLen = convLen; - break; - } - bufSize = (int)(tag->bufEnd - tag->buf) << 1; - { - char *temp = (char *)REALLOC(parser, tag->buf, bufSize); - if (temp == NULL) - return XML_ERROR_NO_MEMORY; - tag->buf = temp; - tag->bufEnd = temp + bufSize; - toPtr = (XML_Char *)temp + convLen; - } - } - } - tag->name.str = (XML_Char *)tag->buf; - *toPtr = XML_T('\0'); - result = storeAtts(parser, enc, s, &(tag->name), &(tag->bindings)); - if (result) - return result; - if (parser->m_startElementHandler) - parser->m_startElementHandler(parser->m_handlerArg, tag->name.str, - (const XML_Char **)parser->m_atts); - else if (parser->m_defaultHandler) - reportDefault(parser, enc, s, next); - poolClear(&parser->m_tempPool); - break; - } - case XML_TOK_EMPTY_ELEMENT_NO_ATTS: - /* fall through */ - case XML_TOK_EMPTY_ELEMENT_WITH_ATTS: - { - const char *rawName = s + enc->minBytesPerChar; - enum XML_Error result; - BINDING *bindings = NULL; - XML_Bool noElmHandlers = XML_TRUE; - TAG_NAME name; - name.str = poolStoreString(&parser->m_tempPool, enc, rawName, - rawName + XmlNameLength(enc, rawName)); - if (!name.str) - return XML_ERROR_NO_MEMORY; - poolFinish(&parser->m_tempPool); - result = storeAtts(parser, enc, s, &name, &bindings); - if (result != XML_ERROR_NONE) { - freeBindings(parser, bindings); - return result; - } - poolFinish(&parser->m_tempPool); - if (parser->m_startElementHandler) { - parser->m_startElementHandler(parser->m_handlerArg, name.str, (const XML_Char **)parser->m_atts); - noElmHandlers = XML_FALSE; - } - if (parser->m_endElementHandler) { - if (parser->m_startElementHandler) - *eventPP = *eventEndPP; - parser->m_endElementHandler(parser->m_handlerArg, name.str); - noElmHandlers = XML_FALSE; - } - if (noElmHandlers && parser->m_defaultHandler) - reportDefault(parser, enc, s, next); - poolClear(&parser->m_tempPool); - freeBindings(parser, bindings); - } - if ((parser->m_tagLevel == 0) && (parser->m_parsingStatus.parsing != XML_FINISHED)) { + case XML_TOK_ENTITY_REF: { + const XML_Char *name; + ENTITY *entity; + XML_Char ch = (XML_Char)XmlPredefinedEntityName( + enc, s + enc->minBytesPerChar, next - enc->minBytesPerChar); + if (ch) { + if (parser->m_characterDataHandler) + parser->m_characterDataHandler(parser->m_handlerArg, &ch, 1); + else if (parser->m_defaultHandler) + reportDefault(parser, enc, s, next); + break; + } + name = poolStoreString(&dtd->pool, enc, s + enc->minBytesPerChar, + next - enc->minBytesPerChar); + if (! name) + return XML_ERROR_NO_MEMORY; + entity = (ENTITY *)lookup(parser, &dtd->generalEntities, name, 0); + poolDiscard(&dtd->pool); + /* First, determine if a check for an existing declaration is needed; + if yes, check that the entity exists, and that it is internal, + otherwise call the skipped entity or default handler. + */ + if (! dtd->hasParamEntityRefs || dtd->standalone) { + if (! entity) + return XML_ERROR_UNDEFINED_ENTITY; + else if (! entity->is_internal) + return XML_ERROR_ENTITY_DECLARED_IN_PE; + } else if (! entity) { + if (parser->m_skippedEntityHandler) + parser->m_skippedEntityHandler(parser->m_handlerArg, name, 0); + else if (parser->m_defaultHandler) + reportDefault(parser, enc, s, next); + break; + } + if (entity->open) + return XML_ERROR_RECURSIVE_ENTITY_REF; + if (entity->notation) + return XML_ERROR_BINARY_ENTITY_REF; + if (entity->textPtr) { + enum XML_Error result; + if (! parser->m_defaultExpandInternalEntities) { + if (parser->m_skippedEntityHandler) + parser->m_skippedEntityHandler(parser->m_handlerArg, entity->name, + 0); + else if (parser->m_defaultHandler) + reportDefault(parser, enc, s, next); + break; + } + result = processInternalEntity(parser, entity, XML_FALSE); + if (result != XML_ERROR_NONE) + return result; + } else if (parser->m_externalEntityRefHandler) { + const XML_Char *context; + entity->open = XML_TRUE; + context = getContext(parser); + entity->open = XML_FALSE; + if (! context) + return XML_ERROR_NO_MEMORY; + if (! parser->m_externalEntityRefHandler( + parser->m_externalEntityRefHandlerArg, context, entity->base, + entity->systemId, entity->publicId)) + return XML_ERROR_EXTERNAL_ENTITY_HANDLING; + poolDiscard(&parser->m_tempPool); + } else if (parser->m_defaultHandler) + reportDefault(parser, enc, s, next); + break; + } + case XML_TOK_START_TAG_NO_ATTS: + /* fall through */ + case XML_TOK_START_TAG_WITH_ATTS: { + TAG *tag; + enum XML_Error result; + XML_Char *toPtr; + if (parser->m_freeTagList) { + tag = parser->m_freeTagList; + parser->m_freeTagList = parser->m_freeTagList->parent; + } else { + tag = (TAG *)MALLOC(parser, sizeof(TAG)); + if (! tag) + return XML_ERROR_NO_MEMORY; + tag->buf = (char *)MALLOC(parser, INIT_TAG_BUF_SIZE); + if (! tag->buf) { + FREE(parser, tag); + return XML_ERROR_NO_MEMORY; + } + tag->bufEnd = tag->buf + INIT_TAG_BUF_SIZE; + } + tag->bindings = NULL; + tag->parent = parser->m_tagStack; + parser->m_tagStack = tag; + tag->name.localPart = NULL; + tag->name.prefix = NULL; + tag->rawName = s + enc->minBytesPerChar; + tag->rawNameLength = XmlNameLength(enc, tag->rawName); + ++parser->m_tagLevel; + { + const char *rawNameEnd = tag->rawName + tag->rawNameLength; + const char *fromPtr = tag->rawName; + toPtr = (XML_Char *)tag->buf; + for (;;) { + int bufSize; + int convLen; + const enum XML_Convert_Result convert_res + = XmlConvert(enc, &fromPtr, rawNameEnd, (ICHAR **)&toPtr, + (ICHAR *)tag->bufEnd - 1); + convLen = (int)(toPtr - (XML_Char *)tag->buf); + if ((fromPtr >= rawNameEnd) + || (convert_res == XML_CONVERT_INPUT_INCOMPLETE)) { + tag->name.strLen = convLen; + break; + } + bufSize = (int)(tag->bufEnd - tag->buf) << 1; + { + char *temp = (char *)REALLOC(parser, tag->buf, bufSize); + if (temp == NULL) + return XML_ERROR_NO_MEMORY; + tag->buf = temp; + tag->bufEnd = temp + bufSize; + toPtr = (XML_Char *)temp + convLen; + } + } + } + tag->name.str = (XML_Char *)tag->buf; + *toPtr = XML_T('\0'); + result = storeAtts(parser, enc, s, &(tag->name), &(tag->bindings)); + if (result) + return result; + if (parser->m_startElementHandler) + parser->m_startElementHandler(parser->m_handlerArg, tag->name.str, + (const XML_Char **)parser->m_atts); + else if (parser->m_defaultHandler) + reportDefault(parser, enc, s, next); + poolClear(&parser->m_tempPool); + break; + } + case XML_TOK_EMPTY_ELEMENT_NO_ATTS: + /* fall through */ + case XML_TOK_EMPTY_ELEMENT_WITH_ATTS: { + const char *rawName = s + enc->minBytesPerChar; + enum XML_Error result; + BINDING *bindings = NULL; + XML_Bool noElmHandlers = XML_TRUE; + TAG_NAME name; + name.str = poolStoreString(&parser->m_tempPool, enc, rawName, + rawName + XmlNameLength(enc, rawName)); + if (! name.str) + return XML_ERROR_NO_MEMORY; + poolFinish(&parser->m_tempPool); + result = storeAtts(parser, enc, s, &name, &bindings); + if (result != XML_ERROR_NONE) { + freeBindings(parser, bindings); + return result; + } + poolFinish(&parser->m_tempPool); + if (parser->m_startElementHandler) { + parser->m_startElementHandler(parser->m_handlerArg, name.str, + (const XML_Char **)parser->m_atts); + noElmHandlers = XML_FALSE; + } + if (parser->m_endElementHandler) { + if (parser->m_startElementHandler) + *eventPP = *eventEndPP; + parser->m_endElementHandler(parser->m_handlerArg, name.str); + noElmHandlers = XML_FALSE; + } + if (noElmHandlers && parser->m_defaultHandler) + reportDefault(parser, enc, s, next); + poolClear(&parser->m_tempPool); + freeBindings(parser, bindings); + } + if ((parser->m_tagLevel == 0) + && (parser->m_parsingStatus.parsing != XML_FINISHED)) { if (parser->m_parsingStatus.parsing == XML_SUSPENDED) parser->m_processor = epilogProcessor; else return epilogProcessor(parser, next, end, nextPtr); } @@ -2944,11 +2810,11 @@ const char *rawName; TAG *tag = parser->m_tagStack; parser->m_tagStack = tag->parent; tag->parent = parser->m_freeTagList; parser->m_freeTagList = tag; - rawName = s + enc->minBytesPerChar*2; + rawName = s + enc->minBytesPerChar * 2; len = XmlNameLength(enc, rawName); if (len != tag->rawNameLength || memcmp(tag->rawName, rawName, len) != 0) { *eventPP = rawName; return XML_ERROR_TAG_MISMATCH; @@ -2964,108 +2830,110 @@ tag->name.str, since this points to the binding->uri buffer which gets re-used; so we have to add them again */ uri = (XML_Char *)tag->name.str + tag->name.uriLen; /* don't need to check for space - already done in storeAtts() */ - while (*localPart) *uri++ = *localPart++; + while (*localPart) + *uri++ = *localPart++; prefix = (XML_Char *)tag->name.prefix; if (parser->m_ns_triplets && prefix) { *uri++ = parser->m_namespaceSeparator; - while (*prefix) *uri++ = *prefix++; - } + while (*prefix) + *uri++ = *prefix++; + } *uri = XML_T('\0'); } parser->m_endElementHandler(parser->m_handlerArg, tag->name.str); - } - else if (parser->m_defaultHandler) + } else if (parser->m_defaultHandler) reportDefault(parser, enc, s, next); while (tag->bindings) { BINDING *b = tag->bindings; if (parser->m_endNamespaceDeclHandler) - parser->m_endNamespaceDeclHandler(parser->m_handlerArg, b->prefix->name); + parser->m_endNamespaceDeclHandler(parser->m_handlerArg, + b->prefix->name); tag->bindings = tag->bindings->nextTagBinding; b->nextTagBinding = parser->m_freeBindingList; parser->m_freeBindingList = b; b->prefix->binding = b->prevPrefixBinding; } - if (parser->m_tagLevel == 0) - return epilogProcessor(parser, next, end, nextPtr); - } - break; - case XML_TOK_CHAR_REF: - { - int n = XmlCharRefNumber(enc, s); - if (n < 0) - return XML_ERROR_BAD_CHAR_REF; - if (parser->m_characterDataHandler) { - XML_Char buf[XML_ENCODE_MAX]; - parser->m_characterDataHandler(parser->m_handlerArg, buf, XmlEncode(n, (ICHAR *)buf)); - } - else if (parser->m_defaultHandler) - reportDefault(parser, enc, s, next); - } - break; + if ((parser->m_tagLevel == 0) + && (parser->m_parsingStatus.parsing != XML_FINISHED)) { + if (parser->m_parsingStatus.parsing == XML_SUSPENDED) + parser->m_processor = epilogProcessor; + else + return epilogProcessor(parser, next, end, nextPtr); + } + } + break; + case XML_TOK_CHAR_REF: { + int n = XmlCharRefNumber(enc, s); + if (n < 0) + return XML_ERROR_BAD_CHAR_REF; + if (parser->m_characterDataHandler) { + XML_Char buf[XML_ENCODE_MAX]; + parser->m_characterDataHandler(parser->m_handlerArg, buf, + XmlEncode(n, (ICHAR *)buf)); + } else if (parser->m_defaultHandler) + reportDefault(parser, enc, s, next); + } break; case XML_TOK_XML_DECL: return XML_ERROR_MISPLACED_XML_PI; case XML_TOK_DATA_NEWLINE: if (parser->m_characterDataHandler) { XML_Char c = 0xA; parser->m_characterDataHandler(parser->m_handlerArg, &c, 1); - } - else if (parser->m_defaultHandler) - reportDefault(parser, enc, s, next); - break; - case XML_TOK_CDATA_SECT_OPEN: - { - enum XML_Error result; - if (parser->m_startCdataSectionHandler) - parser->m_startCdataSectionHandler(parser->m_handlerArg); -#if 0 - /* Suppose you doing a transformation on a document that involves - changing only the character data. You set up a defaultHandler - and a characterDataHandler. The defaultHandler simply copies - characters through. The characterDataHandler does the - transformation and writes the characters out escaping them as - necessary. This case will fail to work if we leave out the - following two lines (because & and < inside CDATA sections will - be incorrectly escaped). - - However, now we have a start/endCdataSectionHandler, so it seems - easier to let the user deal with this. - */ - else if (parser->m_characterDataHandler) - parser->m_characterDataHandler(parser->m_handlerArg, parser->m_dataBuf, 0); -#endif - else if (parser->m_defaultHandler) - reportDefault(parser, enc, s, next); - result = doCdataSection(parser, enc, &next, end, nextPtr, haveMore); - if (result != XML_ERROR_NONE) - return result; - else if (!next) { - parser->m_processor = cdataSectionProcessor; - return result; - } - } - break; + } else if (parser->m_defaultHandler) + reportDefault(parser, enc, s, next); + break; + case XML_TOK_CDATA_SECT_OPEN: { + enum XML_Error result; + if (parser->m_startCdataSectionHandler) + parser->m_startCdataSectionHandler(parser->m_handlerArg); + /* BEGIN disabled code */ + /* Suppose you doing a transformation on a document that involves + changing only the character data. You set up a defaultHandler + and a characterDataHandler. The defaultHandler simply copies + characters through. The characterDataHandler does the + transformation and writes the characters out escaping them as + necessary. This case will fail to work if we leave out the + following two lines (because & and < inside CDATA sections will + be incorrectly escaped). + + However, now we have a start/endCdataSectionHandler, so it seems + easier to let the user deal with this. + */ + else if (0 && parser->m_characterDataHandler) + parser->m_characterDataHandler(parser->m_handlerArg, parser->m_dataBuf, + 0); + /* END disabled code */ + else if (parser->m_defaultHandler) + reportDefault(parser, enc, s, next); + result = doCdataSection(parser, enc, &next, end, nextPtr, haveMore); + if (result != XML_ERROR_NONE) + return result; + else if (! next) { + parser->m_processor = cdataSectionProcessor; + return result; + } + } break; case XML_TOK_TRAILING_RSQB: if (haveMore) { *nextPtr = s; return XML_ERROR_NONE; } if (parser->m_characterDataHandler) { if (MUST_CONVERT(enc, s)) { ICHAR *dataPtr = (ICHAR *)parser->m_dataBuf; XmlConvert(enc, &s, end, &dataPtr, (ICHAR *)parser->m_dataBufEnd); - parser->m_characterDataHandler(parser->m_handlerArg, parser->m_dataBuf, - (int)(dataPtr - (ICHAR *)parser->m_dataBuf)); - } - else - parser->m_characterDataHandler(parser->m_handlerArg, - (XML_Char *)s, - (int)((XML_Char *)end - (XML_Char *)s)); - } - else if (parser->m_defaultHandler) + parser->m_characterDataHandler( + parser->m_handlerArg, parser->m_dataBuf, + (int)(dataPtr - (ICHAR *)parser->m_dataBuf)); + } else + parser->m_characterDataHandler( + parser->m_handlerArg, (XML_Char *)s, + (int)((XML_Char *)end - (XML_Char *)s)); + } else if (parser->m_defaultHandler) reportDefault(parser, enc, s, end); /* We are at the end of the final buffer, should we check for XML_SUSPENDED, XML_FINISHED? */ if (startTagLevel == 0) { @@ -3076,41 +2944,38 @@ *eventPP = end; return XML_ERROR_ASYNC_ENTITY; } *nextPtr = end; return XML_ERROR_NONE; - case XML_TOK_DATA_CHARS: - { - XML_CharacterDataHandler charDataHandler = parser->m_characterDataHandler; - if (charDataHandler) { - if (MUST_CONVERT(enc, s)) { - for (;;) { - ICHAR *dataPtr = (ICHAR *)parser->m_dataBuf; - const enum XML_Convert_Result convert_res = XmlConvert(enc, &s, next, &dataPtr, (ICHAR *)parser->m_dataBufEnd); - *eventEndPP = s; - charDataHandler(parser->m_handlerArg, parser->m_dataBuf, - (int)(dataPtr - (ICHAR *)parser->m_dataBuf)); - if ((convert_res == XML_CONVERT_COMPLETED) || (convert_res == XML_CONVERT_INPUT_INCOMPLETE)) - break; - *eventPP = s; - } - } - else - charDataHandler(parser->m_handlerArg, - (XML_Char *)s, - (int)((XML_Char *)next - (XML_Char *)s)); - } - else if (parser->m_defaultHandler) - reportDefault(parser, enc, s, next); - } - break; + case XML_TOK_DATA_CHARS: { + XML_CharacterDataHandler charDataHandler = parser->m_characterDataHandler; + if (charDataHandler) { + if (MUST_CONVERT(enc, s)) { + for (;;) { + ICHAR *dataPtr = (ICHAR *)parser->m_dataBuf; + const enum XML_Convert_Result convert_res = XmlConvert( + enc, &s, next, &dataPtr, (ICHAR *)parser->m_dataBufEnd); + *eventEndPP = s; + charDataHandler(parser->m_handlerArg, parser->m_dataBuf, + (int)(dataPtr - (ICHAR *)parser->m_dataBuf)); + if ((convert_res == XML_CONVERT_COMPLETED) + || (convert_res == XML_CONVERT_INPUT_INCOMPLETE)) + break; + *eventPP = s; + } + } else + charDataHandler(parser->m_handlerArg, (XML_Char *)s, + (int)((XML_Char *)next - (XML_Char *)s)); + } else if (parser->m_defaultHandler) + reportDefault(parser, enc, s, next); + } break; case XML_TOK_PI: - if (!reportProcessingInstruction(parser, enc, s, next)) + if (! reportProcessingInstruction(parser, enc, s, next)) return XML_ERROR_NO_MEMORY; break; case XML_TOK_COMMENT: - if (!reportComment(parser, enc, s, next)) + if (! reportComment(parser, enc, s, next)) return XML_ERROR_NO_MEMORY; break; default: /* All of the tokens produced by XmlContentTok() have their own * explicit cases, so this default is not strictly necessary. @@ -3129,11 +2994,11 @@ case XML_SUSPENDED: *nextPtr = next; return XML_ERROR_NONE; case XML_FINISHED: return XML_ERROR_ABORTED; - default: ; + default:; } } /* not reached */ } @@ -3140,20 +3005,19 @@ /* This function does not call free() on the allocated memory, merely * moving it to the parser's m_freeBindingList where it can be freed or * reused as appropriate. */ static void -freeBindings(XML_Parser parser, BINDING *bindings) -{ +freeBindings(XML_Parser parser, BINDING *bindings) { while (bindings) { BINDING *b = bindings; /* m_startNamespaceDeclHandler will have been called for this * binding in addBindings(), so call the end handler now. */ if (parser->m_endNamespaceDeclHandler) - parser->m_endNamespaceDeclHandler(parser->m_handlerArg, b->prefix->name); + parser->m_endNamespaceDeclHandler(parser->m_handlerArg, b->prefix->name); bindings = bindings->nextTagBinding; b->nextTagBinding = parser->m_freeBindingList; parser->m_freeBindingList = b; b->prefix->binding = b->prevPrefixBinding; @@ -3169,18 +3033,16 @@ - default attributes - process namespace declarations (check and report them) - generate namespace aware element name (URI, prefix) */ static enum XML_Error -storeAtts(XML_Parser parser, const ENCODING *enc, - const char *attStr, TAG_NAME *tagNamePtr, - BINDING **bindingsPtr) -{ - DTD * const dtd = parser->m_dtd; /* save one level of indirection */ +storeAtts(XML_Parser parser, const ENCODING *enc, const char *attStr, + TAG_NAME *tagNamePtr, BINDING **bindingsPtr) { + DTD *const dtd = parser->m_dtd; /* save one level of indirection */ ELEMENT_TYPE *elementType; int nDefaultAtts; - const XML_Char **appAtts; /* the attribute list for the application */ + const XML_Char **appAtts; /* the attribute list for the application */ int attIndex = 0; int prefixLen; int i; int n; XML_Char *uri; @@ -3187,20 +3049,21 @@ int nPrefixes = 0; BINDING *binding; const XML_Char *localPart; /* lookup the element type name */ - elementType = (ELEMENT_TYPE *)lookup(parser, &dtd->elementTypes, tagNamePtr->str,0); - if (!elementType) { + elementType + = (ELEMENT_TYPE *)lookup(parser, &dtd->elementTypes, tagNamePtr->str, 0); + if (! elementType) { const XML_Char *name = poolCopyString(&dtd->pool, tagNamePtr->str); - if (!name) + if (! name) return XML_ERROR_NO_MEMORY; elementType = (ELEMENT_TYPE *)lookup(parser, &dtd->elementTypes, name, sizeof(ELEMENT_TYPE)); - if (!elementType) + if (! elementType) return XML_ERROR_NO_MEMORY; - if (parser->m_ns && !setElementTypePrefix(parser, elementType)) + if (parser->m_ns && ! setElementTypePrefix(parser, elementType)) return XML_ERROR_NO_MEMORY; } nDefaultAtts = elementType->nDefaultAtts; /* get the attributes from the tokenizer */ @@ -3210,18 +3073,20 @@ ATTRIBUTE *temp; #ifdef XML_ATTR_INFO XML_AttrInfo *temp2; #endif parser->m_attsSize = n + nDefaultAtts + INIT_ATTS_SIZE; - temp = (ATTRIBUTE *)REALLOC(parser, (void *)parser->m_atts, parser->m_attsSize * sizeof(ATTRIBUTE)); + temp = (ATTRIBUTE *)REALLOC(parser, (void *)parser->m_atts, + parser->m_attsSize * sizeof(ATTRIBUTE)); if (temp == NULL) { parser->m_attsSize = oldAttsSize; return XML_ERROR_NO_MEMORY; } parser->m_atts = temp; #ifdef XML_ATTR_INFO - temp2 = (XML_AttrInfo *)REALLOC(parser, (void *)parser->m_attInfo, parser->m_attsSize * sizeof(XML_AttrInfo)); + temp2 = (XML_AttrInfo *)REALLOC(parser, (void *)parser->m_attInfo, + parser->m_attsSize * sizeof(XML_AttrInfo)); if (temp2 == NULL) { parser->m_attsSize = oldAttsSize; return XML_ERROR_NO_MEMORY; } parser->m_attInfo = temp2; @@ -3235,22 +3100,24 @@ ATTRIBUTE *currAtt = &parser->m_atts[i]; #ifdef XML_ATTR_INFO XML_AttrInfo *currAttInfo = &parser->m_attInfo[i]; #endif /* add the name and value to the attribute list */ - ATTRIBUTE_ID *attId = getAttributeId(parser, enc, currAtt->name, - currAtt->name - + XmlNameLength(enc, currAtt->name)); - if (!attId) + ATTRIBUTE_ID *attId + = getAttributeId(parser, enc, currAtt->name, + currAtt->name + XmlNameLength(enc, currAtt->name)); + if (! attId) return XML_ERROR_NO_MEMORY; #ifdef XML_ATTR_INFO - currAttInfo->nameStart = parser->m_parseEndByteIndex - (parser->m_parseEndPtr - currAtt->name); - currAttInfo->nameEnd = currAttInfo->nameStart + - XmlNameLength(enc, currAtt->name); - currAttInfo->valueStart = parser->m_parseEndByteIndex - - (parser->m_parseEndPtr - currAtt->valuePtr); - currAttInfo->valueEnd = parser->m_parseEndByteIndex - (parser->m_parseEndPtr - currAtt->valueEnd); + currAttInfo->nameStart + = parser->m_parseEndByteIndex - (parser->m_parseEndPtr - currAtt->name); + currAttInfo->nameEnd + = currAttInfo->nameStart + XmlNameLength(enc, currAtt->name); + currAttInfo->valueStart = parser->m_parseEndByteIndex + - (parser->m_parseEndPtr - currAtt->valuePtr); + currAttInfo->valueEnd = parser->m_parseEndByteIndex + - (parser->m_parseEndPtr - currAtt->valueEnd); #endif /* Detect duplicate attributes by their QNames. This does not work when namespace processing is turned on and different prefixes for the same namespace are used. For this case we have a check further down. */ @@ -3259,11 +3126,11 @@ parser->m_eventPtr = parser->m_atts[i].name; return XML_ERROR_DUPLICATE_ATTRIBUTE; } (attId->name)[-1] = 1; appAtts[attIndex++] = attId->name; - if (!parser->m_atts[i].normalized) { + if (! parser->m_atts[i].normalized) { enum XML_Error result; XML_Bool isCdata = XML_TRUE; /* figure out whether declared as other than CDATA */ if (attId->maybeTokenized) { @@ -3275,21 +3142,21 @@ } } } /* normalize the attribute value */ - result = storeAttributeValue(parser, enc, isCdata, - parser->m_atts[i].valuePtr, parser->m_atts[i].valueEnd, - &parser->m_tempPool); + result = storeAttributeValue( + parser, enc, isCdata, parser->m_atts[i].valuePtr, + parser->m_atts[i].valueEnd, &parser->m_tempPool); if (result) return result; appAtts[attIndex] = poolStart(&parser->m_tempPool); poolFinish(&parser->m_tempPool); - } - else { + } else { /* the value did not need normalizing */ - appAtts[attIndex] = poolStoreString(&parser->m_tempPool, enc, parser->m_atts[i].valuePtr, + appAtts[attIndex] = poolStoreString(&parser->m_tempPool, enc, + parser->m_atts[i].valuePtr, parser->m_atts[i].valueEnd); if (appAtts[attIndex] == 0) return XML_ERROR_NO_MEMORY; poolFinish(&parser->m_tempPool); } @@ -3300,19 +3167,17 @@ enum XML_Error result = addBinding(parser, attId->prefix, attId, appAtts[attIndex], bindingsPtr); if (result) return result; --attIndex; - } - else { + } else { /* deal with other prefixed names later */ attIndex++; nPrefixes++; (attId->name)[-1] = 2; } - } - else + } else attIndex++; } /* set-up for XML_GetSpecifiedAttributeCount and XML_GetIdAttributeIndex */ parser->m_nSpecifiedAtts = attIndex; @@ -3320,33 +3185,30 @@ for (i = 0; i < attIndex; i += 2) if (appAtts[i] == elementType->idAtt->name) { parser->m_idAttIndex = i; break; } - } - else + } else parser->m_idAttIndex = -1; /* do attribute defaulting */ for (i = 0; i < nDefaultAtts; i++) { const DEFAULT_ATTRIBUTE *da = elementType->defaultAtts + i; - if (!(da->id->name)[-1] && da->value) { + if (! (da->id->name)[-1] && da->value) { if (da->id->prefix) { if (da->id->xmlns) { enum XML_Error result = addBinding(parser, da->id->prefix, da->id, da->value, bindingsPtr); if (result) return result; - } - else { + } else { (da->id->name)[-1] = 2; nPrefixes++; appAtts[attIndex++] = da->id->name; appAtts[attIndex++] = da->value; } - } - else { + } else { (da->id->name)[-1] = 1; appAtts[attIndex++] = da->id->name; appAtts[attIndex++] = da->value; } } @@ -3355,55 +3217,58 @@ /* expand prefixed attribute names, check for duplicates, and clear flags that say whether attributes were specified */ i = 0; if (nPrefixes) { - int j; /* hash table index */ + int j; /* hash table index */ unsigned long version = parser->m_nsAttsVersion; int nsAttsSize = (int)1 << parser->m_nsAttsPower; unsigned char oldNsAttsPower = parser->m_nsAttsPower; /* size of hash table must be at least 2 * (# of prefixed attributes) */ - if ((nPrefixes << 1) >> parser->m_nsAttsPower) { /* true for m_nsAttsPower = 0 */ + if ((nPrefixes << 1) + >> parser->m_nsAttsPower) { /* true for m_nsAttsPower = 0 */ NS_ATT *temp; /* hash table size must also be a power of 2 and >= 8 */ - while (nPrefixes >> parser->m_nsAttsPower++); + while (nPrefixes >> parser->m_nsAttsPower++) + ; if (parser->m_nsAttsPower < 3) parser->m_nsAttsPower = 3; nsAttsSize = (int)1 << parser->m_nsAttsPower; - temp = (NS_ATT *)REALLOC(parser, parser->m_nsAtts, nsAttsSize * sizeof(NS_ATT)); - if (!temp) { + temp = (NS_ATT *)REALLOC(parser, parser->m_nsAtts, + nsAttsSize * sizeof(NS_ATT)); + if (! temp) { /* Restore actual size of memory in m_nsAtts */ parser->m_nsAttsPower = oldNsAttsPower; return XML_ERROR_NO_MEMORY; } parser->m_nsAtts = temp; - version = 0; /* force re-initialization of m_nsAtts hash table */ + version = 0; /* force re-initialization of m_nsAtts hash table */ } /* using a version flag saves us from initializing m_nsAtts every time */ - if (!version) { /* initialize version flags when version wraps around */ + if (! version) { /* initialize version flags when version wraps around */ version = INIT_ATTS_VERSION; - for (j = nsAttsSize; j != 0; ) + for (j = nsAttsSize; j != 0;) parser->m_nsAtts[--j].version = version; } parser->m_nsAttsVersion = --version; /* expand prefixed names and check for duplicates */ for (; i < attIndex; i += 2) { const XML_Char *s = appAtts[i]; - if (s[-1] == 2) { /* prefixed */ + if (s[-1] == 2) { /* prefixed */ ATTRIBUTE_ID *id; const BINDING *b; unsigned long uriHash; struct siphash sip_state; struct sipkey sip_key; copy_salt_to_sipkey(parser, &sip_key); sip24_init(&sip_state, &sip_key); - ((XML_Char *)s)[-1] = 0; /* clear flag */ + ((XML_Char *)s)[-1] = 0; /* clear flag */ id = (ATTRIBUTE_ID *)lookup(parser, &dtd->attributeIds, s, 0); - if (!id || !id->prefix) { + if (! id || ! id->prefix) { /* This code is walking through the appAtts array, dealing * with (in this case) a prefixed attribute name. To be in * the array, the attribute must have already been bound, so * has to have passed through the hash table lookup once * already. That implies that an entry for it already @@ -3417,16 +3282,16 @@ * remove the code from coverage tests. */ return XML_ERROR_NO_MEMORY; /* LCOV_EXCL_LINE */ } b = id->prefix->binding; - if (!b) + if (! b) return XML_ERROR_UNBOUND_PREFIX; for (j = 0; j < b->uriLen; j++) { const XML_Char c = b->uri[j]; - if (!poolAppendChar(&parser->m_tempPool, c)) + if (! poolAppendChar(&parser->m_tempPool, c)) return XML_ERROR_NO_MEMORY; } sip24_update(&sip_state, b->uri, b->uriLen * sizeof(XML_Char)); @@ -3433,12 +3298,12 @@ while (*s++ != XML_T(ASCII_COLON)) ; sip24_update(&sip_state, s, keylen(s) * sizeof(XML_Char)); - do { /* copies null terminator */ - if (!poolAppendChar(&parser->m_tempPool, *s)) + do { /* copies null terminator */ + if (! poolAppendChar(&parser->m_tempPool, *s)) return XML_ERROR_NO_MEMORY; } while (*s++); uriHash = (unsigned long)sip24_final(&sip_state); @@ -3445,32 +3310,33 @@ { /* Check hash table for duplicate of expanded name (uriName). Derived from code in lookup(parser, HASH_TABLE *table, ...). */ unsigned char step = 0; unsigned long mask = nsAttsSize - 1; - j = uriHash & mask; /* index into hash table */ + j = uriHash & mask; /* index into hash table */ while (parser->m_nsAtts[j].version == version) { /* for speed we compare stored hash values first */ if (uriHash == parser->m_nsAtts[j].hash) { const XML_Char *s1 = poolStart(&parser->m_tempPool); const XML_Char *s2 = parser->m_nsAtts[j].uriName; /* s1 is null terminated, but not s2 */ - for (; *s1 == *s2 && *s1 != 0; s1++, s2++); + for (; *s1 == *s2 && *s1 != 0; s1++, s2++) + ; if (*s1 == 0) return XML_ERROR_DUPLICATE_ATTRIBUTE; } - if (!step) + if (! step) step = PROBE_STEP(uriHash, mask, parser->m_nsAttsPower); j < step ? (j += nsAttsSize - step) : (j -= step); } } - if (parser->m_ns_triplets) { /* append namespace separator and prefix */ + if (parser->m_ns_triplets) { /* append namespace separator and prefix */ parser->m_tempPool.ptr[-1] = parser->m_namespaceSeparator; s = b->prefix->name; do { - if (!poolAppendChar(&parser->m_tempPool, *s)) + if (! poolAppendChar(&parser->m_tempPool, *s)) return XML_ERROR_NO_MEMORY; } while (*s++); } /* store expanded name in attribute list */ @@ -3481,59 +3347,56 @@ /* fill empty slot with new version, uriName and hash value */ parser->m_nsAtts[j].version = version; parser->m_nsAtts[j].hash = uriHash; parser->m_nsAtts[j].uriName = s; - if (!--nPrefixes) { + if (! --nPrefixes) { i += 2; break; } - } - else /* not prefixed */ - ((XML_Char *)s)[-1] = 0; /* clear flag */ + } else /* not prefixed */ + ((XML_Char *)s)[-1] = 0; /* clear flag */ } } /* clear flags for the remaining attributes */ for (; i < attIndex; i += 2) ((XML_Char *)(appAtts[i]))[-1] = 0; for (binding = *bindingsPtr; binding; binding = binding->nextTagBinding) binding->attId->name[-1] = 0; - if (!parser->m_ns) + if (! parser->m_ns) return XML_ERROR_NONE; /* expand the element type name */ if (elementType->prefix) { binding = elementType->prefix->binding; - if (!binding) + if (! binding) return XML_ERROR_UNBOUND_PREFIX; localPart = tagNamePtr->str; while (*localPart++ != XML_T(ASCII_COLON)) ; - } - else if (dtd->defaultPrefix.binding) { + } else if (dtd->defaultPrefix.binding) { binding = dtd->defaultPrefix.binding; localPart = tagNamePtr->str; - } - else + } else return XML_ERROR_NONE; prefixLen = 0; if (parser->m_ns_triplets && binding->prefix->name) { for (; binding->prefix->name[prefixLen++];) - ; /* prefixLen includes null terminator */ + ; /* prefixLen includes null terminator */ } tagNamePtr->localPart = localPart; tagNamePtr->uriLen = binding->uriLen; tagNamePtr->prefix = binding->prefix->name; tagNamePtr->prefixLen = prefixLen; for (i = 0; localPart[i++];) - ; /* i includes null terminator */ + ; /* i includes null terminator */ n = i + binding->uriLen + prefixLen; if (n > binding->uriAlloc) { TAG *p; uri = (XML_Char *)MALLOC(parser, (n + EXPAND_SPARE) * sizeof(XML_Char)); - if (!uri) + if (! uri) return XML_ERROR_NO_MEMORY; binding->uriAlloc = n + EXPAND_SPARE; memcpy(uri, binding->uri, binding->uriLen * sizeof(XML_Char)); for (p = parser->m_tagStack; p; p = p->parent) if (p->name.str == binding->uri) @@ -3545,11 +3408,11 @@ uri = binding->uri + binding->uriLen; memcpy(uri, localPart, i * sizeof(XML_Char)); /* we always have a namespace separator between localPart and prefix */ if (prefixLen) { uri += i - 1; - *uri = parser->m_namespaceSeparator; /* replace null terminator */ + *uri = parser->m_namespaceSeparator; /* replace null terminator */ memcpy(uri + 1, binding->prefix->name, prefixLen * sizeof(XML_Char)); } tagNamePtr->str = binding->uri; return XML_ERROR_NONE; } @@ -3557,31 +3420,29 @@ /* addBinding() overwrites the value of prefix->binding without checking. Therefore one must keep track of the old value outside of addBinding(). */ static enum XML_Error addBinding(XML_Parser parser, PREFIX *prefix, const ATTRIBUTE_ID *attId, - const XML_Char *uri, BINDING **bindingsPtr) -{ - static const XML_Char xmlNamespace[] = { - ASCII_h, ASCII_t, ASCII_t, ASCII_p, ASCII_COLON, ASCII_SLASH, ASCII_SLASH, - ASCII_w, ASCII_w, ASCII_w, ASCII_PERIOD, ASCII_w, ASCII_3, ASCII_PERIOD, - ASCII_o, ASCII_r, ASCII_g, ASCII_SLASH, ASCII_X, ASCII_M, ASCII_L, - ASCII_SLASH, ASCII_1, ASCII_9, ASCII_9, ASCII_8, ASCII_SLASH, - ASCII_n, ASCII_a, ASCII_m, ASCII_e, ASCII_s, ASCII_p, ASCII_a, ASCII_c, - ASCII_e, '\0' - }; - static const int xmlLen = - (int)sizeof(xmlNamespace)/sizeof(XML_Char) - 1; - static const XML_Char xmlnsNamespace[] = { - ASCII_h, ASCII_t, ASCII_t, ASCII_p, ASCII_COLON, ASCII_SLASH, ASCII_SLASH, - ASCII_w, ASCII_w, ASCII_w, ASCII_PERIOD, ASCII_w, ASCII_3, ASCII_PERIOD, - ASCII_o, ASCII_r, ASCII_g, ASCII_SLASH, ASCII_2, ASCII_0, ASCII_0, - ASCII_0, ASCII_SLASH, ASCII_x, ASCII_m, ASCII_l, ASCII_n, ASCII_s, - ASCII_SLASH, '\0' - }; - static const int xmlnsLen = - (int)sizeof(xmlnsNamespace)/sizeof(XML_Char) - 1; + const XML_Char *uri, BINDING **bindingsPtr) { + static const XML_Char xmlNamespace[] + = {ASCII_h, ASCII_t, ASCII_t, ASCII_p, ASCII_COLON, + ASCII_SLASH, ASCII_SLASH, ASCII_w, ASCII_w, ASCII_w, + ASCII_PERIOD, ASCII_w, ASCII_3, ASCII_PERIOD, ASCII_o, + ASCII_r, ASCII_g, ASCII_SLASH, ASCII_X, ASCII_M, + ASCII_L, ASCII_SLASH, ASCII_1, ASCII_9, ASCII_9, + ASCII_8, ASCII_SLASH, ASCII_n, ASCII_a, ASCII_m, + ASCII_e, ASCII_s, ASCII_p, ASCII_a, ASCII_c, + ASCII_e, '\0'}; + static const int xmlLen = (int)sizeof(xmlNamespace) / sizeof(XML_Char) - 1; + static const XML_Char xmlnsNamespace[] + = {ASCII_h, ASCII_t, ASCII_t, ASCII_p, ASCII_COLON, ASCII_SLASH, + ASCII_SLASH, ASCII_w, ASCII_w, ASCII_w, ASCII_PERIOD, ASCII_w, + ASCII_3, ASCII_PERIOD, ASCII_o, ASCII_r, ASCII_g, ASCII_SLASH, + ASCII_2, ASCII_0, ASCII_0, ASCII_0, ASCII_SLASH, ASCII_x, + ASCII_m, ASCII_l, ASCII_n, ASCII_s, ASCII_SLASH, '\0'}; + static const int xmlnsLen + = (int)sizeof(xmlnsNamespace) / sizeof(XML_Char) - 1; XML_Bool mustBeXML = XML_FALSE; XML_Bool isXML = XML_TRUE; XML_Bool isXMLNS = XML_TRUE; @@ -3590,18 +3451,15 @@ /* empty URI is only valid for default namespace per XML NS 1.0 (not 1.1) */ if (*uri == XML_T('\0') && prefix->name) return XML_ERROR_UNDECLARING_PREFIX; - if (prefix->name - && prefix->name[0] == XML_T(ASCII_x) + if (prefix->name && prefix->name[0] == XML_T(ASCII_x) && prefix->name[1] == XML_T(ASCII_m) && prefix->name[2] == XML_T(ASCII_l)) { - /* Not allowed to bind xmlns */ - if (prefix->name[3] == XML_T(ASCII_n) - && prefix->name[4] == XML_T(ASCII_s) + if (prefix->name[3] == XML_T(ASCII_n) && prefix->name[4] == XML_T(ASCII_s) && prefix->name[5] == XML_T('\0')) return XML_ERROR_RESERVED_PREFIX_XMLNS; if (prefix->name[3] == XML_T('\0')) mustBeXML = XML_TRUE; @@ -3609,11 +3467,11 @@ for (len = 0; uri[len]; len++) { if (isXML && (len > xmlLen || uri[len] != xmlNamespace[len])) isXML = XML_FALSE; - if (!mustBeXML && isXMLNS + if (! mustBeXML && isXMLNS && (len > xmlnsLen || uri[len] != xmlnsNamespace[len])) isXMLNS = XML_FALSE; } isXML = isXML && len == xmlLen; isXMLNS = isXMLNS && len == xmlnsLen; @@ -3628,25 +3486,25 @@ if (parser->m_namespaceSeparator) len++; if (parser->m_freeBindingList) { b = parser->m_freeBindingList; if (len > b->uriAlloc) { - XML_Char *temp = (XML_Char *)REALLOC(parser, b->uri, - sizeof(XML_Char) * (len + EXPAND_SPARE)); + XML_Char *temp = (XML_Char *)REALLOC( + parser, b->uri, sizeof(XML_Char) * (len + EXPAND_SPARE)); if (temp == NULL) return XML_ERROR_NO_MEMORY; b->uri = temp; b->uriAlloc = len + EXPAND_SPARE; } parser->m_freeBindingList = b->nextTagBinding; - } - else { + } else { b = (BINDING *)MALLOC(parser, sizeof(BINDING)); - if (!b) + if (! b) return XML_ERROR_NO_MEMORY; - b->uri = (XML_Char *)MALLOC(parser, sizeof(XML_Char) * (len + EXPAND_SPARE)); - if (!b->uri) { + b->uri + = (XML_Char *)MALLOC(parser, sizeof(XML_Char) * (len + EXPAND_SPARE)); + if (! b->uri) { FREE(parser, b); return XML_ERROR_NO_MEMORY; } b->uriAlloc = len + EXPAND_SPARE; } @@ -3665,33 +3523,30 @@ b->nextTagBinding = *bindingsPtr; *bindingsPtr = b; /* if attId == NULL then we are not starting a namespace scope */ if (attId && parser->m_startNamespaceDeclHandler) parser->m_startNamespaceDeclHandler(parser->m_handlerArg, prefix->name, - prefix->binding ? uri : 0); + prefix->binding ? uri : 0); return XML_ERROR_NONE; } /* The idea here is to avoid using stack for each CDATA section when the whole file is parsed with one call. */ static enum XML_Error PTRCALL -cdataSectionProcessor(XML_Parser parser, - const char *start, - const char *end, - const char **endPtr) -{ - enum XML_Error result = doCdataSection(parser, parser->m_encoding, &start, end, - endPtr, (XML_Bool)!parser->m_parsingStatus.finalBuffer); +cdataSectionProcessor(XML_Parser parser, const char *start, const char *end, + const char **endPtr) { + enum XML_Error result + = doCdataSection(parser, parser->m_encoding, &start, end, endPtr, + (XML_Bool)! parser->m_parsingStatus.finalBuffer); if (result != XML_ERROR_NONE) return result; if (start) { - if (parser->m_parentParser) { /* we are parsing an external entity */ + if (parser->m_parentParser) { /* we are parsing an external entity */ parser->m_processor = externalEntityContentProcessor; return externalEntityContentProcessor(parser, start, end, endPtr); - } - else { + } else { parser->m_processor = contentProcessor; return contentProcessor(parser, start, end, endPtr); } } return result; @@ -3699,26 +3554,20 @@ /* startPtr gets set to non-null if the section is closed, and to null if the section is not yet closed. */ static enum XML_Error -doCdataSection(XML_Parser parser, - const ENCODING *enc, - const char **startPtr, - const char *end, - const char **nextPtr, - XML_Bool haveMore) -{ +doCdataSection(XML_Parser parser, const ENCODING *enc, const char **startPtr, + const char *end, const char **nextPtr, XML_Bool haveMore) { const char *s = *startPtr; const char **eventPP; const char **eventEndPP; if (enc == parser->m_encoding) { eventPP = &parser->m_eventPtr; *eventPP = s; eventEndPP = &parser->m_eventEndPtr; - } - else { + } else { eventPP = &(parser->m_openInternalEntities->internalEventPtr); eventEndPP = &(parser->m_openInternalEntities->internalEventEndPtr); } *eventPP = s; *startPtr = NULL; @@ -3729,15 +3578,16 @@ *eventEndPP = next; switch (tok) { case XML_TOK_CDATA_SECT_CLOSE: if (parser->m_endCdataSectionHandler) parser->m_endCdataSectionHandler(parser->m_handlerArg); -#if 0 + /* BEGIN disabled code */ /* see comment under XML_TOK_CDATA_SECT_OPEN */ - else if (parser->m_characterDataHandler) - parser->m_characterDataHandler(parser->m_handlerArg, parser->m_dataBuf, 0); -#endif + else if (0 && parser->m_characterDataHandler) + parser->m_characterDataHandler(parser->m_handlerArg, parser->m_dataBuf, + 0); + /* END disabled code */ else if (parser->m_defaultHandler) reportDefault(parser, enc, s, next); *startPtr = next; *nextPtr = next; if (parser->m_parsingStatus.parsing == XML_FINISHED) @@ -3746,39 +3596,35 @@ return XML_ERROR_NONE; case XML_TOK_DATA_NEWLINE: if (parser->m_characterDataHandler) { XML_Char c = 0xA; parser->m_characterDataHandler(parser->m_handlerArg, &c, 1); - } - else if (parser->m_defaultHandler) - reportDefault(parser, enc, s, next); - break; - case XML_TOK_DATA_CHARS: - { - XML_CharacterDataHandler charDataHandler = parser->m_characterDataHandler; - if (charDataHandler) { - if (MUST_CONVERT(enc, s)) { - for (;;) { - ICHAR *dataPtr = (ICHAR *)parser->m_dataBuf; - const enum XML_Convert_Result convert_res = XmlConvert(enc, &s, next, &dataPtr, (ICHAR *)parser->m_dataBufEnd); - *eventEndPP = next; - charDataHandler(parser->m_handlerArg, parser->m_dataBuf, - (int)(dataPtr - (ICHAR *)parser->m_dataBuf)); - if ((convert_res == XML_CONVERT_COMPLETED) || (convert_res == XML_CONVERT_INPUT_INCOMPLETE)) - break; - *eventPP = s; - } - } - else - charDataHandler(parser->m_handlerArg, - (XML_Char *)s, - (int)((XML_Char *)next - (XML_Char *)s)); - } - else if (parser->m_defaultHandler) - reportDefault(parser, enc, s, next); - } - break; + } else if (parser->m_defaultHandler) + reportDefault(parser, enc, s, next); + break; + case XML_TOK_DATA_CHARS: { + XML_CharacterDataHandler charDataHandler = parser->m_characterDataHandler; + if (charDataHandler) { + if (MUST_CONVERT(enc, s)) { + for (;;) { + ICHAR *dataPtr = (ICHAR *)parser->m_dataBuf; + const enum XML_Convert_Result convert_res = XmlConvert( + enc, &s, next, &dataPtr, (ICHAR *)parser->m_dataBufEnd); + *eventEndPP = next; + charDataHandler(parser->m_handlerArg, parser->m_dataBuf, + (int)(dataPtr - (ICHAR *)parser->m_dataBuf)); + if ((convert_res == XML_CONVERT_COMPLETED) + || (convert_res == XML_CONVERT_INPUT_INCOMPLETE)) + break; + *eventPP = s; + } + } else + charDataHandler(parser->m_handlerArg, (XML_Char *)s, + (int)((XML_Char *)next - (XML_Char *)s)); + } else if (parser->m_defaultHandler) + reportDefault(parser, enc, s, next); + } break; case XML_TOK_INVALID: *eventPP = next; return XML_ERROR_INVALID_TOKEN; case XML_TOK_PARTIAL_CHAR: if (haveMore) { @@ -3798,11 +3644,11 @@ * explicit case, so this default case will never be executed. * We retain it as a safety net and exclude it from the coverage * statistics. * * LCOV_EXCL_START - */ + */ *eventPP = next; return XML_ERROR_UNEXPECTED_STATE; /* LCOV_EXCL_STOP */ } @@ -3811,11 +3657,11 @@ case XML_SUSPENDED: *nextPtr = next; return XML_ERROR_NONE; case XML_FINISHED: return XML_ERROR_ABORTED; - default: ; + default:; } } /* not reached */ } @@ -3823,17 +3669,15 @@ /* The idea here is to avoid using stack for each IGNORE section when the whole file is parsed with one call. */ static enum XML_Error PTRCALL -ignoreSectionProcessor(XML_Parser parser, - const char *start, - const char *end, - const char **endPtr) -{ - enum XML_Error result = doIgnoreSection(parser, parser->m_encoding, &start, end, - endPtr, (XML_Bool)!parser->m_parsingStatus.finalBuffer); +ignoreSectionProcessor(XML_Parser parser, const char *start, const char *end, + const char **endPtr) { + enum XML_Error result + = doIgnoreSection(parser, parser->m_encoding, &start, end, endPtr, + (XML_Bool)! parser->m_parsingStatus.finalBuffer); if (result != XML_ERROR_NONE) return result; if (start) { parser->m_processor = prologProcessor; return prologProcessor(parser, start, end, endPtr); @@ -3843,28 +3687,22 @@ /* startPtr gets set to non-null is the section is closed, and to null if the section is not yet closed. */ static enum XML_Error -doIgnoreSection(XML_Parser parser, - const ENCODING *enc, - const char **startPtr, - const char *end, - const char **nextPtr, - XML_Bool haveMore) -{ +doIgnoreSection(XML_Parser parser, const ENCODING *enc, const char **startPtr, + const char *end, const char **nextPtr, XML_Bool haveMore) { const char *next; int tok; const char *s = *startPtr; const char **eventPP; const char **eventEndPP; if (enc == parser->m_encoding) { eventPP = &parser->m_eventPtr; *eventPP = s; eventEndPP = &parser->m_eventEndPtr; - } - else { + } else { /* It's not entirely clear, but it seems the following two lines * of code cannot be executed. The only occasions on which 'enc' * is not 'encoding' are when this function is called * from the internal entity processing, and IGNORE sections are an * error in internal entities. @@ -3924,17 +3762,16 @@ } #endif /* XML_DTD */ static enum XML_Error -initializeEncoding(XML_Parser parser) -{ +initializeEncoding(XML_Parser parser) { const char *s; #ifdef XML_UNICODE char encodingBuf[128]; /* See comments abount `protoclEncodingName` in parserInit() */ - if (!parser->m_protocolEncodingName) + if (! parser->m_protocolEncodingName) s = NULL; else { int i; for (i = 0; parser->m_protocolEncodingName[i]; i++) { if (i == sizeof(encodingBuf) - 1 @@ -3948,95 +3785,83 @@ s = encodingBuf; } #else s = parser->m_protocolEncodingName; #endif - if ((parser->m_ns ? XmlInitEncodingNS : XmlInitEncoding)(&parser->m_initEncoding, &parser->m_encoding, s)) + if ((parser->m_ns ? XmlInitEncodingNS : XmlInitEncoding)( + &parser->m_initEncoding, &parser->m_encoding, s)) return XML_ERROR_NONE; return handleUnknownEncoding(parser, parser->m_protocolEncodingName); } static enum XML_Error -processXmlDecl(XML_Parser parser, int isGeneralTextEntity, - const char *s, const char *next) -{ +processXmlDecl(XML_Parser parser, int isGeneralTextEntity, const char *s, + const char *next) { const char *encodingName = NULL; const XML_Char *storedEncName = NULL; const ENCODING *newEncoding = NULL; const char *version = NULL; const char *versionend; const XML_Char *storedversion = NULL; int standalone = -1; - if (!(parser->m_ns - ? XmlParseXmlDeclNS - : XmlParseXmlDecl)(isGeneralTextEntity, - parser->m_encoding, - s, - next, - &parser->m_eventPtr, - &version, - &versionend, - &encodingName, - &newEncoding, - &standalone)) { + if (! (parser->m_ns ? XmlParseXmlDeclNS : XmlParseXmlDecl)( + isGeneralTextEntity, parser->m_encoding, s, next, &parser->m_eventPtr, + &version, &versionend, &encodingName, &newEncoding, &standalone)) { if (isGeneralTextEntity) return XML_ERROR_TEXT_DECL; else return XML_ERROR_XML_DECL; } - if (!isGeneralTextEntity && standalone == 1) { + if (! isGeneralTextEntity && standalone == 1) { parser->m_dtd->standalone = XML_TRUE; #ifdef XML_DTD - if (parser->m_paramEntityParsing == XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONE) + if (parser->m_paramEntityParsing + == XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONE) parser->m_paramEntityParsing = XML_PARAM_ENTITY_PARSING_NEVER; #endif /* XML_DTD */ } if (parser->m_xmlDeclHandler) { if (encodingName != NULL) { - storedEncName = poolStoreString(&parser->m_temp2Pool, - parser->m_encoding, - encodingName, - encodingName - + XmlNameLength(parser->m_encoding, encodingName)); - if (!storedEncName) - return XML_ERROR_NO_MEMORY; + storedEncName = poolStoreString( + &parser->m_temp2Pool, parser->m_encoding, encodingName, + encodingName + XmlNameLength(parser->m_encoding, encodingName)); + if (! storedEncName) + return XML_ERROR_NO_MEMORY; poolFinish(&parser->m_temp2Pool); } if (version) { - storedversion = poolStoreString(&parser->m_temp2Pool, - parser->m_encoding, - version, - versionend - parser->m_encoding->minBytesPerChar); - if (!storedversion) + storedversion + = poolStoreString(&parser->m_temp2Pool, parser->m_encoding, version, + versionend - parser->m_encoding->minBytesPerChar); + if (! storedversion) return XML_ERROR_NO_MEMORY; } - parser->m_xmlDeclHandler(parser->m_handlerArg, storedversion, storedEncName, standalone); - } - else if (parser->m_defaultHandler) + parser->m_xmlDeclHandler(parser->m_handlerArg, storedversion, storedEncName, + standalone); + } else if (parser->m_defaultHandler) reportDefault(parser, parser->m_encoding, s, next); if (parser->m_protocolEncodingName == NULL) { if (newEncoding) { /* Check that the specified encoding does not conflict with what * the parser has already deduced. Do we have the same number * of bytes in the smallest representation of a character? If * this is UTF-16, is it the same endianness? */ if (newEncoding->minBytesPerChar != parser->m_encoding->minBytesPerChar - || (newEncoding->minBytesPerChar == 2 && - newEncoding != parser->m_encoding)) { + || (newEncoding->minBytesPerChar == 2 + && newEncoding != parser->m_encoding)) { parser->m_eventPtr = encodingName; return XML_ERROR_INCORRECT_ENCODING; } parser->m_encoding = newEncoding; - } - else if (encodingName) { + } else if (encodingName) { enum XML_Error result; - if (!storedEncName) { + if (! storedEncName) { storedEncName = poolStoreString( - &parser->m_temp2Pool, parser->m_encoding, encodingName, - encodingName + XmlNameLength(parser->m_encoding, encodingName)); - if (!storedEncName) + &parser->m_temp2Pool, parser->m_encoding, encodingName, + encodingName + XmlNameLength(parser->m_encoding, encodingName)); + if (! storedEncName) return XML_ERROR_NO_MEMORY; } result = handleUnknownEncoding(parser, storedEncName); poolClear(&parser->m_temp2Pool); if (result == XML_ERROR_UNKNOWN_ENCODING) @@ -4050,35 +3875,30 @@ return XML_ERROR_NONE; } static enum XML_Error -handleUnknownEncoding(XML_Parser parser, const XML_Char *encodingName) -{ +handleUnknownEncoding(XML_Parser parser, const XML_Char *encodingName) { if (parser->m_unknownEncodingHandler) { XML_Encoding info; int i; for (i = 0; i < 256; i++) info.map[i] = -1; info.convert = NULL; info.data = NULL; info.release = NULL; - if (parser->m_unknownEncodingHandler(parser->m_unknownEncodingHandlerData, encodingName, - &info)) { + if (parser->m_unknownEncodingHandler(parser->m_unknownEncodingHandlerData, + encodingName, &info)) { ENCODING *enc; parser->m_unknownEncodingMem = MALLOC(parser, XmlSizeOfUnknownEncoding()); - if (!parser->m_unknownEncodingMem) { + if (! parser->m_unknownEncodingMem) { if (info.release) info.release(info.data); return XML_ERROR_NO_MEMORY; } - enc = (parser->m_ns - ? XmlInitUnknownEncodingNS - : XmlInitUnknownEncoding)(parser->m_unknownEncodingMem, - info.map, - info.convert, - info.data); + enc = (parser->m_ns ? XmlInitUnknownEncodingNS : XmlInitUnknownEncoding)( + parser->m_unknownEncodingMem, info.map, info.convert, info.data); if (enc) { parser->m_unknownEncodingData = info.data; parser->m_unknownEncodingRelease = info.release; parser->m_encoding = enc; return XML_ERROR_NONE; @@ -4089,15 +3909,12 @@ } return XML_ERROR_UNKNOWN_ENCODING; } static enum XML_Error PTRCALL -prologInitProcessor(XML_Parser parser, - const char *s, - const char *end, - const char **nextPtr) -{ +prologInitProcessor(XML_Parser parser, const char *s, const char *end, + const char **nextPtr) { enum XML_Error result = initializeEncoding(parser); if (result != XML_ERROR_NONE) return result; parser->m_processor = prologProcessor; return prologProcessor(parser, s, end, nextPtr); @@ -4104,15 +3921,12 @@ } #ifdef XML_DTD static enum XML_Error PTRCALL -externalParEntInitProcessor(XML_Parser parser, - const char *s, - const char *end, - const char **nextPtr) -{ +externalParEntInitProcessor(XML_Parser parser, const char *s, const char *end, + const char **nextPtr) { enum XML_Error result = initializeEncoding(parser); if (result != XML_ERROR_NONE) return result; /* we know now that XML_Parse(Buffer) has been called, @@ -4120,33 +3934,29 @@ parser->m_dtd->paramEntityRead = XML_TRUE; if (parser->m_prologState.inEntityValue) { parser->m_processor = entityValueInitProcessor; return entityValueInitProcessor(parser, s, end, nextPtr); - } - else { + } else { parser->m_processor = externalParEntProcessor; return externalParEntProcessor(parser, s, end, nextPtr); } } static enum XML_Error PTRCALL -entityValueInitProcessor(XML_Parser parser, - const char *s, - const char *end, - const char **nextPtr) -{ +entityValueInitProcessor(XML_Parser parser, const char *s, const char *end, + const char **nextPtr) { int tok; const char *start = s; const char *next = start; parser->m_eventPtr = start; for (;;) { tok = XmlPrologTok(parser->m_encoding, start, end, &next); parser->m_eventEndPtr = next; if (tok <= 0) { - if (!parser->m_parsingStatus.finalBuffer && tok != XML_TOK_INVALID) { + if (! parser->m_parsingStatus.finalBuffer && tok != XML_TOK_INVALID) { *nextPtr = s; return XML_ERROR_NONE; } switch (tok) { case XML_TOK_INVALID: @@ -4153,26 +3963,25 @@ return XML_ERROR_INVALID_TOKEN; case XML_TOK_PARTIAL: return XML_ERROR_UNCLOSED_TOKEN; case XML_TOK_PARTIAL_CHAR: return XML_ERROR_PARTIAL_CHAR; - case XML_TOK_NONE: /* start == end */ + case XML_TOK_NONE: /* start == end */ default: break; } /* found end of entity value - can store it now */ return storeEntityValue(parser, parser->m_encoding, s, end); - } - else if (tok == XML_TOK_XML_DECL) { + } else if (tok == XML_TOK_XML_DECL) { enum XML_Error result; result = processXmlDecl(parser, 0, start, next); if (result != XML_ERROR_NONE) return result; - /* At this point, m_parsingStatus.parsing cannot be XML_SUSPENDED. For that - * to happen, a parameter entity parsing handler must have - * attempted to suspend the parser, which fails and raises an - * error. The parser can be aborted, but can't be suspended. + /* At this point, m_parsingStatus.parsing cannot be XML_SUSPENDED. For + * that to happen, a parameter entity parsing handler must have attempted + * to suspend the parser, which fails and raises an error. The parser can + * be aborted, but can't be suspended. */ if (parser->m_parsingStatus.parsing == XML_FINISHED) return XML_ERROR_ABORTED; *nextPtr = next; /* stop scanning for text declaration - we found one */ @@ -4184,11 +3993,12 @@ function to exit with *nextPtr set to s - that is what we want for other tokens, but not for the BOM - we would rather like to skip it; then, when this routine is entered the next time, XmlPrologTok will return XML_TOK_INVALID, since the BOM is still in the buffer */ - else if (tok == XML_TOK_BOM && next == end && !parser->m_parsingStatus.finalBuffer) { + else if (tok == XML_TOK_BOM && next == end + && ! parser->m_parsingStatus.finalBuffer) { *nextPtr = next; return XML_ERROR_NONE; } /* If we get this token, we have the start of what might be a normal tag, but not a declaration (i.e. it doesn't begin with @@ -4202,21 +4012,18 @@ parser->m_eventPtr = start; } } static enum XML_Error PTRCALL -externalParEntProcessor(XML_Parser parser, - const char *s, - const char *end, - const char **nextPtr) -{ +externalParEntProcessor(XML_Parser parser, const char *s, const char *end, + const char **nextPtr) { const char *next = s; int tok; tok = XmlPrologTok(parser->m_encoding, s, end, &next); if (tok <= 0) { - if (!parser->m_parsingStatus.finalBuffer && tok != XML_TOK_INVALID) { + if (! parser->m_parsingStatus.finalBuffer && tok != XML_TOK_INVALID) { *nextPtr = s; return XML_ERROR_NONE; } switch (tok) { case XML_TOK_INVALID: @@ -4223,11 +4030,11 @@ return XML_ERROR_INVALID_TOKEN; case XML_TOK_PARTIAL: return XML_ERROR_UNCLOSED_TOKEN; case XML_TOK_PARTIAL_CHAR: return XML_ERROR_PARTIAL_CHAR; - case XML_TOK_NONE: /* start == end */ + case XML_TOK_NONE: /* start == end */ default: break; } } /* This would cause the next stage, i.e. doProlog to be passed XML_TOK_BOM. @@ -4238,29 +4045,26 @@ s = next; tok = XmlPrologTok(parser->m_encoding, s, end, &next); } parser->m_processor = prologProcessor; - return doProlog(parser, parser->m_encoding, s, end, tok, next, - nextPtr, (XML_Bool)!parser->m_parsingStatus.finalBuffer); + return doProlog(parser, parser->m_encoding, s, end, tok, next, nextPtr, + (XML_Bool)! parser->m_parsingStatus.finalBuffer, XML_TRUE); } static enum XML_Error PTRCALL -entityValueProcessor(XML_Parser parser, - const char *s, - const char *end, - const char **nextPtr) -{ +entityValueProcessor(XML_Parser parser, const char *s, const char *end, + const char **nextPtr) { const char *start = s; const char *next = s; const ENCODING *enc = parser->m_encoding; int tok; for (;;) { tok = XmlPrologTok(enc, start, end, &next); if (tok <= 0) { - if (!parser->m_parsingStatus.finalBuffer && tok != XML_TOK_INVALID) { + if (! parser->m_parsingStatus.finalBuffer && tok != XML_TOK_INVALID) { *nextPtr = s; return XML_ERROR_NONE; } switch (tok) { case XML_TOK_INVALID: @@ -4267,11 +4071,11 @@ return XML_ERROR_INVALID_TOKEN; case XML_TOK_PARTIAL: return XML_ERROR_UNCLOSED_TOKEN; case XML_TOK_PARTIAL_CHAR: return XML_ERROR_PARTIAL_CHAR; - case XML_TOK_NONE: /* start == end */ + case XML_TOK_NONE: /* start == end */ default: break; } /* found end of entity value - can store it now */ return storeEntityValue(parser, enc, s, end); @@ -4281,66 +4085,59 @@ } #endif /* XML_DTD */ static enum XML_Error PTRCALL -prologProcessor(XML_Parser parser, - const char *s, - const char *end, - const char **nextPtr) -{ +prologProcessor(XML_Parser parser, const char *s, const char *end, + const char **nextPtr) { const char *next = s; int tok = XmlPrologTok(parser->m_encoding, s, end, &next); - return doProlog(parser, parser->m_encoding, s, end, tok, next, - nextPtr, (XML_Bool)!parser->m_parsingStatus.finalBuffer); + return doProlog(parser, parser->m_encoding, s, end, tok, next, nextPtr, + (XML_Bool)! parser->m_parsingStatus.finalBuffer, XML_TRUE); } static enum XML_Error -doProlog(XML_Parser parser, - const ENCODING *enc, - const char *s, - const char *end, - int tok, - const char *next, - const char **nextPtr, - XML_Bool haveMore) -{ +doProlog(XML_Parser parser, const ENCODING *enc, const char *s, const char *end, + int tok, const char *next, const char **nextPtr, XML_Bool haveMore, + XML_Bool allowClosingDoctype) { #ifdef XML_DTD - static const XML_Char externalSubsetName[] = { ASCII_HASH , '\0' }; + static const XML_Char externalSubsetName[] = {ASCII_HASH, '\0'}; #endif /* XML_DTD */ - static const XML_Char atypeCDATA[] = - { ASCII_C, ASCII_D, ASCII_A, ASCII_T, ASCII_A, '\0' }; - static const XML_Char atypeID[] = { ASCII_I, ASCII_D, '\0' }; - static const XML_Char atypeIDREF[] = - { ASCII_I, ASCII_D, ASCII_R, ASCII_E, ASCII_F, '\0' }; - static const XML_Char atypeIDREFS[] = - { ASCII_I, ASCII_D, ASCII_R, ASCII_E, ASCII_F, ASCII_S, '\0' }; - static const XML_Char atypeENTITY[] = - { ASCII_E, ASCII_N, ASCII_T, ASCII_I, ASCII_T, ASCII_Y, '\0' }; - static const XML_Char atypeENTITIES[] = { ASCII_E, ASCII_N, - ASCII_T, ASCII_I, ASCII_T, ASCII_I, ASCII_E, ASCII_S, '\0' }; - static const XML_Char atypeNMTOKEN[] = { - ASCII_N, ASCII_M, ASCII_T, ASCII_O, ASCII_K, ASCII_E, ASCII_N, '\0' }; - static const XML_Char atypeNMTOKENS[] = { ASCII_N, ASCII_M, ASCII_T, - ASCII_O, ASCII_K, ASCII_E, ASCII_N, ASCII_S, '\0' }; - static const XML_Char notationPrefix[] = { ASCII_N, ASCII_O, ASCII_T, - ASCII_A, ASCII_T, ASCII_I, ASCII_O, ASCII_N, ASCII_LPAREN, '\0' }; - static const XML_Char enumValueSep[] = { ASCII_PIPE, '\0' }; - static const XML_Char enumValueStart[] = { ASCII_LPAREN, '\0' }; + static const XML_Char atypeCDATA[] + = {ASCII_C, ASCII_D, ASCII_A, ASCII_T, ASCII_A, '\0'}; + static const XML_Char atypeID[] = {ASCII_I, ASCII_D, '\0'}; + static const XML_Char atypeIDREF[] + = {ASCII_I, ASCII_D, ASCII_R, ASCII_E, ASCII_F, '\0'}; + static const XML_Char atypeIDREFS[] + = {ASCII_I, ASCII_D, ASCII_R, ASCII_E, ASCII_F, ASCII_S, '\0'}; + static const XML_Char atypeENTITY[] + = {ASCII_E, ASCII_N, ASCII_T, ASCII_I, ASCII_T, ASCII_Y, '\0'}; + static const XML_Char atypeENTITIES[] + = {ASCII_E, ASCII_N, ASCII_T, ASCII_I, ASCII_T, + ASCII_I, ASCII_E, ASCII_S, '\0'}; + static const XML_Char atypeNMTOKEN[] + = {ASCII_N, ASCII_M, ASCII_T, ASCII_O, ASCII_K, ASCII_E, ASCII_N, '\0'}; + static const XML_Char atypeNMTOKENS[] + = {ASCII_N, ASCII_M, ASCII_T, ASCII_O, ASCII_K, + ASCII_E, ASCII_N, ASCII_S, '\0'}; + static const XML_Char notationPrefix[] + = {ASCII_N, ASCII_O, ASCII_T, ASCII_A, ASCII_T, + ASCII_I, ASCII_O, ASCII_N, ASCII_LPAREN, '\0'}; + static const XML_Char enumValueSep[] = {ASCII_PIPE, '\0'}; + static const XML_Char enumValueStart[] = {ASCII_LPAREN, '\0'}; /* save one level of indirection */ - DTD * const dtd = parser->m_dtd; + DTD *const dtd = parser->m_dtd; const char **eventPP; const char **eventEndPP; enum XML_Content_Quant quant; if (enc == parser->m_encoding) { eventPP = &parser->m_eventPtr; eventEndPP = &parser->m_eventEndPtr; - } - else { + } else { eventPP = &(parser->m_openInternalEntities->internalEventPtr); eventEndPP = &(parser->m_openInternalEntities->internalEventEndPtr); } for (;;) { @@ -4365,11 +4162,12 @@ tok = -tok; break; case XML_TOK_NONE: #ifdef XML_DTD /* for internal PE NOT referenced between declarations */ - if (enc != parser->m_encoding && !parser->m_openInternalEntities->betweenDecl) { + if (enc != parser->m_encoding + && ! parser->m_openInternalEntities->betweenDecl) { *nextPtr = s; return XML_ERROR_NONE; } /* WFC: PE Between Declarations - must check that PE contains complete markup, not only for external PEs, but also for @@ -4390,87 +4188,82 @@ break; } } role = XmlTokenRole(&parser->m_prologState, tok, s, next, enc); switch (role) { - case XML_ROLE_XML_DECL: - { - enum XML_Error result = processXmlDecl(parser, 0, s, next); - if (result != XML_ERROR_NONE) - return result; - enc = parser->m_encoding; - handleDefault = XML_FALSE; - } - break; + case XML_ROLE_XML_DECL: { + enum XML_Error result = processXmlDecl(parser, 0, s, next); + if (result != XML_ERROR_NONE) + return result; + enc = parser->m_encoding; + handleDefault = XML_FALSE; + } break; case XML_ROLE_DOCTYPE_NAME: if (parser->m_startDoctypeDeclHandler) { - parser->m_doctypeName = poolStoreString(&parser->m_tempPool, enc, s, next); - if (!parser->m_doctypeName) + parser->m_doctypeName + = poolStoreString(&parser->m_tempPool, enc, s, next); + if (! parser->m_doctypeName) return XML_ERROR_NO_MEMORY; poolFinish(&parser->m_tempPool); parser->m_doctypePubid = NULL; handleDefault = XML_FALSE; } parser->m_doctypeSysid = NULL; /* always initialize to NULL */ break; case XML_ROLE_DOCTYPE_INTERNAL_SUBSET: if (parser->m_startDoctypeDeclHandler) { - parser->m_startDoctypeDeclHandler(parser->m_handlerArg, parser->m_doctypeName, parser->m_doctypeSysid, - parser->m_doctypePubid, 1); + parser->m_startDoctypeDeclHandler( + parser->m_handlerArg, parser->m_doctypeName, parser->m_doctypeSysid, + parser->m_doctypePubid, 1); parser->m_doctypeName = NULL; poolClear(&parser->m_tempPool); handleDefault = XML_FALSE; } break; #ifdef XML_DTD - case XML_ROLE_TEXT_DECL: - { - enum XML_Error result = processXmlDecl(parser, 1, s, next); - if (result != XML_ERROR_NONE) - return result; - enc = parser->m_encoding; - handleDefault = XML_FALSE; - } - break; + case XML_ROLE_TEXT_DECL: { + enum XML_Error result = processXmlDecl(parser, 1, s, next); + if (result != XML_ERROR_NONE) + return result; + enc = parser->m_encoding; + handleDefault = XML_FALSE; + } break; #endif /* XML_DTD */ case XML_ROLE_DOCTYPE_PUBLIC_ID: #ifdef XML_DTD parser->m_useForeignDTD = XML_FALSE; - parser->m_declEntity = (ENTITY *)lookup(parser, - &dtd->paramEntities, - externalSubsetName, - sizeof(ENTITY)); - if (!parser->m_declEntity) + parser->m_declEntity = (ENTITY *)lookup( + parser, &dtd->paramEntities, externalSubsetName, sizeof(ENTITY)); + if (! parser->m_declEntity) return XML_ERROR_NO_MEMORY; #endif /* XML_DTD */ dtd->hasParamEntityRefs = XML_TRUE; if (parser->m_startDoctypeDeclHandler) { XML_Char *pubId; - if (!XmlIsPublicId(enc, s, next, eventPP)) + if (! XmlIsPublicId(enc, s, next, eventPP)) return XML_ERROR_PUBLICID; pubId = poolStoreString(&parser->m_tempPool, enc, s + enc->minBytesPerChar, next - enc->minBytesPerChar); - if (!pubId) + if (! pubId) return XML_ERROR_NO_MEMORY; normalizePublicId(pubId); poolFinish(&parser->m_tempPool); parser->m_doctypePubid = pubId; handleDefault = XML_FALSE; goto alreadyChecked; } /* fall through */ case XML_ROLE_ENTITY_PUBLIC_ID: - if (!XmlIsPublicId(enc, s, next, eventPP)) + if (! XmlIsPublicId(enc, s, next, eventPP)) return XML_ERROR_PUBLICID; alreadyChecked: if (dtd->keepProcessing && parser->m_declEntity) { - XML_Char *tem = poolStoreString(&dtd->pool, - enc, - s + enc->minBytesPerChar, - next - enc->minBytesPerChar); - if (!tem) + XML_Char *tem + = poolStoreString(&dtd->pool, enc, s + enc->minBytesPerChar, + next - enc->minBytesPerChar); + if (! tem) return XML_ERROR_NO_MEMORY; normalizePublicId(tem); parser->m_declEntity->publicId = tem; poolFinish(&dtd->pool); /* Don't suppress the default handler if we fell through from @@ -4479,13 +4272,19 @@ if (parser->m_entityDeclHandler && role == XML_ROLE_ENTITY_PUBLIC_ID) handleDefault = XML_FALSE; } break; case XML_ROLE_DOCTYPE_CLOSE: + if (allowClosingDoctype != XML_TRUE) { + /* Must not close doctype from within expanded parameter entities */ + return XML_ERROR_INVALID_TOKEN; + } + if (parser->m_doctypeName) { - parser->m_startDoctypeDeclHandler(parser->m_handlerArg, parser->m_doctypeName, - parser->m_doctypeSysid, parser->m_doctypePubid, 0); + parser->m_startDoctypeDeclHandler( + parser->m_handlerArg, parser->m_doctypeName, parser->m_doctypeSysid, + parser->m_doctypePubid, 0); poolClear(&parser->m_tempPool); handleDefault = XML_FALSE; } /* parser->m_doctypeSysid will be non-NULL in the case of a previous XML_ROLE_DOCTYPE_SYSTEM_ID, even if parser->m_startDoctypeDeclHandler @@ -4493,16 +4292,15 @@ */ #ifdef XML_DTD if (parser->m_doctypeSysid || parser->m_useForeignDTD) { XML_Bool hadParamEntityRefs = dtd->hasParamEntityRefs; dtd->hasParamEntityRefs = XML_TRUE; - if (parser->m_paramEntityParsing && parser->m_externalEntityRefHandler) { - ENTITY *entity = (ENTITY *)lookup(parser, - &dtd->paramEntities, - externalSubsetName, - sizeof(ENTITY)); - if (!entity) { + if (parser->m_paramEntityParsing + && parser->m_externalEntityRefHandler) { + ENTITY *entity = (ENTITY *)lookup(parser, &dtd->paramEntities, + externalSubsetName, sizeof(ENTITY)); + if (! entity) { /* The external subset name "#" will have already been * inserted into the hash table at the start of the * external entity parsing, so no allocation will happen * and lookup() cannot fail. */ @@ -4509,26 +4307,23 @@ return XML_ERROR_NO_MEMORY; /* LCOV_EXCL_LINE */ } if (parser->m_useForeignDTD) entity->base = parser->m_curBase; dtd->paramEntityRead = XML_FALSE; - if (!parser->m_externalEntityRefHandler(parser->m_externalEntityRefHandlerArg, - 0, - entity->base, - entity->systemId, - entity->publicId)) + if (! parser->m_externalEntityRefHandler( + parser->m_externalEntityRefHandlerArg, 0, entity->base, + entity->systemId, entity->publicId)) return XML_ERROR_EXTERNAL_ENTITY_HANDLING; if (dtd->paramEntityRead) { - if (!dtd->standalone && - parser->m_notStandaloneHandler && - !parser->m_notStandaloneHandler(parser->m_handlerArg)) + if (! dtd->standalone && parser->m_notStandaloneHandler + && ! parser->m_notStandaloneHandler(parser->m_handlerArg)) return XML_ERROR_NOT_STANDALONE; } /* if we didn't read the foreign DTD then this means that there is no external subset and we must reset dtd->hasParamEntityRefs */ - else if (!parser->m_doctypeSysid) + else if (! parser->m_doctypeSysid) dtd->hasParamEntityRefs = hadParamEntityRefs; /* end of DTD - no need to update dtd->keepProcessing */ } parser->m_useForeignDTD = XML_FALSE; } @@ -4544,28 +4339,25 @@ last chance to read the foreign DTD */ if (parser->m_useForeignDTD) { XML_Bool hadParamEntityRefs = dtd->hasParamEntityRefs; dtd->hasParamEntityRefs = XML_TRUE; - if (parser->m_paramEntityParsing && parser->m_externalEntityRefHandler) { + if (parser->m_paramEntityParsing + && parser->m_externalEntityRefHandler) { ENTITY *entity = (ENTITY *)lookup(parser, &dtd->paramEntities, - externalSubsetName, - sizeof(ENTITY)); - if (!entity) + externalSubsetName, sizeof(ENTITY)); + if (! entity) return XML_ERROR_NO_MEMORY; entity->base = parser->m_curBase; dtd->paramEntityRead = XML_FALSE; - if (!parser->m_externalEntityRefHandler(parser->m_externalEntityRefHandlerArg, - 0, - entity->base, - entity->systemId, - entity->publicId)) + if (! parser->m_externalEntityRefHandler( + parser->m_externalEntityRefHandlerArg, 0, entity->base, + entity->systemId, entity->publicId)) return XML_ERROR_EXTERNAL_ENTITY_HANDLING; if (dtd->paramEntityRead) { - if (!dtd->standalone && - parser->m_notStandaloneHandler && - !parser->m_notStandaloneHandler(parser->m_handlerArg)) + if (! dtd->standalone && parser->m_notStandaloneHandler + && ! parser->m_notStandaloneHandler(parser->m_handlerArg)) return XML_ERROR_NOT_STANDALONE; } /* if we didn't read the foreign DTD then this means that there is no external subset and we must reset dtd->hasParamEntityRefs */ @@ -4577,16 +4369,16 @@ #endif /* XML_DTD */ parser->m_processor = contentProcessor; return contentProcessor(parser, s, end, nextPtr); case XML_ROLE_ATTLIST_ELEMENT_NAME: parser->m_declElementType = getElementType(parser, enc, s, next); - if (!parser->m_declElementType) + if (! parser->m_declElementType) return XML_ERROR_NO_MEMORY; goto checkAttListDeclHandler; case XML_ROLE_ATTRIBUTE_NAME: parser->m_declAttributeId = getAttributeId(parser, enc, s, next); - if (!parser->m_declAttributeId) + if (! parser->m_declAttributeId) return XML_ERROR_NO_MEMORY; parser->m_declAttributeIsCdata = XML_FALSE; parser->m_declAttributeType = NULL; parser->m_declAttributeIsId = XML_FALSE; goto checkAttListDeclHandler; @@ -4623,110 +4415,106 @@ case XML_ROLE_ATTRIBUTE_NOTATION_VALUE: if (dtd->keepProcessing && parser->m_attlistDeclHandler) { const XML_Char *prefix; if (parser->m_declAttributeType) { prefix = enumValueSep; - } - else { - prefix = (role == XML_ROLE_ATTRIBUTE_NOTATION_VALUE - ? notationPrefix - : enumValueStart); - } - if (!poolAppendString(&parser->m_tempPool, prefix)) - return XML_ERROR_NO_MEMORY; - if (!poolAppend(&parser->m_tempPool, enc, s, next)) + } else { + prefix = (role == XML_ROLE_ATTRIBUTE_NOTATION_VALUE ? notationPrefix + : enumValueStart); + } + if (! poolAppendString(&parser->m_tempPool, prefix)) + return XML_ERROR_NO_MEMORY; + if (! poolAppend(&parser->m_tempPool, enc, s, next)) return XML_ERROR_NO_MEMORY; parser->m_declAttributeType = parser->m_tempPool.start; handleDefault = XML_FALSE; } break; case XML_ROLE_IMPLIED_ATTRIBUTE_VALUE: case XML_ROLE_REQUIRED_ATTRIBUTE_VALUE: if (dtd->keepProcessing) { - if (!defineAttribute(parser->m_declElementType, parser->m_declAttributeId, - parser->m_declAttributeIsCdata, parser->m_declAttributeIsId, - 0, parser)) + if (! defineAttribute(parser->m_declElementType, + parser->m_declAttributeId, + parser->m_declAttributeIsCdata, + parser->m_declAttributeIsId, 0, parser)) return XML_ERROR_NO_MEMORY; if (parser->m_attlistDeclHandler && parser->m_declAttributeType) { if (*parser->m_declAttributeType == XML_T(ASCII_LPAREN) || (*parser->m_declAttributeType == XML_T(ASCII_N) && parser->m_declAttributeType[1] == XML_T(ASCII_O))) { /* Enumerated or Notation type */ - if (!poolAppendChar(&parser->m_tempPool, XML_T(ASCII_RPAREN)) - || !poolAppendChar(&parser->m_tempPool, XML_T('\0'))) + if (! poolAppendChar(&parser->m_tempPool, XML_T(ASCII_RPAREN)) + || ! poolAppendChar(&parser->m_tempPool, XML_T('\0'))) return XML_ERROR_NO_MEMORY; parser->m_declAttributeType = parser->m_tempPool.start; poolFinish(&parser->m_tempPool); } *eventEndPP = s; - parser->m_attlistDeclHandler(parser->m_handlerArg, parser->m_declElementType->name, - parser->m_declAttributeId->name, parser->m_declAttributeType, - 0, role == XML_ROLE_REQUIRED_ATTRIBUTE_VALUE); + parser->m_attlistDeclHandler( + parser->m_handlerArg, parser->m_declElementType->name, + parser->m_declAttributeId->name, parser->m_declAttributeType, 0, + role == XML_ROLE_REQUIRED_ATTRIBUTE_VALUE); poolClear(&parser->m_tempPool); handleDefault = XML_FALSE; } } break; case XML_ROLE_DEFAULT_ATTRIBUTE_VALUE: case XML_ROLE_FIXED_ATTRIBUTE_VALUE: if (dtd->keepProcessing) { const XML_Char *attVal; - enum XML_Error result = - storeAttributeValue(parser, enc, parser->m_declAttributeIsCdata, - s + enc->minBytesPerChar, - next - enc->minBytesPerChar, - &dtd->pool); + enum XML_Error result = storeAttributeValue( + parser, enc, parser->m_declAttributeIsCdata, + s + enc->minBytesPerChar, next - enc->minBytesPerChar, &dtd->pool); if (result) return result; attVal = poolStart(&dtd->pool); poolFinish(&dtd->pool); /* ID attributes aren't allowed to have a default */ - if (!defineAttribute(parser->m_declElementType, parser->m_declAttributeId, - parser->m_declAttributeIsCdata, XML_FALSE, attVal, parser)) + if (! defineAttribute( + parser->m_declElementType, parser->m_declAttributeId, + parser->m_declAttributeIsCdata, XML_FALSE, attVal, parser)) return XML_ERROR_NO_MEMORY; if (parser->m_attlistDeclHandler && parser->m_declAttributeType) { if (*parser->m_declAttributeType == XML_T(ASCII_LPAREN) || (*parser->m_declAttributeType == XML_T(ASCII_N) && parser->m_declAttributeType[1] == XML_T(ASCII_O))) { /* Enumerated or Notation type */ - if (!poolAppendChar(&parser->m_tempPool, XML_T(ASCII_RPAREN)) - || !poolAppendChar(&parser->m_tempPool, XML_T('\0'))) + if (! poolAppendChar(&parser->m_tempPool, XML_T(ASCII_RPAREN)) + || ! poolAppendChar(&parser->m_tempPool, XML_T('\0'))) return XML_ERROR_NO_MEMORY; parser->m_declAttributeType = parser->m_tempPool.start; poolFinish(&parser->m_tempPool); } *eventEndPP = s; - parser->m_attlistDeclHandler(parser->m_handlerArg, parser->m_declElementType->name, - parser->m_declAttributeId->name, parser->m_declAttributeType, - attVal, - role == XML_ROLE_FIXED_ATTRIBUTE_VALUE); + parser->m_attlistDeclHandler( + parser->m_handlerArg, parser->m_declElementType->name, + parser->m_declAttributeId->name, parser->m_declAttributeType, + attVal, role == XML_ROLE_FIXED_ATTRIBUTE_VALUE); poolClear(&parser->m_tempPool); handleDefault = XML_FALSE; } } break; case XML_ROLE_ENTITY_VALUE: if (dtd->keepProcessing) { - enum XML_Error result = storeEntityValue(parser, enc, - s + enc->minBytesPerChar, - next - enc->minBytesPerChar); + enum XML_Error result = storeEntityValue( + parser, enc, s + enc->minBytesPerChar, next - enc->minBytesPerChar); if (parser->m_declEntity) { parser->m_declEntity->textPtr = poolStart(&dtd->entityValuePool); - parser->m_declEntity->textLen = (int)(poolLength(&dtd->entityValuePool)); + parser->m_declEntity->textLen + = (int)(poolLength(&dtd->entityValuePool)); poolFinish(&dtd->entityValuePool); if (parser->m_entityDeclHandler) { *eventEndPP = s; - parser->m_entityDeclHandler(parser->m_handlerArg, - parser->m_declEntity->name, - parser->m_declEntity->is_param, - parser->m_declEntity->textPtr, - parser->m_declEntity->textLen, - parser->m_curBase, 0, 0, 0); + parser->m_entityDeclHandler( + parser->m_handlerArg, parser->m_declEntity->name, + parser->m_declEntity->is_param, parser->m_declEntity->textPtr, + parser->m_declEntity->textLen, parser->m_curBase, 0, 0, 0); handleDefault = XML_FALSE; } - } - else + } else poolDiscard(&dtd->entityValuePool); if (result != XML_ERROR_NONE) return result; } break; @@ -4735,12 +4523,12 @@ parser->m_useForeignDTD = XML_FALSE; #endif /* XML_DTD */ dtd->hasParamEntityRefs = XML_TRUE; if (parser->m_startDoctypeDeclHandler) { parser->m_doctypeSysid = poolStoreString(&parser->m_tempPool, enc, - s + enc->minBytesPerChar, - next - enc->minBytesPerChar); + s + enc->minBytesPerChar, + next - enc->minBytesPerChar); if (parser->m_doctypeSysid == NULL) return XML_ERROR_NO_MEMORY; poolFinish(&parser->m_tempPool); handleDefault = XML_FALSE; } @@ -4748,37 +4536,35 @@ else /* use externalSubsetName to make parser->m_doctypeSysid non-NULL for the case where no parser->m_startDoctypeDeclHandler is set */ parser->m_doctypeSysid = externalSubsetName; #endif /* XML_DTD */ - if (!dtd->standalone + if (! dtd->standalone #ifdef XML_DTD - && !parser->m_paramEntityParsing + && ! parser->m_paramEntityParsing #endif /* XML_DTD */ && parser->m_notStandaloneHandler - && !parser->m_notStandaloneHandler(parser->m_handlerArg)) + && ! parser->m_notStandaloneHandler(parser->m_handlerArg)) return XML_ERROR_NOT_STANDALONE; #ifndef XML_DTD break; -#else /* XML_DTD */ - if (!parser->m_declEntity) { - parser->m_declEntity = (ENTITY *)lookup(parser, - &dtd->paramEntities, - externalSubsetName, - sizeof(ENTITY)); - if (!parser->m_declEntity) +#else /* XML_DTD */ + if (! parser->m_declEntity) { + parser->m_declEntity = (ENTITY *)lookup( + parser, &dtd->paramEntities, externalSubsetName, sizeof(ENTITY)); + if (! parser->m_declEntity) return XML_ERROR_NO_MEMORY; parser->m_declEntity->publicId = NULL; } #endif /* XML_DTD */ /* fall through */ case XML_ROLE_ENTITY_SYSTEM_ID: if (dtd->keepProcessing && parser->m_declEntity) { - parser->m_declEntity->systemId = poolStoreString(&dtd->pool, enc, - s + enc->minBytesPerChar, - next - enc->minBytesPerChar); - if (!parser->m_declEntity->systemId) + parser->m_declEntity->systemId + = poolStoreString(&dtd->pool, enc, s + enc->minBytesPerChar, + next - enc->minBytesPerChar); + if (! parser->m_declEntity->systemId) return XML_ERROR_NO_MEMORY; parser->m_declEntity->base = parser->m_curBase; poolFinish(&dtd->pool); /* Don't suppress the default handler if we fell through from * the XML_ROLE_DOCTYPE_SYSTEM_ID case. @@ -4786,175 +4572,159 @@ if (parser->m_entityDeclHandler && role == XML_ROLE_ENTITY_SYSTEM_ID) handleDefault = XML_FALSE; } break; case XML_ROLE_ENTITY_COMPLETE: - if (dtd->keepProcessing && parser->m_declEntity && parser->m_entityDeclHandler) { + if (dtd->keepProcessing && parser->m_declEntity + && parser->m_entityDeclHandler) { *eventEndPP = s; - parser->m_entityDeclHandler(parser->m_handlerArg, - parser->m_declEntity->name, - parser->m_declEntity->is_param, - 0,0, - parser->m_declEntity->base, - parser->m_declEntity->systemId, - parser->m_declEntity->publicId, - 0); + parser->m_entityDeclHandler( + parser->m_handlerArg, parser->m_declEntity->name, + parser->m_declEntity->is_param, 0, 0, parser->m_declEntity->base, + parser->m_declEntity->systemId, parser->m_declEntity->publicId, 0); handleDefault = XML_FALSE; } break; case XML_ROLE_ENTITY_NOTATION_NAME: if (dtd->keepProcessing && parser->m_declEntity) { - parser->m_declEntity->notation = poolStoreString(&dtd->pool, enc, s, next); - if (!parser->m_declEntity->notation) + parser->m_declEntity->notation + = poolStoreString(&dtd->pool, enc, s, next); + if (! parser->m_declEntity->notation) return XML_ERROR_NO_MEMORY; poolFinish(&dtd->pool); if (parser->m_unparsedEntityDeclHandler) { *eventEndPP = s; - parser->m_unparsedEntityDeclHandler(parser->m_handlerArg, - parser->m_declEntity->name, - parser->m_declEntity->base, - parser->m_declEntity->systemId, - parser->m_declEntity->publicId, - parser->m_declEntity->notation); - handleDefault = XML_FALSE; - } - else if (parser->m_entityDeclHandler) { - *eventEndPP = s; - parser->m_entityDeclHandler(parser->m_handlerArg, - parser->m_declEntity->name, - 0,0,0, - parser->m_declEntity->base, - parser->m_declEntity->systemId, - parser->m_declEntity->publicId, - parser->m_declEntity->notation); - handleDefault = XML_FALSE; - } - } - break; - case XML_ROLE_GENERAL_ENTITY_NAME: - { - if (XmlPredefinedEntityName(enc, s, next)) { - parser->m_declEntity = NULL; - break; - } - if (dtd->keepProcessing) { - const XML_Char *name = poolStoreString(&dtd->pool, enc, s, next); - if (!name) - return XML_ERROR_NO_MEMORY; - parser->m_declEntity = (ENTITY *)lookup(parser, &dtd->generalEntities, name, - sizeof(ENTITY)); - if (!parser->m_declEntity) - return XML_ERROR_NO_MEMORY; - if (parser->m_declEntity->name != name) { - poolDiscard(&dtd->pool); - parser->m_declEntity = NULL; - } - else { - poolFinish(&dtd->pool); - parser->m_declEntity->publicId = NULL; - parser->m_declEntity->is_param = XML_FALSE; - /* if we have a parent parser or are reading an internal parameter - entity, then the entity declaration is not considered "internal" - */ - parser->m_declEntity->is_internal = !(parser->m_parentParser || parser->m_openInternalEntities); - if (parser->m_entityDeclHandler) - handleDefault = XML_FALSE; - } - } - else { - poolDiscard(&dtd->pool); - parser->m_declEntity = NULL; - } - } - break; + parser->m_unparsedEntityDeclHandler( + parser->m_handlerArg, parser->m_declEntity->name, + parser->m_declEntity->base, parser->m_declEntity->systemId, + parser->m_declEntity->publicId, parser->m_declEntity->notation); + handleDefault = XML_FALSE; + } else if (parser->m_entityDeclHandler) { + *eventEndPP = s; + parser->m_entityDeclHandler( + parser->m_handlerArg, parser->m_declEntity->name, 0, 0, 0, + parser->m_declEntity->base, parser->m_declEntity->systemId, + parser->m_declEntity->publicId, parser->m_declEntity->notation); + handleDefault = XML_FALSE; + } + } + break; + case XML_ROLE_GENERAL_ENTITY_NAME: { + if (XmlPredefinedEntityName(enc, s, next)) { + parser->m_declEntity = NULL; + break; + } + if (dtd->keepProcessing) { + const XML_Char *name = poolStoreString(&dtd->pool, enc, s, next); + if (! name) + return XML_ERROR_NO_MEMORY; + parser->m_declEntity = (ENTITY *)lookup(parser, &dtd->generalEntities, + name, sizeof(ENTITY)); + if (! parser->m_declEntity) + return XML_ERROR_NO_MEMORY; + if (parser->m_declEntity->name != name) { + poolDiscard(&dtd->pool); + parser->m_declEntity = NULL; + } else { + poolFinish(&dtd->pool); + parser->m_declEntity->publicId = NULL; + parser->m_declEntity->is_param = XML_FALSE; + /* if we have a parent parser or are reading an internal parameter + entity, then the entity declaration is not considered "internal" + */ + parser->m_declEntity->is_internal + = ! (parser->m_parentParser || parser->m_openInternalEntities); + if (parser->m_entityDeclHandler) + handleDefault = XML_FALSE; + } + } else { + poolDiscard(&dtd->pool); + parser->m_declEntity = NULL; + } + } break; case XML_ROLE_PARAM_ENTITY_NAME: #ifdef XML_DTD if (dtd->keepProcessing) { const XML_Char *name = poolStoreString(&dtd->pool, enc, s, next); - if (!name) + if (! name) return XML_ERROR_NO_MEMORY; parser->m_declEntity = (ENTITY *)lookup(parser, &dtd->paramEntities, - name, sizeof(ENTITY)); - if (!parser->m_declEntity) + name, sizeof(ENTITY)); + if (! parser->m_declEntity) return XML_ERROR_NO_MEMORY; if (parser->m_declEntity->name != name) { poolDiscard(&dtd->pool); parser->m_declEntity = NULL; - } - else { + } else { poolFinish(&dtd->pool); parser->m_declEntity->publicId = NULL; parser->m_declEntity->is_param = XML_TRUE; /* if we have a parent parser or are reading an internal parameter entity, then the entity declaration is not considered "internal" */ - parser->m_declEntity->is_internal = !(parser->m_parentParser || parser->m_openInternalEntities); + parser->m_declEntity->is_internal + = ! (parser->m_parentParser || parser->m_openInternalEntities); if (parser->m_entityDeclHandler) handleDefault = XML_FALSE; } - } - else { + } else { poolDiscard(&dtd->pool); parser->m_declEntity = NULL; } -#else /* not XML_DTD */ +#else /* not XML_DTD */ parser->m_declEntity = NULL; #endif /* XML_DTD */ break; case XML_ROLE_NOTATION_NAME: parser->m_declNotationPublicId = NULL; parser->m_declNotationName = NULL; if (parser->m_notationDeclHandler) { - parser->m_declNotationName = poolStoreString(&parser->m_tempPool, enc, s, next); - if (!parser->m_declNotationName) + parser->m_declNotationName + = poolStoreString(&parser->m_tempPool, enc, s, next); + if (! parser->m_declNotationName) return XML_ERROR_NO_MEMORY; poolFinish(&parser->m_tempPool); handleDefault = XML_FALSE; } break; case XML_ROLE_NOTATION_PUBLIC_ID: - if (!XmlIsPublicId(enc, s, next, eventPP)) + if (! XmlIsPublicId(enc, s, next, eventPP)) return XML_ERROR_PUBLICID; - if (parser->m_declNotationName) { /* means m_notationDeclHandler != NULL */ - XML_Char *tem = poolStoreString(&parser->m_tempPool, - enc, + if (parser + ->m_declNotationName) { /* means m_notationDeclHandler != NULL */ + XML_Char *tem = poolStoreString(&parser->m_tempPool, enc, s + enc->minBytesPerChar, next - enc->minBytesPerChar); - if (!tem) + if (! tem) return XML_ERROR_NO_MEMORY; normalizePublicId(tem); parser->m_declNotationPublicId = tem; poolFinish(&parser->m_tempPool); handleDefault = XML_FALSE; } break; case XML_ROLE_NOTATION_SYSTEM_ID: if (parser->m_declNotationName && parser->m_notationDeclHandler) { - const XML_Char *systemId - = poolStoreString(&parser->m_tempPool, enc, - s + enc->minBytesPerChar, - next - enc->minBytesPerChar); - if (!systemId) + const XML_Char *systemId = poolStoreString(&parser->m_tempPool, enc, + s + enc->minBytesPerChar, + next - enc->minBytesPerChar); + if (! systemId) return XML_ERROR_NO_MEMORY; *eventEndPP = s; - parser->m_notationDeclHandler(parser->m_handlerArg, - parser->m_declNotationName, - parser->m_curBase, - systemId, - parser->m_declNotationPublicId); + parser->m_notationDeclHandler( + parser->m_handlerArg, parser->m_declNotationName, parser->m_curBase, + systemId, parser->m_declNotationPublicId); handleDefault = XML_FALSE; } poolClear(&parser->m_tempPool); break; case XML_ROLE_NOTATION_NO_SYSTEM_ID: if (parser->m_declNotationPublicId && parser->m_notationDeclHandler) { *eventEndPP = s; - parser->m_notationDeclHandler(parser->m_handlerArg, - parser->m_declNotationName, - parser->m_curBase, - 0, - parser->m_declNotationPublicId); + parser->m_notationDeclHandler( + parser->m_handlerArg, parser->m_declNotationName, parser->m_curBase, + 0, parser->m_declNotationPublicId); handleDefault = XML_FALSE; } poolClear(&parser->m_tempPool); break; case XML_ROLE_ERROR: @@ -4967,46 +4737,48 @@ return XML_ERROR_MISPLACED_XML_PI; default: return XML_ERROR_SYNTAX; } #ifdef XML_DTD - case XML_ROLE_IGNORE_SECT: - { - enum XML_Error result; - if (parser->m_defaultHandler) - reportDefault(parser, enc, s, next); - handleDefault = XML_FALSE; - result = doIgnoreSection(parser, enc, &next, end, nextPtr, haveMore); - if (result != XML_ERROR_NONE) - return result; - else if (!next) { - parser->m_processor = ignoreSectionProcessor; - return result; - } - } - break; + case XML_ROLE_IGNORE_SECT: { + enum XML_Error result; + if (parser->m_defaultHandler) + reportDefault(parser, enc, s, next); + handleDefault = XML_FALSE; + result = doIgnoreSection(parser, enc, &next, end, nextPtr, haveMore); + if (result != XML_ERROR_NONE) + return result; + else if (! next) { + parser->m_processor = ignoreSectionProcessor; + return result; + } + } break; #endif /* XML_DTD */ case XML_ROLE_GROUP_OPEN: if (parser->m_prologState.level >= parser->m_groupSize) { if (parser->m_groupSize) { - char *temp = (char *)REALLOC(parser, parser->m_groupConnector, parser->m_groupSize *= 2); - if (temp == NULL) { - parser->m_groupSize /= 2; - return XML_ERROR_NO_MEMORY; + { + char *const new_connector = (char *)REALLOC( + parser, parser->m_groupConnector, parser->m_groupSize *= 2); + if (new_connector == NULL) { + parser->m_groupSize /= 2; + return XML_ERROR_NO_MEMORY; + } + parser->m_groupConnector = new_connector; } - parser->m_groupConnector = temp; + if (dtd->scaffIndex) { - int *temp = (int *)REALLOC(parser, dtd->scaffIndex, - parser->m_groupSize * sizeof(int)); - if (temp == NULL) + int *const new_scaff_index = (int *)REALLOC( + parser, dtd->scaffIndex, parser->m_groupSize * sizeof(int)); + if (new_scaff_index == NULL) return XML_ERROR_NO_MEMORY; - dtd->scaffIndex = temp; + dtd->scaffIndex = new_scaff_index; } - } - else { - parser->m_groupConnector = (char *)MALLOC(parser, parser->m_groupSize = 32); - if (!parser->m_groupConnector) { + } else { + parser->m_groupConnector + = (char *)MALLOC(parser, parser->m_groupSize = 32); + if (! parser->m_groupConnector) { parser->m_groupSize = 0; return XML_ERROR_NO_MEMORY; } } } @@ -5013,10 +4785,11 @@ parser->m_groupConnector[parser->m_prologState.level] = 0; if (dtd->in_eldecl) { int myindex = nextScaffoldPart(parser); if (myindex < 0) return XML_ERROR_NO_MEMORY; + assert(dtd->scaffIndex != NULL); dtd->scaffIndex[dtd->scaffLevel] = myindex; dtd->scaffLevel++; dtd->scaffold[myindex].type = XML_CTYPE_SEQ; if (parser->m_elementDeclHandler) handleDefault = XML_FALSE; @@ -5031,14 +4804,13 @@ break; case XML_ROLE_GROUP_CHOICE: if (parser->m_groupConnector[parser->m_prologState.level] == ASCII_COMMA) return XML_ERROR_SYNTAX; if (dtd->in_eldecl - && !parser->m_groupConnector[parser->m_prologState.level] + && ! parser->m_groupConnector[parser->m_prologState.level] && (dtd->scaffold[dtd->scaffIndex[dtd->scaffLevel - 1]].type - != XML_CTYPE_MIXED) - ) { + != XML_CTYPE_MIXED)) { dtd->scaffold[dtd->scaffIndex[dtd->scaffLevel - 1]].type = XML_CTYPE_CHOICE; if (parser->m_elementDeclHandler) handleDefault = XML_FALSE; } @@ -5046,33 +4818,31 @@ break; case XML_ROLE_PARAM_ENTITY_REF: #ifdef XML_DTD case XML_ROLE_INNER_PARAM_ENTITY_REF: dtd->hasParamEntityRefs = XML_TRUE; - if (!parser->m_paramEntityParsing) + if (! parser->m_paramEntityParsing) dtd->keepProcessing = dtd->standalone; else { const XML_Char *name; ENTITY *entity; - name = poolStoreString(&dtd->pool, enc, - s + enc->minBytesPerChar, - next - enc->minBytesPerChar); - if (!name) + name = poolStoreString(&dtd->pool, enc, s + enc->minBytesPerChar, + next - enc->minBytesPerChar); + if (! name) return XML_ERROR_NO_MEMORY; entity = (ENTITY *)lookup(parser, &dtd->paramEntities, name, 0); poolDiscard(&dtd->pool); /* first, determine if a check for an existing declaration is needed; if yes, check that the entity exists, and that it is internal, otherwise call the skipped entity handler */ - if (parser->m_prologState.documentEntity && - (dtd->standalone - ? !parser->m_openInternalEntities - : !dtd->hasParamEntityRefs)) { - if (!entity) + if (parser->m_prologState.documentEntity + && (dtd->standalone ? ! parser->m_openInternalEntities + : ! dtd->hasParamEntityRefs)) { + if (! entity) return XML_ERROR_UNDEFINED_ENTITY; - else if (!entity->is_internal) { + else if (! entity->is_internal) { /* It's hard to exhaustively search the code to be sure, * but there doesn't seem to be a way of executing the * following line. There are two cases: * * If 'standalone' is false, the DTD must have no @@ -5091,68 +4861,64 @@ * being left in place and merely removed from the * coverage test statistics. */ return XML_ERROR_ENTITY_DECLARED_IN_PE; /* LCOV_EXCL_LINE */ } - } - else if (!entity) { + } else if (! entity) { dtd->keepProcessing = dtd->standalone; /* cannot report skipped entities in declarations */ - if ((role == XML_ROLE_PARAM_ENTITY_REF) && parser->m_skippedEntityHandler) { + if ((role == XML_ROLE_PARAM_ENTITY_REF) + && parser->m_skippedEntityHandler) { parser->m_skippedEntityHandler(parser->m_handlerArg, name, 1); handleDefault = XML_FALSE; } break; } if (entity->open) return XML_ERROR_RECURSIVE_ENTITY_REF; if (entity->textPtr) { enum XML_Error result; - XML_Bool betweenDecl = - (role == XML_ROLE_PARAM_ENTITY_REF ? XML_TRUE : XML_FALSE); + XML_Bool betweenDecl + = (role == XML_ROLE_PARAM_ENTITY_REF ? XML_TRUE : XML_FALSE); result = processInternalEntity(parser, entity, betweenDecl); if (result != XML_ERROR_NONE) return result; handleDefault = XML_FALSE; break; } if (parser->m_externalEntityRefHandler) { dtd->paramEntityRead = XML_FALSE; entity->open = XML_TRUE; - if (!parser->m_externalEntityRefHandler(parser->m_externalEntityRefHandlerArg, - 0, - entity->base, - entity->systemId, - entity->publicId)) { + if (! parser->m_externalEntityRefHandler( + parser->m_externalEntityRefHandlerArg, 0, entity->base, + entity->systemId, entity->publicId)) { entity->open = XML_FALSE; return XML_ERROR_EXTERNAL_ENTITY_HANDLING; } entity->open = XML_FALSE; handleDefault = XML_FALSE; - if (!dtd->paramEntityRead) { + if (! dtd->paramEntityRead) { dtd->keepProcessing = dtd->standalone; break; } - } - else { + } else { dtd->keepProcessing = dtd->standalone; break; } } #endif /* XML_DTD */ - if (!dtd->standalone && - parser->m_notStandaloneHandler && - !parser->m_notStandaloneHandler(parser->m_handlerArg)) + if (! dtd->standalone && parser->m_notStandaloneHandler + && ! parser->m_notStandaloneHandler(parser->m_handlerArg)) return XML_ERROR_NOT_STANDALONE; break; - /* Element declaration stuff */ + /* Element declaration stuff */ case XML_ROLE_ELEMENT_NAME: if (parser->m_elementDeclHandler) { parser->m_declElementType = getElementType(parser, enc, s, next); - if (!parser->m_declElementType) + if (! parser->m_declElementType) return XML_ERROR_NO_MEMORY; dtd->scaffLevel = 0; dtd->scaffCount = 0; dtd->in_eldecl = XML_TRUE; handleDefault = XML_FALSE; @@ -5161,22 +4927,23 @@ case XML_ROLE_CONTENT_ANY: case XML_ROLE_CONTENT_EMPTY: if (dtd->in_eldecl) { if (parser->m_elementDeclHandler) { - XML_Content * content = (XML_Content *) MALLOC(parser, sizeof(XML_Content)); - if (!content) + XML_Content *content + = (XML_Content *)MALLOC(parser, sizeof(XML_Content)); + if (! content) return XML_ERROR_NO_MEMORY; content->quant = XML_CQUANT_NONE; content->name = NULL; content->numchildren = 0; content->children = NULL; - content->type = ((role == XML_ROLE_CONTENT_ANY) ? - XML_CTYPE_ANY : - XML_CTYPE_EMPTY); + content->type = ((role == XML_ROLE_CONTENT_ANY) ? XML_CTYPE_ANY + : XML_CTYPE_EMPTY); *eventEndPP = s; - parser->m_elementDeclHandler(parser->m_handlerArg, parser->m_declElementType->name, content); + parser->m_elementDeclHandler( + parser->m_handlerArg, parser->m_declElementType->name, content); handleDefault = XML_FALSE; } dtd->in_eldecl = XML_FALSE; } break; @@ -5204,26 +4971,26 @@ elementContent: if (dtd->in_eldecl) { ELEMENT_TYPE *el; const XML_Char *name; int nameLen; - const char *nxt = (quant == XML_CQUANT_NONE - ? next - : next - enc->minBytesPerChar); + const char *nxt + = (quant == XML_CQUANT_NONE ? next : next - enc->minBytesPerChar); int myindex = nextScaffoldPart(parser); if (myindex < 0) return XML_ERROR_NO_MEMORY; dtd->scaffold[myindex].type = XML_CTYPE_NAME; dtd->scaffold[myindex].quant = quant; el = getElementType(parser, enc, s, nxt); - if (!el) + if (! el) return XML_ERROR_NO_MEMORY; name = el->name; dtd->scaffold[myindex].name = name; nameLen = 0; - for (; name[nameLen++]; ); - dtd->contentStringLen += nameLen; + for (; name[nameLen++];) + ; + dtd->contentStringLen += nameLen; if (parser->m_elementDeclHandler) handleDefault = XML_FALSE; } break; @@ -5243,31 +5010,32 @@ if (parser->m_elementDeclHandler) handleDefault = XML_FALSE; dtd->scaffLevel--; dtd->scaffold[dtd->scaffIndex[dtd->scaffLevel]].quant = quant; if (dtd->scaffLevel == 0) { - if (!handleDefault) { + if (! handleDefault) { XML_Content *model = build_model(parser); - if (!model) + if (! model) return XML_ERROR_NO_MEMORY; *eventEndPP = s; - parser->m_elementDeclHandler(parser->m_handlerArg, parser->m_declElementType->name, model); + parser->m_elementDeclHandler( + parser->m_handlerArg, parser->m_declElementType->name, model); } dtd->in_eldecl = XML_FALSE; dtd->contentStringLen = 0; } } break; /* End element declaration stuff */ case XML_ROLE_PI: - if (!reportProcessingInstruction(parser, enc, s, next)) + if (! reportProcessingInstruction(parser, enc, s, next)) return XML_ERROR_NO_MEMORY; handleDefault = XML_FALSE; break; case XML_ROLE_COMMENT: - if (!reportComment(parser, enc, s, next)) + if (! reportComment(parser, enc, s, next)) return XML_ERROR_NO_MEMORY; handleDefault = XML_FALSE; break; case XML_ROLE_NONE: switch (tok) { @@ -5314,15 +5082,12 @@ } /* not reached */ } static enum XML_Error PTRCALL -epilogProcessor(XML_Parser parser, - const char *s, - const char *end, - const char **nextPtr) -{ +epilogProcessor(XML_Parser parser, const char *s, const char *end, + const char **nextPtr) { parser->m_processor = epilogProcessor; parser->m_eventPtr = s; for (;;) { const char *next = NULL; int tok = XmlPrologTok(parser->m_encoding, s, end, &next); @@ -5343,28 +5108,28 @@ case XML_TOK_PROLOG_S: if (parser->m_defaultHandler) reportDefault(parser, parser->m_encoding, s, next); break; case XML_TOK_PI: - if (!reportProcessingInstruction(parser, parser->m_encoding, s, next)) + if (! reportProcessingInstruction(parser, parser->m_encoding, s, next)) return XML_ERROR_NO_MEMORY; break; case XML_TOK_COMMENT: - if (!reportComment(parser, parser->m_encoding, s, next)) + if (! reportComment(parser, parser->m_encoding, s, next)) return XML_ERROR_NO_MEMORY; break; case XML_TOK_INVALID: parser->m_eventPtr = next; return XML_ERROR_INVALID_TOKEN; case XML_TOK_PARTIAL: - if (!parser->m_parsingStatus.finalBuffer) { + if (! parser->m_parsingStatus.finalBuffer) { *nextPtr = s; return XML_ERROR_NONE; } return XML_ERROR_UNCLOSED_TOKEN; case XML_TOK_PARTIAL_CHAR: - if (!parser->m_parsingStatus.finalBuffer) { + if (! parser->m_parsingStatus.finalBuffer) { *nextPtr = s; return XML_ERROR_NONE; } return XML_ERROR_PARTIAL_CHAR; default: @@ -5375,31 +5140,29 @@ case XML_SUSPENDED: *nextPtr = next; return XML_ERROR_NONE; case XML_FINISHED: return XML_ERROR_ABORTED; - default: ; + default:; } } } static enum XML_Error -processInternalEntity(XML_Parser parser, ENTITY *entity, - XML_Bool betweenDecl) -{ +processInternalEntity(XML_Parser parser, ENTITY *entity, XML_Bool betweenDecl) { const char *textStart, *textEnd; const char *next; enum XML_Error result; OPEN_INTERNAL_ENTITY *openEntity; if (parser->m_freeInternalEntities) { openEntity = parser->m_freeInternalEntities; parser->m_freeInternalEntities = openEntity->next; - } - else { - openEntity = (OPEN_INTERNAL_ENTITY *)MALLOC(parser, sizeof(OPEN_INTERNAL_ENTITY)); - if (!openEntity) + } else { + openEntity + = (OPEN_INTERNAL_ENTITY *)MALLOC(parser, sizeof(OPEN_INTERNAL_ENTITY)); + if (! openEntity) return XML_ERROR_NO_MEMORY; } entity->open = XML_TRUE; entity->processed = 0; openEntity->next = parser->m_openInternalEntities; @@ -5414,25 +5177,24 @@ /* Set a safe default value in case 'next' does not get set */ next = textStart; #ifdef XML_DTD if (entity->is_param) { - int tok = XmlPrologTok(parser->m_internalEncoding, textStart, textEnd, &next); - result = doProlog(parser, parser->m_internalEncoding, textStart, textEnd, tok, - next, &next, XML_FALSE); - } - else + int tok + = XmlPrologTok(parser->m_internalEncoding, textStart, textEnd, &next); + result = doProlog(parser, parser->m_internalEncoding, textStart, textEnd, + tok, next, &next, XML_FALSE, XML_FALSE); + } else #endif /* XML_DTD */ - result = doContent(parser, parser->m_tagLevel, parser->m_internalEncoding, textStart, - textEnd, &next, XML_FALSE); + result = doContent(parser, parser->m_tagLevel, parser->m_internalEncoding, + textStart, textEnd, &next, XML_FALSE); if (result == XML_ERROR_NONE) { if (textEnd != next && parser->m_parsingStatus.parsing == XML_SUSPENDED) { entity->processed = (int)(next - textStart); parser->m_processor = internalEntityProcessor; - } - else { + } else { entity->open = XML_FALSE; parser->m_openInternalEntities = openEntity->next; /* put openEntity back in list of free instances */ openEntity->next = parser->m_freeInternalEntities; parser->m_freeInternalEntities = openEntity; @@ -5440,21 +5202,18 @@ } return result; } static enum XML_Error PTRCALL -internalEntityProcessor(XML_Parser parser, - const char *s, - const char *end, - const char **nextPtr) -{ +internalEntityProcessor(XML_Parser parser, const char *s, const char *end, + const char **nextPtr) { ENTITY *entity; const char *textStart, *textEnd; const char *next; enum XML_Error result; OPEN_INTERNAL_ENTITY *openEntity = parser->m_openInternalEntities; - if (!openEntity) + if (! openEntity) return XML_ERROR_UNEXPECTED_STATE; entity = openEntity->entity; textStart = ((char *)entity->textPtr) + entity->processed; textEnd = (char *)(entity->textPtr + entity->textLen); @@ -5461,26 +5220,27 @@ /* Set a safe default value in case 'next' does not get set */ next = textStart; #ifdef XML_DTD if (entity->is_param) { - int tok = XmlPrologTok(parser->m_internalEncoding, textStart, textEnd, &next); - result = doProlog(parser, parser->m_internalEncoding, textStart, textEnd, tok, - next, &next, XML_FALSE); - } - else + int tok + = XmlPrologTok(parser->m_internalEncoding, textStart, textEnd, &next); + result = doProlog(parser, parser->m_internalEncoding, textStart, textEnd, + tok, next, &next, XML_FALSE, XML_TRUE); + } else #endif /* XML_DTD */ - result = doContent(parser, openEntity->startTagLevel, parser->m_internalEncoding, - textStart, textEnd, &next, XML_FALSE); + result = doContent(parser, openEntity->startTagLevel, + parser->m_internalEncoding, textStart, textEnd, &next, + XML_FALSE); if (result != XML_ERROR_NONE) return result; - else if (textEnd != next && parser->m_parsingStatus.parsing == XML_SUSPENDED) { + else if (textEnd != next + && parser->m_parsingStatus.parsing == XML_SUSPENDED) { entity->processed = (int)(next - (char *)entity->textPtr); return result; - } - else { + } else { entity->open = XML_FALSE; parser->m_openInternalEntities = openEntity->next; /* put openEntity back in list of free instances */ openEntity->next = parser->m_freeInternalEntities; parser->m_freeInternalEntities = openEntity; @@ -5490,53 +5250,49 @@ if (entity->is_param) { int tok; parser->m_processor = prologProcessor; tok = XmlPrologTok(parser->m_encoding, s, end, &next); return doProlog(parser, parser->m_encoding, s, end, tok, next, nextPtr, - (XML_Bool)!parser->m_parsingStatus.finalBuffer); - } - else + (XML_Bool)! parser->m_parsingStatus.finalBuffer, XML_TRUE); + } else #endif /* XML_DTD */ { parser->m_processor = contentProcessor; /* see externalEntityContentProcessor vs contentProcessor */ - return doContent(parser, parser->m_parentParser ? 1 : 0, parser->m_encoding, s, end, - nextPtr, (XML_Bool)!parser->m_parsingStatus.finalBuffer); + return doContent(parser, parser->m_parentParser ? 1 : 0, parser->m_encoding, + s, end, nextPtr, + (XML_Bool)! parser->m_parsingStatus.finalBuffer); } } static enum XML_Error PTRCALL -errorProcessor(XML_Parser parser, - const char *UNUSED_P(s), - const char *UNUSED_P(end), - const char **UNUSED_P(nextPtr)) -{ +errorProcessor(XML_Parser parser, const char *s, const char *end, + const char **nextPtr) { + UNUSED_P(s); + UNUSED_P(end); + UNUSED_P(nextPtr); return parser->m_errorCode; } static enum XML_Error storeAttributeValue(XML_Parser parser, const ENCODING *enc, XML_Bool isCdata, - const char *ptr, const char *end, - STRING_POOL *pool) -{ - enum XML_Error result = appendAttributeValue(parser, enc, isCdata, ptr, - end, pool); + const char *ptr, const char *end, STRING_POOL *pool) { + enum XML_Error result + = appendAttributeValue(parser, enc, isCdata, ptr, end, pool); if (result) return result; - if (!isCdata && poolLength(pool) && poolLastChar(pool) == 0x20) + if (! isCdata && poolLength(pool) && poolLastChar(pool) == 0x20) poolChop(pool); - if (!poolAppendChar(pool, XML_T('\0'))) + if (! poolAppendChar(pool, XML_T('\0'))) return XML_ERROR_NO_MEMORY; return XML_ERROR_NONE; } static enum XML_Error appendAttributeValue(XML_Parser parser, const ENCODING *enc, XML_Bool isCdata, - const char *ptr, const char *end, - STRING_POOL *pool) -{ - DTD * const dtd = parser->m_dtd; /* save one level of indirection */ + const char *ptr, const char *end, STRING_POOL *pool) { + DTD *const dtd = parser->m_dtd; /* save one level of indirection */ for (;;) { const char *next; int tok = XmlAttributeValueTok(enc, ptr, end, &next); switch (tok) { case XML_TOK_NONE: @@ -5547,152 +5303,143 @@ return XML_ERROR_INVALID_TOKEN; case XML_TOK_PARTIAL: if (enc == parser->m_encoding) parser->m_eventPtr = ptr; return XML_ERROR_INVALID_TOKEN; - case XML_TOK_CHAR_REF: - { - XML_Char buf[XML_ENCODE_MAX]; - int i; - int n = XmlCharRefNumber(enc, ptr); - if (n < 0) { - if (enc == parser->m_encoding) - parser->m_eventPtr = ptr; - return XML_ERROR_BAD_CHAR_REF; - } - if (!isCdata - && n == 0x20 /* space */ - && (poolLength(pool) == 0 || poolLastChar(pool) == 0x20)) - break; - n = XmlEncode(n, (ICHAR *)buf); - /* The XmlEncode() functions can never return 0 here. That - * error return happens if the code point passed in is either - * negative or greater than or equal to 0x110000. The - * XmlCharRefNumber() functions will all return a number - * strictly less than 0x110000 or a negative value if an error - * occurred. The negative value is intercepted above, so - * XmlEncode() is never passed a value it might return an - * error for. - */ - for (i = 0; i < n; i++) { - if (!poolAppendChar(pool, buf[i])) - return XML_ERROR_NO_MEMORY; - } - } - break; + case XML_TOK_CHAR_REF: { + XML_Char buf[XML_ENCODE_MAX]; + int i; + int n = XmlCharRefNumber(enc, ptr); + if (n < 0) { + if (enc == parser->m_encoding) + parser->m_eventPtr = ptr; + return XML_ERROR_BAD_CHAR_REF; + } + if (! isCdata && n == 0x20 /* space */ + && (poolLength(pool) == 0 || poolLastChar(pool) == 0x20)) + break; + n = XmlEncode(n, (ICHAR *)buf); + /* The XmlEncode() functions can never return 0 here. That + * error return happens if the code point passed in is either + * negative or greater than or equal to 0x110000. The + * XmlCharRefNumber() functions will all return a number + * strictly less than 0x110000 or a negative value if an error + * occurred. The negative value is intercepted above, so + * XmlEncode() is never passed a value it might return an + * error for. + */ + for (i = 0; i < n; i++) { + if (! poolAppendChar(pool, buf[i])) + return XML_ERROR_NO_MEMORY; + } + } break; case XML_TOK_DATA_CHARS: - if (!poolAppend(pool, enc, ptr, next)) + if (! poolAppend(pool, enc, ptr, next)) return XML_ERROR_NO_MEMORY; break; case XML_TOK_TRAILING_CR: next = ptr + enc->minBytesPerChar; /* fall through */ case XML_TOK_ATTRIBUTE_VALUE_S: case XML_TOK_DATA_NEWLINE: - if (!isCdata && (poolLength(pool) == 0 || poolLastChar(pool) == 0x20)) - break; - if (!poolAppendChar(pool, 0x20)) - return XML_ERROR_NO_MEMORY; - break; - case XML_TOK_ENTITY_REF: - { - const XML_Char *name; - ENTITY *entity; - char checkEntityDecl; - XML_Char ch = (XML_Char) XmlPredefinedEntityName(enc, - ptr + enc->minBytesPerChar, - next - enc->minBytesPerChar); - if (ch) { - if (!poolAppendChar(pool, ch)) - return XML_ERROR_NO_MEMORY; - break; - } - name = poolStoreString(&parser->m_temp2Pool, enc, - ptr + enc->minBytesPerChar, - next - enc->minBytesPerChar); - if (!name) - return XML_ERROR_NO_MEMORY; - entity = (ENTITY *)lookup(parser, &dtd->generalEntities, name, 0); - poolDiscard(&parser->m_temp2Pool); - /* First, determine if a check for an existing declaration is needed; - if yes, check that the entity exists, and that it is internal. - */ - if (pool == &dtd->pool) /* are we called from prolog? */ - checkEntityDecl = -#ifdef XML_DTD - parser->m_prologState.documentEntity && -#endif /* XML_DTD */ - (dtd->standalone - ? !parser->m_openInternalEntities - : !dtd->hasParamEntityRefs); - else /* if (pool == &parser->m_tempPool): we are called from content */ - checkEntityDecl = !dtd->hasParamEntityRefs || dtd->standalone; - if (checkEntityDecl) { - if (!entity) - return XML_ERROR_UNDEFINED_ENTITY; - else if (!entity->is_internal) - return XML_ERROR_ENTITY_DECLARED_IN_PE; - } - else if (!entity) { - /* Cannot report skipped entity here - see comments on - parser->m_skippedEntityHandler. - if (parser->m_skippedEntityHandler) - parser->m_skippedEntityHandler(parser->m_handlerArg, name, 0); - */ - /* Cannot call the default handler because this would be - out of sync with the call to the startElementHandler. - if ((pool == &parser->m_tempPool) && parser->m_defaultHandler) - reportDefault(parser, enc, ptr, next); - */ - break; - } - if (entity->open) { - if (enc == parser->m_encoding) { - /* It does not appear that this line can be executed. - * - * The "if (entity->open)" check catches recursive entity - * definitions. In order to be called with an open - * entity, it must have gone through this code before and - * been through the recursive call to - * appendAttributeValue() some lines below. That call - * sets the local encoding ("enc") to the parser's - * internal encoding (internal_utf8 or internal_utf16), - * which can never be the same as the principle encoding. - * It doesn't appear there is another code path that gets - * here with entity->open being TRUE. - * - * Since it is not certain that this logic is watertight, - * we keep the line and merely exclude it from coverage - * tests. - */ - parser->m_eventPtr = ptr; /* LCOV_EXCL_LINE */ - } - return XML_ERROR_RECURSIVE_ENTITY_REF; - } - if (entity->notation) { - if (enc == parser->m_encoding) - parser->m_eventPtr = ptr; - return XML_ERROR_BINARY_ENTITY_REF; - } - if (!entity->textPtr) { - if (enc == parser->m_encoding) - parser->m_eventPtr = ptr; - return XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF; - } - else { - enum XML_Error result; - const XML_Char *textEnd = entity->textPtr + entity->textLen; - entity->open = XML_TRUE; - result = appendAttributeValue(parser, parser->m_internalEncoding, isCdata, - (char *)entity->textPtr, - (char *)textEnd, pool); - entity->open = XML_FALSE; - if (result) - return result; - } - } - break; + if (! isCdata && (poolLength(pool) == 0 || poolLastChar(pool) == 0x20)) + break; + if (! poolAppendChar(pool, 0x20)) + return XML_ERROR_NO_MEMORY; + break; + case XML_TOK_ENTITY_REF: { + const XML_Char *name; + ENTITY *entity; + char checkEntityDecl; + XML_Char ch = (XML_Char)XmlPredefinedEntityName( + enc, ptr + enc->minBytesPerChar, next - enc->minBytesPerChar); + if (ch) { + if (! poolAppendChar(pool, ch)) + return XML_ERROR_NO_MEMORY; + break; + } + name = poolStoreString(&parser->m_temp2Pool, enc, + ptr + enc->minBytesPerChar, + next - enc->minBytesPerChar); + if (! name) + return XML_ERROR_NO_MEMORY; + entity = (ENTITY *)lookup(parser, &dtd->generalEntities, name, 0); + poolDiscard(&parser->m_temp2Pool); + /* First, determine if a check for an existing declaration is needed; + if yes, check that the entity exists, and that it is internal. + */ + if (pool == &dtd->pool) /* are we called from prolog? */ + checkEntityDecl = +#ifdef XML_DTD + parser->m_prologState.documentEntity && +#endif /* XML_DTD */ + (dtd->standalone ? ! parser->m_openInternalEntities + : ! dtd->hasParamEntityRefs); + else /* if (pool == &parser->m_tempPool): we are called from content */ + checkEntityDecl = ! dtd->hasParamEntityRefs || dtd->standalone; + if (checkEntityDecl) { + if (! entity) + return XML_ERROR_UNDEFINED_ENTITY; + else if (! entity->is_internal) + return XML_ERROR_ENTITY_DECLARED_IN_PE; + } else if (! entity) { + /* Cannot report skipped entity here - see comments on + parser->m_skippedEntityHandler. + if (parser->m_skippedEntityHandler) + parser->m_skippedEntityHandler(parser->m_handlerArg, name, 0); + */ + /* Cannot call the default handler because this would be + out of sync with the call to the startElementHandler. + if ((pool == &parser->m_tempPool) && parser->m_defaultHandler) + reportDefault(parser, enc, ptr, next); + */ + break; + } + if (entity->open) { + if (enc == parser->m_encoding) { + /* It does not appear that this line can be executed. + * + * The "if (entity->open)" check catches recursive entity + * definitions. In order to be called with an open + * entity, it must have gone through this code before and + * been through the recursive call to + * appendAttributeValue() some lines below. That call + * sets the local encoding ("enc") to the parser's + * internal encoding (internal_utf8 or internal_utf16), + * which can never be the same as the principle encoding. + * It doesn't appear there is another code path that gets + * here with entity->open being TRUE. + * + * Since it is not certain that this logic is watertight, + * we keep the line and merely exclude it from coverage + * tests. + */ + parser->m_eventPtr = ptr; /* LCOV_EXCL_LINE */ + } + return XML_ERROR_RECURSIVE_ENTITY_REF; + } + if (entity->notation) { + if (enc == parser->m_encoding) + parser->m_eventPtr = ptr; + return XML_ERROR_BINARY_ENTITY_REF; + } + if (! entity->textPtr) { + if (enc == parser->m_encoding) + parser->m_eventPtr = ptr; + return XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF; + } else { + enum XML_Error result; + const XML_Char *textEnd = entity->textPtr + entity->textLen; + entity->open = XML_TRUE; + result = appendAttributeValue(parser, parser->m_internalEncoding, + isCdata, (char *)entity->textPtr, + (char *)textEnd, pool); + entity->open = XML_FALSE; + if (result) + return result; + } + } break; default: /* The only token returned by XmlAttributeValueTok() that does * not have an explicit case here is XML_TOK_PARTIAL_CHAR. * Getting that would require an entity name to contain an * incomplete XML character (e.g. \xE2\x82); however previous @@ -5712,27 +5459,24 @@ } /* not reached */ } static enum XML_Error -storeEntityValue(XML_Parser parser, - const ENCODING *enc, - const char *entityTextPtr, - const char *entityTextEnd) -{ - DTD * const dtd = parser->m_dtd; /* save one level of indirection */ +storeEntityValue(XML_Parser parser, const ENCODING *enc, + const char *entityTextPtr, const char *entityTextEnd) { + DTD *const dtd = parser->m_dtd; /* save one level of indirection */ STRING_POOL *pool = &(dtd->entityValuePool); enum XML_Error result = XML_ERROR_NONE; #ifdef XML_DTD int oldInEntityValue = parser->m_prologState.inEntityValue; parser->m_prologState.inEntityValue = 1; #endif /* XML_DTD */ /* never return Null for the value argument in EntityDeclHandler, since this would indicate an external entity; therefore we have to make sure that entityValuePool.start is not null */ - if (!pool->blocks) { - if (!poolGrow(pool)) + if (! pool->blocks) { + if (! poolGrow(pool)) return XML_ERROR_NO_MEMORY; } for (;;) { const char *next; @@ -5744,17 +5488,17 @@ const XML_Char *name; ENTITY *entity; name = poolStoreString(&parser->m_tempPool, enc, entityTextPtr + enc->minBytesPerChar, next - enc->minBytesPerChar); - if (!name) { + if (! name) { result = XML_ERROR_NO_MEMORY; goto endEntityValue; } entity = (ENTITY *)lookup(parser, &dtd->paramEntities, name, 0); poolDiscard(&parser->m_tempPool); - if (!entity) { + if (! entity) { /* not a well-formedness error - see XML 1.0: WFC Entity Declared */ /* cannot report skipped entity here - see comments on parser->m_skippedEntityHandler if (parser->m_skippedEntityHandler) parser->m_skippedEntityHandler(parser->m_handlerArg, name, 0); @@ -5770,33 +5514,27 @@ } if (entity->systemId) { if (parser->m_externalEntityRefHandler) { dtd->paramEntityRead = XML_FALSE; entity->open = XML_TRUE; - if (!parser->m_externalEntityRefHandler(parser->m_externalEntityRefHandlerArg, - 0, - entity->base, - entity->systemId, - entity->publicId)) { + if (! parser->m_externalEntityRefHandler( + parser->m_externalEntityRefHandlerArg, 0, entity->base, + entity->systemId, entity->publicId)) { entity->open = XML_FALSE; result = XML_ERROR_EXTERNAL_ENTITY_HANDLING; goto endEntityValue; } entity->open = XML_FALSE; - if (!dtd->paramEntityRead) - dtd->keepProcessing = dtd->standalone; - } - else - dtd->keepProcessing = dtd->standalone; - } - else { - entity->open = XML_TRUE; - result = storeEntityValue(parser, - parser->m_internalEncoding, - (char *)entity->textPtr, - (char *)(entity->textPtr - + entity->textLen)); + if (! dtd->paramEntityRead) + dtd->keepProcessing = dtd->standalone; + } else + dtd->keepProcessing = dtd->standalone; + } else { + entity->open = XML_TRUE; + result = storeEntityValue( + parser, parser->m_internalEncoding, (char *)entity->textPtr, + (char *)(entity->textPtr + entity->textLen)); entity->open = XML_FALSE; if (result) goto endEntityValue; } break; @@ -5810,55 +5548,53 @@ case XML_TOK_NONE: result = XML_ERROR_NONE; goto endEntityValue; case XML_TOK_ENTITY_REF: case XML_TOK_DATA_CHARS: - if (!poolAppend(pool, enc, entityTextPtr, next)) { + if (! poolAppend(pool, enc, entityTextPtr, next)) { result = XML_ERROR_NO_MEMORY; goto endEntityValue; } break; case XML_TOK_TRAILING_CR: next = entityTextPtr + enc->minBytesPerChar; /* fall through */ case XML_TOK_DATA_NEWLINE: - if (pool->end == pool->ptr && !poolGrow(pool)) { - result = XML_ERROR_NO_MEMORY; + if (pool->end == pool->ptr && ! poolGrow(pool)) { + result = XML_ERROR_NO_MEMORY; goto endEntityValue; } *(pool->ptr)++ = 0xA; break; - case XML_TOK_CHAR_REF: - { - XML_Char buf[XML_ENCODE_MAX]; - int i; - int n = XmlCharRefNumber(enc, entityTextPtr); - if (n < 0) { - if (enc == parser->m_encoding) - parser->m_eventPtr = entityTextPtr; - result = XML_ERROR_BAD_CHAR_REF; - goto endEntityValue; - } - n = XmlEncode(n, (ICHAR *)buf); - /* The XmlEncode() functions can never return 0 here. That - * error return happens if the code point passed in is either - * negative or greater than or equal to 0x110000. The - * XmlCharRefNumber() functions will all return a number - * strictly less than 0x110000 or a negative value if an error - * occurred. The negative value is intercepted above, so - * XmlEncode() is never passed a value it might return an - * error for. - */ - for (i = 0; i < n; i++) { - if (pool->end == pool->ptr && !poolGrow(pool)) { - result = XML_ERROR_NO_MEMORY; - goto endEntityValue; - } - *(pool->ptr)++ = buf[i]; - } - } - break; + case XML_TOK_CHAR_REF: { + XML_Char buf[XML_ENCODE_MAX]; + int i; + int n = XmlCharRefNumber(enc, entityTextPtr); + if (n < 0) { + if (enc == parser->m_encoding) + parser->m_eventPtr = entityTextPtr; + result = XML_ERROR_BAD_CHAR_REF; + goto endEntityValue; + } + n = XmlEncode(n, (ICHAR *)buf); + /* The XmlEncode() functions can never return 0 here. That + * error return happens if the code point passed in is either + * negative or greater than or equal to 0x110000. The + * XmlCharRefNumber() functions will all return a number + * strictly less than 0x110000 or a negative value if an error + * occurred. The negative value is intercepted above, so + * XmlEncode() is never passed a value it might return an + * error for. + */ + for (i = 0; i < n; i++) { + if (pool->end == pool->ptr && ! poolGrow(pool)) { + result = XML_ERROR_NO_MEMORY; + goto endEntityValue; + } + *(pool->ptr)++ = buf[i]; + } + } break; case XML_TOK_PARTIAL: if (enc == parser->m_encoding) parser->m_eventPtr = entityTextPtr; result = XML_ERROR_INVALID_TOKEN; goto endEntityValue; @@ -5889,12 +5625,11 @@ #endif /* XML_DTD */ return result; } static void FASTCALL -normalizeLines(XML_Char *s) -{ +normalizeLines(XML_Char *s) { XML_Char *p; for (;; s++) { if (*s == XML_T('\0')) return; if (*s == 0xD) @@ -5904,81 +5639,74 @@ do { if (*s == 0xD) { *p++ = 0xA; if (*++s == 0xA) s++; - } - else + } else *p++ = *s++; } while (*s); *p = XML_T('\0'); } static int reportProcessingInstruction(XML_Parser parser, const ENCODING *enc, - const char *start, const char *end) -{ + const char *start, const char *end) { const XML_Char *target; XML_Char *data; const char *tem; - if (!parser->m_processingInstructionHandler) { + if (! parser->m_processingInstructionHandler) { if (parser->m_defaultHandler) reportDefault(parser, enc, start, end); return 1; } start += enc->minBytesPerChar * 2; tem = start + XmlNameLength(enc, start); target = poolStoreString(&parser->m_tempPool, enc, start, tem); - if (!target) + if (! target) return 0; poolFinish(&parser->m_tempPool); - data = poolStoreString(&parser->m_tempPool, enc, - XmlSkipS(enc, tem), - end - enc->minBytesPerChar*2); - if (!data) + data = poolStoreString(&parser->m_tempPool, enc, XmlSkipS(enc, tem), + end - enc->minBytesPerChar * 2); + if (! data) return 0; normalizeLines(data); parser->m_processingInstructionHandler(parser->m_handlerArg, target, data); poolClear(&parser->m_tempPool); return 1; } static int -reportComment(XML_Parser parser, const ENCODING *enc, - const char *start, const char *end) -{ +reportComment(XML_Parser parser, const ENCODING *enc, const char *start, + const char *end) { XML_Char *data; - if (!parser->m_commentHandler) { + if (! parser->m_commentHandler) { if (parser->m_defaultHandler) reportDefault(parser, enc, start, end); return 1; } - data = poolStoreString(&parser->m_tempPool, - enc, + data = poolStoreString(&parser->m_tempPool, enc, start + enc->minBytesPerChar * 4, end - enc->minBytesPerChar * 3); - if (!data) + if (! data) return 0; normalizeLines(data); parser->m_commentHandler(parser->m_handlerArg, data); poolClear(&parser->m_tempPool); return 1; } static void -reportDefault(XML_Parser parser, const ENCODING *enc, - const char *s, const char *end) -{ +reportDefault(XML_Parser parser, const ENCODING *enc, const char *s, + const char *end) { if (MUST_CONVERT(enc, s)) { enum XML_Convert_Result convert_res; const char **eventPP; const char **eventEndPP; if (enc == parser->m_encoding) { eventPP = &parser->m_eventPtr; eventEndPP = &parser->m_eventEndPtr; - } - else { + } else { /* To get here, two things must be true; the parser must be * using a character encoding that is not the same as the * encoding passed in, and the encoding passed in must need * conversion to the internal format (UTF-8 unless XML_UNICODE * is defined). The only occasions on which the encoding passed @@ -5997,51 +5725,51 @@ eventEndPP = &(parser->m_openInternalEntities->internalEventEndPtr); /* LCOV_EXCL_STOP */ } do { ICHAR *dataPtr = (ICHAR *)parser->m_dataBuf; - convert_res = XmlConvert(enc, &s, end, &dataPtr, (ICHAR *)parser->m_dataBufEnd); + convert_res + = XmlConvert(enc, &s, end, &dataPtr, (ICHAR *)parser->m_dataBufEnd); *eventEndPP = s; - parser->m_defaultHandler(parser->m_handlerArg, parser->m_dataBuf, (int)(dataPtr - (ICHAR *)parser->m_dataBuf)); + parser->m_defaultHandler(parser->m_handlerArg, parser->m_dataBuf, + (int)(dataPtr - (ICHAR *)parser->m_dataBuf)); *eventPP = s; - } while ((convert_res != XML_CONVERT_COMPLETED) && (convert_res != XML_CONVERT_INPUT_INCOMPLETE)); - } - else - parser->m_defaultHandler(parser->m_handlerArg, (XML_Char *)s, (int)((XML_Char *)end - (XML_Char *)s)); + } while ((convert_res != XML_CONVERT_COMPLETED) + && (convert_res != XML_CONVERT_INPUT_INCOMPLETE)); + } else + parser->m_defaultHandler(parser->m_handlerArg, (XML_Char *)s, + (int)((XML_Char *)end - (XML_Char *)s)); } - static int defineAttribute(ELEMENT_TYPE *type, ATTRIBUTE_ID *attId, XML_Bool isCdata, - XML_Bool isId, const XML_Char *value, XML_Parser parser) -{ + XML_Bool isId, const XML_Char *value, XML_Parser parser) { DEFAULT_ATTRIBUTE *att; if (value || isId) { /* The handling of default attributes gets messed up if we have a default which duplicates a non-default. */ int i; for (i = 0; i < type->nDefaultAtts; i++) if (attId == type->defaultAtts[i].id) return 1; - if (isId && !type->idAtt && !attId->xmlns) + if (isId && ! type->idAtt && ! attId->xmlns) type->idAtt = attId; } if (type->nDefaultAtts == type->allocDefaultAtts) { if (type->allocDefaultAtts == 0) { type->allocDefaultAtts = 8; - type->defaultAtts = (DEFAULT_ATTRIBUTE *)MALLOC(parser, type->allocDefaultAtts - * sizeof(DEFAULT_ATTRIBUTE)); - if (!type->defaultAtts) { + type->defaultAtts = (DEFAULT_ATTRIBUTE *)MALLOC( + parser, type->allocDefaultAtts * sizeof(DEFAULT_ATTRIBUTE)); + if (! type->defaultAtts) { type->allocDefaultAtts = 0; return 0; } - } - else { + } else { DEFAULT_ATTRIBUTE *temp; int count = type->allocDefaultAtts * 2; - temp = (DEFAULT_ATTRIBUTE *) - REALLOC(parser, type->defaultAtts, (count * sizeof(DEFAULT_ATTRIBUTE))); + temp = (DEFAULT_ATTRIBUTE *)REALLOC(parser, type->defaultAtts, + (count * sizeof(DEFAULT_ATTRIBUTE))); if (temp == NULL) return 0; type->allocDefaultAtts = count; type->defaultAtts = temp; } @@ -6048,96 +5776,93 @@ } att = type->defaultAtts + type->nDefaultAtts; att->id = attId; att->value = value; att->isCdata = isCdata; - if (!isCdata) + if (! isCdata) attId->maybeTokenized = XML_TRUE; type->nDefaultAtts += 1; return 1; } static int -setElementTypePrefix(XML_Parser parser, ELEMENT_TYPE *elementType) -{ - DTD * const dtd = parser->m_dtd; /* save one level of indirection */ +setElementTypePrefix(XML_Parser parser, ELEMENT_TYPE *elementType) { + DTD *const dtd = parser->m_dtd; /* save one level of indirection */ const XML_Char *name; for (name = elementType->name; *name; name++) { if (*name == XML_T(ASCII_COLON)) { PREFIX *prefix; const XML_Char *s; for (s = elementType->name; s != name; s++) { - if (!poolAppendChar(&dtd->pool, *s)) + if (! poolAppendChar(&dtd->pool, *s)) return 0; } - if (!poolAppendChar(&dtd->pool, XML_T('\0'))) + if (! poolAppendChar(&dtd->pool, XML_T('\0'))) return 0; prefix = (PREFIX *)lookup(parser, &dtd->prefixes, poolStart(&dtd->pool), sizeof(PREFIX)); - if (!prefix) + if (! prefix) return 0; if (prefix->name == poolStart(&dtd->pool)) poolFinish(&dtd->pool); else poolDiscard(&dtd->pool); elementType->prefix = prefix; - + break; } } return 1; } static ATTRIBUTE_ID * -getAttributeId(XML_Parser parser, const ENCODING *enc, - const char *start, const char *end) -{ - DTD * const dtd = parser->m_dtd; /* save one level of indirection */ +getAttributeId(XML_Parser parser, const ENCODING *enc, const char *start, + const char *end) { + DTD *const dtd = parser->m_dtd; /* save one level of indirection */ ATTRIBUTE_ID *id; const XML_Char *name; - if (!poolAppendChar(&dtd->pool, XML_T('\0'))) + if (! poolAppendChar(&dtd->pool, XML_T('\0'))) return NULL; name = poolStoreString(&dtd->pool, enc, start, end); - if (!name) + if (! name) return NULL; /* skip quotation mark - its storage will be re-used (like in name[-1]) */ ++name; - id = (ATTRIBUTE_ID *)lookup(parser, &dtd->attributeIds, name, sizeof(ATTRIBUTE_ID)); - if (!id) + id = (ATTRIBUTE_ID *)lookup(parser, &dtd->attributeIds, name, + sizeof(ATTRIBUTE_ID)); + if (! id) return NULL; if (id->name != name) poolDiscard(&dtd->pool); else { poolFinish(&dtd->pool); - if (!parser->m_ns) - ; - else if (name[0] == XML_T(ASCII_x) - && name[1] == XML_T(ASCII_m) - && name[2] == XML_T(ASCII_l) - && name[3] == XML_T(ASCII_n) - && name[4] == XML_T(ASCII_s) - && (name[5] == XML_T('\0') || name[5] == XML_T(ASCII_COLON))) { + if (! parser->m_ns) + ; + else if (name[0] == XML_T(ASCII_x) && name[1] == XML_T(ASCII_m) + && name[2] == XML_T(ASCII_l) && name[3] == XML_T(ASCII_n) + && name[4] == XML_T(ASCII_s) + && (name[5] == XML_T('\0') || name[5] == XML_T(ASCII_COLON))) { if (name[5] == XML_T('\0')) id->prefix = &dtd->defaultPrefix; else - id->prefix = (PREFIX *)lookup(parser, &dtd->prefixes, name + 6, sizeof(PREFIX)); + id->prefix = (PREFIX *)lookup(parser, &dtd->prefixes, name + 6, + sizeof(PREFIX)); id->xmlns = XML_TRUE; - } - else { + } else { int i; for (i = 0; name[i]; i++) { /* attributes without prefix are *not* in the default namespace */ if (name[i] == XML_T(ASCII_COLON)) { int j; for (j = 0; j < i; j++) { - if (!poolAppendChar(&dtd->pool, name[j])) + if (! poolAppendChar(&dtd->pool, name[j])) return NULL; } - if (!poolAppendChar(&dtd->pool, XML_T('\0'))) + if (! poolAppendChar(&dtd->pool, XML_T('\0'))) return NULL; - id->prefix = (PREFIX *)lookup(parser, &dtd->prefixes, poolStart(&dtd->pool), - sizeof(PREFIX)); - if (!id->prefix) + id->prefix = (PREFIX *)lookup(parser, &dtd->prefixes, + poolStart(&dtd->pool), sizeof(PREFIX)); + if (! id->prefix) return NULL; if (id->prefix->name == poolStart(&dtd->pool)) poolFinish(&dtd->pool); else poolDiscard(&dtd->pool); @@ -6150,26 +5875,26 @@ } #define CONTEXT_SEP XML_T(ASCII_FF) static const XML_Char * -getContext(XML_Parser parser) -{ - DTD * const dtd = parser->m_dtd; /* save one level of indirection */ +getContext(XML_Parser parser) { + DTD *const dtd = parser->m_dtd; /* save one level of indirection */ HASH_TABLE_ITER iter; XML_Bool needSep = XML_FALSE; if (dtd->defaultPrefix.binding) { int i; int len; - if (!poolAppendChar(&parser->m_tempPool, XML_T(ASCII_EQUALS))) + if (! poolAppendChar(&parser->m_tempPool, XML_T(ASCII_EQUALS))) return NULL; len = dtd->defaultPrefix.binding->uriLen; if (parser->m_namespaceSeparator) len--; for (i = 0; i < len; i++) { - if (!poolAppendChar(&parser->m_tempPool, dtd->defaultPrefix.binding->uri[i])) { + if (! poolAppendChar(&parser->m_tempPool, + dtd->defaultPrefix.binding->uri[i])) { /* Because of memory caching, I don't believe this line can be * executed. * * This is part of a loop copying the default prefix binding * URI into the parser's temporary string pool. Previously, @@ -6197,123 +5922,120 @@ for (;;) { int i; int len; const XML_Char *s; PREFIX *prefix = (PREFIX *)hashTableIterNext(&iter); - if (!prefix) + if (! prefix) break; - if (!prefix->binding) { + if (! prefix->binding) { /* This test appears to be (justifiable) paranoia. There does * not seem to be a way of injecting a prefix without a binding * that doesn't get errored long before this function is called. * The test should remain for safety's sake, so we instead * exclude the following line from the coverage statistics. */ continue; /* LCOV_EXCL_LINE */ } - if (needSep && !poolAppendChar(&parser->m_tempPool, CONTEXT_SEP)) + if (needSep && ! poolAppendChar(&parser->m_tempPool, CONTEXT_SEP)) return NULL; for (s = prefix->name; *s; s++) - if (!poolAppendChar(&parser->m_tempPool, *s)) + if (! poolAppendChar(&parser->m_tempPool, *s)) return NULL; - if (!poolAppendChar(&parser->m_tempPool, XML_T(ASCII_EQUALS))) + if (! poolAppendChar(&parser->m_tempPool, XML_T(ASCII_EQUALS))) return NULL; len = prefix->binding->uriLen; if (parser->m_namespaceSeparator) len--; for (i = 0; i < len; i++) - if (!poolAppendChar(&parser->m_tempPool, prefix->binding->uri[i])) + if (! poolAppendChar(&parser->m_tempPool, prefix->binding->uri[i])) return NULL; needSep = XML_TRUE; } - hashTableIterInit(&iter, &(dtd->generalEntities)); for (;;) { const XML_Char *s; ENTITY *e = (ENTITY *)hashTableIterNext(&iter); - if (!e) + if (! e) break; - if (!e->open) + if (! e->open) continue; - if (needSep && !poolAppendChar(&parser->m_tempPool, CONTEXT_SEP)) + if (needSep && ! poolAppendChar(&parser->m_tempPool, CONTEXT_SEP)) return NULL; for (s = e->name; *s; s++) - if (!poolAppendChar(&parser->m_tempPool, *s)) + if (! poolAppendChar(&parser->m_tempPool, *s)) return 0; needSep = XML_TRUE; } - if (!poolAppendChar(&parser->m_tempPool, XML_T('\0'))) + if (! poolAppendChar(&parser->m_tempPool, XML_T('\0'))) return NULL; return parser->m_tempPool.start; } static XML_Bool -setContext(XML_Parser parser, const XML_Char *context) -{ - DTD * const dtd = parser->m_dtd; /* save one level of indirection */ +setContext(XML_Parser parser, const XML_Char *context) { + DTD *const dtd = parser->m_dtd; /* save one level of indirection */ const XML_Char *s = context; while (*context != XML_T('\0')) { if (*s == CONTEXT_SEP || *s == XML_T('\0')) { ENTITY *e; - if (!poolAppendChar(&parser->m_tempPool, XML_T('\0'))) + if (! poolAppendChar(&parser->m_tempPool, XML_T('\0'))) return XML_FALSE; - e = (ENTITY *)lookup(parser, &dtd->generalEntities, poolStart(&parser->m_tempPool), 0); + e = (ENTITY *)lookup(parser, &dtd->generalEntities, + poolStart(&parser->m_tempPool), 0); if (e) e->open = XML_TRUE; if (*s != XML_T('\0')) s++; context = s; poolDiscard(&parser->m_tempPool); - } - else if (*s == XML_T(ASCII_EQUALS)) { + } else if (*s == XML_T(ASCII_EQUALS)) { PREFIX *prefix; if (poolLength(&parser->m_tempPool) == 0) prefix = &dtd->defaultPrefix; else { - if (!poolAppendChar(&parser->m_tempPool, XML_T('\0'))) + if (! poolAppendChar(&parser->m_tempPool, XML_T('\0'))) return XML_FALSE; - prefix = (PREFIX *)lookup(parser, &dtd->prefixes, poolStart(&parser->m_tempPool), - sizeof(PREFIX)); - if (!prefix) + prefix + = (PREFIX *)lookup(parser, &dtd->prefixes, + poolStart(&parser->m_tempPool), sizeof(PREFIX)); + if (! prefix) return XML_FALSE; if (prefix->name == poolStart(&parser->m_tempPool)) { prefix->name = poolCopyString(&dtd->pool, prefix->name); - if (!prefix->name) + if (! prefix->name) return XML_FALSE; } poolDiscard(&parser->m_tempPool); } - for (context = s + 1; - *context != CONTEXT_SEP && *context != XML_T('\0'); + for (context = s + 1; *context != CONTEXT_SEP && *context != XML_T('\0'); context++) - if (!poolAppendChar(&parser->m_tempPool, *context)) + if (! poolAppendChar(&parser->m_tempPool, *context)) return XML_FALSE; - if (!poolAppendChar(&parser->m_tempPool, XML_T('\0'))) + if (! poolAppendChar(&parser->m_tempPool, XML_T('\0'))) return XML_FALSE; if (addBinding(parser, prefix, NULL, poolStart(&parser->m_tempPool), - &parser->m_inheritedBindings) != XML_ERROR_NONE) + &parser->m_inheritedBindings) + != XML_ERROR_NONE) return XML_FALSE; poolDiscard(&parser->m_tempPool); if (*context != XML_T('\0')) ++context; s = context; - } - else { - if (!poolAppendChar(&parser->m_tempPool, *s)) + } else { + if (! poolAppendChar(&parser->m_tempPool, *s)) return XML_FALSE; s++; } } return XML_TRUE; } static void FASTCALL -normalizePublicId(XML_Char *publicId) -{ +normalizePublicId(XML_Char *publicId) { XML_Char *p = publicId; XML_Char *s; for (s = publicId; *s; s++) { switch (*s) { case 0x20: @@ -6330,12 +6052,11 @@ --p; *p = XML_T('\0'); } static DTD * -dtdCreate(const XML_Memory_Handling_Suite *ms) -{ +dtdCreate(const XML_Memory_Handling_Suite *ms) { DTD *p = (DTD *)ms->malloc_fcn(sizeof(DTD)); if (p == NULL) return p; poolInit(&(p->pool), ms); poolInit(&(p->entityValuePool), ms); @@ -6363,17 +6084,16 @@ p->standalone = XML_FALSE; return p; } static void -dtdReset(DTD *p, const XML_Memory_Handling_Suite *ms) -{ +dtdReset(DTD *p, const XML_Memory_Handling_Suite *ms) { HASH_TABLE_ITER iter; hashTableIterInit(&iter, &(p->elementTypes)); for (;;) { ELEMENT_TYPE *e = (ELEMENT_TYPE *)hashTableIterNext(&iter); - if (!e) + if (! e) break; if (e->allocDefaultAtts != 0) ms->free_fcn(e->defaultAtts); } hashTableClear(&(p->generalEntities)); @@ -6405,17 +6125,16 @@ p->hasParamEntityRefs = XML_FALSE; p->standalone = XML_FALSE; } static void -dtdDestroy(DTD *p, XML_Bool isDocEntity, const XML_Memory_Handling_Suite *ms) -{ +dtdDestroy(DTD *p, XML_Bool isDocEntity, const XML_Memory_Handling_Suite *ms) { HASH_TABLE_ITER iter; hashTableIterInit(&iter, &(p->elementTypes)); for (;;) { ELEMENT_TYPE *e = (ELEMENT_TYPE *)hashTableIterNext(&iter); - if (!e) + if (! e) break; if (e->allocDefaultAtts != 0) ms->free_fcn(e->defaultAtts); } hashTableDestroy(&(p->generalEntities)); @@ -6436,26 +6155,26 @@ /* Do a deep copy of the DTD. Return 0 for out of memory, non-zero otherwise. The new DTD has already been initialized. */ static int -dtdCopy(XML_Parser oldParser, DTD *newDtd, const DTD *oldDtd, const XML_Memory_Handling_Suite *ms) -{ +dtdCopy(XML_Parser oldParser, DTD *newDtd, const DTD *oldDtd, + const XML_Memory_Handling_Suite *ms) { HASH_TABLE_ITER iter; /* Copy the prefix table. */ hashTableIterInit(&iter, &(oldDtd->prefixes)); for (;;) { const XML_Char *name; const PREFIX *oldP = (PREFIX *)hashTableIterNext(&iter); - if (!oldP) + if (! oldP) break; name = poolCopyString(&(newDtd->pool), oldP->name); - if (!name) + if (! name) return 0; - if (!lookup(oldParser, &(newDtd->prefixes), name, sizeof(PREFIX))) + if (! lookup(oldParser, &(newDtd->prefixes), name, sizeof(PREFIX))) return 0; } hashTableIterInit(&iter, &(oldDtd->attributeIds)); @@ -6464,22 +6183,22 @@ for (;;) { ATTRIBUTE_ID *newA; const XML_Char *name; const ATTRIBUTE_ID *oldA = (ATTRIBUTE_ID *)hashTableIterNext(&iter); - if (!oldA) + if (! oldA) break; /* Remember to allocate the scratch byte before the name. */ - if (!poolAppendChar(&(newDtd->pool), XML_T('\0'))) + if (! poolAppendChar(&(newDtd->pool), XML_T('\0'))) return 0; name = poolCopyString(&(newDtd->pool), oldA->name); - if (!name) + if (! name) return 0; ++name; newA = (ATTRIBUTE_ID *)lookup(oldParser, &(newDtd->attributeIds), name, sizeof(ATTRIBUTE_ID)); - if (!newA) + if (! newA) return 0; newA->maybeTokenized = oldA->maybeTokenized; if (oldA->prefix) { newA->xmlns = oldA->xmlns; if (oldA->prefix == &oldDtd->defaultPrefix) @@ -6497,61 +6216,56 @@ for (;;) { int i; ELEMENT_TYPE *newE; const XML_Char *name; const ELEMENT_TYPE *oldE = (ELEMENT_TYPE *)hashTableIterNext(&iter); - if (!oldE) + if (! oldE) break; name = poolCopyString(&(newDtd->pool), oldE->name); - if (!name) + if (! name) return 0; newE = (ELEMENT_TYPE *)lookup(oldParser, &(newDtd->elementTypes), name, sizeof(ELEMENT_TYPE)); - if (!newE) + if (! newE) return 0; if (oldE->nDefaultAtts) { - newE->defaultAtts = (DEFAULT_ATTRIBUTE *) - ms->malloc_fcn(oldE->nDefaultAtts * sizeof(DEFAULT_ATTRIBUTE)); - if (!newE->defaultAtts) { + newE->defaultAtts = (DEFAULT_ATTRIBUTE *)ms->malloc_fcn( + oldE->nDefaultAtts * sizeof(DEFAULT_ATTRIBUTE)); + if (! newE->defaultAtts) { return 0; } } if (oldE->idAtt) - newE->idAtt = (ATTRIBUTE_ID *) - lookup(oldParser, &(newDtd->attributeIds), oldE->idAtt->name, 0); + newE->idAtt = (ATTRIBUTE_ID *)lookup(oldParser, &(newDtd->attributeIds), + oldE->idAtt->name, 0); newE->allocDefaultAtts = newE->nDefaultAtts = oldE->nDefaultAtts; if (oldE->prefix) newE->prefix = (PREFIX *)lookup(oldParser, &(newDtd->prefixes), oldE->prefix->name, 0); for (i = 0; i < newE->nDefaultAtts; i++) { - newE->defaultAtts[i].id = (ATTRIBUTE_ID *) - lookup(oldParser, &(newDtd->attributeIds), oldE->defaultAtts[i].id->name, 0); + newE->defaultAtts[i].id = (ATTRIBUTE_ID *)lookup( + oldParser, &(newDtd->attributeIds), oldE->defaultAtts[i].id->name, 0); newE->defaultAtts[i].isCdata = oldE->defaultAtts[i].isCdata; if (oldE->defaultAtts[i].value) { newE->defaultAtts[i].value = poolCopyString(&(newDtd->pool), oldE->defaultAtts[i].value); - if (!newE->defaultAtts[i].value) + if (! newE->defaultAtts[i].value) return 0; - } - else + } else newE->defaultAtts[i].value = NULL; } } /* Copy the entity tables. */ - if (!copyEntityTable(oldParser, - &(newDtd->generalEntities), - &(newDtd->pool), - &(oldDtd->generalEntities))) - return 0; + if (! copyEntityTable(oldParser, &(newDtd->generalEntities), &(newDtd->pool), + &(oldDtd->generalEntities))) + return 0; #ifdef XML_DTD - if (!copyEntityTable(oldParser, - &(newDtd->paramEntities), - &(newDtd->pool), - &(oldDtd->paramEntities))) - return 0; + if (! copyEntityTable(oldParser, &(newDtd->paramEntities), &(newDtd->pool), + &(oldDtd->paramEntities))) + return 0; newDtd->paramEntityRead = oldDtd->paramEntityRead; #endif /* XML_DTD */ newDtd->keepProcessing = oldDtd->keepProcessing; newDtd->hasParamEntityRefs = oldDtd->hasParamEntityRefs; @@ -6564,18 +6278,15 @@ newDtd->scaffSize = oldDtd->scaffSize; newDtd->scaffLevel = oldDtd->scaffLevel; newDtd->scaffIndex = oldDtd->scaffIndex; return 1; -} /* End dtdCopy */ +} /* End dtdCopy */ static int -copyEntityTable(XML_Parser oldParser, - HASH_TABLE *newTable, - STRING_POOL *newPool, - const HASH_TABLE *oldTable) -{ +copyEntityTable(XML_Parser oldParser, HASH_TABLE *newTable, + STRING_POOL *newPool, const HASH_TABLE *oldTable) { HASH_TABLE_ITER iter; const XML_Char *cachedOldBase = NULL; const XML_Char *cachedNewBase = NULL; hashTableIterInit(&iter, oldTable); @@ -6582,52 +6293,51 @@ for (;;) { ENTITY *newE; const XML_Char *name; const ENTITY *oldE = (ENTITY *)hashTableIterNext(&iter); - if (!oldE) + if (! oldE) break; name = poolCopyString(newPool, oldE->name); - if (!name) + if (! name) return 0; newE = (ENTITY *)lookup(oldParser, newTable, name, sizeof(ENTITY)); - if (!newE) + if (! newE) return 0; if (oldE->systemId) { const XML_Char *tem = poolCopyString(newPool, oldE->systemId); - if (!tem) + if (! tem) return 0; newE->systemId = tem; if (oldE->base) { if (oldE->base == cachedOldBase) newE->base = cachedNewBase; else { cachedOldBase = oldE->base; tem = poolCopyString(newPool, cachedOldBase); - if (!tem) + if (! tem) return 0; cachedNewBase = newE->base = tem; } } if (oldE->publicId) { tem = poolCopyString(newPool, oldE->publicId); - if (!tem) + if (! tem) return 0; newE->publicId = tem; } - } - else { - const XML_Char *tem = poolCopyStringN(newPool, oldE->textPtr, - oldE->textLen); - if (!tem) + } else { + const XML_Char *tem + = poolCopyStringN(newPool, oldE->textPtr, oldE->textLen); + if (! tem) return 0; newE->textPtr = tem; newE->textLen = oldE->textLen; } if (oldE->notation) { const XML_Char *tem = poolCopyString(newPool, oldE->notation); - if (!tem) + if (! tem) return 0; newE->notation = tem; } newE->is_param = oldE->is_param; newE->is_internal = oldE->is_internal; @@ -6636,36 +6346,33 @@ } #define INIT_POWER 6 static XML_Bool FASTCALL -keyeq(KEY s1, KEY s2) -{ +keyeq(KEY s1, KEY s2) { for (; *s1 == *s2; s1++, s2++) if (*s1 == 0) return XML_TRUE; return XML_FALSE; } static size_t -keylen(KEY s) -{ +keylen(KEY s) { size_t len = 0; - for (; *s; s++, len++); + for (; *s; s++, len++) + ; return len; } static void -copy_salt_to_sipkey(XML_Parser parser, struct sipkey * key) -{ +copy_salt_to_sipkey(XML_Parser parser, struct sipkey *key) { key->k[0] = 0; key->k[1] = get_hash_secret_salt(parser); } static unsigned long FASTCALL -hash(XML_Parser parser, KEY s) -{ +hash(XML_Parser parser, KEY s) { struct siphash state; struct sipkey key; (void)sip24_valid; copy_salt_to_sipkey(parser, &key); sip24_init(&state, &key); @@ -6672,61 +6379,59 @@ sip24_update(&state, s, keylen(s) * sizeof(XML_Char)); return (unsigned long)sip24_final(&state); } static NAMED * -lookup(XML_Parser parser, HASH_TABLE *table, KEY name, size_t createSize) -{ +lookup(XML_Parser parser, HASH_TABLE *table, KEY name, size_t createSize) { size_t i; if (table->size == 0) { size_t tsize; - if (!createSize) + if (! createSize) return NULL; table->power = INIT_POWER; /* table->size is a power of 2 */ table->size = (size_t)1 << INIT_POWER; tsize = table->size * sizeof(NAMED *); table->v = (NAMED **)table->mem->malloc_fcn(tsize); - if (!table->v) { + if (! table->v) { table->size = 0; return NULL; } memset(table->v, 0, tsize); i = hash(parser, name) & ((unsigned long)table->size - 1); - } - else { + } else { unsigned long h = hash(parser, name); unsigned long mask = (unsigned long)table->size - 1; unsigned char step = 0; i = h & mask; while (table->v[i]) { if (keyeq(name, table->v[i]->name)) return table->v[i]; - if (!step) + if (! step) step = PROBE_STEP(h, mask, table->power); i < step ? (i += table->size - step) : (i -= step); } - if (!createSize) + if (! createSize) return NULL; /* check for overflow (table is half full) */ if (table->used >> (table->power - 1)) { unsigned char newPower = table->power + 1; size_t newSize = (size_t)1 << newPower; unsigned long newMask = (unsigned long)newSize - 1; size_t tsize = newSize * sizeof(NAMED *); NAMED **newV = (NAMED **)table->mem->malloc_fcn(tsize); - if (!newV) + if (! newV) return NULL; memset(newV, 0, tsize); for (i = 0; i < table->size; i++) if (table->v[i]) { unsigned long newHash = hash(parser, table->v[i]->name); size_t j = newHash & newMask; step = 0; while (newV[j]) { - if (!step) + if (! step) step = PROBE_STEP(newHash, newMask, newPower); j < step ? (j += newSize - step) : (j -= step); } newV[j] = table->v[i]; } @@ -6735,88 +6440,81 @@ table->power = newPower; table->size = newSize; i = h & newMask; step = 0; while (table->v[i]) { - if (!step) + if (! step) step = PROBE_STEP(h, newMask, newPower); i < step ? (i += newSize - step) : (i -= step); } } } table->v[i] = (NAMED *)table->mem->malloc_fcn(createSize); - if (!table->v[i]) + if (! table->v[i]) return NULL; memset(table->v[i], 0, createSize); table->v[i]->name = name; (table->used)++; return table->v[i]; } static void FASTCALL -hashTableClear(HASH_TABLE *table) -{ +hashTableClear(HASH_TABLE *table) { size_t i; for (i = 0; i < table->size; i++) { table->mem->free_fcn(table->v[i]); table->v[i] = NULL; } table->used = 0; } static void FASTCALL -hashTableDestroy(HASH_TABLE *table) -{ +hashTableDestroy(HASH_TABLE *table) { size_t i; for (i = 0; i < table->size; i++) table->mem->free_fcn(table->v[i]); table->mem->free_fcn(table->v); } static void FASTCALL -hashTableInit(HASH_TABLE *p, const XML_Memory_Handling_Suite *ms) -{ +hashTableInit(HASH_TABLE *p, const XML_Memory_Handling_Suite *ms) { p->power = 0; p->size = 0; p->used = 0; p->v = NULL; p->mem = ms; } static void FASTCALL -hashTableIterInit(HASH_TABLE_ITER *iter, const HASH_TABLE *table) -{ +hashTableIterInit(HASH_TABLE_ITER *iter, const HASH_TABLE *table) { iter->p = table->v; iter->end = iter->p + table->size; } -static NAMED * FASTCALL -hashTableIterNext(HASH_TABLE_ITER *iter) -{ +static NAMED *FASTCALL +hashTableIterNext(HASH_TABLE_ITER *iter) { while (iter->p != iter->end) { NAMED *tem = *(iter->p)++; if (tem) return tem; } return NULL; } static void FASTCALL -poolInit(STRING_POOL *pool, const XML_Memory_Handling_Suite *ms) -{ +poolInit(STRING_POOL *pool, const XML_Memory_Handling_Suite *ms) { pool->blocks = NULL; pool->freeBlocks = NULL; pool->start = NULL; pool->ptr = NULL; pool->end = NULL; pool->mem = ms; } static void FASTCALL -poolClear(STRING_POOL *pool) -{ - if (!pool->freeBlocks) +poolClear(STRING_POOL *pool) { + if (! pool->freeBlocks) pool->freeBlocks = pool->blocks; else { BLOCK *p = pool->blocks; while (p) { BLOCK *tem = p->next; @@ -6830,12 +6528,11 @@ pool->ptr = NULL; pool->end = NULL; } static void FASTCALL -poolDestroy(STRING_POOL *pool) -{ +poolDestroy(STRING_POOL *pool) { BLOCK *p = pool->blocks; while (p) { BLOCK *tem = p->next; pool->mem->free_fcn(p); p = tem; @@ -6847,41 +6544,40 @@ p = tem; } } static XML_Char * -poolAppend(STRING_POOL *pool, const ENCODING *enc, - const char *ptr, const char *end) -{ - if (!pool->ptr && !poolGrow(pool)) +poolAppend(STRING_POOL *pool, const ENCODING *enc, const char *ptr, + const char *end) { + if (! pool->ptr && ! poolGrow(pool)) return NULL; for (;;) { - const enum XML_Convert_Result convert_res = XmlConvert(enc, &ptr, end, (ICHAR **)&(pool->ptr), (ICHAR *)pool->end); - if ((convert_res == XML_CONVERT_COMPLETED) || (convert_res == XML_CONVERT_INPUT_INCOMPLETE)) + const enum XML_Convert_Result convert_res = XmlConvert( + enc, &ptr, end, (ICHAR **)&(pool->ptr), (ICHAR *)pool->end); + if ((convert_res == XML_CONVERT_COMPLETED) + || (convert_res == XML_CONVERT_INPUT_INCOMPLETE)) break; - if (!poolGrow(pool)) + if (! poolGrow(pool)) return NULL; } return pool->start; } -static const XML_Char * FASTCALL -poolCopyString(STRING_POOL *pool, const XML_Char *s) -{ +static const XML_Char *FASTCALL +poolCopyString(STRING_POOL *pool, const XML_Char *s) { do { - if (!poolAppendChar(pool, *s)) + if (! poolAppendChar(pool, *s)) return NULL; } while (*s++); s = pool->start; poolFinish(pool); return s; } static const XML_Char * -poolCopyStringN(STRING_POOL *pool, const XML_Char *s, int n) -{ - if (!pool->ptr && !poolGrow(pool)) { +poolCopyStringN(STRING_POOL *pool, const XML_Char *s, int n) { + if (! pool->ptr && ! poolGrow(pool)) { /* The following line is unreachable given the current usage of * poolCopyStringN(). Currently it is called from exactly one * place to copy the text of a simple general entity. By that * point, the name of the entity is already stored in the pool, so * pool->ptr cannot be NULL. @@ -6892,73 +6588,69 @@ * it from the coverage statistics. */ return NULL; /* LCOV_EXCL_LINE */ } for (; n > 0; --n, s++) { - if (!poolAppendChar(pool, *s)) + if (! poolAppendChar(pool, *s)) return NULL; } s = pool->start; poolFinish(pool); return s; } -static const XML_Char * FASTCALL -poolAppendString(STRING_POOL *pool, const XML_Char *s) -{ +static const XML_Char *FASTCALL +poolAppendString(STRING_POOL *pool, const XML_Char *s) { while (*s) { - if (!poolAppendChar(pool, *s)) + if (! poolAppendChar(pool, *s)) return NULL; s++; } return pool->start; } static XML_Char * -poolStoreString(STRING_POOL *pool, const ENCODING *enc, - const char *ptr, const char *end) -{ - if (!poolAppend(pool, enc, ptr, end)) +poolStoreString(STRING_POOL *pool, const ENCODING *enc, const char *ptr, + const char *end) { + if (! poolAppend(pool, enc, ptr, end)) return NULL; - if (pool->ptr == pool->end && !poolGrow(pool)) + if (pool->ptr == pool->end && ! poolGrow(pool)) return NULL; *(pool->ptr)++ = 0; return pool->start; } static size_t -poolBytesToAllocateFor(int blockSize) -{ +poolBytesToAllocateFor(int blockSize) { /* Unprotected math would be: ** return offsetof(BLOCK, s) + blockSize * sizeof(XML_Char); ** ** Detect overflow, avoiding _signed_ overflow undefined behavior ** For a + b * c we check b * c in isolation first, so that addition of a ** on top has no chance of making us accept a small non-negative number */ - const size_t stretch = sizeof(XML_Char); /* can be 4 bytes */ + const size_t stretch = sizeof(XML_Char); /* can be 4 bytes */ if (blockSize <= 0) return 0; if (blockSize > (int)(INT_MAX / stretch)) return 0; { const int stretchedBlockSize = blockSize * (int)stretch; - const int bytesToAllocate = (int)( - offsetof(BLOCK, s) + (unsigned)stretchedBlockSize); + const int bytesToAllocate + = (int)(offsetof(BLOCK, s) + (unsigned)stretchedBlockSize); if (bytesToAllocate < 0) return 0; return (size_t)bytesToAllocate; } } static XML_Bool FASTCALL -poolGrow(STRING_POOL *pool) -{ +poolGrow(STRING_POOL *pool) { if (pool->freeBlocks) { if (pool->start == 0) { pool->blocks = pool->freeBlocks; pool->freeBlocks = pool->freeBlocks->next; pool->blocks->next = NULL; @@ -6980,11 +6672,11 @@ return XML_TRUE; } } if (pool->blocks && pool->start == pool->blocks->s) { BLOCK *temp; - int blockSize = (int)((unsigned)(pool->end - pool->start)*2U); + int blockSize = (int)((unsigned)(pool->end - pool->start) * 2U); size_t bytesToAllocate; /* NOTE: Needs to be calculated prior to calling `realloc` to avoid dangling pointers: */ const ptrdiff_t offsetInsideBlock = pool->ptr - pool->start; @@ -7001,21 +6693,20 @@ bytesToAllocate = poolBytesToAllocateFor(blockSize); if (bytesToAllocate == 0) return XML_FALSE; - temp = (BLOCK *) - pool->mem->realloc_fcn(pool->blocks, (unsigned)bytesToAllocate); + temp = (BLOCK *)pool->mem->realloc_fcn(pool->blocks, + (unsigned)bytesToAllocate); if (temp == NULL) return XML_FALSE; pool->blocks = temp; pool->blocks->size = blockSize; pool->ptr = pool->blocks->s + offsetInsideBlock; pool->start = pool->blocks->s; pool->end = pool->start + blockSize; - } - else { + } else { BLOCK *tem; int blockSize = (int)(pool->end - pool->start); size_t bytesToAllocate; if (blockSize < 0) { @@ -7026,11 +6717,11 @@ * the pool control fields have been corrupted (which could * conceivably happen in an extremely buggy user handler * function). Either way it isn't readily testable, so we * exclude it from the coverage statistics. */ - return XML_FALSE; /* LCOV_EXCL_LINE */ + return XML_FALSE; /* LCOV_EXCL_LINE */ } if (blockSize < INIT_BLOCK_SIZE) blockSize = INIT_BLOCK_SIZE; else { @@ -7044,174 +6735,161 @@ bytesToAllocate = poolBytesToAllocateFor(blockSize); if (bytesToAllocate == 0) return XML_FALSE; tem = (BLOCK *)pool->mem->malloc_fcn(bytesToAllocate); - if (!tem) + if (! tem) return XML_FALSE; tem->size = blockSize; tem->next = pool->blocks; pool->blocks = tem; if (pool->ptr != pool->start) - memcpy(tem->s, pool->start, - (pool->ptr - pool->start) * sizeof(XML_Char)); + memcpy(tem->s, pool->start, (pool->ptr - pool->start) * sizeof(XML_Char)); pool->ptr = tem->s + (pool->ptr - pool->start); pool->start = tem->s; pool->end = tem->s + blockSize; } return XML_TRUE; } static int FASTCALL -nextScaffoldPart(XML_Parser parser) -{ - DTD * const dtd = parser->m_dtd; /* save one level of indirection */ - CONTENT_SCAFFOLD * me; +nextScaffoldPart(XML_Parser parser) { + DTD *const dtd = parser->m_dtd; /* save one level of indirection */ + CONTENT_SCAFFOLD *me; int next; - if (!dtd->scaffIndex) { + if (! dtd->scaffIndex) { dtd->scaffIndex = (int *)MALLOC(parser, parser->m_groupSize * sizeof(int)); - if (!dtd->scaffIndex) + if (! dtd->scaffIndex) return -1; dtd->scaffIndex[0] = 0; } if (dtd->scaffCount >= dtd->scaffSize) { CONTENT_SCAFFOLD *temp; if (dtd->scaffold) { - temp = (CONTENT_SCAFFOLD *) - REALLOC(parser, dtd->scaffold, dtd->scaffSize * 2 * sizeof(CONTENT_SCAFFOLD)); + temp = (CONTENT_SCAFFOLD *)REALLOC( + parser, dtd->scaffold, dtd->scaffSize * 2 * sizeof(CONTENT_SCAFFOLD)); if (temp == NULL) return -1; dtd->scaffSize *= 2; - } - else { + } else { temp = (CONTENT_SCAFFOLD *)MALLOC(parser, INIT_SCAFFOLD_ELEMENTS - * sizeof(CONTENT_SCAFFOLD)); + * sizeof(CONTENT_SCAFFOLD)); if (temp == NULL) return -1; dtd->scaffSize = INIT_SCAFFOLD_ELEMENTS; } dtd->scaffold = temp; } next = dtd->scaffCount++; me = &dtd->scaffold[next]; if (dtd->scaffLevel) { - CONTENT_SCAFFOLD *parent = &dtd->scaffold[dtd->scaffIndex[dtd->scaffLevel-1]]; + CONTENT_SCAFFOLD *parent + = &dtd->scaffold[dtd->scaffIndex[dtd->scaffLevel - 1]]; if (parent->lastchild) { dtd->scaffold[parent->lastchild].nextsib = next; } - if (!parent->childcnt) + if (! parent->childcnt) parent->firstchild = next; parent->lastchild = next; parent->childcnt++; } me->firstchild = me->lastchild = me->childcnt = me->nextsib = 0; return next; } static void -build_node(XML_Parser parser, - int src_node, - XML_Content *dest, - XML_Content **contpos, - XML_Char **strpos) -{ - DTD * const dtd = parser->m_dtd; /* save one level of indirection */ +build_node(XML_Parser parser, int src_node, XML_Content *dest, + XML_Content **contpos, XML_Char **strpos) { + DTD *const dtd = parser->m_dtd; /* save one level of indirection */ dest->type = dtd->scaffold[src_node].type; dest->quant = dtd->scaffold[src_node].quant; if (dest->type == XML_CTYPE_NAME) { const XML_Char *src; dest->name = *strpos; src = dtd->scaffold[src_node].name; for (;;) { *(*strpos)++ = *src; - if (!*src) + if (! *src) break; src++; } dest->numchildren = 0; dest->children = NULL; - } - else { + } else { unsigned int i; int cn; dest->numchildren = dtd->scaffold[src_node].childcnt; dest->children = *contpos; *contpos += dest->numchildren; - for (i = 0, cn = dtd->scaffold[src_node].firstchild; - i < dest->numchildren; + for (i = 0, cn = dtd->scaffold[src_node].firstchild; i < dest->numchildren; i++, cn = dtd->scaffold[cn].nextsib) { build_node(parser, cn, &(dest->children[i]), contpos, strpos); } dest->name = NULL; } } static XML_Content * -build_model (XML_Parser parser) -{ - DTD * const dtd = parser->m_dtd; /* save one level of indirection */ +build_model(XML_Parser parser) { + DTD *const dtd = parser->m_dtd; /* save one level of indirection */ XML_Content *ret; XML_Content *cpos; - XML_Char * str; + XML_Char *str; int allocsize = (dtd->scaffCount * sizeof(XML_Content) + (dtd->contentStringLen * sizeof(XML_Char))); ret = (XML_Content *)MALLOC(parser, allocsize); - if (!ret) + if (! ret) return NULL; - str = (XML_Char *) (&ret[dtd->scaffCount]); + str = (XML_Char *)(&ret[dtd->scaffCount]); cpos = &ret[1]; build_node(parser, 0, ret, &cpos, &str); return ret; } static ELEMENT_TYPE * -getElementType(XML_Parser parser, - const ENCODING *enc, - const char *ptr, - const char *end) -{ - DTD * const dtd = parser->m_dtd; /* save one level of indirection */ +getElementType(XML_Parser parser, const ENCODING *enc, const char *ptr, + const char *end) { + DTD *const dtd = parser->m_dtd; /* save one level of indirection */ const XML_Char *name = poolStoreString(&dtd->pool, enc, ptr, end); ELEMENT_TYPE *ret; - if (!name) + if (! name) return NULL; - ret = (ELEMENT_TYPE *) lookup(parser, &dtd->elementTypes, name, sizeof(ELEMENT_TYPE)); - if (!ret) + ret = (ELEMENT_TYPE *)lookup(parser, &dtd->elementTypes, name, + sizeof(ELEMENT_TYPE)); + if (! ret) return NULL; if (ret->name != name) poolDiscard(&dtd->pool); else { poolFinish(&dtd->pool); - if (!setElementTypePrefix(parser, ret)) + if (! setElementTypePrefix(parser, ret)) return NULL; } return ret; } static XML_Char * -copyString(const XML_Char *s, - const XML_Memory_Handling_Suite *memsuite) -{ - int charsRequired = 0; - XML_Char *result; - - /* First determine how long the string is */ - while (s[charsRequired] != 0) { - charsRequired++; - } - /* Include the terminator */ - charsRequired++; - - /* Now allocate space for the copy */ - result = memsuite->malloc_fcn(charsRequired * sizeof(XML_Char)); - if (result == NULL) - return NULL; - /* Copy the original into place */ - memcpy(result, s, charsRequired * sizeof(XML_Char)); - return result; +copyString(const XML_Char *s, const XML_Memory_Handling_Suite *memsuite) { + int charsRequired = 0; + XML_Char *result; + + /* First determine how long the string is */ + while (s[charsRequired] != 0) { + charsRequired++; + } + /* Include the terminator */ + charsRequired++; + + /* Now allocate space for the copy */ + result = memsuite->malloc_fcn(charsRequired * sizeof(XML_Char)); + if (result == NULL) + return NULL; + /* Copy the original into place */ + memcpy(result, s, charsRequired * sizeof(XML_Char)); + return result; } Index: expat/xmlrole.c ================================================================== --- expat/xmlrole.c +++ expat/xmlrole.c @@ -31,15 +31,15 @@ */ #include #ifdef _WIN32 -#include "winconfig.h" +# include "winconfig.h" #else -#ifdef HAVE_EXPAT_CONFIG_H -#include -#endif +# ifdef HAVE_EXPAT_CONFIG_H +# include +# endif #endif /* ndef _WIN32 */ #include "expat_external.h" #include "internal.h" #include "xmlrole.h" @@ -50,111 +50,92 @@ that ,| are not mixed in a model group content of literals */ -static const char KW_ANY[] = { - ASCII_A, ASCII_N, ASCII_Y, '\0' }; -static const char KW_ATTLIST[] = { - ASCII_A, ASCII_T, ASCII_T, ASCII_L, ASCII_I, ASCII_S, ASCII_T, '\0' }; -static const char KW_CDATA[] = { - ASCII_C, ASCII_D, ASCII_A, ASCII_T, ASCII_A, '\0' }; -static const char KW_DOCTYPE[] = { - ASCII_D, ASCII_O, ASCII_C, ASCII_T, ASCII_Y, ASCII_P, ASCII_E, '\0' }; -static const char KW_ELEMENT[] = { - ASCII_E, ASCII_L, ASCII_E, ASCII_M, ASCII_E, ASCII_N, ASCII_T, '\0' }; -static const char KW_EMPTY[] = { - ASCII_E, ASCII_M, ASCII_P, ASCII_T, ASCII_Y, '\0' }; -static const char KW_ENTITIES[] = { - ASCII_E, ASCII_N, ASCII_T, ASCII_I, ASCII_T, ASCII_I, ASCII_E, ASCII_S, - '\0' }; -static const char KW_ENTITY[] = { - ASCII_E, ASCII_N, ASCII_T, ASCII_I, ASCII_T, ASCII_Y, '\0' }; -static const char KW_FIXED[] = { - ASCII_F, ASCII_I, ASCII_X, ASCII_E, ASCII_D, '\0' }; -static const char KW_ID[] = { - ASCII_I, ASCII_D, '\0' }; -static const char KW_IDREF[] = { - ASCII_I, ASCII_D, ASCII_R, ASCII_E, ASCII_F, '\0' }; -static const char KW_IDREFS[] = { - ASCII_I, ASCII_D, ASCII_R, ASCII_E, ASCII_F, ASCII_S, '\0' }; -#ifdef XML_DTD -static const char KW_IGNORE[] = { - ASCII_I, ASCII_G, ASCII_N, ASCII_O, ASCII_R, ASCII_E, '\0' }; -#endif -static const char KW_IMPLIED[] = { - ASCII_I, ASCII_M, ASCII_P, ASCII_L, ASCII_I, ASCII_E, ASCII_D, '\0' }; -#ifdef XML_DTD -static const char KW_INCLUDE[] = { - ASCII_I, ASCII_N, ASCII_C, ASCII_L, ASCII_U, ASCII_D, ASCII_E, '\0' }; -#endif -static const char KW_NDATA[] = { - ASCII_N, ASCII_D, ASCII_A, ASCII_T, ASCII_A, '\0' }; -static const char KW_NMTOKEN[] = { - ASCII_N, ASCII_M, ASCII_T, ASCII_O, ASCII_K, ASCII_E, ASCII_N, '\0' }; -static const char KW_NMTOKENS[] = { - ASCII_N, ASCII_M, ASCII_T, ASCII_O, ASCII_K, ASCII_E, ASCII_N, ASCII_S, - '\0' }; -static const char KW_NOTATION[] = - { ASCII_N, ASCII_O, ASCII_T, ASCII_A, ASCII_T, ASCII_I, ASCII_O, ASCII_N, - '\0' }; -static const char KW_PCDATA[] = { - ASCII_P, ASCII_C, ASCII_D, ASCII_A, ASCII_T, ASCII_A, '\0' }; -static const char KW_PUBLIC[] = { - ASCII_P, ASCII_U, ASCII_B, ASCII_L, ASCII_I, ASCII_C, '\0' }; -static const char KW_REQUIRED[] = { - ASCII_R, ASCII_E, ASCII_Q, ASCII_U, ASCII_I, ASCII_R, ASCII_E, ASCII_D, - '\0' }; -static const char KW_SYSTEM[] = { - ASCII_S, ASCII_Y, ASCII_S, ASCII_T, ASCII_E, ASCII_M, '\0' }; - -#ifndef MIN_BYTES_PER_CHAR -#define MIN_BYTES_PER_CHAR(enc) ((enc)->minBytesPerChar) -#endif - -#ifdef XML_DTD -#define setTopLevel(state) \ - ((state)->handler = ((state)->documentEntity \ - ? internalSubset \ - : externalSubset1)) -#else /* not XML_DTD */ -#define setTopLevel(state) ((state)->handler = internalSubset) -#endif /* not XML_DTD */ - -typedef int PTRCALL PROLOG_HANDLER(PROLOG_STATE *state, - int tok, - const char *ptr, - const char *end, - const ENCODING *enc); - -static PROLOG_HANDLER - prolog0, prolog1, prolog2, - doctype0, doctype1, doctype2, doctype3, doctype4, doctype5, - internalSubset, - entity0, entity1, entity2, entity3, entity4, entity5, entity6, - entity7, entity8, entity9, entity10, - notation0, notation1, notation2, notation3, notation4, - attlist0, attlist1, attlist2, attlist3, attlist4, attlist5, attlist6, - attlist7, attlist8, attlist9, - element0, element1, element2, element3, element4, element5, element6, - element7, -#ifdef XML_DTD - externalSubset0, externalSubset1, - condSect0, condSect1, condSect2, -#endif /* XML_DTD */ - declClose, - error; +static const char KW_ANY[] = {ASCII_A, ASCII_N, ASCII_Y, '\0'}; +static const char KW_ATTLIST[] + = {ASCII_A, ASCII_T, ASCII_T, ASCII_L, ASCII_I, ASCII_S, ASCII_T, '\0'}; +static const char KW_CDATA[] + = {ASCII_C, ASCII_D, ASCII_A, ASCII_T, ASCII_A, '\0'}; +static const char KW_DOCTYPE[] + = {ASCII_D, ASCII_O, ASCII_C, ASCII_T, ASCII_Y, ASCII_P, ASCII_E, '\0'}; +static const char KW_ELEMENT[] + = {ASCII_E, ASCII_L, ASCII_E, ASCII_M, ASCII_E, ASCII_N, ASCII_T, '\0'}; +static const char KW_EMPTY[] + = {ASCII_E, ASCII_M, ASCII_P, ASCII_T, ASCII_Y, '\0'}; +static const char KW_ENTITIES[] = {ASCII_E, ASCII_N, ASCII_T, ASCII_I, ASCII_T, + ASCII_I, ASCII_E, ASCII_S, '\0'}; +static const char KW_ENTITY[] + = {ASCII_E, ASCII_N, ASCII_T, ASCII_I, ASCII_T, ASCII_Y, '\0'}; +static const char KW_FIXED[] + = {ASCII_F, ASCII_I, ASCII_X, ASCII_E, ASCII_D, '\0'}; +static const char KW_ID[] = {ASCII_I, ASCII_D, '\0'}; +static const char KW_IDREF[] + = {ASCII_I, ASCII_D, ASCII_R, ASCII_E, ASCII_F, '\0'}; +static const char KW_IDREFS[] + = {ASCII_I, ASCII_D, ASCII_R, ASCII_E, ASCII_F, ASCII_S, '\0'}; +#ifdef XML_DTD +static const char KW_IGNORE[] + = {ASCII_I, ASCII_G, ASCII_N, ASCII_O, ASCII_R, ASCII_E, '\0'}; +#endif +static const char KW_IMPLIED[] + = {ASCII_I, ASCII_M, ASCII_P, ASCII_L, ASCII_I, ASCII_E, ASCII_D, '\0'}; +#ifdef XML_DTD +static const char KW_INCLUDE[] + = {ASCII_I, ASCII_N, ASCII_C, ASCII_L, ASCII_U, ASCII_D, ASCII_E, '\0'}; +#endif +static const char KW_NDATA[] + = {ASCII_N, ASCII_D, ASCII_A, ASCII_T, ASCII_A, '\0'}; +static const char KW_NMTOKEN[] + = {ASCII_N, ASCII_M, ASCII_T, ASCII_O, ASCII_K, ASCII_E, ASCII_N, '\0'}; +static const char KW_NMTOKENS[] = {ASCII_N, ASCII_M, ASCII_T, ASCII_O, ASCII_K, + ASCII_E, ASCII_N, ASCII_S, '\0'}; +static const char KW_NOTATION[] = {ASCII_N, ASCII_O, ASCII_T, ASCII_A, ASCII_T, + ASCII_I, ASCII_O, ASCII_N, '\0'}; +static const char KW_PCDATA[] + = {ASCII_P, ASCII_C, ASCII_D, ASCII_A, ASCII_T, ASCII_A, '\0'}; +static const char KW_PUBLIC[] + = {ASCII_P, ASCII_U, ASCII_B, ASCII_L, ASCII_I, ASCII_C, '\0'}; +static const char KW_REQUIRED[] = {ASCII_R, ASCII_E, ASCII_Q, ASCII_U, ASCII_I, + ASCII_R, ASCII_E, ASCII_D, '\0'}; +static const char KW_SYSTEM[] + = {ASCII_S, ASCII_Y, ASCII_S, ASCII_T, ASCII_E, ASCII_M, '\0'}; + +#ifndef MIN_BYTES_PER_CHAR +# define MIN_BYTES_PER_CHAR(enc) ((enc)->minBytesPerChar) +#endif + +#ifdef XML_DTD +# define setTopLevel(state) \ + ((state)->handler \ + = ((state)->documentEntity ? internalSubset : externalSubset1)) +#else /* not XML_DTD */ +# define setTopLevel(state) ((state)->handler = internalSubset) +#endif /* not XML_DTD */ + +typedef int PTRCALL PROLOG_HANDLER(PROLOG_STATE *state, int tok, + const char *ptr, const char *end, + const ENCODING *enc); + +static PROLOG_HANDLER prolog0, prolog1, prolog2, doctype0, doctype1, doctype2, + doctype3, doctype4, doctype5, internalSubset, entity0, entity1, entity2, + entity3, entity4, entity5, entity6, entity7, entity8, entity9, entity10, + notation0, notation1, notation2, notation3, notation4, attlist0, attlist1, + attlist2, attlist3, attlist4, attlist5, attlist6, attlist7, attlist8, + attlist9, element0, element1, element2, element3, element4, element5, + element6, element7, +#ifdef XML_DTD + externalSubset0, externalSubset1, condSect0, condSect1, condSect2, +#endif /* XML_DTD */ + declClose, error; static int FASTCALL common(PROLOG_STATE *state, int tok); static int PTRCALL -prolog0(PROLOG_STATE *state, - int tok, - const char *ptr, - const char *end, - const ENCODING *enc) -{ +prolog0(PROLOG_STATE *state, int tok, const char *ptr, const char *end, + const ENCODING *enc) { switch (tok) { case XML_TOK_PROLOG_S: state->handler = prolog1; return XML_ROLE_NONE; case XML_TOK_XML_DECL: @@ -167,14 +148,12 @@ state->handler = prolog1; return XML_ROLE_COMMENT; case XML_TOK_BOM: return XML_ROLE_NONE; case XML_TOK_DECL_OPEN: - if (!XmlNameMatchesAscii(enc, - ptr + 2 * MIN_BYTES_PER_CHAR(enc), - end, - KW_DOCTYPE)) + if (! XmlNameMatchesAscii(enc, ptr + 2 * MIN_BYTES_PER_CHAR(enc), end, + KW_DOCTYPE)) break; state->handler = doctype0; return XML_ROLE_DOCTYPE_NONE; case XML_TOK_INSTANCE_START: state->handler = error; @@ -182,16 +161,12 @@ } return common(state, tok); } static int PTRCALL -prolog1(PROLOG_STATE *state, - int tok, - const char *ptr, - const char *end, - const ENCODING *enc) -{ +prolog1(PROLOG_STATE *state, int tok, const char *ptr, const char *end, + const ENCODING *enc) { switch (tok) { case XML_TOK_PROLOG_S: return XML_ROLE_NONE; case XML_TOK_PI: return XML_ROLE_PI; @@ -205,14 +180,12 @@ * technically it should be interpreted as a non-breaking space), * so will be rejected by the tokenizing stages. */ return XML_ROLE_NONE; /* LCOV_EXCL_LINE */ case XML_TOK_DECL_OPEN: - if (!XmlNameMatchesAscii(enc, - ptr + 2 * MIN_BYTES_PER_CHAR(enc), - end, - KW_DOCTYPE)) + if (! XmlNameMatchesAscii(enc, ptr + 2 * MIN_BYTES_PER_CHAR(enc), end, + KW_DOCTYPE)) break; state->handler = doctype0; return XML_ROLE_DOCTYPE_NONE; case XML_TOK_INSTANCE_START: state->handler = error; @@ -220,16 +193,15 @@ } return common(state, tok); } static int PTRCALL -prolog2(PROLOG_STATE *state, - int tok, - const char *UNUSED_P(ptr), - const char *UNUSED_P(end), - const ENCODING *UNUSED_P(enc)) -{ +prolog2(PROLOG_STATE *state, int tok, const char *ptr, const char *end, + const ENCODING *enc) { + UNUSED_P(ptr); + UNUSED_P(end); + UNUSED_P(enc); switch (tok) { case XML_TOK_PROLOG_S: return XML_ROLE_NONE; case XML_TOK_PI: return XML_ROLE_PI; @@ -241,16 +213,15 @@ } return common(state, tok); } static int PTRCALL -doctype0(PROLOG_STATE *state, - int tok, - const char *UNUSED_P(ptr), - const char *UNUSED_P(end), - const ENCODING *UNUSED_P(enc)) -{ +doctype0(PROLOG_STATE *state, int tok, const char *ptr, const char *end, + const ENCODING *enc) { + UNUSED_P(ptr); + UNUSED_P(end); + UNUSED_P(enc); switch (tok) { case XML_TOK_PROLOG_S: return XML_ROLE_DOCTYPE_NONE; case XML_TOK_NAME: case XML_TOK_PREFIXED_NAME: @@ -259,16 +230,12 @@ } return common(state, tok); } static int PTRCALL -doctype1(PROLOG_STATE *state, - int tok, - const char *ptr, - const char *end, - const ENCODING *enc) -{ +doctype1(PROLOG_STATE *state, int tok, const char *ptr, const char *end, + const ENCODING *enc) { switch (tok) { case XML_TOK_PROLOG_S: return XML_ROLE_DOCTYPE_NONE; case XML_TOK_OPEN_BRACKET: state->handler = internalSubset; @@ -289,16 +256,15 @@ } return common(state, tok); } static int PTRCALL -doctype2(PROLOG_STATE *state, - int tok, - const char *UNUSED_P(ptr), - const char *UNUSED_P(end), - const ENCODING *UNUSED_P(enc)) -{ +doctype2(PROLOG_STATE *state, int tok, const char *ptr, const char *end, + const ENCODING *enc) { + UNUSED_P(ptr); + UNUSED_P(end); + UNUSED_P(enc); switch (tok) { case XML_TOK_PROLOG_S: return XML_ROLE_DOCTYPE_NONE; case XML_TOK_LITERAL: state->handler = doctype3; @@ -306,16 +272,15 @@ } return common(state, tok); } static int PTRCALL -doctype3(PROLOG_STATE *state, - int tok, - const char *UNUSED_P(ptr), - const char *UNUSED_P(end), - const ENCODING *UNUSED_P(enc)) -{ +doctype3(PROLOG_STATE *state, int tok, const char *ptr, const char *end, + const ENCODING *enc) { + UNUSED_P(ptr); + UNUSED_P(end); + UNUSED_P(enc); switch (tok) { case XML_TOK_PROLOG_S: return XML_ROLE_DOCTYPE_NONE; case XML_TOK_LITERAL: state->handler = doctype4; @@ -323,16 +288,15 @@ } return common(state, tok); } static int PTRCALL -doctype4(PROLOG_STATE *state, - int tok, - const char *UNUSED_P(ptr), - const char *UNUSED_P(end), - const ENCODING *UNUSED_P(enc)) -{ +doctype4(PROLOG_STATE *state, int tok, const char *ptr, const char *end, + const ENCODING *enc) { + UNUSED_P(ptr); + UNUSED_P(end); + UNUSED_P(enc); switch (tok) { case XML_TOK_PROLOG_S: return XML_ROLE_DOCTYPE_NONE; case XML_TOK_OPEN_BRACKET: state->handler = internalSubset; @@ -343,16 +307,15 @@ } return common(state, tok); } static int PTRCALL -doctype5(PROLOG_STATE *state, - int tok, - const char *UNUSED_P(ptr), - const char *UNUSED_P(end), - const ENCODING *UNUSED_P(enc)) -{ +doctype5(PROLOG_STATE *state, int tok, const char *ptr, const char *end, + const ENCODING *enc) { + UNUSED_P(ptr); + UNUSED_P(end); + UNUSED_P(enc); switch (tok) { case XML_TOK_PROLOG_S: return XML_ROLE_DOCTYPE_NONE; case XML_TOK_DECL_CLOSE: state->handler = prolog2; @@ -360,44 +323,32 @@ } return common(state, tok); } static int PTRCALL -internalSubset(PROLOG_STATE *state, - int tok, - const char *ptr, - const char *end, - const ENCODING *enc) -{ +internalSubset(PROLOG_STATE *state, int tok, const char *ptr, const char *end, + const ENCODING *enc) { switch (tok) { case XML_TOK_PROLOG_S: return XML_ROLE_NONE; case XML_TOK_DECL_OPEN: - if (XmlNameMatchesAscii(enc, - ptr + 2 * MIN_BYTES_PER_CHAR(enc), - end, + if (XmlNameMatchesAscii(enc, ptr + 2 * MIN_BYTES_PER_CHAR(enc), end, KW_ENTITY)) { state->handler = entity0; return XML_ROLE_ENTITY_NONE; } - if (XmlNameMatchesAscii(enc, - ptr + 2 * MIN_BYTES_PER_CHAR(enc), - end, + if (XmlNameMatchesAscii(enc, ptr + 2 * MIN_BYTES_PER_CHAR(enc), end, KW_ATTLIST)) { state->handler = attlist0; return XML_ROLE_ATTLIST_NONE; } - if (XmlNameMatchesAscii(enc, - ptr + 2 * MIN_BYTES_PER_CHAR(enc), - end, + if (XmlNameMatchesAscii(enc, ptr + 2 * MIN_BYTES_PER_CHAR(enc), end, KW_ELEMENT)) { state->handler = element0; return XML_ROLE_ELEMENT_NONE; } - if (XmlNameMatchesAscii(enc, - ptr + 2 * MIN_BYTES_PER_CHAR(enc), - end, + if (XmlNameMatchesAscii(enc, ptr + 2 * MIN_BYTES_PER_CHAR(enc), end, KW_NOTATION)) { state->handler = notation0; return XML_ROLE_NOTATION_NONE; } break; @@ -417,29 +368,21 @@ } #ifdef XML_DTD static int PTRCALL -externalSubset0(PROLOG_STATE *state, - int tok, - const char *ptr, - const char *end, - const ENCODING *enc) -{ +externalSubset0(PROLOG_STATE *state, int tok, const char *ptr, const char *end, + const ENCODING *enc) { state->handler = externalSubset1; if (tok == XML_TOK_XML_DECL) return XML_ROLE_TEXT_DECL; return externalSubset1(state, tok, ptr, end, enc); } static int PTRCALL -externalSubset1(PROLOG_STATE *state, - int tok, - const char *ptr, - const char *end, - const ENCODING *enc) -{ +externalSubset1(PROLOG_STATE *state, int tok, const char *ptr, const char *end, + const ENCODING *enc) { switch (tok) { case XML_TOK_COND_SECT_OPEN: state->handler = condSect0; return XML_ROLE_NONE; case XML_TOK_COND_SECT_CLOSE: @@ -462,16 +405,15 @@ } #endif /* XML_DTD */ static int PTRCALL -entity0(PROLOG_STATE *state, - int tok, - const char *UNUSED_P(ptr), - const char *UNUSED_P(end), - const ENCODING *UNUSED_P(enc)) -{ +entity0(PROLOG_STATE *state, int tok, const char *ptr, const char *end, + const ENCODING *enc) { + UNUSED_P(ptr); + UNUSED_P(end); + UNUSED_P(enc); switch (tok) { case XML_TOK_PROLOG_S: return XML_ROLE_ENTITY_NONE; case XML_TOK_PERCENT: state->handler = entity1; @@ -482,16 +424,15 @@ } return common(state, tok); } static int PTRCALL -entity1(PROLOG_STATE *state, - int tok, - const char *UNUSED_P(ptr), - const char *UNUSED_P(end), - const ENCODING *UNUSED_P(enc)) -{ +entity1(PROLOG_STATE *state, int tok, const char *ptr, const char *end, + const ENCODING *enc) { + UNUSED_P(ptr); + UNUSED_P(end); + UNUSED_P(enc); switch (tok) { case XML_TOK_PROLOG_S: return XML_ROLE_ENTITY_NONE; case XML_TOK_NAME: state->handler = entity7; @@ -499,16 +440,12 @@ } return common(state, tok); } static int PTRCALL -entity2(PROLOG_STATE *state, - int tok, - const char *ptr, - const char *end, - const ENCODING *enc) -{ +entity2(PROLOG_STATE *state, int tok, const char *ptr, const char *end, + const ENCODING *enc) { switch (tok) { case XML_TOK_PROLOG_S: return XML_ROLE_ENTITY_NONE; case XML_TOK_NAME: if (XmlNameMatchesAscii(enc, ptr, end, KW_SYSTEM)) { @@ -527,16 +464,15 @@ } return common(state, tok); } static int PTRCALL -entity3(PROLOG_STATE *state, - int tok, - const char *UNUSED_P(ptr), - const char *UNUSED_P(end), - const ENCODING *UNUSED_P(enc)) -{ +entity3(PROLOG_STATE *state, int tok, const char *ptr, const char *end, + const ENCODING *enc) { + UNUSED_P(ptr); + UNUSED_P(end); + UNUSED_P(enc); switch (tok) { case XML_TOK_PROLOG_S: return XML_ROLE_ENTITY_NONE; case XML_TOK_LITERAL: state->handler = entity4; @@ -544,16 +480,15 @@ } return common(state, tok); } static int PTRCALL -entity4(PROLOG_STATE *state, - int tok, - const char *UNUSED_P(ptr), - const char *UNUSED_P(end), - const ENCODING *UNUSED_P(enc)) -{ +entity4(PROLOG_STATE *state, int tok, const char *ptr, const char *end, + const ENCODING *enc) { + UNUSED_P(ptr); + UNUSED_P(end); + UNUSED_P(enc); switch (tok) { case XML_TOK_PROLOG_S: return XML_ROLE_ENTITY_NONE; case XML_TOK_LITERAL: state->handler = entity5; @@ -561,16 +496,12 @@ } return common(state, tok); } static int PTRCALL -entity5(PROLOG_STATE *state, - int tok, - const char *ptr, - const char *end, - const ENCODING *enc) -{ +entity5(PROLOG_STATE *state, int tok, const char *ptr, const char *end, + const ENCODING *enc) { switch (tok) { case XML_TOK_PROLOG_S: return XML_ROLE_ENTITY_NONE; case XML_TOK_DECL_CLOSE: setTopLevel(state); @@ -584,16 +515,15 @@ } return common(state, tok); } static int PTRCALL -entity6(PROLOG_STATE *state, - int tok, - const char *UNUSED_P(ptr), - const char *UNUSED_P(end), - const ENCODING *UNUSED_P(enc)) -{ +entity6(PROLOG_STATE *state, int tok, const char *ptr, const char *end, + const ENCODING *enc) { + UNUSED_P(ptr); + UNUSED_P(end); + UNUSED_P(enc); switch (tok) { case XML_TOK_PROLOG_S: return XML_ROLE_ENTITY_NONE; case XML_TOK_NAME: state->handler = declClose; @@ -602,16 +532,12 @@ } return common(state, tok); } static int PTRCALL -entity7(PROLOG_STATE *state, - int tok, - const char *ptr, - const char *end, - const ENCODING *enc) -{ +entity7(PROLOG_STATE *state, int tok, const char *ptr, const char *end, + const ENCODING *enc) { switch (tok) { case XML_TOK_PROLOG_S: return XML_ROLE_ENTITY_NONE; case XML_TOK_NAME: if (XmlNameMatchesAscii(enc, ptr, end, KW_SYSTEM)) { @@ -630,16 +556,15 @@ } return common(state, tok); } static int PTRCALL -entity8(PROLOG_STATE *state, - int tok, - const char *UNUSED_P(ptr), - const char *UNUSED_P(end), - const ENCODING *UNUSED_P(enc)) -{ +entity8(PROLOG_STATE *state, int tok, const char *ptr, const char *end, + const ENCODING *enc) { + UNUSED_P(ptr); + UNUSED_P(end); + UNUSED_P(enc); switch (tok) { case XML_TOK_PROLOG_S: return XML_ROLE_ENTITY_NONE; case XML_TOK_LITERAL: state->handler = entity9; @@ -647,16 +572,15 @@ } return common(state, tok); } static int PTRCALL -entity9(PROLOG_STATE *state, - int tok, - const char *UNUSED_P(ptr), - const char *UNUSED_P(end), - const ENCODING *UNUSED_P(enc)) -{ +entity9(PROLOG_STATE *state, int tok, const char *ptr, const char *end, + const ENCODING *enc) { + UNUSED_P(ptr); + UNUSED_P(end); + UNUSED_P(enc); switch (tok) { case XML_TOK_PROLOG_S: return XML_ROLE_ENTITY_NONE; case XML_TOK_LITERAL: state->handler = entity10; @@ -664,16 +588,15 @@ } return common(state, tok); } static int PTRCALL -entity10(PROLOG_STATE *state, - int tok, - const char *UNUSED_P(ptr), - const char *UNUSED_P(end), - const ENCODING *UNUSED_P(enc)) -{ +entity10(PROLOG_STATE *state, int tok, const char *ptr, const char *end, + const ENCODING *enc) { + UNUSED_P(ptr); + UNUSED_P(end); + UNUSED_P(enc); switch (tok) { case XML_TOK_PROLOG_S: return XML_ROLE_ENTITY_NONE; case XML_TOK_DECL_CLOSE: setTopLevel(state); @@ -681,16 +604,15 @@ } return common(state, tok); } static int PTRCALL -notation0(PROLOG_STATE *state, - int tok, - const char *UNUSED_P(ptr), - const char *UNUSED_P(end), - const ENCODING *UNUSED_P(enc)) -{ +notation0(PROLOG_STATE *state, int tok, const char *ptr, const char *end, + const ENCODING *enc) { + UNUSED_P(ptr); + UNUSED_P(end); + UNUSED_P(enc); switch (tok) { case XML_TOK_PROLOG_S: return XML_ROLE_NOTATION_NONE; case XML_TOK_NAME: state->handler = notation1; @@ -698,16 +620,12 @@ } return common(state, tok); } static int PTRCALL -notation1(PROLOG_STATE *state, - int tok, - const char *ptr, - const char *end, - const ENCODING *enc) -{ +notation1(PROLOG_STATE *state, int tok, const char *ptr, const char *end, + const ENCODING *enc) { switch (tok) { case XML_TOK_PROLOG_S: return XML_ROLE_NOTATION_NONE; case XML_TOK_NAME: if (XmlNameMatchesAscii(enc, ptr, end, KW_SYSTEM)) { @@ -722,16 +640,15 @@ } return common(state, tok); } static int PTRCALL -notation2(PROLOG_STATE *state, - int tok, - const char *UNUSED_P(ptr), - const char *UNUSED_P(end), - const ENCODING *UNUSED_P(enc)) -{ +notation2(PROLOG_STATE *state, int tok, const char *ptr, const char *end, + const ENCODING *enc) { + UNUSED_P(ptr); + UNUSED_P(end); + UNUSED_P(enc); switch (tok) { case XML_TOK_PROLOG_S: return XML_ROLE_NOTATION_NONE; case XML_TOK_LITERAL: state->handler = notation4; @@ -739,16 +656,15 @@ } return common(state, tok); } static int PTRCALL -notation3(PROLOG_STATE *state, - int tok, - const char *UNUSED_P(ptr), - const char *UNUSED_P(end), - const ENCODING *UNUSED_P(enc)) -{ +notation3(PROLOG_STATE *state, int tok, const char *ptr, const char *end, + const ENCODING *enc) { + UNUSED_P(ptr); + UNUSED_P(end); + UNUSED_P(enc); switch (tok) { case XML_TOK_PROLOG_S: return XML_ROLE_NOTATION_NONE; case XML_TOK_LITERAL: state->handler = declClose; @@ -757,16 +673,15 @@ } return common(state, tok); } static int PTRCALL -notation4(PROLOG_STATE *state, - int tok, - const char *UNUSED_P(ptr), - const char *UNUSED_P(end), - const ENCODING *UNUSED_P(enc)) -{ +notation4(PROLOG_STATE *state, int tok, const char *ptr, const char *end, + const ENCODING *enc) { + UNUSED_P(ptr); + UNUSED_P(end); + UNUSED_P(enc); switch (tok) { case XML_TOK_PROLOG_S: return XML_ROLE_NOTATION_NONE; case XML_TOK_LITERAL: state->handler = declClose; @@ -778,16 +693,15 @@ } return common(state, tok); } static int PTRCALL -attlist0(PROLOG_STATE *state, - int tok, - const char *UNUSED_P(ptr), - const char *UNUSED_P(end), - const ENCODING *UNUSED_P(enc)) -{ +attlist0(PROLOG_STATE *state, int tok, const char *ptr, const char *end, + const ENCODING *enc) { + UNUSED_P(ptr); + UNUSED_P(end); + UNUSED_P(enc); switch (tok) { case XML_TOK_PROLOG_S: return XML_ROLE_ATTLIST_NONE; case XML_TOK_NAME: case XML_TOK_PREFIXED_NAME: @@ -796,16 +710,15 @@ } return common(state, tok); } static int PTRCALL -attlist1(PROLOG_STATE *state, - int tok, - const char *UNUSED_P(ptr), - const char *UNUSED_P(end), - const ENCODING *UNUSED_P(enc)) -{ +attlist1(PROLOG_STATE *state, int tok, const char *ptr, const char *end, + const ENCODING *enc) { + UNUSED_P(ptr); + UNUSED_P(end); + UNUSED_P(enc); switch (tok) { case XML_TOK_PROLOG_S: return XML_ROLE_ATTLIST_NONE; case XML_TOK_DECL_CLOSE: setTopLevel(state); @@ -817,38 +730,27 @@ } return common(state, tok); } static int PTRCALL -attlist2(PROLOG_STATE *state, - int tok, - const char *ptr, - const char *end, - const ENCODING *enc) -{ +attlist2(PROLOG_STATE *state, int tok, const char *ptr, const char *end, + const ENCODING *enc) { switch (tok) { case XML_TOK_PROLOG_S: return XML_ROLE_ATTLIST_NONE; - case XML_TOK_NAME: - { - static const char * const types[] = { - KW_CDATA, - KW_ID, - KW_IDREF, - KW_IDREFS, - KW_ENTITY, - KW_ENTITIES, - KW_NMTOKEN, - KW_NMTOKENS, - }; - int i; - for (i = 0; i < (int)(sizeof(types)/sizeof(types[0])); i++) - if (XmlNameMatchesAscii(enc, ptr, end, types[i])) { - state->handler = attlist8; - return XML_ROLE_ATTRIBUTE_TYPE_CDATA + i; - } - } + case XML_TOK_NAME: { + static const char *const types[] = { + KW_CDATA, KW_ID, KW_IDREF, KW_IDREFS, + KW_ENTITY, KW_ENTITIES, KW_NMTOKEN, KW_NMTOKENS, + }; + int i; + for (i = 0; i < (int)(sizeof(types) / sizeof(types[0])); i++) + if (XmlNameMatchesAscii(enc, ptr, end, types[i])) { + state->handler = attlist8; + return XML_ROLE_ATTRIBUTE_TYPE_CDATA + i; + } + } if (XmlNameMatchesAscii(enc, ptr, end, KW_NOTATION)) { state->handler = attlist5; return XML_ROLE_ATTLIST_NONE; } break; @@ -858,16 +760,15 @@ } return common(state, tok); } static int PTRCALL -attlist3(PROLOG_STATE *state, - int tok, - const char *UNUSED_P(ptr), - const char *UNUSED_P(end), - const ENCODING *UNUSED_P(enc)) -{ +attlist3(PROLOG_STATE *state, int tok, const char *ptr, const char *end, + const ENCODING *enc) { + UNUSED_P(ptr); + UNUSED_P(end); + UNUSED_P(enc); switch (tok) { case XML_TOK_PROLOG_S: return XML_ROLE_ATTLIST_NONE; case XML_TOK_NMTOKEN: case XML_TOK_NAME: @@ -877,16 +778,15 @@ } return common(state, tok); } static int PTRCALL -attlist4(PROLOG_STATE *state, - int tok, - const char *UNUSED_P(ptr), - const char *UNUSED_P(end), - const ENCODING *UNUSED_P(enc)) -{ +attlist4(PROLOG_STATE *state, int tok, const char *ptr, const char *end, + const ENCODING *enc) { + UNUSED_P(ptr); + UNUSED_P(end); + UNUSED_P(enc); switch (tok) { case XML_TOK_PROLOG_S: return XML_ROLE_ATTLIST_NONE; case XML_TOK_CLOSE_PAREN: state->handler = attlist8; @@ -897,16 +797,15 @@ } return common(state, tok); } static int PTRCALL -attlist5(PROLOG_STATE *state, - int tok, - const char *UNUSED_P(ptr), - const char *UNUSED_P(end), - const ENCODING *UNUSED_P(enc)) -{ +attlist5(PROLOG_STATE *state, int tok, const char *ptr, const char *end, + const ENCODING *enc) { + UNUSED_P(ptr); + UNUSED_P(end); + UNUSED_P(enc); switch (tok) { case XML_TOK_PROLOG_S: return XML_ROLE_ATTLIST_NONE; case XML_TOK_OPEN_PAREN: state->handler = attlist6; @@ -914,16 +813,15 @@ } return common(state, tok); } static int PTRCALL -attlist6(PROLOG_STATE *state, - int tok, - const char *UNUSED_P(ptr), - const char *UNUSED_P(end), - const ENCODING *UNUSED_P(enc)) -{ +attlist6(PROLOG_STATE *state, int tok, const char *ptr, const char *end, + const ENCODING *enc) { + UNUSED_P(ptr); + UNUSED_P(end); + UNUSED_P(enc); switch (tok) { case XML_TOK_PROLOG_S: return XML_ROLE_ATTLIST_NONE; case XML_TOK_NAME: state->handler = attlist7; @@ -931,16 +829,15 @@ } return common(state, tok); } static int PTRCALL -attlist7(PROLOG_STATE *state, - int tok, - const char *UNUSED_P(ptr), - const char *UNUSED_P(end), - const ENCODING *UNUSED_P(enc)) -{ +attlist7(PROLOG_STATE *state, int tok, const char *ptr, const char *end, + const ENCODING *enc) { + UNUSED_P(ptr); + UNUSED_P(end); + UNUSED_P(enc); switch (tok) { case XML_TOK_PROLOG_S: return XML_ROLE_ATTLIST_NONE; case XML_TOK_CLOSE_PAREN: state->handler = attlist8; @@ -952,37 +849,27 @@ return common(state, tok); } /* default value */ static int PTRCALL -attlist8(PROLOG_STATE *state, - int tok, - const char *ptr, - const char *end, - const ENCODING *enc) -{ +attlist8(PROLOG_STATE *state, int tok, const char *ptr, const char *end, + const ENCODING *enc) { switch (tok) { case XML_TOK_PROLOG_S: return XML_ROLE_ATTLIST_NONE; case XML_TOK_POUND_NAME: - if (XmlNameMatchesAscii(enc, - ptr + MIN_BYTES_PER_CHAR(enc), - end, + if (XmlNameMatchesAscii(enc, ptr + MIN_BYTES_PER_CHAR(enc), end, KW_IMPLIED)) { state->handler = attlist1; return XML_ROLE_IMPLIED_ATTRIBUTE_VALUE; } - if (XmlNameMatchesAscii(enc, - ptr + MIN_BYTES_PER_CHAR(enc), - end, + if (XmlNameMatchesAscii(enc, ptr + MIN_BYTES_PER_CHAR(enc), end, KW_REQUIRED)) { state->handler = attlist1; return XML_ROLE_REQUIRED_ATTRIBUTE_VALUE; } - if (XmlNameMatchesAscii(enc, - ptr + MIN_BYTES_PER_CHAR(enc), - end, + if (XmlNameMatchesAscii(enc, ptr + MIN_BYTES_PER_CHAR(enc), end, KW_FIXED)) { state->handler = attlist9; return XML_ROLE_ATTLIST_NONE; } break; @@ -992,16 +879,15 @@ } return common(state, tok); } static int PTRCALL -attlist9(PROLOG_STATE *state, - int tok, - const char *UNUSED_P(ptr), - const char *UNUSED_P(end), - const ENCODING *UNUSED_P(enc)) -{ +attlist9(PROLOG_STATE *state, int tok, const char *ptr, const char *end, + const ENCODING *enc) { + UNUSED_P(ptr); + UNUSED_P(end); + UNUSED_P(enc); switch (tok) { case XML_TOK_PROLOG_S: return XML_ROLE_ATTLIST_NONE; case XML_TOK_LITERAL: state->handler = attlist1; @@ -1009,16 +895,15 @@ } return common(state, tok); } static int PTRCALL -element0(PROLOG_STATE *state, - int tok, - const char *UNUSED_P(ptr), - const char *UNUSED_P(end), - const ENCODING *UNUSED_P(enc)) -{ +element0(PROLOG_STATE *state, int tok, const char *ptr, const char *end, + const ENCODING *enc) { + UNUSED_P(ptr); + UNUSED_P(end); + UNUSED_P(enc); switch (tok) { case XML_TOK_PROLOG_S: return XML_ROLE_ELEMENT_NONE; case XML_TOK_NAME: case XML_TOK_PREFIXED_NAME: @@ -1027,16 +912,12 @@ } return common(state, tok); } static int PTRCALL -element1(PROLOG_STATE *state, - int tok, - const char *ptr, - const char *end, - const ENCODING *enc) -{ +element1(PROLOG_STATE *state, int tok, const char *ptr, const char *end, + const ENCODING *enc) { switch (tok) { case XML_TOK_PROLOG_S: return XML_ROLE_ELEMENT_NONE; case XML_TOK_NAME: if (XmlNameMatchesAscii(enc, ptr, end, KW_EMPTY)) { @@ -1057,23 +938,17 @@ } return common(state, tok); } static int PTRCALL -element2(PROLOG_STATE *state, - int tok, - const char *ptr, - const char *end, - const ENCODING *enc) -{ +element2(PROLOG_STATE *state, int tok, const char *ptr, const char *end, + const ENCODING *enc) { switch (tok) { case XML_TOK_PROLOG_S: return XML_ROLE_ELEMENT_NONE; case XML_TOK_POUND_NAME: - if (XmlNameMatchesAscii(enc, - ptr + MIN_BYTES_PER_CHAR(enc), - end, + if (XmlNameMatchesAscii(enc, ptr + MIN_BYTES_PER_CHAR(enc), end, KW_PCDATA)) { state->handler = element3; return XML_ROLE_CONTENT_PCDATA; } break; @@ -1097,16 +972,15 @@ } return common(state, tok); } static int PTRCALL -element3(PROLOG_STATE *state, - int tok, - const char *UNUSED_P(ptr), - const char *UNUSED_P(end), - const ENCODING *UNUSED_P(enc)) -{ +element3(PROLOG_STATE *state, int tok, const char *ptr, const char *end, + const ENCODING *enc) { + UNUSED_P(ptr); + UNUSED_P(end); + UNUSED_P(enc); switch (tok) { case XML_TOK_PROLOG_S: return XML_ROLE_ELEMENT_NONE; case XML_TOK_CLOSE_PAREN: state->handler = declClose; @@ -1122,16 +996,15 @@ } return common(state, tok); } static int PTRCALL -element4(PROLOG_STATE *state, - int tok, - const char *UNUSED_P(ptr), - const char *UNUSED_P(end), - const ENCODING *UNUSED_P(enc)) -{ +element4(PROLOG_STATE *state, int tok, const char *ptr, const char *end, + const ENCODING *enc) { + UNUSED_P(ptr); + UNUSED_P(end); + UNUSED_P(enc); switch (tok) { case XML_TOK_PROLOG_S: return XML_ROLE_ELEMENT_NONE; case XML_TOK_NAME: case XML_TOK_PREFIXED_NAME: @@ -1140,16 +1013,15 @@ } return common(state, tok); } static int PTRCALL -element5(PROLOG_STATE *state, - int tok, - const char *UNUSED_P(ptr), - const char *UNUSED_P(end), - const ENCODING *UNUSED_P(enc)) -{ +element5(PROLOG_STATE *state, int tok, const char *ptr, const char *end, + const ENCODING *enc) { + UNUSED_P(ptr); + UNUSED_P(end); + UNUSED_P(enc); switch (tok) { case XML_TOK_PROLOG_S: return XML_ROLE_ELEMENT_NONE; case XML_TOK_CLOSE_PAREN_ASTERISK: state->handler = declClose; @@ -1161,16 +1033,15 @@ } return common(state, tok); } static int PTRCALL -element6(PROLOG_STATE *state, - int tok, - const char *UNUSED_P(ptr), - const char *UNUSED_P(end), - const ENCODING *UNUSED_P(enc)) -{ +element6(PROLOG_STATE *state, int tok, const char *ptr, const char *end, + const ENCODING *enc) { + UNUSED_P(ptr); + UNUSED_P(end); + UNUSED_P(enc); switch (tok) { case XML_TOK_PROLOG_S: return XML_ROLE_ELEMENT_NONE; case XML_TOK_OPEN_PAREN: state->level += 1; @@ -1191,16 +1062,15 @@ } return common(state, tok); } static int PTRCALL -element7(PROLOG_STATE *state, - int tok, - const char *UNUSED_P(ptr), - const char *UNUSED_P(end), - const ENCODING *UNUSED_P(enc)) -{ +element7(PROLOG_STATE *state, int tok, const char *ptr, const char *end, + const ENCODING *enc) { + UNUSED_P(ptr); + UNUSED_P(end); + UNUSED_P(enc); switch (tok) { case XML_TOK_PROLOG_S: return XML_ROLE_ELEMENT_NONE; case XML_TOK_CLOSE_PAREN: state->level -= 1; @@ -1241,16 +1111,12 @@ } #ifdef XML_DTD static int PTRCALL -condSect0(PROLOG_STATE *state, - int tok, - const char *ptr, - const char *end, - const ENCODING *enc) -{ +condSect0(PROLOG_STATE *state, int tok, const char *ptr, const char *end, + const ENCODING *enc) { switch (tok) { case XML_TOK_PROLOG_S: return XML_ROLE_NONE; case XML_TOK_NAME: if (XmlNameMatchesAscii(enc, ptr, end, KW_INCLUDE)) { @@ -1265,16 +1131,15 @@ } return common(state, tok); } static int PTRCALL -condSect1(PROLOG_STATE *state, - int tok, - const char *UNUSED_P(ptr), - const char *UNUSED_P(end), - const ENCODING *UNUSED_P(enc)) -{ +condSect1(PROLOG_STATE *state, int tok, const char *ptr, const char *end, + const ENCODING *enc) { + UNUSED_P(ptr); + UNUSED_P(end); + UNUSED_P(enc); switch (tok) { case XML_TOK_PROLOG_S: return XML_ROLE_NONE; case XML_TOK_OPEN_BRACKET: state->handler = externalSubset1; @@ -1283,16 +1148,15 @@ } return common(state, tok); } static int PTRCALL -condSect2(PROLOG_STATE *state, - int tok, - const char *UNUSED_P(ptr), - const char *UNUSED_P(end), - const ENCODING *UNUSED_P(enc)) -{ +condSect2(PROLOG_STATE *state, int tok, const char *ptr, const char *end, + const ENCODING *enc) { + UNUSED_P(ptr); + UNUSED_P(end); + UNUSED_P(enc); switch (tok) { case XML_TOK_PROLOG_S: return XML_ROLE_NONE; case XML_TOK_OPEN_BRACKET: state->handler = externalSubset1; @@ -1302,16 +1166,15 @@ } #endif /* XML_DTD */ static int PTRCALL -declClose(PROLOG_STATE *state, - int tok, - const char *UNUSED_P(ptr), - const char *UNUSED_P(end), - const ENCODING *UNUSED_P(enc)) -{ +declClose(PROLOG_STATE *state, int tok, const char *ptr, const char *end, + const ENCODING *enc) { + UNUSED_P(ptr); + UNUSED_P(end); + UNUSED_P(enc); switch (tok) { case XML_TOK_PROLOG_S: return state->role_none; case XML_TOK_DECL_CLOSE: setTopLevel(state); @@ -1339,34 +1202,33 @@ * it from the coverage statistics. * * LCOV_EXCL_START */ static int PTRCALL -error(PROLOG_STATE *UNUSED_P(state), - int UNUSED_P(tok), - const char *UNUSED_P(ptr), - const char *UNUSED_P(end), - const ENCODING *UNUSED_P(enc)) -{ +error(PROLOG_STATE *state, int tok, const char *ptr, const char *end, + const ENCODING *enc) { + UNUSED_P(state); + UNUSED_P(tok); + UNUSED_P(ptr); + UNUSED_P(end); + UNUSED_P(enc); return XML_ROLE_NONE; } /* LCOV_EXCL_STOP */ static int FASTCALL -common(PROLOG_STATE *state, int tok) -{ +common(PROLOG_STATE *state, int tok) { #ifdef XML_DTD - if (!state->documentEntity && tok == XML_TOK_PARAM_ENTITY_REF) + if (! state->documentEntity && tok == XML_TOK_PARAM_ENTITY_REF) return XML_ROLE_INNER_PARAM_ENTITY_REF; #endif state->handler = error; return XML_ROLE_ERROR; } void -XmlPrologStateInit(PROLOG_STATE *state) -{ +XmlPrologStateInit(PROLOG_STATE *state) { state->handler = prolog0; #ifdef XML_DTD state->documentEntity = 1; state->includeLevel = 0; state->inEntityValue = 0; @@ -1374,13 +1236,12 @@ } #ifdef XML_DTD void -XmlPrologStateInitExternalEntity(PROLOG_STATE *state) -{ +XmlPrologStateInitExternalEntity(PROLOG_STATE *state) { state->handler = externalSubset0; state->documentEntity = 0; state->includeLevel = 0; } #endif /* XML_DTD */ Index: expat/xmlrole.h ================================================================== --- expat/xmlrole.h +++ expat/xmlrole.h @@ -34,11 +34,11 @@ #define XmlRole_INCLUDED 1 #ifdef __VMS /* 0 1 2 3 0 1 2 3 1234567890123456789012345678901 1234567890123456789012345678901 */ -#define XmlPrologStateInitExternalEntity XmlPrologStateInitExternalEnt +# define XmlPrologStateInitExternalEntity XmlPrologStateInitExternalEnt #endif #include "xmltok.h" #ifdef __cplusplus @@ -111,15 +111,12 @@ #endif /* XML_DTD */ XML_ROLE_PARAM_ENTITY_REF }; typedef struct prolog_state { - int (PTRCALL *handler) (struct prolog_state *state, - int tok, - const char *ptr, - const char *end, - const ENCODING *enc); + int(PTRCALL *handler)(struct prolog_state *state, int tok, const char *ptr, + const char *end, const ENCODING *enc); unsigned level; int role_none; #ifdef XML_DTD unsigned includeLevel; int documentEntity; @@ -130,13 +127,13 @@ void XmlPrologStateInit(PROLOG_STATE *); #ifdef XML_DTD void XmlPrologStateInitExternalEntity(PROLOG_STATE *); #endif /* XML_DTD */ -#define XmlTokenRole(state, tok, ptr, end, enc) \ - (((state)->handler)(state, tok, ptr, end, enc)) +#define XmlTokenRole(state, tok, ptr, end, enc) \ + (((state)->handler)(state, tok, ptr, end, enc)) #ifdef __cplusplus } #endif #endif /* not XmlRole_INCLUDED */ Index: expat/xmltok.c ================================================================== --- expat/xmltok.c +++ expat/xmltok.c @@ -29,88 +29,78 @@ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include -#include /* memcpy */ +#include /* memcpy */ #if defined(_MSC_VER) && (_MSC_VER <= 1700) - /* for vs2012/11.0/1700 and earlier Visual Studio compilers */ -# define bool int -# define false 0 -# define true 1 +/* for vs2012/11.0/1700 and earlier Visual Studio compilers */ +# define bool int +# define false 0 +# define true 1 #else -# include +# include #endif - #ifdef _WIN32 -#include "winconfig.h" +# include "winconfig.h" #else -#ifdef HAVE_EXPAT_CONFIG_H -#include -#endif +# ifdef HAVE_EXPAT_CONFIG_H +# include +# endif #endif /* ndef _WIN32 */ #include "expat_external.h" #include "internal.h" #include "xmltok.h" #include "nametab.h" #ifdef XML_DTD -#define IGNORE_SECTION_TOK_VTABLE , PREFIX(ignoreSectionTok) +# define IGNORE_SECTION_TOK_VTABLE , PREFIX(ignoreSectionTok) #else -#define IGNORE_SECTION_TOK_VTABLE /* as nothing */ +# define IGNORE_SECTION_TOK_VTABLE /* as nothing */ #endif -#define VTABLE1 \ - { PREFIX(prologTok), PREFIX(contentTok), \ - PREFIX(cdataSectionTok) IGNORE_SECTION_TOK_VTABLE }, \ - { PREFIX(attributeValueTok), PREFIX(entityValueTok) }, \ - PREFIX(nameMatchesAscii), \ - PREFIX(nameLength), \ - PREFIX(skipS), \ - PREFIX(getAtts), \ - PREFIX(charRefNumber), \ - PREFIX(predefinedEntityName), \ - PREFIX(updatePosition), \ - PREFIX(isPublicId) +#define VTABLE1 \ + {PREFIX(prologTok), PREFIX(contentTok), \ + PREFIX(cdataSectionTok) IGNORE_SECTION_TOK_VTABLE}, \ + {PREFIX(attributeValueTok), PREFIX(entityValueTok)}, \ + PREFIX(nameMatchesAscii), PREFIX(nameLength), PREFIX(skipS), \ + PREFIX(getAtts), PREFIX(charRefNumber), PREFIX(predefinedEntityName), \ + PREFIX(updatePosition), PREFIX(isPublicId) #define VTABLE VTABLE1, PREFIX(toUtf8), PREFIX(toUtf16) -#define UCS2_GET_NAMING(pages, hi, lo) \ - (namingBitmap[(pages[hi] << 3) + ((lo) >> 5)] & (1u << ((lo) & 0x1F))) +#define UCS2_GET_NAMING(pages, hi, lo) \ + (namingBitmap[(pages[hi] << 3) + ((lo) >> 5)] & (1u << ((lo)&0x1F))) /* A 2 byte UTF-8 representation splits the characters 11 bits between the bottom 5 and 6 bits of the bytes. We need 8 bits to index into pages, 3 bits to add to that index and 5 bits to generate the mask. */ -#define UTF8_GET_NAMING2(pages, byte) \ - (namingBitmap[((pages)[(((byte)[0]) >> 2) & 7] << 3) \ - + ((((byte)[0]) & 3) << 1) \ - + ((((byte)[1]) >> 5) & 1)] \ - & (1u << (((byte)[1]) & 0x1F))) +#define UTF8_GET_NAMING2(pages, byte) \ + (namingBitmap[((pages)[(((byte)[0]) >> 2) & 7] << 3) \ + + ((((byte)[0]) & 3) << 1) + ((((byte)[1]) >> 5) & 1)] \ + & (1u << (((byte)[1]) & 0x1F))) /* A 3 byte UTF-8 representation splits the characters 16 bits between the bottom 4, 6 and 6 bits of the bytes. We need 8 bits to index into pages, 3 bits to add to that index and 5 bits to generate the mask. */ -#define UTF8_GET_NAMING3(pages, byte) \ - (namingBitmap[((pages)[((((byte)[0]) & 0xF) << 4) \ - + ((((byte)[1]) >> 2) & 0xF)] \ - << 3) \ - + ((((byte)[1]) & 3) << 1) \ - + ((((byte)[2]) >> 5) & 1)] \ - & (1u << (((byte)[2]) & 0x1F))) - -#define UTF8_GET_NAMING(pages, p, n) \ - ((n) == 2 \ - ? UTF8_GET_NAMING2(pages, (const unsigned char *)(p)) \ - : ((n) == 3 \ - ? UTF8_GET_NAMING3(pages, (const unsigned char *)(p)) \ - : 0)) +#define UTF8_GET_NAMING3(pages, byte) \ + (namingBitmap \ + [((pages)[((((byte)[0]) & 0xF) << 4) + ((((byte)[1]) >> 2) & 0xF)] \ + << 3) \ + + ((((byte)[1]) & 3) << 1) + ((((byte)[2]) >> 5) & 1)] \ + & (1u << (((byte)[2]) & 0x1F))) + +#define UTF8_GET_NAMING(pages, p, n) \ + ((n) == 2 \ + ? UTF8_GET_NAMING2(pages, (const unsigned char *)(p)) \ + : ((n) == 3 ? UTF8_GET_NAMING3(pages, (const unsigned char *)(p)) : 0)) /* Detection of invalid UTF-8 sequences is based on Table 3.1B of Unicode 3.2: http://www.unicode.org/unicode/reports/tr28/ with the additional restriction of not allowing the Unicode code points 0xFFFF and 0xFFFE (sequences EF,BF,BF and EF,BF,BE). @@ -118,230 +108,196 @@ (A & 0x80) == 0 means A < 0x80 and (A & 0xC0) == 0xC0 means A > 0xBF */ -#define UTF8_INVALID2(p) \ +#define UTF8_INVALID2(p) \ ((*p) < 0xC2 || ((p)[1] & 0x80) == 0 || ((p)[1] & 0xC0) == 0xC0) -#define UTF8_INVALID3(p) \ - (((p)[2] & 0x80) == 0 \ - || \ - ((*p) == 0xEF && (p)[1] == 0xBF \ - ? \ - (p)[2] > 0xBD \ - : \ - ((p)[2] & 0xC0) == 0xC0) \ - || \ - ((*p) == 0xE0 \ - ? \ - (p)[1] < 0xA0 || ((p)[1] & 0xC0) == 0xC0 \ - : \ - ((p)[1] & 0x80) == 0 \ - || \ - ((*p) == 0xED ? (p)[1] > 0x9F : ((p)[1] & 0xC0) == 0xC0))) - -#define UTF8_INVALID4(p) \ - (((p)[3] & 0x80) == 0 || ((p)[3] & 0xC0) == 0xC0 \ - || \ - ((p)[2] & 0x80) == 0 || ((p)[2] & 0xC0) == 0xC0 \ - || \ - ((*p) == 0xF0 \ - ? \ - (p)[1] < 0x90 || ((p)[1] & 0xC0) == 0xC0 \ - : \ - ((p)[1] & 0x80) == 0 \ - || \ - ((*p) == 0xF4 ? (p)[1] > 0x8F : ((p)[1] & 0xC0) == 0xC0))) +#define UTF8_INVALID3(p) \ + (((p)[2] & 0x80) == 0 \ + || ((*p) == 0xEF && (p)[1] == 0xBF ? (p)[2] > 0xBD \ + : ((p)[2] & 0xC0) == 0xC0) \ + || ((*p) == 0xE0 \ + ? (p)[1] < 0xA0 || ((p)[1] & 0xC0) == 0xC0 \ + : ((p)[1] & 0x80) == 0 \ + || ((*p) == 0xED ? (p)[1] > 0x9F : ((p)[1] & 0xC0) == 0xC0))) + +#define UTF8_INVALID4(p) \ + (((p)[3] & 0x80) == 0 || ((p)[3] & 0xC0) == 0xC0 || ((p)[2] & 0x80) == 0 \ + || ((p)[2] & 0xC0) == 0xC0 \ + || ((*p) == 0xF0 \ + ? (p)[1] < 0x90 || ((p)[1] & 0xC0) == 0xC0 \ + : ((p)[1] & 0x80) == 0 \ + || ((*p) == 0xF4 ? (p)[1] > 0x8F : ((p)[1] & 0xC0) == 0xC0))) static int PTRFASTCALL -isNever(const ENCODING *UNUSED_P(enc), const char *UNUSED_P(p)) -{ +isNever(const ENCODING *enc, const char *p) { + UNUSED_P(enc); + UNUSED_P(p); return 0; } static int PTRFASTCALL -utf8_isName2(const ENCODING *UNUSED_P(enc), const char *p) -{ +utf8_isName2(const ENCODING *enc, const char *p) { + UNUSED_P(enc); return UTF8_GET_NAMING2(namePages, (const unsigned char *)p); } static int PTRFASTCALL -utf8_isName3(const ENCODING *UNUSED_P(enc), const char *p) -{ +utf8_isName3(const ENCODING *enc, const char *p) { + UNUSED_P(enc); return UTF8_GET_NAMING3(namePages, (const unsigned char *)p); } #define utf8_isName4 isNever static int PTRFASTCALL -utf8_isNmstrt2(const ENCODING *UNUSED_P(enc), const char *p) -{ +utf8_isNmstrt2(const ENCODING *enc, const char *p) { + UNUSED_P(enc); return UTF8_GET_NAMING2(nmstrtPages, (const unsigned char *)p); } static int PTRFASTCALL -utf8_isNmstrt3(const ENCODING *UNUSED_P(enc), const char *p) -{ +utf8_isNmstrt3(const ENCODING *enc, const char *p) { + UNUSED_P(enc); return UTF8_GET_NAMING3(nmstrtPages, (const unsigned char *)p); } #define utf8_isNmstrt4 isNever static int PTRFASTCALL -utf8_isInvalid2(const ENCODING *UNUSED_P(enc), const char *p) -{ +utf8_isInvalid2(const ENCODING *enc, const char *p) { + UNUSED_P(enc); return UTF8_INVALID2((const unsigned char *)p); } static int PTRFASTCALL -utf8_isInvalid3(const ENCODING *UNUSED_P(enc), const char *p) -{ +utf8_isInvalid3(const ENCODING *enc, const char *p) { + UNUSED_P(enc); return UTF8_INVALID3((const unsigned char *)p); } static int PTRFASTCALL -utf8_isInvalid4(const ENCODING *UNUSED_P(enc), const char *p) -{ +utf8_isInvalid4(const ENCODING *enc, const char *p) { + UNUSED_P(enc); return UTF8_INVALID4((const unsigned char *)p); } struct normal_encoding { ENCODING enc; unsigned char type[256]; #ifdef XML_MIN_SIZE - int (PTRFASTCALL *byteType)(const ENCODING *, const char *); - int (PTRFASTCALL *isNameMin)(const ENCODING *, const char *); - int (PTRFASTCALL *isNmstrtMin)(const ENCODING *, const char *); - int (PTRFASTCALL *byteToAscii)(const ENCODING *, const char *); - int (PTRCALL *charMatches)(const ENCODING *, const char *, int); + int(PTRFASTCALL *byteType)(const ENCODING *, const char *); + int(PTRFASTCALL *isNameMin)(const ENCODING *, const char *); + int(PTRFASTCALL *isNmstrtMin)(const ENCODING *, const char *); + int(PTRFASTCALL *byteToAscii)(const ENCODING *, const char *); + int(PTRCALL *charMatches)(const ENCODING *, const char *, int); #endif /* XML_MIN_SIZE */ - int (PTRFASTCALL *isName2)(const ENCODING *, const char *); - int (PTRFASTCALL *isName3)(const ENCODING *, const char *); - int (PTRFASTCALL *isName4)(const ENCODING *, const char *); - int (PTRFASTCALL *isNmstrt2)(const ENCODING *, const char *); - int (PTRFASTCALL *isNmstrt3)(const ENCODING *, const char *); - int (PTRFASTCALL *isNmstrt4)(const ENCODING *, const char *); - int (PTRFASTCALL *isInvalid2)(const ENCODING *, const char *); - int (PTRFASTCALL *isInvalid3)(const ENCODING *, const char *); - int (PTRFASTCALL *isInvalid4)(const ENCODING *, const char *); + int(PTRFASTCALL *isName2)(const ENCODING *, const char *); + int(PTRFASTCALL *isName3)(const ENCODING *, const char *); + int(PTRFASTCALL *isName4)(const ENCODING *, const char *); + int(PTRFASTCALL *isNmstrt2)(const ENCODING *, const char *); + int(PTRFASTCALL *isNmstrt3)(const ENCODING *, const char *); + int(PTRFASTCALL *isNmstrt4)(const ENCODING *, const char *); + int(PTRFASTCALL *isInvalid2)(const ENCODING *, const char *); + int(PTRFASTCALL *isInvalid3)(const ENCODING *, const char *); + int(PTRFASTCALL *isInvalid4)(const ENCODING *, const char *); }; -#define AS_NORMAL_ENCODING(enc) ((const struct normal_encoding *) (enc)) +#define AS_NORMAL_ENCODING(enc) ((const struct normal_encoding *)(enc)) #ifdef XML_MIN_SIZE -#define STANDARD_VTABLE(E) \ - E ## byteType, \ - E ## isNameMin, \ - E ## isNmstrtMin, \ - E ## byteToAscii, \ - E ## charMatches, +# define STANDARD_VTABLE(E) \ + E##byteType, E##isNameMin, E##isNmstrtMin, E##byteToAscii, E##charMatches, #else -#define STANDARD_VTABLE(E) /* as nothing */ +# define STANDARD_VTABLE(E) /* as nothing */ #endif -#define NORMAL_VTABLE(E) \ - E ## isName2, \ - E ## isName3, \ - E ## isName4, \ - E ## isNmstrt2, \ - E ## isNmstrt3, \ - E ## isNmstrt4, \ - E ## isInvalid2, \ - E ## isInvalid3, \ - E ## isInvalid4 - -#define NULL_VTABLE \ - /* isName2 */ NULL, \ - /* isName3 */ NULL, \ - /* isName4 */ NULL, \ - /* isNmstrt2 */ NULL, \ - /* isNmstrt3 */ NULL, \ - /* isNmstrt4 */ NULL, \ - /* isInvalid2 */ NULL, \ - /* isInvalid3 */ NULL, \ - /* isInvalid4 */ NULL +#define NORMAL_VTABLE(E) \ + E##isName2, E##isName3, E##isName4, E##isNmstrt2, E##isNmstrt3, \ + E##isNmstrt4, E##isInvalid2, E##isInvalid3, E##isInvalid4 + +#define NULL_VTABLE \ + /* isName2 */ NULL, /* isName3 */ NULL, /* isName4 */ NULL, \ + /* isNmstrt2 */ NULL, /* isNmstrt3 */ NULL, /* isNmstrt4 */ NULL, \ + /* isInvalid2 */ NULL, /* isInvalid3 */ NULL, /* isInvalid4 */ NULL static int FASTCALL checkCharRefNumber(int); #include "xmltok_impl.h" #include "ascii.h" #ifdef XML_MIN_SIZE -#define sb_isNameMin isNever -#define sb_isNmstrtMin isNever +# define sb_isNameMin isNever +# define sb_isNmstrtMin isNever #endif #ifdef XML_MIN_SIZE -#define MINBPC(enc) ((enc)->minBytesPerChar) +# define MINBPC(enc) ((enc)->minBytesPerChar) #else /* minimum bytes per character */ -#define MINBPC(enc) 1 +# define MINBPC(enc) 1 #endif -#define SB_BYTE_TYPE(enc, p) \ +#define SB_BYTE_TYPE(enc, p) \ (((struct normal_encoding *)(enc))->type[(unsigned char)*(p)]) #ifdef XML_MIN_SIZE static int PTRFASTCALL -sb_byteType(const ENCODING *enc, const char *p) -{ +sb_byteType(const ENCODING *enc, const char *p) { return SB_BYTE_TYPE(enc, p); } -#define BYTE_TYPE(enc, p) \ - (AS_NORMAL_ENCODING(enc)->byteType(enc, p)) +# define BYTE_TYPE(enc, p) (AS_NORMAL_ENCODING(enc)->byteType(enc, p)) #else -#define BYTE_TYPE(enc, p) SB_BYTE_TYPE(enc, p) +# define BYTE_TYPE(enc, p) SB_BYTE_TYPE(enc, p) #endif #ifdef XML_MIN_SIZE -#define BYTE_TO_ASCII(enc, p) \ - (AS_NORMAL_ENCODING(enc)->byteToAscii(enc, p)) +# define BYTE_TO_ASCII(enc, p) (AS_NORMAL_ENCODING(enc)->byteToAscii(enc, p)) static int PTRFASTCALL -sb_byteToAscii(const ENCODING *enc, const char *p) -{ +sb_byteToAscii(const ENCODING *enc, const char *p) { + UNUSED_P(enc); return *p; } #else -#define BYTE_TO_ASCII(enc, p) (*(p)) -#endif - -#define IS_NAME_CHAR(enc, p, n) \ - (AS_NORMAL_ENCODING(enc)->isName ## n(enc, p)) -#define IS_NMSTRT_CHAR(enc, p, n) \ - (AS_NORMAL_ENCODING(enc)->isNmstrt ## n(enc, p)) -#define IS_INVALID_CHAR(enc, p, n) \ - (AS_NORMAL_ENCODING(enc)->isInvalid ## n(enc, p)) - -#ifdef XML_MIN_SIZE -#define IS_NAME_CHAR_MINBPC(enc, p) \ - (AS_NORMAL_ENCODING(enc)->isNameMin(enc, p)) -#define IS_NMSTRT_CHAR_MINBPC(enc, p) \ - (AS_NORMAL_ENCODING(enc)->isNmstrtMin(enc, p)) -#else -#define IS_NAME_CHAR_MINBPC(enc, p) (0) -#define IS_NMSTRT_CHAR_MINBPC(enc, p) (0) -#endif - -#ifdef XML_MIN_SIZE -#define CHAR_MATCHES(enc, p, c) \ - (AS_NORMAL_ENCODING(enc)->charMatches(enc, p, c)) -static int PTRCALL -sb_charMatches(const ENCODING *enc, const char *p, int c) -{ +# define BYTE_TO_ASCII(enc, p) (*(p)) +#endif + +#define IS_NAME_CHAR(enc, p, n) (AS_NORMAL_ENCODING(enc)->isName##n(enc, p)) +#define IS_NMSTRT_CHAR(enc, p, n) (AS_NORMAL_ENCODING(enc)->isNmstrt##n(enc, p)) +#define IS_INVALID_CHAR(enc, p, n) \ + (AS_NORMAL_ENCODING(enc)->isInvalid##n(enc, p)) + +#ifdef XML_MIN_SIZE +# define IS_NAME_CHAR_MINBPC(enc, p) \ + (AS_NORMAL_ENCODING(enc)->isNameMin(enc, p)) +# define IS_NMSTRT_CHAR_MINBPC(enc, p) \ + (AS_NORMAL_ENCODING(enc)->isNmstrtMin(enc, p)) +#else +# define IS_NAME_CHAR_MINBPC(enc, p) (0) +# define IS_NMSTRT_CHAR_MINBPC(enc, p) (0) +#endif + +#ifdef XML_MIN_SIZE +# define CHAR_MATCHES(enc, p, c) \ + (AS_NORMAL_ENCODING(enc)->charMatches(enc, p, c)) +static int PTRCALL +sb_charMatches(const ENCODING *enc, const char *p, int c) { + UNUSED_P(enc); return *p == c; } #else /* c is an ASCII character */ -#define CHAR_MATCHES(enc, p, c) (*(p) == c) +# define CHAR_MATCHES(enc, p, c) (*(p) == c) #endif -#define PREFIX(ident) normal_ ## ident +#define PREFIX(ident) normal_##ident #define XML_TOK_IMPL_C #include "xmltok_impl.c" #undef XML_TOK_IMPL_C #undef MINBPC @@ -352,71 +308,74 @@ #undef IS_NAME_CHAR_MINBPC #undef IS_NMSTRT_CHAR #undef IS_NMSTRT_CHAR_MINBPC #undef IS_INVALID_CHAR -enum { /* UTF8_cvalN is value of masked first byte of N byte sequence */ - UTF8_cval1 = 0x00, - UTF8_cval2 = 0xc0, - UTF8_cval3 = 0xe0, - UTF8_cval4 = 0xf0 +enum { /* UTF8_cvalN is value of masked first byte of N byte sequence */ + UTF8_cval1 = 0x00, + UTF8_cval2 = 0xc0, + UTF8_cval3 = 0xe0, + UTF8_cval4 = 0xf0 }; void -_INTERNAL_trim_to_complete_utf8_characters(const char * from, const char ** fromLimRef) -{ - const char * fromLim = *fromLimRef; +_INTERNAL_trim_to_complete_utf8_characters(const char *from, + const char **fromLimRef) { + const char *fromLim = *fromLimRef; size_t walked = 0; for (; fromLim > from; fromLim--, walked++) { const unsigned char prev = (unsigned char)fromLim[-1]; - if ((prev & 0xf8u) == 0xf0u) { /* 4-byte character, lead by 0b11110xxx byte */ + if ((prev & 0xf8u) + == 0xf0u) { /* 4-byte character, lead by 0b11110xxx byte */ if (walked + 1 >= 4) { fromLim += 4 - 1; break; } else { walked = 0; } - } else if ((prev & 0xf0u) == 0xe0u) { /* 3-byte character, lead by 0b1110xxxx byte */ + } else if ((prev & 0xf0u) + == 0xe0u) { /* 3-byte character, lead by 0b1110xxxx byte */ if (walked + 1 >= 3) { fromLim += 3 - 1; break; } else { walked = 0; } - } else if ((prev & 0xe0u) == 0xc0u) { /* 2-byte character, lead by 0b110xxxxx byte */ + } else if ((prev & 0xe0u) + == 0xc0u) { /* 2-byte character, lead by 0b110xxxxx byte */ if (walked + 1 >= 2) { fromLim += 2 - 1; break; } else { walked = 0; } - } else if ((prev & 0x80u) == 0x00u) { /* 1-byte character, matching 0b0xxxxxxx */ + } else if ((prev & 0x80u) + == 0x00u) { /* 1-byte character, matching 0b0xxxxxxx */ break; } } *fromLimRef = fromLim; } static enum XML_Convert_Result PTRCALL -utf8_toUtf8(const ENCODING *UNUSED_P(enc), - const char **fromP, const char *fromLim, - char **toP, const char *toLim) -{ +utf8_toUtf8(const ENCODING *enc, const char **fromP, const char *fromLim, + char **toP, const char *toLim) { bool input_incomplete = false; bool output_exhausted = false; /* Avoid copying partial characters (due to limited space). */ const ptrdiff_t bytesAvailable = fromLim - *fromP; const ptrdiff_t bytesStorable = toLim - *toP; + UNUSED_P(enc); if (bytesAvailable > bytesStorable) { fromLim = *fromP + bytesStorable; output_exhausted = true; } /* Avoid copying partial characters (from incomplete input). */ { - const char * const fromLimBefore = fromLim; + const char *const fromLimBefore = fromLim; _INTERNAL_trim_to_complete_utf8_characters(*fromP, &fromLim); if (fromLim < fromLimBefore) { input_incomplete = true; } } @@ -426,23 +385,21 @@ memcpy(*toP, *fromP, bytesToCopy); *fromP += bytesToCopy; *toP += bytesToCopy; } - if (output_exhausted) /* needs to go first */ + if (output_exhausted) /* needs to go first */ return XML_CONVERT_OUTPUT_EXHAUSTED; else if (input_incomplete) return XML_CONVERT_INPUT_INCOMPLETE; else return XML_CONVERT_COMPLETED; } static enum XML_Convert_Result PTRCALL -utf8_toUtf16(const ENCODING *enc, - const char **fromP, const char *fromLim, - unsigned short **toP, const unsigned short *toLim) -{ +utf8_toUtf16(const ENCODING *enc, const char **fromP, const char *fromLim, + unsigned short **toP, const unsigned short *toLim) { enum XML_Convert_Result res = XML_CONVERT_COMPLETED; unsigned short *to = *toP; const char *from = *fromP; while (from < fromLim && to < toLim) { switch (((struct normal_encoding *)enc)->type[(unsigned char)*from]) { @@ -457,34 +414,32 @@ case BT_LEAD3: if (fromLim - from < 3) { res = XML_CONVERT_INPUT_INCOMPLETE; goto after; } - *to++ = (unsigned short)(((from[0] & 0xf) << 12) - | ((from[1] & 0x3f) << 6) | (from[2] & 0x3f)); + *to++ = (unsigned short)(((from[0] & 0xf) << 12) | ((from[1] & 0x3f) << 6) + | (from[2] & 0x3f)); from += 3; break; - case BT_LEAD4: - { - unsigned long n; - if (toLim - to < 2) { - res = XML_CONVERT_OUTPUT_EXHAUSTED; - goto after; - } - if (fromLim - from < 4) { - res = XML_CONVERT_INPUT_INCOMPLETE; - goto after; - } - n = ((from[0] & 0x7) << 18) | ((from[1] & 0x3f) << 12) - | ((from[2] & 0x3f) << 6) | (from[3] & 0x3f); - n -= 0x10000; - to[0] = (unsigned short)((n >> 10) | 0xD800); - to[1] = (unsigned short)((n & 0x3FF) | 0xDC00); - to += 2; - from += 4; - } - break; + case BT_LEAD4: { + unsigned long n; + if (toLim - to < 2) { + res = XML_CONVERT_OUTPUT_EXHAUSTED; + goto after; + } + if (fromLim - from < 4) { + res = XML_CONVERT_INPUT_INCOMPLETE; + goto after; + } + n = ((from[0] & 0x7) << 18) | ((from[1] & 0x3f) << 12) + | ((from[2] & 0x3f) << 6) | (from[3] & 0x3f); + n -= 0x10000; + to[0] = (unsigned short)((n >> 10) | 0xD800); + to[1] = (unsigned short)((n & 0x3FF) | 0xDC00); + to += 2; + from += 4; + } break; default: *to++ = *from++; break; } } @@ -495,60 +450,55 @@ *toP = to; return res; } #ifdef XML_NS -static const struct normal_encoding utf8_encoding_ns = { - { VTABLE1, utf8_toUtf8, utf8_toUtf16, 1, 1, 0 }, - { -#include "asciitab.h" -#include "utf8tab.h" - }, - STANDARD_VTABLE(sb_) NORMAL_VTABLE(utf8_) -}; -#endif - -static const struct normal_encoding utf8_encoding = { - { VTABLE1, utf8_toUtf8, utf8_toUtf16, 1, 1, 0 }, - { -#define BT_COLON BT_NMSTRT -#include "asciitab.h" -#undef BT_COLON -#include "utf8tab.h" - }, - STANDARD_VTABLE(sb_) NORMAL_VTABLE(utf8_) -}; - -#ifdef XML_NS - -static const struct normal_encoding internal_utf8_encoding_ns = { - { VTABLE1, utf8_toUtf8, utf8_toUtf16, 1, 1, 0 }, - { -#include "iasciitab.h" -#include "utf8tab.h" - }, - STANDARD_VTABLE(sb_) NORMAL_VTABLE(utf8_) -}; - -#endif - -static const struct normal_encoding internal_utf8_encoding = { - { VTABLE1, utf8_toUtf8, utf8_toUtf16, 1, 1, 0 }, - { -#define BT_COLON BT_NMSTRT -#include "iasciitab.h" -#undef BT_COLON -#include "utf8tab.h" - }, - STANDARD_VTABLE(sb_) NORMAL_VTABLE(utf8_) -}; - -static enum XML_Convert_Result PTRCALL -latin1_toUtf8(const ENCODING *UNUSED_P(enc), - const char **fromP, const char *fromLim, - char **toP, const char *toLim) -{ +static const struct normal_encoding utf8_encoding_ns + = {{VTABLE1, utf8_toUtf8, utf8_toUtf16, 1, 1, 0}, + { +# include "asciitab.h" +# include "utf8tab.h" + }, + STANDARD_VTABLE(sb_) NORMAL_VTABLE(utf8_)}; +#endif + +static const struct normal_encoding utf8_encoding + = {{VTABLE1, utf8_toUtf8, utf8_toUtf16, 1, 1, 0}, + { +#define BT_COLON BT_NMSTRT +#include "asciitab.h" +#undef BT_COLON +#include "utf8tab.h" + }, + STANDARD_VTABLE(sb_) NORMAL_VTABLE(utf8_)}; + +#ifdef XML_NS + +static const struct normal_encoding internal_utf8_encoding_ns + = {{VTABLE1, utf8_toUtf8, utf8_toUtf16, 1, 1, 0}, + { +# include "iasciitab.h" +# include "utf8tab.h" + }, + STANDARD_VTABLE(sb_) NORMAL_VTABLE(utf8_)}; + +#endif + +static const struct normal_encoding internal_utf8_encoding + = {{VTABLE1, utf8_toUtf8, utf8_toUtf16, 1, 1, 0}, + { +#define BT_COLON BT_NMSTRT +#include "iasciitab.h" +#undef BT_COLON +#include "utf8tab.h" + }, + STANDARD_VTABLE(sb_) NORMAL_VTABLE(utf8_)}; + +static enum XML_Convert_Result PTRCALL +latin1_toUtf8(const ENCODING *enc, const char **fromP, const char *fromLim, + char **toP, const char *toLim) { + UNUSED_P(enc); for (;;) { unsigned char c; if (*fromP == fromLim) return XML_CONVERT_COMPLETED; c = (unsigned char)**fromP; @@ -556,24 +506,22 @@ if (toLim - *toP < 2) return XML_CONVERT_OUTPUT_EXHAUSTED; *(*toP)++ = (char)((c >> 6) | UTF8_cval2); *(*toP)++ = (char)((c & 0x3f) | 0x80); (*fromP)++; - } - else { + } else { if (*toP == toLim) return XML_CONVERT_OUTPUT_EXHAUSTED; *(*toP)++ = *(*fromP)++; } } } static enum XML_Convert_Result PTRCALL -latin1_toUtf16(const ENCODING *UNUSED_P(enc), - const char **fromP, const char *fromLim, - unsigned short **toP, const unsigned short *toLim) -{ +latin1_toUtf16(const ENCODING *enc, const char **fromP, const char *fromLim, + unsigned short **toP, const unsigned short *toLim) { + UNUSED_P(enc); while (*fromP < fromLim && *toP < toLim) *(*toP)++ = (unsigned char)*(*fromP)++; if ((*toP == toLim) && (*fromP < fromLim)) return XML_CONVERT_OUTPUT_EXHAUSTED; @@ -581,37 +529,34 @@ return XML_CONVERT_COMPLETED; } #ifdef XML_NS -static const struct normal_encoding latin1_encoding_ns = { - { VTABLE1, latin1_toUtf8, latin1_toUtf16, 1, 0, 0 }, - { -#include "asciitab.h" -#include "latin1tab.h" - }, - STANDARD_VTABLE(sb_) NULL_VTABLE -}; +static const struct normal_encoding latin1_encoding_ns + = {{VTABLE1, latin1_toUtf8, latin1_toUtf16, 1, 0, 0}, + { +# include "asciitab.h" +# include "latin1tab.h" + }, + STANDARD_VTABLE(sb_) NULL_VTABLE}; #endif -static const struct normal_encoding latin1_encoding = { - { VTABLE1, latin1_toUtf8, latin1_toUtf16, 1, 0, 0 }, - { +static const struct normal_encoding latin1_encoding + = {{VTABLE1, latin1_toUtf8, latin1_toUtf16, 1, 0, 0}, + { #define BT_COLON BT_NMSTRT #include "asciitab.h" #undef BT_COLON #include "latin1tab.h" - }, - STANDARD_VTABLE(sb_) NULL_VTABLE -}; + }, + STANDARD_VTABLE(sb_) NULL_VTABLE}; static enum XML_Convert_Result PTRCALL -ascii_toUtf8(const ENCODING *UNUSED_P(enc), - const char **fromP, const char *fromLim, - char **toP, const char *toLim) -{ +ascii_toUtf8(const ENCODING *enc, const char **fromP, const char *fromLim, + char **toP, const char *toLim) { + UNUSED_P(enc); while (*fromP < fromLim && *toP < toLim) *(*toP)++ = *(*fromP)++; if ((*toP == toLim) && (*fromP < fromLim)) return XML_CONVERT_OUTPUT_EXHAUSTED; @@ -619,147 +564,155 @@ return XML_CONVERT_COMPLETED; } #ifdef XML_NS -static const struct normal_encoding ascii_encoding_ns = { - { VTABLE1, ascii_toUtf8, latin1_toUtf16, 1, 1, 0 }, - { -#include "asciitab.h" -/* BT_NONXML == 0 */ - }, - STANDARD_VTABLE(sb_) NULL_VTABLE -}; +static const struct normal_encoding ascii_encoding_ns + = {{VTABLE1, ascii_toUtf8, latin1_toUtf16, 1, 1, 0}, + { +# include "asciitab.h" + /* BT_NONXML == 0 */ + }, + STANDARD_VTABLE(sb_) NULL_VTABLE}; #endif -static const struct normal_encoding ascii_encoding = { - { VTABLE1, ascii_toUtf8, latin1_toUtf16, 1, 1, 0 }, - { +static const struct normal_encoding ascii_encoding + = {{VTABLE1, ascii_toUtf8, latin1_toUtf16, 1, 1, 0}, + { #define BT_COLON BT_NMSTRT #include "asciitab.h" #undef BT_COLON -/* BT_NONXML == 0 */ - }, - STANDARD_VTABLE(sb_) NULL_VTABLE -}; + /* BT_NONXML == 0 */ + }, + STANDARD_VTABLE(sb_) NULL_VTABLE}; static int PTRFASTCALL -unicode_byte_type(char hi, char lo) -{ +unicode_byte_type(char hi, char lo) { switch ((unsigned char)hi) { - case 0xD8: case 0xD9: case 0xDA: case 0xDB: + /* 0xD800–0xDBFF first 16-bit code unit or high surrogate (W1) */ + case 0xD8: + case 0xD9: + case 0xDA: + case 0xDB: return BT_LEAD4; - case 0xDC: case 0xDD: case 0xDE: case 0xDF: + /* 0xDC00–0xDFFF second 16-bit code unit or low surrogate (W2) */ + case 0xDC: + case 0xDD: + case 0xDE: + case 0xDF: return BT_TRAIL; case 0xFF: switch ((unsigned char)lo) { - case 0xFF: - case 0xFE: + case 0xFF: /* noncharacter-FFFF */ + case 0xFE: /* noncharacter-FFFE */ return BT_NONXML; } break; } return BT_NONASCII; } -#define DEFINE_UTF16_TO_UTF8(E) \ -static enum XML_Convert_Result PTRCALL \ -E ## toUtf8(const ENCODING *UNUSED_P(enc), \ - const char **fromP, const char *fromLim, \ - char **toP, const char *toLim) \ -{ \ - const char *from = *fromP; \ - fromLim = from + (((fromLim - from) >> 1) << 1); /* shrink to even */ \ - for (; from < fromLim; from += 2) { \ - int plane; \ - unsigned char lo2; \ - unsigned char lo = GET_LO(from); \ - unsigned char hi = GET_HI(from); \ - switch (hi) { \ - case 0: \ - if (lo < 0x80) { \ - if (*toP == toLim) { \ - *fromP = from; \ - return XML_CONVERT_OUTPUT_EXHAUSTED; \ - } \ - *(*toP)++ = lo; \ - break; \ - } \ - /* fall through */ \ - case 0x1: case 0x2: case 0x3: \ - case 0x4: case 0x5: case 0x6: case 0x7: \ - if (toLim - *toP < 2) { \ - *fromP = from; \ - return XML_CONVERT_OUTPUT_EXHAUSTED; \ - } \ - *(*toP)++ = ((lo >> 6) | (hi << 2) | UTF8_cval2); \ - *(*toP)++ = ((lo & 0x3f) | 0x80); \ - break; \ - default: \ - if (toLim - *toP < 3) { \ - *fromP = from; \ - return XML_CONVERT_OUTPUT_EXHAUSTED; \ - } \ - /* 16 bits divided 4, 6, 6 amongst 3 bytes */ \ - *(*toP)++ = ((hi >> 4) | UTF8_cval3); \ - *(*toP)++ = (((hi & 0xf) << 2) | (lo >> 6) | 0x80); \ - *(*toP)++ = ((lo & 0x3f) | 0x80); \ - break; \ - case 0xD8: case 0xD9: case 0xDA: case 0xDB: \ - if (toLim - *toP < 4) { \ - *fromP = from; \ - return XML_CONVERT_OUTPUT_EXHAUSTED; \ - } \ - if (fromLim - from < 4) { \ - *fromP = from; \ - return XML_CONVERT_INPUT_INCOMPLETE; \ - } \ - plane = (((hi & 0x3) << 2) | ((lo >> 6) & 0x3)) + 1; \ - *(*toP)++ = ((plane >> 2) | UTF8_cval4); \ - *(*toP)++ = (((lo >> 2) & 0xF) | ((plane & 0x3) << 4) | 0x80); \ - from += 2; \ - lo2 = GET_LO(from); \ - *(*toP)++ = (((lo & 0x3) << 4) \ - | ((GET_HI(from) & 0x3) << 2) \ - | (lo2 >> 6) \ - | 0x80); \ - *(*toP)++ = ((lo2 & 0x3f) | 0x80); \ - break; \ - } \ - } \ - *fromP = from; \ - if (from < fromLim) \ - return XML_CONVERT_INPUT_INCOMPLETE; \ - else \ - return XML_CONVERT_COMPLETED; \ -} - -#define DEFINE_UTF16_TO_UTF16(E) \ -static enum XML_Convert_Result PTRCALL \ -E ## toUtf16(const ENCODING *UNUSED_P(enc), \ - const char **fromP, const char *fromLim, \ - unsigned short **toP, const unsigned short *toLim) \ -{ \ - enum XML_Convert_Result res = XML_CONVERT_COMPLETED; \ - fromLim = *fromP + (((fromLim - *fromP) >> 1) << 1); /* shrink to even */ \ - /* Avoid copying first half only of surrogate */ \ - if (fromLim - *fromP > ((toLim - *toP) << 1) \ - && (GET_HI(fromLim - 2) & 0xF8) == 0xD8) { \ - fromLim -= 2; \ - res = XML_CONVERT_INPUT_INCOMPLETE; \ - } \ - for (; *fromP < fromLim && *toP < toLim; *fromP += 2) \ - *(*toP)++ = (GET_HI(*fromP) << 8) | GET_LO(*fromP); \ - if ((*toP == toLim) && (*fromP < fromLim)) \ - return XML_CONVERT_OUTPUT_EXHAUSTED; \ - else \ - return res; \ -} - -#define SET2(ptr, ch) \ - (((ptr)[0] = ((ch) & 0xff)), ((ptr)[1] = ((ch) >> 8))) +#define DEFINE_UTF16_TO_UTF8(E) \ + static enum XML_Convert_Result PTRCALL E##toUtf8( \ + const ENCODING *enc, const char **fromP, const char *fromLim, \ + char **toP, const char *toLim) { \ + const char *from = *fromP; \ + UNUSED_P(enc); \ + fromLim = from + (((fromLim - from) >> 1) << 1); /* shrink to even */ \ + for (; from < fromLim; from += 2) { \ + int plane; \ + unsigned char lo2; \ + unsigned char lo = GET_LO(from); \ + unsigned char hi = GET_HI(from); \ + switch (hi) { \ + case 0: \ + if (lo < 0x80) { \ + if (*toP == toLim) { \ + *fromP = from; \ + return XML_CONVERT_OUTPUT_EXHAUSTED; \ + } \ + *(*toP)++ = lo; \ + break; \ + } \ + /* fall through */ \ + case 0x1: \ + case 0x2: \ + case 0x3: \ + case 0x4: \ + case 0x5: \ + case 0x6: \ + case 0x7: \ + if (toLim - *toP < 2) { \ + *fromP = from; \ + return XML_CONVERT_OUTPUT_EXHAUSTED; \ + } \ + *(*toP)++ = ((lo >> 6) | (hi << 2) | UTF8_cval2); \ + *(*toP)++ = ((lo & 0x3f) | 0x80); \ + break; \ + default: \ + if (toLim - *toP < 3) { \ + *fromP = from; \ + return XML_CONVERT_OUTPUT_EXHAUSTED; \ + } \ + /* 16 bits divided 4, 6, 6 amongst 3 bytes */ \ + *(*toP)++ = ((hi >> 4) | UTF8_cval3); \ + *(*toP)++ = (((hi & 0xf) << 2) | (lo >> 6) | 0x80); \ + *(*toP)++ = ((lo & 0x3f) | 0x80); \ + break; \ + case 0xD8: \ + case 0xD9: \ + case 0xDA: \ + case 0xDB: \ + if (toLim - *toP < 4) { \ + *fromP = from; \ + return XML_CONVERT_OUTPUT_EXHAUSTED; \ + } \ + if (fromLim - from < 4) { \ + *fromP = from; \ + return XML_CONVERT_INPUT_INCOMPLETE; \ + } \ + plane = (((hi & 0x3) << 2) | ((lo >> 6) & 0x3)) + 1; \ + *(*toP)++ = (char)((plane >> 2) | UTF8_cval4); \ + *(*toP)++ = (((lo >> 2) & 0xF) | ((plane & 0x3) << 4) | 0x80); \ + from += 2; \ + lo2 = GET_LO(from); \ + *(*toP)++ = (((lo & 0x3) << 4) | ((GET_HI(from) & 0x3) << 2) \ + | (lo2 >> 6) | 0x80); \ + *(*toP)++ = ((lo2 & 0x3f) | 0x80); \ + break; \ + } \ + } \ + *fromP = from; \ + if (from < fromLim) \ + return XML_CONVERT_INPUT_INCOMPLETE; \ + else \ + return XML_CONVERT_COMPLETED; \ + } + +#define DEFINE_UTF16_TO_UTF16(E) \ + static enum XML_Convert_Result PTRCALL E##toUtf16( \ + const ENCODING *enc, const char **fromP, const char *fromLim, \ + unsigned short **toP, const unsigned short *toLim) { \ + enum XML_Convert_Result res = XML_CONVERT_COMPLETED; \ + UNUSED_P(enc); \ + fromLim = *fromP + (((fromLim - *fromP) >> 1) << 1); /* shrink to even */ \ + /* Avoid copying first half only of surrogate */ \ + if (fromLim - *fromP > ((toLim - *toP) << 1) \ + && (GET_HI(fromLim - 2) & 0xF8) == 0xD8) { \ + fromLim -= 2; \ + res = XML_CONVERT_INPUT_INCOMPLETE; \ + } \ + for (; *fromP < fromLim && *toP < toLim; *fromP += 2) \ + *(*toP)++ = (GET_HI(*fromP) << 8) | GET_LO(*fromP); \ + if ((*toP == toLim) && (*fromP < fromLim)) \ + return XML_CONVERT_OUTPUT_EXHAUSTED; \ + else \ + return res; \ + } + +#define SET2(ptr, ch) (((ptr)[0] = ((ch)&0xff)), ((ptr)[1] = ((ch) >> 8))) #define GET_LO(ptr) ((unsigned char)(ptr)[0]) #define GET_HI(ptr) ((unsigned char)(ptr)[1]) DEFINE_UTF16_TO_UTF8(little2_) DEFINE_UTF16_TO_UTF16(little2_) @@ -766,12 +719,11 @@ #undef SET2 #undef GET_LO #undef GET_HI -#define SET2(ptr, ch) \ - (((ptr)[0] = ((ch) >> 8)), ((ptr)[1] = ((ch) & 0xFF))) +#define SET2(ptr, ch) (((ptr)[0] = ((ch) >> 8)), ((ptr)[1] = ((ch)&0xFF))) #define GET_LO(ptr) ((unsigned char)(ptr)[1]) #define GET_HI(ptr) ((unsigned char)(ptr)[0]) DEFINE_UTF16_TO_UTF8(big2_) DEFINE_UTF16_TO_UTF16(big2_) @@ -778,296 +730,283 @@ #undef SET2 #undef GET_LO #undef GET_HI -#define LITTLE2_BYTE_TYPE(enc, p) \ - ((p)[1] == 0 \ - ? ((struct normal_encoding *)(enc))->type[(unsigned char)*(p)] \ - : unicode_byte_type((p)[1], (p)[0])) -#define LITTLE2_BYTE_TO_ASCII(enc, p) ((p)[1] == 0 ? (p)[0] : -1) -#define LITTLE2_CHAR_MATCHES(enc, p, c) ((p)[1] == 0 && (p)[0] == c) -#define LITTLE2_IS_NAME_CHAR_MINBPC(enc, p) \ +#define LITTLE2_BYTE_TYPE(enc, p) \ + ((p)[1] == 0 ? ((struct normal_encoding *)(enc))->type[(unsigned char)*(p)] \ + : unicode_byte_type((p)[1], (p)[0])) +#define LITTLE2_BYTE_TO_ASCII(p) ((p)[1] == 0 ? (p)[0] : -1) +#define LITTLE2_CHAR_MATCHES(p, c) ((p)[1] == 0 && (p)[0] == c) +#define LITTLE2_IS_NAME_CHAR_MINBPC(p) \ UCS2_GET_NAMING(namePages, (unsigned char)p[1], (unsigned char)p[0]) -#define LITTLE2_IS_NMSTRT_CHAR_MINBPC(enc, p) \ +#define LITTLE2_IS_NMSTRT_CHAR_MINBPC(p) \ UCS2_GET_NAMING(nmstrtPages, (unsigned char)p[1], (unsigned char)p[0]) #ifdef XML_MIN_SIZE static int PTRFASTCALL -little2_byteType(const ENCODING *enc, const char *p) -{ +little2_byteType(const ENCODING *enc, const char *p) { return LITTLE2_BYTE_TYPE(enc, p); } static int PTRFASTCALL -little2_byteToAscii(const ENCODING *enc, const char *p) -{ - return LITTLE2_BYTE_TO_ASCII(enc, p); +little2_byteToAscii(const ENCODING *enc, const char *p) { + UNUSED_P(enc); + return LITTLE2_BYTE_TO_ASCII(p); } static int PTRCALL -little2_charMatches(const ENCODING *enc, const char *p, int c) -{ - return LITTLE2_CHAR_MATCHES(enc, p, c); +little2_charMatches(const ENCODING *enc, const char *p, int c) { + UNUSED_P(enc); + return LITTLE2_CHAR_MATCHES(p, c); } static int PTRFASTCALL -little2_isNameMin(const ENCODING *enc, const char *p) -{ - return LITTLE2_IS_NAME_CHAR_MINBPC(enc, p); +little2_isNameMin(const ENCODING *enc, const char *p) { + UNUSED_P(enc); + return LITTLE2_IS_NAME_CHAR_MINBPC(p); } static int PTRFASTCALL -little2_isNmstrtMin(const ENCODING *enc, const char *p) -{ - return LITTLE2_IS_NMSTRT_CHAR_MINBPC(enc, p); +little2_isNmstrtMin(const ENCODING *enc, const char *p) { + UNUSED_P(enc); + return LITTLE2_IS_NMSTRT_CHAR_MINBPC(p); } -#undef VTABLE -#define VTABLE VTABLE1, little2_toUtf8, little2_toUtf16 +# undef VTABLE +# define VTABLE VTABLE1, little2_toUtf8, little2_toUtf16 #else /* not XML_MIN_SIZE */ -#undef PREFIX -#define PREFIX(ident) little2_ ## ident -#define MINBPC(enc) 2 +# undef PREFIX +# define PREFIX(ident) little2_##ident +# define MINBPC(enc) 2 /* CHAR_MATCHES is guaranteed to have MINBPC bytes available. */ -#define BYTE_TYPE(enc, p) LITTLE2_BYTE_TYPE(enc, p) -#define BYTE_TO_ASCII(enc, p) LITTLE2_BYTE_TO_ASCII(enc, p) -#define CHAR_MATCHES(enc, p, c) LITTLE2_CHAR_MATCHES(enc, p, c) -#define IS_NAME_CHAR(enc, p, n) 0 -#define IS_NAME_CHAR_MINBPC(enc, p) LITTLE2_IS_NAME_CHAR_MINBPC(enc, p) -#define IS_NMSTRT_CHAR(enc, p, n) (0) -#define IS_NMSTRT_CHAR_MINBPC(enc, p) LITTLE2_IS_NMSTRT_CHAR_MINBPC(enc, p) - -#define XML_TOK_IMPL_C -#include "xmltok_impl.c" -#undef XML_TOK_IMPL_C - -#undef MINBPC -#undef BYTE_TYPE -#undef BYTE_TO_ASCII -#undef CHAR_MATCHES -#undef IS_NAME_CHAR -#undef IS_NAME_CHAR_MINBPC -#undef IS_NMSTRT_CHAR -#undef IS_NMSTRT_CHAR_MINBPC -#undef IS_INVALID_CHAR +# define BYTE_TYPE(enc, p) LITTLE2_BYTE_TYPE(enc, p) +# define BYTE_TO_ASCII(enc, p) LITTLE2_BYTE_TO_ASCII(p) +# define CHAR_MATCHES(enc, p, c) LITTLE2_CHAR_MATCHES(p, c) +# define IS_NAME_CHAR(enc, p, n) 0 +# define IS_NAME_CHAR_MINBPC(enc, p) LITTLE2_IS_NAME_CHAR_MINBPC(p) +# define IS_NMSTRT_CHAR(enc, p, n) (0) +# define IS_NMSTRT_CHAR_MINBPC(enc, p) LITTLE2_IS_NMSTRT_CHAR_MINBPC(p) + +# define XML_TOK_IMPL_C +# include "xmltok_impl.c" +# undef XML_TOK_IMPL_C + +# undef MINBPC +# undef BYTE_TYPE +# undef BYTE_TO_ASCII +# undef CHAR_MATCHES +# undef IS_NAME_CHAR +# undef IS_NAME_CHAR_MINBPC +# undef IS_NMSTRT_CHAR +# undef IS_NMSTRT_CHAR_MINBPC +# undef IS_INVALID_CHAR #endif /* not XML_MIN_SIZE */ #ifdef XML_NS -static const struct normal_encoding little2_encoding_ns = { - { VTABLE, 2, 0, -#if BYTEORDER == 1234 - 1 -#else - 0 -#endif - }, - { -#include "asciitab.h" -#include "latin1tab.h" - }, - STANDARD_VTABLE(little2_) NULL_VTABLE -}; - -#endif - -static const struct normal_encoding little2_encoding = { - { VTABLE, 2, 0, -#if BYTEORDER == 1234 - 1 -#else - 0 -#endif - }, - { -#define BT_COLON BT_NMSTRT -#include "asciitab.h" -#undef BT_COLON -#include "latin1tab.h" - }, - STANDARD_VTABLE(little2_) NULL_VTABLE -}; - -#if BYTEORDER != 4321 - -#ifdef XML_NS - -static const struct normal_encoding internal_little2_encoding_ns = { - { VTABLE, 2, 0, 1 }, - { -#include "iasciitab.h" -#include "latin1tab.h" - }, - STANDARD_VTABLE(little2_) NULL_VTABLE -}; - -#endif - -static const struct normal_encoding internal_little2_encoding = { - { VTABLE, 2, 0, 1 }, - { -#define BT_COLON BT_NMSTRT -#include "iasciitab.h" -#undef BT_COLON -#include "latin1tab.h" - }, - STANDARD_VTABLE(little2_) NULL_VTABLE -}; - -#endif - - -#define BIG2_BYTE_TYPE(enc, p) \ - ((p)[0] == 0 \ - ? ((struct normal_encoding *)(enc))->type[(unsigned char)(p)[1]] \ - : unicode_byte_type((p)[0], (p)[1])) -#define BIG2_BYTE_TO_ASCII(enc, p) ((p)[0] == 0 ? (p)[1] : -1) -#define BIG2_CHAR_MATCHES(enc, p, c) ((p)[0] == 0 && (p)[1] == c) -#define BIG2_IS_NAME_CHAR_MINBPC(enc, p) \ - UCS2_GET_NAMING(namePages, (unsigned char)p[0], (unsigned char)p[1]) -#define BIG2_IS_NMSTRT_CHAR_MINBPC(enc, p) \ +static const struct normal_encoding little2_encoding_ns + = {{VTABLE, 2, 0, +# if BYTEORDER == 1234 + 1 +# else + 0 +# endif + }, + { +# include "asciitab.h" +# include "latin1tab.h" + }, + STANDARD_VTABLE(little2_) NULL_VTABLE}; + +#endif + +static const struct normal_encoding little2_encoding + = {{VTABLE, 2, 0, +#if BYTEORDER == 1234 + 1 +#else + 0 +#endif + }, + { +#define BT_COLON BT_NMSTRT +#include "asciitab.h" +#undef BT_COLON +#include "latin1tab.h" + }, + STANDARD_VTABLE(little2_) NULL_VTABLE}; + +#if BYTEORDER != 4321 + +# ifdef XML_NS + +static const struct normal_encoding internal_little2_encoding_ns + = {{VTABLE, 2, 0, 1}, + { +# include "iasciitab.h" +# include "latin1tab.h" + }, + STANDARD_VTABLE(little2_) NULL_VTABLE}; + +# endif + +static const struct normal_encoding internal_little2_encoding + = {{VTABLE, 2, 0, 1}, + { +# define BT_COLON BT_NMSTRT +# include "iasciitab.h" +# undef BT_COLON +# include "latin1tab.h" + }, + STANDARD_VTABLE(little2_) NULL_VTABLE}; + +#endif + +#define BIG2_BYTE_TYPE(enc, p) \ + ((p)[0] == 0 \ + ? ((struct normal_encoding *)(enc))->type[(unsigned char)(p)[1]] \ + : unicode_byte_type((p)[0], (p)[1])) +#define BIG2_BYTE_TO_ASCII(p) ((p)[0] == 0 ? (p)[1] : -1) +#define BIG2_CHAR_MATCHES(p, c) ((p)[0] == 0 && (p)[1] == c) +#define BIG2_IS_NAME_CHAR_MINBPC(p) \ + UCS2_GET_NAMING(namePages, (unsigned char)p[0], (unsigned char)p[1]) +#define BIG2_IS_NMSTRT_CHAR_MINBPC(p) \ UCS2_GET_NAMING(nmstrtPages, (unsigned char)p[0], (unsigned char)p[1]) #ifdef XML_MIN_SIZE static int PTRFASTCALL -big2_byteType(const ENCODING *enc, const char *p) -{ +big2_byteType(const ENCODING *enc, const char *p) { return BIG2_BYTE_TYPE(enc, p); } static int PTRFASTCALL -big2_byteToAscii(const ENCODING *enc, const char *p) -{ - return BIG2_BYTE_TO_ASCII(enc, p); -} - -static int PTRCALL -big2_charMatches(const ENCODING *enc, const char *p, int c) -{ - return BIG2_CHAR_MATCHES(enc, p, c); -} - -static int PTRFASTCALL -big2_isNameMin(const ENCODING *enc, const char *p) -{ - return BIG2_IS_NAME_CHAR_MINBPC(enc, p); -} - -static int PTRFASTCALL -big2_isNmstrtMin(const ENCODING *enc, const char *p) -{ - return BIG2_IS_NMSTRT_CHAR_MINBPC(enc, p); -} - -#undef VTABLE -#define VTABLE VTABLE1, big2_toUtf8, big2_toUtf16 +big2_byteToAscii(const ENCODING *enc, const char *p) { + UNUSED_P(enc); + return BIG2_BYTE_TO_ASCII(p); +} + +static int PTRCALL +big2_charMatches(const ENCODING *enc, const char *p, int c) { + UNUSED_P(enc); + return BIG2_CHAR_MATCHES(p, c); +} + +static int PTRFASTCALL +big2_isNameMin(const ENCODING *enc, const char *p) { + UNUSED_P(enc); + return BIG2_IS_NAME_CHAR_MINBPC(p); +} + +static int PTRFASTCALL +big2_isNmstrtMin(const ENCODING *enc, const char *p) { + UNUSED_P(enc); + return BIG2_IS_NMSTRT_CHAR_MINBPC(p); +} + +# undef VTABLE +# define VTABLE VTABLE1, big2_toUtf8, big2_toUtf16 #else /* not XML_MIN_SIZE */ -#undef PREFIX -#define PREFIX(ident) big2_ ## ident -#define MINBPC(enc) 2 +# undef PREFIX +# define PREFIX(ident) big2_##ident +# define MINBPC(enc) 2 /* CHAR_MATCHES is guaranteed to have MINBPC bytes available. */ -#define BYTE_TYPE(enc, p) BIG2_BYTE_TYPE(enc, p) -#define BYTE_TO_ASCII(enc, p) BIG2_BYTE_TO_ASCII(enc, p) -#define CHAR_MATCHES(enc, p, c) BIG2_CHAR_MATCHES(enc, p, c) -#define IS_NAME_CHAR(enc, p, n) 0 -#define IS_NAME_CHAR_MINBPC(enc, p) BIG2_IS_NAME_CHAR_MINBPC(enc, p) -#define IS_NMSTRT_CHAR(enc, p, n) (0) -#define IS_NMSTRT_CHAR_MINBPC(enc, p) BIG2_IS_NMSTRT_CHAR_MINBPC(enc, p) - -#define XML_TOK_IMPL_C -#include "xmltok_impl.c" -#undef XML_TOK_IMPL_C - -#undef MINBPC -#undef BYTE_TYPE -#undef BYTE_TO_ASCII -#undef CHAR_MATCHES -#undef IS_NAME_CHAR -#undef IS_NAME_CHAR_MINBPC -#undef IS_NMSTRT_CHAR -#undef IS_NMSTRT_CHAR_MINBPC -#undef IS_INVALID_CHAR +# define BYTE_TYPE(enc, p) BIG2_BYTE_TYPE(enc, p) +# define BYTE_TO_ASCII(enc, p) BIG2_BYTE_TO_ASCII(p) +# define CHAR_MATCHES(enc, p, c) BIG2_CHAR_MATCHES(p, c) +# define IS_NAME_CHAR(enc, p, n) 0 +# define IS_NAME_CHAR_MINBPC(enc, p) BIG2_IS_NAME_CHAR_MINBPC(p) +# define IS_NMSTRT_CHAR(enc, p, n) (0) +# define IS_NMSTRT_CHAR_MINBPC(enc, p) BIG2_IS_NMSTRT_CHAR_MINBPC(p) + +# define XML_TOK_IMPL_C +# include "xmltok_impl.c" +# undef XML_TOK_IMPL_C + +# undef MINBPC +# undef BYTE_TYPE +# undef BYTE_TO_ASCII +# undef CHAR_MATCHES +# undef IS_NAME_CHAR +# undef IS_NAME_CHAR_MINBPC +# undef IS_NMSTRT_CHAR +# undef IS_NMSTRT_CHAR_MINBPC +# undef IS_INVALID_CHAR #endif /* not XML_MIN_SIZE */ #ifdef XML_NS -static const struct normal_encoding big2_encoding_ns = { - { VTABLE, 2, 0, -#if BYTEORDER == 4321 - 1 -#else - 0 -#endif - }, - { -#include "asciitab.h" -#include "latin1tab.h" - }, - STANDARD_VTABLE(big2_) NULL_VTABLE -}; - -#endif - -static const struct normal_encoding big2_encoding = { - { VTABLE, 2, 0, -#if BYTEORDER == 4321 - 1 -#else - 0 -#endif - }, - { -#define BT_COLON BT_NMSTRT -#include "asciitab.h" -#undef BT_COLON -#include "latin1tab.h" - }, - STANDARD_VTABLE(big2_) NULL_VTABLE -}; - -#if BYTEORDER != 1234 - -#ifdef XML_NS - -static const struct normal_encoding internal_big2_encoding_ns = { - { VTABLE, 2, 0, 1 }, - { -#include "iasciitab.h" -#include "latin1tab.h" - }, - STANDARD_VTABLE(big2_) NULL_VTABLE -}; - -#endif - -static const struct normal_encoding internal_big2_encoding = { - { VTABLE, 2, 0, 1 }, - { -#define BT_COLON BT_NMSTRT -#include "iasciitab.h" -#undef BT_COLON -#include "latin1tab.h" - }, - STANDARD_VTABLE(big2_) NULL_VTABLE -}; +static const struct normal_encoding big2_encoding_ns + = {{VTABLE, 2, 0, +# if BYTEORDER == 4321 + 1 +# else + 0 +# endif + }, + { +# include "asciitab.h" +# include "latin1tab.h" + }, + STANDARD_VTABLE(big2_) NULL_VTABLE}; + +#endif + +static const struct normal_encoding big2_encoding + = {{VTABLE, 2, 0, +#if BYTEORDER == 4321 + 1 +#else + 0 +#endif + }, + { +#define BT_COLON BT_NMSTRT +#include "asciitab.h" +#undef BT_COLON +#include "latin1tab.h" + }, + STANDARD_VTABLE(big2_) NULL_VTABLE}; + +#if BYTEORDER != 1234 + +# ifdef XML_NS + +static const struct normal_encoding internal_big2_encoding_ns + = {{VTABLE, 2, 0, 1}, + { +# include "iasciitab.h" +# include "latin1tab.h" + }, + STANDARD_VTABLE(big2_) NULL_VTABLE}; + +# endif + +static const struct normal_encoding internal_big2_encoding + = {{VTABLE, 2, 0, 1}, + { +# define BT_COLON BT_NMSTRT +# include "iasciitab.h" +# undef BT_COLON +# include "latin1tab.h" + }, + STANDARD_VTABLE(big2_) NULL_VTABLE}; #endif #undef PREFIX static int FASTCALL -streqci(const char *s1, const char *s2) -{ +streqci(const char *s1, const char *s2) { for (;;) { char c1 = *s1++; char c2 = *s2++; if (ASCII_a <= c1 && c1 <= ASCII_z) c1 += ASCII_A - ASCII_a; @@ -1077,26 +1016,25 @@ * upper-case strings into s2. */ c2 += ASCII_A - ASCII_a; /* LCOV_EXCL_LINE */ if (c1 != c2) return 0; - if (!c1) + if (! c1) break; } return 1; } static void PTRCALL -initUpdatePosition(const ENCODING *UNUSED_P(enc), const char *ptr, - const char *end, POSITION *pos) -{ +initUpdatePosition(const ENCODING *enc, const char *ptr, const char *end, + POSITION *pos) { + UNUSED_P(enc); normal_updatePosition(&utf8_encoding.enc, ptr, end, pos); } static int -toAscii(const ENCODING *enc, const char *ptr, const char *end) -{ +toAscii(const ENCODING *enc, const char *ptr, const char *end) { char buf[1]; char *p = buf; XmlUtf8Convert(enc, &ptr, end, &p, p + 1); if (p == buf) return -1; @@ -1103,12 +1041,11 @@ else return buf[0]; } static int FASTCALL -isSpace(int c) -{ +isSpace(int c) { switch (c) { case 0x20: case 0xD: case 0xA: case 0x9: @@ -1119,25 +1056,20 @@ /* Return 1 if there's just optional white space or there's an S followed by name=val. */ static int -parsePseudoAttribute(const ENCODING *enc, - const char *ptr, - const char *end, - const char **namePtr, - const char **nameEndPtr, - const char **valPtr, - const char **nextTokPtr) -{ +parsePseudoAttribute(const ENCODING *enc, const char *ptr, const char *end, + const char **namePtr, const char **nameEndPtr, + const char **valPtr, const char **nextTokPtr) { int c; char open; if (ptr == end) { *namePtr = NULL; return 1; } - if (!isSpace(toAscii(enc, ptr, end))) { + if (! isSpace(toAscii(enc, ptr, end))) { *nextTokPtr = ptr; return 0; } do { ptr += enc->minBytesPerChar; @@ -1189,86 +1121,67 @@ *valPtr = ptr; for (;; ptr += enc->minBytesPerChar) { c = toAscii(enc, ptr, end); if (c == open) break; - if (!(ASCII_a <= c && c <= ASCII_z) - && !(ASCII_A <= c && c <= ASCII_Z) - && !(ASCII_0 <= c && c <= ASCII_9) - && c != ASCII_PERIOD - && c != ASCII_MINUS - && c != ASCII_UNDERSCORE) { + if (! (ASCII_a <= c && c <= ASCII_z) && ! (ASCII_A <= c && c <= ASCII_Z) + && ! (ASCII_0 <= c && c <= ASCII_9) && c != ASCII_PERIOD + && c != ASCII_MINUS && c != ASCII_UNDERSCORE) { *nextTokPtr = ptr; return 0; } } *nextTokPtr = ptr + enc->minBytesPerChar; return 1; } -static const char KW_version[] = { - ASCII_v, ASCII_e, ASCII_r, ASCII_s, ASCII_i, ASCII_o, ASCII_n, '\0' -}; - -static const char KW_encoding[] = { - ASCII_e, ASCII_n, ASCII_c, ASCII_o, ASCII_d, ASCII_i, ASCII_n, ASCII_g, '\0' -}; - -static const char KW_standalone[] = { - ASCII_s, ASCII_t, ASCII_a, ASCII_n, ASCII_d, ASCII_a, ASCII_l, ASCII_o, - ASCII_n, ASCII_e, '\0' -}; - -static const char KW_yes[] = { - ASCII_y, ASCII_e, ASCII_s, '\0' -}; - -static const char KW_no[] = { - ASCII_n, ASCII_o, '\0' -}; +static const char KW_version[] + = {ASCII_v, ASCII_e, ASCII_r, ASCII_s, ASCII_i, ASCII_o, ASCII_n, '\0'}; + +static const char KW_encoding[] = {ASCII_e, ASCII_n, ASCII_c, ASCII_o, ASCII_d, + ASCII_i, ASCII_n, ASCII_g, '\0'}; + +static const char KW_standalone[] + = {ASCII_s, ASCII_t, ASCII_a, ASCII_n, ASCII_d, ASCII_a, + ASCII_l, ASCII_o, ASCII_n, ASCII_e, '\0'}; + +static const char KW_yes[] = {ASCII_y, ASCII_e, ASCII_s, '\0'}; + +static const char KW_no[] = {ASCII_n, ASCII_o, '\0'}; static int -doParseXmlDecl(const ENCODING *(*encodingFinder)(const ENCODING *, - const char *, +doParseXmlDecl(const ENCODING *(*encodingFinder)(const ENCODING *, const char *, const char *), - int isGeneralTextEntity, - const ENCODING *enc, - const char *ptr, - const char *end, - const char **badPtr, - const char **versionPtr, - const char **versionEndPtr, - const char **encodingName, - const ENCODING **encoding, - int *standalone) -{ + int isGeneralTextEntity, const ENCODING *enc, const char *ptr, + const char *end, const char **badPtr, const char **versionPtr, + const char **versionEndPtr, const char **encodingName, + const ENCODING **encoding, int *standalone) { const char *val = NULL; const char *name = NULL; const char *nameEnd = NULL; ptr += 5 * enc->minBytesPerChar; end -= 2 * enc->minBytesPerChar; - if (!parsePseudoAttribute(enc, ptr, end, &name, &nameEnd, &val, &ptr) - || !name) { + if (! parsePseudoAttribute(enc, ptr, end, &name, &nameEnd, &val, &ptr) + || ! name) { *badPtr = ptr; return 0; } - if (!XmlNameMatchesAscii(enc, name, nameEnd, KW_version)) { - if (!isGeneralTextEntity) { + if (! XmlNameMatchesAscii(enc, name, nameEnd, KW_version)) { + if (! isGeneralTextEntity) { *badPtr = name; return 0; } - } - else { + } else { if (versionPtr) *versionPtr = val; if (versionEndPtr) *versionEndPtr = ptr; - if (!parsePseudoAttribute(enc, ptr, end, &name, &nameEnd, &val, &ptr)) { + if (! parsePseudoAttribute(enc, ptr, end, &name, &nameEnd, &val, &ptr)) { *badPtr = ptr; return 0; } - if (!name) { + if (! name) { if (isGeneralTextEntity) { /* a TextDecl must have an EncodingDecl */ *badPtr = ptr; return 0; } @@ -1275,39 +1188,37 @@ return 1; } } if (XmlNameMatchesAscii(enc, name, nameEnd, KW_encoding)) { int c = toAscii(enc, val, end); - if (!(ASCII_a <= c && c <= ASCII_z) && !(ASCII_A <= c && c <= ASCII_Z)) { + if (! (ASCII_a <= c && c <= ASCII_z) && ! (ASCII_A <= c && c <= ASCII_Z)) { *badPtr = val; return 0; } if (encodingName) *encodingName = val; if (encoding) *encoding = encodingFinder(enc, val, ptr - enc->minBytesPerChar); - if (!parsePseudoAttribute(enc, ptr, end, &name, &nameEnd, &val, &ptr)) { + if (! parsePseudoAttribute(enc, ptr, end, &name, &nameEnd, &val, &ptr)) { *badPtr = ptr; return 0; } - if (!name) + if (! name) return 1; } - if (!XmlNameMatchesAscii(enc, name, nameEnd, KW_standalone) + if (! XmlNameMatchesAscii(enc, name, nameEnd, KW_standalone) || isGeneralTextEntity) { *badPtr = name; return 0; } if (XmlNameMatchesAscii(enc, val, ptr - enc->minBytesPerChar, KW_yes)) { if (standalone) *standalone = 1; - } - else if (XmlNameMatchesAscii(enc, val, ptr - enc->minBytesPerChar, KW_no)) { + } else if (XmlNameMatchesAscii(enc, val, ptr - enc->minBytesPerChar, KW_no)) { if (standalone) *standalone = 0; - } - else { + } else { *badPtr = val; return 0; } while (isSpace(toAscii(enc, ptr, end))) ptr += enc->minBytesPerChar; @@ -1317,15 +1228,20 @@ } return 1; } static int FASTCALL -checkCharRefNumber(int result) -{ +checkCharRefNumber(int result) { switch (result >> 8) { - case 0xD8: case 0xD9: case 0xDA: case 0xDB: - case 0xDC: case 0xDD: case 0xDE: case 0xDF: + case 0xD8: + case 0xD9: + case 0xDA: + case 0xDB: + case 0xDC: + case 0xDD: + case 0xDE: + case 0xDF: return -1; case 0: if (latin1_encoding.type[result] == BT_NONXML) return -1; break; @@ -1336,12 +1252,11 @@ } return result; } int FASTCALL -XmlUtf8Encode(int c, char *buf) -{ +XmlUtf8Encode(int c, char *buf) { enum { /* minN is minimum legal resulting value for N byte sequence */ min2 = 0x80, min3 = 0x800, min4 = 0x10000 @@ -1373,12 +1288,11 @@ } return 0; /* LCOV_EXCL_LINE: this case too is eliminated before calling */ } int FASTCALL -XmlUtf16Encode(int charNum, unsigned short *buf) -{ +XmlUtf16Encode(int charNum, unsigned short *buf) { if (charNum < 0) return 0; if (charNum < 0x10000) { buf[0] = (unsigned short)charNum; return 1; @@ -1398,51 +1312,45 @@ void *userData; unsigned short utf16[256]; char utf8[256][4]; }; -#define AS_UNKNOWN_ENCODING(enc) ((const struct unknown_encoding *) (enc)) +#define AS_UNKNOWN_ENCODING(enc) ((const struct unknown_encoding *)(enc)) int -XmlSizeOfUnknownEncoding(void) -{ +XmlSizeOfUnknownEncoding(void) { return sizeof(struct unknown_encoding); } static int PTRFASTCALL -unknown_isName(const ENCODING *enc, const char *p) -{ +unknown_isName(const ENCODING *enc, const char *p) { const struct unknown_encoding *uenc = AS_UNKNOWN_ENCODING(enc); int c = uenc->convert(uenc->userData, p); if (c & ~0xFFFF) return 0; return UCS2_GET_NAMING(namePages, c >> 8, c & 0xFF); } static int PTRFASTCALL -unknown_isNmstrt(const ENCODING *enc, const char *p) -{ +unknown_isNmstrt(const ENCODING *enc, const char *p) { const struct unknown_encoding *uenc = AS_UNKNOWN_ENCODING(enc); int c = uenc->convert(uenc->userData, p); if (c & ~0xFFFF) return 0; return UCS2_GET_NAMING(nmstrtPages, c >> 8, c & 0xFF); } static int PTRFASTCALL -unknown_isInvalid(const ENCODING *enc, const char *p) -{ +unknown_isInvalid(const ENCODING *enc, const char *p) { const struct unknown_encoding *uenc = AS_UNKNOWN_ENCODING(enc); int c = uenc->convert(uenc->userData, p); return (c & ~0xFFFF) || checkCharRefNumber(c) < 0; } static enum XML_Convert_Result PTRCALL -unknown_toUtf8(const ENCODING *enc, - const char **fromP, const char *fromLim, - char **toP, const char *toLim) -{ +unknown_toUtf8(const ENCODING *enc, const char **fromP, const char *fromLim, + char **toP, const char *toLim) { const struct unknown_encoding *uenc = AS_UNKNOWN_ENCODING(enc); char buf[XML_UTF8_ENCODE_MAX]; for (;;) { const char *utf8; int n; @@ -1456,12 +1364,11 @@ if (n > toLim - *toP) return XML_CONVERT_OUTPUT_EXHAUSTED; utf8 = buf; *fromP += (AS_NORMAL_ENCODING(enc)->type[(unsigned char)**fromP] - (BT_LEAD2 - 2)); - } - else { + } else { if (n > toLim - *toP) return XML_CONVERT_OUTPUT_EXHAUSTED; (*fromP)++; } memcpy(*toP, utf8, n); @@ -1468,24 +1375,20 @@ *toP += n; } } static enum XML_Convert_Result PTRCALL -unknown_toUtf16(const ENCODING *enc, - const char **fromP, const char *fromLim, - unsigned short **toP, const unsigned short *toLim) -{ +unknown_toUtf16(const ENCODING *enc, const char **fromP, const char *fromLim, + unsigned short **toP, const unsigned short *toLim) { const struct unknown_encoding *uenc = AS_UNKNOWN_ENCODING(enc); while (*fromP < fromLim && *toP < toLim) { unsigned short c = uenc->utf16[(unsigned char)**fromP]; if (c == 0) { - c = (unsigned short) - uenc->convert(uenc->userData, *fromP); + c = (unsigned short)uenc->convert(uenc->userData, *fromP); *fromP += (AS_NORMAL_ENCODING(enc)->type[(unsigned char)**fromP] - (BT_LEAD2 - 2)); - } - else + } else (*fromP)++; *(*toP)++ = c; } if ((*toP == toLim) && (*fromP < fromLim)) @@ -1493,61 +1396,51 @@ else return XML_CONVERT_COMPLETED; } ENCODING * -XmlInitUnknownEncoding(void *mem, - int *table, - CONVERTER convert, - void *userData) -{ +XmlInitUnknownEncoding(void *mem, int *table, CONVERTER convert, + void *userData) { int i; struct unknown_encoding *e = (struct unknown_encoding *)mem; - for (i = 0; i < (int)sizeof(struct normal_encoding); i++) - ((char *)mem)[i] = ((char *)&latin1_encoding)[i]; + memcpy(mem, &latin1_encoding, sizeof(struct normal_encoding)); for (i = 0; i < 128; i++) if (latin1_encoding.type[i] != BT_OTHER - && latin1_encoding.type[i] != BT_NONXML - && table[i] != i) + && latin1_encoding.type[i] != BT_NONXML && table[i] != i) return 0; for (i = 0; i < 256; i++) { int c = table[i]; if (c == -1) { e->normal.type[i] = BT_MALFORM; /* This shouldn't really get used. */ e->utf16[i] = 0xFFFF; e->utf8[i][0] = 1; e->utf8[i][1] = 0; - } - else if (c < 0) { + } else if (c < 0) { if (c < -4) return 0; /* Multi-byte sequences need a converter function */ - if (!convert) + if (! convert) return 0; e->normal.type[i] = (unsigned char)(BT_LEAD2 - (c + 2)); e->utf8[i][0] = 0; e->utf16[i] = 0; - } - else if (c < 0x80) { + } else if (c < 0x80) { if (latin1_encoding.type[c] != BT_OTHER - && latin1_encoding.type[c] != BT_NONXML - && c != i) + && latin1_encoding.type[c] != BT_NONXML && c != i) return 0; e->normal.type[i] = latin1_encoding.type[c]; e->utf8[i][0] = 1; e->utf8[i][1] = (char)c; e->utf16[i] = (unsigned short)(c == 0 ? 0xFFFF : c); - } - else if (checkCharRefNumber(c) < 0) { + } else if (checkCharRefNumber(c) < 0) { e->normal.type[i] = BT_NONXML; /* This shouldn't really get used. */ e->utf16[i] = 0xFFFF; e->utf8[i][0] = 1; e->utf8[i][1] = 0; - } - else { + } else { if (c > 0xFFFF) return 0; if (UCS2_GET_NAMING(nmstrtPages, c >> 8, c & 0xff)) e->normal.type[i] = BT_NMSTRT; else if (UCS2_GET_NAMING(namePages, c >> 8, c & 0xff)) @@ -1588,48 +1481,36 @@ UTF_16LE_ENC, /* must match encodingNames up to here */ NO_ENC }; -static const char KW_ISO_8859_1[] = { - ASCII_I, ASCII_S, ASCII_O, ASCII_MINUS, ASCII_8, ASCII_8, ASCII_5, ASCII_9, - ASCII_MINUS, ASCII_1, '\0' -}; -static const char KW_US_ASCII[] = { - ASCII_U, ASCII_S, ASCII_MINUS, ASCII_A, ASCII_S, ASCII_C, ASCII_I, ASCII_I, - '\0' -}; -static const char KW_UTF_8[] = { - ASCII_U, ASCII_T, ASCII_F, ASCII_MINUS, ASCII_8, '\0' -}; -static const char KW_UTF_16[] = { - ASCII_U, ASCII_T, ASCII_F, ASCII_MINUS, ASCII_1, ASCII_6, '\0' -}; -static const char KW_UTF_16BE[] = { - ASCII_U, ASCII_T, ASCII_F, ASCII_MINUS, ASCII_1, ASCII_6, ASCII_B, ASCII_E, - '\0' -}; -static const char KW_UTF_16LE[] = { - ASCII_U, ASCII_T, ASCII_F, ASCII_MINUS, ASCII_1, ASCII_6, ASCII_L, ASCII_E, - '\0' -}; +static const char KW_ISO_8859_1[] + = {ASCII_I, ASCII_S, ASCII_O, ASCII_MINUS, ASCII_8, ASCII_8, + ASCII_5, ASCII_9, ASCII_MINUS, ASCII_1, '\0'}; +static const char KW_US_ASCII[] + = {ASCII_U, ASCII_S, ASCII_MINUS, ASCII_A, ASCII_S, + ASCII_C, ASCII_I, ASCII_I, '\0'}; +static const char KW_UTF_8[] + = {ASCII_U, ASCII_T, ASCII_F, ASCII_MINUS, ASCII_8, '\0'}; +static const char KW_UTF_16[] + = {ASCII_U, ASCII_T, ASCII_F, ASCII_MINUS, ASCII_1, ASCII_6, '\0'}; +static const char KW_UTF_16BE[] + = {ASCII_U, ASCII_T, ASCII_F, ASCII_MINUS, ASCII_1, + ASCII_6, ASCII_B, ASCII_E, '\0'}; +static const char KW_UTF_16LE[] + = {ASCII_U, ASCII_T, ASCII_F, ASCII_MINUS, ASCII_1, + ASCII_6, ASCII_L, ASCII_E, '\0'}; static int FASTCALL -getEncodingIndex(const char *name) -{ - static const char * const encodingNames[] = { - KW_ISO_8859_1, - KW_US_ASCII, - KW_UTF_8, - KW_UTF_16, - KW_UTF_16BE, - KW_UTF_16LE, +getEncodingIndex(const char *name) { + static const char *const encodingNames[] = { + KW_ISO_8859_1, KW_US_ASCII, KW_UTF_8, KW_UTF_16, KW_UTF_16BE, KW_UTF_16LE, }; int i; if (name == NULL) return NO_ENC; - for (i = 0; i < (int)(sizeof(encodingNames)/sizeof(encodingNames[0])); i++) + for (i = 0; i < (int)(sizeof(encodingNames) / sizeof(encodingNames[0])); i++) if (streqci(name, encodingNames[i])) return i; return UNKNOWN_ENC; } @@ -1645,19 +1526,13 @@ the external (protocol) specified encoding; state is XML_CONTENT_STATE if we're parsing an external text entity, and XML_PROLOG_STATE otherwise. */ - static int -initScan(const ENCODING * const *encodingTable, - const INIT_ENCODING *enc, - int state, - const char *ptr, - const char *end, - const char **nextTokPtr) -{ +initScan(const ENCODING *const *encodingTable, const INIT_ENCODING *enc, + int state, const char *ptr, const char *end, const char **nextTokPtr) { const ENCODING **encPtr; if (ptr >= end) return XML_TOK_NONE; encPtr = enc->encPtr; @@ -1678,24 +1553,21 @@ } switch ((unsigned char)*ptr) { case 0xFE: case 0xFF: case 0xEF: /* possibly first byte of UTF-8 BOM */ - if (INIT_ENC_INDEX(enc) == ISO_8859_1_ENC - && state == XML_CONTENT_STATE) + if (INIT_ENC_INDEX(enc) == ISO_8859_1_ENC && state == XML_CONTENT_STATE) break; /* fall through */ case 0x00: case 0x3C: return XML_TOK_PARTIAL; } - } - else { + } else { switch (((unsigned char)ptr[0] << 8) | (unsigned char)ptr[1]) { case 0xFEFF: - if (INIT_ENC_INDEX(enc) == ISO_8859_1_ENC - && state == XML_CONTENT_STATE) + if (INIT_ENC_INDEX(enc) == ISO_8859_1_ENC && state == XML_CONTENT_STATE) break; *nextTokPtr = ptr + 2; *encPtr = encodingTable[UTF_16BE_ENC]; return XML_TOK_BOM; /* 00 3C is handled in the default case */ @@ -1705,12 +1577,11 @@ && state == XML_CONTENT_STATE) break; *encPtr = encodingTable[UTF_16LE_ENC]; return XmlTok(*encPtr, state, ptr, end, nextTokPtr); case 0xFFFE: - if (INIT_ENC_INDEX(enc) == ISO_8859_1_ENC - && state == XML_CONTENT_STATE) + if (INIT_ENC_INDEX(enc) == ISO_8859_1_ENC && state == XML_CONTENT_STATE) break; *nextTokPtr = ptr + 2; *encPtr = encodingTable[UTF_16LE_ENC]; return XML_TOK_BOM; case 0xEFBB: @@ -1721,12 +1592,12 @@ don't look for the BOM, because it might be a legal data. */ if (state == XML_CONTENT_STATE) { int e = INIT_ENC_INDEX(enc); - if (e == ISO_8859_1_ENC || e == UTF_16BE_ENC - || e == UTF_16LE_ENC || e == UTF_16_ENC) + if (e == ISO_8859_1_ENC || e == UTF_16BE_ENC || e == UTF_16LE_ENC + || e == UTF_16_ENC) break; } if (ptr + 2 == end) return XML_TOK_PARTIAL; if ((unsigned char)ptr[2] == 0xBF) { @@ -1745,12 +1616,11 @@ */ if (state == XML_CONTENT_STATE && INIT_ENC_INDEX(enc) == UTF_16LE_ENC) break; *encPtr = encodingTable[UTF_16BE_ENC]; return XmlTok(*encPtr, state, ptr, end, nextTokPtr); - } - else if (ptr[1] == '\0') { + } else if (ptr[1] == '\0') { /* We could recover here in the case: - parsing an external entity - second byte is 0 - no externally specified encoding - no encoding declaration @@ -1768,11 +1638,10 @@ } *encPtr = encodingTable[INIT_ENC_INDEX(enc)]; return XmlTok(*encPtr, state, ptr, end, nextTokPtr); } - #define NS(x) x #define ns(x) x #define XML_TOK_NS_C #include "xmltok_ns.c" #undef XML_TOK_NS_C @@ -1779,28 +1648,25 @@ #undef NS #undef ns #ifdef XML_NS -#define NS(x) x ## NS -#define ns(x) x ## _ns - -#define XML_TOK_NS_C -#include "xmltok_ns.c" -#undef XML_TOK_NS_C - -#undef NS -#undef ns +# define NS(x) x##NS +# define ns(x) x##_ns + +# define XML_TOK_NS_C +# include "xmltok_ns.c" +# undef XML_TOK_NS_C + +# undef NS +# undef ns ENCODING * -XmlInitUnknownEncodingNS(void *mem, - int *table, - CONVERTER convert, - void *userData) -{ +XmlInitUnknownEncodingNS(void *mem, int *table, CONVERTER convert, + void *userData) { ENCODING *enc = XmlInitUnknownEncoding(mem, table, convert, userData); if (enc) ((struct normal_encoding *)enc)->type[ASCII_COLON] = BT_COLON; return enc; } #endif /* XML_NS */ Index: expat/xmltok.h ================================================================== --- expat/xmltok.h +++ expat/xmltok.h @@ -36,20 +36,22 @@ #ifdef __cplusplus extern "C" { #endif /* The following token may be returned by XmlContentTok */ -#define XML_TOK_TRAILING_RSQB -5 /* ] or ]] at the end of the scan; might be - start of illegal ]]> sequence */ +#define XML_TOK_TRAILING_RSQB \ + -5 /* ] or ]] at the end of the scan; might be \ + start of illegal ]]> sequence */ /* The following tokens may be returned by both XmlPrologTok and XmlContentTok. */ -#define XML_TOK_NONE -4 /* The string to be scanned is empty */ -#define XML_TOK_TRAILING_CR -3 /* A CR at the end of the scan; - might be part of CRLF sequence */ -#define XML_TOK_PARTIAL_CHAR -2 /* only part of a multibyte sequence */ -#define XML_TOK_PARTIAL -1 /* only part of a token */ +#define XML_TOK_NONE -4 /* The string to be scanned is empty */ +#define XML_TOK_TRAILING_CR \ + -3 /* A CR at the end of the scan; \ + might be part of CRLF sequence */ +#define XML_TOK_PARTIAL_CHAR -2 /* only part of a multibyte sequence */ +#define XML_TOK_PARTIAL -1 /* only part of a token */ #define XML_TOK_INVALID 0 /* The following tokens are returned by XmlContentTok; some are also returned by XmlAttributeValueTok, XmlEntityTok, XmlCdataSectionTok. */ @@ -60,28 +62,28 @@ #define XML_TOK_END_TAG 5 #define XML_TOK_DATA_CHARS 6 #define XML_TOK_DATA_NEWLINE 7 #define XML_TOK_CDATA_SECT_OPEN 8 #define XML_TOK_ENTITY_REF 9 -#define XML_TOK_CHAR_REF 10 /* numeric character reference */ +#define XML_TOK_CHAR_REF 10 /* numeric character reference */ /* The following tokens may be returned by both XmlPrologTok and XmlContentTok. */ -#define XML_TOK_PI 11 /* processing instruction */ -#define XML_TOK_XML_DECL 12 /* XML decl or text decl */ +#define XML_TOK_PI 11 /* processing instruction */ +#define XML_TOK_XML_DECL 12 /* XML decl or text decl */ #define XML_TOK_COMMENT 13 -#define XML_TOK_BOM 14 /* Byte order mark */ +#define XML_TOK_BOM 14 /* Byte order mark */ /* The following tokens are returned only by XmlPrologTok */ #define XML_TOK_PROLOG_S 15 -#define XML_TOK_DECL_OPEN 16 /* */ +#define XML_TOK_DECL_OPEN 16 /* */ #define XML_TOK_NAME 18 #define XML_TOK_NMTOKEN 19 -#define XML_TOK_POUND_NAME 20 /* #name */ -#define XML_TOK_OR 21 /* | */ +#define XML_TOK_POUND_NAME 20 /* #name */ +#define XML_TOK_OR 21 /* | */ #define XML_TOK_PERCENT 22 #define XML_TOK_OPEN_PAREN 23 #define XML_TOK_CLOSE_PAREN 24 #define XML_TOK_OPEN_BRACKET 25 #define XML_TOK_CLOSE_BRACKET 26 @@ -88,18 +90,18 @@ #define XML_TOK_LITERAL 27 #define XML_TOK_PARAM_ENTITY_REF 28 #define XML_TOK_INSTANCE_START 29 /* The following occur only in element type declarations */ -#define XML_TOK_NAME_QUESTION 30 /* name? */ -#define XML_TOK_NAME_ASTERISK 31 /* name* */ -#define XML_TOK_NAME_PLUS 32 /* name+ */ -#define XML_TOK_COND_SECT_OPEN 33 /* */ -#define XML_TOK_CLOSE_PAREN_QUESTION 35 /* )? */ -#define XML_TOK_CLOSE_PAREN_ASTERISK 36 /* )* */ -#define XML_TOK_CLOSE_PAREN_PLUS 37 /* )+ */ +#define XML_TOK_NAME_QUESTION 30 /* name? */ +#define XML_TOK_NAME_ASTERISK 31 /* name* */ +#define XML_TOK_NAME_PLUS 32 /* name+ */ +#define XML_TOK_COND_SECT_OPEN 33 /* */ +#define XML_TOK_CLOSE_PAREN_QUESTION 35 /* )? */ +#define XML_TOK_CLOSE_PAREN_ASTERISK 36 /* )* */ +#define XML_TOK_CLOSE_PAREN_PLUS 37 /* )+ */ #define XML_TOK_COMMA 38 /* The following token is returned only by XmlAttributeValueTok */ #define XML_TOK_ATTRIBUTE_VALUE_S 39 @@ -110,24 +112,24 @@ name with a colon. */ #define XML_TOK_PREFIXED_NAME 41 #ifdef XML_DTD -#define XML_TOK_IGNORE_SECT 42 +# define XML_TOK_IGNORE_SECT 42 #endif /* XML_DTD */ #ifdef XML_DTD -#define XML_N_STATES 4 +# define XML_N_STATES 4 #else /* not XML_DTD */ -#define XML_N_STATES 3 +# define XML_N_STATES 3 #endif /* not XML_DTD */ #define XML_PROLOG_STATE 0 #define XML_CONTENT_STATE 1 #define XML_CDATA_SECTION_STATE 2 #ifdef XML_DTD -#define XML_IGNORE_SECTION_STATE 3 +# define XML_IGNORE_SECTION_STATE 3 #endif /* XML_DTD */ #define XML_N_LITERAL_TYPES 2 #define XML_ATTRIBUTE_VALUE_LITERAL 0 #define XML_ENTITY_VALUE_LITERAL 1 @@ -151,56 +153,45 @@ } ATTRIBUTE; struct encoding; typedef struct encoding ENCODING; -typedef int (PTRCALL *SCANNER)(const ENCODING *, - const char *, - const char *, - const char **); +typedef int(PTRCALL *SCANNER)(const ENCODING *, const char *, const char *, + const char **); enum XML_Convert_Result { XML_CONVERT_COMPLETED = 0, XML_CONVERT_INPUT_INCOMPLETE = 1, - XML_CONVERT_OUTPUT_EXHAUSTED = 2 /* and therefore potentially input remaining as well */ + XML_CONVERT_OUTPUT_EXHAUSTED + = 2 /* and therefore potentially input remaining as well */ }; struct encoding { SCANNER scanners[XML_N_STATES]; SCANNER literalScanners[XML_N_LITERAL_TYPES]; - int (PTRCALL *nameMatchesAscii)(const ENCODING *, - const char *, - const char *, - const char *); - int (PTRFASTCALL *nameLength)(const ENCODING *, const char *); + int(PTRCALL *nameMatchesAscii)(const ENCODING *, const char *, const char *, + const char *); + int(PTRFASTCALL *nameLength)(const ENCODING *, const char *); const char *(PTRFASTCALL *skipS)(const ENCODING *, const char *); - int (PTRCALL *getAtts)(const ENCODING *enc, - const char *ptr, - int attsMax, - ATTRIBUTE *atts); - int (PTRFASTCALL *charRefNumber)(const ENCODING *enc, const char *ptr); - int (PTRCALL *predefinedEntityName)(const ENCODING *, - const char *, - const char *); - void (PTRCALL *updatePosition)(const ENCODING *, - const char *ptr, - const char *end, - POSITION *); - int (PTRCALL *isPublicId)(const ENCODING *enc, - const char *ptr, - const char *end, - const char **badPtr); - enum XML_Convert_Result (PTRCALL *utf8Convert)(const ENCODING *enc, - const char **fromP, - const char *fromLim, - char **toP, - const char *toLim); - enum XML_Convert_Result (PTRCALL *utf16Convert)(const ENCODING *enc, - const char **fromP, - const char *fromLim, - unsigned short **toP, - const unsigned short *toLim); + int(PTRCALL *getAtts)(const ENCODING *enc, const char *ptr, int attsMax, + ATTRIBUTE *atts); + int(PTRFASTCALL *charRefNumber)(const ENCODING *enc, const char *ptr); + int(PTRCALL *predefinedEntityName)(const ENCODING *, const char *, + const char *); + void(PTRCALL *updatePosition)(const ENCODING *, const char *ptr, + const char *end, POSITION *); + int(PTRCALL *isPublicId)(const ENCODING *enc, const char *ptr, + const char *end, const char **badPtr); + enum XML_Convert_Result(PTRCALL *utf8Convert)(const ENCODING *enc, + const char **fromP, + const char *fromLim, char **toP, + const char *toLim); + enum XML_Convert_Result(PTRCALL *utf16Convert)(const ENCODING *enc, + const char **fromP, + const char *fromLim, + unsigned short **toP, + const unsigned short *toLim); int minBytesPerChar; char isUtf8; char isUtf16; }; @@ -223,123 +214,102 @@ Each data character counts as a single token, but adjacent data characters may be returned together. Similarly for characters in the prolog outside literals, comments and processing instructions. */ - -#define XmlTok(enc, state, ptr, end, nextTokPtr) \ +#define XmlTok(enc, state, ptr, end, nextTokPtr) \ (((enc)->scanners[state])(enc, ptr, end, nextTokPtr)) -#define XmlPrologTok(enc, ptr, end, nextTokPtr) \ - XmlTok(enc, XML_PROLOG_STATE, ptr, end, nextTokPtr) - -#define XmlContentTok(enc, ptr, end, nextTokPtr) \ - XmlTok(enc, XML_CONTENT_STATE, ptr, end, nextTokPtr) - -#define XmlCdataSectionTok(enc, ptr, end, nextTokPtr) \ - XmlTok(enc, XML_CDATA_SECTION_STATE, ptr, end, nextTokPtr) +#define XmlPrologTok(enc, ptr, end, nextTokPtr) \ + XmlTok(enc, XML_PROLOG_STATE, ptr, end, nextTokPtr) + +#define XmlContentTok(enc, ptr, end, nextTokPtr) \ + XmlTok(enc, XML_CONTENT_STATE, ptr, end, nextTokPtr) + +#define XmlCdataSectionTok(enc, ptr, end, nextTokPtr) \ + XmlTok(enc, XML_CDATA_SECTION_STATE, ptr, end, nextTokPtr) #ifdef XML_DTD -#define XmlIgnoreSectionTok(enc, ptr, end, nextTokPtr) \ - XmlTok(enc, XML_IGNORE_SECTION_STATE, ptr, end, nextTokPtr) +# define XmlIgnoreSectionTok(enc, ptr, end, nextTokPtr) \ + XmlTok(enc, XML_IGNORE_SECTION_STATE, ptr, end, nextTokPtr) #endif /* XML_DTD */ /* This is used for performing a 2nd-level tokenization on the content of a literal that has already been returned by XmlTok. */ -#define XmlLiteralTok(enc, literalType, ptr, end, nextTokPtr) \ +#define XmlLiteralTok(enc, literalType, ptr, end, nextTokPtr) \ (((enc)->literalScanners[literalType])(enc, ptr, end, nextTokPtr)) -#define XmlAttributeValueTok(enc, ptr, end, nextTokPtr) \ - XmlLiteralTok(enc, XML_ATTRIBUTE_VALUE_LITERAL, ptr, end, nextTokPtr) +#define XmlAttributeValueTok(enc, ptr, end, nextTokPtr) \ + XmlLiteralTok(enc, XML_ATTRIBUTE_VALUE_LITERAL, ptr, end, nextTokPtr) -#define XmlEntityValueTok(enc, ptr, end, nextTokPtr) \ - XmlLiteralTok(enc, XML_ENTITY_VALUE_LITERAL, ptr, end, nextTokPtr) +#define XmlEntityValueTok(enc, ptr, end, nextTokPtr) \ + XmlLiteralTok(enc, XML_ENTITY_VALUE_LITERAL, ptr, end, nextTokPtr) -#define XmlNameMatchesAscii(enc, ptr1, end1, ptr2) \ +#define XmlNameMatchesAscii(enc, ptr1, end1, ptr2) \ (((enc)->nameMatchesAscii)(enc, ptr1, end1, ptr2)) -#define XmlNameLength(enc, ptr) \ - (((enc)->nameLength)(enc, ptr)) +#define XmlNameLength(enc, ptr) (((enc)->nameLength)(enc, ptr)) + +#define XmlSkipS(enc, ptr) (((enc)->skipS)(enc, ptr)) -#define XmlSkipS(enc, ptr) \ - (((enc)->skipS)(enc, ptr)) - -#define XmlGetAttributes(enc, ptr, attsMax, atts) \ +#define XmlGetAttributes(enc, ptr, attsMax, atts) \ (((enc)->getAtts)(enc, ptr, attsMax, atts)) -#define XmlCharRefNumber(enc, ptr) \ - (((enc)->charRefNumber)(enc, ptr)) +#define XmlCharRefNumber(enc, ptr) (((enc)->charRefNumber)(enc, ptr)) -#define XmlPredefinedEntityName(enc, ptr, end) \ +#define XmlPredefinedEntityName(enc, ptr, end) \ (((enc)->predefinedEntityName)(enc, ptr, end)) -#define XmlUpdatePosition(enc, ptr, end, pos) \ +#define XmlUpdatePosition(enc, ptr, end, pos) \ (((enc)->updatePosition)(enc, ptr, end, pos)) -#define XmlIsPublicId(enc, ptr, end, badPtr) \ +#define XmlIsPublicId(enc, ptr, end, badPtr) \ (((enc)->isPublicId)(enc, ptr, end, badPtr)) -#define XmlUtf8Convert(enc, fromP, fromLim, toP, toLim) \ +#define XmlUtf8Convert(enc, fromP, fromLim, toP, toLim) \ (((enc)->utf8Convert)(enc, fromP, fromLim, toP, toLim)) -#define XmlUtf16Convert(enc, fromP, fromLim, toP, toLim) \ +#define XmlUtf16Convert(enc, fromP, fromLim, toP, toLim) \ (((enc)->utf16Convert)(enc, fromP, fromLim, toP, toLim)) typedef struct { ENCODING initEnc; const ENCODING **encPtr; } INIT_ENCODING; -int XmlParseXmlDecl(int isGeneralTextEntity, - const ENCODING *enc, - const char *ptr, - const char *end, - const char **badPtr, - const char **versionPtr, - const char **versionEndPtr, +int XmlParseXmlDecl(int isGeneralTextEntity, const ENCODING *enc, + const char *ptr, const char *end, const char **badPtr, + const char **versionPtr, const char **versionEndPtr, const char **encodingNamePtr, - const ENCODING **namedEncodingPtr, - int *standalonePtr); + const ENCODING **namedEncodingPtr, int *standalonePtr); int XmlInitEncoding(INIT_ENCODING *, const ENCODING **, const char *name); const ENCODING *XmlGetUtf8InternalEncoding(void); const ENCODING *XmlGetUtf16InternalEncoding(void); int FASTCALL XmlUtf8Encode(int charNumber, char *buf); int FASTCALL XmlUtf16Encode(int charNumber, unsigned short *buf); int XmlSizeOfUnknownEncoding(void); - -typedef int (XMLCALL *CONVERTER) (void *userData, const char *p); - -ENCODING * -XmlInitUnknownEncoding(void *mem, - int *table, - CONVERTER convert, - void *userData); - -int XmlParseXmlDeclNS(int isGeneralTextEntity, - const ENCODING *enc, - const char *ptr, - const char *end, - const char **badPtr, - const char **versionPtr, - const char **versionEndPtr, - const char **encodingNamePtr, - const ENCODING **namedEncodingPtr, - int *standalonePtr); +typedef int(XMLCALL *CONVERTER)(void *userData, const char *p); + +ENCODING *XmlInitUnknownEncoding(void *mem, int *table, CONVERTER convert, + void *userData); + +int XmlParseXmlDeclNS(int isGeneralTextEntity, const ENCODING *enc, + const char *ptr, const char *end, const char **badPtr, + const char **versionPtr, const char **versionEndPtr, + const char **encodingNamePtr, + const ENCODING **namedEncodingPtr, int *standalonePtr); int XmlInitEncodingNS(INIT_ENCODING *, const ENCODING **, const char *name); const ENCODING *XmlGetUtf8InternalEncodingNS(void); const ENCODING *XmlGetUtf16InternalEncodingNS(void); -ENCODING * -XmlInitUnknownEncodingNS(void *mem, - int *table, - CONVERTER convert, - void *userData); +ENCODING *XmlInitUnknownEncodingNS(void *mem, int *table, CONVERTER convert, + void *userData); #ifdef __cplusplus } #endif #endif /* not XmlTok_INCLUDED */ Index: expat/xmltok_impl.c ================================================================== --- expat/xmltok_impl.c +++ expat/xmltok_impl.c @@ -30,134 +30,128 @@ USE OR OTHER DEALINGS IN THE SOFTWARE. */ #ifdef XML_TOK_IMPL_C -#ifndef IS_INVALID_CHAR -#define IS_INVALID_CHAR(enc, ptr, n) (0) -#endif - -#define INVALID_LEAD_CASE(n, ptr, nextTokPtr) \ - case BT_LEAD ## n: \ - if (end - ptr < n) \ - return XML_TOK_PARTIAL_CHAR; \ - if (IS_INVALID_CHAR(enc, ptr, n)) { \ - *(nextTokPtr) = (ptr); \ - return XML_TOK_INVALID; \ - } \ - ptr += n; \ - break; - -#define INVALID_CASES(ptr, nextTokPtr) \ - INVALID_LEAD_CASE(2, ptr, nextTokPtr) \ - INVALID_LEAD_CASE(3, ptr, nextTokPtr) \ - INVALID_LEAD_CASE(4, ptr, nextTokPtr) \ - case BT_NONXML: \ - case BT_MALFORM: \ - case BT_TRAIL: \ - *(nextTokPtr) = (ptr); \ +# ifndef IS_INVALID_CHAR +# define IS_INVALID_CHAR(enc, ptr, n) (0) +# endif + +# define INVALID_LEAD_CASE(n, ptr, nextTokPtr) \ + case BT_LEAD##n: \ + if (end - ptr < n) \ + return XML_TOK_PARTIAL_CHAR; \ + if (IS_INVALID_CHAR(enc, ptr, n)) { \ + *(nextTokPtr) = (ptr); \ + return XML_TOK_INVALID; \ + } \ + ptr += n; \ + break; + +# define INVALID_CASES(ptr, nextTokPtr) \ + INVALID_LEAD_CASE(2, ptr, nextTokPtr) \ + INVALID_LEAD_CASE(3, ptr, nextTokPtr) \ + INVALID_LEAD_CASE(4, ptr, nextTokPtr) \ + case BT_NONXML: \ + case BT_MALFORM: \ + case BT_TRAIL: \ + *(nextTokPtr) = (ptr); \ return XML_TOK_INVALID; -#define CHECK_NAME_CASE(n, enc, ptr, end, nextTokPtr) \ - case BT_LEAD ## n: \ - if (end - ptr < n) \ - return XML_TOK_PARTIAL_CHAR; \ - if (!IS_NAME_CHAR(enc, ptr, n)) { \ - *nextTokPtr = ptr; \ - return XML_TOK_INVALID; \ - } \ - ptr += n; \ - break; - -#define CHECK_NAME_CASES(enc, ptr, end, nextTokPtr) \ - case BT_NONASCII: \ - if (!IS_NAME_CHAR_MINBPC(enc, ptr)) { \ - *nextTokPtr = ptr; \ - return XML_TOK_INVALID; \ - } \ - /* fall through */ \ - case BT_NMSTRT: \ - case BT_HEX: \ - case BT_DIGIT: \ - case BT_NAME: \ - case BT_MINUS: \ - ptr += MINBPC(enc); \ - break; \ - CHECK_NAME_CASE(2, enc, ptr, end, nextTokPtr) \ - CHECK_NAME_CASE(3, enc, ptr, end, nextTokPtr) \ - CHECK_NAME_CASE(4, enc, ptr, end, nextTokPtr) - -#define CHECK_NMSTRT_CASE(n, enc, ptr, end, nextTokPtr) \ - case BT_LEAD ## n: \ - if (end - ptr < n) \ - return XML_TOK_PARTIAL_CHAR; \ - if (!IS_NMSTRT_CHAR(enc, ptr, n)) { \ - *nextTokPtr = ptr; \ - return XML_TOK_INVALID; \ - } \ - ptr += n; \ - break; - -#define CHECK_NMSTRT_CASES(enc, ptr, end, nextTokPtr) \ - case BT_NONASCII: \ - if (!IS_NMSTRT_CHAR_MINBPC(enc, ptr)) { \ - *nextTokPtr = ptr; \ - return XML_TOK_INVALID; \ - } \ - /* fall through */ \ - case BT_NMSTRT: \ - case BT_HEX: \ - ptr += MINBPC(enc); \ - break; \ - CHECK_NMSTRT_CASE(2, enc, ptr, end, nextTokPtr) \ - CHECK_NMSTRT_CASE(3, enc, ptr, end, nextTokPtr) \ - CHECK_NMSTRT_CASE(4, enc, ptr, end, nextTokPtr) - -#ifndef PREFIX -#define PREFIX(ident) ident -#endif - - -#define HAS_CHARS(enc, ptr, end, count) \ - (end - ptr >= count * MINBPC(enc)) - -#define HAS_CHAR(enc, ptr, end) \ - HAS_CHARS(enc, ptr, end, 1) - -#define REQUIRE_CHARS(enc, ptr, end, count) \ - { \ - if (! HAS_CHARS(enc, ptr, end, count)) { \ - return XML_TOK_PARTIAL; \ - } \ - } - -#define REQUIRE_CHAR(enc, ptr, end) \ - REQUIRE_CHARS(enc, ptr, end, 1) - +# define CHECK_NAME_CASE(n, enc, ptr, end, nextTokPtr) \ + case BT_LEAD##n: \ + if (end - ptr < n) \ + return XML_TOK_PARTIAL_CHAR; \ + if (! IS_NAME_CHAR(enc, ptr, n)) { \ + *nextTokPtr = ptr; \ + return XML_TOK_INVALID; \ + } \ + ptr += n; \ + break; + +# define CHECK_NAME_CASES(enc, ptr, end, nextTokPtr) \ + case BT_NONASCII: \ + if (! IS_NAME_CHAR_MINBPC(enc, ptr)) { \ + *nextTokPtr = ptr; \ + return XML_TOK_INVALID; \ + } \ + /* fall through */ \ + case BT_NMSTRT: \ + case BT_HEX: \ + case BT_DIGIT: \ + case BT_NAME: \ + case BT_MINUS: \ + ptr += MINBPC(enc); \ + break; \ + CHECK_NAME_CASE(2, enc, ptr, end, nextTokPtr) \ + CHECK_NAME_CASE(3, enc, ptr, end, nextTokPtr) \ + CHECK_NAME_CASE(4, enc, ptr, end, nextTokPtr) + +# define CHECK_NMSTRT_CASE(n, enc, ptr, end, nextTokPtr) \ + case BT_LEAD##n: \ + if (end - ptr < n) \ + return XML_TOK_PARTIAL_CHAR; \ + if (! IS_NMSTRT_CHAR(enc, ptr, n)) { \ + *nextTokPtr = ptr; \ + return XML_TOK_INVALID; \ + } \ + ptr += n; \ + break; + +# define CHECK_NMSTRT_CASES(enc, ptr, end, nextTokPtr) \ + case BT_NONASCII: \ + if (! IS_NMSTRT_CHAR_MINBPC(enc, ptr)) { \ + *nextTokPtr = ptr; \ + return XML_TOK_INVALID; \ + } \ + /* fall through */ \ + case BT_NMSTRT: \ + case BT_HEX: \ + ptr += MINBPC(enc); \ + break; \ + CHECK_NMSTRT_CASE(2, enc, ptr, end, nextTokPtr) \ + CHECK_NMSTRT_CASE(3, enc, ptr, end, nextTokPtr) \ + CHECK_NMSTRT_CASE(4, enc, ptr, end, nextTokPtr) + +# ifndef PREFIX +# define PREFIX(ident) ident +# endif + +# define HAS_CHARS(enc, ptr, end, count) (end - ptr >= count * MINBPC(enc)) + +# define HAS_CHAR(enc, ptr, end) HAS_CHARS(enc, ptr, end, 1) + +# define REQUIRE_CHARS(enc, ptr, end, count) \ + { \ + if (! HAS_CHARS(enc, ptr, end, count)) { \ + return XML_TOK_PARTIAL; \ + } \ + } + +# define REQUIRE_CHAR(enc, ptr, end) REQUIRE_CHARS(enc, ptr, end, 1) /* ptr points to character following " */ switch (BYTE_TYPE(enc, ptr + MINBPC(enc))) { - case BT_S: case BT_CR: case BT_LF: case BT_PERCNT: + case BT_S: + case BT_CR: + case BT_LF: + case BT_PERCNT: *nextTokPtr = ptr; return XML_TOK_INVALID; } /* fall through */ - case BT_S: case BT_CR: case BT_LF: + case BT_S: + case BT_CR: + case BT_LF: *nextTokPtr = ptr; return XML_TOK_DECL_OPEN; case BT_NMSTRT: case BT_HEX: ptr += MINBPC(enc); @@ -218,16 +216,16 @@ } return XML_TOK_PARTIAL; } static int PTRCALL -PREFIX(checkPiTarget)(const ENCODING *UNUSED_P(enc), const char *ptr, - const char *end, int *tokPtr) -{ +PREFIX(checkPiTarget)(const ENCODING *enc, const char *ptr, const char *end, + int *tokPtr) { int upper = 0; + UNUSED_P(enc); *tokPtr = XML_TOK_PI; - if (end - ptr != MINBPC(enc)*3) + if (end - ptr != MINBPC(enc) * 3) return 1; switch (BYTE_TO_ASCII(enc, ptr)) { case ASCII_x: break; case ASCII_X: @@ -263,34 +261,35 @@ } /* ptr points to character following "= end) return XML_TOK_NONE; if (MINBPC(enc) > 1) { size_t n = end - ptr; if (n & (MINBPC(enc) - 1)) { @@ -359,15 +357,15 @@ } switch (BYTE_TYPE(enc, ptr)) { case BT_RSQB: ptr += MINBPC(enc); REQUIRE_CHAR(enc, ptr, end); - if (!CHAR_MATCHES(enc, ptr, ASCII_RSQB)) + if (! CHAR_MATCHES(enc, ptr, ASCII_RSQB)) break; ptr += MINBPC(enc); REQUIRE_CHAR(enc, ptr, end); - if (!CHAR_MATCHES(enc, ptr, ASCII_GT)) { + if (! CHAR_MATCHES(enc, ptr, ASCII_GT)) { ptr -= MINBPC(enc); break; } *nextTokPtr = ptr + MINBPC(enc); return XML_TOK_CDATA_SECT_CLOSE; @@ -379,27 +377,29 @@ *nextTokPtr = ptr; return XML_TOK_DATA_NEWLINE; case BT_LF: *nextTokPtr = ptr + MINBPC(enc); return XML_TOK_DATA_NEWLINE; - INVALID_CASES(ptr, nextTokPtr) + INVALID_CASES(ptr, nextTokPtr) default: ptr += MINBPC(enc); break; } while (HAS_CHAR(enc, ptr, end)) { switch (BYTE_TYPE(enc, ptr)) { -#define LEAD_CASE(n) \ - case BT_LEAD ## n: \ - if (end - ptr < n || IS_INVALID_CHAR(enc, ptr, n)) { \ - *nextTokPtr = ptr; \ - return XML_TOK_DATA_CHARS; \ - } \ - ptr += n; \ - break; - LEAD_CASE(2) LEAD_CASE(3) LEAD_CASE(4) -#undef LEAD_CASE +# define LEAD_CASE(n) \ + case BT_LEAD##n: \ + if (end - ptr < n || IS_INVALID_CHAR(enc, ptr, n)) { \ + *nextTokPtr = ptr; \ + return XML_TOK_DATA_CHARS; \ + } \ + ptr += n; \ + break; + LEAD_CASE(2) + LEAD_CASE(3) + LEAD_CASE(4) +# undef LEAD_CASE case BT_NONXML: case BT_MALFORM: case BT_TRAIL: case BT_CR: case BT_LF: @@ -416,27 +416,30 @@ } /* ptr points to character following "= end) return XML_TOK_NONE; if (MINBPC(enc) > 1) { size_t n = end - ptr; if (n & (MINBPC(enc) - 1)) { @@ -840,52 +841,54 @@ return XML_TOK_DATA_NEWLINE; case BT_RSQB: ptr += MINBPC(enc); if (! HAS_CHAR(enc, ptr, end)) return XML_TOK_TRAILING_RSQB; - if (!CHAR_MATCHES(enc, ptr, ASCII_RSQB)) + if (! CHAR_MATCHES(enc, ptr, ASCII_RSQB)) break; ptr += MINBPC(enc); if (! HAS_CHAR(enc, ptr, end)) return XML_TOK_TRAILING_RSQB; - if (!CHAR_MATCHES(enc, ptr, ASCII_GT)) { + if (! CHAR_MATCHES(enc, ptr, ASCII_GT)) { ptr -= MINBPC(enc); break; } *nextTokPtr = ptr; return XML_TOK_INVALID; - INVALID_CASES(ptr, nextTokPtr) + INVALID_CASES(ptr, nextTokPtr) default: ptr += MINBPC(enc); break; } while (HAS_CHAR(enc, ptr, end)) { switch (BYTE_TYPE(enc, ptr)) { -#define LEAD_CASE(n) \ - case BT_LEAD ## n: \ - if (end - ptr < n || IS_INVALID_CHAR(enc, ptr, n)) { \ - *nextTokPtr = ptr; \ - return XML_TOK_DATA_CHARS; \ - } \ - ptr += n; \ - break; - LEAD_CASE(2) LEAD_CASE(3) LEAD_CASE(4) -#undef LEAD_CASE +# define LEAD_CASE(n) \ + case BT_LEAD##n: \ + if (end - ptr < n || IS_INVALID_CHAR(enc, ptr, n)) { \ + *nextTokPtr = ptr; \ + return XML_TOK_DATA_CHARS; \ + } \ + ptr += n; \ + break; + LEAD_CASE(2) + LEAD_CASE(3) + LEAD_CASE(4) +# undef LEAD_CASE case BT_RSQB: if (HAS_CHARS(enc, ptr, end, 2)) { - if (!CHAR_MATCHES(enc, ptr + MINBPC(enc), ASCII_RSQB)) { - ptr += MINBPC(enc); - break; - } - if (HAS_CHARS(enc, ptr, end, 3)) { - if (!CHAR_MATCHES(enc, ptr + 2*MINBPC(enc), ASCII_GT)) { - ptr += MINBPC(enc); - break; - } - *nextTokPtr = ptr + 2*MINBPC(enc); - return XML_TOK_INVALID; - } + if (! CHAR_MATCHES(enc, ptr + MINBPC(enc), ASCII_RSQB)) { + ptr += MINBPC(enc); + break; + } + if (HAS_CHARS(enc, ptr, end, 3)) { + if (! CHAR_MATCHES(enc, ptr + 2 * MINBPC(enc), ASCII_GT)) { + ptr += MINBPC(enc); + break; + } + *nextTokPtr = ptr + 2 * MINBPC(enc); + return XML_TOK_INVALID; + } } /* fall through */ case BT_AMP: case BT_LT: case BT_NONXML: @@ -906,25 +909,27 @@ /* ptr points to character following "%" */ static int PTRCALL PREFIX(scanPercent)(const ENCODING *enc, const char *ptr, const char *end, - const char **nextTokPtr) -{ + const char **nextTokPtr) { REQUIRE_CHAR(enc, ptr, end); switch (BYTE_TYPE(enc, ptr)) { - CHECK_NMSTRT_CASES(enc, ptr, end, nextTokPtr) - case BT_S: case BT_LF: case BT_CR: case BT_PERCNT: + CHECK_NMSTRT_CASES(enc, ptr, end, nextTokPtr) + case BT_S: + case BT_LF: + case BT_CR: + case BT_PERCNT: *nextTokPtr = ptr; return XML_TOK_PERCENT; default: *nextTokPtr = ptr; return XML_TOK_INVALID; } while (HAS_CHAR(enc, ptr, end)) { switch (BYTE_TYPE(enc, ptr)) { - CHECK_NAME_CASES(enc, ptr, end, nextTokPtr) + CHECK_NAME_CASES(enc, ptr, end, nextTokPtr) case BT_SEMI: *nextTokPtr = ptr + MINBPC(enc); return XML_TOK_PARAM_ENTITY_REF; default: *nextTokPtr = ptr; @@ -934,24 +939,28 @@ return XML_TOK_PARTIAL; } static int PTRCALL PREFIX(scanPoundName)(const ENCODING *enc, const char *ptr, const char *end, - const char **nextTokPtr) -{ + const char **nextTokPtr) { REQUIRE_CHAR(enc, ptr, end); switch (BYTE_TYPE(enc, ptr)) { - CHECK_NMSTRT_CASES(enc, ptr, end, nextTokPtr) + CHECK_NMSTRT_CASES(enc, ptr, end, nextTokPtr) default: *nextTokPtr = ptr; return XML_TOK_INVALID; } while (HAS_CHAR(enc, ptr, end)) { switch (BYTE_TYPE(enc, ptr)) { - CHECK_NAME_CASES(enc, ptr, end, nextTokPtr) - case BT_CR: case BT_LF: case BT_S: - case BT_RPAR: case BT_GT: case BT_PERCNT: case BT_VERBAR: + CHECK_NAME_CASES(enc, ptr, end, nextTokPtr) + case BT_CR: + case BT_LF: + case BT_S: + case BT_RPAR: + case BT_GT: + case BT_PERCNT: + case BT_VERBAR: *nextTokPtr = ptr; return XML_TOK_POUND_NAME; default: *nextTokPtr = ptr; return XML_TOK_INVALID; @@ -959,29 +968,31 @@ } return -XML_TOK_POUND_NAME; } static int PTRCALL -PREFIX(scanLit)(int open, const ENCODING *enc, - const char *ptr, const char *end, - const char **nextTokPtr) -{ +PREFIX(scanLit)(int open, const ENCODING *enc, const char *ptr, const char *end, + const char **nextTokPtr) { while (HAS_CHAR(enc, ptr, end)) { int t = BYTE_TYPE(enc, ptr); switch (t) { - INVALID_CASES(ptr, nextTokPtr) + INVALID_CASES(ptr, nextTokPtr) case BT_QUOT: case BT_APOS: ptr += MINBPC(enc); if (t != open) break; if (! HAS_CHAR(enc, ptr, end)) return -XML_TOK_LITERAL; *nextTokPtr = ptr; switch (BYTE_TYPE(enc, ptr)) { - case BT_S: case BT_CR: case BT_LF: - case BT_GT: case BT_PERCNT: case BT_LSQB: + case BT_S: + case BT_CR: + case BT_LF: + case BT_GT: + case BT_PERCNT: + case BT_LSQB: return XML_TOK_LITERAL; default: return XML_TOK_INVALID; } default: @@ -992,12 +1003,11 @@ return XML_TOK_PARTIAL; } static int PTRCALL PREFIX(prologTok)(const ENCODING *enc, const char *ptr, const char *end, - const char **nextTokPtr) -{ + const char **nextTokPtr) { int tok; if (ptr >= end) return XML_TOK_NONE; if (MINBPC(enc) > 1) { size_t n = end - ptr; @@ -1011,45 +1021,46 @@ switch (BYTE_TYPE(enc, ptr)) { case BT_QUOT: return PREFIX(scanLit)(BT_QUOT, enc, ptr + MINBPC(enc), end, nextTokPtr); case BT_APOS: return PREFIX(scanLit)(BT_APOS, enc, ptr + MINBPC(enc), end, nextTokPtr); - case BT_LT: - { - ptr += MINBPC(enc); - REQUIRE_CHAR(enc, ptr, end); - switch (BYTE_TYPE(enc, ptr)) { - case BT_EXCL: - return PREFIX(scanDecl)(enc, ptr + MINBPC(enc), end, nextTokPtr); - case BT_QUEST: - return PREFIX(scanPi)(enc, ptr + MINBPC(enc), end, nextTokPtr); - case BT_NMSTRT: - case BT_HEX: - case BT_NONASCII: - case BT_LEAD2: - case BT_LEAD3: - case BT_LEAD4: - *nextTokPtr = ptr - MINBPC(enc); - return XML_TOK_INSTANCE_START; - } - *nextTokPtr = ptr; - return XML_TOK_INVALID; - } + case BT_LT: { + ptr += MINBPC(enc); + REQUIRE_CHAR(enc, ptr, end); + switch (BYTE_TYPE(enc, ptr)) { + case BT_EXCL: + return PREFIX(scanDecl)(enc, ptr + MINBPC(enc), end, nextTokPtr); + case BT_QUEST: + return PREFIX(scanPi)(enc, ptr + MINBPC(enc), end, nextTokPtr); + case BT_NMSTRT: + case BT_HEX: + case BT_NONASCII: + case BT_LEAD2: + case BT_LEAD3: + case BT_LEAD4: + *nextTokPtr = ptr - MINBPC(enc); + return XML_TOK_INSTANCE_START; + } + *nextTokPtr = ptr; + return XML_TOK_INVALID; + } case BT_CR: if (ptr + MINBPC(enc) == end) { *nextTokPtr = end; /* indicate that this might be part of a CR/LF pair */ return -XML_TOK_PROLOG_S; } /* fall through */ - case BT_S: case BT_LF: + case BT_S: + case BT_LF: for (;;) { ptr += MINBPC(enc); if (! HAS_CHAR(enc, ptr, end)) break; switch (BYTE_TYPE(enc, ptr)) { - case BT_S: case BT_LF: + case BT_S: + case BT_LF: break; case BT_CR: /* don't split CR/LF pair */ if (ptr + MINBPC(enc) != end) break; @@ -1074,11 +1085,11 @@ if (! HAS_CHAR(enc, ptr, end)) return -XML_TOK_CLOSE_BRACKET; if (CHAR_MATCHES(enc, ptr, ASCII_RSQB)) { REQUIRE_CHARS(enc, ptr, end, 2); if (CHAR_MATCHES(enc, ptr + MINBPC(enc), ASCII_GT)) { - *nextTokPtr = ptr + 2*MINBPC(enc); + *nextTokPtr = ptr + 2 * MINBPC(enc); return XML_TOK_COND_SECT_CLOSE; } } *nextTokPtr = ptr; return XML_TOK_CLOSE_BRACKET; @@ -1097,12 +1108,16 @@ *nextTokPtr = ptr + MINBPC(enc); return XML_TOK_CLOSE_PAREN_QUESTION; case BT_PLUS: *nextTokPtr = ptr + MINBPC(enc); return XML_TOK_CLOSE_PAREN_PLUS; - case BT_CR: case BT_LF: case BT_S: - case BT_GT: case BT_COMMA: case BT_VERBAR: + case BT_CR: + case BT_LF: + case BT_S: + case BT_GT: + case BT_COMMA: + case BT_VERBAR: case BT_RPAR: *nextTokPtr = ptr; return XML_TOK_CLOSE_PAREN; } *nextTokPtr = ptr; @@ -1113,39 +1128,41 @@ case BT_GT: *nextTokPtr = ptr + MINBPC(enc); return XML_TOK_DECL_CLOSE; case BT_NUM: return PREFIX(scanPoundName)(enc, ptr + MINBPC(enc), end, nextTokPtr); -#define LEAD_CASE(n) \ - case BT_LEAD ## n: \ - if (end - ptr < n) \ - return XML_TOK_PARTIAL_CHAR; \ - if (IS_NMSTRT_CHAR(enc, ptr, n)) { \ - ptr += n; \ - tok = XML_TOK_NAME; \ - break; \ - } \ - if (IS_NAME_CHAR(enc, ptr, n)) { \ - ptr += n; \ - tok = XML_TOK_NMTOKEN; \ - break; \ - } \ - *nextTokPtr = ptr; \ +# define LEAD_CASE(n) \ + case BT_LEAD##n: \ + if (end - ptr < n) \ + return XML_TOK_PARTIAL_CHAR; \ + if (IS_NMSTRT_CHAR(enc, ptr, n)) { \ + ptr += n; \ + tok = XML_TOK_NAME; \ + break; \ + } \ + if (IS_NAME_CHAR(enc, ptr, n)) { \ + ptr += n; \ + tok = XML_TOK_NMTOKEN; \ + break; \ + } \ + *nextTokPtr = ptr; \ return XML_TOK_INVALID; - LEAD_CASE(2) LEAD_CASE(3) LEAD_CASE(4) -#undef LEAD_CASE + LEAD_CASE(2) + LEAD_CASE(3) + LEAD_CASE(4) +# undef LEAD_CASE case BT_NMSTRT: case BT_HEX: tok = XML_TOK_NAME; ptr += MINBPC(enc); break; case BT_DIGIT: case BT_NAME: case BT_MINUS: -#ifdef XML_NS +# ifdef XML_NS case BT_COLON: -#endif +# endif tok = XML_TOK_NMTOKEN; ptr += MINBPC(enc); break; case BT_NONASCII: if (IS_NMSTRT_CHAR_MINBPC(enc, ptr)) { @@ -1163,25 +1180,31 @@ *nextTokPtr = ptr; return XML_TOK_INVALID; } while (HAS_CHAR(enc, ptr, end)) { switch (BYTE_TYPE(enc, ptr)) { - CHECK_NAME_CASES(enc, ptr, end, nextTokPtr) - case BT_GT: case BT_RPAR: case BT_COMMA: - case BT_VERBAR: case BT_LSQB: case BT_PERCNT: - case BT_S: case BT_CR: case BT_LF: + CHECK_NAME_CASES(enc, ptr, end, nextTokPtr) + case BT_GT: + case BT_RPAR: + case BT_COMMA: + case BT_VERBAR: + case BT_LSQB: + case BT_PERCNT: + case BT_S: + case BT_CR: + case BT_LF: *nextTokPtr = ptr; return tok; -#ifdef XML_NS +# ifdef XML_NS case BT_COLON: ptr += MINBPC(enc); switch (tok) { case XML_TOK_NAME: REQUIRE_CHAR(enc, ptr, end); tok = XML_TOK_PREFIXED_NAME; switch (BYTE_TYPE(enc, ptr)) { - CHECK_NAME_CASES(enc, ptr, end, nextTokPtr) + CHECK_NAME_CASES(enc, ptr, end, nextTokPtr) default: tok = XML_TOK_NMTOKEN; break; } break; @@ -1188,27 +1211,27 @@ case XML_TOK_PREFIXED_NAME: tok = XML_TOK_NMTOKEN; break; } break; -#endif +# endif case BT_PLUS: - if (tok == XML_TOK_NMTOKEN) { + if (tok == XML_TOK_NMTOKEN) { *nextTokPtr = ptr; return XML_TOK_INVALID; } *nextTokPtr = ptr + MINBPC(enc); return XML_TOK_NAME_PLUS; case BT_AST: - if (tok == XML_TOK_NMTOKEN) { + if (tok == XML_TOK_NMTOKEN) { *nextTokPtr = ptr; return XML_TOK_INVALID; } *nextTokPtr = ptr + MINBPC(enc); return XML_TOK_NAME_ASTERISK; case BT_QUEST: - if (tok == XML_TOK_NMTOKEN) { + if (tok == XML_TOK_NMTOKEN) { *nextTokPtr = ptr; return XML_TOK_INVALID; } *nextTokPtr = ptr + MINBPC(enc); return XML_TOK_NAME_QUESTION; @@ -1219,13 +1242,12 @@ } return -tok; } static int PTRCALL -PREFIX(attributeValueTok)(const ENCODING *enc, const char *ptr, - const char *end, const char **nextTokPtr) -{ +PREFIX(attributeValueTok)(const ENCODING *enc, const char *ptr, const char *end, + const char **nextTokPtr) { const char *start; if (ptr >= end) return XML_TOK_NONE; else if (! HAS_CHAR(enc, ptr, end)) { /* This line cannot be executed. The incoming data has already @@ -1236,14 +1258,18 @@ return XML_TOK_PARTIAL; /* LCOV_EXCL_LINE */ } start = ptr; while (HAS_CHAR(enc, ptr, end)) { switch (BYTE_TYPE(enc, ptr)) { -#define LEAD_CASE(n) \ - case BT_LEAD ## n: ptr += n; break; - LEAD_CASE(2) LEAD_CASE(3) LEAD_CASE(4) -#undef LEAD_CASE +# define LEAD_CASE(n) \ + case BT_LEAD##n: \ + ptr += n; \ + break; + LEAD_CASE(2) + LEAD_CASE(3) + LEAD_CASE(4) +# undef LEAD_CASE case BT_AMP: if (ptr == start) return PREFIX(scanRef)(enc, ptr + MINBPC(enc), end, nextTokPtr); *nextTokPtr = ptr; return XML_TOK_DATA_CHARS; @@ -1285,13 +1311,12 @@ *nextTokPtr = ptr; return XML_TOK_DATA_CHARS; } static int PTRCALL -PREFIX(entityValueTok)(const ENCODING *enc, const char *ptr, - const char *end, const char **nextTokPtr) -{ +PREFIX(entityValueTok)(const ENCODING *enc, const char *ptr, const char *end, + const char **nextTokPtr) { const char *start; if (ptr >= end) return XML_TOK_NONE; else if (! HAS_CHAR(enc, ptr, end)) { /* This line cannot be executed. The incoming data has already @@ -1302,23 +1327,26 @@ return XML_TOK_PARTIAL; /* LCOV_EXCL_LINE */ } start = ptr; while (HAS_CHAR(enc, ptr, end)) { switch (BYTE_TYPE(enc, ptr)) { -#define LEAD_CASE(n) \ - case BT_LEAD ## n: ptr += n; break; - LEAD_CASE(2) LEAD_CASE(3) LEAD_CASE(4) -#undef LEAD_CASE +# define LEAD_CASE(n) \ + case BT_LEAD##n: \ + ptr += n; \ + break; + LEAD_CASE(2) + LEAD_CASE(3) + LEAD_CASE(4) +# undef LEAD_CASE case BT_AMP: if (ptr == start) return PREFIX(scanRef)(enc, ptr + MINBPC(enc), end, nextTokPtr); *nextTokPtr = ptr; return XML_TOK_DATA_CHARS; case BT_PERCNT: if (ptr == start) { - int tok = PREFIX(scanPercent)(enc, ptr + MINBPC(enc), - end, nextTokPtr); + int tok = PREFIX(scanPercent)(enc, ptr + MINBPC(enc), end, nextTokPtr); return (tok == XML_TOK_PERCENT) ? XML_TOK_INVALID : tok; } *nextTokPtr = ptr; return XML_TOK_DATA_CHARS; case BT_LF: @@ -1347,16 +1375,15 @@ } *nextTokPtr = ptr; return XML_TOK_DATA_CHARS; } -#ifdef XML_DTD +# ifdef XML_DTD static int PTRCALL -PREFIX(ignoreSectionTok)(const ENCODING *enc, const char *ptr, - const char *end, const char **nextTokPtr) -{ +PREFIX(ignoreSectionTok)(const ENCODING *enc, const char *ptr, const char *end, + const char **nextTokPtr) { int level = 0; if (MINBPC(enc) > 1) { size_t n = end - ptr; if (n & (MINBPC(enc) - 1)) { n &= ~(MINBPC(enc) - 1); @@ -1363,11 +1390,11 @@ end = ptr + n; } } while (HAS_CHAR(enc, ptr, end)) { switch (BYTE_TYPE(enc, ptr)) { - INVALID_CASES(ptr, nextTokPtr) + INVALID_CASES(ptr, nextTokPtr) case BT_LT: ptr += MINBPC(enc); REQUIRE_CHAR(enc, ptr, end); if (CHAR_MATCHES(enc, ptr, ASCII_EXCL)) { ptr += MINBPC(enc); @@ -1400,16 +1427,15 @@ } } return XML_TOK_PARTIAL; } -#endif /* XML_DTD */ +# endif /* XML_DTD */ static int PTRCALL PREFIX(isPublicId)(const ENCODING *enc, const char *ptr, const char *end, - const char **badPtr) -{ + const char **badPtr) { ptr += MINBPC(enc); end -= MINBPC(enc); for (; HAS_CHAR(enc, ptr, end); ptr += MINBPC(enc)) { switch (BYTE_TYPE(enc, ptr)) { case BT_DIGIT: @@ -1428,23 +1454,23 @@ case BT_SEMI: case BT_EXCL: case BT_AST: case BT_PERCNT: case BT_NUM: -#ifdef XML_NS +# ifdef XML_NS case BT_COLON: -#endif +# endif break; case BT_S: if (CHAR_MATCHES(enc, ptr, ASCII_TAB)) { *badPtr = ptr; return 0; } break; case BT_NAME: case BT_NMSTRT: - if (!(BYTE_TO_ASCII(enc, ptr) & ~0x7f)) + if (! (BYTE_TO_ASCII(enc, ptr) & ~0x7f)) break; /* fall through */ default: switch (BYTE_TO_ASCII(enc, ptr)) { case 0x24: /* $ */ @@ -1464,46 +1490,48 @@ element tag. Returns the number of attributes. Pointers to the first attsMax attributes are stored in atts. */ static int PTRCALL -PREFIX(getAtts)(const ENCODING *enc, const char *ptr, - int attsMax, ATTRIBUTE *atts) -{ +PREFIX(getAtts)(const ENCODING *enc, const char *ptr, int attsMax, + ATTRIBUTE *atts) { enum { other, inName, inValue } state = inName; int nAtts = 0; int open = 0; /* defined when state == inValue; initialization just to shut up compilers */ for (ptr += MINBPC(enc);; ptr += MINBPC(enc)) { switch (BYTE_TYPE(enc, ptr)) { -#define START_NAME \ - if (state == other) { \ - if (nAtts < attsMax) { \ - atts[nAtts].name = ptr; \ - atts[nAtts].normalized = 1; \ - } \ - state = inName; \ - } -#define LEAD_CASE(n) \ - case BT_LEAD ## n: START_NAME ptr += (n - MINBPC(enc)); break; - LEAD_CASE(2) LEAD_CASE(3) LEAD_CASE(4) -#undef LEAD_CASE +# define START_NAME \ + if (state == other) { \ + if (nAtts < attsMax) { \ + atts[nAtts].name = ptr; \ + atts[nAtts].normalized = 1; \ + } \ + state = inName; \ + } +# define LEAD_CASE(n) \ + case BT_LEAD##n: \ + START_NAME ptr += (n - MINBPC(enc)); \ + break; + LEAD_CASE(2) + LEAD_CASE(3) + LEAD_CASE(4) +# undef LEAD_CASE case BT_NONASCII: case BT_NMSTRT: case BT_HEX: START_NAME break; -#undef START_NAME +# undef START_NAME case BT_QUOT: if (state != inValue) { if (nAtts < attsMax) atts[nAtts].valuePtr = ptr + MINBPC(enc); state = inValue; open = BT_QUOT; - } - else if (open == BT_QUOT) { + } else if (open == BT_QUOT) { state = other; if (nAtts < attsMax) atts[nAtts].valueEnd = ptr; nAtts++; } @@ -1512,12 +1540,11 @@ if (state != inValue) { if (nAtts < attsMax) atts[nAtts].valuePtr = ptr + MINBPC(enc); state = inValue; open = BT_APOS; - } - else if (open == BT_APOS) { + } else if (open == BT_APOS) { state = other; if (nAtts < attsMax) atts[nAtts].valueEnd = ptr; nAtts++; } @@ -1527,20 +1554,19 @@ atts[nAtts].normalized = 0; break; case BT_S: if (state == inName) state = other; - else if (state == inValue - && nAtts < attsMax - && atts[nAtts].normalized + else if (state == inValue && nAtts < attsMax && atts[nAtts].normalized && (ptr == atts[nAtts].valuePtr || BYTE_TO_ASCII(enc, ptr) != ASCII_SPACE || BYTE_TO_ASCII(enc, ptr + MINBPC(enc)) == ASCII_SPACE || BYTE_TYPE(enc, ptr + MINBPC(enc)) == open)) atts[nAtts].normalized = 0; break; - case BT_CR: case BT_LF: + case BT_CR: + case BT_LF: /* This case ensures that the first attribute name is counted Apart from that we could just change state on the quote. */ if (state == inName) state = other; else if (state == inValue && nAtts < attsMax) @@ -1557,43 +1583,57 @@ } /* not reached */ } static int PTRFASTCALL -PREFIX(charRefNumber)(const ENCODING *UNUSED_P(enc), const char *ptr) -{ +PREFIX(charRefNumber)(const ENCODING *enc, const char *ptr) { int result = 0; /* skip &# */ - ptr += 2*MINBPC(enc); + UNUSED_P(enc); + ptr += 2 * MINBPC(enc); if (CHAR_MATCHES(enc, ptr, ASCII_x)) { - for (ptr += MINBPC(enc); - !CHAR_MATCHES(enc, ptr, ASCII_SEMI); + for (ptr += MINBPC(enc); ! CHAR_MATCHES(enc, ptr, ASCII_SEMI); ptr += MINBPC(enc)) { int c = BYTE_TO_ASCII(enc, ptr); switch (c) { - case ASCII_0: case ASCII_1: case ASCII_2: case ASCII_3: case ASCII_4: - case ASCII_5: case ASCII_6: case ASCII_7: case ASCII_8: case ASCII_9: + case ASCII_0: + case ASCII_1: + case ASCII_2: + case ASCII_3: + case ASCII_4: + case ASCII_5: + case ASCII_6: + case ASCII_7: + case ASCII_8: + case ASCII_9: result <<= 4; result |= (c - ASCII_0); break; - case ASCII_A: case ASCII_B: case ASCII_C: - case ASCII_D: case ASCII_E: case ASCII_F: + case ASCII_A: + case ASCII_B: + case ASCII_C: + case ASCII_D: + case ASCII_E: + case ASCII_F: result <<= 4; result += 10 + (c - ASCII_A); break; - case ASCII_a: case ASCII_b: case ASCII_c: - case ASCII_d: case ASCII_e: case ASCII_f: + case ASCII_a: + case ASCII_b: + case ASCII_c: + case ASCII_d: + case ASCII_e: + case ASCII_f: result <<= 4; result += 10 + (c - ASCII_a); break; } if (result >= 0x110000) return -1; } - } - else { - for (; !CHAR_MATCHES(enc, ptr, ASCII_SEMI); ptr += MINBPC(enc)) { + } else { + for (; ! CHAR_MATCHES(enc, ptr, ASCII_SEMI); ptr += MINBPC(enc)) { int c = BYTE_TO_ASCII(enc, ptr); result *= 10; result += (c - ASCII_0); if (result >= 0x110000) return -1; @@ -1601,14 +1641,14 @@ } return checkCharRefNumber(result); } static int PTRCALL -PREFIX(predefinedEntityName)(const ENCODING *UNUSED_P(enc), const char *ptr, - const char *end) -{ - switch ((end - ptr)/MINBPC(enc)) { +PREFIX(predefinedEntityName)(const ENCODING *enc, const char *ptr, + const char *end) { + UNUSED_P(enc); + switch ((end - ptr) / MINBPC(enc)) { case 2: if (CHAR_MATCHES(enc, ptr + MINBPC(enc), ASCII_t)) { switch (BYTE_TO_ASCII(enc, ptr)) { case ASCII_l: return ASCII_LT; @@ -1655,43 +1695,46 @@ } return 0; } static int PTRCALL -PREFIX(nameMatchesAscii)(const ENCODING *UNUSED_P(enc), const char *ptr1, - const char *end1, const char *ptr2) -{ +PREFIX(nameMatchesAscii)(const ENCODING *enc, const char *ptr1, + const char *end1, const char *ptr2) { + UNUSED_P(enc); for (; *ptr2; ptr1 += MINBPC(enc), ptr2++) { if (end1 - ptr1 < MINBPC(enc)) { /* This line cannot be executed. The incoming data has already * been tokenized once, so incomplete characters like this have * already been eliminated from the input. Retaining the * paranoia check is still valuable, however. */ return 0; /* LCOV_EXCL_LINE */ } - if (!CHAR_MATCHES(enc, ptr1, *ptr2)) + if (! CHAR_MATCHES(enc, ptr1, *ptr2)) return 0; } return ptr1 == end1; } static int PTRFASTCALL -PREFIX(nameLength)(const ENCODING *enc, const char *ptr) -{ +PREFIX(nameLength)(const ENCODING *enc, const char *ptr) { const char *start = ptr; for (;;) { switch (BYTE_TYPE(enc, ptr)) { -#define LEAD_CASE(n) \ - case BT_LEAD ## n: ptr += n; break; - LEAD_CASE(2) LEAD_CASE(3) LEAD_CASE(4) -#undef LEAD_CASE +# define LEAD_CASE(n) \ + case BT_LEAD##n: \ + ptr += n; \ + break; + LEAD_CASE(2) + LEAD_CASE(3) + LEAD_CASE(4) +# undef LEAD_CASE case BT_NONASCII: case BT_NMSTRT: -#ifdef XML_NS +# ifdef XML_NS case BT_COLON: -#endif +# endif case BT_HEX: case BT_DIGIT: case BT_NAME: case BT_MINUS: ptr += MINBPC(enc); @@ -1700,13 +1743,12 @@ return (int)(ptr - start); } } } -static const char * PTRFASTCALL -PREFIX(skipS)(const ENCODING *enc, const char *ptr) -{ +static const char *PTRFASTCALL +PREFIX(skipS)(const ENCODING *enc, const char *ptr) { for (;;) { switch (BYTE_TYPE(enc, ptr)) { case BT_LF: case BT_CR: case BT_S: @@ -1717,23 +1759,22 @@ } } } static void PTRCALL -PREFIX(updatePosition)(const ENCODING *enc, - const char *ptr, - const char *end, - POSITION *pos) -{ +PREFIX(updatePosition)(const ENCODING *enc, const char *ptr, const char *end, + POSITION *pos) { while (HAS_CHAR(enc, ptr, end)) { switch (BYTE_TYPE(enc, ptr)) { -#define LEAD_CASE(n) \ - case BT_LEAD ## n: \ - ptr += n; \ - break; - LEAD_CASE(2) LEAD_CASE(3) LEAD_CASE(4) -#undef LEAD_CASE +# define LEAD_CASE(n) \ + case BT_LEAD##n: \ + ptr += n; \ + break; + LEAD_CASE(2) + LEAD_CASE(3) + LEAD_CASE(4) +# undef LEAD_CASE case BT_LF: pos->columnNumber = (XML_Size)-1; pos->lineNumber++; ptr += MINBPC(enc); break; @@ -1750,14 +1791,14 @@ } pos->columnNumber++; } } -#undef DO_LEAD_CASE -#undef MULTIBYTE_CASES -#undef INVALID_CASES -#undef CHECK_NAME_CASE -#undef CHECK_NAME_CASES -#undef CHECK_NMSTRT_CASE -#undef CHECK_NMSTRT_CASES +# undef DO_LEAD_CASE +# undef MULTIBYTE_CASES +# undef INVALID_CASES +# undef CHECK_NAME_CASE +# undef CHECK_NAME_CASES +# undef CHECK_NMSTRT_CASE +# undef CHECK_NMSTRT_CASES #endif /* XML_TOK_IMPL_C */ Index: expat/xmltok_impl.h ================================================================== --- expat/xmltok_impl.h +++ expat/xmltok_impl.h @@ -29,45 +29,45 @@ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ enum { - BT_NONXML, - BT_MALFORM, - BT_LT, - BT_AMP, - BT_RSQB, - BT_LEAD2, - BT_LEAD3, - BT_LEAD4, - BT_TRAIL, - BT_CR, - BT_LF, - BT_GT, - BT_QUOT, - BT_APOS, - BT_EQUALS, - BT_QUEST, - BT_EXCL, - BT_SOL, - BT_SEMI, - BT_NUM, - BT_LSQB, - BT_S, - BT_NMSTRT, - BT_COLON, - BT_HEX, - BT_DIGIT, - BT_NAME, - BT_MINUS, - BT_OTHER, /* known not to be a name or name start character */ + BT_NONXML, /* e.g. noncharacter-FFFF */ + BT_MALFORM, /* illegal, with regard to encoding */ + BT_LT, /* less than = "<" */ + BT_AMP, /* ampersand = "&" */ + BT_RSQB, /* right square bracket = "[" */ + BT_LEAD2, /* lead byte of a 2-byte UTF-8 character */ + BT_LEAD3, /* lead byte of a 3-byte UTF-8 character */ + BT_LEAD4, /* lead byte of a 4-byte UTF-8 character */ + BT_TRAIL, /* trailing unit, e.g. second 16-bit unit of a 4-byte char. */ + BT_CR, /* carriage return = "\r" */ + BT_LF, /* line feed = "\n" */ + BT_GT, /* greater than = ">" */ + BT_QUOT, /* quotation character = "\"" */ + BT_APOS, /* aposthrophe = "'" */ + BT_EQUALS, /* equal sign = "=" */ + BT_QUEST, /* question mark = "?" */ + BT_EXCL, /* exclamation mark = "!" */ + BT_SOL, /* solidus, slash = "/" */ + BT_SEMI, /* semicolon = ";" */ + BT_NUM, /* number sign = "#" */ + BT_LSQB, /* left square bracket = "[" */ + BT_S, /* white space, e.g. "\t", " "[, "\r"] */ + BT_NMSTRT, /* non-hex name start letter = "G".."Z" + "g".."z" + "_" */ + BT_COLON, /* colon = ":" */ + BT_HEX, /* hex letter = "A".."F" + "a".."f" */ + BT_DIGIT, /* digit = "0".."9" */ + BT_NAME, /* dot and middle dot = "." + chr(0xb7) */ + BT_MINUS, /* minus = "-" */ + BT_OTHER, /* known not to be a name or name start character */ BT_NONASCII, /* might be a name or name start character */ - BT_PERCNT, - BT_LPAR, - BT_RPAR, - BT_AST, - BT_PLUS, - BT_COMMA, - BT_VERBAR + BT_PERCNT, /* percent sign = "%" */ + BT_LPAR, /* left parenthesis = "(" */ + BT_RPAR, /* right parenthesis = "(" */ + BT_AST, /* asterisk = "*" */ + BT_PLUS, /* plus sign = "+" */ + BT_COMMA, /* comma = "," */ + BT_VERBAR /* vertical bar = "|" */ }; #include Index: expat/xmltok_ns.c ================================================================== --- expat/xmltok_ns.c +++ expat/xmltok_ns.c @@ -31,60 +31,51 @@ */ #ifdef XML_TOK_NS_C const ENCODING * -NS(XmlGetUtf8InternalEncoding)(void) -{ +NS(XmlGetUtf8InternalEncoding)(void) { return &ns(internal_utf8_encoding).enc; } const ENCODING * -NS(XmlGetUtf16InternalEncoding)(void) -{ -#if BYTEORDER == 1234 +NS(XmlGetUtf16InternalEncoding)(void) { +# if BYTEORDER == 1234 return &ns(internal_little2_encoding).enc; -#elif BYTEORDER == 4321 +# elif BYTEORDER == 4321 return &ns(internal_big2_encoding).enc; -#else +# else const short n = 1; - return (*(const char *)&n - ? &ns(internal_little2_encoding).enc - : &ns(internal_big2_encoding).enc); -#endif + return (*(const char *)&n ? &ns(internal_little2_encoding).enc + : &ns(internal_big2_encoding).enc); +# endif } -static const ENCODING * const NS(encodings)[] = { - &ns(latin1_encoding).enc, - &ns(ascii_encoding).enc, - &ns(utf8_encoding).enc, - &ns(big2_encoding).enc, - &ns(big2_encoding).enc, - &ns(little2_encoding).enc, - &ns(utf8_encoding).enc /* NO_ENC */ +static const ENCODING *const NS(encodings)[] = { + &ns(latin1_encoding).enc, &ns(ascii_encoding).enc, + &ns(utf8_encoding).enc, &ns(big2_encoding).enc, + &ns(big2_encoding).enc, &ns(little2_encoding).enc, + &ns(utf8_encoding).enc /* NO_ENC */ }; static int PTRCALL NS(initScanProlog)(const ENCODING *enc, const char *ptr, const char *end, - const char **nextTokPtr) -{ - return initScan(NS(encodings), (const INIT_ENCODING *)enc, - XML_PROLOG_STATE, ptr, end, nextTokPtr); + const char **nextTokPtr) { + return initScan(NS(encodings), (const INIT_ENCODING *)enc, XML_PROLOG_STATE, + ptr, end, nextTokPtr); } static int PTRCALL NS(initScanContent)(const ENCODING *enc, const char *ptr, const char *end, - const char **nextTokPtr) -{ - return initScan(NS(encodings), (const INIT_ENCODING *)enc, - XML_CONTENT_STATE, ptr, end, nextTokPtr); + const char **nextTokPtr) { + return initScan(NS(encodings), (const INIT_ENCODING *)enc, XML_CONTENT_STATE, + ptr, end, nextTokPtr); } int NS(XmlInitEncoding)(INIT_ENCODING *p, const ENCODING **encPtr, - const char *name) -{ + const char *name) { int i = getEncodingIndex(name); if (i == UNKNOWN_ENC) return 0; SET_INIT_ENC_INDEX(p, i); p->initEnc.scanners[XML_PROLOG_STATE] = NS(initScanProlog); @@ -94,13 +85,12 @@ *encPtr = &(p->initEnc); return 1; } static const ENCODING * -NS(findEncoding)(const ENCODING *enc, const char *ptr, const char *end) -{ -#define ENCODING_MAX 128 +NS(findEncoding)(const ENCODING *enc, const char *ptr, const char *end) { +# define ENCODING_MAX 128 char buf[ENCODING_MAX]; char *p = buf; int i; XmlUtf8Convert(enc, &ptr, end, &p, p + ENCODING_MAX - 1); if (ptr != end) @@ -113,30 +103,16 @@ return 0; return NS(encodings)[i]; } int -NS(XmlParseXmlDecl)(int isGeneralTextEntity, - const ENCODING *enc, - const char *ptr, - const char *end, - const char **badPtr, - const char **versionPtr, - const char **versionEndPtr, - const char **encodingName, - const ENCODING **encoding, - int *standalone) -{ - return doParseXmlDecl(NS(findEncoding), - isGeneralTextEntity, - enc, - ptr, - end, - badPtr, - versionPtr, - versionEndPtr, - encodingName, - encoding, - standalone); +NS(XmlParseXmlDecl)(int isGeneralTextEntity, const ENCODING *enc, + const char *ptr, const char *end, const char **badPtr, + const char **versionPtr, const char **versionEndPtr, + const char **encodingName, const ENCODING **encoding, + int *standalone) { + return doParseXmlDecl(NS(findEncoding), isGeneralTextEntity, enc, ptr, end, + badPtr, versionPtr, versionEndPtr, encodingName, + encoding, standalone); } #endif /* XML_TOK_NS_C */ DELETED extensions/example/mkinstalldirs Index: extensions/example/mkinstalldirs ================================================================== --- extensions/example/mkinstalldirs +++ /dev/null @@ -1,40 +0,0 @@ -#! /bin/sh -# mkinstalldirs --- make directory hierarchy -# Author: Noah Friedman -# Created: 1993-05-16 -# Public domain - -# $Id$ - -errstatus=0 - -for file -do - set fnord `echo ":$file" | sed -ne 's/^:\//#/;s/^://;s/\// /g;s/^#/\//;p'` - shift - - pathcomp= - for d - do - pathcomp="$pathcomp$d" - case "$pathcomp" in - -* ) pathcomp=./$pathcomp ;; - esac - - if test ! -d "$pathcomp"; then - echo "mkdir $pathcomp" - - mkdir "$pathcomp" || lasterr=$? - - if test ! -d "$pathcomp"; then - errstatus=$lasterr - fi - fi - - pathcomp="$pathcomp/" - done -done - -exit $errstatus - -# mkinstalldirs ends here ADDED extensions/schemadtx/Makefile.in Index: extensions/schemadtx/Makefile.in ================================================================== --- /dev/null +++ extensions/schemadtx/Makefile.in @@ -0,0 +1,447 @@ +# Makefile.in -- +# +# This file is a Makefile for Sample TEA Extension. If it has the name +# "Makefile.in" then it is a template for a Makefile; to generate the +# actual Makefile, run "./configure", which is a configuration script +# generated by the "autoconf" program (constructs like "@foo@" will get +# replaced in the actual Makefile. +# +# Copyright (c) 1999 Scriptics Corporation. +# Copyright (c) 2002-2005 ActiveState Corporation. +# +# See the file "license.terms" for information on usage and redistribution +# of this file, and for a DISCLAIMER OF ALL WARRANTIES. + +#======================================================================== +# Add additional lines to handle any additional AC_SUBST cases that +# have been added in a customized configure script. +#======================================================================== + +#SAMPLE_NEW_VAR = @SAMPLE_NEW_VAR@ + +#======================================================================== +# Nothing of the variables below this line should need to be changed. +# Please check the TARGETS section below to make sure the make targets +# are correct. +#======================================================================== + +#======================================================================== +# The names of the source files is defined in the configure script. +# The object files are used for linking into the final library. +# This will be used when a dist target is added to the Makefile. +# It is not important to specify the directory, as long as it is the +# $(srcdir) or in the generic, win or unix subdirectory. +#======================================================================== + +PKG_SOURCES = @PKG_SOURCES@ +PKG_OBJECTS = @PKG_OBJECTS@ + +PKG_STUB_SOURCES = @PKG_STUB_SOURCES@ +PKG_STUB_OBJECTS = @PKG_STUB_OBJECTS@ + +#======================================================================== +# PKG_TCL_SOURCES identifies Tcl runtime files that are associated with +# this package that need to be installed, if any. +#======================================================================== + +PKG_TCL_SOURCES = @PKG_TCL_SOURCES@ + +#======================================================================== +# This is a list of public header files to be installed, if any. +#======================================================================== + +PKG_HEADERS = @PKG_HEADERS@ + +#======================================================================== +# "PKG_LIB_FILE" refers to the library (dynamic or static as per +# configuration options) composed of the named objects. +#======================================================================== + +PKG_LIB_FILE = @PKG_LIB_FILE@ +PKG_STUB_LIB_FILE = @PKG_STUB_LIB_FILE@ + +lib_BINARIES = $(PKG_LIB_FILE) +BINARIES = $(lib_BINARIES) + +SHELL = @SHELL@ + +srcdir = @srcdir@ +prefix = @prefix@ +exec_prefix = @exec_prefix@ + +bindir = @bindir@ +libdir = @libdir@ +includedir = @includedir@ +datarootdir = @datarootdir@ +datadir = @datadir@ +mandir = @mandir@ + +DESTDIR = + +PKG_DIR = $(PACKAGE_NAME)$(PACKAGE_VERSION) +pkgdatadir = $(datadir)/$(PKG_DIR) +pkglibdir = $(libdir)/$(PKG_DIR) +pkgincludedir = $(includedir)/$(PKG_DIR) + +top_builddir = . + +INSTALL_OPTIONS = +INSTALL = $(SHELL) $(srcdir)/tclconfig/install-sh -c ${INSTALL_OPTIONS} +INSTALL_DATA_DIR = ${INSTALL} -d -m 755 +INSTALL_PROGRAM = ${INSTALL} -m 555 +INSTALL_DATA = ${INSTALL} -m 444 +INSTALL_SCRIPT = ${INSTALL_PROGRAM} +INSTALL_LIBRARY = ${INSTALL_DATA} + +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +CC = @CC@ +CFLAGS_DEFAULT = @CFLAGS_DEFAULT@ +CFLAGS_WARNING = @CFLAGS_WARNING@ +EXEEXT = @EXEEXT@ +LDFLAGS_DEFAULT = @LDFLAGS_DEFAULT@ +MAKE_LIB = @MAKE_LIB@ +MAKE_SHARED_LIB = @MAKE_SHARED_LIB@ +MAKE_STATIC_LIB = @MAKE_STATIC_LIB@ +MAKE_STUB_LIB = @MAKE_STUB_LIB@ +OBJEXT = @OBJEXT@ +RANLIB = @RANLIB@ +RANLIB_STUB = @RANLIB_STUB@ +SHLIB_CFLAGS = @SHLIB_CFLAGS@ +SHLIB_LD = @SHLIB_LD@ +SHLIB_LD_LIBS = @SHLIB_LD_LIBS@ +STLIB_LD = @STLIB_LD@ +#TCL_DEFS = @TCL_DEFS@ +TCL_BIN_DIR = @TCL_BIN_DIR@ +TCL_SRC_DIR = @TCL_SRC_DIR@ +#TK_BIN_DIR = @TK_BIN_DIR@ +#TK_SRC_DIR = @TK_SRC_DIR@ + +# Not used, but retained for reference of what libs Tcl required +#TCL_LIBS = @TCL_LIBS@ + +#======================================================================== +# TCLLIBPATH seeds the auto_path in Tcl's init.tcl so we can test our +# package without installing. The other environment variables allow us +# to test against an uninstalled Tcl. Add special env vars that you +# require for testing here (like TCLX_LIBRARY). +#======================================================================== + +EXTRA_PATH = $(top_builddir):$(TCL_BIN_DIR) +#EXTRA_PATH = $(top_builddir):$(TCL_BIN_DIR):$(TK_BIN_DIR) +TCLLIBPATH = $(top_builddir) +TCLSH_ENV = TCL_LIBRARY=`@CYGPATH@ $(TCL_SRC_DIR)/library` +PKG_ENV = @LD_LIBRARY_PATH_VAR@="$(EXTRA_PATH):$(@LD_LIBRARY_PATH_VAR@)" \ + PATH="$(EXTRA_PATH):$(PATH)" \ + TCLLIBPATH="$(TCLLIBPATH)" + +TCLSH_PROG = @TCLSH_PROG@ +TCLSH = $(PKG_ENV) $(TCLSH_ENV) $(TCLSH_PROG) + +#WISH_ENV = TK_LIBRARY=`@CYGPATH@ $(TK_SRC_DIR)/library` +#WISH_PROG = @WISH_PROG@ +#WISH = $(PKG_ENV) $(TCLSH_ENV) $(WISH_ENV) $(WISH_PROG) + +SHARED_BUILD = @SHARED_BUILD@ + +INCLUDES = @PKG_INCLUDES@ @TCL_INCLUDES@ +#INCLUDES = @PKG_INCLUDES@ @TCL_INCLUDES@ @TK_INCLUDES@ @TK_XINCLUDES@ + +PKG_CFLAGS = @PKG_CFLAGS@ + +# TCL_DEFS is not strictly need here, but if you remove it, then you +# must make sure that configure.in checks for the necessary components +# that your library may use. TCL_DEFS can actually be a problem if +# you do not compile with a similar machine setup as the Tcl core was +# compiled with. +#DEFS = $(TCL_DEFS) @DEFS@ $(PKG_CFLAGS) +DEFS = @DEFS@ $(PKG_CFLAGS) + +# Move pkgIndex.tcl to 'BINARIES' var if it is generated in the Makefile +CONFIG_CLEAN_FILES = Makefile pkgIndex.tcl +CLEANFILES = @CLEANFILES@ + +CPPFLAGS = @CPPFLAGS@ +LIBS = @PKG_LIBS@ @LIBS@ +AR = @AR@ +CFLAGS = @CFLAGS@ +COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) + +.SUFFIXES: .c .$(OBJEXT) + +#======================================================================== +# Start of user-definable TARGETS section +#======================================================================== + +#======================================================================== +# TEA TARGETS. Please note that the "libraries:" target refers to platform +# independent files, and the "binaries:" target includes executable programs and +# platform-dependent libraries. Modify these targets so that they install +# the various pieces of your package. The make and install rules +# for the BINARIES that you specified above have already been done. +#======================================================================== + +all: binaries libraries doc + +#======================================================================== +# The binaries target builds executable programs, Windows .dll's, unix +# shared/static libraries, and any other platform-dependent files. +# The list of targets to build for "binaries:" is specified at the top +# of the Makefile, in the "BINARIES" variable. +#======================================================================== + +binaries: $(BINARIES) + +libraries: + +#======================================================================== +# Your doc target should differentiate from doc builds (by the developer) +# and doc installs (see install-doc), which just install the docs on the +# end user machine when building from source. +#======================================================================== + +doc: + @echo "If you have documentation to create, place the commands to" + @echo "build the docs in the 'doc:' target. For example:" + @echo " xml2nroff sample.xml > sample.n" + @echo " xml2html sample.xml > sample.html" + +install: all install-binaries install-libraries install-doc + +install-binaries: binaries install-lib-binaries install-bin-binaries + +#======================================================================== +# This rule installs platform-independent files, such as header files. +# The list=...; for p in $$list handles the empty list case x-platform. +#======================================================================== + +install-libraries: libraries + @$(INSTALL_DATA_DIR) $(DESTDIR)$(includedir) + @echo "Installing header files in $(DESTDIR)$(includedir)" + @list='$(PKG_HEADERS)'; for i in $$list; do \ + echo "Installing $(srcdir)/$$i" ; \ + $(INSTALL_DATA) $(srcdir)/$$i $(DESTDIR)$(includedir) ; \ + done; + +#======================================================================== +# Install documentation. Unix manpages should go in the $(mandir) +# directory. +#======================================================================== + +install-doc: doc + @$(INSTALL_DATA_DIR) $(DESTDIR)$(mandir)/mann + @echo "Installing documentation in $(DESTDIR)$(mandir)" + @list='$(srcdir)/doc/*.n'; for i in $$list; do \ + echo "Installing $$i"; \ + $(INSTALL_DATA) $$i $(DESTDIR)$(mandir)/mann ; \ + done + +test: binaries libraries + $(TCLSH) `@CYGPATH@ $(srcdir)/tests/all.tcl` $(TESTFLAGS) + +shell: binaries libraries + @$(TCLSH) $(SCRIPT) + +gdb: + $(TCLSH_ENV) gdb $(TCLSH_PROG) $(SCRIPT) + +VALGRINDARGS = --tool=memcheck --num-callers=8 --leak-resolution=high \ + --leak-check=yes --show-reachable=yes -v + +valgrind: binaries libraries + $(TCLSH_ENV) valgrind $(VALGRINDARGS) $(TCLSH_PROG) \ + `@CYGPATH@ $(srcdir)/tests/all.tcl` $(TESTFLAGS) + +valgrindshell: binaries libraries + $(TCLSH_ENV) valgrind $(VALGRINDARGS) $(TCLSH_PROG) $(SCRIPT) + +depend: + +#======================================================================== +# $(PKG_LIB_FILE) should be listed as part of the BINARIES variable +# mentioned above. That will ensure that this target is built when you +# run "make binaries". +# +# The $(PKG_OBJECTS) objects are created and linked into the final +# library. In most cases these object files will correspond to the +# source files above. +#======================================================================== + +$(PKG_LIB_FILE): $(PKG_OBJECTS) + -rm -f $(PKG_LIB_FILE) + ${MAKE_LIB} + $(RANLIB) $(PKG_LIB_FILE) + +$(PKG_STUB_LIB_FILE): $(PKG_STUB_OBJECTS) + -rm -f $(PKG_STUB_LIB_FILE) + ${MAKE_STUB_LIB} + $(RANLIB_STUB) $(PKG_STUB_LIB_FILE) + +#======================================================================== +# We need to enumerate the list of .c to .o lines here. +# +# In the following lines, $(srcdir) refers to the toplevel directory +# containing your extension. If your sources are in a subdirectory, +# you will have to modify the paths to reflect this: +# +# sample.$(OBJEXT): $(srcdir)/generic/sample.c +# $(COMPILE) -c `@CYGPATH@ $(srcdir)/generic/sample.c` -o $@ +# +# Setting the VPATH variable to a list of paths will cause the makefile +# to look into these paths when resolving .c to .obj dependencies. +# As necessary, add $(srcdir):$(srcdir)/compat:.... +#======================================================================== + +VPATH = $(srcdir):$(srcdir)/generic:$(srcdir)/unix:$(srcdir)/win:$(srcdir)/macosx + +.c.@OBJEXT@: + $(COMPILE) -c `@CYGPATH@ $<` -o $@ + +#======================================================================== +# Distribution creation +# You may need to tweak this target to make it work correctly. +#======================================================================== + +#COMPRESS = tar cvf $(PKG_DIR).tar $(PKG_DIR); compress $(PKG_DIR).tar +COMPRESS = tar zcvf $(PKG_DIR).tar.gz $(PKG_DIR) +DIST_ROOT = /tmp/dist +DIST_DIR = $(DIST_ROOT)/$(PKG_DIR) + +dist-clean: + rm -rf $(DIST_DIR) $(DIST_ROOT)/$(PKG_DIR).tar.* + +dist: dist-clean + mkdir -p $(DIST_DIR) + cp -p $(srcdir)/ChangeLog $(srcdir)/README* $(srcdir)/license* \ + $(srcdir)/aclocal.m4 $(srcdir)/configure $(srcdir)/*.in \ + $(DIST_DIR)/ + chmod 664 $(DIST_DIR)/Makefile.in $(DIST_DIR)/aclocal.m4 + chmod 775 $(DIST_DIR)/configure $(DIST_DIR)/configure.in + + for i in $(srcdir)/*.[ch]; do \ + if [ -f $$i ]; then \ + cp -p $$i $(DIST_DIR)/ ; \ + fi; \ + done; + + mkdir $(DIST_DIR)/tclconfig + cp $(srcdir)/tclconfig/install-sh $(srcdir)/tclconfig/tcl.m4 \ + $(DIST_DIR)/tclconfig/ + chmod 664 $(DIST_DIR)/tclconfig/tcl.m4 + chmod +x $(DIST_DIR)/tclconfig/install-sh + + list='demos doc generic library mac tests unix win'; \ + for p in $$list; do \ + if test -d $(srcdir)/$$p ; then \ + mkdir $(DIST_DIR)/$$p; \ + cp -p $(srcdir)/$$p/*.* $(DIST_DIR)/$$p/; \ + fi; \ + done + + (cd $(DIST_ROOT); $(COMPRESS);) + +#======================================================================== +# End of user-definable section +#======================================================================== + +#======================================================================== +# Don't modify the file to clean here. Instead, set the "CLEANFILES" +# variable in configure.in +#======================================================================== + +clean: + -test -z "$(BINARIES)" || rm -f $(BINARIES) + -rm -f *.$(OBJEXT) core *.core + -test -z "$(CLEANFILES)" || rm -f $(CLEANFILES) + +distclean: clean + -rm -f *.tab.c + -rm -f $(CONFIG_CLEAN_FILES) + -rm -f config.cache config.log config.status + +#======================================================================== +# Install binary object libraries. On Windows this includes both .dll and +# .lib files. Because the .lib files are not explicitly listed anywhere, +# we need to deduce their existence from the .dll file of the same name. +# Library files go into the lib directory. +# In addition, this will generate the pkgIndex.tcl +# file in the install location (assuming it can find a usable tclsh shell) +# +# You should not have to modify this target. +#======================================================================== + +install-lib-binaries: binaries + @$(INSTALL_DATA_DIR) $(DESTDIR)$(pkglibdir) + @list='$(lib_BINARIES)'; for p in $$list; do \ + if test -f $$p; then \ + echo " $(INSTALL_LIBRARY) $$p $(DESTDIR)$(pkglibdir)/$$p"; \ + $(INSTALL_LIBRARY) $$p $(DESTDIR)$(pkglibdir)/$$p; \ + stub=`echo $$p|sed -e "s/.*\(stub\).*/\1/"`; \ + if test "x$$stub" = "xstub"; then \ + echo " $(RANLIB_STUB) $(DESTDIR)$(pkglibdir)/$$p"; \ + $(RANLIB_STUB) $(DESTDIR)$(pkglibdir)/$$p; \ + else \ + echo " $(RANLIB) $(DESTDIR)$(pkglibdir)/$$p"; \ + $(RANLIB) $(DESTDIR)$(pkglibdir)/$$p; \ + fi; \ + ext=`echo $$p|sed -e "s/.*\.//"`; \ + if test "x$$ext" = "xdll"; then \ + lib=`basename $$p|sed -e 's/.[^.]*$$//'`.lib; \ + if test -f $$lib; then \ + echo " $(INSTALL_DATA) $$lib $(DESTDIR)$(pkglibdir)/$$lib"; \ + $(INSTALL_DATA) $$lib $(DESTDIR)$(pkglibdir)/$$lib; \ + fi; \ + fi; \ + fi; \ + done + @list='$(PKG_TCL_SOURCES)'; for p in $$list; do \ + if test -f $(srcdir)/$$p; then \ + destp=`basename $$p`; \ + echo " Install $$destp $(DESTDIR)$(pkglibdir)/$$destp"; \ + $(INSTALL_DATA) $(srcdir)/$$p $(DESTDIR)$(pkglibdir)/$$destp; \ + fi; \ + done + @if test "x$(SHARED_BUILD)" = "x1"; then \ + echo " Install pkgIndex.tcl $(DESTDIR)$(pkglibdir)"; \ + $(INSTALL_DATA) pkgIndex.tcl $(DESTDIR)$(pkglibdir); \ + fi + +#======================================================================== +# Install binary executables (e.g. .exe files and dependent .dll files) +# This is for files that must go in the bin directory (located next to +# wish and tclsh), like dependent .dll files on Windows. +# +# You should not have to modify this target, except to define bin_BINARIES +# above if necessary. +#======================================================================== + +install-bin-binaries: binaries + @$(INSTALL_DATA_DIR) $(DESTDIR)$(bindir) + @list='$(bin_BINARIES)'; for p in $$list; do \ + if test -f $$p; then \ + echo " $(INSTALL_PROGRAM) $$p $(DESTDIR)$(bindir)/$$p"; \ + $(INSTALL_PROGRAM) $$p $(DESTDIR)$(bindir)/$$p; \ + fi; \ + done + +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + cd $(top_builddir) \ + && CONFIG_FILES=$@ CONFIG_HEADERS= $(SHELL) ./config.status + +uninstall-binaries: + list='$(lib_BINARIES)'; for p in $$list; do \ + rm -f $(DESTDIR)$(pkglibdir)/$$p; \ + done + list='$(PKG_TCL_SOURCES)'; for p in $$list; do \ + p=`basename $$p`; \ + rm -f $(DESTDIR)$(pkglibdir)/$$p; \ + done + list='$(bin_BINARIES)'; for p in $$list; do \ + rm -f $(DESTDIR)$(bindir)/$$p; \ + done + +.PHONY: all binaries clean depend distclean doc install libraries test + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: ADDED extensions/schemadtx/aclocal.m4 Index: extensions/schemadtx/aclocal.m4 ================================================================== --- /dev/null +++ extensions/schemadtx/aclocal.m4 @@ -0,0 +1,9 @@ +# +# Include the TEA standard macro set +# +builtin(include,../../tclconfig/tcl.m4) + +# +# Add here whatever m4 macros you want to define for your package +# +builtin(include,../../tdom.m4) ADDED extensions/schemadtx/configure Index: extensions/schemadtx/configure ================================================================== --- /dev/null +++ extensions/schemadtx/configure @@ -0,0 +1,9448 @@ +#! /bin/sh +# Guess values for system-dependent variables and create Makefiles. +# Generated by GNU Autoconf 2.69 for schemadtx 1.0. +# +# +# Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc. +# +# +# This configure script is free software; the Free Software Foundation +# gives unlimited permission to copy, distribute and modify it. +## -------------------- ## +## M4sh Initialization. ## +## -------------------- ## + +# Be more Bourne compatible +DUALCASE=1; export DUALCASE # for MKS sh +if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then : + emulate sh + NULLCMD=: + # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which + # is contrary to our usage. Disable this feature. + alias -g '${1+"$@"}'='"$@"' + setopt NO_GLOB_SUBST +else + case `(set -o) 2>/dev/null` in #( + *posix*) : + set -o posix ;; #( + *) : + ;; +esac +fi + + +as_nl=' +' +export as_nl +# Printing a long string crashes Solaris 7 /usr/bin/printf. +as_echo='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\' +as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo +as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo$as_echo +# Prefer a ksh shell builtin over an external printf program on Solaris, +# but without wasting forks for bash or zsh. +if test -z "$BASH_VERSION$ZSH_VERSION" \ + && (test "X`print -r -- $as_echo`" = "X$as_echo") 2>/dev/null; then + as_echo='print -r --' + as_echo_n='print -rn --' +elif (test "X`printf %s $as_echo`" = "X$as_echo") 2>/dev/null; then + as_echo='printf %s\n' + as_echo_n='printf %s' +else + if test "X`(/usr/ucb/echo -n -n $as_echo) 2>/dev/null`" = "X-n $as_echo"; then + as_echo_body='eval /usr/ucb/echo -n "$1$as_nl"' + as_echo_n='/usr/ucb/echo -n' + else + as_echo_body='eval expr "X$1" : "X\\(.*\\)"' + as_echo_n_body='eval + arg=$1; + case $arg in #( + *"$as_nl"*) + expr "X$arg" : "X\\(.*\\)$as_nl"; + arg=`expr "X$arg" : ".*$as_nl\\(.*\\)"`;; + esac; + expr "X$arg" : "X\\(.*\\)" | tr -d "$as_nl" + ' + export as_echo_n_body + as_echo_n='sh -c $as_echo_n_body as_echo' + fi + export as_echo_body + as_echo='sh -c $as_echo_body as_echo' +fi + +# The user is always right. +if test "${PATH_SEPARATOR+set}" != set; then + PATH_SEPARATOR=: + (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && { + (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 || + PATH_SEPARATOR=';' + } +fi + + +# IFS +# We need space, tab and new line, in precisely that order. Quoting is +# there to prevent editors from complaining about space-tab. +# (If _AS_PATH_WALK were called with IFS unset, it would disable word +# splitting by setting IFS to empty value.) +IFS=" "" $as_nl" + +# Find who we are. Look in the path if we contain no directory separator. +as_myself= +case $0 in #(( + *[\\/]* ) as_myself=$0 ;; + *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break + done +IFS=$as_save_IFS + + ;; +esac +# We did not find ourselves, most probably we were run as `sh COMMAND' +# in which case we are not to be found in the path. +if test "x$as_myself" = x; then + as_myself=$0 +fi +if test ! -f "$as_myself"; then + $as_echo "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2 + exit 1 +fi + +# Unset variables that we do not need and which cause bugs (e.g. in +# pre-3.0 UWIN ksh). But do not cause bugs in bash 2.01; the "|| exit 1" +# suppresses any "Segmentation fault" message there. '((' could +# trigger a bug in pdksh 5.2.14. +for as_var in BASH_ENV ENV MAIL MAILPATH +do eval test x\${$as_var+set} = xset \ + && ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || : +done +PS1='$ ' +PS2='> ' +PS4='+ ' + +# NLS nuisances. +LC_ALL=C +export LC_ALL +LANGUAGE=C +export LANGUAGE + +# CDPATH. +(unset CDPATH) >/dev/null 2>&1 && unset CDPATH + +# Use a proper internal environment variable to ensure we don't fall + # into an infinite loop, continuously re-executing ourselves. + if test x"${_as_can_reexec}" != xno && test "x$CONFIG_SHELL" != x; then + _as_can_reexec=no; export _as_can_reexec; + # We cannot yet assume a decent shell, so we have to provide a +# neutralization value for shells without unset; and this also +# works around shells that cannot unset nonexistent variables. +# Preserve -v and -x to the replacement shell. +BASH_ENV=/dev/null +ENV=/dev/null +(unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV +case $- in # (((( + *v*x* | *x*v* ) as_opts=-vx ;; + *v* ) as_opts=-v ;; + *x* ) as_opts=-x ;; + * ) as_opts= ;; +esac +exec $CONFIG_SHELL $as_opts "$as_myself" ${1+"$@"} +# Admittedly, this is quite paranoid, since all the known shells bail +# out after a failed `exec'. +$as_echo "$0: could not re-execute with $CONFIG_SHELL" >&2 +as_fn_exit 255 + fi + # We don't want this to propagate to other subprocesses. + { _as_can_reexec=; unset _as_can_reexec;} +if test "x$CONFIG_SHELL" = x; then + as_bourne_compatible="if test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then : + emulate sh + NULLCMD=: + # Pre-4.2 versions of Zsh do word splitting on \${1+\"\$@\"}, which + # is contrary to our usage. Disable this feature. + alias -g '\${1+\"\$@\"}'='\"\$@\"' + setopt NO_GLOB_SUBST +else + case \`(set -o) 2>/dev/null\` in #( + *posix*) : + set -o posix ;; #( + *) : + ;; +esac +fi +" + as_required="as_fn_return () { (exit \$1); } +as_fn_success () { as_fn_return 0; } +as_fn_failure () { as_fn_return 1; } +as_fn_ret_success () { return 0; } +as_fn_ret_failure () { return 1; } + +exitcode=0 +as_fn_success || { exitcode=1; echo as_fn_success failed.; } +as_fn_failure && { exitcode=1; echo as_fn_failure succeeded.; } +as_fn_ret_success || { exitcode=1; echo as_fn_ret_success failed.; } +as_fn_ret_failure && { exitcode=1; echo as_fn_ret_failure succeeded.; } +if ( set x; as_fn_ret_success y && test x = \"\$1\" ); then : + +else + exitcode=1; echo positional parameters were not saved. +fi +test x\$exitcode = x0 || exit 1 +test -x / || exit 1" + as_suggested=" as_lineno_1=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_1a=\$LINENO + as_lineno_2=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_2a=\$LINENO + eval 'test \"x\$as_lineno_1'\$as_run'\" != \"x\$as_lineno_2'\$as_run'\" && + test \"x\`expr \$as_lineno_1'\$as_run' + 1\`\" = \"x\$as_lineno_2'\$as_run'\"' || exit 1 +test \$(( 1 + 1 )) = 2 || exit 1" + if (eval "$as_required") 2>/dev/null; then : + as_have_required=yes +else + as_have_required=no +fi + if test x$as_have_required = xyes && (eval "$as_suggested") 2>/dev/null; then : + +else + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +as_found=false +for as_dir in /bin$PATH_SEPARATOR/usr/bin$PATH_SEPARATOR$PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + as_found=: + case $as_dir in #( + /*) + for as_base in sh bash ksh sh5; do + # Try only shells that exist, to save several forks. + as_shell=$as_dir/$as_base + if { test -f "$as_shell" || test -f "$as_shell.exe"; } && + { $as_echo "$as_bourne_compatible""$as_required" | as_run=a "$as_shell"; } 2>/dev/null; then : + CONFIG_SHELL=$as_shell as_have_required=yes + if { $as_echo "$as_bourne_compatible""$as_suggested" | as_run=a "$as_shell"; } 2>/dev/null; then : + break 2 +fi +fi + done;; + esac + as_found=false +done +$as_found || { if { test -f "$SHELL" || test -f "$SHELL.exe"; } && + { $as_echo "$as_bourne_compatible""$as_required" | as_run=a "$SHELL"; } 2>/dev/null; then : + CONFIG_SHELL=$SHELL as_have_required=yes +fi; } +IFS=$as_save_IFS + + + if test "x$CONFIG_SHELL" != x; then : + export CONFIG_SHELL + # We cannot yet assume a decent shell, so we have to provide a +# neutralization value for shells without unset; and this also +# works around shells that cannot unset nonexistent variables. +# Preserve -v and -x to the replacement shell. +BASH_ENV=/dev/null +ENV=/dev/null +(unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV +case $- in # (((( + *v*x* | *x*v* ) as_opts=-vx ;; + *v* ) as_opts=-v ;; + *x* ) as_opts=-x ;; + * ) as_opts= ;; +esac +exec $CONFIG_SHELL $as_opts "$as_myself" ${1+"$@"} +# Admittedly, this is quite paranoid, since all the known shells bail +# out after a failed `exec'. +$as_echo "$0: could not re-execute with $CONFIG_SHELL" >&2 +exit 255 +fi + + if test x$as_have_required = xno; then : + $as_echo "$0: This script requires a shell more modern than all" + $as_echo "$0: the shells that I found on your system." + if test x${ZSH_VERSION+set} = xset ; then + $as_echo "$0: In particular, zsh $ZSH_VERSION has bugs and should" + $as_echo "$0: be upgraded to zsh 4.3.4 or later." + else + $as_echo "$0: Please tell bug-autoconf@gnu.org about your system, +$0: including any error possibly output before this +$0: message. Then install a modern shell, or manually run +$0: the script under such a shell if you do have one." + fi + exit 1 +fi +fi +fi +SHELL=${CONFIG_SHELL-/bin/sh} +export SHELL +# Unset more variables known to interfere with behavior of common tools. +CLICOLOR_FORCE= GREP_OPTIONS= +unset CLICOLOR_FORCE GREP_OPTIONS + +## --------------------- ## +## M4sh Shell Functions. ## +## --------------------- ## +# as_fn_unset VAR +# --------------- +# Portably unset VAR. +as_fn_unset () +{ + { eval $1=; unset $1;} +} +as_unset=as_fn_unset + +# as_fn_set_status STATUS +# ----------------------- +# Set $? to STATUS, without forking. +as_fn_set_status () +{ + return $1 +} # as_fn_set_status + +# as_fn_exit STATUS +# ----------------- +# Exit the shell with STATUS, even in a "trap 0" or "set -e" context. +as_fn_exit () +{ + set +e + as_fn_set_status $1 + exit $1 +} # as_fn_exit + +# as_fn_mkdir_p +# ------------- +# Create "$as_dir" as a directory, including parents if necessary. +as_fn_mkdir_p () +{ + + case $as_dir in #( + -*) as_dir=./$as_dir;; + esac + test -d "$as_dir" || eval $as_mkdir_p || { + as_dirs= + while :; do + case $as_dir in #( + *\'*) as_qdir=`$as_echo "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'( + *) as_qdir=$as_dir;; + esac + as_dirs="'$as_qdir' $as_dirs" + as_dir=`$as_dirname -- "$as_dir" || +$as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ + X"$as_dir" : 'X\(//\)[^/]' \| \ + X"$as_dir" : 'X\(//\)$' \| \ + X"$as_dir" : 'X\(/\)' \| . 2>/dev/null || +$as_echo X"$as_dir" | + sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ + s//\1/ + q + } + /^X\(\/\/\)[^/].*/{ + s//\1/ + q + } + /^X\(\/\/\)$/{ + s//\1/ + q + } + /^X\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` + test -d "$as_dir" && break + done + test -z "$as_dirs" || eval "mkdir $as_dirs" + } || test -d "$as_dir" || as_fn_error $? "cannot create directory $as_dir" + + +} # as_fn_mkdir_p + +# as_fn_executable_p FILE +# ----------------------- +# Test if FILE is an executable regular file. +as_fn_executable_p () +{ + test -f "$1" && test -x "$1" +} # as_fn_executable_p +# as_fn_append VAR VALUE +# ---------------------- +# Append the text in VALUE to the end of the definition contained in VAR. Take +# advantage of any shell optimizations that allow amortized linear growth over +# repeated appends, instead of the typical quadratic growth present in naive +# implementations. +if (eval "as_var=1; as_var+=2; test x\$as_var = x12") 2>/dev/null; then : + eval 'as_fn_append () + { + eval $1+=\$2 + }' +else + as_fn_append () + { + eval $1=\$$1\$2 + } +fi # as_fn_append + +# as_fn_arith ARG... +# ------------------ +# Perform arithmetic evaluation on the ARGs, and store the result in the +# global $as_val. Take advantage of shells that can avoid forks. The arguments +# must be portable across $(()) and expr. +if (eval "test \$(( 1 + 1 )) = 2") 2>/dev/null; then : + eval 'as_fn_arith () + { + as_val=$(( $* )) + }' +else + as_fn_arith () + { + as_val=`expr "$@" || test $? -eq 1` + } +fi # as_fn_arith + + +# as_fn_error STATUS ERROR [LINENO LOG_FD] +# ---------------------------------------- +# Output "`basename $0`: error: ERROR" to stderr. If LINENO and LOG_FD are +# provided, also output the error to LOG_FD, referencing LINENO. Then exit the +# script with STATUS, using 1 if that was 0. +as_fn_error () +{ + as_status=$1; test $as_status -eq 0 && as_status=1 + if test "$4"; then + as_lineno=${as_lineno-"$3"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + $as_echo "$as_me:${as_lineno-$LINENO}: error: $2" >&$4 + fi + $as_echo "$as_me: error: $2" >&2 + as_fn_exit $as_status +} # as_fn_error + +if expr a : '\(a\)' >/dev/null 2>&1 && + test "X`expr 00001 : '.*\(...\)'`" = X001; then + as_expr=expr +else + as_expr=false +fi + +if (basename -- /) >/dev/null 2>&1 && test "X`basename -- / 2>&1`" = "X/"; then + as_basename=basename +else + as_basename=false +fi + +if (as_dir=`dirname -- /` && test "X$as_dir" = X/) >/dev/null 2>&1; then + as_dirname=dirname +else + as_dirname=false +fi + +as_me=`$as_basename -- "$0" || +$as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \ + X"$0" : 'X\(//\)$' \| \ + X"$0" : 'X\(/\)' \| . 2>/dev/null || +$as_echo X/"$0" | + sed '/^.*\/\([^/][^/]*\)\/*$/{ + s//\1/ + q + } + /^X\/\(\/\/\)$/{ + s//\1/ + q + } + /^X\/\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` + +# Avoid depending upon Character Ranges. +as_cr_letters='abcdefghijklmnopqrstuvwxyz' +as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ' +as_cr_Letters=$as_cr_letters$as_cr_LETTERS +as_cr_digits='0123456789' +as_cr_alnum=$as_cr_Letters$as_cr_digits + + + as_lineno_1=$LINENO as_lineno_1a=$LINENO + as_lineno_2=$LINENO as_lineno_2a=$LINENO + eval 'test "x$as_lineno_1'$as_run'" != "x$as_lineno_2'$as_run'" && + test "x`expr $as_lineno_1'$as_run' + 1`" = "x$as_lineno_2'$as_run'"' || { + # Blame Lee E. McMahon (1931-1989) for sed's syntax. :-) + sed -n ' + p + /[$]LINENO/= + ' <$as_myself | + sed ' + s/[$]LINENO.*/&-/ + t lineno + b + :lineno + N + :loop + s/[$]LINENO\([^'$as_cr_alnum'_].*\n\)\(.*\)/\2\1\2/ + t loop + s/-\n.*// + ' >$as_me.lineno && + chmod +x "$as_me.lineno" || + { $as_echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2; as_fn_exit 1; } + + # If we had to re-execute with $CONFIG_SHELL, we're ensured to have + # already done that, so ensure we don't try to do so again and fall + # in an infinite loop. This has already happened in practice. + _as_can_reexec=no; export _as_can_reexec + # Don't try to exec as it changes $[0], causing all sort of problems + # (the dirname of $[0] is not the place where we might find the + # original and so on. Autoconf is especially sensitive to this). + . "./$as_me.lineno" + # Exit status is that of the last command. + exit +} + +ECHO_C= ECHO_N= ECHO_T= +case `echo -n x` in #((((( +-n*) + case `echo 'xy\c'` in + *c*) ECHO_T=' ';; # ECHO_T is single tab character. + xy) ECHO_C='\c';; + *) echo `echo ksh88 bug on AIX 6.1` > /dev/null + ECHO_T=' ';; + esac;; +*) + ECHO_N='-n';; +esac + +rm -f conf$$ conf$$.exe conf$$.file +if test -d conf$$.dir; then + rm -f conf$$.dir/conf$$.file +else + rm -f conf$$.dir + mkdir conf$$.dir 2>/dev/null +fi +if (echo >conf$$.file) 2>/dev/null; then + if ln -s conf$$.file conf$$ 2>/dev/null; then + as_ln_s='ln -s' + # ... but there are two gotchas: + # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail. + # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable. + # In both cases, we have to default to `cp -pR'. + ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe || + as_ln_s='cp -pR' + elif ln conf$$.file conf$$ 2>/dev/null; then + as_ln_s=ln + else + as_ln_s='cp -pR' + fi +else + as_ln_s='cp -pR' +fi +rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file +rmdir conf$$.dir 2>/dev/null + +if mkdir -p . 2>/dev/null; then + as_mkdir_p='mkdir -p "$as_dir"' +else + test -d ./-p && rmdir ./-p + as_mkdir_p=false +fi + +as_test_x='test -x' +as_executable_p=as_fn_executable_p + +# Sed expression to map a string onto a valid CPP name. +as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'" + +# Sed expression to map a string onto a valid variable name. +as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'" + + +test -n "$DJDIR" || exec 7<&0 &1 + +# Name of the host. +# hostname on some systems (SVR3.2, old GNU/Linux) returns a bogus exit status, +# so uname gets run too. +ac_hostname=`(hostname || uname -n) 2>/dev/null | sed 1q` + +# +# Initializations. +# +ac_default_prefix=/usr/local +ac_clean_files= +ac_config_libobj_dir=. +LIBOBJS= +cross_compiling=no +subdirs= +MFLAGS= +MAKEFLAGS= + +# Identity of this package. +PACKAGE_NAME='schemadtx' +PACKAGE_TARNAME='schemadtx' +PACKAGE_VERSION='1.0' +PACKAGE_STRING='schemadtx 1.0' +PACKAGE_BUGREPORT='' +PACKAGE_URL='' + +# Factoring default headers for most tests. +ac_includes_default="\ +#include +#ifdef HAVE_SYS_TYPES_H +# include +#endif +#ifdef HAVE_SYS_STAT_H +# include +#endif +#ifdef STDC_HEADERS +# include +# include +#else +# ifdef HAVE_STDLIB_H +# include +# endif +#endif +#ifdef HAVE_STRING_H +# if !defined STDC_HEADERS && defined HAVE_MEMORY_H +# include +# endif +# include +#endif +#ifdef HAVE_STRINGS_H +# include +#endif +#ifdef HAVE_INTTYPES_H +# include +#endif +#ifdef HAVE_STDINT_H +# include +#endif +#ifdef HAVE_UNISTD_H +# include +#endif" + +ac_subst_vars='LTLIBOBJS +LIBOBJS +TCLSH_PROG +VC_MANIFEST_EMBED_EXE +VC_MANIFEST_EMBED_DLL +RANLIB_STUB +MAKE_STUB_LIB +MAKE_STATIC_LIB +MAKE_SHARED_LIB +MAKE_LIB +TCL_DBGX +LDFLAGS_DEFAULT +CFLAGS_DEFAULT +LD_LIBRARY_PATH_VAR +SHLIB_CFLAGS +SHLIB_LD_LIBS +SHLIB_LD +STLIB_LD +CFLAGS_WARNING +CFLAGS_OPTIMIZE +CFLAGS_DEBUG +RC +CELIB_DIR +AR +STUBS_BUILD +SHARED_BUILD +TCL_THREADS +TCL_INCLUDES +PKG_OBJECTS +PKG_SOURCES +TDOM_SRC_DIR +TDOM_STUB_LIB_SPEC +TDOM_VERSION +EGREP +GREP +RANLIB +SET_MAKE +CPP +TCL_SHLIB_LD_LIBS +TCL_LD_FLAGS +TCL_EXTRA_CFLAGS +TCL_DEFS +TCL_LIBS +CLEANFILES +OBJEXT +ac_ct_CC +CPPFLAGS +LDFLAGS +CFLAGS +CC +TCL_STUB_LIB_SPEC +TCL_STUB_LIB_FLAG +TCL_STUB_LIB_FILE +TCL_LIB_SPEC +TCL_LIB_FLAG +TCL_LIB_FILE +TCL_SRC_DIR +TCL_BIN_DIR +TCL_PATCH_LEVEL +TCL_VERSION +INSTALL_LIBRARY +INSTALL_SCRIPT +INSTALL_PROGRAM +INSTALL_DATA +INSTALL_DATA_DIR +INSTALL +PKG_CFLAGS +PKG_LIBS +PKG_INCLUDES +PKG_HEADERS +PKG_TCL_SOURCES +PKG_STUB_OBJECTS +PKG_STUB_SOURCES +PKG_STUB_LIB_FILE +PKG_LIB_FILE +EXEEXT +CYGPATH +target_alias +host_alias +build_alias +LIBS +ECHO_T +ECHO_N +ECHO_C +DEFS +mandir +localedir +libdir +psdir +pdfdir +dvidir +htmldir +infodir +docdir +oldincludedir +includedir +runstatedir +localstatedir +sharedstatedir +sysconfdir +datadir +datarootdir +libexecdir +sbindir +bindir +program_transform_name +prefix +exec_prefix +PACKAGE_URL +PACKAGE_BUGREPORT +PACKAGE_STRING +PACKAGE_VERSION +PACKAGE_TARNAME +PACKAGE_NAME +PATH_SEPARATOR +SHELL' +ac_subst_files='' +ac_user_opts=' +enable_option_checking +with_tcl +with_tdom +with_tclinclude +enable_threads +enable_shared +enable_stubs +enable_64bit +enable_64bit_vis +enable_rpath +enable_wince +with_celib +enable_symbols +' + ac_precious_vars='build_alias +host_alias +target_alias +CC +CFLAGS +LDFLAGS +LIBS +CPPFLAGS +CPP' + + +# Initialize some variables set by options. +ac_init_help= +ac_init_version=false +ac_unrecognized_opts= +ac_unrecognized_sep= +# The variables have the same names as the options, with +# dashes changed to underlines. +cache_file=/dev/null +exec_prefix=NONE +no_create= +no_recursion= +prefix=NONE +program_prefix=NONE +program_suffix=NONE +program_transform_name=s,x,x, +silent= +site= +srcdir= +verbose= +x_includes=NONE +x_libraries=NONE + +# Installation directory options. +# These are left unexpanded so users can "make install exec_prefix=/foo" +# and all the variables that are supposed to be based on exec_prefix +# by default will actually change. +# Use braces instead of parens because sh, perl, etc. also accept them. +# (The list follows the same order as the GNU Coding Standards.) +bindir='${exec_prefix}/bin' +sbindir='${exec_prefix}/sbin' +libexecdir='${exec_prefix}/libexec' +datarootdir='${prefix}/share' +datadir='${datarootdir}' +sysconfdir='${prefix}/etc' +sharedstatedir='${prefix}/com' +localstatedir='${prefix}/var' +runstatedir='${localstatedir}/run' +includedir='${prefix}/include' +oldincludedir='/usr/include' +docdir='${datarootdir}/doc/${PACKAGE_TARNAME}' +infodir='${datarootdir}/info' +htmldir='${docdir}' +dvidir='${docdir}' +pdfdir='${docdir}' +psdir='${docdir}' +libdir='${exec_prefix}/lib' +localedir='${datarootdir}/locale' +mandir='${datarootdir}/man' + +ac_prev= +ac_dashdash= +for ac_option +do + # If the previous option needs an argument, assign it. + if test -n "$ac_prev"; then + eval $ac_prev=\$ac_option + ac_prev= + continue + fi + + case $ac_option in + *=?*) ac_optarg=`expr "X$ac_option" : '[^=]*=\(.*\)'` ;; + *=) ac_optarg= ;; + *) ac_optarg=yes ;; + esac + + # Accept the important Cygnus configure options, so we can diagnose typos. + + case $ac_dashdash$ac_option in + --) + ac_dashdash=yes ;; + + -bindir | --bindir | --bindi | --bind | --bin | --bi) + ac_prev=bindir ;; + -bindir=* | --bindir=* | --bindi=* | --bind=* | --bin=* | --bi=*) + bindir=$ac_optarg ;; + + -build | --build | --buil | --bui | --bu) + ac_prev=build_alias ;; + -build=* | --build=* | --buil=* | --bui=* | --bu=*) + build_alias=$ac_optarg ;; + + -cache-file | --cache-file | --cache-fil | --cache-fi \ + | --cache-f | --cache- | --cache | --cach | --cac | --ca | --c) + ac_prev=cache_file ;; + -cache-file=* | --cache-file=* | --cache-fil=* | --cache-fi=* \ + | --cache-f=* | --cache-=* | --cache=* | --cach=* | --cac=* | --ca=* | --c=*) + cache_file=$ac_optarg ;; + + --config-cache | -C) + cache_file=config.cache ;; + + -datadir | --datadir | --datadi | --datad) + ac_prev=datadir ;; + -datadir=* | --datadir=* | --datadi=* | --datad=*) + datadir=$ac_optarg ;; + + -datarootdir | --datarootdir | --datarootdi | --datarootd | --dataroot \ + | --dataroo | --dataro | --datar) + ac_prev=datarootdir ;; + -datarootdir=* | --datarootdir=* | --datarootdi=* | --datarootd=* \ + | --dataroot=* | --dataroo=* | --dataro=* | --datar=*) + datarootdir=$ac_optarg ;; + + -disable-* | --disable-*) + ac_useropt=`expr "x$ac_option" : 'x-*disable-\(.*\)'` + # Reject names that are not valid shell variable names. + expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && + as_fn_error $? "invalid feature name: $ac_useropt" + ac_useropt_orig=$ac_useropt + ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` + case $ac_user_opts in + *" +"enable_$ac_useropt" +"*) ;; + *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--disable-$ac_useropt_orig" + ac_unrecognized_sep=', ';; + esac + eval enable_$ac_useropt=no ;; + + -docdir | --docdir | --docdi | --doc | --do) + ac_prev=docdir ;; + -docdir=* | --docdir=* | --docdi=* | --doc=* | --do=*) + docdir=$ac_optarg ;; + + -dvidir | --dvidir | --dvidi | --dvid | --dvi | --dv) + ac_prev=dvidir ;; + -dvidir=* | --dvidir=* | --dvidi=* | --dvid=* | --dvi=* | --dv=*) + dvidir=$ac_optarg ;; + + -enable-* | --enable-*) + ac_useropt=`expr "x$ac_option" : 'x-*enable-\([^=]*\)'` + # Reject names that are not valid shell variable names. + expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && + as_fn_error $? "invalid feature name: $ac_useropt" + ac_useropt_orig=$ac_useropt + ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` + case $ac_user_opts in + *" +"enable_$ac_useropt" +"*) ;; + *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--enable-$ac_useropt_orig" + ac_unrecognized_sep=', ';; + esac + eval enable_$ac_useropt=\$ac_optarg ;; + + -exec-prefix | --exec_prefix | --exec-prefix | --exec-prefi \ + | --exec-pref | --exec-pre | --exec-pr | --exec-p | --exec- \ + | --exec | --exe | --ex) + ac_prev=exec_prefix ;; + -exec-prefix=* | --exec_prefix=* | --exec-prefix=* | --exec-prefi=* \ + | --exec-pref=* | --exec-pre=* | --exec-pr=* | --exec-p=* | --exec-=* \ + | --exec=* | --exe=* | --ex=*) + exec_prefix=$ac_optarg ;; + + -gas | --gas | --ga | --g) + # Obsolete; use --with-gas. + with_gas=yes ;; + + -help | --help | --hel | --he | -h) + ac_init_help=long ;; + -help=r* | --help=r* | --hel=r* | --he=r* | -hr*) + ac_init_help=recursive ;; + -help=s* | --help=s* | --hel=s* | --he=s* | -hs*) + ac_init_help=short ;; + + -host | --host | --hos | --ho) + ac_prev=host_alias ;; + -host=* | --host=* | --hos=* | --ho=*) + host_alias=$ac_optarg ;; + + -htmldir | --htmldir | --htmldi | --htmld | --html | --htm | --ht) + ac_prev=htmldir ;; + -htmldir=* | --htmldir=* | --htmldi=* | --htmld=* | --html=* | --htm=* \ + | --ht=*) + htmldir=$ac_optarg ;; + + -includedir | --includedir | --includedi | --included | --include \ + | --includ | --inclu | --incl | --inc) + ac_prev=includedir ;; + -includedir=* | --includedir=* | --includedi=* | --included=* | --include=* \ + | --includ=* | --inclu=* | --incl=* | --inc=*) + includedir=$ac_optarg ;; + + -infodir | --infodir | --infodi | --infod | --info | --inf) + ac_prev=infodir ;; + -infodir=* | --infodir=* | --infodi=* | --infod=* | --info=* | --inf=*) + infodir=$ac_optarg ;; + + -libdir | --libdir | --libdi | --libd) + ac_prev=libdir ;; + -libdir=* | --libdir=* | --libdi=* | --libd=*) + libdir=$ac_optarg ;; + + -libexecdir | --libexecdir | --libexecdi | --libexecd | --libexec \ + | --libexe | --libex | --libe) + ac_prev=libexecdir ;; + -libexecdir=* | --libexecdir=* | --libexecdi=* | --libexecd=* | --libexec=* \ + | --libexe=* | --libex=* | --libe=*) + libexecdir=$ac_optarg ;; + + -localedir | --localedir | --localedi | --localed | --locale) + ac_prev=localedir ;; + -localedir=* | --localedir=* | --localedi=* | --localed=* | --locale=*) + localedir=$ac_optarg ;; + + -localstatedir | --localstatedir | --localstatedi | --localstated \ + | --localstate | --localstat | --localsta | --localst | --locals) + ac_prev=localstatedir ;; + -localstatedir=* | --localstatedir=* | --localstatedi=* | --localstated=* \ + | --localstate=* | --localstat=* | --localsta=* | --localst=* | --locals=*) + localstatedir=$ac_optarg ;; + + -mandir | --mandir | --mandi | --mand | --man | --ma | --m) + ac_prev=mandir ;; + -mandir=* | --mandir=* | --mandi=* | --mand=* | --man=* | --ma=* | --m=*) + mandir=$ac_optarg ;; + + -nfp | --nfp | --nf) + # Obsolete; use --without-fp. + with_fp=no ;; + + -no-create | --no-create | --no-creat | --no-crea | --no-cre \ + | --no-cr | --no-c | -n) + no_create=yes ;; + + -no-recursion | --no-recursion | --no-recursio | --no-recursi \ + | --no-recurs | --no-recur | --no-recu | --no-rec | --no-re | --no-r) + no_recursion=yes ;; + + -oldincludedir | --oldincludedir | --oldincludedi | --oldincluded \ + | --oldinclude | --oldinclud | --oldinclu | --oldincl | --oldinc \ + | --oldin | --oldi | --old | --ol | --o) + ac_prev=oldincludedir ;; + -oldincludedir=* | --oldincludedir=* | --oldincludedi=* | --oldincluded=* \ + | --oldinclude=* | --oldinclud=* | --oldinclu=* | --oldincl=* | --oldinc=* \ + | --oldin=* | --oldi=* | --old=* | --ol=* | --o=*) + oldincludedir=$ac_optarg ;; + + -prefix | --prefix | --prefi | --pref | --pre | --pr | --p) + ac_prev=prefix ;; + -prefix=* | --prefix=* | --prefi=* | --pref=* | --pre=* | --pr=* | --p=*) + prefix=$ac_optarg ;; + + -program-prefix | --program-prefix | --program-prefi | --program-pref \ + | --program-pre | --program-pr | --program-p) + ac_prev=program_prefix ;; + -program-prefix=* | --program-prefix=* | --program-prefi=* \ + | --program-pref=* | --program-pre=* | --program-pr=* | --program-p=*) + program_prefix=$ac_optarg ;; + + -program-suffix | --program-suffix | --program-suffi | --program-suff \ + | --program-suf | --program-su | --program-s) + ac_prev=program_suffix ;; + -program-suffix=* | --program-suffix=* | --program-suffi=* \ + | --program-suff=* | --program-suf=* | --program-su=* | --program-s=*) + program_suffix=$ac_optarg ;; + + -program-transform-name | --program-transform-name \ + | --program-transform-nam | --program-transform-na \ + | --program-transform-n | --program-transform- \ + | --program-transform | --program-transfor \ + | --program-transfo | --program-transf \ + | --program-trans | --program-tran \ + | --progr-tra | --program-tr | --program-t) + ac_prev=program_transform_name ;; + -program-transform-name=* | --program-transform-name=* \ + | --program-transform-nam=* | --program-transform-na=* \ + | --program-transform-n=* | --program-transform-=* \ + | --program-transform=* | --program-transfor=* \ + | --program-transfo=* | --program-transf=* \ + | --program-trans=* | --program-tran=* \ + | --progr-tra=* | --program-tr=* | --program-t=*) + program_transform_name=$ac_optarg ;; + + -pdfdir | --pdfdir | --pdfdi | --pdfd | --pdf | --pd) + ac_prev=pdfdir ;; + -pdfdir=* | --pdfdir=* | --pdfdi=* | --pdfd=* | --pdf=* | --pd=*) + pdfdir=$ac_optarg ;; + + -psdir | --psdir | --psdi | --psd | --ps) + ac_prev=psdir ;; + -psdir=* | --psdir=* | --psdi=* | --psd=* | --ps=*) + psdir=$ac_optarg ;; + + -q | -quiet | --quiet | --quie | --qui | --qu | --q \ + | -silent | --silent | --silen | --sile | --sil) + silent=yes ;; + + -runstatedir | --runstatedir | --runstatedi | --runstated \ + | --runstate | --runstat | --runsta | --runst | --runs \ + | --run | --ru | --r) + ac_prev=runstatedir ;; + -runstatedir=* | --runstatedir=* | --runstatedi=* | --runstated=* \ + | --runstate=* | --runstat=* | --runsta=* | --runst=* | --runs=* \ + | --run=* | --ru=* | --r=*) + runstatedir=$ac_optarg ;; + + -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb) + ac_prev=sbindir ;; + -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \ + | --sbi=* | --sb=*) + sbindir=$ac_optarg ;; + + -sharedstatedir | --sharedstatedir | --sharedstatedi \ + | --sharedstated | --sharedstate | --sharedstat | --sharedsta \ + | --sharedst | --shareds | --shared | --share | --shar \ + | --sha | --sh) + ac_prev=sharedstatedir ;; + -sharedstatedir=* | --sharedstatedir=* | --sharedstatedi=* \ + | --sharedstated=* | --sharedstate=* | --sharedstat=* | --sharedsta=* \ + | --sharedst=* | --shareds=* | --shared=* | --share=* | --shar=* \ + | --sha=* | --sh=*) + sharedstatedir=$ac_optarg ;; + + -site | --site | --sit) + ac_prev=site ;; + -site=* | --site=* | --sit=*) + site=$ac_optarg ;; + + -srcdir | --srcdir | --srcdi | --srcd | --src | --sr) + ac_prev=srcdir ;; + -srcdir=* | --srcdir=* | --srcdi=* | --srcd=* | --src=* | --sr=*) + srcdir=$ac_optarg ;; + + -sysconfdir | --sysconfdir | --sysconfdi | --sysconfd | --sysconf \ + | --syscon | --sysco | --sysc | --sys | --sy) + ac_prev=sysconfdir ;; + -sysconfdir=* | --sysconfdir=* | --sysconfdi=* | --sysconfd=* | --sysconf=* \ + | --syscon=* | --sysco=* | --sysc=* | --sys=* | --sy=*) + sysconfdir=$ac_optarg ;; + + -target | --target | --targe | --targ | --tar | --ta | --t) + ac_prev=target_alias ;; + -target=* | --target=* | --targe=* | --targ=* | --tar=* | --ta=* | --t=*) + target_alias=$ac_optarg ;; + + -v | -verbose | --verbose | --verbos | --verbo | --verb) + verbose=yes ;; + + -version | --version | --versio | --versi | --vers | -V) + ac_init_version=: ;; + + -with-* | --with-*) + ac_useropt=`expr "x$ac_option" : 'x-*with-\([^=]*\)'` + # Reject names that are not valid shell variable names. + expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && + as_fn_error $? "invalid package name: $ac_useropt" + ac_useropt_orig=$ac_useropt + ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` + case $ac_user_opts in + *" +"with_$ac_useropt" +"*) ;; + *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--with-$ac_useropt_orig" + ac_unrecognized_sep=', ';; + esac + eval with_$ac_useropt=\$ac_optarg ;; + + -without-* | --without-*) + ac_useropt=`expr "x$ac_option" : 'x-*without-\(.*\)'` + # Reject names that are not valid shell variable names. + expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && + as_fn_error $? "invalid package name: $ac_useropt" + ac_useropt_orig=$ac_useropt + ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` + case $ac_user_opts in + *" +"with_$ac_useropt" +"*) ;; + *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--without-$ac_useropt_orig" + ac_unrecognized_sep=', ';; + esac + eval with_$ac_useropt=no ;; + + --x) + # Obsolete; use --with-x. + with_x=yes ;; + + -x-includes | --x-includes | --x-include | --x-includ | --x-inclu \ + | --x-incl | --x-inc | --x-in | --x-i) + ac_prev=x_includes ;; + -x-includes=* | --x-includes=* | --x-include=* | --x-includ=* | --x-inclu=* \ + | --x-incl=* | --x-inc=* | --x-in=* | --x-i=*) + x_includes=$ac_optarg ;; + + -x-libraries | --x-libraries | --x-librarie | --x-librari \ + | --x-librar | --x-libra | --x-libr | --x-lib | --x-li | --x-l) + ac_prev=x_libraries ;; + -x-libraries=* | --x-libraries=* | --x-librarie=* | --x-librari=* \ + | --x-librar=* | --x-libra=* | --x-libr=* | --x-lib=* | --x-li=* | --x-l=*) + x_libraries=$ac_optarg ;; + + -*) as_fn_error $? "unrecognized option: \`$ac_option' +Try \`$0 --help' for more information" + ;; + + *=*) + ac_envvar=`expr "x$ac_option" : 'x\([^=]*\)='` + # Reject names that are not valid shell variable names. + case $ac_envvar in #( + '' | [0-9]* | *[!_$as_cr_alnum]* ) + as_fn_error $? "invalid variable name: \`$ac_envvar'" ;; + esac + eval $ac_envvar=\$ac_optarg + export $ac_envvar ;; + + *) + # FIXME: should be removed in autoconf 3.0. + $as_echo "$as_me: WARNING: you should use --build, --host, --target" >&2 + expr "x$ac_option" : ".*[^-._$as_cr_alnum]" >/dev/null && + $as_echo "$as_me: WARNING: invalid host type: $ac_option" >&2 + : "${build_alias=$ac_option} ${host_alias=$ac_option} ${target_alias=$ac_option}" + ;; + + esac +done + +if test -n "$ac_prev"; then + ac_option=--`echo $ac_prev | sed 's/_/-/g'` + as_fn_error $? "missing argument to $ac_option" +fi + +if test -n "$ac_unrecognized_opts"; then + case $enable_option_checking in + no) ;; + fatal) as_fn_error $? "unrecognized options: $ac_unrecognized_opts" ;; + *) $as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2 ;; + esac +fi + +# Check all directory arguments for consistency. +for ac_var in exec_prefix prefix bindir sbindir libexecdir datarootdir \ + datadir sysconfdir sharedstatedir localstatedir includedir \ + oldincludedir docdir infodir htmldir dvidir pdfdir psdir \ + libdir localedir mandir runstatedir +do + eval ac_val=\$$ac_var + # Remove trailing slashes. + case $ac_val in + */ ) + ac_val=`expr "X$ac_val" : 'X\(.*[^/]\)' \| "X$ac_val" : 'X\(.*\)'` + eval $ac_var=\$ac_val;; + esac + # Be sure to have absolute directory names. + case $ac_val in + [\\/$]* | ?:[\\/]* ) continue;; + NONE | '' ) case $ac_var in *prefix ) continue;; esac;; + esac + as_fn_error $? "expected an absolute directory name for --$ac_var: $ac_val" +done + +# There might be people who depend on the old broken behavior: `$host' +# used to hold the argument of --host etc. +# FIXME: To remove some day. +build=$build_alias +host=$host_alias +target=$target_alias + +# FIXME: To remove some day. +if test "x$host_alias" != x; then + if test "x$build_alias" = x; then + cross_compiling=maybe + elif test "x$build_alias" != "x$host_alias"; then + cross_compiling=yes + fi +fi + +ac_tool_prefix= +test -n "$host_alias" && ac_tool_prefix=$host_alias- + +test "$silent" = yes && exec 6>/dev/null + + +ac_pwd=`pwd` && test -n "$ac_pwd" && +ac_ls_di=`ls -di .` && +ac_pwd_ls_di=`cd "$ac_pwd" && ls -di .` || + as_fn_error $? "working directory cannot be determined" +test "X$ac_ls_di" = "X$ac_pwd_ls_di" || + as_fn_error $? "pwd does not report name of working directory" + + +# Find the source files, if location was not specified. +if test -z "$srcdir"; then + ac_srcdir_defaulted=yes + # Try the directory containing this script, then the parent directory. + ac_confdir=`$as_dirname -- "$as_myself" || +$as_expr X"$as_myself" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ + X"$as_myself" : 'X\(//\)[^/]' \| \ + X"$as_myself" : 'X\(//\)$' \| \ + X"$as_myself" : 'X\(/\)' \| . 2>/dev/null || +$as_echo X"$as_myself" | + sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ + s//\1/ + q + } + /^X\(\/\/\)[^/].*/{ + s//\1/ + q + } + /^X\(\/\/\)$/{ + s//\1/ + q + } + /^X\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` + srcdir=$ac_confdir + if test ! -r "$srcdir/$ac_unique_file"; then + srcdir=.. + fi +else + ac_srcdir_defaulted=no +fi +if test ! -r "$srcdir/$ac_unique_file"; then + test "$ac_srcdir_defaulted" = yes && srcdir="$ac_confdir or .." + as_fn_error $? "cannot find sources ($ac_unique_file) in $srcdir" +fi +ac_msg="sources are in $srcdir, but \`cd $srcdir' does not work" +ac_abs_confdir=`( + cd "$srcdir" && test -r "./$ac_unique_file" || as_fn_error $? "$ac_msg" + pwd)` +# When building in place, set srcdir=. +if test "$ac_abs_confdir" = "$ac_pwd"; then + srcdir=. +fi +# Remove unnecessary trailing slashes from srcdir. +# Double slashes in file names in object file debugging info +# mess up M-x gdb in Emacs. +case $srcdir in +*/) srcdir=`expr "X$srcdir" : 'X\(.*[^/]\)' \| "X$srcdir" : 'X\(.*\)'`;; +esac +for ac_var in $ac_precious_vars; do + eval ac_env_${ac_var}_set=\${${ac_var}+set} + eval ac_env_${ac_var}_value=\$${ac_var} + eval ac_cv_env_${ac_var}_set=\${${ac_var}+set} + eval ac_cv_env_${ac_var}_value=\$${ac_var} +done + +# +# Report the --help message. +# +if test "$ac_init_help" = "long"; then + # Omit some internal or obsolete options to make the list less imposing. + # This message is too long to be a string in the A/UX 3.1 sh. + cat <<_ACEOF +\`configure' configures schemadtx 1.0 to adapt to many kinds of systems. + +Usage: $0 [OPTION]... [VAR=VALUE]... + +To assign environment variables (e.g., CC, CFLAGS...), specify them as +VAR=VALUE. See below for descriptions of some of the useful variables. + +Defaults for the options are specified in brackets. + +Configuration: + -h, --help display this help and exit + --help=short display options specific to this package + --help=recursive display the short help of all the included packages + -V, --version display version information and exit + -q, --quiet, --silent do not print \`checking ...' messages + --cache-file=FILE cache test results in FILE [disabled] + -C, --config-cache alias for \`--cache-file=config.cache' + -n, --no-create do not create output files + --srcdir=DIR find the sources in DIR [configure dir or \`..'] + +Installation directories: + --prefix=PREFIX install architecture-independent files in PREFIX + [$ac_default_prefix] + --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX + [PREFIX] + +By default, \`make install' will install all the files in +\`$ac_default_prefix/bin', \`$ac_default_prefix/lib' etc. You can specify +an installation prefix other than \`$ac_default_prefix' using \`--prefix', +for instance \`--prefix=\$HOME'. + +For better control, use the options below. + +Fine tuning of the installation directories: + --bindir=DIR user executables [EPREFIX/bin] + --sbindir=DIR system admin executables [EPREFIX/sbin] + --libexecdir=DIR program executables [EPREFIX/libexec] + --sysconfdir=DIR read-only single-machine data [PREFIX/etc] + --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com] + --localstatedir=DIR modifiable single-machine data [PREFIX/var] + --runstatedir=DIR modifiable per-process data [LOCALSTATEDIR/run] + --libdir=DIR object code libraries [EPREFIX/lib] + --includedir=DIR C header files [PREFIX/include] + --oldincludedir=DIR C header files for non-gcc [/usr/include] + --datarootdir=DIR read-only arch.-independent data root [PREFIX/share] + --datadir=DIR read-only architecture-independent data [DATAROOTDIR] + --infodir=DIR info documentation [DATAROOTDIR/info] + --localedir=DIR locale-dependent data [DATAROOTDIR/locale] + --mandir=DIR man documentation [DATAROOTDIR/man] + --docdir=DIR documentation root [DATAROOTDIR/doc/schemadtx] + --htmldir=DIR html documentation [DOCDIR] + --dvidir=DIR dvi documentation [DOCDIR] + --pdfdir=DIR pdf documentation [DOCDIR] + --psdir=DIR ps documentation [DOCDIR] +_ACEOF + + cat <<\_ACEOF +_ACEOF +fi + +if test -n "$ac_init_help"; then + case $ac_init_help in + short | recursive ) echo "Configuration of schemadtx 1.0:";; + esac + cat <<\_ACEOF + +Optional Features: + --disable-option-checking ignore unrecognized --enable/--with options + --disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no) + --enable-FEATURE[=ARG] include FEATURE [ARG=yes] + --enable-threads build with threads (default: on) + --enable-shared build and link with shared libraries (default: on) + --enable-stubs build and link with stub libraries. Always true for + shared builds (default: on) + --enable-64bit enable 64bit support (default: off) + --enable-64bit-vis enable 64bit Sparc VIS support (default: off) + --disable-rpath disable rpath support (default: on) + --enable-wince enable Win/CE support (where applicable) + --enable-symbols build with debugging symbols (default: off) + +Optional Packages: + --with-PACKAGE[=ARG] use PACKAGE [ARG=yes] + --without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no) + --with-tcl directory containing tcl configuration + (tclConfig.sh) + --with-tdom directory containing tDOM configuration + (tdomConfig.sh) + --with-tclinclude directory containing the public Tcl header files + --with-celib=DIR use Windows/CE support library from DIR + +Some influential environment variables: + CC C compiler command + CFLAGS C compiler flags + LDFLAGS linker flags, e.g. -L if you have libraries in a + nonstandard directory + LIBS libraries to pass to the linker, e.g. -l + CPPFLAGS (Objective) C/C++ preprocessor flags, e.g. -I if + you have headers in a nonstandard directory + CPP C preprocessor + +Use these variables to override the choices made by `configure' or to help +it to find libraries and programs with nonstandard names/locations. + +Report bugs to the package provider. +_ACEOF +ac_status=$? +fi + +if test "$ac_init_help" = "recursive"; then + # If there are subdirs, report their specific --help. + for ac_dir in : $ac_subdirs_all; do test "x$ac_dir" = x: && continue + test -d "$ac_dir" || + { cd "$srcdir" && ac_pwd=`pwd` && srcdir=. && test -d "$ac_dir"; } || + continue + ac_builddir=. + +case "$ac_dir" in +.) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;; +*) + ac_dir_suffix=/`$as_echo "$ac_dir" | sed 's|^\.[\\/]||'` + # A ".." for each directory in $ac_dir_suffix. + ac_top_builddir_sub=`$as_echo "$ac_dir_suffix" | sed 's|/[^\\/]*|/..|g;s|/||'` + case $ac_top_builddir_sub in + "") ac_top_builddir_sub=. ac_top_build_prefix= ;; + *) ac_top_build_prefix=$ac_top_builddir_sub/ ;; + esac ;; +esac +ac_abs_top_builddir=$ac_pwd +ac_abs_builddir=$ac_pwd$ac_dir_suffix +# for backward compatibility: +ac_top_builddir=$ac_top_build_prefix + +case $srcdir in + .) # We are building in place. + ac_srcdir=. + ac_top_srcdir=$ac_top_builddir_sub + ac_abs_top_srcdir=$ac_pwd ;; + [\\/]* | ?:[\\/]* ) # Absolute name. + ac_srcdir=$srcdir$ac_dir_suffix; + ac_top_srcdir=$srcdir + ac_abs_top_srcdir=$srcdir ;; + *) # Relative name. + ac_srcdir=$ac_top_build_prefix$srcdir$ac_dir_suffix + ac_top_srcdir=$ac_top_build_prefix$srcdir + ac_abs_top_srcdir=$ac_pwd/$srcdir ;; +esac +ac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix + + cd "$ac_dir" || { ac_status=$?; continue; } + # Check for guested configure. + if test -f "$ac_srcdir/configure.gnu"; then + echo && + $SHELL "$ac_srcdir/configure.gnu" --help=recursive + elif test -f "$ac_srcdir/configure"; then + echo && + $SHELL "$ac_srcdir/configure" --help=recursive + else + $as_echo "$as_me: WARNING: no configuration information is in $ac_dir" >&2 + fi || ac_status=$? + cd "$ac_pwd" || { ac_status=$?; break; } + done +fi + +test -n "$ac_init_help" && exit $ac_status +if $ac_init_version; then + cat <<\_ACEOF +schemadtx configure 1.0 +generated by GNU Autoconf 2.69 + +Copyright (C) 2012 Free Software Foundation, Inc. +This configure script is free software; the Free Software Foundation +gives unlimited permission to copy, distribute and modify it. +_ACEOF + exit +fi + +## ------------------------ ## +## Autoconf initialization. ## +## ------------------------ ## + +# ac_fn_c_try_compile LINENO +# -------------------------- +# Try to compile conftest.$ac_ext, and return whether this succeeded. +ac_fn_c_try_compile () +{ + as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + rm -f conftest.$ac_objext + if { { ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_compile") 2>conftest.err + ac_status=$? + if test -s conftest.err; then + grep -v '^ *+' conftest.err >conftest.er1 + cat conftest.er1 >&5 + mv -f conftest.er1 conftest.err + fi + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest.$ac_objext; then : + ac_retval=0 +else + $as_echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_retval=1 +fi + eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno + as_fn_set_status $ac_retval + +} # ac_fn_c_try_compile + +# ac_fn_c_try_cpp LINENO +# ---------------------- +# Try to preprocess conftest.$ac_ext, and return whether this succeeded. +ac_fn_c_try_cpp () +{ + as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + if { { ac_try="$ac_cpp conftest.$ac_ext" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_cpp conftest.$ac_ext") 2>conftest.err + ac_status=$? + if test -s conftest.err; then + grep -v '^ *+' conftest.err >conftest.er1 + cat conftest.er1 >&5 + mv -f conftest.er1 conftest.err + fi + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } > conftest.i && { + test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" || + test ! -s conftest.err + }; then : + ac_retval=0 +else + $as_echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_retval=1 +fi + eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno + as_fn_set_status $ac_retval + +} # ac_fn_c_try_cpp + +# ac_fn_c_try_run LINENO +# ---------------------- +# Try to link conftest.$ac_ext, and return whether this succeeded. Assumes +# that executables *can* be run. +ac_fn_c_try_run () +{ + as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + if { { ac_try="$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_link") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } && { ac_try='./conftest$ac_exeext' + { { case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; }; then : + ac_retval=0 +else + $as_echo "$as_me: program exited with status $ac_status" >&5 + $as_echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_retval=$ac_status +fi + rm -rf conftest.dSYM conftest_ipa8_conftest.oo + eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno + as_fn_set_status $ac_retval + +} # ac_fn_c_try_run + +# ac_fn_c_check_header_compile LINENO HEADER VAR INCLUDES +# ------------------------------------------------------- +# Tests whether HEADER exists and can be compiled using the include files in +# INCLUDES, setting the cache variable VAR accordingly. +ac_fn_c_check_header_compile () +{ + as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 +$as_echo_n "checking for $2... " >&6; } +if eval \${$3+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +$4 +#include <$2> +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + eval "$3=yes" +else + eval "$3=no" +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +eval ac_res=\$$3 + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +$as_echo "$ac_res" >&6; } + eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno + +} # ac_fn_c_check_header_compile + +# ac_fn_c_try_link LINENO +# ----------------------- +# Try to link conftest.$ac_ext, and return whether this succeeded. +ac_fn_c_try_link () +{ + as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + rm -f conftest.$ac_objext conftest$ac_exeext + if { { ac_try="$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_link") 2>conftest.err + ac_status=$? + if test -s conftest.err; then + grep -v '^ *+' conftest.err >conftest.er1 + cat conftest.er1 >&5 + mv -f conftest.er1 conftest.err + fi + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest$ac_exeext && { + test "$cross_compiling" = yes || + test -x conftest$ac_exeext + }; then : + ac_retval=0 +else + $as_echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_retval=1 +fi + # Delete the IPA/IPO (Inter Procedural Analysis/Optimization) information + # created by the PGI compiler (conftest_ipa8_conftest.oo), as it would + # interfere with the next link command; also delete a directory that is + # left behind by Apple's compiler. We do this before executing the actions. + rm -rf conftest.dSYM conftest_ipa8_conftest.oo + eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno + as_fn_set_status $ac_retval + +} # ac_fn_c_try_link + +# ac_fn_c_check_func LINENO FUNC VAR +# ---------------------------------- +# Tests whether FUNC exists, setting the cache variable VAR accordingly +ac_fn_c_check_func () +{ + as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 +$as_echo_n "checking for $2... " >&6; } +if eval \${$3+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +/* Define $2 to an innocuous variant, in case declares $2. + For example, HP-UX 11i declares gettimeofday. */ +#define $2 innocuous_$2 + +/* System header to define __stub macros and hopefully few prototypes, + which can conflict with char $2 (); below. + Prefer to if __STDC__ is defined, since + exists even on freestanding compilers. */ + +#ifdef __STDC__ +# include +#else +# include +#endif + +#undef $2 + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char $2 (); +/* The GNU C library defines this for functions which it implements + to always fail with ENOSYS. Some functions are actually named + something starting with __ and the normal name is an alias. */ +#if defined __stub_$2 || defined __stub___$2 +choke me +#endif + +int +main () +{ +return $2 (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + eval "$3=yes" +else + eval "$3=no" +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +fi +eval ac_res=\$$3 + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +$as_echo "$ac_res" >&6; } + eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno + +} # ac_fn_c_check_func +cat >config.log <<_ACEOF +This file contains any messages produced by compilers while +running configure, to aid debugging if configure makes a mistake. + +It was created by schemadtx $as_me 1.0, which was +generated by GNU Autoconf 2.69. Invocation command line was + + $ $0 $@ + +_ACEOF +exec 5>>config.log +{ +cat <<_ASUNAME +## --------- ## +## Platform. ## +## --------- ## + +hostname = `(hostname || uname -n) 2>/dev/null | sed 1q` +uname -m = `(uname -m) 2>/dev/null || echo unknown` +uname -r = `(uname -r) 2>/dev/null || echo unknown` +uname -s = `(uname -s) 2>/dev/null || echo unknown` +uname -v = `(uname -v) 2>/dev/null || echo unknown` + +/usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null || echo unknown` +/bin/uname -X = `(/bin/uname -X) 2>/dev/null || echo unknown` + +/bin/arch = `(/bin/arch) 2>/dev/null || echo unknown` +/usr/bin/arch -k = `(/usr/bin/arch -k) 2>/dev/null || echo unknown` +/usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null || echo unknown` +/usr/bin/hostinfo = `(/usr/bin/hostinfo) 2>/dev/null || echo unknown` +/bin/machine = `(/bin/machine) 2>/dev/null || echo unknown` +/usr/bin/oslevel = `(/usr/bin/oslevel) 2>/dev/null || echo unknown` +/bin/universe = `(/bin/universe) 2>/dev/null || echo unknown` + +_ASUNAME + +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + $as_echo "PATH: $as_dir" + done +IFS=$as_save_IFS + +} >&5 + +cat >&5 <<_ACEOF + + +## ----------- ## +## Core tests. ## +## ----------- ## + +_ACEOF + + +# Keep a trace of the command line. +# Strip out --no-create and --no-recursion so they do not pile up. +# Strip out --silent because we don't want to record it for future runs. +# Also quote any args containing shell meta-characters. +# Make two passes to allow for proper duplicate-argument suppression. +ac_configure_args= +ac_configure_args0= +ac_configure_args1= +ac_must_keep_next=false +for ac_pass in 1 2 +do + for ac_arg + do + case $ac_arg in + -no-create | --no-c* | -n | -no-recursion | --no-r*) continue ;; + -q | -quiet | --quiet | --quie | --qui | --qu | --q \ + | -silent | --silent | --silen | --sile | --sil) + continue ;; + *\'*) + ac_arg=`$as_echo "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` ;; + esac + case $ac_pass in + 1) as_fn_append ac_configure_args0 " '$ac_arg'" ;; + 2) + as_fn_append ac_configure_args1 " '$ac_arg'" + if test $ac_must_keep_next = true; then + ac_must_keep_next=false # Got value, back to normal. + else + case $ac_arg in + *=* | --config-cache | -C | -disable-* | --disable-* \ + | -enable-* | --enable-* | -gas | --g* | -nfp | --nf* \ + | -q | -quiet | --q* | -silent | --sil* | -v | -verb* \ + | -with-* | --with-* | -without-* | --without-* | --x) + case "$ac_configure_args0 " in + "$ac_configure_args1"*" '$ac_arg' "* ) continue ;; + esac + ;; + -* ) ac_must_keep_next=true ;; + esac + fi + as_fn_append ac_configure_args " '$ac_arg'" + ;; + esac + done +done +{ ac_configure_args0=; unset ac_configure_args0;} +{ ac_configure_args1=; unset ac_configure_args1;} + +# When interrupted or exit'd, cleanup temporary files, and complete +# config.log. We remove comments because anyway the quotes in there +# would cause problems or look ugly. +# WARNING: Use '\'' to represent an apostrophe within the trap. +# WARNING: Do not start the trap code with a newline, due to a FreeBSD 4.0 bug. +trap 'exit_status=$? + # Save into config.log some information that might help in debugging. + { + echo + + $as_echo "## ---------------- ## +## Cache variables. ## +## ---------------- ##" + echo + # The following way of writing the cache mishandles newlines in values, +( + for ac_var in `(set) 2>&1 | sed -n '\''s/^\([a-zA-Z_][a-zA-Z0-9_]*\)=.*/\1/p'\''`; do + eval ac_val=\$$ac_var + case $ac_val in #( + *${as_nl}*) + case $ac_var in #( + *_cv_*) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: cache variable $ac_var contains a newline" >&5 +$as_echo "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;; + esac + case $ac_var in #( + _ | IFS | as_nl) ;; #( + BASH_ARGV | BASH_SOURCE) eval $ac_var= ;; #( + *) { eval $ac_var=; unset $ac_var;} ;; + esac ;; + esac + done + (set) 2>&1 | + case $as_nl`(ac_space='\'' '\''; set) 2>&1` in #( + *${as_nl}ac_space=\ *) + sed -n \ + "s/'\''/'\''\\\\'\'''\''/g; + s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\''\\2'\''/p" + ;; #( + *) + sed -n "/^[_$as_cr_alnum]*_cv_[_$as_cr_alnum]*=/p" + ;; + esac | + sort +) + echo + + $as_echo "## ----------------- ## +## Output variables. ## +## ----------------- ##" + echo + for ac_var in $ac_subst_vars + do + eval ac_val=\$$ac_var + case $ac_val in + *\'\''*) ac_val=`$as_echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;; + esac + $as_echo "$ac_var='\''$ac_val'\''" + done | sort + echo + + if test -n "$ac_subst_files"; then + $as_echo "## ------------------- ## +## File substitutions. ## +## ------------------- ##" + echo + for ac_var in $ac_subst_files + do + eval ac_val=\$$ac_var + case $ac_val in + *\'\''*) ac_val=`$as_echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;; + esac + $as_echo "$ac_var='\''$ac_val'\''" + done | sort + echo + fi + + if test -s confdefs.h; then + $as_echo "## ----------- ## +## confdefs.h. ## +## ----------- ##" + echo + cat confdefs.h + echo + fi + test "$ac_signal" != 0 && + $as_echo "$as_me: caught signal $ac_signal" + $as_echo "$as_me: exit $exit_status" + } >&5 + rm -f core *.core core.conftest.* && + rm -f -r conftest* confdefs* conf$$* $ac_clean_files && + exit $exit_status +' 0 +for ac_signal in 1 2 13 15; do + trap 'ac_signal='$ac_signal'; as_fn_exit 1' $ac_signal +done +ac_signal=0 + +# confdefs.h avoids OS command line length limits that DEFS can exceed. +rm -f -r conftest* confdefs.h + +$as_echo "/* confdefs.h */" > confdefs.h + +# Predefined preprocessor variables. + +cat >>confdefs.h <<_ACEOF +#define PACKAGE_NAME "$PACKAGE_NAME" +_ACEOF + +cat >>confdefs.h <<_ACEOF +#define PACKAGE_TARNAME "$PACKAGE_TARNAME" +_ACEOF + +cat >>confdefs.h <<_ACEOF +#define PACKAGE_VERSION "$PACKAGE_VERSION" +_ACEOF + +cat >>confdefs.h <<_ACEOF +#define PACKAGE_STRING "$PACKAGE_STRING" +_ACEOF + +cat >>confdefs.h <<_ACEOF +#define PACKAGE_BUGREPORT "$PACKAGE_BUGREPORT" +_ACEOF + +cat >>confdefs.h <<_ACEOF +#define PACKAGE_URL "$PACKAGE_URL" +_ACEOF + + +# Let the site file select an alternate cache file if it wants to. +# Prefer an explicitly selected file to automatically selected ones. +ac_site_file1=NONE +ac_site_file2=NONE +if test -n "$CONFIG_SITE"; then + # We do not want a PATH search for config.site. + case $CONFIG_SITE in #(( + -*) ac_site_file1=./$CONFIG_SITE;; + */*) ac_site_file1=$CONFIG_SITE;; + *) ac_site_file1=./$CONFIG_SITE;; + esac +elif test "x$prefix" != xNONE; then + ac_site_file1=$prefix/share/config.site + ac_site_file2=$prefix/etc/config.site +else + ac_site_file1=$ac_default_prefix/share/config.site + ac_site_file2=$ac_default_prefix/etc/config.site +fi +for ac_site_file in "$ac_site_file1" "$ac_site_file2" +do + test "x$ac_site_file" = xNONE && continue + if test /dev/null != "$ac_site_file" && test -r "$ac_site_file"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: loading site script $ac_site_file" >&5 +$as_echo "$as_me: loading site script $ac_site_file" >&6;} + sed 's/^/| /' "$ac_site_file" >&5 + . "$ac_site_file" \ + || { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error $? "failed to load site script $ac_site_file +See \`config.log' for more details" "$LINENO" 5; } + fi +done + +if test -r "$cache_file"; then + # Some versions of bash will fail to source /dev/null (special files + # actually), so we avoid doing that. DJGPP emulates it as a regular file. + if test /dev/null != "$cache_file" && test -f "$cache_file"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: loading cache $cache_file" >&5 +$as_echo "$as_me: loading cache $cache_file" >&6;} + case $cache_file in + [\\/]* | ?:[\\/]* ) . "$cache_file";; + *) . "./$cache_file";; + esac + fi +else + { $as_echo "$as_me:${as_lineno-$LINENO}: creating cache $cache_file" >&5 +$as_echo "$as_me: creating cache $cache_file" >&6;} + >$cache_file +fi + +# Check that the precious variables saved in the cache have kept the same +# value. +ac_cache_corrupted=false +for ac_var in $ac_precious_vars; do + eval ac_old_set=\$ac_cv_env_${ac_var}_set + eval ac_new_set=\$ac_env_${ac_var}_set + eval ac_old_val=\$ac_cv_env_${ac_var}_value + eval ac_new_val=\$ac_env_${ac_var}_value + case $ac_old_set,$ac_new_set in + set,) + { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&5 +$as_echo "$as_me: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&2;} + ac_cache_corrupted=: ;; + ,set) + { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' was not set in the previous run" >&5 +$as_echo "$as_me: error: \`$ac_var' was not set in the previous run" >&2;} + ac_cache_corrupted=: ;; + ,);; + *) + if test "x$ac_old_val" != "x$ac_new_val"; then + # differences in whitespace do not lead to failure. + ac_old_val_w=`echo x $ac_old_val` + ac_new_val_w=`echo x $ac_new_val` + if test "$ac_old_val_w" != "$ac_new_val_w"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' has changed since the previous run:" >&5 +$as_echo "$as_me: error: \`$ac_var' has changed since the previous run:" >&2;} + ac_cache_corrupted=: + else + { $as_echo "$as_me:${as_lineno-$LINENO}: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&5 +$as_echo "$as_me: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&2;} + eval $ac_var=\$ac_old_val + fi + { $as_echo "$as_me:${as_lineno-$LINENO}: former value: \`$ac_old_val'" >&5 +$as_echo "$as_me: former value: \`$ac_old_val'" >&2;} + { $as_echo "$as_me:${as_lineno-$LINENO}: current value: \`$ac_new_val'" >&5 +$as_echo "$as_me: current value: \`$ac_new_val'" >&2;} + fi;; + esac + # Pass precious variables to config.status. + if test "$ac_new_set" = set; then + case $ac_new_val in + *\'*) ac_arg=$ac_var=`$as_echo "$ac_new_val" | sed "s/'/'\\\\\\\\''/g"` ;; + *) ac_arg=$ac_var=$ac_new_val ;; + esac + case " $ac_configure_args " in + *" '$ac_arg' "*) ;; # Avoid dups. Use of quotes ensures accuracy. + *) as_fn_append ac_configure_args " '$ac_arg'" ;; + esac + fi +done +if $ac_cache_corrupted; then + { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} + { $as_echo "$as_me:${as_lineno-$LINENO}: error: changes in the environment can compromise the build" >&5 +$as_echo "$as_me: error: changes in the environment can compromise the build" >&2;} + as_fn_error $? "run \`make distclean' and/or \`rm $cache_file' and start over" "$LINENO" 5 +fi +## -------------------- ## +## Main body of script. ## +## -------------------- ## + +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + + +#-------------------------------------------------------------------- +# Call TEA_INIT as the first TEA_ macro to set up initial vars. +# This will define a ${TEA_PLATFORM} variable == "unix" or "windows" +# as well as PKG_LIB_FILE and PKG_STUB_LIB_FILE. +#-------------------------------------------------------------------- + + + TEA_VERSION="3.13" + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking TEA configuration" >&5 +$as_echo_n "checking TEA configuration... " >&6; } + if test x"${PACKAGE_NAME}" = x ; then + as_fn_error $? " +The PACKAGE_NAME variable must be defined by your TEA configure.ac" "$LINENO" 5 + fi + { $as_echo "$as_me:${as_lineno-$LINENO}: result: ok (TEA ${TEA_VERSION})" >&5 +$as_echo "ok (TEA ${TEA_VERSION})" >&6; } + + # If the user did not set CFLAGS, set it now to keep macros + # like AC_PROG_CC and AC_TRY_COMPILE from adding "-g -O2". + if test "${CFLAGS+set}" != "set" ; then + CFLAGS="" + fi + + case "`uname -s`" in + *win32*|*WIN32*|*MINGW32_*|*MINGW64_*) + # Extract the first word of "cygpath", so it can be a program name with args. +set dummy cygpath; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_CYGPATH+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$CYGPATH"; then + ac_cv_prog_CYGPATH="$CYGPATH" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_CYGPATH="cygpath -m" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + + test -z "$ac_cv_prog_CYGPATH" && ac_cv_prog_CYGPATH="echo" +fi +fi +CYGPATH=$ac_cv_prog_CYGPATH +if test -n "$CYGPATH"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CYGPATH" >&5 +$as_echo "$CYGPATH" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + EXEEXT=".exe" + TEA_PLATFORM="windows" + ;; + *CYGWIN_*) + EXEEXT=".exe" + # CYGPATH and TEA_PLATFORM are determined later in LOAD_TCLCONFIG + ;; + *) + CYGPATH=echo + # Maybe we are cross-compiling.... + case ${host_alias} in + *mingw32*) + EXEEXT=".exe" + TEA_PLATFORM="windows" + ;; + *) + EXEEXT="" + TEA_PLATFORM="unix" + ;; + esac + ;; + esac + + # Check if exec_prefix is set. If not use fall back to prefix. + # Note when adjusted, so that TEA_PREFIX can correct for this. + # This is needed for recursive configures, since autoconf propagates + # $prefix, but not $exec_prefix (doh!). + if test x$exec_prefix = xNONE ; then + exec_prefix_default=yes + exec_prefix=$prefix + fi + + { $as_echo "$as_me:${as_lineno-$LINENO}: configuring ${PACKAGE_NAME} ${PACKAGE_VERSION}" >&5 +$as_echo "$as_me: configuring ${PACKAGE_NAME} ${PACKAGE_VERSION}" >&6;} + + + + + # This package name must be replaced statically for AC_SUBST to work + + # Substitute STUB_LIB_FILE in case package creates a stub library too. + + + # We AC_SUBST these here to ensure they are subst'ed, + # in case the user doesn't call TEA_ADD_... + + + + + + + + + # Configure the installer. + + INSTALL='$(SHELL) $(srcdir)/tclconfig/install-sh -c' + INSTALL_DATA_DIR='${INSTALL} -d -m 755' + INSTALL_DATA='${INSTALL} -m 644' + INSTALL_PROGRAM='${INSTALL} -m 755' + INSTALL_SCRIPT='${INSTALL} -m 755' + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking system version" >&5 +$as_echo_n "checking system version... " >&6; } +if ${tcl_cv_sys_version+:} false; then : + $as_echo_n "(cached) " >&6 +else + + # TEA specific: + if test "${TEA_PLATFORM}" = "windows" ; then + tcl_cv_sys_version=windows + else + tcl_cv_sys_version=`uname -s`-`uname -r` + if test "$?" -ne 0 ; then + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: can't find uname command" >&5 +$as_echo "$as_me: WARNING: can't find uname command" >&2;} + tcl_cv_sys_version=unknown + else + if test "`uname -s`" = "AIX" ; then + tcl_cv_sys_version=AIX-`uname -v`.`uname -r` + fi + fi + fi + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_sys_version" >&5 +$as_echo "$tcl_cv_sys_version" >&6; } + system=$tcl_cv_sys_version + + case $system in + HP-UX-*) INSTALL_LIBRARY='${INSTALL} -m 755' ;; + *) INSTALL_LIBRARY='${INSTALL} -m 644' ;; + esac + + + + + + + + + + +ac_aux_dir= +for ac_dir in ../../tclconfig "$srcdir"/../../tclconfig; do + if test -f "$ac_dir/install-sh"; then + ac_aux_dir=$ac_dir + ac_install_sh="$ac_aux_dir/install-sh -c" + break + elif test -f "$ac_dir/install.sh"; then + ac_aux_dir=$ac_dir + ac_install_sh="$ac_aux_dir/install.sh -c" + break + elif test -f "$ac_dir/shtool"; then + ac_aux_dir=$ac_dir + ac_install_sh="$ac_aux_dir/shtool install -c" + break + fi +done +if test -z "$ac_aux_dir"; then + as_fn_error $? "cannot find install-sh, install.sh, or shtool in ../../tclconfig \"$srcdir\"/../../tclconfig" "$LINENO" 5 +fi + +# These three variables are undocumented and unsupported, +# and are intended to be withdrawn in a future Autoconf release. +# They can cause serious problems if a builder's source tree is in a directory +# whose full name contains unusual characters. +ac_config_guess="$SHELL $ac_aux_dir/config.guess" # Please don't use this var. +ac_config_sub="$SHELL $ac_aux_dir/config.sub" # Please don't use this var. +ac_configure="$SHELL $ac_aux_dir/configure" # Please don't use this var. + + + +#-------------------------------------------------------------------- +# Load the tclConfig.sh file +#-------------------------------------------------------------------- + + + + # + # Ok, lets find the tcl configuration + # First, look for one uninstalled. + # the alternative search directory is invoked by --with-tcl + # + + if test x"${no_tcl}" = x ; then + # we reset no_tcl in case something fails here + no_tcl=true + +# Check whether --with-tcl was given. +if test "${with_tcl+set}" = set; then : + withval=$with_tcl; with_tclconfig="${withval}" +fi + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for Tcl configuration" >&5 +$as_echo_n "checking for Tcl configuration... " >&6; } + if ${ac_cv_c_tclconfig+:} false; then : + $as_echo_n "(cached) " >&6 +else + + + # First check to see if --with-tcl was specified. + if test x"${with_tclconfig}" != x ; then + case "${with_tclconfig}" in + */tclConfig.sh ) + if test -f "${with_tclconfig}"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: --with-tcl argument should refer to directory containing tclConfig.sh, not to tclConfig.sh itself" >&5 +$as_echo "$as_me: WARNING: --with-tcl argument should refer to directory containing tclConfig.sh, not to tclConfig.sh itself" >&2;} + with_tclconfig="`echo "${with_tclconfig}" | sed 's!/tclConfig\.sh$!!'`" + fi ;; + esac + if test -f "${with_tclconfig}/tclConfig.sh" ; then + ac_cv_c_tclconfig="`(cd "${with_tclconfig}"; pwd)`" + else + as_fn_error $? "${with_tclconfig} directory doesn't contain tclConfig.sh" "$LINENO" 5 + fi + fi + + # then check for a private Tcl installation + if test x"${ac_cv_c_tclconfig}" = x ; then + for i in \ + ../tcl \ + `ls -dr ../tcl[8-9].[0-9].[0-9]* 2>/dev/null` \ + `ls -dr ../tcl[8-9].[0-9] 2>/dev/null` \ + `ls -dr ../tcl[8-9].[0-9]* 2>/dev/null` \ + ../../tcl \ + `ls -dr ../../tcl[8-9].[0-9].[0-9]* 2>/dev/null` \ + `ls -dr ../../tcl[8-9].[0-9] 2>/dev/null` \ + `ls -dr ../../tcl[8-9].[0-9]* 2>/dev/null` \ + ../../../tcl \ + `ls -dr ../../../tcl[8-9].[0-9].[0-9]* 2>/dev/null` \ + `ls -dr ../../../tcl[8-9].[0-9] 2>/dev/null` \ + `ls -dr ../../../tcl[8-9].[0-9]* 2>/dev/null` ; do + if test "${TEA_PLATFORM}" = "windows" \ + -a -f "$i/win/tclConfig.sh" ; then + ac_cv_c_tclconfig="`(cd $i/win; pwd)`" + break + fi + if test -f "$i/unix/tclConfig.sh" ; then + ac_cv_c_tclconfig="`(cd $i/unix; pwd)`" + break + fi + done + fi + + # on Darwin, check in Framework installation locations + if test "`uname -s`" = "Darwin" -a x"${ac_cv_c_tclconfig}" = x ; then + for i in `ls -d ~/Library/Frameworks 2>/dev/null` \ + `ls -d /Library/Frameworks 2>/dev/null` \ + `ls -d /Network/Library/Frameworks 2>/dev/null` \ + `ls -d /System/Library/Frameworks 2>/dev/null` \ + `ls -d /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/Library/Frameworks/Tcl.framework 2>/dev/null` \ + `ls -d /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/Network/Library/Frameworks/Tcl.framework 2>/dev/null` \ + `ls -d /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/Tcl.framework 2>/dev/null` \ + ; do + if test -f "$i/Tcl.framework/tclConfig.sh" ; then + ac_cv_c_tclconfig="`(cd $i/Tcl.framework; pwd)`" + break + fi + done + fi + + # TEA specific: on Windows, check in common installation locations + if test "${TEA_PLATFORM}" = "windows" \ + -a x"${ac_cv_c_tclconfig}" = x ; then + for i in `ls -d C:/Tcl/lib 2>/dev/null` \ + `ls -d C:/Progra~1/Tcl/lib 2>/dev/null` \ + ; do + if test -f "$i/tclConfig.sh" ; then + ac_cv_c_tclconfig="`(cd $i; pwd)`" + break + fi + done + fi + + # check in a few common install locations + if test x"${ac_cv_c_tclconfig}" = x ; then + for i in `ls -d ${libdir} 2>/dev/null` \ + `ls -d ${exec_prefix}/lib 2>/dev/null` \ + `ls -d ${prefix}/lib 2>/dev/null` \ + `ls -d /usr/local/lib 2>/dev/null` \ + `ls -d /usr/contrib/lib 2>/dev/null` \ + `ls -d /usr/pkg/lib 2>/dev/null` \ + `ls -d /usr/lib 2>/dev/null` \ + `ls -d /usr/lib64 2>/dev/null` \ + `ls -d /usr/lib/tcl8.6 2>/dev/null` \ + `ls -d /usr/lib/tcl8.5 2>/dev/null` \ + `ls -d /usr/local/lib/tcl8.6 2>/dev/null` \ + `ls -d /usr/local/lib/tcl8.5 2>/dev/null` \ + `ls -d /usr/local/lib/tcl/tcl8.6 2>/dev/null` \ + `ls -d /usr/local/lib/tcl/tcl8.5 2>/dev/null` \ + ; do + if test -f "$i/tclConfig.sh" ; then + ac_cv_c_tclconfig="`(cd $i; pwd)`" + break + fi + done + fi + + # check in a few other private locations + if test x"${ac_cv_c_tclconfig}" = x ; then + for i in \ + ${srcdir}/../tcl \ + `ls -dr ${srcdir}/../tcl[8-9].[0-9].[0-9]* 2>/dev/null` \ + `ls -dr ${srcdir}/../tcl[8-9].[0-9] 2>/dev/null` \ + `ls -dr ${srcdir}/../tcl[8-9].[0-9]* 2>/dev/null` ; do + if test "${TEA_PLATFORM}" = "windows" \ + -a -f "$i/win/tclConfig.sh" ; then + ac_cv_c_tclconfig="`(cd $i/win; pwd)`" + break + fi + if test -f "$i/unix/tclConfig.sh" ; then + ac_cv_c_tclconfig="`(cd $i/unix; pwd)`" + break + fi + done + fi + +fi + + + if test x"${ac_cv_c_tclconfig}" = x ; then + TCL_BIN_DIR="# no Tcl configs found" + as_fn_error $? "Can't find Tcl configuration definitions. Use --with-tcl to specify a directory containing tclConfig.sh" "$LINENO" 5 + else + no_tcl= + TCL_BIN_DIR="${ac_cv_c_tclconfig}" + { $as_echo "$as_me:${as_lineno-$LINENO}: result: found ${TCL_BIN_DIR}/tclConfig.sh" >&5 +$as_echo "found ${TCL_BIN_DIR}/tclConfig.sh" >&6; } + fi + fi + +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu +if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}gcc", so it can be a program name with args. +set dummy ${ac_tool_prefix}gcc; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_CC+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$CC"; then + ac_cv_prog_CC="$CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_CC="${ac_tool_prefix}gcc" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +CC=$ac_cv_prog_CC +if test -n "$CC"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 +$as_echo "$CC" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_prog_CC"; then + ac_ct_CC=$CC + # Extract the first word of "gcc", so it can be a program name with args. +set dummy gcc; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_ac_ct_CC+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_CC"; then + ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_ac_ct_CC="gcc" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_CC=$ac_cv_prog_ac_ct_CC +if test -n "$ac_ct_CC"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5 +$as_echo "$ac_ct_CC" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_ct_CC" = x; then + CC="" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + CC=$ac_ct_CC + fi +else + CC="$ac_cv_prog_CC" +fi + +if test -z "$CC"; then + if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}cc", so it can be a program name with args. +set dummy ${ac_tool_prefix}cc; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_CC+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$CC"; then + ac_cv_prog_CC="$CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_CC="${ac_tool_prefix}cc" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +CC=$ac_cv_prog_CC +if test -n "$CC"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 +$as_echo "$CC" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + fi +fi +if test -z "$CC"; then + # Extract the first word of "cc", so it can be a program name with args. +set dummy cc; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_CC+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$CC"; then + ac_cv_prog_CC="$CC" # Let the user override the test. +else + ac_prog_rejected=no +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if test "$as_dir/$ac_word$ac_exec_ext" = "/usr/ucb/cc"; then + ac_prog_rejected=yes + continue + fi + ac_cv_prog_CC="cc" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +if test $ac_prog_rejected = yes; then + # We found a bogon in the path, so make sure we never use it. + set dummy $ac_cv_prog_CC + shift + if test $# != 0; then + # We chose a different compiler from the bogus one. + # However, it has the same basename, so the bogon will be chosen + # first if we set CC to just the basename; use the full file name. + shift + ac_cv_prog_CC="$as_dir/$ac_word${1+' '}$@" + fi +fi +fi +fi +CC=$ac_cv_prog_CC +if test -n "$CC"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 +$as_echo "$CC" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$CC"; then + if test -n "$ac_tool_prefix"; then + for ac_prog in cl.exe + do + # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args. +set dummy $ac_tool_prefix$ac_prog; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_CC+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$CC"; then + ac_cv_prog_CC="$CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_CC="$ac_tool_prefix$ac_prog" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +CC=$ac_cv_prog_CC +if test -n "$CC"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 +$as_echo "$CC" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + test -n "$CC" && break + done +fi +if test -z "$CC"; then + ac_ct_CC=$CC + for ac_prog in cl.exe +do + # Extract the first word of "$ac_prog", so it can be a program name with args. +set dummy $ac_prog; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_ac_ct_CC+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_CC"; then + ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_ac_ct_CC="$ac_prog" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_CC=$ac_cv_prog_ac_ct_CC +if test -n "$ac_ct_CC"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5 +$as_echo "$ac_ct_CC" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + test -n "$ac_ct_CC" && break +done + + if test "x$ac_ct_CC" = x; then + CC="" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + CC=$ac_ct_CC + fi +fi + +fi + + +test -z "$CC" && { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error $? "no acceptable C compiler found in \$PATH +See \`config.log' for more details" "$LINENO" 5; } + +# Provide some information about the compiler. +$as_echo "$as_me:${as_lineno-$LINENO}: checking for C compiler version" >&5 +set X $ac_compile +ac_compiler=$2 +for ac_option in --version -v -V -qversion; do + { { ac_try="$ac_compiler $ac_option >&5" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_compiler $ac_option >&5") 2>conftest.err + ac_status=$? + if test -s conftest.err; then + sed '10a\ +... rest of stderr output deleted ... + 10q' conftest.err >conftest.er1 + cat conftest.er1 >&5 + fi + rm -f conftest.er1 conftest.err + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } +done + +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +ac_clean_files_save=$ac_clean_files +ac_clean_files="$ac_clean_files a.out a.out.dSYM a.exe b.out" +# Try to create an executable without -o first, disregard a.out. +# It will help us diagnose broken compilers, and finding out an intuition +# of exeext. +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the C compiler works" >&5 +$as_echo_n "checking whether the C compiler works... " >&6; } +ac_link_default=`$as_echo "$ac_link" | sed 's/ -o *conftest[^ ]*//'` + +# The possible output files: +ac_files="a.out conftest.exe conftest a.exe a_out.exe b.out conftest.*" + +ac_rmfiles= +for ac_file in $ac_files +do + case $ac_file in + *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) ;; + * ) ac_rmfiles="$ac_rmfiles $ac_file";; + esac +done +rm -f $ac_rmfiles + +if { { ac_try="$ac_link_default" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_link_default") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then : + # Autoconf-2.13 could set the ac_cv_exeext variable to `no'. +# So ignore a value of `no', otherwise this would lead to `EXEEXT = no' +# in a Makefile. We should not override ac_cv_exeext if it was cached, +# so that the user can short-circuit this test for compilers unknown to +# Autoconf. +for ac_file in $ac_files '' +do + test -f "$ac_file" || continue + case $ac_file in + *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) + ;; + [ab].out ) + # We found the default executable, but exeext='' is most + # certainly right. + break;; + *.* ) + if test "${ac_cv_exeext+set}" = set && test "$ac_cv_exeext" != no; + then :; else + ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'` + fi + # We set ac_cv_exeext here because the later test for it is not + # safe: cross compilers may not add the suffix if given an `-o' + # argument, so we may need to know it at that point already. + # Even if this section looks crufty: it has the advantage of + # actually working. + break;; + * ) + break;; + esac +done +test "$ac_cv_exeext" = no && ac_cv_exeext= + +else + ac_file='' +fi +if test -z "$ac_file"; then : + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +$as_echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +{ { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error 77 "C compiler cannot create executables +See \`config.log' for more details" "$LINENO" 5; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for C compiler default output file name" >&5 +$as_echo_n "checking for C compiler default output file name... " >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_file" >&5 +$as_echo "$ac_file" >&6; } +ac_exeext=$ac_cv_exeext + +rm -f -r a.out a.out.dSYM a.exe conftest$ac_cv_exeext b.out +ac_clean_files=$ac_clean_files_save +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for suffix of executables" >&5 +$as_echo_n "checking for suffix of executables... " >&6; } +if { { ac_try="$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_link") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then : + # If both `conftest.exe' and `conftest' are `present' (well, observable) +# catch `conftest.exe'. For instance with Cygwin, `ls conftest' will +# work properly (i.e., refer to `conftest.exe'), while it won't with +# `rm'. +for ac_file in conftest.exe conftest conftest.*; do + test -f "$ac_file" || continue + case $ac_file in + *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) ;; + *.* ) ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'` + break;; + * ) break;; + esac +done +else + { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error $? "cannot compute suffix of executables: cannot compile and link +See \`config.log' for more details" "$LINENO" 5; } +fi +rm -f conftest conftest$ac_cv_exeext +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_exeext" >&5 +$as_echo "$ac_cv_exeext" >&6; } + +rm -f conftest.$ac_ext +EXEEXT=$ac_cv_exeext +ac_exeext=$EXEEXT +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +int +main () +{ +FILE *f = fopen ("conftest.out", "w"); + return ferror (f) || fclose (f) != 0; + + ; + return 0; +} +_ACEOF +ac_clean_files="$ac_clean_files conftest.out" +# Check that the compiler produces executables we can run. If not, either +# the compiler is broken, or we cross compile. +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are cross compiling" >&5 +$as_echo_n "checking whether we are cross compiling... " >&6; } +if test "$cross_compiling" != yes; then + { { ac_try="$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_link") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } + if { ac_try='./conftest$ac_cv_exeext' + { { case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; }; then + cross_compiling=no + else + if test "$cross_compiling" = maybe; then + cross_compiling=yes + else + { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error $? "cannot run C compiled programs. +If you meant to cross compile, use \`--host'. +See \`config.log' for more details" "$LINENO" 5; } + fi + fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $cross_compiling" >&5 +$as_echo "$cross_compiling" >&6; } + +rm -f conftest.$ac_ext conftest$ac_cv_exeext conftest.out +ac_clean_files=$ac_clean_files_save +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for suffix of object files" >&5 +$as_echo_n "checking for suffix of object files... " >&6; } +if ${ac_cv_objext+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +rm -f conftest.o conftest.obj +if { { ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_compile") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then : + for ac_file in conftest.o conftest.obj conftest.*; do + test -f "$ac_file" || continue; + case $ac_file in + *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM ) ;; + *) ac_cv_objext=`expr "$ac_file" : '.*\.\(.*\)'` + break;; + esac +done +else + $as_echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +{ { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error $? "cannot compute suffix of object files: cannot compile +See \`config.log' for more details" "$LINENO" 5; } +fi +rm -f conftest.$ac_cv_objext conftest.$ac_ext +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_objext" >&5 +$as_echo "$ac_cv_objext" >&6; } +OBJEXT=$ac_cv_objext +ac_objext=$OBJEXT +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are using the GNU C compiler" >&5 +$as_echo_n "checking whether we are using the GNU C compiler... " >&6; } +if ${ac_cv_c_compiler_gnu+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ +#ifndef __GNUC__ + choke me +#endif + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_compiler_gnu=yes +else + ac_compiler_gnu=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +ac_cv_c_compiler_gnu=$ac_compiler_gnu + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_compiler_gnu" >&5 +$as_echo "$ac_cv_c_compiler_gnu" >&6; } +if test $ac_compiler_gnu = yes; then + GCC=yes +else + GCC= +fi +ac_test_CFLAGS=${CFLAGS+set} +ac_save_CFLAGS=$CFLAGS +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC accepts -g" >&5 +$as_echo_n "checking whether $CC accepts -g... " >&6; } +if ${ac_cv_prog_cc_g+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_save_c_werror_flag=$ac_c_werror_flag + ac_c_werror_flag=yes + ac_cv_prog_cc_g=no + CFLAGS="-g" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_cv_prog_cc_g=yes +else + CFLAGS="" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + +else + ac_c_werror_flag=$ac_save_c_werror_flag + CFLAGS="-g" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_cv_prog_cc_g=yes +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + ac_c_werror_flag=$ac_save_c_werror_flag +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_g" >&5 +$as_echo "$ac_cv_prog_cc_g" >&6; } +if test "$ac_test_CFLAGS" = set; then + CFLAGS=$ac_save_CFLAGS +elif test $ac_cv_prog_cc_g = yes; then + if test "$GCC" = yes; then + CFLAGS="-g -O2" + else + CFLAGS="-g" + fi +else + if test "$GCC" = yes; then + CFLAGS="-O2" + else + CFLAGS= + fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $CC option to accept ISO C89" >&5 +$as_echo_n "checking for $CC option to accept ISO C89... " >&6; } +if ${ac_cv_prog_cc_c89+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_cv_prog_cc_c89=no +ac_save_CC=$CC +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +#include +struct stat; +/* Most of the following tests are stolen from RCS 5.7's src/conf.sh. */ +struct buf { int x; }; +FILE * (*rcsopen) (struct buf *, struct stat *, int); +static char *e (p, i) + char **p; + int i; +{ + return p[i]; +} +static char *f (char * (*g) (char **, int), char **p, ...) +{ + char *s; + va_list v; + va_start (v,p); + s = g (p, va_arg (v,int)); + va_end (v); + return s; +} + +/* OSF 4.0 Compaq cc is some sort of almost-ANSI by default. It has + function prototypes and stuff, but not '\xHH' hex character constants. + These don't provoke an error unfortunately, instead are silently treated + as 'x'. The following induces an error, until -std is added to get + proper ANSI mode. Curiously '\x00'!='x' always comes out true, for an + array size at least. It's necessary to write '\x00'==0 to get something + that's true only with -std. */ +int osf4_cc_array ['\x00' == 0 ? 1 : -1]; + +/* IBM C 6 for AIX is almost-ANSI by default, but it replaces macro parameters + inside strings and character constants. */ +#define FOO(x) 'x' +int xlc6_cc_array[FOO(a) == 'x' ? 1 : -1]; + +int test (int i, double x); +struct s1 {int (*f) (int a);}; +struct s2 {int (*f) (double a);}; +int pairnames (int, char **, FILE *(*)(struct buf *, struct stat *, int), int, int); +int argc; +char **argv; +int +main () +{ +return f (e, argv, 0) != argv[0] || f (e, argv, 1) != argv[1]; + ; + return 0; +} +_ACEOF +for ac_arg in '' -qlanglvl=extc89 -qlanglvl=ansi -std \ + -Ae "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__" +do + CC="$ac_save_CC $ac_arg" + if ac_fn_c_try_compile "$LINENO"; then : + ac_cv_prog_cc_c89=$ac_arg +fi +rm -f core conftest.err conftest.$ac_objext + test "x$ac_cv_prog_cc_c89" != "xno" && break +done +rm -f conftest.$ac_ext +CC=$ac_save_CC + +fi +# AC_CACHE_VAL +case "x$ac_cv_prog_cc_c89" in + x) + { $as_echo "$as_me:${as_lineno-$LINENO}: result: none needed" >&5 +$as_echo "none needed" >&6; } ;; + xno) + { $as_echo "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5 +$as_echo "unsupported" >&6; } ;; + *) + CC="$CC $ac_cv_prog_cc_c89" + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_c89" >&5 +$as_echo "$ac_cv_prog_cc_c89" >&6; } ;; +esac +if test "x$ac_cv_prog_cc_c89" != xno; then : + +fi + +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for existence of ${TCL_BIN_DIR}/tclConfig.sh" >&5 +$as_echo_n "checking for existence of ${TCL_BIN_DIR}/tclConfig.sh... " >&6; } + + if test -f "${TCL_BIN_DIR}/tclConfig.sh" ; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: loading" >&5 +$as_echo "loading" >&6; } + . "${TCL_BIN_DIR}/tclConfig.sh" + else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: could not find ${TCL_BIN_DIR}/tclConfig.sh" >&5 +$as_echo "could not find ${TCL_BIN_DIR}/tclConfig.sh" >&6; } + fi + + # eval is required to do the TCL_DBGX substitution + eval "TCL_LIB_FILE=\"${TCL_LIB_FILE}\"" + eval "TCL_STUB_LIB_FILE=\"${TCL_STUB_LIB_FILE}\"" + + # If the TCL_BIN_DIR is the build directory (not the install directory), + # then set the common variable name to the value of the build variables. + # For example, the variable TCL_LIB_SPEC will be set to the value + # of TCL_BUILD_LIB_SPEC. An extension should make use of TCL_LIB_SPEC + # instead of TCL_BUILD_LIB_SPEC since it will work with both an + # installed and uninstalled version of Tcl. + if test -f "${TCL_BIN_DIR}/Makefile" ; then + TCL_LIB_SPEC="${TCL_BUILD_LIB_SPEC}" + TCL_STUB_LIB_SPEC="${TCL_BUILD_STUB_LIB_SPEC}" + TCL_STUB_LIB_PATH="${TCL_BUILD_STUB_LIB_PATH}" + elif test "`uname -s`" = "Darwin"; then + # If Tcl was built as a framework, attempt to use the libraries + # from the framework at the given location so that linking works + # against Tcl.framework installed in an arbitrary location. + case ${TCL_DEFS} in + *TCL_FRAMEWORK*) + if test -f "${TCL_BIN_DIR}/${TCL_LIB_FILE}"; then + for i in "`cd "${TCL_BIN_DIR}"; pwd`" \ + "`cd "${TCL_BIN_DIR}"/../..; pwd`"; do + if test "`basename "$i"`" = "${TCL_LIB_FILE}.framework"; then + TCL_LIB_SPEC="-F`dirname "$i" | sed -e 's/ /\\\\ /g'` -framework ${TCL_LIB_FILE}" + break + fi + done + fi + if test -f "${TCL_BIN_DIR}/${TCL_STUB_LIB_FILE}"; then + TCL_STUB_LIB_SPEC="-L`echo "${TCL_BIN_DIR}" | sed -e 's/ /\\\\ /g'` ${TCL_STUB_LIB_FLAG}" + TCL_STUB_LIB_PATH="${TCL_BIN_DIR}/${TCL_STUB_LIB_FILE}" + fi + ;; + esac + fi + + # eval is required to do the TCL_DBGX substitution + eval "TCL_LIB_FLAG=\"${TCL_LIB_FLAG}\"" + eval "TCL_LIB_SPEC=\"${TCL_LIB_SPEC}\"" + eval "TCL_STUB_LIB_FLAG=\"${TCL_STUB_LIB_FLAG}\"" + eval "TCL_STUB_LIB_SPEC=\"${TCL_STUB_LIB_SPEC}\"" + + + + + + + + + + + + + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking platform" >&5 +$as_echo_n "checking platform... " >&6; } + hold_cc=$CC; CC="$TCL_CC" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + #ifdef _WIN32 + #error win32 + #endif + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + + TEA_PLATFORM="unix" + CYGPATH=echo + +else + + TEA_PLATFORM="windows" + # Extract the first word of "cygpath", so it can be a program name with args. +set dummy cygpath; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_CYGPATH+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$CYGPATH"; then + ac_cv_prog_CYGPATH="$CYGPATH" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_CYGPATH="cygpath -m" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + + test -z "$ac_cv_prog_CYGPATH" && ac_cv_prog_CYGPATH="echo" +fi +fi +CYGPATH=$ac_cv_prog_CYGPATH +if test -n "$CYGPATH"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CYGPATH" >&5 +$as_echo "$CYGPATH" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + CC=$hold_cc + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $TEA_PLATFORM" >&5 +$as_echo "$TEA_PLATFORM" >&6; } + + # The BUILD_$pkg is to define the correct extern storage class + # handling when making this package + +cat >>confdefs.h <<_ACEOF +#define BUILD_${PACKAGE_NAME} /**/ +_ACEOF + + # Do this here as we have fully defined TEA_PLATFORM now + if test "${TEA_PLATFORM}" = "windows" ; then + EXEEXT=".exe" + CLEANFILES="$CLEANFILES *.lib *.dll *.pdb *.exp" + fi + + # TEA specific: + + + + + + + + +#-------------------------------------------------------------------- +# Load the tkConfig.sh file if necessary (Tk extension) +#-------------------------------------------------------------------- + +#TEA_PATH_TKCONFIG +#TEA_LOAD_TKCONFIG + +#----------------------------------------------------------------------- +# Handle the --prefix=... option by defaulting to what Tcl gave. +# Must be called after TEA_LOAD_TCLCONFIG and before TEA_SETUP_COMPILER. +#----------------------------------------------------------------------- + + + if test "${prefix}" = "NONE"; then + prefix_default=yes + if test x"${TCL_PREFIX}" != x; then + { $as_echo "$as_me:${as_lineno-$LINENO}: --prefix defaulting to TCL_PREFIX ${TCL_PREFIX}" >&5 +$as_echo "$as_me: --prefix defaulting to TCL_PREFIX ${TCL_PREFIX}" >&6;} + prefix=${TCL_PREFIX} + else + { $as_echo "$as_me:${as_lineno-$LINENO}: --prefix defaulting to /usr/local" >&5 +$as_echo "$as_me: --prefix defaulting to /usr/local" >&6;} + prefix=/usr/local + fi + fi + if test "${exec_prefix}" = "NONE" -a x"${prefix_default}" = x"yes" \ + -o x"${exec_prefix_default}" = x"yes" ; then + if test x"${TCL_EXEC_PREFIX}" != x; then + { $as_echo "$as_me:${as_lineno-$LINENO}: --exec-prefix defaulting to TCL_EXEC_PREFIX ${TCL_EXEC_PREFIX}" >&5 +$as_echo "$as_me: --exec-prefix defaulting to TCL_EXEC_PREFIX ${TCL_EXEC_PREFIX}" >&6;} + exec_prefix=${TCL_EXEC_PREFIX} + else + { $as_echo "$as_me:${as_lineno-$LINENO}: --exec-prefix defaulting to ${prefix}" >&5 +$as_echo "$as_me: --exec-prefix defaulting to ${prefix}" >&6;} + exec_prefix=$prefix + fi + fi + + +#----------------------------------------------------------------------- +# Standard compiler checks. +# This sets up CC by using the CC env var, or looks for gcc otherwise. +# This also calls AC_PROG_CC and a few others to create the basic setup +# necessary to compile executables. +#----------------------------------------------------------------------- + + + # Don't put any macros that use the compiler (e.g. AC_TRY_COMPILE) + # in this macro, they need to go into TEA_SETUP_COMPILER instead. + + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu +if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}gcc", so it can be a program name with args. +set dummy ${ac_tool_prefix}gcc; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_CC+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$CC"; then + ac_cv_prog_CC="$CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_CC="${ac_tool_prefix}gcc" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +CC=$ac_cv_prog_CC +if test -n "$CC"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 +$as_echo "$CC" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_prog_CC"; then + ac_ct_CC=$CC + # Extract the first word of "gcc", so it can be a program name with args. +set dummy gcc; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_ac_ct_CC+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_CC"; then + ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_ac_ct_CC="gcc" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_CC=$ac_cv_prog_ac_ct_CC +if test -n "$ac_ct_CC"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5 +$as_echo "$ac_ct_CC" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_ct_CC" = x; then + CC="" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + CC=$ac_ct_CC + fi +else + CC="$ac_cv_prog_CC" +fi + +if test -z "$CC"; then + if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}cc", so it can be a program name with args. +set dummy ${ac_tool_prefix}cc; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_CC+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$CC"; then + ac_cv_prog_CC="$CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_CC="${ac_tool_prefix}cc" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +CC=$ac_cv_prog_CC +if test -n "$CC"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 +$as_echo "$CC" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + fi +fi +if test -z "$CC"; then + # Extract the first word of "cc", so it can be a program name with args. +set dummy cc; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_CC+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$CC"; then + ac_cv_prog_CC="$CC" # Let the user override the test. +else + ac_prog_rejected=no +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if test "$as_dir/$ac_word$ac_exec_ext" = "/usr/ucb/cc"; then + ac_prog_rejected=yes + continue + fi + ac_cv_prog_CC="cc" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +if test $ac_prog_rejected = yes; then + # We found a bogon in the path, so make sure we never use it. + set dummy $ac_cv_prog_CC + shift + if test $# != 0; then + # We chose a different compiler from the bogus one. + # However, it has the same basename, so the bogon will be chosen + # first if we set CC to just the basename; use the full file name. + shift + ac_cv_prog_CC="$as_dir/$ac_word${1+' '}$@" + fi +fi +fi +fi +CC=$ac_cv_prog_CC +if test -n "$CC"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 +$as_echo "$CC" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$CC"; then + if test -n "$ac_tool_prefix"; then + for ac_prog in cl.exe + do + # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args. +set dummy $ac_tool_prefix$ac_prog; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_CC+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$CC"; then + ac_cv_prog_CC="$CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_CC="$ac_tool_prefix$ac_prog" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +CC=$ac_cv_prog_CC +if test -n "$CC"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 +$as_echo "$CC" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + test -n "$CC" && break + done +fi +if test -z "$CC"; then + ac_ct_CC=$CC + for ac_prog in cl.exe +do + # Extract the first word of "$ac_prog", so it can be a program name with args. +set dummy $ac_prog; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_ac_ct_CC+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_CC"; then + ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_ac_ct_CC="$ac_prog" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_CC=$ac_cv_prog_ac_ct_CC +if test -n "$ac_ct_CC"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5 +$as_echo "$ac_ct_CC" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + test -n "$ac_ct_CC" && break +done + + if test "x$ac_ct_CC" = x; then + CC="" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + CC=$ac_ct_CC + fi +fi + +fi + + +test -z "$CC" && { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error $? "no acceptable C compiler found in \$PATH +See \`config.log' for more details" "$LINENO" 5; } + +# Provide some information about the compiler. +$as_echo "$as_me:${as_lineno-$LINENO}: checking for C compiler version" >&5 +set X $ac_compile +ac_compiler=$2 +for ac_option in --version -v -V -qversion; do + { { ac_try="$ac_compiler $ac_option >&5" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_compiler $ac_option >&5") 2>conftest.err + ac_status=$? + if test -s conftest.err; then + sed '10a\ +... rest of stderr output deleted ... + 10q' conftest.err >conftest.er1 + cat conftest.er1 >&5 + fi + rm -f conftest.er1 conftest.err + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } +done + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are using the GNU C compiler" >&5 +$as_echo_n "checking whether we are using the GNU C compiler... " >&6; } +if ${ac_cv_c_compiler_gnu+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ +#ifndef __GNUC__ + choke me +#endif + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_compiler_gnu=yes +else + ac_compiler_gnu=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +ac_cv_c_compiler_gnu=$ac_compiler_gnu + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_compiler_gnu" >&5 +$as_echo "$ac_cv_c_compiler_gnu" >&6; } +if test $ac_compiler_gnu = yes; then + GCC=yes +else + GCC= +fi +ac_test_CFLAGS=${CFLAGS+set} +ac_save_CFLAGS=$CFLAGS +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC accepts -g" >&5 +$as_echo_n "checking whether $CC accepts -g... " >&6; } +if ${ac_cv_prog_cc_g+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_save_c_werror_flag=$ac_c_werror_flag + ac_c_werror_flag=yes + ac_cv_prog_cc_g=no + CFLAGS="-g" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_cv_prog_cc_g=yes +else + CFLAGS="" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + +else + ac_c_werror_flag=$ac_save_c_werror_flag + CFLAGS="-g" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_cv_prog_cc_g=yes +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + ac_c_werror_flag=$ac_save_c_werror_flag +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_g" >&5 +$as_echo "$ac_cv_prog_cc_g" >&6; } +if test "$ac_test_CFLAGS" = set; then + CFLAGS=$ac_save_CFLAGS +elif test $ac_cv_prog_cc_g = yes; then + if test "$GCC" = yes; then + CFLAGS="-g -O2" + else + CFLAGS="-g" + fi +else + if test "$GCC" = yes; then + CFLAGS="-O2" + else + CFLAGS= + fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $CC option to accept ISO C89" >&5 +$as_echo_n "checking for $CC option to accept ISO C89... " >&6; } +if ${ac_cv_prog_cc_c89+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_cv_prog_cc_c89=no +ac_save_CC=$CC +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +#include +struct stat; +/* Most of the following tests are stolen from RCS 5.7's src/conf.sh. */ +struct buf { int x; }; +FILE * (*rcsopen) (struct buf *, struct stat *, int); +static char *e (p, i) + char **p; + int i; +{ + return p[i]; +} +static char *f (char * (*g) (char **, int), char **p, ...) +{ + char *s; + va_list v; + va_start (v,p); + s = g (p, va_arg (v,int)); + va_end (v); + return s; +} + +/* OSF 4.0 Compaq cc is some sort of almost-ANSI by default. It has + function prototypes and stuff, but not '\xHH' hex character constants. + These don't provoke an error unfortunately, instead are silently treated + as 'x'. The following induces an error, until -std is added to get + proper ANSI mode. Curiously '\x00'!='x' always comes out true, for an + array size at least. It's necessary to write '\x00'==0 to get something + that's true only with -std. */ +int osf4_cc_array ['\x00' == 0 ? 1 : -1]; + +/* IBM C 6 for AIX is almost-ANSI by default, but it replaces macro parameters + inside strings and character constants. */ +#define FOO(x) 'x' +int xlc6_cc_array[FOO(a) == 'x' ? 1 : -1]; + +int test (int i, double x); +struct s1 {int (*f) (int a);}; +struct s2 {int (*f) (double a);}; +int pairnames (int, char **, FILE *(*)(struct buf *, struct stat *, int), int, int); +int argc; +char **argv; +int +main () +{ +return f (e, argv, 0) != argv[0] || f (e, argv, 1) != argv[1]; + ; + return 0; +} +_ACEOF +for ac_arg in '' -qlanglvl=extc89 -qlanglvl=ansi -std \ + -Ae "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__" +do + CC="$ac_save_CC $ac_arg" + if ac_fn_c_try_compile "$LINENO"; then : + ac_cv_prog_cc_c89=$ac_arg +fi +rm -f core conftest.err conftest.$ac_objext + test "x$ac_cv_prog_cc_c89" != "xno" && break +done +rm -f conftest.$ac_ext +CC=$ac_save_CC + +fi +# AC_CACHE_VAL +case "x$ac_cv_prog_cc_c89" in + x) + { $as_echo "$as_me:${as_lineno-$LINENO}: result: none needed" >&5 +$as_echo "none needed" >&6; } ;; + xno) + { $as_echo "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5 +$as_echo "unsupported" >&6; } ;; + *) + CC="$CC $ac_cv_prog_cc_c89" + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_c89" >&5 +$as_echo "$ac_cv_prog_cc_c89" >&6; } ;; +esac +if test "x$ac_cv_prog_cc_c89" != xno; then : + +fi + +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking how to run the C preprocessor" >&5 +$as_echo_n "checking how to run the C preprocessor... " >&6; } +# On Suns, sometimes $CPP names a directory. +if test -n "$CPP" && test -d "$CPP"; then + CPP= +fi +if test -z "$CPP"; then + if ${ac_cv_prog_CPP+:} false; then : + $as_echo_n "(cached) " >&6 +else + # Double quotes because CPP needs to be expanded + for CPP in "$CC -E" "$CC -E -traditional-cpp" "/lib/cpp" + do + ac_preproc_ok=false +for ac_c_preproc_warn_flag in '' yes +do + # Use a header file that comes with gcc, so configuring glibc + # with a fresh cross-compiler works. + # Prefer to if __STDC__ is defined, since + # exists even on freestanding compilers. + # On the NeXT, cc -E runs the code through the compiler's parser, + # not just through cpp. "Syntax error" is here to catch this case. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#ifdef __STDC__ +# include +#else +# include +#endif + Syntax error +_ACEOF +if ac_fn_c_try_cpp "$LINENO"; then : + +else + # Broken: fails on valid input. +continue +fi +rm -f conftest.err conftest.i conftest.$ac_ext + + # OK, works on sane cases. Now check whether nonexistent headers + # can be detected and how. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +_ACEOF +if ac_fn_c_try_cpp "$LINENO"; then : + # Broken: success on invalid input. +continue +else + # Passes both tests. +ac_preproc_ok=: +break +fi +rm -f conftest.err conftest.i conftest.$ac_ext + +done +# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. +rm -f conftest.i conftest.err conftest.$ac_ext +if $ac_preproc_ok; then : + break +fi + + done + ac_cv_prog_CPP=$CPP + +fi + CPP=$ac_cv_prog_CPP +else + ac_cv_prog_CPP=$CPP +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $CPP" >&5 +$as_echo "$CPP" >&6; } +ac_preproc_ok=false +for ac_c_preproc_warn_flag in '' yes +do + # Use a header file that comes with gcc, so configuring glibc + # with a fresh cross-compiler works. + # Prefer to if __STDC__ is defined, since + # exists even on freestanding compilers. + # On the NeXT, cc -E runs the code through the compiler's parser, + # not just through cpp. "Syntax error" is here to catch this case. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#ifdef __STDC__ +# include +#else +# include +#endif + Syntax error +_ACEOF +if ac_fn_c_try_cpp "$LINENO"; then : + +else + # Broken: fails on valid input. +continue +fi +rm -f conftest.err conftest.i conftest.$ac_ext + + # OK, works on sane cases. Now check whether nonexistent headers + # can be detected and how. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +_ACEOF +if ac_fn_c_try_cpp "$LINENO"; then : + # Broken: success on invalid input. +continue +else + # Passes both tests. +ac_preproc_ok=: +break +fi +rm -f conftest.err conftest.i conftest.$ac_ext + +done +# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. +rm -f conftest.i conftest.err conftest.$ac_ext +if $ac_preproc_ok; then : + +else + { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error $? "C preprocessor \"$CPP\" fails sanity check +See \`config.log' for more details" "$LINENO" 5; } +fi + +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + + #-------------------------------------------------------------------- + # Checks to see if the make program sets the $MAKE variable. + #-------------------------------------------------------------------- + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${MAKE-make} sets \$(MAKE)" >&5 +$as_echo_n "checking whether ${MAKE-make} sets \$(MAKE)... " >&6; } +set x ${MAKE-make} +ac_make=`$as_echo "$2" | sed 's/+/p/g; s/[^a-zA-Z0-9_]/_/g'` +if eval \${ac_cv_prog_make_${ac_make}_set+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat >conftest.make <<\_ACEOF +SHELL = /bin/sh +all: + @echo '@@@%%%=$(MAKE)=@@@%%%' +_ACEOF +# GNU make sometimes prints "make[1]: Entering ...", which would confuse us. +case `${MAKE-make} -f conftest.make 2>/dev/null` in + *@@@%%%=?*=@@@%%%*) + eval ac_cv_prog_make_${ac_make}_set=yes;; + *) + eval ac_cv_prog_make_${ac_make}_set=no;; +esac +rm -f conftest.make +fi +if eval test \$ac_cv_prog_make_${ac_make}_set = yes; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + SET_MAKE= +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + SET_MAKE="MAKE=${MAKE-make}" +fi + + + #-------------------------------------------------------------------- + # Find ranlib + #-------------------------------------------------------------------- + + if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}ranlib", so it can be a program name with args. +set dummy ${ac_tool_prefix}ranlib; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_RANLIB+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$RANLIB"; then + ac_cv_prog_RANLIB="$RANLIB" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_RANLIB="${ac_tool_prefix}ranlib" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +RANLIB=$ac_cv_prog_RANLIB +if test -n "$RANLIB"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $RANLIB" >&5 +$as_echo "$RANLIB" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_prog_RANLIB"; then + ac_ct_RANLIB=$RANLIB + # Extract the first word of "ranlib", so it can be a program name with args. +set dummy ranlib; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_ac_ct_RANLIB+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_RANLIB"; then + ac_cv_prog_ac_ct_RANLIB="$ac_ct_RANLIB" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_ac_ct_RANLIB="ranlib" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_RANLIB=$ac_cv_prog_ac_ct_RANLIB +if test -n "$ac_ct_RANLIB"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_RANLIB" >&5 +$as_echo "$ac_ct_RANLIB" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_ct_RANLIB" = x; then + RANLIB="" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + RANLIB=$ac_ct_RANLIB + fi +else + RANLIB="$ac_cv_prog_RANLIB" +fi + + + #-------------------------------------------------------------------- + # Determines the correct binary file extension (.o, .obj, .exe etc.) + #-------------------------------------------------------------------- + + + + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for grep that handles long lines and -e" >&5 +$as_echo_n "checking for grep that handles long lines and -e... " >&6; } +if ${ac_cv_path_GREP+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -z "$GREP"; then + ac_path_GREP_found=false + # Loop through the user's path and test for each of PROGNAME-LIST + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_prog in grep ggrep; do + for ac_exec_ext in '' $ac_executable_extensions; do + ac_path_GREP="$as_dir/$ac_prog$ac_exec_ext" + as_fn_executable_p "$ac_path_GREP" || continue +# Check for GNU ac_path_GREP and select it if it is found. + # Check for GNU $ac_path_GREP +case `"$ac_path_GREP" --version 2>&1` in +*GNU*) + ac_cv_path_GREP="$ac_path_GREP" ac_path_GREP_found=:;; +*) + ac_count=0 + $as_echo_n 0123456789 >"conftest.in" + while : + do + cat "conftest.in" "conftest.in" >"conftest.tmp" + mv "conftest.tmp" "conftest.in" + cp "conftest.in" "conftest.nl" + $as_echo 'GREP' >> "conftest.nl" + "$ac_path_GREP" -e 'GREP$' -e '-(cannot match)-' < "conftest.nl" >"conftest.out" 2>/dev/null || break + diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break + as_fn_arith $ac_count + 1 && ac_count=$as_val + if test $ac_count -gt ${ac_path_GREP_max-0}; then + # Best one so far, save it but keep looking for a better one + ac_cv_path_GREP="$ac_path_GREP" + ac_path_GREP_max=$ac_count + fi + # 10*(2^10) chars as input seems more than enough + test $ac_count -gt 10 && break + done + rm -f conftest.in conftest.tmp conftest.nl conftest.out;; +esac + + $ac_path_GREP_found && break 3 + done + done + done +IFS=$as_save_IFS + if test -z "$ac_cv_path_GREP"; then + as_fn_error $? "no acceptable grep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" "$LINENO" 5 + fi +else + ac_cv_path_GREP=$GREP +fi + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_GREP" >&5 +$as_echo "$ac_cv_path_GREP" >&6; } + GREP="$ac_cv_path_GREP" + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for egrep" >&5 +$as_echo_n "checking for egrep... " >&6; } +if ${ac_cv_path_EGREP+:} false; then : + $as_echo_n "(cached) " >&6 +else + if echo a | $GREP -E '(a|b)' >/dev/null 2>&1 + then ac_cv_path_EGREP="$GREP -E" + else + if test -z "$EGREP"; then + ac_path_EGREP_found=false + # Loop through the user's path and test for each of PROGNAME-LIST + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_prog in egrep; do + for ac_exec_ext in '' $ac_executable_extensions; do + ac_path_EGREP="$as_dir/$ac_prog$ac_exec_ext" + as_fn_executable_p "$ac_path_EGREP" || continue +# Check for GNU ac_path_EGREP and select it if it is found. + # Check for GNU $ac_path_EGREP +case `"$ac_path_EGREP" --version 2>&1` in +*GNU*) + ac_cv_path_EGREP="$ac_path_EGREP" ac_path_EGREP_found=:;; +*) + ac_count=0 + $as_echo_n 0123456789 >"conftest.in" + while : + do + cat "conftest.in" "conftest.in" >"conftest.tmp" + mv "conftest.tmp" "conftest.in" + cp "conftest.in" "conftest.nl" + $as_echo 'EGREP' >> "conftest.nl" + "$ac_path_EGREP" 'EGREP$' < "conftest.nl" >"conftest.out" 2>/dev/null || break + diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break + as_fn_arith $ac_count + 1 && ac_count=$as_val + if test $ac_count -gt ${ac_path_EGREP_max-0}; then + # Best one so far, save it but keep looking for a better one + ac_cv_path_EGREP="$ac_path_EGREP" + ac_path_EGREP_max=$ac_count + fi + # 10*(2^10) chars as input seems more than enough + test $ac_count -gt 10 && break + done + rm -f conftest.in conftest.tmp conftest.nl conftest.out;; +esac + + $ac_path_EGREP_found && break 3 + done + done + done +IFS=$as_save_IFS + if test -z "$ac_cv_path_EGREP"; then + as_fn_error $? "no acceptable egrep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" "$LINENO" 5 + fi +else + ac_cv_path_EGREP=$EGREP +fi + + fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_EGREP" >&5 +$as_echo "$ac_cv_path_EGREP" >&6; } + EGREP="$ac_cv_path_EGREP" + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for ANSI C header files" >&5 +$as_echo_n "checking for ANSI C header files... " >&6; } +if ${ac_cv_header_stdc+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +#include +#include +#include + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_cv_header_stdc=yes +else + ac_cv_header_stdc=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + +if test $ac_cv_header_stdc = yes; then + # SunOS 4.x string.h does not declare mem*, contrary to ANSI. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include + +_ACEOF +if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | + $EGREP "memchr" >/dev/null 2>&1; then : + +else + ac_cv_header_stdc=no +fi +rm -f conftest* + +fi + +if test $ac_cv_header_stdc = yes; then + # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include + +_ACEOF +if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | + $EGREP "free" >/dev/null 2>&1; then : + +else + ac_cv_header_stdc=no +fi +rm -f conftest* + +fi + +if test $ac_cv_header_stdc = yes; then + # /bin/cc in Irix-4.0.5 gets non-ANSI ctype macros unless using -ansi. + if test "$cross_compiling" = yes; then : + : +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +#include +#if ((' ' & 0x0FF) == 0x020) +# define ISLOWER(c) ('a' <= (c) && (c) <= 'z') +# define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c)) +#else +# define ISLOWER(c) \ + (('a' <= (c) && (c) <= 'i') \ + || ('j' <= (c) && (c) <= 'r') \ + || ('s' <= (c) && (c) <= 'z')) +# define TOUPPER(c) (ISLOWER(c) ? ((c) | 0x40) : (c)) +#endif + +#define XOR(e, f) (((e) && !(f)) || (!(e) && (f))) +int +main () +{ + int i; + for (i = 0; i < 256; i++) + if (XOR (islower (i), ISLOWER (i)) + || toupper (i) != TOUPPER (i)) + return 2; + return 0; +} +_ACEOF +if ac_fn_c_try_run "$LINENO"; then : + +else + ac_cv_header_stdc=no +fi +rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ + conftest.$ac_objext conftest.beam conftest.$ac_ext +fi + +fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_header_stdc" >&5 +$as_echo "$ac_cv_header_stdc" >&6; } +if test $ac_cv_header_stdc = yes; then + +$as_echo "#define STDC_HEADERS 1" >>confdefs.h + +fi + +# On IRIX 5.3, sys/types and inttypes.h are conflicting. +for ac_header in sys/types.h sys/stat.h stdlib.h string.h memory.h strings.h \ + inttypes.h stdint.h unistd.h +do : + as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` +ac_fn_c_check_header_compile "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default +" +if eval test \"x\$"$as_ac_Header"\" = x"yes"; then : + cat >>confdefs.h <<_ACEOF +#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1 +_ACEOF + +fi + +done + + + + # Any macros that use the compiler (e.g. AC_TRY_COMPILE) have to go here. + + + #------------------------------------------------------------------------ + # If we're using GCC, see if the compiler understands -pipe. If so, use it. + # It makes compiling go faster. (This is only a performance feature.) + #------------------------------------------------------------------------ + + if test -z "$no_pipe" -a -n "$GCC"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: checking if the compiler understands -pipe" >&5 +$as_echo_n "checking if the compiler understands -pipe... " >&6; } +if ${tcl_cv_cc_pipe+:} false; then : + $as_echo_n "(cached) " >&6 +else + + hold_cflags=$CFLAGS; CFLAGS="$CFLAGS -pipe" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + tcl_cv_cc_pipe=yes +else + tcl_cv_cc_pipe=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + CFLAGS=$hold_cflags +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_cc_pipe" >&5 +$as_echo "$tcl_cv_cc_pipe" >&6; } + if test $tcl_cv_cc_pipe = yes; then + CFLAGS="$CFLAGS -pipe" + fi + fi + + #-------------------------------------------------------------------- + # Common compiler flag setup + #-------------------------------------------------------------------- + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether byte ordering is bigendian" >&5 +$as_echo_n "checking whether byte ordering is bigendian... " >&6; } +if ${ac_cv_c_bigendian+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_cv_c_bigendian=unknown + # See if we're dealing with a universal compiler. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#ifndef __APPLE_CC__ + not a universal capable compiler + #endif + typedef int dummy; + +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + + # Check for potential -arch flags. It is not universal unless + # there are at least two -arch flags with different values. + ac_arch= + ac_prev= + for ac_word in $CC $CFLAGS $CPPFLAGS $LDFLAGS; do + if test -n "$ac_prev"; then + case $ac_word in + i?86 | x86_64 | ppc | ppc64) + if test -z "$ac_arch" || test "$ac_arch" = "$ac_word"; then + ac_arch=$ac_word + else + ac_cv_c_bigendian=universal + break + fi + ;; + esac + ac_prev= + elif test "x$ac_word" = "x-arch"; then + ac_prev=arch + fi + done +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + if test $ac_cv_c_bigendian = unknown; then + # See if sys/param.h defines the BYTE_ORDER macro. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include + #include + +int +main () +{ +#if ! (defined BYTE_ORDER && defined BIG_ENDIAN \ + && defined LITTLE_ENDIAN && BYTE_ORDER && BIG_ENDIAN \ + && LITTLE_ENDIAN) + bogus endian macros + #endif + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + # It does; now see whether it defined to BIG_ENDIAN or not. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include + #include + +int +main () +{ +#if BYTE_ORDER != BIG_ENDIAN + not big endian + #endif + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_cv_c_bigendian=yes +else + ac_cv_c_bigendian=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + fi + if test $ac_cv_c_bigendian = unknown; then + # See if defines _LITTLE_ENDIAN or _BIG_ENDIAN (e.g., Solaris). + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include + +int +main () +{ +#if ! (defined _LITTLE_ENDIAN || defined _BIG_ENDIAN) + bogus endian macros + #endif + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + # It does; now see whether it defined to _BIG_ENDIAN or not. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include + +int +main () +{ +#ifndef _BIG_ENDIAN + not big endian + #endif + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_cv_c_bigendian=yes +else + ac_cv_c_bigendian=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + fi + if test $ac_cv_c_bigendian = unknown; then + # Compile a test program. + if test "$cross_compiling" = yes; then : + # Try to guess by grepping values from an object file. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +short int ascii_mm[] = + { 0x4249, 0x4765, 0x6E44, 0x6961, 0x6E53, 0x7953, 0 }; + short int ascii_ii[] = + { 0x694C, 0x5454, 0x656C, 0x6E45, 0x6944, 0x6E61, 0 }; + int use_ascii (int i) { + return ascii_mm[i] + ascii_ii[i]; + } + short int ebcdic_ii[] = + { 0x89D3, 0xE3E3, 0x8593, 0x95C5, 0x89C4, 0x9581, 0 }; + short int ebcdic_mm[] = + { 0xC2C9, 0xC785, 0x95C4, 0x8981, 0x95E2, 0xA8E2, 0 }; + int use_ebcdic (int i) { + return ebcdic_mm[i] + ebcdic_ii[i]; + } + extern int foo; + +int +main () +{ +return use_ascii (foo) == use_ebcdic (foo); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + if grep BIGenDianSyS conftest.$ac_objext >/dev/null; then + ac_cv_c_bigendian=yes + fi + if grep LiTTleEnDian conftest.$ac_objext >/dev/null ; then + if test "$ac_cv_c_bigendian" = unknown; then + ac_cv_c_bigendian=no + else + # finding both strings is unlikely to happen, but who knows? + ac_cv_c_bigendian=unknown + fi + fi +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +$ac_includes_default +int +main () +{ + + /* Are we little or big endian? From Harbison&Steele. */ + union + { + long int l; + char c[sizeof (long int)]; + } u; + u.l = 1; + return u.c[sizeof (long int) - 1] == 1; + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_run "$LINENO"; then : + ac_cv_c_bigendian=no +else + ac_cv_c_bigendian=yes +fi +rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ + conftest.$ac_objext conftest.beam conftest.$ac_ext +fi + + fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_bigendian" >&5 +$as_echo "$ac_cv_c_bigendian" >&6; } + case $ac_cv_c_bigendian in #( + yes) + $as_echo "#define WORDS_BIGENDIAN 1" >>confdefs.h +;; #( + no) + ;; #( + universal) + +$as_echo "#define AC_APPLE_UNIVERSAL_BUILD 1" >>confdefs.h + + ;; #( + *) + as_fn_error $? "unknown endianness + presetting ac_cv_c_bigendian=no (or yes) will help" "$LINENO" 5 ;; + esac + + + +#-------------------------------------------------------------------- +# Load the tdomConfig.sh file +#-------------------------------------------------------------------- + + + if test x"${no_tdom}" = x ; then + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for tDOM configuration" >&5 +$as_echo_n "checking for tDOM configuration... " >&6; } + +# Check whether --with-tdom was given. +if test "${with_tdom+set}" = set; then : + withval=$with_tdom; with_tdomconfig=${withval} +fi + + + no_tdom=true + if test "${TEA_PLATFORM}" = "windows" ; then + tdom_bindir=win + else + tdom_bindir=unix + fi + + if ${ac_cv_c_tdomconfig+:} false; then : + $as_echo_n "(cached) " >&6 +else + + + # First check to see if --with-tdom was specified. + if test x"${with_tdomconfig}" != x ; then + if test -f "${with_tdomconfig}/tdomConfig.sh" ; then + ac_cv_c_tdomconfig=`(cd ${with_tdomconfig}; pwd)` + else + as_fn_error $? "${with_tdomconfig} directory doesn't contain tdomConfig.sh" "$LINENO" 5 + fi + fi + # Then check for a sibling installation + if test x"${ac_cv_c_tdomconfig}" = x ; then + for i in \ + ../tdom `ls -dr ../tdom-* 2>/dev/null` \ + ../../tdom `ls -dr ../../tdom-* 2>/dev/null` \ + ../../../tdom `ls -dr ../../../tdom-* 2>/dev/null` ; do + if test -f "$i/$tdom_bindir/tdomConfig.sh" ; then + ac_cv_c_tdomconfig=`(cd $i/$tdom_bindir; pwd)` + fi + done + fi + # Then check if tnc/tdom are compilied in the source tree + if test x"${ac_cv_c_tdomconfig}" = x ; then + if test -f "../../$tdom_bindir/tdomConfig.sh" ; then + ac_cv_c_tdomconfig=`(cd ../../$tdom_bindir; pwd)` + fi + fi + # Check in a few common install locations + if test x"${ac_cv_c_tdomconfig}" = x ; then + for i in \ + `ls -d ${prefix}/lib 2>/dev/null` \ + `ls -d /usr/local/lib 2>/dev/null` ; do + if test -f "$i/tdomConfig.sh" ; then + ac_cv_c_tdomconfig=`(cd $i; pwd)` + fi + done + fi + # Check in a few other private locations + if test x"${ac_cv_c_tdomconfig}" = x ; then + for i in \ + ${srcdir}/../tdom \ + `ls -dr ${srcdir}/../tdom[0-9].[0-9]* 2>/dev/null` ; do + if test -f "$i/$tdom_bindir/tdomConfig.sh" ; then + ac_cv_c_tdomconfig=`(cd $i/$tdom_bindir; pwd)` + fi + done + fi + +fi + + if test x"${ac_cv_c_tdomconfig}" = x ; then + TDOM_BIN_DIR="# no tDOM configuration file found" + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Can't find tDOM configuration definitions" >&5 +$as_echo "$as_me: WARNING: Can't find tDOM configuration definitions" >&2;} + exit 0 + else + no_tdom= + TDOM_BIN_DIR=${ac_cv_c_tdomconfig} + { $as_echo "$as_me:${as_lineno-$LINENO}: result: found $TDOM_BIN_DIR/tdomConfig.sh" >&5 +$as_echo "found $TDOM_BIN_DIR/tdomConfig.sh" >&6; } + fi + fi + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for existence of $TDOM_BIN_DIR/tdomConfig.sh" >&5 +$as_echo_n "checking for existence of $TDOM_BIN_DIR/tdomConfig.sh... " >&6; } + if test -f "$TDOM_BIN_DIR/tdomConfig.sh" ; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: loading" >&5 +$as_echo "loading" >&6; } + . $TDOM_BIN_DIR/tdomConfig.sh + else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: file not found" >&5 +$as_echo "file not found" >&6; } + fi + if test -f "${TDOM_BIN_DIR}/Makefile" ; then + TDOM_STUB_LIB_SPEC=${TDOM_BUILD_STUB_LIB_SPEC} + fi + + + + + +#----------------------------------------------------------------------- +# __CHANGE__ +# Specify the C source files to compile in TEA_ADD_SOURCES, +# public headers that need to be installed in TEA_ADD_HEADERS, +# stub library C source files to compile in TEA_ADD_STUB_SOURCES, +# and runtime Tcl library files in TEA_ADD_TCL_SOURCES. +# This defines PKG(_STUB)_SOURCES, PKG(_STUB)_OBJECTS, PKG_HEADERS +# and PKG_TCL_SOURCES. +#----------------------------------------------------------------------- + + + vars="schemadtx.c" + for i in $vars; do + case $i in + \$*) + # allow $-var names + PKG_SOURCES="$PKG_SOURCES $i" + PKG_OBJECTS="$PKG_OBJECTS $i" + ;; + *) + # check for existence - allows for generic/win/unix VPATH + # To add more dirs here (like 'src'), you have to update VPATH + # in Makefile.in as well + if test ! -f "${srcdir}/$i" -a ! -f "${srcdir}/generic/$i" \ + -a ! -f "${srcdir}/win/$i" -a ! -f "${srcdir}/unix/$i" \ + -a ! -f "${srcdir}/macosx/$i" \ + ; then + as_fn_error $? "could not find source file '$i'" "$LINENO" 5 + fi + PKG_SOURCES="$PKG_SOURCES $i" + # this assumes it is in a VPATH dir + i=`basename $i` + # handle user calling this before or after TEA_SETUP_COMPILER + if test x"${OBJEXT}" != x ; then + j="`echo $i | sed -e 's/\.[^.]*$//'`.${OBJEXT}" + else + j="`echo $i | sed -e 's/\.[^.]*$//'`.\${OBJEXT}" + fi + PKG_OBJECTS="$PKG_OBJECTS $j" + ;; + esac + done + + + + + vars="" + for i in $vars; do + # check for existence, be strict because it is installed + if test ! -f "${srcdir}/$i" ; then + as_fn_error $? "could not find header file '${srcdir}/$i'" "$LINENO" 5 + fi + PKG_HEADERS="$PKG_HEADERS $i" + done + + + + vars="-I${srcdir}/../../generic -I${srcdir}/../../expat" + for i in $vars; do + PKG_INCLUDES="$PKG_INCLUDES $i" + done + + + + vars="${TDOM_STUB_LIB_SPEC}" + for i in $vars; do + if test "${TEA_PLATFORM}" = "windows" -a "$GCC" = "yes" ; then + # Convert foo.lib to -lfoo for GCC. No-op if not *.lib + i=`echo "$i" | sed -e 's/^\([^-].*\)\.lib$/-l\1/i'` + fi + PKG_LIBS="$PKG_LIBS $i" + done + + + + PKG_CFLAGS="$PKG_CFLAGS -DUSE_TDOM_STUBS=1" + + + + vars="" + for i in $vars; do + # check for existence - allows for generic/win/unix VPATH + if test ! -f "${srcdir}/$i" -a ! -f "${srcdir}/generic/$i" \ + -a ! -f "${srcdir}/win/$i" -a ! -f "${srcdir}/unix/$i" \ + -a ! -f "${srcdir}/macosx/$i" \ + ; then + as_fn_error $? "could not find stub source file '$i'" "$LINENO" 5 + fi + PKG_STUB_SOURCES="$PKG_STUB_SOURCES $i" + # this assumes it is in a VPATH dir + i=`basename $i` + # handle user calling this before or after TEA_SETUP_COMPILER + if test x"${OBJEXT}" != x ; then + j="`echo $i | sed -e 's/\.[^.]*$//'`.${OBJEXT}" + else + j="`echo $i | sed -e 's/\.[^.]*$//'`.\${OBJEXT}" + fi + PKG_STUB_OBJECTS="$PKG_STUB_OBJECTS $j" + done + + + + + vars="" + for i in $vars; do + # check for existence, be strict because it is installed + if test ! -f "${srcdir}/$i" ; then + as_fn_error $? "could not find tcl source file '${srcdir}/$i'" "$LINENO" 5 + fi + PKG_TCL_SOURCES="$PKG_TCL_SOURCES $i" + done + + + +#-------------------------------------------------------------------- +# __CHANGE__ +# +# You can add more files to clean if your extension creates any extra +# files by extending CLEANFILES. +# Add pkgIndex.tcl if it is generated in the Makefile instead of ./configure +# and change Makefile.in to move it from CONFIG_CLEAN_FILES to BINARIES var. +# +# A few miscellaneous platform-specific items: +# TEA_ADD_* any platform specific compiler/build info here. +#-------------------------------------------------------------------- + +#CLEANFILES="$CLEANFILES pkgIndex.tcl" +if test "${TEA_PLATFORM}" = "windows" ; then + # Ensure no empty if clauses + : + #TEA_ADD_SOURCES([win/winFile.c]) + #TEA_ADD_INCLUDES([-I\"$(${CYGPATH} ${srcdir}/win)\"]) +else + # Ensure no empty else clauses + : + #TEA_ADD_SOURCES([unix/unixFile.c]) + #TEA_ADD_LIBS([-lsuperfly]) +fi + +#-------------------------------------------------------------------- +# __CHANGE__ +# Choose which headers you need. Extension authors should try very +# hard to only rely on the Tcl public header files. Internal headers +# contain private data structures and are subject to change without +# notice. +# This MUST be called after TEA_LOAD_TCLCONFIG / TEA_LOAD_TKCONFIG +#-------------------------------------------------------------------- + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for Tcl public headers" >&5 +$as_echo_n "checking for Tcl public headers... " >&6; } + + +# Check whether --with-tclinclude was given. +if test "${with_tclinclude+set}" = set; then : + withval=$with_tclinclude; with_tclinclude=${withval} +fi + + + if ${ac_cv_c_tclh+:} false; then : + $as_echo_n "(cached) " >&6 +else + + # Use the value from --with-tclinclude, if it was given + + if test x"${with_tclinclude}" != x ; then + if test -f "${with_tclinclude}/tcl.h" ; then + ac_cv_c_tclh=${with_tclinclude} + else + as_fn_error $? "${with_tclinclude} directory does not contain tcl.h" "$LINENO" 5 + fi + else + list="" + if test "`uname -s`" = "Darwin"; then + # If Tcl was built as a framework, attempt to use + # the framework's Headers directory + case ${TCL_DEFS} in + *TCL_FRAMEWORK*) + list="`ls -d ${TCL_BIN_DIR}/Headers 2>/dev/null`" + ;; + esac + fi + + # Look in the source dir only if Tcl is not installed, + # and in that situation, look there before installed locations. + if test -f "${TCL_BIN_DIR}/Makefile" ; then + list="$list `ls -d ${TCL_SRC_DIR}/generic 2>/dev/null`" + fi + + # Check order: pkg --prefix location, Tcl's --prefix location, + # relative to directory of tclConfig.sh. + + eval "temp_includedir=${includedir}" + list="$list \ + `ls -d ${temp_includedir} 2>/dev/null` \ + `ls -d ${TCL_PREFIX}/include 2>/dev/null` \ + `ls -d ${TCL_BIN_DIR}/../include 2>/dev/null`" + if test "${TEA_PLATFORM}" != "windows" -o "$GCC" = "yes"; then + list="$list /usr/local/include /usr/include" + if test x"${TCL_INCLUDE_SPEC}" != x ; then + d=`echo "${TCL_INCLUDE_SPEC}" | sed -e 's/^-I//'` + list="$list `ls -d ${d} 2>/dev/null`" + fi + fi + for i in $list ; do + if test -f "$i/tcl.h" ; then + ac_cv_c_tclh=$i + break + fi + done + fi + +fi + + + # Print a message based on how we determined the include path + + if test x"${ac_cv_c_tclh}" = x ; then + as_fn_error $? "tcl.h not found. Please specify its location with --with-tclinclude" "$LINENO" 5 + else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: ${ac_cv_c_tclh}" >&5 +$as_echo "${ac_cv_c_tclh}" >&6; } + fi + + # Convert to a native path and substitute into the output files. + + INCLUDE_DIR_NATIVE=`${CYGPATH} ${ac_cv_c_tclh}` + + TCL_INCLUDES=-I\"${INCLUDE_DIR_NATIVE}\" + + + +#TEA_PRIVATE_TCL_HEADERS + +#TEA_PUBLIC_TK_HEADERS +#TEA_PRIVATE_TK_HEADERS +#TEA_PATH_X + +#-------------------------------------------------------------------- +# Check whether --enable-threads or --disable-threads was given. +# This auto-enables if Tcl was compiled threaded. +#-------------------------------------------------------------------- + + + # Check whether --enable-threads was given. +if test "${enable_threads+set}" = set; then : + enableval=$enable_threads; tcl_ok=$enableval +else + tcl_ok=yes +fi + + + if test "${enable_threads+set}" = set; then + enableval="$enable_threads" + tcl_ok=$enableval + else + tcl_ok=yes + fi + + if test "$tcl_ok" = "yes" -o "${TCL_THREADS}" = 1; then + TCL_THREADS=1 + + if test "${TEA_PLATFORM}" != "windows" ; then + # We are always OK on Windows, so check what this platform wants: + + # USE_THREAD_ALLOC tells us to try the special thread-based + # allocator that significantly reduces lock contention + +$as_echo "#define USE_THREAD_ALLOC 1" >>confdefs.h + + +$as_echo "#define _REENTRANT 1" >>confdefs.h + + if test "`uname -s`" = "SunOS" ; then + +$as_echo "#define _POSIX_PTHREAD_SEMANTICS 1" >>confdefs.h + + fi + +$as_echo "#define _THREAD_SAFE 1" >>confdefs.h + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for pthread_mutex_init in -lpthread" >&5 +$as_echo_n "checking for pthread_mutex_init in -lpthread... " >&6; } +if ${ac_cv_lib_pthread_pthread_mutex_init+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-lpthread $LIBS" +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char pthread_mutex_init (); +int +main () +{ +return pthread_mutex_init (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + ac_cv_lib_pthread_pthread_mutex_init=yes +else + ac_cv_lib_pthread_pthread_mutex_init=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_pthread_pthread_mutex_init" >&5 +$as_echo "$ac_cv_lib_pthread_pthread_mutex_init" >&6; } +if test "x$ac_cv_lib_pthread_pthread_mutex_init" = xyes; then : + tcl_ok=yes +else + tcl_ok=no +fi + + if test "$tcl_ok" = "no"; then + # Check a little harder for __pthread_mutex_init in the same + # library, as some systems hide it there until pthread.h is + # defined. We could alternatively do an AC_TRY_COMPILE with + # pthread.h, but that will work with libpthread really doesn't + # exist, like AIX 4.2. [Bug: 4359] + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for __pthread_mutex_init in -lpthread" >&5 +$as_echo_n "checking for __pthread_mutex_init in -lpthread... " >&6; } +if ${ac_cv_lib_pthread___pthread_mutex_init+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-lpthread $LIBS" +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char __pthread_mutex_init (); +int +main () +{ +return __pthread_mutex_init (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + ac_cv_lib_pthread___pthread_mutex_init=yes +else + ac_cv_lib_pthread___pthread_mutex_init=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_pthread___pthread_mutex_init" >&5 +$as_echo "$ac_cv_lib_pthread___pthread_mutex_init" >&6; } +if test "x$ac_cv_lib_pthread___pthread_mutex_init" = xyes; then : + tcl_ok=yes +else + tcl_ok=no +fi + + fi + + if test "$tcl_ok" = "yes"; then + # The space is needed + THREADS_LIBS=" -lpthread" + else + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for pthread_mutex_init in -lpthreads" >&5 +$as_echo_n "checking for pthread_mutex_init in -lpthreads... " >&6; } +if ${ac_cv_lib_pthreads_pthread_mutex_init+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-lpthreads $LIBS" +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char pthread_mutex_init (); +int +main () +{ +return pthread_mutex_init (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + ac_cv_lib_pthreads_pthread_mutex_init=yes +else + ac_cv_lib_pthreads_pthread_mutex_init=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_pthreads_pthread_mutex_init" >&5 +$as_echo "$ac_cv_lib_pthreads_pthread_mutex_init" >&6; } +if test "x$ac_cv_lib_pthreads_pthread_mutex_init" = xyes; then : + tcl_ok=yes +else + tcl_ok=no +fi + + if test "$tcl_ok" = "yes"; then + # The space is needed + THREADS_LIBS=" -lpthreads" + else + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for pthread_mutex_init in -lc" >&5 +$as_echo_n "checking for pthread_mutex_init in -lc... " >&6; } +if ${ac_cv_lib_c_pthread_mutex_init+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-lc $LIBS" +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char pthread_mutex_init (); +int +main () +{ +return pthread_mutex_init (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + ac_cv_lib_c_pthread_mutex_init=yes +else + ac_cv_lib_c_pthread_mutex_init=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_c_pthread_mutex_init" >&5 +$as_echo "$ac_cv_lib_c_pthread_mutex_init" >&6; } +if test "x$ac_cv_lib_c_pthread_mutex_init" = xyes; then : + tcl_ok=yes +else + tcl_ok=no +fi + + if test "$tcl_ok" = "no"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for pthread_mutex_init in -lc_r" >&5 +$as_echo_n "checking for pthread_mutex_init in -lc_r... " >&6; } +if ${ac_cv_lib_c_r_pthread_mutex_init+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-lc_r $LIBS" +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char pthread_mutex_init (); +int +main () +{ +return pthread_mutex_init (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + ac_cv_lib_c_r_pthread_mutex_init=yes +else + ac_cv_lib_c_r_pthread_mutex_init=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_c_r_pthread_mutex_init" >&5 +$as_echo "$ac_cv_lib_c_r_pthread_mutex_init" >&6; } +if test "x$ac_cv_lib_c_r_pthread_mutex_init" = xyes; then : + tcl_ok=yes +else + tcl_ok=no +fi + + if test "$tcl_ok" = "yes"; then + # The space is needed + THREADS_LIBS=" -pthread" + else + TCL_THREADS=0 + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Do not know how to find pthread lib on your system - thread support disabled" >&5 +$as_echo "$as_me: WARNING: Do not know how to find pthread lib on your system - thread support disabled" >&2;} + fi + fi + fi + fi + fi + else + TCL_THREADS=0 + fi + # Do checking message here to not mess up interleaved configure output + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for building with threads" >&5 +$as_echo_n "checking for building with threads... " >&6; } + if test "${TCL_THREADS}" = 1; then + +$as_echo "#define TCL_THREADS 1" >>confdefs.h + + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes (default)" >&5 +$as_echo "yes (default)" >&6; } + else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + fi + # TCL_THREADS sanity checking. See if our request for building with + # threads is the same as the way Tcl was built. If not, warn the user. + case ${TCL_DEFS} in + *THREADS=1*) + if test "${TCL_THREADS}" = "0"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: + Building ${PACKAGE_NAME} without threads enabled, but building against Tcl + that IS thread-enabled. It is recommended to use --enable-threads." >&5 +$as_echo "$as_me: WARNING: + Building ${PACKAGE_NAME} without threads enabled, but building against Tcl + that IS thread-enabled. It is recommended to use --enable-threads." >&2;} + fi + ;; + *) + if test "${TCL_THREADS}" = "1"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: + --enable-threads requested, but building against a Tcl that is NOT + thread-enabled. This is an OK configuration that will also run in + a thread-enabled core." >&5 +$as_echo "$as_me: WARNING: + --enable-threads requested, but building against a Tcl that is NOT + thread-enabled. This is an OK configuration that will also run in + a thread-enabled core." >&2;} + fi + ;; + esac + + + +#-------------------------------------------------------------------- +# The statement below defines a collection of symbols related to +# building as a shared library instead of a static library. +#-------------------------------------------------------------------- + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking how to build libraries" >&5 +$as_echo_n "checking how to build libraries... " >&6; } + # Check whether --enable-shared was given. +if test "${enable_shared+set}" = set; then : + enableval=$enable_shared; shared_ok=$enableval +else + shared_ok=yes +fi + + + if test "${enable_shared+set}" = set; then + enableval="$enable_shared" + shared_ok=$enableval + else + shared_ok=yes + fi + + # Check whether --enable-stubs was given. +if test "${enable_stubs+set}" = set; then : + enableval=$enable_stubs; stubs_ok=$enableval +else + stubs_ok=yes +fi + + + if test "${enable_stubs+set}" = set; then + enableval="$enable_stubs" + stubs_ok=$enableval + else + stubs_ok=yes + fi + + # Stubs are always enabled for shared builds + if test "$shared_ok" = "yes" ; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: shared" >&5 +$as_echo "shared" >&6; } + SHARED_BUILD=1 + STUBS_BUILD=1 + else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: static" >&5 +$as_echo "static" >&6; } + SHARED_BUILD=0 + +$as_echo "#define STATIC_BUILD 1" >>confdefs.h + + if test "$stubs_ok" = "yes" ; then + STUBS_BUILD=1 + else + STUBS_BUILD=0 + fi + fi + if test "${STUBS_BUILD}" = "1" ; then + +$as_echo "#define USE_TCL_STUBS 1" >>confdefs.h + + +$as_echo "#define USE_TCLOO_STUBS 1" >>confdefs.h + + if test "${TEA_WINDOWINGSYSTEM}" != ""; then + +$as_echo "#define USE_TK_STUBS 1" >>confdefs.h + + fi + fi + + + + + +#-------------------------------------------------------------------- +# This macro figures out what flags to use with the compiler/linker +# when building shared/static debug/optimized objects. This information +# can be taken from the tclConfig.sh file, but this figures it all out. +#-------------------------------------------------------------------- + +if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}ranlib", so it can be a program name with args. +set dummy ${ac_tool_prefix}ranlib; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_RANLIB+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$RANLIB"; then + ac_cv_prog_RANLIB="$RANLIB" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_RANLIB="${ac_tool_prefix}ranlib" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +RANLIB=$ac_cv_prog_RANLIB +if test -n "$RANLIB"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $RANLIB" >&5 +$as_echo "$RANLIB" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_prog_RANLIB"; then + ac_ct_RANLIB=$RANLIB + # Extract the first word of "ranlib", so it can be a program name with args. +set dummy ranlib; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_ac_ct_RANLIB+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_RANLIB"; then + ac_cv_prog_ac_ct_RANLIB="$ac_ct_RANLIB" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_ac_ct_RANLIB="ranlib" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_RANLIB=$ac_cv_prog_ac_ct_RANLIB +if test -n "$ac_ct_RANLIB"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_RANLIB" >&5 +$as_echo "$ac_ct_RANLIB" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_ct_RANLIB" = x; then + RANLIB=":" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + RANLIB=$ac_ct_RANLIB + fi +else + RANLIB="$ac_cv_prog_RANLIB" +fi + + + + + # Step 0.a: Enable 64 bit support? + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking if 64bit support is requested" >&5 +$as_echo_n "checking if 64bit support is requested... " >&6; } + # Check whether --enable-64bit was given. +if test "${enable_64bit+set}" = set; then : + enableval=$enable_64bit; do64bit=$enableval +else + do64bit=no +fi + + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $do64bit" >&5 +$as_echo "$do64bit" >&6; } + + # Step 0.b: Enable Solaris 64 bit VIS support? + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking if 64bit Sparc VIS support is requested" >&5 +$as_echo_n "checking if 64bit Sparc VIS support is requested... " >&6; } + # Check whether --enable-64bit-vis was given. +if test "${enable_64bit_vis+set}" = set; then : + enableval=$enable_64bit_vis; do64bitVIS=$enableval +else + do64bitVIS=no +fi + + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $do64bitVIS" >&5 +$as_echo "$do64bitVIS" >&6; } + # Force 64bit on with VIS + if test "$do64bitVIS" = "yes"; then : + do64bit=yes +fi + + # Step 0.c: Check if visibility support is available. Do this here so + # that platform specific alternatives can be used below if this fails. + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking if compiler supports visibility \"hidden\"" >&5 +$as_echo_n "checking if compiler supports visibility \"hidden\"... " >&6; } +if ${tcl_cv_cc_visibility_hidden+:} false; then : + $as_echo_n "(cached) " >&6 +else + + hold_cflags=$CFLAGS; CFLAGS="$CFLAGS -Werror" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + + extern __attribute__((__visibility__("hidden"))) void f(void); + void f(void) {} +int +main () +{ +f(); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + tcl_cv_cc_visibility_hidden=yes +else + tcl_cv_cc_visibility_hidden=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext + CFLAGS=$hold_cflags +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_cc_visibility_hidden" >&5 +$as_echo "$tcl_cv_cc_visibility_hidden" >&6; } + if test $tcl_cv_cc_visibility_hidden = yes; then : + + +$as_echo "#define MODULE_SCOPE extern __attribute__((__visibility__(\"hidden\")))" >>confdefs.h + + +$as_echo "#define HAVE_HIDDEN 1" >>confdefs.h + + +fi + + # Step 0.d: Disable -rpath support? + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking if rpath support is requested" >&5 +$as_echo_n "checking if rpath support is requested... " >&6; } + # Check whether --enable-rpath was given. +if test "${enable_rpath+set}" = set; then : + enableval=$enable_rpath; doRpath=$enableval +else + doRpath=yes +fi + + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $doRpath" >&5 +$as_echo "$doRpath" >&6; } + + # TEA specific: Cross-compiling options for Windows/CE builds? + + if test "${TEA_PLATFORM}" = windows; then : + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking if Windows/CE build is requested" >&5 +$as_echo_n "checking if Windows/CE build is requested... " >&6; } + # Check whether --enable-wince was given. +if test "${enable_wince+set}" = set; then : + enableval=$enable_wince; doWince=$enableval +else + doWince=no +fi + + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $doWince" >&5 +$as_echo "$doWince" >&6; } + +fi + + # Set the variable "system" to hold the name and version number + # for the system. + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking system version" >&5 +$as_echo_n "checking system version... " >&6; } +if ${tcl_cv_sys_version+:} false; then : + $as_echo_n "(cached) " >&6 +else + + # TEA specific: + if test "${TEA_PLATFORM}" = "windows" ; then + tcl_cv_sys_version=windows + else + tcl_cv_sys_version=`uname -s`-`uname -r` + if test "$?" -ne 0 ; then + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: can't find uname command" >&5 +$as_echo "$as_me: WARNING: can't find uname command" >&2;} + tcl_cv_sys_version=unknown + else + if test "`uname -s`" = "AIX" ; then + tcl_cv_sys_version=AIX-`uname -v`.`uname -r` + fi + fi + fi + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_sys_version" >&5 +$as_echo "$tcl_cv_sys_version" >&6; } + system=$tcl_cv_sys_version + + + # Require ranlib early so we can override it in special cases below. + + + + # Set configuration options based on system name and version. + # This is similar to Tcl's unix/tcl.m4 except that we've added a + # "windows" case and removed some core-only vars. + + do64bit_ok=no + # default to '{$LIBS}' and set to "" on per-platform necessary basis + SHLIB_LD_LIBS='${LIBS}' + # When ld needs options to work in 64-bit mode, put them in + # LDFLAGS_ARCH so they eventually end up in LDFLAGS even if [load] + # is disabled by the user. [Bug 1016796] + LDFLAGS_ARCH="" + UNSHARED_LIB_SUFFIX="" + # TEA specific: use PACKAGE_VERSION instead of VERSION + TCL_TRIM_DOTS='`echo ${PACKAGE_VERSION} | tr -d .`' + ECHO_VERSION='`echo ${PACKAGE_VERSION}`' + TCL_LIB_VERSIONS_OK=ok + CFLAGS_DEBUG=-g + if test "$GCC" = yes; then : + + CFLAGS_OPTIMIZE=-O2 + CFLAGS_WARNING="-Wall" + +else + + CFLAGS_OPTIMIZE=-O + CFLAGS_WARNING="" + +fi + if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}ar", so it can be a program name with args. +set dummy ${ac_tool_prefix}ar; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_AR+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$AR"; then + ac_cv_prog_AR="$AR" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_AR="${ac_tool_prefix}ar" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +AR=$ac_cv_prog_AR +if test -n "$AR"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $AR" >&5 +$as_echo "$AR" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_prog_AR"; then + ac_ct_AR=$AR + # Extract the first word of "ar", so it can be a program name with args. +set dummy ar; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_ac_ct_AR+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_AR"; then + ac_cv_prog_ac_ct_AR="$ac_ct_AR" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_ac_ct_AR="ar" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_AR=$ac_cv_prog_ac_ct_AR +if test -n "$ac_ct_AR"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_AR" >&5 +$as_echo "$ac_ct_AR" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_ct_AR" = x; then + AR="" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + AR=$ac_ct_AR + fi +else + AR="$ac_cv_prog_AR" +fi + + STLIB_LD='${AR} cr' + LD_LIBRARY_PATH_VAR="LD_LIBRARY_PATH" + if test "x$SHLIB_VERSION" = x; then : + SHLIB_VERSION="" +else + SHLIB_VERSION=".$SHLIB_VERSION" +fi + case $system in + # TEA specific: + windows) + # This is a 2-stage check to make sure we have the 64-bit SDK + # We have to know where the SDK is installed. + # This magic is based on MS Platform SDK for Win2003 SP1 - hobbs + # MACHINE is IX86 for LINK, but this is used by the manifest, + # which requires x86|amd64|ia64. + MACHINE="X86" + if test "$do64bit" != "no" ; then + if test "x${MSSDK}x" = "xx" ; then + MSSDK="C:/Progra~1/Microsoft Platform SDK" + fi + MSSDK=`echo "$MSSDK" | sed -e 's!\\\!/!g'` + PATH64="" + case "$do64bit" in + amd64|x64|yes) + MACHINE="AMD64" ; # default to AMD64 64-bit build + PATH64="${MSSDK}/Bin/Win64/x86/AMD64" + ;; + ia64) + MACHINE="IA64" + PATH64="${MSSDK}/Bin/Win64" + ;; + esac + if test "$GCC" != "yes" -a ! -d "${PATH64}" ; then + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Could not find 64-bit $MACHINE SDK to enable 64bit mode" >&5 +$as_echo "$as_me: WARNING: Could not find 64-bit $MACHINE SDK to enable 64bit mode" >&2;} + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Ensure latest Platform SDK is installed" >&5 +$as_echo "$as_me: WARNING: Ensure latest Platform SDK is installed" >&2;} + do64bit="no" + else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: Using 64-bit $MACHINE mode" >&5 +$as_echo " Using 64-bit $MACHINE mode" >&6; } + do64bit_ok="yes" + fi + fi + + if test "$doWince" != "no" ; then + if test "$do64bit" != "no" ; then + as_fn_error $? "Windows/CE and 64-bit builds incompatible" "$LINENO" 5 + fi + if test "$GCC" = "yes" ; then + as_fn_error $? "Windows/CE and GCC builds incompatible" "$LINENO" 5 + fi + + # First, look for one uninstalled. + # the alternative search directory is invoked by --with-celib + + if test x"${no_celib}" = x ; then + # we reset no_celib in case something fails here + no_celib=true + +# Check whether --with-celib was given. +if test "${with_celib+set}" = set; then : + withval=$with_celib; with_celibconfig=${withval} +fi + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for Windows/CE celib directory" >&5 +$as_echo_n "checking for Windows/CE celib directory... " >&6; } + if ${ac_cv_c_celibconfig+:} false; then : + $as_echo_n "(cached) " >&6 +else + + # First check to see if --with-celibconfig was specified. + if test x"${with_celibconfig}" != x ; then + if test -d "${with_celibconfig}/inc" ; then + ac_cv_c_celibconfig=`(cd ${with_celibconfig}; pwd)` + else + as_fn_error $? "${with_celibconfig} directory doesn't contain inc directory" "$LINENO" 5 + fi + fi + + # then check for a celib library + if test x"${ac_cv_c_celibconfig}" = x ; then + for i in \ + ../celib-palm-3.0 \ + ../celib \ + ../../celib-palm-3.0 \ + ../../celib \ + `ls -dr ../celib-*3.[0-9]* 2>/dev/null` \ + ${srcdir}/../celib-palm-3.0 \ + ${srcdir}/../celib \ + `ls -dr ${srcdir}/../celib-*3.[0-9]* 2>/dev/null` \ + ; do + if test -d "$i/inc" ; then + ac_cv_c_celibconfig=`(cd $i; pwd)` + break + fi + done + fi + +fi + + if test x"${ac_cv_c_celibconfig}" = x ; then + as_fn_error $? "Cannot find celib support library directory" "$LINENO" 5 + else + no_celib= + CELIB_DIR=${ac_cv_c_celibconfig} + CELIB_DIR=`echo "$CELIB_DIR" | sed -e 's!\\\!/!g'` + { $as_echo "$as_me:${as_lineno-$LINENO}: result: found $CELIB_DIR" >&5 +$as_echo "found $CELIB_DIR" >&6; } + fi + fi + + # Set defaults for common evc4/PPC2003 setup + # Currently Tcl requires 300+, possibly 420+ for sockets + CEVERSION=420; # could be 211 300 301 400 420 ... + TARGETCPU=ARMV4; # could be ARMV4 ARM MIPS SH3 X86 ... + ARCH=ARM; # could be ARM MIPS X86EM ... + PLATFORM="Pocket PC 2003"; # or "Pocket PC 2002" + if test "$doWince" != "yes"; then + # If !yes then the user specified something + # Reset ARCH to allow user to skip specifying it + ARCH= + eval `echo $doWince | awk -F, '{ \ + if (length($1)) { printf "CEVERSION=\"%s\"\n", $1; \ + if ($1 < 400) { printf "PLATFORM=\"Pocket PC 2002\"\n" } }; \ + if (length($2)) { printf "TARGETCPU=\"%s\"\n", toupper($2) }; \ + if (length($3)) { printf "ARCH=\"%s\"\n", toupper($3) }; \ + if (length($4)) { printf "PLATFORM=\"%s\"\n", $4 }; \ + }'` + if test "x${ARCH}" = "x" ; then + ARCH=$TARGETCPU; + fi + fi + OSVERSION=WCE$CEVERSION; + if test "x${WCEROOT}" = "x" ; then + WCEROOT="C:/Program Files/Microsoft eMbedded C++ 4.0" + if test ! -d "${WCEROOT}" ; then + WCEROOT="C:/Program Files/Microsoft eMbedded Tools" + fi + fi + if test "x${SDKROOT}" = "x" ; then + SDKROOT="C:/Program Files/Windows CE Tools" + if test ! -d "${SDKROOT}" ; then + SDKROOT="C:/Windows CE Tools" + fi + fi + WCEROOT=`echo "$WCEROOT" | sed -e 's!\\\!/!g'` + SDKROOT=`echo "$SDKROOT" | sed -e 's!\\\!/!g'` + if test ! -d "${SDKROOT}/${OSVERSION}/${PLATFORM}/Lib/${TARGETCPU}" \ + -o ! -d "${WCEROOT}/EVC/${OSVERSION}/bin"; then + as_fn_error $? "could not find PocketPC SDK or target compiler to enable WinCE mode $CEVERSION,$TARGETCPU,$ARCH,$PLATFORM" "$LINENO" 5 + doWince="no" + else + # We could PATH_NOSPACE these, but that's not important, + # as long as we quote them when used. + CEINCLUDE="${SDKROOT}/${OSVERSION}/${PLATFORM}/include" + if test -d "${CEINCLUDE}/${TARGETCPU}" ; then + CEINCLUDE="${CEINCLUDE}/${TARGETCPU}" + fi + CELIBPATH="${SDKROOT}/${OSVERSION}/${PLATFORM}/Lib/${TARGETCPU}" + fi + fi + + if test "$GCC" != "yes" ; then + if test "${SHARED_BUILD}" = "0" ; then + runtime=-MT + else + runtime=-MD + fi + case "x`echo \${VisualStudioVersion}`" in + x1[4-9]*) + lflags="${lflags} -nodefaultlib:libucrt.lib" + + vars="ucrt.lib" + for i in $vars; do + if test "${TEA_PLATFORM}" = "windows" -a "$GCC" = "yes" ; then + # Convert foo.lib to -lfoo for GCC. No-op if not *.lib + i=`echo "$i" | sed -e 's/^\([^-].*\)\.lib$/-l\1/i'` + fi + PKG_LIBS="$PKG_LIBS $i" + done + + + ;; + *) + ;; + esac + + if test "$do64bit" != "no" ; then + # All this magic is necessary for the Win64 SDK RC1 - hobbs + CC="\"${PATH64}/cl.exe\"" + CFLAGS="${CFLAGS} -I\"${MSSDK}/Include\" -I\"${MSSDK}/Include/crt\" -I\"${MSSDK}/Include/crt/sys\"" + RC="\"${MSSDK}/bin/rc.exe\"" + lflags="${lflags} -nologo -MACHINE:${MACHINE} -LIBPATH:\"${MSSDK}/Lib/${MACHINE}\"" + LINKBIN="\"${PATH64}/link.exe\"" + CFLAGS_DEBUG="-nologo -Zi -Od -W3 ${runtime}d" + CFLAGS_OPTIMIZE="-nologo -O2 -W2 ${runtime}" + # Avoid 'unresolved external symbol __security_cookie' + # errors, c.f. http://support.microsoft.com/?id=894573 + + vars="bufferoverflowU.lib" + for i in $vars; do + if test "${TEA_PLATFORM}" = "windows" -a "$GCC" = "yes" ; then + # Convert foo.lib to -lfoo for GCC. No-op if not *.lib + i=`echo "$i" | sed -e 's/^\([^-].*\)\.lib$/-l\1/i'` + fi + PKG_LIBS="$PKG_LIBS $i" + done + + + elif test "$doWince" != "no" ; then + CEBINROOT="${WCEROOT}/EVC/${OSVERSION}/bin" + if test "${TARGETCPU}" = "X86"; then + CC="\"${CEBINROOT}/cl.exe\"" + else + CC="\"${CEBINROOT}/cl${ARCH}.exe\"" + fi + CFLAGS="$CFLAGS -I\"${CELIB_DIR}/inc\" -I\"${CEINCLUDE}\"" + RC="\"${WCEROOT}/Common/EVC/bin/rc.exe\"" + arch=`echo ${ARCH} | awk '{print tolower($0)}'` + defs="${ARCH} _${ARCH}_ ${arch} PALM_SIZE _MT _WINDOWS" + if test "${SHARED_BUILD}" = "1" ; then + # Static CE builds require static celib as well + defs="${defs} _DLL" + fi + for i in $defs ; do + +cat >>confdefs.h <<_ACEOF +#define $i 1 +_ACEOF + + done + +cat >>confdefs.h <<_ACEOF +#define _WIN32_WCE $CEVERSION +_ACEOF + + +cat >>confdefs.h <<_ACEOF +#define UNDER_CE $CEVERSION +_ACEOF + + CFLAGS_DEBUG="-nologo -Zi -Od" + CFLAGS_OPTIMIZE="-nologo -Ox" + lversion=`echo ${CEVERSION} | sed -e 's/\(.\)\(..\)/\1\.\2/'` + lflags="${lflags} -MACHINE:${ARCH} -LIBPATH:\"${CELIBPATH}\" -subsystem:windowsce,${lversion} -nologo" + LINKBIN="\"${CEBINROOT}/link.exe\"" + + else + RC="rc" + lflags="${lflags} -nologo" + LINKBIN="link" + CFLAGS_DEBUG="-nologo -Z7 -Od -W3 -WX ${runtime}d" + CFLAGS_OPTIMIZE="-nologo -O2 -W2 ${runtime}" + fi + fi + + if test "$GCC" = "yes"; then + # mingw gcc mode + if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}windres", so it can be a program name with args. +set dummy ${ac_tool_prefix}windres; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_RC+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$RC"; then + ac_cv_prog_RC="$RC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_RC="${ac_tool_prefix}windres" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +RC=$ac_cv_prog_RC +if test -n "$RC"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $RC" >&5 +$as_echo "$RC" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_prog_RC"; then + ac_ct_RC=$RC + # Extract the first word of "windres", so it can be a program name with args. +set dummy windres; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_ac_ct_RC+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_RC"; then + ac_cv_prog_ac_ct_RC="$ac_ct_RC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_ac_ct_RC="windres" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_RC=$ac_cv_prog_ac_ct_RC +if test -n "$ac_ct_RC"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_RC" >&5 +$as_echo "$ac_ct_RC" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_ct_RC" = x; then + RC="" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + RC=$ac_ct_RC + fi +else + RC="$ac_cv_prog_RC" +fi + + CFLAGS_DEBUG="-g" + CFLAGS_OPTIMIZE="-O2 -fomit-frame-pointer" + SHLIB_LD='${CC} -shared' + UNSHARED_LIB_SUFFIX='${TCL_TRIM_DOTS}.a' + LDFLAGS_CONSOLE="-wl,--subsystem,console ${lflags}" + LDFLAGS_WINDOW="-wl,--subsystem,windows ${lflags}" + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for cross-compile version of gcc" >&5 +$as_echo_n "checking for cross-compile version of gcc... " >&6; } +if ${ac_cv_cross+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + + #ifdef _WIN32 + #error cross-compiler + #endif + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_cv_cross=yes +else + ac_cv_cross=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_cross" >&5 +$as_echo "$ac_cv_cross" >&6; } + if test "$ac_cv_cross" = "yes"; then + case "$do64bit" in + amd64|x64|yes) + CC="x86_64-w64-mingw32-gcc" + LD="x86_64-w64-mingw32-ld" + AR="x86_64-w64-mingw32-ar" + RANLIB="x86_64-w64-mingw32-ranlib" + RC="x86_64-w64-mingw32-windres" + ;; + *) + CC="i686-w64-mingw32-gcc" + LD="i686-w64-mingw32-ld" + AR="i686-w64-mingw32-ar" + RANLIB="i686-w64-mingw32-ranlib" + RC="i686-w64-mingw32-windres" + ;; + esac + fi + + else + SHLIB_LD="${LINKBIN} -dll ${lflags}" + # link -lib only works when -lib is the first arg + STLIB_LD="${LINKBIN} -lib ${lflags}" + UNSHARED_LIB_SUFFIX='${TCL_TRIM_DOTS}.lib' + PATHTYPE=-w + # For information on what debugtype is most useful, see: + # http://msdn.microsoft.com/library/en-us/dnvc60/html/gendepdebug.asp + # and also + # http://msdn2.microsoft.com/en-us/library/y0zzbyt4%28VS.80%29.aspx + # This essentially turns it all on. + LDFLAGS_DEBUG="-debug -debugtype:cv" + LDFLAGS_OPTIMIZE="-release" + if test "$doWince" != "no" ; then + LDFLAGS_CONSOLE="-link ${lflags}" + LDFLAGS_WINDOW=${LDFLAGS_CONSOLE} + else + LDFLAGS_CONSOLE="-link -subsystem:console ${lflags}" + LDFLAGS_WINDOW="-link -subsystem:windows ${lflags}" + fi + fi + + SHLIB_SUFFIX=".dll" + SHARED_LIB_SUFFIX='${TCL_TRIM_DOTS}.dll' + + TCL_LIB_VERSIONS_OK=nodots + ;; + AIX-*) + if test "${TCL_THREADS}" = "1" -a "$GCC" != "yes"; then : + + # AIX requires the _r compiler when gcc isn't being used + case "${CC}" in + *_r|*_r\ *) + # ok ... + ;; + *) + # Make sure only first arg gets _r + CC=`echo "$CC" | sed -e 's/^\([^ ]*\)/\1_r/'` + ;; + esac + { $as_echo "$as_me:${as_lineno-$LINENO}: result: Using $CC for compiling with threads" >&5 +$as_echo "Using $CC for compiling with threads" >&6; } + +fi + LIBS="$LIBS -lc" + SHLIB_CFLAGS="" + SHLIB_SUFFIX=".so" + + LD_LIBRARY_PATH_VAR="LIBPATH" + + # Check to enable 64-bit flags for compiler/linker + if test "$do64bit" = yes; then : + + if test "$GCC" = yes; then : + + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: 64bit mode not supported with GCC on $system" >&5 +$as_echo "$as_me: WARNING: 64bit mode not supported with GCC on $system" >&2;} + +else + + do64bit_ok=yes + CFLAGS="$CFLAGS -q64" + LDFLAGS_ARCH="-q64" + RANLIB="${RANLIB} -X64" + AR="${AR} -X64" + SHLIB_LD_FLAGS="-b64" + +fi + +fi + + if test "`uname -m`" = ia64; then : + + # AIX-5 uses ELF style dynamic libraries on IA-64, but not PPC + SHLIB_LD="/usr/ccs/bin/ld -G -z text" + if test "$GCC" = yes; then : + + CC_SEARCH_FLAGS='-Wl,-R,${LIB_RUNTIME_DIR}' + +else + + CC_SEARCH_FLAGS='-R${LIB_RUNTIME_DIR}' + +fi + LD_SEARCH_FLAGS='-R ${LIB_RUNTIME_DIR}' + +else + + if test "$GCC" = yes; then : + + SHLIB_LD='${CC} -shared -Wl,-bexpall' + +else + + SHLIB_LD="/bin/ld -bhalt:4 -bM:SRE -bexpall -H512 -T512 -bnoentry" + LDFLAGS="$LDFLAGS -brtl" + +fi + SHLIB_LD="${SHLIB_LD} ${SHLIB_LD_FLAGS}" + CC_SEARCH_FLAGS='-L${LIB_RUNTIME_DIR}' + LD_SEARCH_FLAGS=${CC_SEARCH_FLAGS} + +fi + ;; + BeOS*) + SHLIB_CFLAGS="-fPIC" + SHLIB_LD='${CC} -nostart' + SHLIB_SUFFIX=".so" + + #----------------------------------------------------------- + # Check for inet_ntoa in -lbind, for BeOS (which also needs + # -lsocket, even if the network functions are in -lnet which + # is always linked to, for compatibility. + #----------------------------------------------------------- + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for inet_ntoa in -lbind" >&5 +$as_echo_n "checking for inet_ntoa in -lbind... " >&6; } +if ${ac_cv_lib_bind_inet_ntoa+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-lbind $LIBS" +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char inet_ntoa (); +int +main () +{ +return inet_ntoa (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + ac_cv_lib_bind_inet_ntoa=yes +else + ac_cv_lib_bind_inet_ntoa=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_bind_inet_ntoa" >&5 +$as_echo "$ac_cv_lib_bind_inet_ntoa" >&6; } +if test "x$ac_cv_lib_bind_inet_ntoa" = xyes; then : + LIBS="$LIBS -lbind -lsocket" +fi + + ;; + BSD/OS-4.*) + SHLIB_CFLAGS="-export-dynamic -fPIC" + SHLIB_LD='${CC} -shared' + SHLIB_SUFFIX=".so" + LDFLAGS="$LDFLAGS -export-dynamic" + CC_SEARCH_FLAGS="" + LD_SEARCH_FLAGS="" + ;; + CYGWIN_*) + SHLIB_CFLAGS="" + SHLIB_LD='${CC} -shared' + SHLIB_LD_LIBS="${SHLIB_LD_LIBS} -Wl,--out-implib,\$@.a" + SHLIB_SUFFIX=".dll" + EXEEXT=".exe" + do64bit_ok=yes + CC_SEARCH_FLAGS="" + LD_SEARCH_FLAGS="" + ;; + Haiku*) + LDFLAGS="$LDFLAGS -Wl,--export-dynamic" + SHLIB_CFLAGS="-fPIC" + SHLIB_SUFFIX=".so" + SHLIB_LD='${CC} ${CFLAGS} ${LDFLAGS} -shared' + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for inet_ntoa in -lnetwork" >&5 +$as_echo_n "checking for inet_ntoa in -lnetwork... " >&6; } +if ${ac_cv_lib_network_inet_ntoa+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-lnetwork $LIBS" +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char inet_ntoa (); +int +main () +{ +return inet_ntoa (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + ac_cv_lib_network_inet_ntoa=yes +else + ac_cv_lib_network_inet_ntoa=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_network_inet_ntoa" >&5 +$as_echo "$ac_cv_lib_network_inet_ntoa" >&6; } +if test "x$ac_cv_lib_network_inet_ntoa" = xyes; then : + LIBS="$LIBS -lnetwork" +fi + + ;; + HP-UX-*.11.*) + # Use updated header definitions where possible + +$as_echo "#define _XOPEN_SOURCE_EXTENDED 1" >>confdefs.h + + # TEA specific: Needed by Tcl, but not most extensions + #AC_DEFINE(_XOPEN_SOURCE, 1, [Do we want to use the XOPEN network library?]) + #LIBS="$LIBS -lxnet" # Use the XOPEN network library + + if test "`uname -m`" = ia64; then : + + SHLIB_SUFFIX=".so" + # Use newer C++ library for C++ extensions + #if test "$GCC" != "yes" ; then + # CPPFLAGS="-AA" + #fi + +else + + SHLIB_SUFFIX=".sl" + +fi + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for shl_load in -ldld" >&5 +$as_echo_n "checking for shl_load in -ldld... " >&6; } +if ${ac_cv_lib_dld_shl_load+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-ldld $LIBS" +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char shl_load (); +int +main () +{ +return shl_load (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + ac_cv_lib_dld_shl_load=yes +else + ac_cv_lib_dld_shl_load=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dld_shl_load" >&5 +$as_echo "$ac_cv_lib_dld_shl_load" >&6; } +if test "x$ac_cv_lib_dld_shl_load" = xyes; then : + tcl_ok=yes +else + tcl_ok=no +fi + + if test "$tcl_ok" = yes; then : + + LDFLAGS="$LDFLAGS -Wl,-E" + CC_SEARCH_FLAGS='-Wl,+s,+b,${LIB_RUNTIME_DIR}:.' + LD_SEARCH_FLAGS='+s +b ${LIB_RUNTIME_DIR}:.' + LD_LIBRARY_PATH_VAR="SHLIB_PATH" + +fi + if test "$GCC" = yes; then : + + SHLIB_LD='${CC} -shared' + LD_SEARCH_FLAGS=${CC_SEARCH_FLAGS} + +else + + CFLAGS="$CFLAGS -z" + # Users may want PA-RISC 1.1/2.0 portable code - needs HP cc + #CFLAGS="$CFLAGS +DAportable" + SHLIB_CFLAGS="+z" + SHLIB_LD="ld -b" + +fi + + # Check to enable 64-bit flags for compiler/linker + if test "$do64bit" = "yes"; then : + + if test "$GCC" = yes; then : + + case `${CC} -dumpmachine` in + hppa64*) + # 64-bit gcc in use. Fix flags for GNU ld. + do64bit_ok=yes + SHLIB_LD='${CC} -shared' + if test $doRpath = yes; then : + + CC_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}' +fi + LD_SEARCH_FLAGS=${CC_SEARCH_FLAGS} + ;; + *) + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: 64bit mode not supported with GCC on $system" >&5 +$as_echo "$as_me: WARNING: 64bit mode not supported with GCC on $system" >&2;} + ;; + esac + +else + + do64bit_ok=yes + CFLAGS="$CFLAGS +DD64" + LDFLAGS_ARCH="+DD64" + +fi + +fi ;; + IRIX-6.*) + SHLIB_CFLAGS="" + SHLIB_LD="ld -n32 -shared -rdata_shared" + SHLIB_SUFFIX=".so" + if test $doRpath = yes; then : + + CC_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}' + LD_SEARCH_FLAGS='-rpath ${LIB_RUNTIME_DIR}' +fi + if test "$GCC" = yes; then : + + CFLAGS="$CFLAGS -mabi=n32" + LDFLAGS="$LDFLAGS -mabi=n32" + +else + + case $system in + IRIX-6.3) + # Use to build 6.2 compatible binaries on 6.3. + CFLAGS="$CFLAGS -n32 -D_OLD_TERMIOS" + ;; + *) + CFLAGS="$CFLAGS -n32" + ;; + esac + LDFLAGS="$LDFLAGS -n32" + +fi + ;; + IRIX64-6.*) + SHLIB_CFLAGS="" + SHLIB_LD="ld -n32 -shared -rdata_shared" + SHLIB_SUFFIX=".so" + if test $doRpath = yes; then : + + CC_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}' + LD_SEARCH_FLAGS='-rpath ${LIB_RUNTIME_DIR}' +fi + + # Check to enable 64-bit flags for compiler/linker + + if test "$do64bit" = yes; then : + + if test "$GCC" = yes; then : + + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: 64bit mode not supported by gcc" >&5 +$as_echo "$as_me: WARNING: 64bit mode not supported by gcc" >&2;} + +else + + do64bit_ok=yes + SHLIB_LD="ld -64 -shared -rdata_shared" + CFLAGS="$CFLAGS -64" + LDFLAGS_ARCH="-64" + +fi + +fi + ;; + Linux*|GNU*|NetBSD-Debian) + SHLIB_CFLAGS="-fPIC" + SHLIB_SUFFIX=".so" + + # TEA specific: + CFLAGS_OPTIMIZE="-O2 -fomit-frame-pointer" + + # TEA specific: use LDFLAGS_DEFAULT instead of LDFLAGS + SHLIB_LD='${CC} ${CFLAGS} ${LDFLAGS_DEFAULT} -shared' + LDFLAGS="$LDFLAGS -Wl,--export-dynamic" + if test $doRpath = yes; then : + + CC_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}' +fi + LD_SEARCH_FLAGS=${CC_SEARCH_FLAGS} + if test "`uname -m`" = "alpha"; then : + CFLAGS="$CFLAGS -mieee" +fi + if test $do64bit = yes; then : + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking if compiler accepts -m64 flag" >&5 +$as_echo_n "checking if compiler accepts -m64 flag... " >&6; } +if ${tcl_cv_cc_m64+:} false; then : + $as_echo_n "(cached) " >&6 +else + + hold_cflags=$CFLAGS + CFLAGS="$CFLAGS -m64" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + tcl_cv_cc_m64=yes +else + tcl_cv_cc_m64=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext + CFLAGS=$hold_cflags +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_cc_m64" >&5 +$as_echo "$tcl_cv_cc_m64" >&6; } + if test $tcl_cv_cc_m64 = yes; then : + + CFLAGS="$CFLAGS -m64" + do64bit_ok=yes + +fi + +fi + + # The combo of gcc + glibc has a bug related to inlining of + # functions like strtod(). The -fno-builtin flag should address + # this problem but it does not work. The -fno-inline flag is kind + # of overkill but it works. Disable inlining only when one of the + # files in compat/*.c is being linked in. + + if test x"${USE_COMPAT}" != x; then : + CFLAGS="$CFLAGS -fno-inline" +fi + ;; + Lynx*) + SHLIB_CFLAGS="-fPIC" + SHLIB_SUFFIX=".so" + CFLAGS_OPTIMIZE=-02 + SHLIB_LD='${CC} -shared' + LD_FLAGS="-Wl,--export-dynamic" + if test $doRpath = yes; then : + + CC_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}' + LD_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}' +fi + ;; + OpenBSD-*) + arch=`arch -s` + case "$arch" in + alpha|sparc64) + SHLIB_CFLAGS="-fPIC" + ;; + *) + SHLIB_CFLAGS="-fpic" + ;; + esac + SHLIB_LD='${CC} ${SHLIB_CFLAGS} -shared' + SHLIB_SUFFIX=".so" + if test $doRpath = yes; then : + + CC_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}' +fi + LD_SEARCH_FLAGS=${CC_SEARCH_FLAGS} + SHARED_LIB_SUFFIX='${TCL_TRIM_DOTS}.so${SHLIB_VERSION}' + LDFLAGS="-Wl,-export-dynamic" + CFLAGS_OPTIMIZE="-O2" + if test "${TCL_THREADS}" = "1"; then : + + # On OpenBSD: Compile with -pthread + # Don't link with -lpthread + LIBS=`echo $LIBS | sed s/-lpthread//` + CFLAGS="$CFLAGS -pthread" + +fi + # OpenBSD doesn't do version numbers with dots. + UNSHARED_LIB_SUFFIX='${TCL_TRIM_DOTS}.a' + TCL_LIB_VERSIONS_OK=nodots + ;; + NetBSD-*) + # NetBSD has ELF and can use 'cc -shared' to build shared libs + SHLIB_CFLAGS="-fPIC" + SHLIB_LD='${CC} ${SHLIB_CFLAGS} -shared' + SHLIB_SUFFIX=".so" + LDFLAGS="$LDFLAGS -export-dynamic" + if test $doRpath = yes; then : + + CC_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}' +fi + LD_SEARCH_FLAGS=${CC_SEARCH_FLAGS} + if test "${TCL_THREADS}" = "1"; then : + + # The -pthread needs to go in the CFLAGS, not LIBS + LIBS=`echo $LIBS | sed s/-pthread//` + CFLAGS="$CFLAGS -pthread" + LDFLAGS="$LDFLAGS -pthread" + +fi + ;; + FreeBSD-*) + # This configuration from FreeBSD Ports. + SHLIB_CFLAGS="-fPIC" + SHLIB_LD="${CC} -shared" + SHLIB_LD_LIBS="${SHLIB_LD_LIBS} -Wl,-soname,\$@" + SHLIB_SUFFIX=".so" + LDFLAGS="" + if test $doRpath = yes; then : + + CC_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}' + LD_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}' +fi + if test "${TCL_THREADS}" = "1"; then : + + # The -pthread needs to go in the LDFLAGS, not LIBS + LIBS=`echo $LIBS | sed s/-pthread//` + CFLAGS="$CFLAGS $PTHREAD_CFLAGS" + LDFLAGS="$LDFLAGS $PTHREAD_LIBS" +fi + case $system in + FreeBSD-3.*) + # Version numbers are dot-stripped by system policy. + TCL_TRIM_DOTS=`echo ${PACKAGE_VERSION} | tr -d .` + UNSHARED_LIB_SUFFIX='${TCL_TRIM_DOTS}.a' + SHARED_LIB_SUFFIX='${TCL_TRIM_DOTS}\$\{DBGX\}.so.1' + TCL_LIB_VERSIONS_OK=nodots + ;; + esac + ;; + Darwin-*) + CFLAGS_OPTIMIZE="-Os" + SHLIB_CFLAGS="-fno-common" + # To avoid discrepancies between what headers configure sees during + # preprocessing tests and compiling tests, move any -isysroot and + # -mmacosx-version-min flags from CFLAGS to CPPFLAGS: + CPPFLAGS="${CPPFLAGS} `echo " ${CFLAGS}" | \ + awk 'BEGIN {FS=" +-";ORS=" "}; {for (i=2;i<=NF;i++) \ + if ($i~/^(isysroot|mmacosx-version-min)/) print "-"$i}'`" + CFLAGS="`echo " ${CFLAGS}" | \ + awk 'BEGIN {FS=" +-";ORS=" "}; {for (i=2;i<=NF;i++) \ + if (!($i~/^(isysroot|mmacosx-version-min)/)) print "-"$i}'`" + if test $do64bit = yes; then : + + case `arch` in + ppc) + { $as_echo "$as_me:${as_lineno-$LINENO}: checking if compiler accepts -arch ppc64 flag" >&5 +$as_echo_n "checking if compiler accepts -arch ppc64 flag... " >&6; } +if ${tcl_cv_cc_arch_ppc64+:} false; then : + $as_echo_n "(cached) " >&6 +else + + hold_cflags=$CFLAGS + CFLAGS="$CFLAGS -arch ppc64 -mpowerpc64 -mcpu=G5" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + tcl_cv_cc_arch_ppc64=yes +else + tcl_cv_cc_arch_ppc64=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext + CFLAGS=$hold_cflags +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_cc_arch_ppc64" >&5 +$as_echo "$tcl_cv_cc_arch_ppc64" >&6; } + if test $tcl_cv_cc_arch_ppc64 = yes; then : + + CFLAGS="$CFLAGS -arch ppc64 -mpowerpc64 -mcpu=G5" + do64bit_ok=yes + +fi;; + i386) + { $as_echo "$as_me:${as_lineno-$LINENO}: checking if compiler accepts -arch x86_64 flag" >&5 +$as_echo_n "checking if compiler accepts -arch x86_64 flag... " >&6; } +if ${tcl_cv_cc_arch_x86_64+:} false; then : + $as_echo_n "(cached) " >&6 +else + + hold_cflags=$CFLAGS + CFLAGS="$CFLAGS -arch x86_64" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + tcl_cv_cc_arch_x86_64=yes +else + tcl_cv_cc_arch_x86_64=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext + CFLAGS=$hold_cflags +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_cc_arch_x86_64" >&5 +$as_echo "$tcl_cv_cc_arch_x86_64" >&6; } + if test $tcl_cv_cc_arch_x86_64 = yes; then : + + CFLAGS="$CFLAGS -arch x86_64" + do64bit_ok=yes + +fi;; + *) + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Don't know how enable 64-bit on architecture \`arch\`" >&5 +$as_echo "$as_me: WARNING: Don't know how enable 64-bit on architecture \`arch\`" >&2;};; + esac + +else + + # Check for combined 32-bit and 64-bit fat build + if echo "$CFLAGS " |grep -E -q -- '-arch (ppc64|x86_64) ' \ + && echo "$CFLAGS " |grep -E -q -- '-arch (ppc|i386) '; then : + + fat_32_64=yes +fi + +fi + # TEA specific: use LDFLAGS_DEFAULT instead of LDFLAGS + SHLIB_LD='${CC} -dynamiclib ${CFLAGS} ${LDFLAGS_DEFAULT}' + { $as_echo "$as_me:${as_lineno-$LINENO}: checking if ld accepts -single_module flag" >&5 +$as_echo_n "checking if ld accepts -single_module flag... " >&6; } +if ${tcl_cv_ld_single_module+:} false; then : + $as_echo_n "(cached) " >&6 +else + + hold_ldflags=$LDFLAGS + LDFLAGS="$LDFLAGS -dynamiclib -Wl,-single_module" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ +int i; + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + tcl_cv_ld_single_module=yes +else + tcl_cv_ld_single_module=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext + LDFLAGS=$hold_ldflags +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_ld_single_module" >&5 +$as_echo "$tcl_cv_ld_single_module" >&6; } + if test $tcl_cv_ld_single_module = yes; then : + + SHLIB_LD="${SHLIB_LD} -Wl,-single_module" + +fi + # TEA specific: link shlib with current and compatibility version flags + vers=`echo ${PACKAGE_VERSION} | sed -e 's/^\([0-9]\{1,5\}\)\(\(\.[0-9]\{1,3\}\)\{0,2\}\).*$/\1\2/p' -e d` + SHLIB_LD="${SHLIB_LD} -current_version ${vers:-0} -compatibility_version ${vers:-0}" + SHLIB_SUFFIX=".dylib" + # Don't use -prebind when building for Mac OS X 10.4 or later only: + if test "`echo "${MACOSX_DEPLOYMENT_TARGET}" | awk -F '10\\.' '{print int($2)}'`" -lt 4 -a \ + "`echo "${CPPFLAGS}" | awk -F '-mmacosx-version-min=10\\.' '{print int($2)}'`" -lt 4; then : + + LDFLAGS="$LDFLAGS -prebind" +fi + LDFLAGS="$LDFLAGS -headerpad_max_install_names" + { $as_echo "$as_me:${as_lineno-$LINENO}: checking if ld accepts -search_paths_first flag" >&5 +$as_echo_n "checking if ld accepts -search_paths_first flag... " >&6; } +if ${tcl_cv_ld_search_paths_first+:} false; then : + $as_echo_n "(cached) " >&6 +else + + hold_ldflags=$LDFLAGS + LDFLAGS="$LDFLAGS -Wl,-search_paths_first" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ +int i; + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + tcl_cv_ld_search_paths_first=yes +else + tcl_cv_ld_search_paths_first=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext + LDFLAGS=$hold_ldflags +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_ld_search_paths_first" >&5 +$as_echo "$tcl_cv_ld_search_paths_first" >&6; } + if test $tcl_cv_ld_search_paths_first = yes; then : + + LDFLAGS="$LDFLAGS -Wl,-search_paths_first" + +fi + if test "$tcl_cv_cc_visibility_hidden" != yes; then : + + +$as_echo "#define MODULE_SCOPE __private_extern__" >>confdefs.h + + tcl_cv_cc_visibility_hidden=yes + +fi + CC_SEARCH_FLAGS="" + LD_SEARCH_FLAGS="" + LD_LIBRARY_PATH_VAR="DYLD_LIBRARY_PATH" + # TEA specific: for combined 32 & 64 bit fat builds of Tk + # extensions, verify that 64-bit build is possible. + if test "$fat_32_64" = yes && test -n "${TK_BIN_DIR}"; then : + + if test "${TEA_WINDOWINGSYSTEM}" = x11; then : + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for 64-bit X11" >&5 +$as_echo_n "checking for 64-bit X11... " >&6; } +if ${tcl_cv_lib_x11_64+:} false; then : + $as_echo_n "(cached) " >&6 +else + + for v in CFLAGS CPPFLAGS LDFLAGS; do + eval 'hold_'$v'="$'$v'";'$v'="`echo "$'$v' "|sed -e "s/-arch ppc / /g" -e "s/-arch i386 / /g"`"' + done + CPPFLAGS="$CPPFLAGS -I/usr/X11R6/include" + LDFLAGS="$LDFLAGS -L/usr/X11R6/lib -lX11" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +int +main () +{ +XrmInitialize(); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + tcl_cv_lib_x11_64=yes +else + tcl_cv_lib_x11_64=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext + for v in CFLAGS CPPFLAGS LDFLAGS; do + eval $v'="$hold_'$v'"' + done +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_lib_x11_64" >&5 +$as_echo "$tcl_cv_lib_x11_64" >&6; } + +fi + if test "${TEA_WINDOWINGSYSTEM}" = aqua; then : + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for 64-bit Tk" >&5 +$as_echo_n "checking for 64-bit Tk... " >&6; } +if ${tcl_cv_lib_tk_64+:} false; then : + $as_echo_n "(cached) " >&6 +else + + for v in CFLAGS CPPFLAGS LDFLAGS; do + eval 'hold_'$v'="$'$v'";'$v'="`echo "$'$v' "|sed -e "s/-arch ppc / /g" -e "s/-arch i386 / /g"`"' + done + CPPFLAGS="$CPPFLAGS -DUSE_TCL_STUBS=1 -DUSE_TK_STUBS=1 ${TCL_INCLUDES} ${TK_INCLUDES}" + LDFLAGS="$LDFLAGS ${TCL_STUB_LIB_SPEC} ${TK_STUB_LIB_SPEC}" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +int +main () +{ +Tk_InitStubs(NULL, "", 0); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + tcl_cv_lib_tk_64=yes +else + tcl_cv_lib_tk_64=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext + for v in CFLAGS CPPFLAGS LDFLAGS; do + eval $v'="$hold_'$v'"' + done +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_lib_tk_64" >&5 +$as_echo "$tcl_cv_lib_tk_64" >&6; } + +fi + # remove 64-bit arch flags from CFLAGS et al. if configuration + # does not support 64-bit. + if test "$tcl_cv_lib_tk_64" = no -o "$tcl_cv_lib_x11_64" = no; then : + + { $as_echo "$as_me:${as_lineno-$LINENO}: Removing 64-bit architectures from compiler & linker flags" >&5 +$as_echo "$as_me: Removing 64-bit architectures from compiler & linker flags" >&6;} + for v in CFLAGS CPPFLAGS LDFLAGS; do + eval $v'="`echo "$'$v' "|sed -e "s/-arch ppc64 / /g" -e "s/-arch x86_64 / /g"`"' + done +fi + +fi + ;; + OS/390-*) + CFLAGS_OPTIMIZE="" # Optimizer is buggy + +$as_echo "#define _OE_SOCKETS 1" >>confdefs.h + + ;; + OSF1-V*) + # Digital OSF/1 + SHLIB_CFLAGS="" + if test "$SHARED_BUILD" = 1; then : + + SHLIB_LD='ld -shared -expect_unresolved "*"' + +else + + SHLIB_LD='ld -non_shared -expect_unresolved "*"' + +fi + SHLIB_SUFFIX=".so" + if test $doRpath = yes; then : + + CC_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}' + LD_SEARCH_FLAGS='-rpath ${LIB_RUNTIME_DIR}' +fi + if test "$GCC" = yes; then : + CFLAGS="$CFLAGS -mieee" +else + + CFLAGS="$CFLAGS -DHAVE_TZSET -std1 -ieee" +fi + # see pthread_intro(3) for pthread support on osf1, k.furukawa + if test "${TCL_THREADS}" = 1; then : + + CFLAGS="$CFLAGS -DHAVE_PTHREAD_ATTR_SETSTACKSIZE" + CFLAGS="$CFLAGS -DTCL_THREAD_STACK_MIN=PTHREAD_STACK_MIN*64" + LIBS=`echo $LIBS | sed s/-lpthreads//` + if test "$GCC" = yes; then : + + LIBS="$LIBS -lpthread -lmach -lexc" + +else + + CFLAGS="$CFLAGS -pthread" + LDFLAGS="$LDFLAGS -pthread" + +fi + +fi + ;; + QNX-6*) + # QNX RTP + # This may work for all QNX, but it was only reported for v6. + SHLIB_CFLAGS="-fPIC" + SHLIB_LD="ld -Bshareable -x" + SHLIB_LD_LIBS="" + SHLIB_SUFFIX=".so" + CC_SEARCH_FLAGS="" + LD_SEARCH_FLAGS="" + ;; + SCO_SV-3.2*) + if test "$GCC" = yes; then : + + SHLIB_CFLAGS="-fPIC -melf" + LDFLAGS="$LDFLAGS -melf -Wl,-Bexport" + +else + + SHLIB_CFLAGS="-Kpic -belf" + LDFLAGS="$LDFLAGS -belf -Wl,-Bexport" + +fi + SHLIB_LD="ld -G" + SHLIB_LD_LIBS="" + SHLIB_SUFFIX=".so" + CC_SEARCH_FLAGS="" + LD_SEARCH_FLAGS="" + ;; + SunOS-5.[0-6]) + # Careful to not let 5.10+ fall into this case + + # Note: If _REENTRANT isn't defined, then Solaris + # won't define thread-safe library routines. + + +$as_echo "#define _REENTRANT 1" >>confdefs.h + + +$as_echo "#define _POSIX_PTHREAD_SEMANTICS 1" >>confdefs.h + + + SHLIB_CFLAGS="-KPIC" + SHLIB_SUFFIX=".so" + if test "$GCC" = yes; then : + + SHLIB_LD='${CC} -shared' + CC_SEARCH_FLAGS='-Wl,-R,${LIB_RUNTIME_DIR}' + LD_SEARCH_FLAGS=${CC_SEARCH_FLAGS} + +else + + SHLIB_LD="/usr/ccs/bin/ld -G -z text" + CC_SEARCH_FLAGS='-R ${LIB_RUNTIME_DIR}' + LD_SEARCH_FLAGS=${CC_SEARCH_FLAGS} + +fi + ;; + SunOS-5*) + # Note: If _REENTRANT isn't defined, then Solaris + # won't define thread-safe library routines. + + +$as_echo "#define _REENTRANT 1" >>confdefs.h + + +$as_echo "#define _POSIX_PTHREAD_SEMANTICS 1" >>confdefs.h + + + SHLIB_CFLAGS="-KPIC" + + # Check to enable 64-bit flags for compiler/linker + if test "$do64bit" = yes; then : + + arch=`isainfo` + if test "$arch" = "sparcv9 sparc"; then : + + if test "$GCC" = yes; then : + + if test "`${CC} -dumpversion | awk -F. '{print $1}'`" -lt 3; then : + + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: 64bit mode not supported with GCC < 3.2 on $system" >&5 +$as_echo "$as_me: WARNING: 64bit mode not supported with GCC < 3.2 on $system" >&2;} + +else + + do64bit_ok=yes + CFLAGS="$CFLAGS -m64 -mcpu=v9" + LDFLAGS="$LDFLAGS -m64 -mcpu=v9" + SHLIB_CFLAGS="-fPIC" + +fi + +else + + do64bit_ok=yes + if test "$do64bitVIS" = yes; then : + + CFLAGS="$CFLAGS -xarch=v9a" + LDFLAGS_ARCH="-xarch=v9a" + +else + + CFLAGS="$CFLAGS -xarch=v9" + LDFLAGS_ARCH="-xarch=v9" + +fi + # Solaris 64 uses this as well + #LD_LIBRARY_PATH_VAR="LD_LIBRARY_PATH_64" + +fi + +else + if test "$arch" = "amd64 i386"; then : + + if test "$GCC" = yes; then : + + case $system in + SunOS-5.1[1-9]*|SunOS-5.[2-9][0-9]*) + do64bit_ok=yes + CFLAGS="$CFLAGS -m64" + LDFLAGS="$LDFLAGS -m64";; + *) + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: 64bit mode not supported with GCC on $system" >&5 +$as_echo "$as_me: WARNING: 64bit mode not supported with GCC on $system" >&2;};; + esac + +else + + do64bit_ok=yes + case $system in + SunOS-5.1[1-9]*|SunOS-5.[2-9][0-9]*) + CFLAGS="$CFLAGS -m64" + LDFLAGS="$LDFLAGS -m64";; + *) + CFLAGS="$CFLAGS -xarch=amd64" + LDFLAGS="$LDFLAGS -xarch=amd64";; + esac + +fi + +else + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: 64bit mode not supported for $arch" >&5 +$as_echo "$as_me: WARNING: 64bit mode not supported for $arch" >&2;} +fi +fi + +fi + + SHLIB_SUFFIX=".so" + if test "$GCC" = yes; then : + + SHLIB_LD='${CC} -shared' + CC_SEARCH_FLAGS='-Wl,-R,${LIB_RUNTIME_DIR}' + LD_SEARCH_FLAGS=${CC_SEARCH_FLAGS} + if test "$do64bit_ok" = yes; then : + + if test "$arch" = "sparcv9 sparc"; then : + + # We need to specify -static-libgcc or we need to + # add the path to the sparv9 libgcc. + # JH: static-libgcc is necessary for core Tcl, but may + # not be necessary for extensions. + SHLIB_LD="$SHLIB_LD -m64 -mcpu=v9 -static-libgcc" + # for finding sparcv9 libgcc, get the regular libgcc + # path, remove so name and append 'sparcv9' + #v9gcclibdir="`gcc -print-file-name=libgcc_s.so` | ..." + #CC_SEARCH_FLAGS="${CC_SEARCH_FLAGS},-R,$v9gcclibdir" + +else + if test "$arch" = "amd64 i386"; then : + + # JH: static-libgcc is necessary for core Tcl, but may + # not be necessary for extensions. + SHLIB_LD="$SHLIB_LD -m64 -static-libgcc" + +fi +fi + +fi + +else + + case $system in + SunOS-5.[1-9][0-9]*) + # TEA specific: use LDFLAGS_DEFAULT instead of LDFLAGS + SHLIB_LD='${CC} -G -z text ${LDFLAGS_DEFAULT}';; + *) + SHLIB_LD='/usr/ccs/bin/ld -G -z text';; + esac + CC_SEARCH_FLAGS='-Wl,-R,${LIB_RUNTIME_DIR}' + LD_SEARCH_FLAGS='-R ${LIB_RUNTIME_DIR}' + +fi + ;; + UNIX_SV* | UnixWare-5*) + SHLIB_CFLAGS="-KPIC" + SHLIB_LD='${CC} -G' + SHLIB_LD_LIBS="" + SHLIB_SUFFIX=".so" + # Some UNIX_SV* systems (unixware 1.1.2 for example) have linkers + # that don't grok the -Bexport option. Test that it does. + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ld accepts -Bexport flag" >&5 +$as_echo_n "checking for ld accepts -Bexport flag... " >&6; } +if ${tcl_cv_ld_Bexport+:} false; then : + $as_echo_n "(cached) " >&6 +else + + hold_ldflags=$LDFLAGS + LDFLAGS="$LDFLAGS -Wl,-Bexport" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ +int i; + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + tcl_cv_ld_Bexport=yes +else + tcl_cv_ld_Bexport=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext + LDFLAGS=$hold_ldflags +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_ld_Bexport" >&5 +$as_echo "$tcl_cv_ld_Bexport" >&6; } + if test $tcl_cv_ld_Bexport = yes; then : + + LDFLAGS="$LDFLAGS -Wl,-Bexport" + +fi + CC_SEARCH_FLAGS="" + LD_SEARCH_FLAGS="" + ;; + esac + + if test "$do64bit" = yes -a "$do64bit_ok" = no; then : + + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: 64bit support being disabled -- don't know magic for this platform" >&5 +$as_echo "$as_me: WARNING: 64bit support being disabled -- don't know magic for this platform" >&2;} + +fi + + + + # Add in the arch flags late to ensure it wasn't removed. + # Not necessary in TEA, but this is aligned with core + LDFLAGS="$LDFLAGS $LDFLAGS_ARCH" + + # If we're running gcc, then change the C flags for compiling shared + # libraries to the right flags for gcc, instead of those for the + # standard manufacturer compiler. + + if test "$GCC" = yes; then : + + case $system in + AIX-*) ;; + BSD/OS*) ;; + CYGWIN_*|MINGW32_*|MINGW64_*) ;; + IRIX*) ;; + NetBSD-*|FreeBSD-*|OpenBSD-*) ;; + Darwin-*) ;; + SCO_SV-3.2*) ;; + windows) ;; + *) SHLIB_CFLAGS="-fPIC" ;; + esac +fi + + if test "$tcl_cv_cc_visibility_hidden" != yes; then : + + +$as_echo "#define MODULE_SCOPE extern" >>confdefs.h + + +fi + + if test "$SHARED_LIB_SUFFIX" = ""; then : + + # TEA specific: use PACKAGE_VERSION instead of VERSION + SHARED_LIB_SUFFIX='${PACKAGE_VERSION}${SHLIB_SUFFIX}' +fi + if test "$UNSHARED_LIB_SUFFIX" = ""; then : + + # TEA specific: use PACKAGE_VERSION instead of VERSION + UNSHARED_LIB_SUFFIX='${PACKAGE_VERSION}.a' +fi + + if test "${GCC}" = "yes" -a ${SHLIB_SUFFIX} = ".dll"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for SEH support in compiler" >&5 +$as_echo_n "checking for SEH support in compiler... " >&6; } +if ${tcl_cv_seh+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test "$cross_compiling" = yes; then : + tcl_cv_seh=no +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +#define WIN32_LEAN_AND_MEAN +#include +#undef WIN32_LEAN_AND_MEAN + + int main(int argc, char** argv) { + int a, b = 0; + __try { + a = 666 / b; + } + __except (EXCEPTION_EXECUTE_HANDLER) { + return 0; + } + return 1; + } + +_ACEOF +if ac_fn_c_try_run "$LINENO"; then : + tcl_cv_seh=yes +else + tcl_cv_seh=no +fi +rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ + conftest.$ac_objext conftest.beam conftest.$ac_ext +fi + + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_seh" >&5 +$as_echo "$tcl_cv_seh" >&6; } + if test "$tcl_cv_seh" = "no" ; then + +$as_echo "#define HAVE_NO_SEH 1" >>confdefs.h + + fi + + # + # Check to see if the excpt.h include file provided contains the + # definition for EXCEPTION_DISPOSITION; if not, which is the case + # with Cygwin's version as of 2002-04-10, define it to be int, + # sufficient for getting the current code to work. + # + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for EXCEPTION_DISPOSITION support in include files" >&5 +$as_echo_n "checking for EXCEPTION_DISPOSITION support in include files... " >&6; } +if ${tcl_cv_eh_disposition+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +# define WIN32_LEAN_AND_MEAN +# include +# undef WIN32_LEAN_AND_MEAN + +int +main () +{ + + EXCEPTION_DISPOSITION x; + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + tcl_cv_eh_disposition=yes +else + tcl_cv_eh_disposition=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_eh_disposition" >&5 +$as_echo "$tcl_cv_eh_disposition" >&6; } + if test "$tcl_cv_eh_disposition" = "no" ; then + +$as_echo "#define EXCEPTION_DISPOSITION int" >>confdefs.h + + fi + + # Check to see if winnt.h defines CHAR, SHORT, and LONG + # even if VOID has already been #defined. The win32api + # used by mingw and cygwin is known to do this. + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for winnt.h that ignores VOID define" >&5 +$as_echo_n "checking for winnt.h that ignores VOID define... " >&6; } +if ${tcl_cv_winnt_ignore_void+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +#define VOID void +#define WIN32_LEAN_AND_MEAN +#include +#undef WIN32_LEAN_AND_MEAN + +int +main () +{ + + CHAR c; + SHORT s; + LONG l; + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + tcl_cv_winnt_ignore_void=yes +else + tcl_cv_winnt_ignore_void=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_winnt_ignore_void" >&5 +$as_echo "$tcl_cv_winnt_ignore_void" >&6; } + if test "$tcl_cv_winnt_ignore_void" = "yes" ; then + +$as_echo "#define HAVE_WINNT_IGNORE_VOID 1" >>confdefs.h + + fi + fi + + # See if the compiler supports casting to a union type. + # This is used to stop gcc from printing a compiler + # warning when initializing a union member. + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for cast to union support" >&5 +$as_echo_n "checking for cast to union support... " >&6; } +if ${tcl_cv_cast_to_union+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + union foo { int i; double d; }; + union foo f = (union foo) (int) 0; + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + tcl_cv_cast_to_union=yes +else + tcl_cv_cast_to_union=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_cast_to_union" >&5 +$as_echo "$tcl_cv_cast_to_union" >&6; } + if test "$tcl_cv_cast_to_union" = "yes"; then + +$as_echo "#define HAVE_CAST_TO_UNION 1" >>confdefs.h + + fi + + + + + + + + + + + + + + # These must be called after we do the basic CFLAGS checks and + # verify any possible 64-bit or similar switches are necessary + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for required early compiler flags" >&5 +$as_echo_n "checking for required early compiler flags... " >&6; } + tcl_flags="" + + if ${tcl_cv_flag__isoc99_source+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +int +main () +{ +char *p = (char *)strtoll; char *q = (char *)strtoull; + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + tcl_cv_flag__isoc99_source=no +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#define _ISOC99_SOURCE 1 +#include +int +main () +{ +char *p = (char *)strtoll; char *q = (char *)strtoull; + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + tcl_cv_flag__isoc99_source=yes +else + tcl_cv_flag__isoc99_source=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi + + if test "x${tcl_cv_flag__isoc99_source}" = "xyes" ; then + +$as_echo "#define _ISOC99_SOURCE 1" >>confdefs.h + + tcl_flags="$tcl_flags _ISOC99_SOURCE" + fi + + + if ${tcl_cv_flag__largefile64_source+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +int +main () +{ +struct stat64 buf; int i = stat64("/", &buf); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + tcl_cv_flag__largefile64_source=no +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#define _LARGEFILE64_SOURCE 1 +#include +int +main () +{ +struct stat64 buf; int i = stat64("/", &buf); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + tcl_cv_flag__largefile64_source=yes +else + tcl_cv_flag__largefile64_source=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi + + if test "x${tcl_cv_flag__largefile64_source}" = "xyes" ; then + +$as_echo "#define _LARGEFILE64_SOURCE 1" >>confdefs.h + + tcl_flags="$tcl_flags _LARGEFILE64_SOURCE" + fi + + + if ${tcl_cv_flag__largefile_source64+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +int +main () +{ +char *p = (char *)open64; + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + tcl_cv_flag__largefile_source64=no +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#define _LARGEFILE_SOURCE64 1 +#include +int +main () +{ +char *p = (char *)open64; + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + tcl_cv_flag__largefile_source64=yes +else + tcl_cv_flag__largefile_source64=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi + + if test "x${tcl_cv_flag__largefile_source64}" = "xyes" ; then + +$as_echo "#define _LARGEFILE_SOURCE64 1" >>confdefs.h + + tcl_flags="$tcl_flags _LARGEFILE_SOURCE64" + fi + + if test "x${tcl_flags}" = "x" ; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: none" >&5 +$as_echo "none" >&6; } + else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: ${tcl_flags}" >&5 +$as_echo "${tcl_flags}" >&6; } + fi + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for 64-bit integer type" >&5 +$as_echo_n "checking for 64-bit integer type... " >&6; } + if ${tcl_cv_type_64bit+:} false; then : + $as_echo_n "(cached) " >&6 +else + + tcl_cv_type_64bit=none + # See if the compiler knows natively about __int64 + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ +__int64 value = (__int64) 0; + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + tcl_type_64bit=__int64 +else + tcl_type_64bit="long long" +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + # See if we should use long anyway Note that we substitute in the + # type that is our current guess for a 64-bit type inside this check + # program, so it should be modified only carefully... + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ +switch (0) { + case 1: case (sizeof(${tcl_type_64bit})==sizeof(long)): ; + } + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + tcl_cv_type_64bit=${tcl_type_64bit} +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi + + if test "${tcl_cv_type_64bit}" = none ; then + +$as_echo "#define TCL_WIDE_INT_IS_LONG 1" >>confdefs.h + + { $as_echo "$as_me:${as_lineno-$LINENO}: result: using long" >&5 +$as_echo "using long" >&6; } + elif test "${tcl_cv_type_64bit}" = "__int64" \ + -a "${TEA_PLATFORM}" = "windows" ; then + # TEA specific: We actually want to use the default tcl.h checks in + # this case to handle both TCL_WIDE_INT_TYPE and TCL_LL_MODIFIER* + { $as_echo "$as_me:${as_lineno-$LINENO}: result: using Tcl header defaults" >&5 +$as_echo "using Tcl header defaults" >&6; } + else + +cat >>confdefs.h <<_ACEOF +#define TCL_WIDE_INT_TYPE ${tcl_cv_type_64bit} +_ACEOF + + { $as_echo "$as_me:${as_lineno-$LINENO}: result: ${tcl_cv_type_64bit}" >&5 +$as_echo "${tcl_cv_type_64bit}" >&6; } + + # Now check for auxiliary declarations + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for struct dirent64" >&5 +$as_echo_n "checking for struct dirent64... " >&6; } +if ${tcl_cv_struct_dirent64+:} false; then : + $as_echo_n "(cached) " >&6 +else + + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +#include +int +main () +{ +struct dirent64 p; + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + tcl_cv_struct_dirent64=yes +else + tcl_cv_struct_dirent64=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_struct_dirent64" >&5 +$as_echo "$tcl_cv_struct_dirent64" >&6; } + if test "x${tcl_cv_struct_dirent64}" = "xyes" ; then + +$as_echo "#define HAVE_STRUCT_DIRENT64 1" >>confdefs.h + + fi + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for struct stat64" >&5 +$as_echo_n "checking for struct stat64... " >&6; } +if ${tcl_cv_struct_stat64+:} false; then : + $as_echo_n "(cached) " >&6 +else + + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +int +main () +{ +struct stat64 p; + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + tcl_cv_struct_stat64=yes +else + tcl_cv_struct_stat64=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_struct_stat64" >&5 +$as_echo "$tcl_cv_struct_stat64" >&6; } + if test "x${tcl_cv_struct_stat64}" = "xyes" ; then + +$as_echo "#define HAVE_STRUCT_STAT64 1" >>confdefs.h + + fi + + for ac_func in open64 lseek64 +do : + as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` +ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var" +if eval test \"x\$"$as_ac_var"\" = x"yes"; then : + cat >>confdefs.h <<_ACEOF +#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1 +_ACEOF + +fi +done + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for off64_t" >&5 +$as_echo_n "checking for off64_t... " >&6; } + if ${tcl_cv_type_off64_t+:} false; then : + $as_echo_n "(cached) " >&6 +else + + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +int +main () +{ +off64_t offset; + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + tcl_cv_type_off64_t=yes +else + tcl_cv_type_off64_t=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi + + if test "x${tcl_cv_type_off64_t}" = "xyes" && \ + test "x${ac_cv_func_lseek64}" = "xyes" && \ + test "x${ac_cv_func_open64}" = "xyes" ; then + +$as_echo "#define HAVE_TYPE_OFF64_T 1" >>confdefs.h + + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + fi + fi + + + +#-------------------------------------------------------------------- +# Set the default compiler switches based on the --enable-symbols option. +#-------------------------------------------------------------------- + + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for build with symbols" >&5 +$as_echo_n "checking for build with symbols... " >&6; } + # Check whether --enable-symbols was given. +if test "${enable_symbols+set}" = set; then : + enableval=$enable_symbols; tcl_ok=$enableval +else + tcl_ok=no +fi + + DBGX="" + if test "$tcl_ok" = "no"; then + CFLAGS_DEFAULT="${CFLAGS_OPTIMIZE} -DNDEBUG" + LDFLAGS_DEFAULT="${LDFLAGS_OPTIMIZE}" + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + else + CFLAGS_DEFAULT="${CFLAGS_DEBUG}" + LDFLAGS_DEFAULT="${LDFLAGS_DEBUG}" + if test "$tcl_ok" = "yes"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes (standard debugging)" >&5 +$as_echo "yes (standard debugging)" >&6; } + fi + fi + # TEA specific: + if test "${TEA_PLATFORM}" != "windows" ; then + LDFLAGS_DEFAULT="${LDFLAGS}" + fi + + + + + if test "$tcl_ok" = "mem" -o "$tcl_ok" = "all"; then + +$as_echo "#define TCL_MEM_DEBUG 1" >>confdefs.h + + fi + + if test "$tcl_ok" != "yes" -a "$tcl_ok" != "no"; then + if test "$tcl_ok" = "all"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: enabled symbols mem debugging" >&5 +$as_echo "enabled symbols mem debugging" >&6; } + else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: enabled $tcl_ok debugging" >&5 +$as_echo "enabled $tcl_ok debugging" >&6; } + fi + fi + + +#-------------------------------------------------------------------- +# Everyone should be linking against the Tcl stub library. If you +# can't for some reason, remove this definition. If you aren't using +# stubs, you also need to modify the SHLIB_LD_LIBS setting below to +# link against the non-stubbed Tcl library. Add Tk too if necessary. +#-------------------------------------------------------------------- + + +$as_echo "#define USE_TCL_STUBS 1" >>confdefs.h + +#AC_DEFINE(USE_TK_STUBS, 1, [Use Tk stubs]) + +#-------------------------------------------------------------------- +# This macro generates a line to use when building a library. It +# depends on values set by the TEA_ENABLE_SHARED, TEA_ENABLE_SYMBOLS, +# and TEA_LOAD_TCLCONFIG macros above. +#-------------------------------------------------------------------- + + + if test "${TEA_PLATFORM}" = "windows" -a "$GCC" != "yes"; then + MAKE_STATIC_LIB="\${STLIB_LD} -out:\$@ \$(PKG_OBJECTS)" + MAKE_SHARED_LIB="\${SHLIB_LD} \${SHLIB_LD_LIBS} \${LDFLAGS_DEFAULT} -out:\$@ \$(PKG_OBJECTS)" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +#if defined(_MSC_VER) && _MSC_VER >= 1400 +print("manifest needed") +#endif + +_ACEOF +if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | + $EGREP "manifest needed" >/dev/null 2>&1; then : + + # Could do a CHECK_PROG for mt, but should always be with MSVC8+ + VC_MANIFEST_EMBED_DLL="if test -f \$@.manifest ; then mt.exe -nologo -manifest \$@.manifest -outputresource:\$@\;2 ; fi" + VC_MANIFEST_EMBED_EXE="if test -f \$@.manifest ; then mt.exe -nologo -manifest \$@.manifest -outputresource:\$@\;1 ; fi" + MAKE_SHARED_LIB="${MAKE_SHARED_LIB} ; ${VC_MANIFEST_EMBED_DLL}" + + CLEANFILES="$CLEANFILES *.manifest" + + +fi +rm -f conftest* + + MAKE_STUB_LIB="\${STLIB_LD} -nodefaultlib -out:\$@ \$(PKG_STUB_OBJECTS)" + else + MAKE_STATIC_LIB="\${STLIB_LD} \$@ \$(PKG_OBJECTS)" + MAKE_SHARED_LIB="\${SHLIB_LD} -o \$@ \$(PKG_OBJECTS) \${SHLIB_LD_LIBS}" + MAKE_STUB_LIB="\${STLIB_LD} \$@ \$(PKG_STUB_OBJECTS)" + fi + + if test "${SHARED_BUILD}" = "1" ; then + MAKE_LIB="${MAKE_SHARED_LIB} " + else + MAKE_LIB="${MAKE_STATIC_LIB} " + fi + + #-------------------------------------------------------------------- + # Shared libraries and static libraries have different names. + # Use the double eval to make sure any variables in the suffix is + # substituted. (@@@ Might not be necessary anymore) + #-------------------------------------------------------------------- + + if test "${TEA_PLATFORM}" = "windows" ; then + if test "${SHARED_BUILD}" = "1" ; then + # We force the unresolved linking of symbols that are really in + # the private libraries of Tcl and Tk. + if test x"${TK_BIN_DIR}" != x ; then + SHLIB_LD_LIBS="${SHLIB_LD_LIBS} \"`${CYGPATH} ${TK_BIN_DIR}/${TK_STUB_LIB_FILE}`\"" + fi + SHLIB_LD_LIBS="${SHLIB_LD_LIBS} \"`${CYGPATH} ${TCL_BIN_DIR}/${TCL_STUB_LIB_FILE}`\"" + if test "$GCC" = "yes"; then + SHLIB_LD_LIBS="${SHLIB_LD_LIBS} -static-libgcc" + fi + eval eval "PKG_LIB_FILE=${PACKAGE_LIB_PREFIX}${PACKAGE_NAME}${SHARED_LIB_SUFFIX}" + else + eval eval "PKG_LIB_FILE=${PACKAGE_LIB_PREFIX}${PACKAGE_NAME}${UNSHARED_LIB_SUFFIX}" + if test "$GCC" = "yes"; then + PKG_LIB_FILE=lib${PKG_LIB_FILE} + fi + fi + # Some packages build their own stubs libraries + eval eval "PKG_STUB_LIB_FILE=${PACKAGE_LIB_PREFIX}${PACKAGE_NAME}stub${UNSHARED_LIB_SUFFIX}" + if test "$GCC" = "yes"; then + PKG_STUB_LIB_FILE=lib${PKG_STUB_LIB_FILE} + fi + # These aren't needed on Windows (either MSVC or gcc) + RANLIB=: + RANLIB_STUB=: + else + RANLIB_STUB="${RANLIB}" + if test "${SHARED_BUILD}" = "1" ; then + SHLIB_LD_LIBS="${SHLIB_LD_LIBS} ${TCL_STUB_LIB_SPEC}" + if test x"${TK_BIN_DIR}" != x ; then + SHLIB_LD_LIBS="${SHLIB_LD_LIBS} ${TK_STUB_LIB_SPEC}" + fi + eval eval "PKG_LIB_FILE=lib${PACKAGE_LIB_PREFIX}${PACKAGE_NAME}${SHARED_LIB_SUFFIX}" + RANLIB=: + else + eval eval "PKG_LIB_FILE=lib${PACKAGE_LIB_PREFIX}${PACKAGE_NAME}${UNSHARED_LIB_SUFFIX}" + fi + # Some packages build their own stubs libraries + eval eval "PKG_STUB_LIB_FILE=lib${PACKAGE_LIB_PREFIX}${PACKAGE_NAME}stub${UNSHARED_LIB_SUFFIX}" + fi + + # These are escaped so that only CFLAGS is picked up at configure time. + # The other values will be substituted at make time. + CFLAGS="${CFLAGS} \${CFLAGS_DEFAULT} \${CFLAGS_WARNING}" + if test "${SHARED_BUILD}" = "1" ; then + CFLAGS="${CFLAGS} \${SHLIB_CFLAGS}" + fi + + + + + + + + + + +#-------------------------------------------------------------------- +# Determine the name of the tclsh and/or wish executables in the +# Tcl and Tk build directories or the location they were installed +# into. These paths are used to support running test cases only, +# the Makefile should not be making use of these paths to generate +# a pkgIndex.tcl file or anything else at extension build time. +#-------------------------------------------------------------------- + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for tclsh" >&5 +$as_echo_n "checking for tclsh... " >&6; } + if test -f "${TCL_BIN_DIR}/Makefile" ; then + # tclConfig.sh is in Tcl build directory + if test "${TEA_PLATFORM}" = "windows"; then + if test -f "${TCL_BIN_DIR}/tclsh${TCL_MAJOR_VERSION}${TCL_MINOR_VERSION}${TCL_DBGX}${EXEEXT}" ; then + TCLSH_PROG="${TCL_BIN_DIR}/tclsh${TCL_MAJOR_VERSION}${TCL_MINOR_VERSION}${TCL_DBGX}${EXEEXT}" + elif test -f "${TCL_BIN_DIR}/tclsh${TCL_MAJOR_VERSION}${TCL_MINOR_VERSION}${TCL_DBGX}s${EXEEXT}" ; then + TCLSH_PROG="${TCL_BIN_DIR}/tclsh${TCL_MAJOR_VERSION}${TCL_MINOR_VERSION}${TCL_DBGX}s${EXEEXT}" + elif test -f "${TCL_BIN_DIR}/tclsh${TCL_MAJOR_VERSION}${TCL_MINOR_VERSION}${TCL_DBGX}t${EXEEXT}" ; then + TCLSH_PROG="${TCL_BIN_DIR}/tclsh${TCL_MAJOR_VERSION}${TCL_MINOR_VERSION}${TCL_DBGX}t${EXEEXT}" + elif test -f "${TCL_BIN_DIR}/tclsh${TCL_MAJOR_VERSION}${TCL_MINOR_VERSION}${TCL_DBGX}st${EXEEXT}" ; then + TCLSH_PROG="${TCL_BIN_DIR}/tclsh${TCL_MAJOR_VERSION}${TCL_MINOR_VERSION}${TCL_DBGX}st${EXEEXT}" + fi + else + TCLSH_PROG="${TCL_BIN_DIR}/tclsh" + fi + else + # tclConfig.sh is in install location + if test "${TEA_PLATFORM}" = "windows"; then + TCLSH_PROG="tclsh${TCL_MAJOR_VERSION}${TCL_MINOR_VERSION}${TCL_DBGX}${EXEEXT}" + else + TCLSH_PROG="tclsh${TCL_MAJOR_VERSION}.${TCL_MINOR_VERSION}${TCL_DBGX}" + fi + list="`ls -d ${TCL_BIN_DIR}/../bin 2>/dev/null` \ + `ls -d ${TCL_BIN_DIR}/.. 2>/dev/null` \ + `ls -d ${TCL_PREFIX}/bin 2>/dev/null`" + for i in $list ; do + if test -f "$i/${TCLSH_PROG}" ; then + REAL_TCL_BIN_DIR="`cd "$i"; pwd`/" + break + fi + done + TCLSH_PROG="${REAL_TCL_BIN_DIR}${TCLSH_PROG}" + fi + { $as_echo "$as_me:${as_lineno-$LINENO}: result: ${TCLSH_PROG}" >&5 +$as_echo "${TCLSH_PROG}" >&6; } + + +#TEA_PROG_WISH + +#-------------------------------------------------------------------- +# Finally, substitute all of the various values into the Makefile. +# You may alternatively have a special pkgIndex.tcl.in or other files +# which require substituting th AC variables in. Include these here. +#-------------------------------------------------------------------- + +ac_config_files="$ac_config_files Makefile pkgIndex.tcl" + +cat >confcache <<\_ACEOF +# This file is a shell script that caches the results of configure +# tests run on this system so they can be shared between configure +# scripts and configure runs, see configure's option --config-cache. +# It is not useful on other systems. If it contains results you don't +# want to keep, you may remove or edit it. +# +# config.status only pays attention to the cache file if you give it +# the --recheck option to rerun configure. +# +# `ac_cv_env_foo' variables (set or unset) will be overridden when +# loading this file, other *unset* `ac_cv_foo' will be assigned the +# following values. + +_ACEOF + +# The following way of writing the cache mishandles newlines in values, +# but we know of no workaround that is simple, portable, and efficient. +# So, we kill variables containing newlines. +# Ultrix sh set writes to stderr and can't be redirected directly, +# and sets the high bit in the cache file unless we assign to the vars. +( + for ac_var in `(set) 2>&1 | sed -n 's/^\([a-zA-Z_][a-zA-Z0-9_]*\)=.*/\1/p'`; do + eval ac_val=\$$ac_var + case $ac_val in #( + *${as_nl}*) + case $ac_var in #( + *_cv_*) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: cache variable $ac_var contains a newline" >&5 +$as_echo "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;; + esac + case $ac_var in #( + _ | IFS | as_nl) ;; #( + BASH_ARGV | BASH_SOURCE) eval $ac_var= ;; #( + *) { eval $ac_var=; unset $ac_var;} ;; + esac ;; + esac + done + + (set) 2>&1 | + case $as_nl`(ac_space=' '; set) 2>&1` in #( + *${as_nl}ac_space=\ *) + # `set' does not quote correctly, so add quotes: double-quote + # substitution turns \\\\ into \\, and sed turns \\ into \. + sed -n \ + "s/'/'\\\\''/g; + s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\\2'/p" + ;; #( + *) + # `set' quotes correctly as required by POSIX, so do not add quotes. + sed -n "/^[_$as_cr_alnum]*_cv_[_$as_cr_alnum]*=/p" + ;; + esac | + sort +) | + sed ' + /^ac_cv_env_/b end + t clear + :clear + s/^\([^=]*\)=\(.*[{}].*\)$/test "${\1+set}" = set || &/ + t end + s/^\([^=]*\)=\(.*\)$/\1=${\1=\2}/ + :end' >>confcache +if diff "$cache_file" confcache >/dev/null 2>&1; then :; else + if test -w "$cache_file"; then + if test "x$cache_file" != "x/dev/null"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: updating cache $cache_file" >&5 +$as_echo "$as_me: updating cache $cache_file" >&6;} + if test ! -f "$cache_file" || test -h "$cache_file"; then + cat confcache >"$cache_file" + else + case $cache_file in #( + */* | ?:*) + mv -f confcache "$cache_file"$$ && + mv -f "$cache_file"$$ "$cache_file" ;; #( + *) + mv -f confcache "$cache_file" ;; + esac + fi + fi + else + { $as_echo "$as_me:${as_lineno-$LINENO}: not updating unwritable cache $cache_file" >&5 +$as_echo "$as_me: not updating unwritable cache $cache_file" >&6;} + fi +fi +rm -f confcache + +test "x$prefix" = xNONE && prefix=$ac_default_prefix +# Let make expand exec_prefix. +test "x$exec_prefix" = xNONE && exec_prefix='${prefix}' + +# Transform confdefs.h into DEFS. +# Protect against shell expansion while executing Makefile rules. +# Protect against Makefile macro expansion. +# +# If the first sed substitution is executed (which looks for macros that +# take arguments), then branch to the quote section. Otherwise, +# look for a macro that doesn't take arguments. +ac_script=' +:mline +/\\$/{ + N + s,\\\n,, + b mline +} +t clear +:clear +s/^[ ]*#[ ]*define[ ][ ]*\([^ (][^ (]*([^)]*)\)[ ]*\(.*\)/-D\1=\2/g +t quote +s/^[ ]*#[ ]*define[ ][ ]*\([^ ][^ ]*\)[ ]*\(.*\)/-D\1=\2/g +t quote +b any +:quote +s/[ `~#$^&*(){}\\|;'\''"<>?]/\\&/g +s/\[/\\&/g +s/\]/\\&/g +s/\$/$$/g +H +:any +${ + g + s/^\n// + s/\n/ /g + p +} +' +DEFS=`sed -n "$ac_script" confdefs.h` + + +ac_libobjs= +ac_ltlibobjs= +U= +for ac_i in : $LIBOBJS; do test "x$ac_i" = x: && continue + # 1. Remove the extension, and $U if already installed. + ac_script='s/\$U\././;s/\.o$//;s/\.obj$//' + ac_i=`$as_echo "$ac_i" | sed "$ac_script"` + # 2. Prepend LIBOBJDIR. When used with automake>=1.10 LIBOBJDIR + # will be set to the directory where LIBOBJS objects are built. + as_fn_append ac_libobjs " \${LIBOBJDIR}$ac_i\$U.$ac_objext" + as_fn_append ac_ltlibobjs " \${LIBOBJDIR}$ac_i"'$U.lo' +done +LIBOBJS=$ac_libobjs + +LTLIBOBJS=$ac_ltlibobjs + + + +CFLAGS="${CFLAGS} ${CPPFLAGS}"; CPPFLAGS="" + +: "${CONFIG_STATUS=./config.status}" +ac_write_fail=0 +ac_clean_files_save=$ac_clean_files +ac_clean_files="$ac_clean_files $CONFIG_STATUS" +{ $as_echo "$as_me:${as_lineno-$LINENO}: creating $CONFIG_STATUS" >&5 +$as_echo "$as_me: creating $CONFIG_STATUS" >&6;} +as_write_fail=0 +cat >$CONFIG_STATUS <<_ASEOF || as_write_fail=1 +#! $SHELL +# Generated by $as_me. +# Run this file to recreate the current configuration. +# Compiler output produced by configure, useful for debugging +# configure, is in config.log if it exists. + +debug=false +ac_cs_recheck=false +ac_cs_silent=false + +SHELL=\${CONFIG_SHELL-$SHELL} +export SHELL +_ASEOF +cat >>$CONFIG_STATUS <<\_ASEOF || as_write_fail=1 +## -------------------- ## +## M4sh Initialization. ## +## -------------------- ## + +# Be more Bourne compatible +DUALCASE=1; export DUALCASE # for MKS sh +if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then : + emulate sh + NULLCMD=: + # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which + # is contrary to our usage. Disable this feature. + alias -g '${1+"$@"}'='"$@"' + setopt NO_GLOB_SUBST +else + case `(set -o) 2>/dev/null` in #( + *posix*) : + set -o posix ;; #( + *) : + ;; +esac +fi + + +as_nl=' +' +export as_nl +# Printing a long string crashes Solaris 7 /usr/bin/printf. +as_echo='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\' +as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo +as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo$as_echo +# Prefer a ksh shell builtin over an external printf program on Solaris, +# but without wasting forks for bash or zsh. +if test -z "$BASH_VERSION$ZSH_VERSION" \ + && (test "X`print -r -- $as_echo`" = "X$as_echo") 2>/dev/null; then + as_echo='print -r --' + as_echo_n='print -rn --' +elif (test "X`printf %s $as_echo`" = "X$as_echo") 2>/dev/null; then + as_echo='printf %s\n' + as_echo_n='printf %s' +else + if test "X`(/usr/ucb/echo -n -n $as_echo) 2>/dev/null`" = "X-n $as_echo"; then + as_echo_body='eval /usr/ucb/echo -n "$1$as_nl"' + as_echo_n='/usr/ucb/echo -n' + else + as_echo_body='eval expr "X$1" : "X\\(.*\\)"' + as_echo_n_body='eval + arg=$1; + case $arg in #( + *"$as_nl"*) + expr "X$arg" : "X\\(.*\\)$as_nl"; + arg=`expr "X$arg" : ".*$as_nl\\(.*\\)"`;; + esac; + expr "X$arg" : "X\\(.*\\)" | tr -d "$as_nl" + ' + export as_echo_n_body + as_echo_n='sh -c $as_echo_n_body as_echo' + fi + export as_echo_body + as_echo='sh -c $as_echo_body as_echo' +fi + +# The user is always right. +if test "${PATH_SEPARATOR+set}" != set; then + PATH_SEPARATOR=: + (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && { + (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 || + PATH_SEPARATOR=';' + } +fi + + +# IFS +# We need space, tab and new line, in precisely that order. Quoting is +# there to prevent editors from complaining about space-tab. +# (If _AS_PATH_WALK were called with IFS unset, it would disable word +# splitting by setting IFS to empty value.) +IFS=" "" $as_nl" + +# Find who we are. Look in the path if we contain no directory separator. +as_myself= +case $0 in #(( + *[\\/]* ) as_myself=$0 ;; + *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break + done +IFS=$as_save_IFS + + ;; +esac +# We did not find ourselves, most probably we were run as `sh COMMAND' +# in which case we are not to be found in the path. +if test "x$as_myself" = x; then + as_myself=$0 +fi +if test ! -f "$as_myself"; then + $as_echo "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2 + exit 1 +fi + +# Unset variables that we do not need and which cause bugs (e.g. in +# pre-3.0 UWIN ksh). But do not cause bugs in bash 2.01; the "|| exit 1" +# suppresses any "Segmentation fault" message there. '((' could +# trigger a bug in pdksh 5.2.14. +for as_var in BASH_ENV ENV MAIL MAILPATH +do eval test x\${$as_var+set} = xset \ + && ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || : +done +PS1='$ ' +PS2='> ' +PS4='+ ' + +# NLS nuisances. +LC_ALL=C +export LC_ALL +LANGUAGE=C +export LANGUAGE + +# CDPATH. +(unset CDPATH) >/dev/null 2>&1 && unset CDPATH + + +# as_fn_error STATUS ERROR [LINENO LOG_FD] +# ---------------------------------------- +# Output "`basename $0`: error: ERROR" to stderr. If LINENO and LOG_FD are +# provided, also output the error to LOG_FD, referencing LINENO. Then exit the +# script with STATUS, using 1 if that was 0. +as_fn_error () +{ + as_status=$1; test $as_status -eq 0 && as_status=1 + if test "$4"; then + as_lineno=${as_lineno-"$3"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + $as_echo "$as_me:${as_lineno-$LINENO}: error: $2" >&$4 + fi + $as_echo "$as_me: error: $2" >&2 + as_fn_exit $as_status +} # as_fn_error + + +# as_fn_set_status STATUS +# ----------------------- +# Set $? to STATUS, without forking. +as_fn_set_status () +{ + return $1 +} # as_fn_set_status + +# as_fn_exit STATUS +# ----------------- +# Exit the shell with STATUS, even in a "trap 0" or "set -e" context. +as_fn_exit () +{ + set +e + as_fn_set_status $1 + exit $1 +} # as_fn_exit + +# as_fn_unset VAR +# --------------- +# Portably unset VAR. +as_fn_unset () +{ + { eval $1=; unset $1;} +} +as_unset=as_fn_unset +# as_fn_append VAR VALUE +# ---------------------- +# Append the text in VALUE to the end of the definition contained in VAR. Take +# advantage of any shell optimizations that allow amortized linear growth over +# repeated appends, instead of the typical quadratic growth present in naive +# implementations. +if (eval "as_var=1; as_var+=2; test x\$as_var = x12") 2>/dev/null; then : + eval 'as_fn_append () + { + eval $1+=\$2 + }' +else + as_fn_append () + { + eval $1=\$$1\$2 + } +fi # as_fn_append + +# as_fn_arith ARG... +# ------------------ +# Perform arithmetic evaluation on the ARGs, and store the result in the +# global $as_val. Take advantage of shells that can avoid forks. The arguments +# must be portable across $(()) and expr. +if (eval "test \$(( 1 + 1 )) = 2") 2>/dev/null; then : + eval 'as_fn_arith () + { + as_val=$(( $* )) + }' +else + as_fn_arith () + { + as_val=`expr "$@" || test $? -eq 1` + } +fi # as_fn_arith + + +if expr a : '\(a\)' >/dev/null 2>&1 && + test "X`expr 00001 : '.*\(...\)'`" = X001; then + as_expr=expr +else + as_expr=false +fi + +if (basename -- /) >/dev/null 2>&1 && test "X`basename -- / 2>&1`" = "X/"; then + as_basename=basename +else + as_basename=false +fi + +if (as_dir=`dirname -- /` && test "X$as_dir" = X/) >/dev/null 2>&1; then + as_dirname=dirname +else + as_dirname=false +fi + +as_me=`$as_basename -- "$0" || +$as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \ + X"$0" : 'X\(//\)$' \| \ + X"$0" : 'X\(/\)' \| . 2>/dev/null || +$as_echo X/"$0" | + sed '/^.*\/\([^/][^/]*\)\/*$/{ + s//\1/ + q + } + /^X\/\(\/\/\)$/{ + s//\1/ + q + } + /^X\/\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` + +# Avoid depending upon Character Ranges. +as_cr_letters='abcdefghijklmnopqrstuvwxyz' +as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ' +as_cr_Letters=$as_cr_letters$as_cr_LETTERS +as_cr_digits='0123456789' +as_cr_alnum=$as_cr_Letters$as_cr_digits + +ECHO_C= ECHO_N= ECHO_T= +case `echo -n x` in #((((( +-n*) + case `echo 'xy\c'` in + *c*) ECHO_T=' ';; # ECHO_T is single tab character. + xy) ECHO_C='\c';; + *) echo `echo ksh88 bug on AIX 6.1` > /dev/null + ECHO_T=' ';; + esac;; +*) + ECHO_N='-n';; +esac + +rm -f conf$$ conf$$.exe conf$$.file +if test -d conf$$.dir; then + rm -f conf$$.dir/conf$$.file +else + rm -f conf$$.dir + mkdir conf$$.dir 2>/dev/null +fi +if (echo >conf$$.file) 2>/dev/null; then + if ln -s conf$$.file conf$$ 2>/dev/null; then + as_ln_s='ln -s' + # ... but there are two gotchas: + # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail. + # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable. + # In both cases, we have to default to `cp -pR'. + ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe || + as_ln_s='cp -pR' + elif ln conf$$.file conf$$ 2>/dev/null; then + as_ln_s=ln + else + as_ln_s='cp -pR' + fi +else + as_ln_s='cp -pR' +fi +rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file +rmdir conf$$.dir 2>/dev/null + + +# as_fn_mkdir_p +# ------------- +# Create "$as_dir" as a directory, including parents if necessary. +as_fn_mkdir_p () +{ + + case $as_dir in #( + -*) as_dir=./$as_dir;; + esac + test -d "$as_dir" || eval $as_mkdir_p || { + as_dirs= + while :; do + case $as_dir in #( + *\'*) as_qdir=`$as_echo "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'( + *) as_qdir=$as_dir;; + esac + as_dirs="'$as_qdir' $as_dirs" + as_dir=`$as_dirname -- "$as_dir" || +$as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ + X"$as_dir" : 'X\(//\)[^/]' \| \ + X"$as_dir" : 'X\(//\)$' \| \ + X"$as_dir" : 'X\(/\)' \| . 2>/dev/null || +$as_echo X"$as_dir" | + sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ + s//\1/ + q + } + /^X\(\/\/\)[^/].*/{ + s//\1/ + q + } + /^X\(\/\/\)$/{ + s//\1/ + q + } + /^X\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` + test -d "$as_dir" && break + done + test -z "$as_dirs" || eval "mkdir $as_dirs" + } || test -d "$as_dir" || as_fn_error $? "cannot create directory $as_dir" + + +} # as_fn_mkdir_p +if mkdir -p . 2>/dev/null; then + as_mkdir_p='mkdir -p "$as_dir"' +else + test -d ./-p && rmdir ./-p + as_mkdir_p=false +fi + + +# as_fn_executable_p FILE +# ----------------------- +# Test if FILE is an executable regular file. +as_fn_executable_p () +{ + test -f "$1" && test -x "$1" +} # as_fn_executable_p +as_test_x='test -x' +as_executable_p=as_fn_executable_p + +# Sed expression to map a string onto a valid CPP name. +as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'" + +# Sed expression to map a string onto a valid variable name. +as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'" + + +exec 6>&1 +## ----------------------------------- ## +## Main body of $CONFIG_STATUS script. ## +## ----------------------------------- ## +_ASEOF +test $as_write_fail = 0 && chmod +x $CONFIG_STATUS || ac_write_fail=1 + +cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 +# Save the log message, to keep $0 and so on meaningful, and to +# report actual input values of CONFIG_FILES etc. instead of their +# values after options handling. +ac_log=" +This file was extended by schemadtx $as_me 1.0, which was +generated by GNU Autoconf 2.69. Invocation command line was + + CONFIG_FILES = $CONFIG_FILES + CONFIG_HEADERS = $CONFIG_HEADERS + CONFIG_LINKS = $CONFIG_LINKS + CONFIG_COMMANDS = $CONFIG_COMMANDS + $ $0 $@ + +on `(hostname || uname -n) 2>/dev/null | sed 1q` +" + +_ACEOF + +case $ac_config_files in *" +"*) set x $ac_config_files; shift; ac_config_files=$*;; +esac + + + +cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 +# Files that config.status was made for. +config_files="$ac_config_files" + +_ACEOF + +cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 +ac_cs_usage="\ +\`$as_me' instantiates files and other configuration actions +from templates according to the current configuration. Unless the files +and actions are specified as TAGs, all are instantiated by default. + +Usage: $0 [OPTION]... [TAG]... + + -h, --help print this help, then exit + -V, --version print version number and configuration settings, then exit + --config print configuration, then exit + -q, --quiet, --silent + do not print progress messages + -d, --debug don't remove temporary files + --recheck update $as_me by reconfiguring in the same conditions + --file=FILE[:TEMPLATE] + instantiate the configuration file FILE + +Configuration files: +$config_files + +Report bugs to the package provider." + +_ACEOF +cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 +ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" +ac_cs_version="\\ +schemadtx config.status 1.0 +configured by $0, generated by GNU Autoconf 2.69, + with options \\"\$ac_cs_config\\" + +Copyright (C) 2012 Free Software Foundation, Inc. +This config.status script is free software; the Free Software Foundation +gives unlimited permission to copy, distribute and modify it." + +ac_pwd='$ac_pwd' +srcdir='$srcdir' +test -n "\$AWK" || AWK=awk +_ACEOF + +cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 +# The default lists apply if the user does not specify any file. +ac_need_defaults=: +while test $# != 0 +do + case $1 in + --*=?*) + ac_option=`expr "X$1" : 'X\([^=]*\)='` + ac_optarg=`expr "X$1" : 'X[^=]*=\(.*\)'` + ac_shift=: + ;; + --*=) + ac_option=`expr "X$1" : 'X\([^=]*\)='` + ac_optarg= + ac_shift=: + ;; + *) + ac_option=$1 + ac_optarg=$2 + ac_shift=shift + ;; + esac + + case $ac_option in + # Handling of the options. + -recheck | --recheck | --rechec | --reche | --rech | --rec | --re | --r) + ac_cs_recheck=: ;; + --version | --versio | --versi | --vers | --ver | --ve | --v | -V ) + $as_echo "$ac_cs_version"; exit ;; + --config | --confi | --conf | --con | --co | --c ) + $as_echo "$ac_cs_config"; exit ;; + --debug | --debu | --deb | --de | --d | -d ) + debug=: ;; + --file | --fil | --fi | --f ) + $ac_shift + case $ac_optarg in + *\'*) ac_optarg=`$as_echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"` ;; + '') as_fn_error $? "missing file argument" ;; + esac + as_fn_append CONFIG_FILES " '$ac_optarg'" + ac_need_defaults=false;; + --he | --h | --help | --hel | -h ) + $as_echo "$ac_cs_usage"; exit ;; + -q | -quiet | --quiet | --quie | --qui | --qu | --q \ + | -silent | --silent | --silen | --sile | --sil | --si | --s) + ac_cs_silent=: ;; + + # This is an error. + -*) as_fn_error $? "unrecognized option: \`$1' +Try \`$0 --help' for more information." ;; + + *) as_fn_append ac_config_targets " $1" + ac_need_defaults=false ;; + + esac + shift +done + +ac_configure_extra_args= + +if $ac_cs_silent; then + exec 6>/dev/null + ac_configure_extra_args="$ac_configure_extra_args --silent" +fi + +_ACEOF +cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 +if \$ac_cs_recheck; then + set X $SHELL '$0' $ac_configure_args \$ac_configure_extra_args --no-create --no-recursion + shift + \$as_echo "running CONFIG_SHELL=$SHELL \$*" >&6 + CONFIG_SHELL='$SHELL' + export CONFIG_SHELL + exec "\$@" +fi + +_ACEOF +cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 +exec 5>>config.log +{ + echo + sed 'h;s/./-/g;s/^.../## /;s/...$/ ##/;p;x;p;x' <<_ASBOX +## Running $as_me. ## +_ASBOX + $as_echo "$ac_log" +} >&5 + +_ACEOF +cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 +_ACEOF + +cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 + +# Handling of arguments. +for ac_config_target in $ac_config_targets +do + case $ac_config_target in + "Makefile") CONFIG_FILES="$CONFIG_FILES Makefile" ;; + "pkgIndex.tcl") CONFIG_FILES="$CONFIG_FILES pkgIndex.tcl" ;; + + *) as_fn_error $? "invalid argument: \`$ac_config_target'" "$LINENO" 5;; + esac +done + + +# If the user did not use the arguments to specify the items to instantiate, +# then the envvar interface is used. Set only those that are not. +# We use the long form for the default assignment because of an extremely +# bizarre bug on SunOS 4.1.3. +if $ac_need_defaults; then + test "${CONFIG_FILES+set}" = set || CONFIG_FILES=$config_files +fi + +# Have a temporary directory for convenience. Make it in the build tree +# simply because there is no reason against having it here, and in addition, +# creating and moving files from /tmp can sometimes cause problems. +# Hook for its removal unless debugging. +# Note that there is a small window in which the directory will not be cleaned: +# after its creation but before its name has been assigned to `$tmp'. +$debug || +{ + tmp= ac_tmp= + trap 'exit_status=$? + : "${ac_tmp:=$tmp}" + { test ! -d "$ac_tmp" || rm -fr "$ac_tmp"; } && exit $exit_status +' 0 + trap 'as_fn_exit 1' 1 2 13 15 +} +# Create a (secure) tmp directory for tmp files. + +{ + tmp=`(umask 077 && mktemp -d "./confXXXXXX") 2>/dev/null` && + test -d "$tmp" +} || +{ + tmp=./conf$$-$RANDOM + (umask 077 && mkdir "$tmp") +} || as_fn_error $? "cannot create a temporary directory in ." "$LINENO" 5 +ac_tmp=$tmp + +# Set up the scripts for CONFIG_FILES section. +# No need to generate them if there are no CONFIG_FILES. +# This happens for instance with `./config.status config.h'. +if test -n "$CONFIG_FILES"; then + + +ac_cr=`echo X | tr X '\015'` +# On cygwin, bash can eat \r inside `` if the user requested igncr. +# But we know of no other shell where ac_cr would be empty at this +# point, so we can use a bashism as a fallback. +if test "x$ac_cr" = x; then + eval ac_cr=\$\'\\r\' +fi +ac_cs_awk_cr=`$AWK 'BEGIN { print "a\rb" }' /dev/null` +if test "$ac_cs_awk_cr" = "a${ac_cr}b"; then + ac_cs_awk_cr='\\r' +else + ac_cs_awk_cr=$ac_cr +fi + +echo 'BEGIN {' >"$ac_tmp/subs1.awk" && +_ACEOF + + +{ + echo "cat >conf$$subs.awk <<_ACEOF" && + echo "$ac_subst_vars" | sed 's/.*/&!$&$ac_delim/' && + echo "_ACEOF" +} >conf$$subs.sh || + as_fn_error $? "could not make $CONFIG_STATUS" "$LINENO" 5 +ac_delim_num=`echo "$ac_subst_vars" | grep -c '^'` +ac_delim='%!_!# ' +for ac_last_try in false false false false false :; do + . ./conf$$subs.sh || + as_fn_error $? "could not make $CONFIG_STATUS" "$LINENO" 5 + + ac_delim_n=`sed -n "s/.*$ac_delim\$/X/p" conf$$subs.awk | grep -c X` + if test $ac_delim_n = $ac_delim_num; then + break + elif $ac_last_try; then + as_fn_error $? "could not make $CONFIG_STATUS" "$LINENO" 5 + else + ac_delim="$ac_delim!$ac_delim _$ac_delim!! " + fi +done +rm -f conf$$subs.sh + +cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 +cat >>"\$ac_tmp/subs1.awk" <<\\_ACAWK && +_ACEOF +sed -n ' +h +s/^/S["/; s/!.*/"]=/ +p +g +s/^[^!]*!// +:repl +t repl +s/'"$ac_delim"'$// +t delim +:nl +h +s/\(.\{148\}\)..*/\1/ +t more1 +s/["\\]/\\&/g; s/^/"/; s/$/\\n"\\/ +p +n +b repl +:more1 +s/["\\]/\\&/g; s/^/"/; s/$/"\\/ +p +g +s/.\{148\}// +t nl +:delim +h +s/\(.\{148\}\)..*/\1/ +t more2 +s/["\\]/\\&/g; s/^/"/; s/$/"/ +p +b +:more2 +s/["\\]/\\&/g; s/^/"/; s/$/"\\/ +p +g +s/.\{148\}// +t delim +' >$CONFIG_STATUS || ac_write_fail=1 +rm -f conf$$subs.awk +cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 +_ACAWK +cat >>"\$ac_tmp/subs1.awk" <<_ACAWK && + for (key in S) S_is_set[key] = 1 + FS = "" + +} +{ + line = $ 0 + nfields = split(line, field, "@") + substed = 0 + len = length(field[1]) + for (i = 2; i < nfields; i++) { + key = field[i] + keylen = length(key) + if (S_is_set[key]) { + value = S[key] + line = substr(line, 1, len) "" value "" substr(line, len + keylen + 3) + len += length(value) + length(field[++i]) + substed = 1 + } else + len += 1 + keylen + } + + print line +} + +_ACAWK +_ACEOF +cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 +if sed "s/$ac_cr//" < /dev/null > /dev/null 2>&1; then + sed "s/$ac_cr\$//; s/$ac_cr/$ac_cs_awk_cr/g" +else + cat +fi < "$ac_tmp/subs1.awk" > "$ac_tmp/subs.awk" \ + || as_fn_error $? "could not setup config files machinery" "$LINENO" 5 +_ACEOF + +# VPATH may cause trouble with some makes, so we remove sole $(srcdir), +# ${srcdir} and @srcdir@ entries from VPATH if srcdir is ".", strip leading and +# trailing colons and then remove the whole line if VPATH becomes empty +# (actually we leave an empty line to preserve line numbers). +if test "x$srcdir" = x.; then + ac_vpsub='/^[ ]*VPATH[ ]*=[ ]*/{ +h +s/// +s/^/:/ +s/[ ]*$/:/ +s/:\$(srcdir):/:/g +s/:\${srcdir}:/:/g +s/:@srcdir@:/:/g +s/^:*// +s/:*$// +x +s/\(=[ ]*\).*/\1/ +G +s/\n// +s/^[^=]*=[ ]*$// +}' +fi + +cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 +fi # test -n "$CONFIG_FILES" + + +eval set X " :F $CONFIG_FILES " +shift +for ac_tag +do + case $ac_tag in + :[FHLC]) ac_mode=$ac_tag; continue;; + esac + case $ac_mode$ac_tag in + :[FHL]*:*);; + :L* | :C*:*) as_fn_error $? "invalid tag \`$ac_tag'" "$LINENO" 5;; + :[FH]-) ac_tag=-:-;; + :[FH]*) ac_tag=$ac_tag:$ac_tag.in;; + esac + ac_save_IFS=$IFS + IFS=: + set x $ac_tag + IFS=$ac_save_IFS + shift + ac_file=$1 + shift + + case $ac_mode in + :L) ac_source=$1;; + :[FH]) + ac_file_inputs= + for ac_f + do + case $ac_f in + -) ac_f="$ac_tmp/stdin";; + *) # Look for the file first in the build tree, then in the source tree + # (if the path is not absolute). The absolute path cannot be DOS-style, + # because $ac_f cannot contain `:'. + test -f "$ac_f" || + case $ac_f in + [\\/$]*) false;; + *) test -f "$srcdir/$ac_f" && ac_f="$srcdir/$ac_f";; + esac || + as_fn_error 1 "cannot find input file: \`$ac_f'" "$LINENO" 5;; + esac + case $ac_f in *\'*) ac_f=`$as_echo "$ac_f" | sed "s/'/'\\\\\\\\''/g"`;; esac + as_fn_append ac_file_inputs " '$ac_f'" + done + + # Let's still pretend it is `configure' which instantiates (i.e., don't + # use $as_me), people would be surprised to read: + # /* config.h. Generated by config.status. */ + configure_input='Generated from '` + $as_echo "$*" | sed 's|^[^:]*/||;s|:[^:]*/|, |g' + `' by configure.' + if test x"$ac_file" != x-; then + configure_input="$ac_file. $configure_input" + { $as_echo "$as_me:${as_lineno-$LINENO}: creating $ac_file" >&5 +$as_echo "$as_me: creating $ac_file" >&6;} + fi + # Neutralize special characters interpreted by sed in replacement strings. + case $configure_input in #( + *\&* | *\|* | *\\* ) + ac_sed_conf_input=`$as_echo "$configure_input" | + sed 's/[\\\\&|]/\\\\&/g'`;; #( + *) ac_sed_conf_input=$configure_input;; + esac + + case $ac_tag in + *:-:* | *:-) cat >"$ac_tmp/stdin" \ + || as_fn_error $? "could not create $ac_file" "$LINENO" 5 ;; + esac + ;; + esac + + ac_dir=`$as_dirname -- "$ac_file" || +$as_expr X"$ac_file" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ + X"$ac_file" : 'X\(//\)[^/]' \| \ + X"$ac_file" : 'X\(//\)$' \| \ + X"$ac_file" : 'X\(/\)' \| . 2>/dev/null || +$as_echo X"$ac_file" | + sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ + s//\1/ + q + } + /^X\(\/\/\)[^/].*/{ + s//\1/ + q + } + /^X\(\/\/\)$/{ + s//\1/ + q + } + /^X\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` + as_dir="$ac_dir"; as_fn_mkdir_p + ac_builddir=. + +case "$ac_dir" in +.) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;; +*) + ac_dir_suffix=/`$as_echo "$ac_dir" | sed 's|^\.[\\/]||'` + # A ".." for each directory in $ac_dir_suffix. + ac_top_builddir_sub=`$as_echo "$ac_dir_suffix" | sed 's|/[^\\/]*|/..|g;s|/||'` + case $ac_top_builddir_sub in + "") ac_top_builddir_sub=. ac_top_build_prefix= ;; + *) ac_top_build_prefix=$ac_top_builddir_sub/ ;; + esac ;; +esac +ac_abs_top_builddir=$ac_pwd +ac_abs_builddir=$ac_pwd$ac_dir_suffix +# for backward compatibility: +ac_top_builddir=$ac_top_build_prefix + +case $srcdir in + .) # We are building in place. + ac_srcdir=. + ac_top_srcdir=$ac_top_builddir_sub + ac_abs_top_srcdir=$ac_pwd ;; + [\\/]* | ?:[\\/]* ) # Absolute name. + ac_srcdir=$srcdir$ac_dir_suffix; + ac_top_srcdir=$srcdir + ac_abs_top_srcdir=$srcdir ;; + *) # Relative name. + ac_srcdir=$ac_top_build_prefix$srcdir$ac_dir_suffix + ac_top_srcdir=$ac_top_build_prefix$srcdir + ac_abs_top_srcdir=$ac_pwd/$srcdir ;; +esac +ac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix + + + case $ac_mode in + :F) + # + # CONFIG_FILE + # + +_ACEOF + +cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 +# If the template does not know about datarootdir, expand it. +# FIXME: This hack should be removed a few years after 2.60. +ac_datarootdir_hack=; ac_datarootdir_seen= +ac_sed_dataroot=' +/datarootdir/ { + p + q +} +/@datadir@/p +/@docdir@/p +/@infodir@/p +/@localedir@/p +/@mandir@/p' +case `eval "sed -n \"\$ac_sed_dataroot\" $ac_file_inputs"` in +*datarootdir*) ac_datarootdir_seen=yes;; +*@datadir@*|*@docdir@*|*@infodir@*|*@localedir@*|*@mandir@*) + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&5 +$as_echo "$as_me: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&2;} +_ACEOF +cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 + ac_datarootdir_hack=' + s&@datadir@&$datadir&g + s&@docdir@&$docdir&g + s&@infodir@&$infodir&g + s&@localedir@&$localedir&g + s&@mandir@&$mandir&g + s&\\\${datarootdir}&$datarootdir&g' ;; +esac +_ACEOF + +# Neutralize VPATH when `$srcdir' = `.'. +# Shell code in configure.ac might set extrasub. +# FIXME: do we really want to maintain this feature? +cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 +ac_sed_extra="$ac_vpsub +$extrasub +_ACEOF +cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 +:t +/@[a-zA-Z_][a-zA-Z_0-9]*@/!b +s|@configure_input@|$ac_sed_conf_input|;t t +s&@top_builddir@&$ac_top_builddir_sub&;t t +s&@top_build_prefix@&$ac_top_build_prefix&;t t +s&@srcdir@&$ac_srcdir&;t t +s&@abs_srcdir@&$ac_abs_srcdir&;t t +s&@top_srcdir@&$ac_top_srcdir&;t t +s&@abs_top_srcdir@&$ac_abs_top_srcdir&;t t +s&@builddir@&$ac_builddir&;t t +s&@abs_builddir@&$ac_abs_builddir&;t t +s&@abs_top_builddir@&$ac_abs_top_builddir&;t t +$ac_datarootdir_hack +" +eval sed \"\$ac_sed_extra\" "$ac_file_inputs" | $AWK -f "$ac_tmp/subs.awk" \ + >$ac_tmp/out || as_fn_error $? "could not create $ac_file" "$LINENO" 5 + +test -z "$ac_datarootdir_hack$ac_datarootdir_seen" && + { ac_out=`sed -n '/\${datarootdir}/p' "$ac_tmp/out"`; test -n "$ac_out"; } && + { ac_out=`sed -n '/^[ ]*datarootdir[ ]*:*=/p' \ + "$ac_tmp/out"`; test -z "$ac_out"; } && + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $ac_file contains a reference to the variable \`datarootdir' +which seems to be undefined. Please make sure it is defined" >&5 +$as_echo "$as_me: WARNING: $ac_file contains a reference to the variable \`datarootdir' +which seems to be undefined. Please make sure it is defined" >&2;} + + rm -f "$ac_tmp/stdin" + case $ac_file in + -) cat "$ac_tmp/out" && rm -f "$ac_tmp/out";; + *) rm -f "$ac_file" && mv "$ac_tmp/out" "$ac_file";; + esac \ + || as_fn_error $? "could not create $ac_file" "$LINENO" 5 + ;; + + + + esac + +done # for ac_tag + + +as_fn_exit 0 +_ACEOF +ac_clean_files=$ac_clean_files_save + +test $ac_write_fail = 0 || + as_fn_error $? "write failure creating $CONFIG_STATUS" "$LINENO" 5 + + +# configure is writing to config.log, and then calls config.status. +# config.status does its own redirection, appending to config.log. +# Unfortunately, on DOS this fails, as config.log is still kept open +# by configure, so config.status won't be able to write to it; its +# output is simply discarded. So we exec the FD to /dev/null, +# effectively closing config.log, so it can be properly (re)opened and +# appended to by config.status. When coming back to configure, we +# need to make the FD available again. +if test "$no_create" != yes; then + ac_cs_success=: + ac_config_status_args= + test "$silent" = yes && + ac_config_status_args="$ac_config_status_args --quiet" + exec 5>/dev/null + $SHELL $CONFIG_STATUS $ac_config_status_args || ac_cs_success=false + exec 5>>config.log + # Use ||, not &&, to avoid exiting from the if with $? = 1, which + # would make configure fail if this is the last instruction. + $ac_cs_success || as_fn_exit 1 +fi +if test -n "$ac_unrecognized_opts" && test "$enable_option_checking" != no; then + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: unrecognized options: $ac_unrecognized_opts" >&5 +$as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2;} +fi + ADDED extensions/schemadtx/configure.ac Index: extensions/schemadtx/configure.ac ================================================================== --- /dev/null +++ extensions/schemadtx/configure.ac @@ -0,0 +1,193 @@ +#!/bin/bash -norc +dnl This file is an input file used by the GNU "autoconf" program to +dnl generate the file "configure", which is run during Tcl installation +dnl to configure the system for the local environment. + +#----------------------------------------------------------------------- +# Sample configure.in for Tcl Extensions. The only places you should +# need to modify this file are marked by the string __CHANGE__ +#----------------------------------------------------------------------- + +#----------------------------------------------------------------------- +# __CHANGE__ +# Set your package name and version numbers here. +# +# This initializes the environment with PACKAGE_NAME and PACKAGE_VERSION +# set as provided. These will also be added as -D defs in your Makefile +# so you can encode the package version directly into the source files. +# This will also define a special symbol for Windows (BUILD_sample in +# this case) so that we create the export library with the dll. +#----------------------------------------------------------------------- + +AC_INIT([schemadtx], [1.0]) + +#-------------------------------------------------------------------- +# Call TEA_INIT as the first TEA_ macro to set up initial vars. +# This will define a ${TEA_PLATFORM} variable == "unix" or "windows" +# as well as PKG_LIB_FILE and PKG_STUB_LIB_FILE. +#-------------------------------------------------------------------- + +TEA_INIT() + +AC_CONFIG_AUX_DIR(../../tclconfig) + +#-------------------------------------------------------------------- +# Load the tclConfig.sh file +#-------------------------------------------------------------------- + +TEA_PATH_TCLCONFIG +TEA_LOAD_TCLCONFIG + +#-------------------------------------------------------------------- +# Load the tkConfig.sh file if necessary (Tk extension) +#-------------------------------------------------------------------- + +#TEA_PATH_TKCONFIG +#TEA_LOAD_TKCONFIG + +#----------------------------------------------------------------------- +# Handle the --prefix=... option by defaulting to what Tcl gave. +# Must be called after TEA_LOAD_TCLCONFIG and before TEA_SETUP_COMPILER. +#----------------------------------------------------------------------- + +TEA_PREFIX + +#----------------------------------------------------------------------- +# Standard compiler checks. +# This sets up CC by using the CC env var, or looks for gcc otherwise. +# This also calls AC_PROG_CC and a few others to create the basic setup +# necessary to compile executables. +#----------------------------------------------------------------------- + +TEA_SETUP_COMPILER + +#-------------------------------------------------------------------- +# Load the tdomConfig.sh file +#-------------------------------------------------------------------- + +TDOM_PATH_CONFIG +TDOM_LOAD_CONFIG + +#----------------------------------------------------------------------- +# __CHANGE__ +# Specify the C source files to compile in TEA_ADD_SOURCES, +# public headers that need to be installed in TEA_ADD_HEADERS, +# stub library C source files to compile in TEA_ADD_STUB_SOURCES, +# and runtime Tcl library files in TEA_ADD_TCL_SOURCES. +# This defines PKG(_STUB)_SOURCES, PKG(_STUB)_OBJECTS, PKG_HEADERS +# and PKG_TCL_SOURCES. +#----------------------------------------------------------------------- + +TEA_ADD_SOURCES([schemadtx.c]) +TEA_ADD_HEADERS([]) +TEA_ADD_INCLUDES([-I${srcdir}/../../generic -I${srcdir}/../../expat]) +TEA_ADD_LIBS([${TDOM_STUB_LIB_SPEC}]) +TEA_ADD_CFLAGS([-DUSE_TDOM_STUBS=1]) +TEA_ADD_STUB_SOURCES([]) +TEA_ADD_TCL_SOURCES([]) + +#-------------------------------------------------------------------- +# __CHANGE__ +# +# You can add more files to clean if your extension creates any extra +# files by extending CLEANFILES. +# Add pkgIndex.tcl if it is generated in the Makefile instead of ./configure +# and change Makefile.in to move it from CONFIG_CLEAN_FILES to BINARIES var. +# +# A few miscellaneous platform-specific items: +# TEA_ADD_* any platform specific compiler/build info here. +#-------------------------------------------------------------------- + +#CLEANFILES="$CLEANFILES pkgIndex.tcl" +if test "${TEA_PLATFORM}" = "windows" ; then + # Ensure no empty if clauses + : + #TEA_ADD_SOURCES([win/winFile.c]) + #TEA_ADD_INCLUDES([-I\"$(${CYGPATH} ${srcdir}/win)\"]) +else + # Ensure no empty else clauses + : + #TEA_ADD_SOURCES([unix/unixFile.c]) + #TEA_ADD_LIBS([-lsuperfly]) +fi + +#-------------------------------------------------------------------- +# __CHANGE__ +# Choose which headers you need. Extension authors should try very +# hard to only rely on the Tcl public header files. Internal headers +# contain private data structures and are subject to change without +# notice. +# This MUST be called after TEA_LOAD_TCLCONFIG / TEA_LOAD_TKCONFIG +#-------------------------------------------------------------------- + +TEA_PUBLIC_TCL_HEADERS +#TEA_PRIVATE_TCL_HEADERS + +#TEA_PUBLIC_TK_HEADERS +#TEA_PRIVATE_TK_HEADERS +#TEA_PATH_X + +#-------------------------------------------------------------------- +# Check whether --enable-threads or --disable-threads was given. +# This auto-enables if Tcl was compiled threaded. +#-------------------------------------------------------------------- + +TEA_ENABLE_THREADS + +#-------------------------------------------------------------------- +# The statement below defines a collection of symbols related to +# building as a shared library instead of a static library. +#-------------------------------------------------------------------- + +TEA_ENABLE_SHARED + +#-------------------------------------------------------------------- +# This macro figures out what flags to use with the compiler/linker +# when building shared/static debug/optimized objects. This information +# can be taken from the tclConfig.sh file, but this figures it all out. +#-------------------------------------------------------------------- + +TEA_CONFIG_CFLAGS + +#-------------------------------------------------------------------- +# Set the default compiler switches based on the --enable-symbols option. +#-------------------------------------------------------------------- + +TEA_ENABLE_SYMBOLS + +#-------------------------------------------------------------------- +# Everyone should be linking against the Tcl stub library. If you +# can't for some reason, remove this definition. If you aren't using +# stubs, you also need to modify the SHLIB_LD_LIBS setting below to +# link against the non-stubbed Tcl library. Add Tk too if necessary. +#-------------------------------------------------------------------- + +AC_DEFINE(USE_TCL_STUBS, 1, [Use Tcl stubs]) +#AC_DEFINE(USE_TK_STUBS, 1, [Use Tk stubs]) + +#-------------------------------------------------------------------- +# This macro generates a line to use when building a library. It +# depends on values set by the TEA_ENABLE_SHARED, TEA_ENABLE_SYMBOLS, +# and TEA_LOAD_TCLCONFIG macros above. +#-------------------------------------------------------------------- + +TEA_MAKE_LIB + +#-------------------------------------------------------------------- +# Determine the name of the tclsh and/or wish executables in the +# Tcl and Tk build directories or the location they were installed +# into. These paths are used to support running test cases only, +# the Makefile should not be making use of these paths to generate +# a pkgIndex.tcl file or anything else at extension build time. +#-------------------------------------------------------------------- + +TEA_PROG_TCLSH +#TEA_PROG_WISH + +#-------------------------------------------------------------------- +# Finally, substitute all of the various values into the Makefile. +# You may alternatively have a special pkgIndex.tcl.in or other files +# which require substituting th AC variables in. Include these here. +#-------------------------------------------------------------------- + +AC_OUTPUT([Makefile pkgIndex.tcl]) ADDED extensions/schemadtx/pkgIndex.tcl.in Index: extensions/schemadtx/pkgIndex.tcl.in ================================================================== --- /dev/null +++ extensions/schemadtx/pkgIndex.tcl.in @@ -0,0 +1,6 @@ +# +# Tcl package index file +# +package ifneeded @PACKAGE_NAME@ @PACKAGE_VERSION@ \ + "package require tdom 0.9.2-; + load [file join $dir @PKG_LIB_FILE@]" ADDED extensions/schemadtx/schemadtx.c Index: extensions/schemadtx/schemadtx.c ================================================================== --- /dev/null +++ extensions/schemadtx/schemadtx.c @@ -0,0 +1,185 @@ + +#include +#include +#include +#include + +#define SetResult(str) Tcl_ResetResult(interp); \ + Tcl_SetStringObj(Tcl_GetObjResult(interp), (str), -1) + +#define CHECK_TI \ + if (!sdata) { \ + SetResult ("Command called outside of schema context"); \ + return TCL_ERROR; \ + } \ + if (!sdata->isTextConstraint) { \ + SetResult ("Command called in invalid schema context"); \ + return TCL_ERROR; \ + } + +#define ADD_CONSTRAINT(sdata, sc) \ + sc = TMALLOC (SchemaConstraint); \ + memset (sc, 0, sizeof (SchemaConstraint)); \ + if (sdata->cp->nc == sdata->contentSize) { \ + sdata->cp->content = \ + REALLOC (sdata->cp->content, \ + 2 * sdata->contentSize \ + * sizeof (SchemaCP*)); \ + sdata->cp->quants = \ + REALLOC (sdata->cp->quants, \ + 2 * sdata->contentSize \ + * sizeof (SchemaQuant)); \ + sdata->contentSize *= 2; \ + } \ + sdata->cp->content[sdata->cp->nc] = (SchemaCP *) sc; \ + sdata->cp->quants[sdata->cp->nc] = SCHEMA_CQUANT_ONE; \ + sdata->cp->nc++; \ + +extern char *Tdom_InitStubs (Tcl_Interp *interp, char *version, int exact); + +#define GTIN_8 1 +#define GTIN_12 2 +#define GTIN_13 4 +#define GTIN_14 8 + + +static int +gtinImpl ( + Tcl_Interp *interp, + void *constraintData, + char *text + ) +{ + int len, sum, i, mult, digit; + long flags = (long) constraintData; + + len = strlen (text); + if (len == 8) { + if (flags && !(flags & GTIN_8)) return 0; + } else if (len == 12) { + if (flags && !(flags & GTIN_12)) return 0; + } else if (len == 13) { + if (flags && !(flags & GTIN_13)) return 0; + } else if (len == 14) { + if (flags && !(flags & GTIN_14)) return 0; + } else { + return 0; + } + + sum = 0; + mult = len % 2; + for (i = len - 1; i >= 0; i--) { + digit = text[i] - '0'; + if (digit < 0 || digit > 9) return 0; + if (i % 2 == mult) digit *= 3; + sum += digit; + } + if (sum % 10 != 0) return 0; + return 1; +} + +/* + *---------------------------------------------------------------------------- + * + * gtinTCObjCmd + * + * This procedure is invoked to process the + * "tdom::schema::text::gtin" command. + * + * Results: + * A standard Tcl result. + * + * Side effects: + * The ususal schema text constraint command machinery. + * + *---------------------------------------------------------------------------- + */ + +int +gtinTCObjCmd (dummy, interp, objc, objv) + ClientData dummy; + Tcl_Interp *interp; + int objc; + Tcl_Obj *const objv[]; +{ + SchemaData *sdata = tdomGetSchemadata(); + SchemaConstraint *sc; + int optionIndex; + long flags = 0; + + CHECK_TI; + + static const char *options[] = { + "-gtin8", "-gtin12", "-gtin13", "-gtin14", NULL + }; + enum option { + m_gtin8, m_gtin12, m_gtin13, m_gtin14 + }; + + while (objc > 1) { + if (Tcl_GetIndexFromObj (interp, objv[1], options, "option", 0, + &optionIndex) != TCL_OK) { + return TCL_ERROR; + } + switch ((enum option) optionIndex) { + case m_gtin8: + flags |= GTIN_8; + break; + case m_gtin12: + flags |= GTIN_12; + break; + case m_gtin13: + flags |= GTIN_13; + break; + case m_gtin14: + flags |= GTIN_14; + break; + } + objv++; + objc--; + } + + ADD_CONSTRAINT (sdata, sc) + sc->constraint = gtinImpl; + sc->constraintData = (void *)flags; + return TCL_OK; +} + +/* + *---------------------------------------------------------------------------- + * + * Schemadtx_Init -- + * + * Initialization routine for loadable module + * + * Results: + * None. + * + * Side effects: + * Defines the additional text constraint commands + * + *---------------------------------------------------------------------------- + */ + +int +Schemadtx_Init (interp) + Tcl_Interp *interp; +{ +#ifdef USE_TCL_STUBS + if (Tcl_InitStubs(interp, "8", 0) == NULL) { + return TCL_ERROR; + } +#endif +#ifdef USE_TDOM_STUBS + if (Tdom_InitStubs(interp, "0.9.2", 0) == NULL) { + return TCL_ERROR; + } +#endif + if (Tcl_PkgRequire (interp, "tdom", "0.9.2", 0) == NULL) { + return TCL_ERROR; + }; + Tcl_CreateObjCommand (interp,"tdom::schema::text::gtin", + gtinTCObjCmd, (ClientData) 3, NULL); + Tcl_PkgProvide (interp, "schemadtx", "1.0"); + return TCL_OK; +} ADDED extensions/schemadtx/tests/all.tcl Index: extensions/schemadtx/tests/all.tcl ================================================================== --- /dev/null +++ extensions/schemadtx/tests/all.tcl @@ -0,0 +1,18 @@ +# all.tcl -- +# +# This file contains a top-level script to run all of the Tcl +# tests. Execute it by invoking "tclsh all.test". +# +# Copyright (c) 1998-1999 by Scriptics Corporation. +# All rights reserved. +# +# RCS: @(#) $Id$ +# + +source [file join [file dir [info script]] loadschemadtx.tcl] + +singleProcess 1 +configure {*}$argv -testdir [file dirname [info script]] +runAllTests +# See http://mini.net/tcl/3248 for an explanation. +proc exit args {} ADDED extensions/schemadtx/tests/loadschemadtx.tcl Index: extensions/schemadtx/tests/loadschemadtx.tcl ================================================================== --- /dev/null +++ extensions/schemadtx/tests/loadschemadtx.tcl @@ -0,0 +1,22 @@ +catch {load ../../../unix/libtdom0.9.2.so} +catch {load ../libschemadtx1.0.so} +catch {load ../../unix/libtdom0.9.2.so} +catch {load libschemadtx1.0.so} +# loadschemadtx.tcl -- +# +# This file is [source]d by all.tcl and all test files, to ensure, that +# the tcltest package and the lastest schemadtx build is present. + +if {[lsearch [namespace children] ::tcltest] == -1} { + package require tcltest + namespace import ::tcltest::* +} + +if {[catch {package present tdom}]} { + package require tdom 0.9.2 +} + +if {[catch {package require tnc}]} { + package require schemadtx +} + ADDED extensions/schemadtx/tests/schemadtx.test Index: extensions/schemadtx/tests/schemadtx.test ================================================================== --- /dev/null +++ extensions/schemadtx/tests/schemadtx.test @@ -0,0 +1,39 @@ +# Features covered: extended schema text constraint commands. +# +# This file contains a collection of tests for the collection of +# additional schema text constraint commands of schemadtx, provided as +# an "extension extension" to tdom. +# +# Copyright (c) 2020 Rolf Ade. + + +set testDir [file dir [info script]] +source [file join $testDir loadschemadtx.tcl] + +test schemadtx-1.1 {gtin} { + tdom::schema s + s defelement e { + text { + gtin + } + } + set result "" + foreach xml { + + + 1 + 4012345123456 + 4012345a23456 + } { + lappend result [s validate $xml] + } + s delete + set result +} {0 0 0 1 0} + + +# Local Variables: +# mode: tcl +# End: + + Index: extensions/tdomhtml/configure ================================================================== --- extensions/tdomhtml/configure +++ extensions/tdomhtml/configure @@ -609,10 +609,11 @@ htmldir infodir docdir oldincludedir includedir +runstatedir localstatedir sharedstatedir sysconfdir datadir datarootdir @@ -673,10 +674,11 @@ datarootdir='${prefix}/share' datadir='${datarootdir}' sysconfdir='${prefix}/etc' sharedstatedir='${prefix}/com' localstatedir='${prefix}/var' +runstatedir='${localstatedir}/run' includedir='${prefix}/include' oldincludedir='/usr/include' docdir='${datarootdir}/doc/${PACKAGE}' infodir='${datarootdir}/info' htmldir='${docdir}' @@ -924,10 +926,19 @@ psdir=$ac_optarg ;; -q | -quiet | --quiet | --quie | --qui | --qu | --q \ | -silent | --silent | --silen | --sile | --sil) silent=yes ;; + + -runstatedir | --runstatedir | --runstatedi | --runstated \ + | --runstate | --runstat | --runsta | --runst | --runs \ + | --run | --ru | --r) + ac_prev=runstatedir ;; + -runstatedir=* | --runstatedir=* | --runstatedi=* | --runstated=* \ + | --runstate=* | --runstat=* | --runsta=* | --runst=* | --runs=* \ + | --run=* | --ru=* | --r=*) + runstatedir=$ac_optarg ;; -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb) ac_prev=sbindir ;; -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \ | --sbi=* | --sb=*) @@ -1062,11 +1073,11 @@ # Check all directory arguments for consistency. for ac_var in exec_prefix prefix bindir sbindir libexecdir datarootdir \ datadir sysconfdir sharedstatedir localstatedir includedir \ oldincludedir docdir infodir htmldir dvidir pdfdir psdir \ - libdir localedir mandir + libdir localedir mandir runstatedir do eval ac_val=\$$ac_var # Remove trailing slashes. case $ac_val in */ ) @@ -1215,10 +1226,11 @@ --sbindir=DIR system admin executables [EPREFIX/sbin] --libexecdir=DIR program executables [EPREFIX/libexec] --sysconfdir=DIR read-only single-machine data [PREFIX/etc] --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com] --localstatedir=DIR modifiable single-machine data [PREFIX/var] + --runstatedir=DIR modifiable per-process data [LOCALSTATEDIR/run] --libdir=DIR object code libraries [EPREFIX/lib] --includedir=DIR C header files [PREFIX/include] --oldincludedir=DIR C header files for non-gcc [/usr/include] --datarootdir=DIR read-only arch.-independent data root [PREFIX/share] --datadir=DIR read-only architecture-independent data [DATAROOTDIR] DELETED extensions/tdomhtml/mkinstalldirs Index: extensions/tdomhtml/mkinstalldirs ================================================================== --- extensions/tdomhtml/mkinstalldirs +++ /dev/null @@ -1,40 +0,0 @@ -#! /bin/sh -# mkinstalldirs --- make directory hierarchy -# Author: Noah Friedman -# Created: 1993-05-16 -# Public domain - -# $Id$ - -errstatus=0 - -for file -do - set fnord `echo ":$file" | sed -ne 's/^:\//#/;s/^://;s/\// /g;s/^#/\//;p'` - shift - - pathcomp= - for d - do - pathcomp="$pathcomp$d" - case "$pathcomp" in - -* ) pathcomp=./$pathcomp ;; - esac - - if test ! -d "$pathcomp"; then - echo "mkdir $pathcomp" - - mkdir "$pathcomp" || lasterr=$? - - if test ! -d "$pathcomp"; then - errstatus=$lasterr - fi - fi - - pathcomp="$pathcomp/" - done -done - -exit $errstatus - -# mkinstalldirs ends here Index: extensions/tnc/configure ================================================================== --- extensions/tnc/configure +++ extensions/tnc/configure @@ -617,32 +617,32 @@ #ifdef HAVE_UNISTD_H # include #endif" ac_subst_vars='LTLIBOBJS -LIBOBJS TCLSH_PROG VC_MANIFEST_EMBED_EXE VC_MANIFEST_EMBED_DLL RANLIB_STUB MAKE_STUB_LIB MAKE_STATIC_LIB MAKE_SHARED_LIB MAKE_LIB -TCL_DBGX LDFLAGS_DEFAULT CFLAGS_DEFAULT LD_LIBRARY_PATH_VAR SHLIB_CFLAGS SHLIB_LD_LIBS SHLIB_LD STLIB_LD +LDFLAGS_OPTIMIZE +LDFLAGS_DEBUG CFLAGS_WARNING CFLAGS_OPTIMIZE CFLAGS_DEBUG +LIBOBJS RC -CELIB_DIR AR STUBS_BUILD SHARED_BUILD TCL_THREADS TCL_INCLUDES @@ -649,21 +649,14 @@ PKG_OBJECTS PKG_SOURCES TDOM_SRC_DIR TDOM_STUB_LIB_SPEC TDOM_VERSION -MATH_LIBS EGREP GREP RANLIB SET_MAKE -INSTALL_LIBRARY -INSTALL_SCRIPT -INSTALL_PROGRAM -INSTALL_DATA -INSTALL_DATA_DIR -INSTALL CPP TCL_SHLIB_LD_LIBS TCL_LD_FLAGS TCL_EXTRA_CFLAGS TCL_DEFS @@ -683,10 +676,16 @@ TCL_LIB_FILE TCL_SRC_DIR TCL_BIN_DIR TCL_PATCH_LEVEL TCL_VERSION +INSTALL_LIBRARY +INSTALL_SCRIPT +INSTALL_PROGRAM +INSTALL_DATA +INSTALL_DATA_DIR +INSTALL PKG_CFLAGS PKG_LIBS PKG_INCLUDES PKG_HEADERS PKG_TCL_SOURCES @@ -713,10 +712,11 @@ htmldir infodir docdir oldincludedir includedir +runstatedir localstatedir sharedstatedir sysconfdir datadir datarootdir @@ -744,12 +744,10 @@ enable_shared enable_stubs enable_64bit enable_64bit_vis enable_rpath -enable_wince -with_celib enable_symbols ' ac_precious_vars='build_alias host_alias target_alias @@ -795,10 +793,11 @@ datarootdir='${prefix}/share' datadir='${datarootdir}' sysconfdir='${prefix}/etc' sharedstatedir='${prefix}/com' localstatedir='${prefix}/var' +runstatedir='${localstatedir}/run' includedir='${prefix}/include' oldincludedir='/usr/include' docdir='${datarootdir}/doc/${PACKAGE_TARNAME}' infodir='${datarootdir}/info' htmldir='${docdir}' @@ -1046,10 +1045,19 @@ psdir=$ac_optarg ;; -q | -quiet | --quiet | --quie | --qui | --qu | --q \ | -silent | --silent | --silen | --sile | --sil) silent=yes ;; + + -runstatedir | --runstatedir | --runstatedi | --runstated \ + | --runstate | --runstat | --runsta | --runst | --runs \ + | --run | --ru | --r) + ac_prev=runstatedir ;; + -runstatedir=* | --runstatedir=* | --runstatedi=* | --runstated=* \ + | --runstate=* | --runstat=* | --runsta=* | --runst=* | --runs=* \ + | --run=* | --ru=* | --r=*) + runstatedir=$ac_optarg ;; -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb) ac_prev=sbindir ;; -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \ | --sbi=* | --sb=*) @@ -1184,11 +1192,11 @@ # Check all directory arguments for consistency. for ac_var in exec_prefix prefix bindir sbindir libexecdir datarootdir \ datadir sysconfdir sharedstatedir localstatedir includedir \ oldincludedir docdir infodir htmldir dvidir pdfdir psdir \ - libdir localedir mandir + libdir localedir mandir runstatedir do eval ac_val=\$$ac_var # Remove trailing slashes. case $ac_val in */ ) @@ -1337,10 +1345,11 @@ --sbindir=DIR system admin executables [EPREFIX/sbin] --libexecdir=DIR program executables [EPREFIX/libexec] --sysconfdir=DIR read-only single-machine data [PREFIX/etc] --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com] --localstatedir=DIR modifiable single-machine data [PREFIX/var] + --runstatedir=DIR modifiable per-process data [LOCALSTATEDIR/run] --libdir=DIR object code libraries [EPREFIX/lib] --includedir=DIR C header files [PREFIX/include] --oldincludedir=DIR C header files for non-gcc [/usr/include] --datarootdir=DIR read-only arch.-independent data root [PREFIX/share] --datadir=DIR read-only architecture-independent data [DATAROOTDIR] @@ -1366,29 +1375,27 @@ Optional Features: --disable-option-checking ignore unrecognized --enable/--with options --disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no) --enable-FEATURE[=ARG] include FEATURE [ARG=yes] - --enable-threads build with threads + --enable-threads build with threads (default: on) --enable-shared build and link with shared libraries (default: on) --enable-stubs build and link with stub libraries. Always true for shared builds (default: on) --enable-64bit enable 64bit support (default: off) --enable-64bit-vis enable 64bit Sparc VIS support (default: off) --disable-rpath disable rpath support (default: on) - --enable-wince enable Win/CE support (where applicable) --enable-symbols build with debugging symbols (default: off) Optional Packages: --with-PACKAGE[=ARG] use PACKAGE [ARG=yes] --without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no) --with-tcl directory containing tcl configuration (tclConfig.sh) - --with-tdom directory containig tDOM configuration + --with-tdom directory containing tDOM configuration (tdomConfig.sh) --with-tclinclude directory containing the public Tcl header files - --with-celib=DIR use Windows/CE support library from DIR Some influential environment variables: CC C compiler command CFLAGS C compiler flags LDFLAGS linker flags, e.g. -L if you have libraries in a @@ -1670,77 +1677,10 @@ eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno as_fn_set_status $ac_retval } # ac_fn_c_try_link -# ac_fn_c_check_func LINENO FUNC VAR -# ---------------------------------- -# Tests whether FUNC exists, setting the cache variable VAR accordingly -ac_fn_c_check_func () -{ - as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 -$as_echo_n "checking for $2... " >&6; } -if eval \${$3+:} false; then : - $as_echo_n "(cached) " >&6 -else - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ -/* Define $2 to an innocuous variant, in case declares $2. - For example, HP-UX 11i declares gettimeofday. */ -#define $2 innocuous_$2 - -/* System header to define __stub macros and hopefully few prototypes, - which can conflict with char $2 (); below. - Prefer to if __STDC__ is defined, since - exists even on freestanding compilers. */ - -#ifdef __STDC__ -# include -#else -# include -#endif - -#undef $2 - -/* Override any GCC internal prototype to avoid an error. - Use char because int might match the return type of a GCC - builtin and then its argument prototype would still apply. */ -#ifdef __cplusplus -extern "C" -#endif -char $2 (); -/* The GNU C library defines this for functions which it implements - to always fail with ENOSYS. Some functions are actually named - something starting with __ and the normal name is an alias. */ -#if defined __stub_$2 || defined __stub___$2 -choke me -#endif - -int -main () -{ -return $2 (); - ; - return 0; -} -_ACEOF -if ac_fn_c_try_link "$LINENO"; then : - eval "$3=yes" -else - eval "$3=no" -fi -rm -f core conftest.err conftest.$ac_objext \ - conftest$ac_exeext conftest.$ac_ext -fi -eval ac_res=\$$3 - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } - eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno - -} # ac_fn_c_check_func - # ac_fn_c_check_header_mongrel LINENO HEADER VAR INCLUDES # ------------------------------------------------------- # Tests whether HEADER exists, giving a warning if it cannot be compiled using # the include files in INCLUDES and setting the cache variable VAR # accordingly. @@ -1823,10 +1763,77 @@ $as_echo "$ac_res" >&6; } fi eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno } # ac_fn_c_check_header_mongrel + +# ac_fn_c_check_func LINENO FUNC VAR +# ---------------------------------- +# Tests whether FUNC exists, setting the cache variable VAR accordingly +ac_fn_c_check_func () +{ + as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 +$as_echo_n "checking for $2... " >&6; } +if eval \${$3+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +/* Define $2 to an innocuous variant, in case declares $2. + For example, HP-UX 11i declares gettimeofday. */ +#define $2 innocuous_$2 + +/* System header to define __stub macros and hopefully few prototypes, + which can conflict with char $2 (); below. + Prefer to if __STDC__ is defined, since + exists even on freestanding compilers. */ + +#ifdef __STDC__ +# include +#else +# include +#endif + +#undef $2 + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char $2 (); +/* The GNU C library defines this for functions which it implements + to always fail with ENOSYS. Some functions are actually named + something starting with __ and the normal name is an alias. */ +#if defined __stub_$2 || defined __stub___$2 +choke me +#endif + +int +main () +{ +return $2 (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + eval "$3=yes" +else + eval "$3=no" +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +fi +eval ac_res=\$$3 + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +$as_echo "$ac_res" >&6; } + eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno + +} # ac_fn_c_check_func cat >config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. It was created by tnc $as_me 0.3.0, which was @@ -2183,39 +2190,29 @@ # This will define a ${TEA_PLATFORM} variable == "unix" or "windows" # as well as PKG_LIB_FILE and PKG_STUB_LIB_FILE. #-------------------------------------------------------------------- - # TEA extensions pass this us the version of TEA they think they - # are compatible with. - TEA_VERSION="3.10" + TEA_VERSION="3.13" - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for correct TEA configuration" >&5 -$as_echo_n "checking for correct TEA configuration... " >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: checking TEA configuration" >&5 +$as_echo_n "checking TEA configuration... " >&6; } if test x"${PACKAGE_NAME}" = x ; then as_fn_error $? " The PACKAGE_NAME variable must be defined by your TEA configure.ac" "$LINENO" 5 fi - if test x"3.10" = x ; then - as_fn_error $? " -TEA version not specified." "$LINENO" 5 - elif test "3.10" != "${TEA_VERSION}" ; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: warning: requested TEA version \"3.10\", have \"${TEA_VERSION}\"" >&5 -$as_echo "warning: requested TEA version \"3.10\", have \"${TEA_VERSION}\"" >&6; } - else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: ok (TEA ${TEA_VERSION})" >&5 + { $as_echo "$as_me:${as_lineno-$LINENO}: result: ok (TEA ${TEA_VERSION})" >&5 $as_echo "ok (TEA ${TEA_VERSION})" >&6; } - fi # If the user did not set CFLAGS, set it now to keep macros # like AC_PROG_CC and AC_TRY_COMPILE from adding "-g -O2". if test "${CFLAGS+set}" != "set" ; then CFLAGS="" fi case "`uname -s`" in - *win32*|*WIN32*|*MINGW32_*) + *win32*|*WIN32*|*MINGW32_*|*MINGW64_*|*MSYS_*) # Extract the first word of "cygpath", so it can be a program name with args. set dummy cygpath; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_prog_CYGPATH+:} false; then : @@ -2295,10 +2292,62 @@ # Substitute STUB_LIB_FILE in case package creates a stub library too. # We AC_SUBST these here to ensure they are subst'ed, # in case the user doesn't call TEA_ADD_... + + + + + + + + + # Configure the installer. + + INSTALL='$(SHELL) $(srcdir)/tclconfig/install-sh -c' + INSTALL_DATA_DIR='${INSTALL} -d -m 755' + INSTALL_DATA='${INSTALL} -m 644' + INSTALL_PROGRAM='${INSTALL} -m 755' + INSTALL_SCRIPT='${INSTALL} -m 755' + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking system version" >&5 +$as_echo_n "checking system version... " >&6; } +if ${tcl_cv_sys_version+:} false; then : + $as_echo_n "(cached) " >&6 +else + + # TEA specific: + if test "${TEA_PLATFORM}" = "windows" ; then + tcl_cv_sys_version=windows + else + tcl_cv_sys_version=`uname -s`-`uname -r` + if test "$?" -ne 0 ; then + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: can't find uname command" >&5 +$as_echo "$as_me: WARNING: can't find uname command" >&2;} + tcl_cv_sys_version=unknown + else + if test "`uname -s`" = "AIX" ; then + tcl_cv_sys_version=AIX-`uname -v`.`uname -r` + fi + if test "`uname -s`" = "NetBSD" -a -f /etc/debian_version ; then + tcl_cv_sys_version=NetBSD-Debian + fi + fi + fi + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_sys_version" >&5 +$as_echo "$tcl_cv_sys_version" >&6; } + system=$tcl_cv_sys_version + + case $system in + HP-UX-*) INSTALL_LIBRARY='${INSTALL} -m 755' ;; + *) INSTALL_LIBRARY='${INSTALL} -m 644' ;; + esac + @@ -2411,11 +2460,13 @@ # on Darwin, check in Framework installation locations if test "`uname -s`" = "Darwin" -a x"${ac_cv_c_tclconfig}" = x ; then for i in `ls -d ~/Library/Frameworks 2>/dev/null` \ `ls -d /Library/Frameworks 2>/dev/null` \ `ls -d /Network/Library/Frameworks 2>/dev/null` \ - `ls -d /System/Library/Frameworks 2>/dev/null` \ + `ls -d /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/Library/Frameworks/Tcl.framework 2>/dev/null` \ + `ls -d /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/Network/Library/Frameworks/Tcl.framework 2>/dev/null` \ + `ls -d /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/Tcl.framework 2>/dev/null` \ ; do if test -f "$i/Tcl.framework/tclConfig.sh" ; then ac_cv_c_tclconfig="`(cd $i/Tcl.framework; pwd)`" break fi @@ -2438,17 +2489,21 @@ # check in a few common install locations if test x"${ac_cv_c_tclconfig}" = x ; then for i in `ls -d ${libdir} 2>/dev/null` \ `ls -d ${exec_prefix}/lib 2>/dev/null` \ `ls -d ${prefix}/lib 2>/dev/null` \ - `ls -d /usr/contrib/lib 2>/dev/null` \ `ls -d /usr/local/lib 2>/dev/null` \ + `ls -d /usr/contrib/lib 2>/dev/null` \ `ls -d /usr/pkg/lib 2>/dev/null` \ `ls -d /usr/lib 2>/dev/null` \ `ls -d /usr/lib64 2>/dev/null` \ `ls -d /usr/lib/tcl8.6 2>/dev/null` \ `ls -d /usr/lib/tcl8.5 2>/dev/null` \ + `ls -d /usr/local/lib/tcl8.6 2>/dev/null` \ + `ls -d /usr/local/lib/tcl8.5 2>/dev/null` \ + `ls -d /usr/local/lib/tcl/tcl8.6 2>/dev/null` \ + `ls -d /usr/local/lib/tcl/tcl8.5 2>/dev/null` \ ; do if test -f "$i/tclConfig.sh" ; then ac_cv_c_tclconfig="`(cd $i; pwd)`" break fi @@ -3289,14 +3344,10 @@ else { $as_echo "$as_me:${as_lineno-$LINENO}: result: could not find ${TCL_BIN_DIR}/tclConfig.sh" >&5 $as_echo "could not find ${TCL_BIN_DIR}/tclConfig.sh" >&6; } fi - # eval is required to do the TCL_DBGX substitution - eval "TCL_LIB_FILE=\"${TCL_LIB_FILE}\"" - eval "TCL_STUB_LIB_FILE=\"${TCL_STUB_LIB_FILE}\"" - # If the TCL_BIN_DIR is the build directory (not the install directory), # then set the common variable name to the value of the build variables. # For example, the variable TCL_LIB_SPEC will be set to the value # of TCL_BUILD_LIB_SPEC. An extension should make use of TCL_LIB_SPEC # instead of TCL_BUILD_LIB_SPEC since it will work with both an @@ -3326,16 +3377,10 @@ fi ;; esac fi - # eval is required to do the TCL_DBGX substitution - eval "TCL_LIB_FLAG=\"${TCL_LIB_FLAG}\"" - eval "TCL_LIB_SPEC=\"${TCL_LIB_SPEC}\"" - eval "TCL_STUB_LIB_FLAG=\"${TCL_STUB_LIB_FLAG}\"" - eval "TCL_STUB_LIB_SPEC=\"${TCL_STUB_LIB_SPEC}\"" - @@ -3365,11 +3410,12 @@ return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : - TEA_PLATFORM="unix" + # first test we've already retrieved platform (cross-compile), fallback to unix otherwise: + TEA_PLATFORM="${TEA_PLATFORM-unix}" CYGPATH=echo else TEA_PLATFORM="windows" @@ -4164,24 +4210,10 @@ ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' ac_compiler_gnu=$ac_cv_c_compiler_gnu - - INSTALL='$(SHELL) $(srcdir)/tclconfig/install-sh -c' - INSTALL_DATA_DIR='${INSTALL} -d -m 755' - INSTALL_DATA='${INSTALL} -m 644' - INSTALL_PROGRAM='${INSTALL}' - INSTALL_SCRIPT='${INSTALL}' - INSTALL_LIBRARY='${INSTALL_DATA}' - - - - - - - #-------------------------------------------------------------------- # Checks to see if the make program sets the $MAKE variable. #-------------------------------------------------------------------- @@ -4850,484 +4882,10 @@ *) as_fn_error $? "unknown endianness presetting ac_cv_c_bigendian=no (or yes) will help" "$LINENO" 5 ;; esac - if test "${TEA_PLATFORM}" = "unix" ; then - - #-------------------------------------------------------------------- - # On a few very rare systems, all of the libm.a stuff is - # already in libc.a. Set compiler flags accordingly. - # Also, Linux requires the "ieee" library for math to work - # right (and it must appear before "-lm"). - #-------------------------------------------------------------------- - - ac_fn_c_check_func "$LINENO" "sin" "ac_cv_func_sin" -if test "x$ac_cv_func_sin" = xyes; then : - MATH_LIBS="" -else - MATH_LIBS="-lm" -fi - - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for main in -lieee" >&5 -$as_echo_n "checking for main in -lieee... " >&6; } -if ${ac_cv_lib_ieee_main+:} false; then : - $as_echo_n "(cached) " >&6 -else - ac_check_lib_save_LIBS=$LIBS -LIBS="-lieee $LIBS" -cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ - - -int -main () -{ -return main (); - ; - return 0; -} -_ACEOF -if ac_fn_c_try_link "$LINENO"; then : - ac_cv_lib_ieee_main=yes -else - ac_cv_lib_ieee_main=no -fi -rm -f core conftest.err conftest.$ac_objext \ - conftest$ac_exeext conftest.$ac_ext -LIBS=$ac_check_lib_save_LIBS -fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_ieee_main" >&5 -$as_echo "$ac_cv_lib_ieee_main" >&6; } -if test "x$ac_cv_lib_ieee_main" = xyes; then : - MATH_LIBS="-lieee $MATH_LIBS" -fi - - - #-------------------------------------------------------------------- - # Interactive UNIX requires -linet instead of -lsocket, plus it - # needs net/errno.h to define the socket-related error codes. - #-------------------------------------------------------------------- - - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for main in -linet" >&5 -$as_echo_n "checking for main in -linet... " >&6; } -if ${ac_cv_lib_inet_main+:} false; then : - $as_echo_n "(cached) " >&6 -else - ac_check_lib_save_LIBS=$LIBS -LIBS="-linet $LIBS" -cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ - - -int -main () -{ -return main (); - ; - return 0; -} -_ACEOF -if ac_fn_c_try_link "$LINENO"; then : - ac_cv_lib_inet_main=yes -else - ac_cv_lib_inet_main=no -fi -rm -f core conftest.err conftest.$ac_objext \ - conftest$ac_exeext conftest.$ac_ext -LIBS=$ac_check_lib_save_LIBS -fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_inet_main" >&5 -$as_echo "$ac_cv_lib_inet_main" >&6; } -if test "x$ac_cv_lib_inet_main" = xyes; then : - LIBS="$LIBS -linet" -fi - - ac_fn_c_check_header_mongrel "$LINENO" "net/errno.h" "ac_cv_header_net_errno_h" "$ac_includes_default" -if test "x$ac_cv_header_net_errno_h" = xyes; then : - - -$as_echo "#define HAVE_NET_ERRNO_H 1" >>confdefs.h - -fi - - - - #-------------------------------------------------------------------- - # Check for the existence of the -lsocket and -lnsl libraries. - # The order here is important, so that they end up in the right - # order in the command line generated by make. Here are some - # special considerations: - # 1. Use "connect" and "accept" to check for -lsocket, and - # "gethostbyname" to check for -lnsl. - # 2. Use each function name only once: can't redo a check because - # autoconf caches the results of the last check and won't redo it. - # 3. Use -lnsl and -lsocket only if they supply procedures that - # aren't already present in the normal libraries. This is because - # IRIX 5.2 has libraries, but they aren't needed and they're - # bogus: they goof up name resolution if used. - # 4. On some SVR4 systems, can't use -lsocket without -lnsl too. - # To get around this problem, check for both libraries together - # if -lsocket doesn't work by itself. - #-------------------------------------------------------------------- - - tcl_checkBoth=0 - ac_fn_c_check_func "$LINENO" "connect" "ac_cv_func_connect" -if test "x$ac_cv_func_connect" = xyes; then : - tcl_checkSocket=0 -else - tcl_checkSocket=1 -fi - - if test "$tcl_checkSocket" = 1; then - ac_fn_c_check_func "$LINENO" "setsockopt" "ac_cv_func_setsockopt" -if test "x$ac_cv_func_setsockopt" = xyes; then : - -else - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for setsockopt in -lsocket" >&5 -$as_echo_n "checking for setsockopt in -lsocket... " >&6; } -if ${ac_cv_lib_socket_setsockopt+:} false; then : - $as_echo_n "(cached) " >&6 -else - ac_check_lib_save_LIBS=$LIBS -LIBS="-lsocket $LIBS" -cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ - -/* Override any GCC internal prototype to avoid an error. - Use char because int might match the return type of a GCC - builtin and then its argument prototype would still apply. */ -#ifdef __cplusplus -extern "C" -#endif -char setsockopt (); -int -main () -{ -return setsockopt (); - ; - return 0; -} -_ACEOF -if ac_fn_c_try_link "$LINENO"; then : - ac_cv_lib_socket_setsockopt=yes -else - ac_cv_lib_socket_setsockopt=no -fi -rm -f core conftest.err conftest.$ac_objext \ - conftest$ac_exeext conftest.$ac_ext -LIBS=$ac_check_lib_save_LIBS -fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_socket_setsockopt" >&5 -$as_echo "$ac_cv_lib_socket_setsockopt" >&6; } -if test "x$ac_cv_lib_socket_setsockopt" = xyes; then : - LIBS="$LIBS -lsocket" -else - tcl_checkBoth=1 -fi - -fi - - fi - if test "$tcl_checkBoth" = 1; then - tk_oldLibs=$LIBS - LIBS="$LIBS -lsocket -lnsl" - ac_fn_c_check_func "$LINENO" "accept" "ac_cv_func_accept" -if test "x$ac_cv_func_accept" = xyes; then : - tcl_checkNsl=0 -else - LIBS=$tk_oldLibs -fi - - fi - ac_fn_c_check_func "$LINENO" "gethostbyname" "ac_cv_func_gethostbyname" -if test "x$ac_cv_func_gethostbyname" = xyes; then : - -else - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for gethostbyname in -lnsl" >&5 -$as_echo_n "checking for gethostbyname in -lnsl... " >&6; } -if ${ac_cv_lib_nsl_gethostbyname+:} false; then : - $as_echo_n "(cached) " >&6 -else - ac_check_lib_save_LIBS=$LIBS -LIBS="-lnsl $LIBS" -cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ - -/* Override any GCC internal prototype to avoid an error. - Use char because int might match the return type of a GCC - builtin and then its argument prototype would still apply. */ -#ifdef __cplusplus -extern "C" -#endif -char gethostbyname (); -int -main () -{ -return gethostbyname (); - ; - return 0; -} -_ACEOF -if ac_fn_c_try_link "$LINENO"; then : - ac_cv_lib_nsl_gethostbyname=yes -else - ac_cv_lib_nsl_gethostbyname=no -fi -rm -f core conftest.err conftest.$ac_objext \ - conftest$ac_exeext conftest.$ac_ext -LIBS=$ac_check_lib_save_LIBS -fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_nsl_gethostbyname" >&5 -$as_echo "$ac_cv_lib_nsl_gethostbyname" >&6; } -if test "x$ac_cv_lib_nsl_gethostbyname" = xyes; then : - LIBS="$LIBS -lnsl" -fi - -fi - - - # TEA specific: Don't perform the eval of the libraries here because - # DL_LIBS won't be set until we call TEA_CONFIG_CFLAGS - - TCL_LIBS='${DL_LIBS} ${LIBS} ${MATH_LIBS}' - - - - - { $as_echo "$as_me:${as_lineno-$LINENO}: checking dirent.h" >&5 -$as_echo_n "checking dirent.h... " >&6; } -if ${tcl_cv_dirent_h+:} false; then : - $as_echo_n "(cached) " >&6 -else - - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ -#include -#include -int -main () -{ - -#ifndef _POSIX_SOURCE -# ifdef __Lynx__ - /* - * Generate compilation error to make the test fail: Lynx headers - * are only valid if really in the POSIX environment. - */ - - missing_procedure(); -# endif -#endif -DIR *d; -struct dirent *entryPtr; -char *p; -d = opendir("foobar"); -entryPtr = readdir(d); -p = entryPtr->d_name; -closedir(d); - - ; - return 0; -} -_ACEOF -if ac_fn_c_try_link "$LINENO"; then : - tcl_cv_dirent_h=yes -else - tcl_cv_dirent_h=no -fi -rm -f core conftest.err conftest.$ac_objext \ - conftest$ac_exeext conftest.$ac_ext -fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_dirent_h" >&5 -$as_echo "$tcl_cv_dirent_h" >&6; } - - if test $tcl_cv_dirent_h = no; then - -$as_echo "#define NO_DIRENT_H 1" >>confdefs.h - - fi - - # TEA specific: - ac_fn_c_check_header_mongrel "$LINENO" "errno.h" "ac_cv_header_errno_h" "$ac_includes_default" -if test "x$ac_cv_header_errno_h" = xyes; then : - -else - -$as_echo "#define NO_ERRNO_H 1" >>confdefs.h - -fi - - - ac_fn_c_check_header_mongrel "$LINENO" "float.h" "ac_cv_header_float_h" "$ac_includes_default" -if test "x$ac_cv_header_float_h" = xyes; then : - -else - -$as_echo "#define NO_FLOAT_H 1" >>confdefs.h - -fi - - - ac_fn_c_check_header_mongrel "$LINENO" "values.h" "ac_cv_header_values_h" "$ac_includes_default" -if test "x$ac_cv_header_values_h" = xyes; then : - -else - -$as_echo "#define NO_VALUES_H 1" >>confdefs.h - -fi - - - ac_fn_c_check_header_mongrel "$LINENO" "limits.h" "ac_cv_header_limits_h" "$ac_includes_default" -if test "x$ac_cv_header_limits_h" = xyes; then : - -$as_echo "#define HAVE_LIMITS_H 1" >>confdefs.h - -else - -$as_echo "#define NO_LIMITS_H 1" >>confdefs.h - -fi - - - ac_fn_c_check_header_mongrel "$LINENO" "stdlib.h" "ac_cv_header_stdlib_h" "$ac_includes_default" -if test "x$ac_cv_header_stdlib_h" = xyes; then : - tcl_ok=1 -else - tcl_ok=0 -fi - - - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ -#include - -_ACEOF -if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | - $EGREP "strtol" >/dev/null 2>&1; then : - -else - tcl_ok=0 -fi -rm -f conftest* - - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ -#include - -_ACEOF -if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | - $EGREP "strtoul" >/dev/null 2>&1; then : - -else - tcl_ok=0 -fi -rm -f conftest* - - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ -#include - -_ACEOF -if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | - $EGREP "strtod" >/dev/null 2>&1; then : - -else - tcl_ok=0 -fi -rm -f conftest* - - if test $tcl_ok = 0; then - -$as_echo "#define NO_STDLIB_H 1" >>confdefs.h - - fi - ac_fn_c_check_header_mongrel "$LINENO" "string.h" "ac_cv_header_string_h" "$ac_includes_default" -if test "x$ac_cv_header_string_h" = xyes; then : - tcl_ok=1 -else - tcl_ok=0 -fi - - - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ -#include - -_ACEOF -if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | - $EGREP "strstr" >/dev/null 2>&1; then : - -else - tcl_ok=0 -fi -rm -f conftest* - - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ -#include - -_ACEOF -if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | - $EGREP "strerror" >/dev/null 2>&1; then : - -else - tcl_ok=0 -fi -rm -f conftest* - - - # See also memmove check below for a place where NO_STRING_H can be - # set and why. - - if test $tcl_ok = 0; then - -$as_echo "#define NO_STRING_H 1" >>confdefs.h - - fi - - ac_fn_c_check_header_mongrel "$LINENO" "sys/wait.h" "ac_cv_header_sys_wait_h" "$ac_includes_default" -if test "x$ac_cv_header_sys_wait_h" = xyes; then : - -else - -$as_echo "#define NO_SYS_WAIT_H 1" >>confdefs.h - -fi - - - ac_fn_c_check_header_mongrel "$LINENO" "dlfcn.h" "ac_cv_header_dlfcn_h" "$ac_includes_default" -if test "x$ac_cv_header_dlfcn_h" = xyes; then : - -else - -$as_echo "#define NO_DLFCN_H 1" >>confdefs.h - -fi - - - - # OS/390 lacks sys/param.h (and doesn't need it, by chance). - for ac_header in sys/param.h -do : - ac_fn_c_check_header_mongrel "$LINENO" "sys/param.h" "ac_cv_header_sys_param_h" "$ac_includes_default" -if test "x$ac_cv_header_sys_param_h" = xyes; then : - cat >>confdefs.h <<_ACEOF -#define HAVE_SYS_PARAM_H 1 -_ACEOF - -fi - -done - - - # Let the user call this, because if it triggers, they will - # need a compat/strtod.c that is correct. Users can also - # use Tcl_GetDouble(FromObj) instead. - #TEA_BUGGY_STRTOD - fi #-------------------------------------------------------------------- # Load the tdomConfig.sh file #-------------------------------------------------------------------- @@ -5501,11 +5059,11 @@ vars="${TDOM_STUB_LIB_SPEC}" for i in $vars; do if test "${TEA_PLATFORM}" = "windows" -a "$GCC" = "yes" ; then # Convert foo.lib to -lfoo for GCC. No-op if not *.lib - i=`echo "$i" | sed -e 's/^\([^-].*\)\.lib$/-l\1/i'` + i=`echo "$i" | sed -e 's/^\([^-].*\)\.[lL][iI][bB]$/-l\1/'` fi PKG_LIBS="$PKG_LIBS $i" done @@ -5983,22 +5541,10 @@ $as_echo "$as_me: WARNING: Building ${PACKAGE_NAME} without threads enabled, but building against Tcl that IS thread-enabled. It is recommended to use --enable-threads." >&2;} fi ;; - *) - if test "${TCL_THREADS}" = "1"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: - --enable-threads requested, but building against a Tcl that is NOT - thread-enabled. This is an OK configuration that will also run in - a thread-enabled core." >&5 -$as_echo "$as_me: WARNING: - --enable-threads requested, but building against a Tcl that is NOT - thread-enabled. This is an OK configuration that will also run in - a thread-enabled core." >&2;} - fi - ;; esac #-------------------------------------------------------------------- @@ -6266,28 +5812,10 @@ fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $doRpath" >&5 $as_echo "$doRpath" >&6; } - # TEA specific: Cross-compiling options for Windows/CE builds? - - if test "${TEA_PLATFORM}" = windows; then : - - { $as_echo "$as_me:${as_lineno-$LINENO}: checking if Windows/CE build is requested" >&5 -$as_echo_n "checking if Windows/CE build is requested... " >&6; } - # Check whether --enable-wince was given. -if test "${enable_wince+set}" = set; then : - enableval=$enable_wince; doWince=$enableval -else - doWince=no -fi - - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $doWince" >&5 -$as_echo "$doWince" >&6; } - -fi - # Set the variable "system" to hold the name and version number # for the system. { $as_echo "$as_me:${as_lineno-$LINENO}: checking system version" >&5 @@ -6306,10 +5834,13 @@ $as_echo "$as_me: WARNING: can't find uname command" >&2;} tcl_cv_sys_version=unknown else if test "`uname -s`" = "AIX" ; then tcl_cv_sys_version=AIX-`uname -v`.`uname -r` + fi + if test "`uname -s`" = "NetBSD" -a -f /etc/debian_version ; then + tcl_cv_sys_version=NetBSD-Debian fi fi fi fi @@ -6450,161 +5981,20 @@ SHLIB_VERSION=".$SHLIB_VERSION" fi case $system in # TEA specific: windows) - # This is a 2-stage check to make sure we have the 64-bit SDK - # We have to know where the SDK is installed. - # This magic is based on MS Platform SDK for Win2003 SP1 - hobbs - # MACHINE is IX86 for LINK, but this is used by the manifest, - # which requires x86|amd64|ia64. MACHINE="X86" if test "$do64bit" != "no" ; then - if test "x${MSSDK}x" = "xx" ; then - MSSDK="C:/Progra~1/Microsoft Platform SDK" - fi - MSSDK=`echo "$MSSDK" | sed -e 's!\\\!/!g'` - PATH64="" case "$do64bit" in amd64|x64|yes) MACHINE="AMD64" ; # default to AMD64 64-bit build - PATH64="${MSSDK}/Bin/Win64/x86/AMD64" ;; ia64) MACHINE="IA64" - PATH64="${MSSDK}/Bin/Win64" ;; esac - if test "$GCC" != "yes" -a ! -d "${PATH64}" ; then - { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Could not find 64-bit $MACHINE SDK to enable 64bit mode" >&5 -$as_echo "$as_me: WARNING: Could not find 64-bit $MACHINE SDK to enable 64bit mode" >&2;} - { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Ensure latest Platform SDK is installed" >&5 -$as_echo "$as_me: WARNING: Ensure latest Platform SDK is installed" >&2;} - do64bit="no" - else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: Using 64-bit $MACHINE mode" >&5 -$as_echo " Using 64-bit $MACHINE mode" >&6; } - do64bit_ok="yes" - fi - fi - - if test "$doWince" != "no" ; then - if test "$do64bit" != "no" ; then - as_fn_error $? "Windows/CE and 64-bit builds incompatible" "$LINENO" 5 - fi - if test "$GCC" = "yes" ; then - as_fn_error $? "Windows/CE and GCC builds incompatible" "$LINENO" 5 - fi - - # First, look for one uninstalled. - # the alternative search directory is invoked by --with-celib - - if test x"${no_celib}" = x ; then - # we reset no_celib in case something fails here - no_celib=true - -# Check whether --with-celib was given. -if test "${with_celib+set}" = set; then : - withval=$with_celib; with_celibconfig=${withval} -fi - - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for Windows/CE celib directory" >&5 -$as_echo_n "checking for Windows/CE celib directory... " >&6; } - if ${ac_cv_c_celibconfig+:} false; then : - $as_echo_n "(cached) " >&6 -else - - # First check to see if --with-celibconfig was specified. - if test x"${with_celibconfig}" != x ; then - if test -d "${with_celibconfig}/inc" ; then - ac_cv_c_celibconfig=`(cd ${with_celibconfig}; pwd)` - else - as_fn_error $? "${with_celibconfig} directory doesn't contain inc directory" "$LINENO" 5 - fi - fi - - # then check for a celib library - if test x"${ac_cv_c_celibconfig}" = x ; then - for i in \ - ../celib-palm-3.0 \ - ../celib \ - ../../celib-palm-3.0 \ - ../../celib \ - `ls -dr ../celib-*3.[0-9]* 2>/dev/null` \ - ${srcdir}/../celib-palm-3.0 \ - ${srcdir}/../celib \ - `ls -dr ${srcdir}/../celib-*3.[0-9]* 2>/dev/null` \ - ; do - if test -d "$i/inc" ; then - ac_cv_c_celibconfig=`(cd $i; pwd)` - break - fi - done - fi - -fi - - if test x"${ac_cv_c_celibconfig}" = x ; then - as_fn_error $? "Cannot find celib support library directory" "$LINENO" 5 - else - no_celib= - CELIB_DIR=${ac_cv_c_celibconfig} - CELIB_DIR=`echo "$CELIB_DIR" | sed -e 's!\\\!/!g'` - { $as_echo "$as_me:${as_lineno-$LINENO}: result: found $CELIB_DIR" >&5 -$as_echo "found $CELIB_DIR" >&6; } - fi - fi - - # Set defaults for common evc4/PPC2003 setup - # Currently Tcl requires 300+, possibly 420+ for sockets - CEVERSION=420; # could be 211 300 301 400 420 ... - TARGETCPU=ARMV4; # could be ARMV4 ARM MIPS SH3 X86 ... - ARCH=ARM; # could be ARM MIPS X86EM ... - PLATFORM="Pocket PC 2003"; # or "Pocket PC 2002" - if test "$doWince" != "yes"; then - # If !yes then the user specified something - # Reset ARCH to allow user to skip specifying it - ARCH= - eval `echo $doWince | awk -F, '{ \ - if (length($1)) { printf "CEVERSION=\"%s\"\n", $1; \ - if ($1 < 400) { printf "PLATFORM=\"Pocket PC 2002\"\n" } }; \ - if (length($2)) { printf "TARGETCPU=\"%s\"\n", toupper($2) }; \ - if (length($3)) { printf "ARCH=\"%s\"\n", toupper($3) }; \ - if (length($4)) { printf "PLATFORM=\"%s\"\n", $4 }; \ - }'` - if test "x${ARCH}" = "x" ; then - ARCH=$TARGETCPU; - fi - fi - OSVERSION=WCE$CEVERSION; - if test "x${WCEROOT}" = "x" ; then - WCEROOT="C:/Program Files/Microsoft eMbedded C++ 4.0" - if test ! -d "${WCEROOT}" ; then - WCEROOT="C:/Program Files/Microsoft eMbedded Tools" - fi - fi - if test "x${SDKROOT}" = "x" ; then - SDKROOT="C:/Program Files/Windows CE Tools" - if test ! -d "${SDKROOT}" ; then - SDKROOT="C:/Windows CE Tools" - fi - fi - WCEROOT=`echo "$WCEROOT" | sed -e 's!\\\!/!g'` - SDKROOT=`echo "$SDKROOT" | sed -e 's!\\\!/!g'` - if test ! -d "${SDKROOT}/${OSVERSION}/${PLATFORM}/Lib/${TARGETCPU}" \ - -o ! -d "${WCEROOT}/EVC/${OSVERSION}/bin"; then - as_fn_error $? "could not find PocketPC SDK or target compiler to enable WinCE mode $CEVERSION,$TARGETCPU,$ARCH,$PLATFORM" "$LINENO" 5 - doWince="no" - else - # We could PATH_NOSPACE these, but that's not important, - # as long as we quote them when used. - CEINCLUDE="${SDKROOT}/${OSVERSION}/${PLATFORM}/include" - if test -d "${CEINCLUDE}/${TARGETCPU}" ; then - CEINCLUDE="${CEINCLUDE}/${TARGETCPU}" - fi - CELIBPATH="${SDKROOT}/${OSVERSION}/${PLATFORM}/Lib/${TARGETCPU}" - fi fi if test "$GCC" != "yes" ; then if test "${SHARED_BUILD}" = "0" ; then runtime=-MT @@ -6617,11 +6007,11 @@ vars="ucrt.lib" for i in $vars; do if test "${TEA_PLATFORM}" = "windows" -a "$GCC" = "yes" ; then # Convert foo.lib to -lfoo for GCC. No-op if not *.lib - i=`echo "$i" | sed -e 's/^\([^-].*\)\.lib$/-l\1/i'` + i=`echo "$i" | sed -e 's/^\([^-].*\)\.[lL][iI][bB]$/-l\1/'` fi PKG_LIBS="$PKG_LIBS $i" done @@ -6629,69 +6019,29 @@ *) ;; esac if test "$do64bit" != "no" ; then - # All this magic is necessary for the Win64 SDK RC1 - hobbs - CC="\"${PATH64}/cl.exe\"" - CFLAGS="${CFLAGS} -I\"${MSSDK}/Include\" -I\"${MSSDK}/Include/crt\" -I\"${MSSDK}/Include/crt/sys\"" - RC="\"${MSSDK}/bin/rc.exe\"" - lflags="${lflags} -nologo -MACHINE:${MACHINE} -LIBPATH:\"${MSSDK}/Lib/${MACHINE}\"" - LINKBIN="\"${PATH64}/link.exe\"" + CC="cl.exe" + RC="rc.exe" + lflags="${lflags} -nologo -MACHINE:${MACHINE} " + LINKBIN="link.exe" CFLAGS_DEBUG="-nologo -Zi -Od -W3 ${runtime}d" CFLAGS_OPTIMIZE="-nologo -O2 -W2 ${runtime}" # Avoid 'unresolved external symbol __security_cookie' # errors, c.f. http://support.microsoft.com/?id=894573 vars="bufferoverflowU.lib" for i in $vars; do if test "${TEA_PLATFORM}" = "windows" -a "$GCC" = "yes" ; then # Convert foo.lib to -lfoo for GCC. No-op if not *.lib - i=`echo "$i" | sed -e 's/^\([^-].*\)\.lib$/-l\1/i'` + i=`echo "$i" | sed -e 's/^\([^-].*\)\.[lL][iI][bB]$/-l\1/'` fi PKG_LIBS="$PKG_LIBS $i" done - elif test "$doWince" != "no" ; then - CEBINROOT="${WCEROOT}/EVC/${OSVERSION}/bin" - if test "${TARGETCPU}" = "X86"; then - CC="\"${CEBINROOT}/cl.exe\"" - else - CC="\"${CEBINROOT}/cl${ARCH}.exe\"" - fi - CFLAGS="$CFLAGS -I\"${CELIB_DIR}/inc\" -I\"${CEINCLUDE}\"" - RC="\"${WCEROOT}/Common/EVC/bin/rc.exe\"" - arch=`echo ${ARCH} | awk '{print tolower($0)}'` - defs="${ARCH} _${ARCH}_ ${arch} PALM_SIZE _MT _WINDOWS" - if test "${SHARED_BUILD}" = "1" ; then - # Static CE builds require static celib as well - defs="${defs} _DLL" - fi - for i in $defs ; do - -cat >>confdefs.h <<_ACEOF -#define $i 1 -_ACEOF - - done - -cat >>confdefs.h <<_ACEOF -#define _WIN32_WCE $CEVERSION -_ACEOF - - -cat >>confdefs.h <<_ACEOF -#define UNDER_CE $CEVERSION -_ACEOF - - CFLAGS_DEBUG="-nologo -Zi -Od" - CFLAGS_OPTIMIZE="-nologo -Ox" - lversion=`echo ${CEVERSION} | sed -e 's/\(.\)\(..\)/\1\.\2/'` - lflags="${lflags} -MACHINE:${ARCH} -LIBPATH:\"${CELIBPATH}\" -subsystem:windowsce,${lversion} -nologo" - LINKBIN="\"${CEBINROOT}/link.exe\"" - else RC="rc" lflags="${lflags} -nologo" LINKBIN="link" CFLAGS_DEBUG="-nologo -Z7 -Od -W3 -WX ${runtime}d" @@ -6831,18 +6181,18 @@ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_cross" >&5 $as_echo "$ac_cv_cross" >&6; } if test "$ac_cv_cross" = "yes"; then case "$do64bit" in amd64|x64|yes) - CC="x86_64-w64-mingw32-gcc" + CC="x86_64-w64-mingw32-${CC}" LD="x86_64-w64-mingw32-ld" AR="x86_64-w64-mingw32-ar" RANLIB="x86_64-w64-mingw32-ranlib" RC="x86_64-w64-mingw32-windres" ;; *) - CC="i686-w64-mingw32-gcc" + CC="i686-w64-mingw32-${CC}" LD="i686-w64-mingw32-ld" AR="i686-w64-mingw32-ar" RANLIB="i686-w64-mingw32-ranlib" RC="i686-w64-mingw32-windres" ;; @@ -6860,26 +6210,21 @@ # and also # http://msdn2.microsoft.com/en-us/library/y0zzbyt4%28VS.80%29.aspx # This essentially turns it all on. LDFLAGS_DEBUG="-debug -debugtype:cv" LDFLAGS_OPTIMIZE="-release" - if test "$doWince" != "no" ; then - LDFLAGS_CONSOLE="-link ${lflags}" - LDFLAGS_WINDOW=${LDFLAGS_CONSOLE} - else - LDFLAGS_CONSOLE="-link -subsystem:console ${lflags}" - LDFLAGS_WINDOW="-link -subsystem:windows ${lflags}" - fi + LDFLAGS_CONSOLE="-link -subsystem:console ${lflags}" + LDFLAGS_WINDOW="-link -subsystem:windows ${lflags}" fi SHLIB_SUFFIX=".dll" SHARED_LIB_SUFFIX='${TCL_TRIM_DOTS}.dll' TCL_LIB_VERSIONS_OK=nodots ;; AIX-*) - if test "${TCL_THREADS}" = "1" -a "$GCC" != "yes"; then : + if test "$GCC" != "yes"; then : # AIX requires the _r compiler when gcc isn't being used case "${CC}" in *_r|*_r\ *) # ok ... @@ -6924,18 +6269,18 @@ # AIX-5 uses ELF style dynamic libraries on IA-64, but not PPC SHLIB_LD="/usr/ccs/bin/ld -G -z text" if test "$GCC" = yes; then : - CC_SEARCH_FLAGS='-Wl,-R,${LIB_RUNTIME_DIR}' + CC_SEARCH_FLAGS='"-Wl,-R,${LIB_RUNTIME_DIR}"' else - CC_SEARCH_FLAGS='-R${LIB_RUNTIME_DIR}' + CC_SEARCH_FLAGS='"-R${LIB_RUNTIME_DIR}"' fi - LD_SEARCH_FLAGS='-R ${LIB_RUNTIME_DIR}' + LD_SEARCH_FLAGS='-R "${LIB_RUNTIME_DIR}"' else if test "$GCC" = yes; then : @@ -6946,11 +6291,11 @@ SHLIB_LD="/bin/ld -bhalt:4 -bM:SRE -bexpall -H512 -T512 -bnoentry" LDFLAGS="$LDFLAGS -brtl" fi SHLIB_LD="${SHLIB_LD} ${SHLIB_LD_FLAGS}" - CC_SEARCH_FLAGS='-L${LIB_RUNTIME_DIR}' + CC_SEARCH_FLAGS='"-L${LIB_RUNTIME_DIR}"' LD_SEARCH_FLAGS=${CC_SEARCH_FLAGS} fi ;; BeOS*) @@ -7002,10 +6347,17 @@ if test "x$ac_cv_lib_bind_inet_ntoa" = xyes; then : LIBS="$LIBS -lbind -lsocket" fi ;; + BSD/OS-2.1*|BSD/OS-3*) + SHLIB_CFLAGS="" + SHLIB_LD="shlicc -r" + SHLIB_SUFFIX=".so" + CC_SEARCH_FLAGS="" + LD_SEARCH_FLAGS="" + ;; BSD/OS-4.*) SHLIB_CFLAGS="-export-dynamic -fPIC" SHLIB_LD='${CC} -shared' SHLIB_SUFFIX=".so" LDFLAGS="$LDFLAGS -export-dynamic" @@ -7013,22 +6365,30 @@ LD_SEARCH_FLAGS="" ;; CYGWIN_*) SHLIB_CFLAGS="" SHLIB_LD='${CC} -shared' - SHLIB_LD_LIBS="${SHLIB_LD_LIBS} -Wl,--out-implib,\$@.a" SHLIB_SUFFIX=".dll" + SHLIB_LD_LIBS="${SHLIB_LD_LIBS} -Wl,--out-implib,\$@.a" EXEEXT=".exe" do64bit_ok=yes + CC_SEARCH_FLAGS="" + LD_SEARCH_FLAGS="" + ;; + dgux*) + SHLIB_CFLAGS="-K PIC" + SHLIB_LD='${CC} -G' + SHLIB_LD_LIBS="" + SHLIB_SUFFIX=".so" CC_SEARCH_FLAGS="" LD_SEARCH_FLAGS="" ;; Haiku*) LDFLAGS="$LDFLAGS -Wl,--export-dynamic" SHLIB_CFLAGS="-fPIC" SHLIB_SUFFIX=".so" - SHLIB_LD='${CC} -shared ${CFLAGS} ${LDFLAGS}' + SHLIB_LD='${CC} ${CFLAGS} ${LDFLAGS} -shared' { $as_echo "$as_me:${as_lineno-$LINENO}: checking for inet_ntoa in -lnetwork" >&5 $as_echo_n "checking for inet_ntoa in -lnetwork... " >&6; } if ${ac_cv_lib_network_inet_ntoa+:} false; then : $as_echo_n "(cached) " >&6 else @@ -7078,14 +6438,10 @@ #LIBS="$LIBS -lxnet" # Use the XOPEN network library if test "`uname -m`" = ia64; then : SHLIB_SUFFIX=".so" - # Use newer C++ library for C++ extensions - #if test "$GCC" != "yes" ; then - # CPPFLAGS="-AA" - #fi else SHLIB_SUFFIX=".sl" @@ -7132,13 +6488,15 @@ tcl_ok=no fi if test "$tcl_ok" = yes; then : + SHLIB_CFLAGS="+z" + SHLIB_LD="ld -b" LDFLAGS="$LDFLAGS -Wl,-E" - CC_SEARCH_FLAGS='-Wl,+s,+b,${LIB_RUNTIME_DIR}:.' - LD_SEARCH_FLAGS='+s +b ${LIB_RUNTIME_DIR}:.' + CC_SEARCH_FLAGS='"-Wl,+s,+b,${LIB_RUNTIME_DIR}:."' + LD_SEARCH_FLAGS='+s +b "${LIB_RUNTIME_DIR}:."' LD_LIBRARY_PATH_VAR="SHLIB_PATH" fi if test "$GCC" = yes; then : @@ -7146,14 +6504,10 @@ LD_SEARCH_FLAGS=${CC_SEARCH_FLAGS} else CFLAGS="$CFLAGS -z" - # Users may want PA-RISC 1.1/2.0 portable code - needs HP cc - #CFLAGS="$CFLAGS +DAportable" - SHLIB_CFLAGS="+z" - SHLIB_LD="ld -b" fi # Check to enable 64-bit flags for compiler/linker if test "$do64bit" = "yes"; then : @@ -7165,11 +6519,11 @@ # 64-bit gcc in use. Fix flags for GNU ld. do64bit_ok=yes SHLIB_LD='${CC} -shared' if test $doRpath = yes; then : - CC_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}' + CC_SEARCH_FLAGS='"-Wl,-rpath,${LIB_RUNTIME_DIR}"' fi LD_SEARCH_FLAGS=${CC_SEARCH_FLAGS} ;; *) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: 64bit mode not supported with GCC on $system" >&5 @@ -7184,18 +6538,89 @@ LDFLAGS_ARCH="+DD64" fi fi ;; + HP-UX-*.08.*|HP-UX-*.09.*|HP-UX-*.10.*) + SHLIB_SUFFIX=".sl" + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for shl_load in -ldld" >&5 +$as_echo_n "checking for shl_load in -ldld... " >&6; } +if ${ac_cv_lib_dld_shl_load+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-ldld $LIBS" +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char shl_load (); +int +main () +{ +return shl_load (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + ac_cv_lib_dld_shl_load=yes +else + ac_cv_lib_dld_shl_load=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dld_shl_load" >&5 +$as_echo "$ac_cv_lib_dld_shl_load" >&6; } +if test "x$ac_cv_lib_dld_shl_load" = xyes; then : + tcl_ok=yes +else + tcl_ok=no +fi + + if test "$tcl_ok" = yes; then : + + SHLIB_CFLAGS="+z" + SHLIB_LD="ld -b" + SHLIB_LD_LIBS="" + LDFLAGS="$LDFLAGS -Wl,-E" + CC_SEARCH_FLAGS='"-Wl,+s,+b,${LIB_RUNTIME_DIR}:."' + LD_SEARCH_FLAGS='+s +b "${LIB_RUNTIME_DIR}:."' + LD_LIBRARY_PATH_VAR="SHLIB_PATH" + +fi ;; + IRIX-5.*) + SHLIB_CFLAGS="" + SHLIB_LD="ld -shared -rdata_shared" + SHLIB_SUFFIX=".so" + case " $LIBOBJS " in + *" mkstemp.$ac_objext "* ) ;; + *) LIBOBJS="$LIBOBJS mkstemp.$ac_objext" + ;; +esac + + if test $doRpath = yes; then : + + CC_SEARCH_FLAGS='"-Wl,-rpath,${LIB_RUNTIME_DIR}"' + LD_SEARCH_FLAGS='-rpath "${LIB_RUNTIME_DIR}"' +fi + ;; IRIX-6.*) SHLIB_CFLAGS="" SHLIB_LD="ld -n32 -shared -rdata_shared" SHLIB_SUFFIX=".so" if test $doRpath = yes; then : - CC_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}' - LD_SEARCH_FLAGS='-rpath ${LIB_RUNTIME_DIR}' + CC_SEARCH_FLAGS='"-Wl,-rpath,${LIB_RUNTIME_DIR}"' + LD_SEARCH_FLAGS='-rpath "${LIB_RUNTIME_DIR}"' fi if test "$GCC" = yes; then : CFLAGS="$CFLAGS -mabi=n32" LDFLAGS="$LDFLAGS -mabi=n32" @@ -7219,12 +6644,12 @@ SHLIB_CFLAGS="" SHLIB_LD="ld -n32 -shared -rdata_shared" SHLIB_SUFFIX=".so" if test $doRpath = yes; then : - CC_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}' - LD_SEARCH_FLAGS='-rpath ${LIB_RUNTIME_DIR}' + CC_SEARCH_FLAGS='"-Wl,-rpath,${LIB_RUNTIME_DIR}"' + LD_SEARCH_FLAGS='-rpath "${LIB_RUNTIME_DIR}"' fi # Check to enable 64-bit flags for compiler/linker if test "$do64bit" = yes; then : @@ -7243,23 +6668,36 @@ fi fi ;; - Linux*|GNU*|NetBSD-Debian) + Linux*|GNU*|NetBSD-Debian|DragonFly-*|FreeBSD-*) SHLIB_CFLAGS="-fPIC" SHLIB_SUFFIX=".so" # TEA specific: CFLAGS_OPTIMIZE="-O2 -fomit-frame-pointer" # TEA specific: use LDFLAGS_DEFAULT instead of LDFLAGS - SHLIB_LD='${CC} -shared ${CFLAGS} ${LDFLAGS_DEFAULT}' + SHLIB_LD='${CC} ${CFLAGS} ${LDFLAGS_DEFAULT} -shared' LDFLAGS="$LDFLAGS -Wl,--export-dynamic" + + case $system in + DragonFly-*|FreeBSD-*) + if test "${TCL_THREADS}" = "1"; then : + + # The -pthread needs to go in the LDFLAGS, not LIBS + LIBS=`echo $LIBS | sed s/-pthread//` + CFLAGS="$CFLAGS $PTHREAD_CFLAGS" + LDFLAGS="$LDFLAGS $PTHREAD_LIBS" +fi + ;; + esac + if test $doRpath = yes; then : - CC_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}' + CC_SEARCH_FLAGS='"-Wl,-rpath,${LIB_RUNTIME_DIR}"' fi LD_SEARCH_FLAGS=${CC_SEARCH_FLAGS} if test "`uname -m`" = "alpha"; then : CFLAGS="$CFLAGS -mieee" fi @@ -7320,12 +6758,12 @@ CFLAGS_OPTIMIZE=-02 SHLIB_LD='${CC} -shared' LD_FLAGS="-Wl,--export-dynamic" if test $doRpath = yes; then : - CC_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}' - LD_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}' + CC_SEARCH_FLAGS='"-Wl,-rpath,${LIB_RUNTIME_DIR}"' + LD_SEARCH_FLAGS='"-Wl,-rpath,${LIB_RUNTIME_DIR}"' fi ;; OpenBSD-*) arch=`arch -s` case "$arch" in @@ -7334,80 +6772,43 @@ ;; *) SHLIB_CFLAGS="-fpic" ;; esac - SHLIB_LD='${CC} -shared ${SHLIB_CFLAGS}' + SHLIB_LD='${CC} ${SHLIB_CFLAGS} -shared' SHLIB_SUFFIX=".so" if test $doRpath = yes; then : - CC_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}' + CC_SEARCH_FLAGS='"-Wl,-rpath,${LIB_RUNTIME_DIR}"' fi LD_SEARCH_FLAGS=${CC_SEARCH_FLAGS} SHARED_LIB_SUFFIX='${TCL_TRIM_DOTS}.so${SHLIB_VERSION}' - LDFLAGS="-Wl,-export-dynamic" + LDFLAGS="$LDFLAGS -Wl,-export-dynamic" CFLAGS_OPTIMIZE="-O2" - if test "${TCL_THREADS}" = "1"; then : - - # On OpenBSD: Compile with -pthread - # Don't link with -lpthread - LIBS=`echo $LIBS | sed s/-lpthread//` - CFLAGS="$CFLAGS -pthread" - -fi + # On OpenBSD: Compile with -pthread + # Don't link with -lpthread + LIBS=`echo $LIBS | sed s/-lpthread//` + CFLAGS="$CFLAGS -pthread" # OpenBSD doesn't do version numbers with dots. UNSHARED_LIB_SUFFIX='${TCL_TRIM_DOTS}.a' TCL_LIB_VERSIONS_OK=nodots ;; NetBSD-*) # NetBSD has ELF and can use 'cc -shared' to build shared libs SHLIB_CFLAGS="-fPIC" - SHLIB_LD='${CC} -shared ${SHLIB_CFLAGS}' + SHLIB_LD='${CC} ${SHLIB_CFLAGS} -shared' SHLIB_SUFFIX=".so" LDFLAGS="$LDFLAGS -export-dynamic" if test $doRpath = yes; then : - CC_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}' + CC_SEARCH_FLAGS='"-Wl,-rpath,${LIB_RUNTIME_DIR}"' fi LD_SEARCH_FLAGS=${CC_SEARCH_FLAGS} - if test "${TCL_THREADS}" = "1"; then : - - # The -pthread needs to go in the CFLAGS, not LIBS - LIBS=`echo $LIBS | sed s/-pthread//` - CFLAGS="$CFLAGS -pthread" - LDFLAGS="$LDFLAGS -pthread" - -fi - ;; - FreeBSD-*) - # This configuration from FreeBSD Ports. - SHLIB_CFLAGS="-fPIC" - SHLIB_LD="${CC} -shared" - SHLIB_LD_LIBS="${SHLIB_LD_LIBS} -Wl,-soname,\$@" - SHLIB_SUFFIX=".so" - LDFLAGS="" - if test $doRpath = yes; then : - - CC_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}' - LD_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}' -fi - if test "${TCL_THREADS}" = "1"; then : - - # The -pthread needs to go in the LDFLAGS, not LIBS - LIBS=`echo $LIBS | sed s/-pthread//` - CFLAGS="$CFLAGS $PTHREAD_CFLAGS" - LDFLAGS="$LDFLAGS $PTHREAD_LIBS" -fi - case $system in - FreeBSD-3.*) - # Version numbers are dot-stripped by system policy. - TCL_TRIM_DOTS=`echo ${PACKAGE_VERSION} | tr -d .` - UNSHARED_LIB_SUFFIX='${TCL_TRIM_DOTS}.a' - SHARED_LIB_SUFFIX='${TCL_TRIM_DOTS}\$\{DBGX\}.so.1' - TCL_LIB_VERSIONS_OK=nodots - ;; - esac + # The -pthread needs to go in the CFLAGS, not LIBS + LIBS=`echo $LIBS | sed s/-pthread//` + CFLAGS="$CFLAGS -pthread" + LDFLAGS="$LDFLAGS -pthread" ;; Darwin-*) CFLAGS_OPTIMIZE="-Os" SHLIB_CFLAGS="-fno-common" # To avoid discrepancies between what headers configure sees during @@ -7550,16 +6951,10 @@ fi # TEA specific: link shlib with current and compatibility version flags vers=`echo ${PACKAGE_VERSION} | sed -e 's/^\([0-9]\{1,5\}\)\(\(\.[0-9]\{1,3\}\)\{0,2\}\).*$/\1\2/p' -e d` SHLIB_LD="${SHLIB_LD} -current_version ${vers:-0} -compatibility_version ${vers:-0}" SHLIB_SUFFIX=".dylib" - # Don't use -prebind when building for Mac OS X 10.4 or later only: - if test "`echo "${MACOSX_DEPLOYMENT_TARGET}" | awk -F '10\\.' '{print int($2)}'`" -lt 4 -a \ - "`echo "${CPPFLAGS}" | awk -F '-mmacosx-version-min=10\\.' '{print int($2)}'`" -lt 4; then : - - LDFLAGS="$LDFLAGS -prebind" -fi LDFLAGS="$LDFLAGS -headerpad_max_install_names" { $as_echo "$as_me:${as_lineno-$LINENO}: checking if ld accepts -search_paths_first flag" >&5 $as_echo_n "checking if ld accepts -search_paths_first flag... " >&6; } if ${tcl_cv_ld_search_paths_first+:} false; then : $as_echo_n "(cached) " >&6 @@ -7719,35 +7114,31 @@ fi SHLIB_SUFFIX=".so" if test $doRpath = yes; then : - CC_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}' + CC_SEARCH_FLAGS='"-Wl,-rpath,${LIB_RUNTIME_DIR}"' LD_SEARCH_FLAGS='-rpath ${LIB_RUNTIME_DIR}' fi if test "$GCC" = yes; then : CFLAGS="$CFLAGS -mieee" else CFLAGS="$CFLAGS -DHAVE_TZSET -std1 -ieee" fi # see pthread_intro(3) for pthread support on osf1, k.furukawa - if test "${TCL_THREADS}" = 1; then : - - CFLAGS="$CFLAGS -DHAVE_PTHREAD_ATTR_SETSTACKSIZE" - CFLAGS="$CFLAGS -DTCL_THREAD_STACK_MIN=PTHREAD_STACK_MIN*64" - LIBS=`echo $LIBS | sed s/-lpthreads//` - if test "$GCC" = yes; then : - - LIBS="$LIBS -lpthread -lmach -lexc" + CFLAGS="$CFLAGS -DHAVE_PTHREAD_ATTR_SETSTACKSIZE" + CFLAGS="$CFLAGS -DTCL_THREAD_STACK_MIN=PTHREAD_STACK_MIN*64" + LIBS=`echo $LIBS | sed s/-lpthreads//` + if test "$GCC" = yes; then : + + LIBS="$LIBS -lpthread -lmach -lexc" else - CFLAGS="$CFLAGS -pthread" - LDFLAGS="$LDFLAGS -pthread" - -fi + CFLAGS="$CFLAGS -pthread" + LDFLAGS="$LDFLAGS -pthread" fi ;; QNX-6*) # QNX RTP @@ -7793,17 +7184,17 @@ SHLIB_CFLAGS="-KPIC" SHLIB_SUFFIX=".so" if test "$GCC" = yes; then : SHLIB_LD='${CC} -shared' - CC_SEARCH_FLAGS='-Wl,-R,${LIB_RUNTIME_DIR}' + CC_SEARCH_FLAGS='"-Wl,-R,${LIB_RUNTIME_DIR}"' LD_SEARCH_FLAGS=${CC_SEARCH_FLAGS} else SHLIB_LD="/usr/ccs/bin/ld -G -z text" - CC_SEARCH_FLAGS='-R ${LIB_RUNTIME_DIR}' + CC_SEARCH_FLAGS='-R "${LIB_RUNTIME_DIR}"' LD_SEARCH_FLAGS=${CC_SEARCH_FLAGS} fi ;; SunOS-5*) @@ -7899,11 +7290,11 @@ SHLIB_SUFFIX=".so" if test "$GCC" = yes; then : SHLIB_LD='${CC} -shared' - CC_SEARCH_FLAGS='-Wl,-R,${LIB_RUNTIME_DIR}' + CC_SEARCH_FLAGS='"-Wl,-R,${LIB_RUNTIME_DIR}"' LD_SEARCH_FLAGS=${CC_SEARCH_FLAGS} if test "$do64bit_ok" = yes; then : if test "$arch" = "sparcv9 sparc"; then : @@ -7936,12 +7327,12 @@ # TEA specific: use LDFLAGS_DEFAULT instead of LDFLAGS SHLIB_LD='${CC} -G -z text ${LDFLAGS_DEFAULT}';; *) SHLIB_LD='/usr/ccs/bin/ld -G -z text';; esac - CC_SEARCH_FLAGS='-Wl,-R,${LIB_RUNTIME_DIR}' - LD_SEARCH_FLAGS='-R ${LIB_RUNTIME_DIR}' + CC_SEARCH_FLAGS='"-Wl,-R,${LIB_RUNTIME_DIR}"' + LD_SEARCH_FLAGS='-R "${LIB_RUNTIME_DIR}"' fi ;; UNIX_SV* | UnixWare-5*) SHLIB_CFLAGS="-KPIC" @@ -8010,13 +7401,13 @@ if test "$GCC" = yes; then : case $system in AIX-*) ;; BSD/OS*) ;; - CYGWIN_*|MINGW32_*) ;; + CYGWIN_*|MINGW32_*|MINGW64_*|MSYS_*) ;; IRIX*) ;; - NetBSD-*|FreeBSD-*|OpenBSD-*) ;; + NetBSD-*|DragonFly-*|FreeBSD-*|OpenBSD-*) ;; Darwin-*) ;; SCO_SV-3.2*) ;; windows) ;; *) SHLIB_CFLAGS="-fPIC" ;; esac @@ -8215,10 +7606,21 @@ $as_echo "#define HAVE_CAST_TO_UNION 1" >>confdefs.h fi + ac_fn_c_check_header_mongrel "$LINENO" "stdbool.h" "ac_cv_header_stdbool_h" "$ac_includes_default" +if test "x$ac_cv_header_stdbool_h" = xyes; then : + +$as_echo "#define HAVE_STDBOOL_H 1" >>confdefs.h + +fi + + + + + @@ -8408,11 +7810,11 @@ tcl_type_64bit=__int64 else tcl_type_64bit="long long" fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext - # See if we should use long anyway Note that we substitute in the + # See if we could use long anyway Note that we substitute in the # type that is our current guess for a 64-bit type inside this check # program, so it should be modified only carefully... cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ @@ -8434,12 +7836,12 @@ if test "${tcl_cv_type_64bit}" = none ; then $as_echo "#define TCL_WIDE_INT_IS_LONG 1" >>confdefs.h - { $as_echo "$as_me:${as_lineno-$LINENO}: result: using long" >&5 -$as_echo "using long" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } elif test "${tcl_cv_type_64bit}" = "__int64" \ -a "${TEA_PLATFORM}" = "windows" ; then # TEA specific: We actually want to use the default tcl.h checks in # this case to handle both TCL_WIDE_INT_TYPE and TCL_LL_MODIFIER* { $as_echo "$as_me:${as_lineno-$LINENO}: result: using Tcl header defaults" >&5 @@ -8483,10 +7885,44 @@ $as_echo "$tcl_cv_struct_dirent64" >&6; } if test "x${tcl_cv_struct_dirent64}" = "xyes" ; then $as_echo "#define HAVE_STRUCT_DIRENT64 1" >>confdefs.h + fi + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for DIR64" >&5 +$as_echo_n "checking for DIR64... " >&6; } +if ${tcl_cv_DIR64+:} false; then : + $as_echo_n "(cached) " >&6 +else + + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +#include +int +main () +{ +struct dirent64 *p; DIR64 d = opendir64("."); + p = readdir64(d); rewinddir64(d); closedir64(d); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + tcl_cv_DIR64=yes +else + tcl_cv_DIR64=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_DIR64" >&5 +$as_echo "$tcl_cv_DIR64" >&6; } + if test "x${tcl_cv_DIR64}" = "xyes" ; then + +$as_echo "#define HAVE_DIR64 1" >>confdefs.h + fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for struct stat64" >&5 $as_echo_n "checking for struct stat64... " >&6; } if ${tcl_cv_struct_stat64+:} false; then : @@ -8587,11 +8023,10 @@ enableval=$enable_symbols; tcl_ok=$enableval else tcl_ok=no fi - DBGX="" if test "$tcl_ok" = "no"; then CFLAGS_DEFAULT="${CFLAGS_OPTIMIZE} -DNDEBUG" LDFLAGS_DEFAULT="${LDFLAGS_OPTIMIZE}" { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } @@ -8601,15 +8036,10 @@ if test "$tcl_ok" = "yes"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes (standard debugging)" >&5 $as_echo "yes (standard debugging)" >&6; } fi fi - # TEA specific: - if test "${TEA_PLATFORM}" != "windows" ; then - LDFLAGS_DEFAULT="${LDFLAGS}" - fi - if test "$tcl_ok" = "mem" -o "$tcl_ok" = "all"; then @@ -8647,11 +8077,11 @@ #-------------------------------------------------------------------- if test "${TEA_PLATFORM}" = "windows" -a "$GCC" != "yes"; then MAKE_STATIC_LIB="\${STLIB_LD} -out:\$@ \$(PKG_OBJECTS)" - MAKE_SHARED_LIB="\${SHLIB_LD} \${SHLIB_LD_LIBS} \${LDFLAGS_DEFAULT} -out:\$@ \$(PKG_OBJECTS)" + MAKE_SHARED_LIB="\${SHLIB_LD} \${LDFLAGS} \${LDFLAGS_DEFAULT} -out:\$@ \$(PKG_OBJECTS) \${SHLIB_LD_LIBS}" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #if defined(_MSC_VER) && _MSC_VER >= 1400 print("manifest needed") @@ -8673,11 +8103,11 @@ rm -f conftest* MAKE_STUB_LIB="\${STLIB_LD} -nodefaultlib -out:\$@ \$(PKG_STUB_OBJECTS)" else MAKE_STATIC_LIB="\${STLIB_LD} \$@ \$(PKG_OBJECTS)" - MAKE_SHARED_LIB="\${SHLIB_LD} -o \$@ \$(PKG_OBJECTS) \${SHLIB_LD_LIBS}" + MAKE_SHARED_LIB="\${SHLIB_LD} \${LDFLAGS} \${LDFLAGS_DEFAULT} -o \$@ \$(PKG_OBJECTS) \${SHLIB_LD_LIBS}" MAKE_STUB_LIB="\${STLIB_LD} \$@ \$(PKG_STUB_OBJECTS)" fi if test "${SHARED_BUILD}" = "1" ; then MAKE_LIB="${MAKE_SHARED_LIB} " @@ -8761,28 +8191,28 @@ { $as_echo "$as_me:${as_lineno-$LINENO}: checking for tclsh" >&5 $as_echo_n "checking for tclsh... " >&6; } if test -f "${TCL_BIN_DIR}/Makefile" ; then # tclConfig.sh is in Tcl build directory if test "${TEA_PLATFORM}" = "windows"; then - if test -f "${TCL_BIN_DIR}/tclsh${TCL_MAJOR_VERSION}${TCL_MINOR_VERSION}${TCL_DBGX}${EXEEXT}" ; then - TCLSH_PROG="${TCL_BIN_DIR}/tclsh${TCL_MAJOR_VERSION}${TCL_MINOR_VERSION}${TCL_DBGX}${EXEEXT}" - elif test -f "${TCL_BIN_DIR}/tclsh${TCL_MAJOR_VERSION}${TCL_MINOR_VERSION}${TCL_DBGX}s${EXEEXT}" ; then - TCLSH_PROG="${TCL_BIN_DIR}/tclsh${TCL_MAJOR_VERSION}${TCL_MINOR_VERSION}${TCL_DBGX}s${EXEEXT}" - elif test -f "${TCL_BIN_DIR}/tclsh${TCL_MAJOR_VERSION}${TCL_MINOR_VERSION}${TCL_DBGX}t${EXEEXT}" ; then - TCLSH_PROG="${TCL_BIN_DIR}/tclsh${TCL_MAJOR_VERSION}${TCL_MINOR_VERSION}${TCL_DBGX}t${EXEEXT}" - elif test -f "${TCL_BIN_DIR}/tclsh${TCL_MAJOR_VERSION}${TCL_MINOR_VERSION}${TCL_DBGX}st${EXEEXT}" ; then - TCLSH_PROG="${TCL_BIN_DIR}/tclsh${TCL_MAJOR_VERSION}${TCL_MINOR_VERSION}${TCL_DBGX}st${EXEEXT}" + if test -f "${TCL_BIN_DIR}/tclsh${TCL_MAJOR_VERSION}${TCL_MINOR_VERSION}${EXEEXT}" ; then + TCLSH_PROG="${TCL_BIN_DIR}/tclsh${TCL_MAJOR_VERSION}${TCL_MINOR_VERSION}${EXEEXT}" + elif test -f "${TCL_BIN_DIR}/tclsh${TCL_MAJOR_VERSION}${TCL_MINOR_VERSION}s${EXEEXT}" ; then + TCLSH_PROG="${TCL_BIN_DIR}/tclsh${TCL_MAJOR_VERSION}${TCL_MINOR_VERSION}s${EXEEXT}" + elif test -f "${TCL_BIN_DIR}/tclsh${TCL_MAJOR_VERSION}${TCL_MINOR_VERSION}t${EXEEXT}" ; then + TCLSH_PROG="${TCL_BIN_DIR}/tclsh${TCL_MAJOR_VERSION}${TCL_MINOR_VERSION}t${EXEEXT}" + elif test -f "${TCL_BIN_DIR}/tclsh${TCL_MAJOR_VERSION}${TCL_MINOR_VERSION}st${EXEEXT}" ; then + TCLSH_PROG="${TCL_BIN_DIR}/tclsh${TCL_MAJOR_VERSION}${TCL_MINOR_VERSION}st${EXEEXT}" fi else TCLSH_PROG="${TCL_BIN_DIR}/tclsh" fi else # tclConfig.sh is in install location if test "${TEA_PLATFORM}" = "windows"; then - TCLSH_PROG="tclsh${TCL_MAJOR_VERSION}${TCL_MINOR_VERSION}${TCL_DBGX}${EXEEXT}" + TCLSH_PROG="tclsh${TCL_MAJOR_VERSION}${TCL_MINOR_VERSION}${EXEEXT}" else - TCLSH_PROG="tclsh${TCL_MAJOR_VERSION}.${TCL_MINOR_VERSION}${TCL_DBGX}" + TCLSH_PROG="tclsh${TCL_MAJOR_VERSION}.${TCL_MINOR_VERSION}" fi list="`ls -d ${TCL_BIN_DIR}/../bin 2>/dev/null` \ `ls -d ${TCL_BIN_DIR}/.. 2>/dev/null` \ `ls -d ${TCL_PREFIX}/bin 2>/dev/null`" for i in $list ; do DELETED extensions/tnc/mkinstalldirs Index: extensions/tnc/mkinstalldirs ================================================================== --- extensions/tnc/mkinstalldirs +++ /dev/null @@ -1,40 +0,0 @@ -#! /bin/sh -# mkinstalldirs --- make directory hierarchy -# Author: Noah Friedman -# Created: 1993-05-16 -# Public domain - -# $Id$ - -errstatus=0 - -for file -do - set fnord `echo ":$file" | sed -ne 's/^:\//#/;s/^://;s/\// /g;s/^#/\//;p'` - shift - - pathcomp= - for d - do - pathcomp="$pathcomp$d" - case "$pathcomp" in - -* ) pathcomp=./$pathcomp ;; - esac - - if test ! -d "$pathcomp"; then - echo "mkdir $pathcomp" - - mkdir "$pathcomp" || lasterr=$? - - if test ! -d "$pathcomp"; then - errstatus=$lasterr - fi - fi - - pathcomp="$pathcomp/" - done -done - -exit $errstatus - -# mkinstalldirs ends here Index: extensions/tnc/tests/tnc.test ================================================================== --- extensions/tnc/tests/tnc.test +++ extensions/tnc/tests/tnc.test @@ -162,11 +162,11 @@ } } } test tnc-2.8 {Validate REC-xslt-19991116.xml} { - set ::tDOM::extRefHandlerDebug 1 + set ::tdom::extRefHandlerDebug 1 set parser [expat -externalentitycommand 2.8-resolver \ -paramentityparsing always] tnc $parser enable $parser parsefile [file join [file dir [info script]] \ ../../../tests/data/REC-xslt-19991116.xml] Index: generic/dom.c ================================================================== --- generic/dom.c +++ generic/dom.c @@ -1,11 +1,8 @@ /*--------------------------------------------------------------------------- | Copyright (C) 1999 Jochen C. Loewer (loewerj@hotmail.com) +---------------------------------------------------------------------------- -| -| $Id$ -| | | A DOM interface upon the expat XML parser for the C language | according to the W3C recommendation REC-DOM-Level-1-19981001 | | @@ -47,10 +44,11 @@ | \--------------------------------------------------------------------------*/ #include #include #include +#include #include /* #define DEBUG */ /*---------------------------------------------------------------------------- @@ -149,11 +147,13 @@ domActiveNS *activeNS; int baseURIstackSize; int baseURIstackPos; domActiveBaseURI *baseURIstack; int insideDTD; - StructureData *sdata; +#ifndef TDOM_NO_SCHEMA + SchemaData *sdata; +#endif int status; } domReadInfo; /*---------------------------------------------------------------------------- @@ -352,10 +352,63 @@ p += clen; else return 0; } return 1; } + +/*--------------------------------------------------------------------------- +| domClearString +| +\--------------------------------------------------------------------------*/ +char * +domClearString ( + char *str, + int *haveToFree + ) +{ + const char *p, *s; + char *p1, *clearedstr; + int clen, i, rewrite = 0; + + p = str; + while (*p) { + clen = UTF8_CHAR_LEN(*p); + if (clen > 4 || !UTF8_XMLCHAR((unsigned const char*)p,clen)) { + rewrite = 1; + break; + } + p += clen; + } + if (!rewrite) { + *haveToFree = 0; + return str; + } + s = p; + p += clen; + while (*p) p++; + clearedstr = MALLOC (sizeof(char) * (p-str)); + p1 = clearedstr; + while (str < s) { + *p1 = *str; + p1++; str++; + } + str += clen; + while (*str) { + clen = UTF8_CHAR_LEN(*str); + if (clen <= 4 && UTF8_XMLCHAR((unsigned const char*)str,clen)) { + for (i = 0; i < clen; i++) { + *p1 = *str; + p1++; str++; + } + } else { + str += clen; + } + } + *p1 = '\0'; + *haveToFree = 1; + return clearedstr; +} /*--------------------------------------------------------------------------- | domIsBMPChar | \--------------------------------------------------------------------------*/ @@ -1376,18 +1429,27 @@ attrNSfound: ; } } } +#ifndef TDOM_NO_SCHEMA if (info->sdata) { - if (probeElement (info->interp, info->sdata, node->nodeName, + if (tDOM_probeElement (info->interp, info->sdata, node->nodeName, node->namespace ? - info->document->namespaces[node->namespace-1]->uri : NULL) + info->document->namespaces[node->namespace-1]->uri + : NULL) != TCL_OK) { XML_StopParser(info->parser, 0); + } else { + if (tDOM_probeDomAttributes (info->interp, info->sdata, + node->firstAttr) + != TCL_OK) { + XML_StopParser(info->parser, 0); + } } } +#endif info->depth++; } /*--------------------------------------------------------------------------- | endElement @@ -1422,15 +1484,17 @@ if (info->depth) { if (info->baseURIstack[info->baseURIstackPos].depth == info->depth) { info->baseURIstackPos--; } } +#ifndef TDOM_NO_SCHEMA if (info->sdata) { - if (probeElementEnd (info->interp, info->sdata) != TCL_OK) { + if (tDOM_probeElementEnd (info->interp, info->sdata) != TCL_OK) { XML_StopParser(info->parser, 0); } } +#endif } /*--------------------------------------------------------------------------- | characterDataHandler | @@ -1491,14 +1555,22 @@ domTextNode *node; domNode *parentNode; domLineColumn *lc; Tcl_HashEntry *h; char *s; - int len, hnew; + int len, hnew, only_whites; len = Tcl_DStringLength (info->cdata); +#ifndef TDOM_NO_SCHEMA + if (!len && !info->cdataSection + && !(info->sdata + && info->sdata->stack + && info->sdata->stack->pattern->flags & CONSTRAINT_TEXT_CHILD)) + return; +#else if (!len && !info->cdataSection) return; +#endif s = Tcl_DStringValue (info->cdata); parentNode = info->currentNode; if (!parentNode) return; @@ -1510,15 +1582,16 @@ node = (domTextNode*)parentNode->lastChild; node->nodeValue = REALLOC(node->nodeValue, node->valueLength + len); memmove(node->nodeValue + node->valueLength, s, len); node->valueLength += len; + only_whites = 0; } else { if (info->ignoreWhiteSpaces) { char *pc; - int i, only_whites; + int i; only_whites = 1; for (i=0, pc = s; i < len; i++, pc++) { if ( (*pc != ' ') && (*pc != '\t') && @@ -1527,12 +1600,11 @@ only_whites = 0; break; } } if (only_whites) { - Tcl_DStringSetLength (info->cdata, 0); - return; + goto checkTextConstraints; } } if (info->storeLineColumn) { node = (domTextNode*) domAlloc(sizeof(domTextNode) @@ -1576,15 +1648,19 @@ node->nodeFlags |= HAS_LINE_COLUMN; lc->line = XML_GetCurrentLineNumber(info->parser); lc->column = XML_GetCurrentColumnNumber(info->parser); } } +checkTextConstraints: +#ifndef TDOM_NO_SCHEMA if (info->sdata) { - if (probeText (info->interp, info->sdata, s) != TCL_OK) { + if (tDOM_probeText (info->interp, info->sdata, s, &only_whites) + != TCL_OK) { XML_StopParser(info->parser, 0); } } +#endif Tcl_DStringSetLength (info->cdata, 0); } /*--------------------------------------------------------------------------- @@ -2109,11 +2185,13 @@ Tcl_Channel channel, const char *baseurl, Tcl_Obj *extResolver, int useForeignDTD, int paramEntityParsing, - StructureData *sdata, +#ifndef TDOM_NO_SCHEMA + SchemaData *sdata, +#endif Tcl_Interp *interp, int *resultcode ) { int done, tclLen; @@ -2156,11 +2234,13 @@ info.baseURIstackSize = INITIAL_BASEURISTACK_SIZE; info.baseURIstack = (domActiveBaseURI*) MALLOC (sizeof(domActiveBaseURI) * info.baseURIstackSize); info.insideDTD = 0; info.status = 0; +#ifndef TDOM_NO_SCHEMA info.sdata = sdata; +#endif XML_SetUserData(parser, &info); XML_SetBase (parser, baseurl); /* We must use XML_GetBase(), because XML_SetBase copies the baseURI, and we want to compare the pointers */ @@ -2309,12 +2389,12 @@ | \--------------------------------------------------------------------------*/ int domGetLineColumn ( domNode *node, - int *line, - int *column + long *line, + long *column ) { char *v; domLineColumn *lc; @@ -4567,21 +4647,15 @@ pinode->dataValue, pinode->dataLength); } if (node->nodeType != ELEMENT_NODE) { domTextNode *t1node, *tnode = (domTextNode*)node; - if (tnode->info) { - t1node = domNewTextNode(tnode->ownerDocument, - tnode->nodeValue, tnode->valueLength, - tnode->nodeType); - t1node->info = tnode->info; - return (domNode*) t1node; - } else { - return (domNode*) domNewTextNode(tnode->ownerDocument, - tnode->nodeValue, tnode->valueLength, - tnode->nodeType); - } + t1node = domNewTextNode(tnode->ownerDocument, tnode->nodeValue, + tnode->valueLength, tnode->nodeType); + t1node->info = tnode->info; + t1node->nodeFlags = tnode->nodeFlags; + return (domNode*) t1node; } n = domNewElementNode(node->ownerDocument, node->nodeName); n->namespace = node->namespace; n->info = node->info; @@ -4591,13 +4665,11 @@ \-----------------------------------------------------------------*/ attr = node->firstAttr; while (attr != NULL) { nattr = domSetAttribute (n, attr->nodeName, attr->nodeValue ); nattr->namespace = attr->namespace; - if (attr->nodeFlags & IS_NS_NODE) { - nattr->nodeFlags |= IS_NS_NODE; - } + nattr->nodeFlags = attr->nodeFlags; attr = attr->nextSibling; } if (deep) { child = node->firstChild; @@ -5147,21 +5219,23 @@ domActiveNS *activeNS; int baseURIstackSize; int baseURIstackPos; domActiveBaseURI *baseURIstack; int insideDTD; - StructureData *sdata; +#ifndef TDOM_NO_SCHEMA + SchemaData *sdata; +#endif /* Now the tdom cmd specific elements */ int tdomStatus; Tcl_Obj *extResolver; } tdomCmdReadInfo; -EXTERN int tcldom_returnDocumentObj (Tcl_Interp *interp, - domDocument *document, - int setVariable, Tcl_Obj *var_name, - int trace, int forOwnerDocument); +int tcldom_returnDocumentObj (Tcl_Interp *interp, + domDocument *document, + int setVariable, Tcl_Obj *var_name, + int trace, int forOwnerDocument); void tdom_freeProc ( Tcl_Interp *interp, void *userData @@ -5359,11 +5433,13 @@ info->baseURIstack = (domActiveBaseURI*) MALLOC (sizeof(domActiveBaseURI) * info->baseURIstackSize); info->insideDTD = 0; info->tdomStatus = 0; info->extResolver = NULL; +#ifndef TDOM_NO_SCHEMA info->sdata = NULL; +#endif handlerSet->userData = info; CHandlerSetInstall (interp, objv[1], handlerSet); break; Index: generic/dom.h ================================================================== --- generic/dom.h +++ generic/dom.h @@ -1,11 +1,8 @@ /*--------------------------------------------------------------------------- | Copyright (C) 1999 Jochen C. Loewer (loewerj@hotmail.com) +---------------------------------------------------------------------------- -| -| $Id$ -| | | A DOM interface upon the expat XML parser for the C language | according to the W3C recommendation REC-DOM-Level-1-19981001 | | @@ -40,11 +37,10 @@ #include #include #include #include #include -#include /* * tDOM provides it's own memory allocator which is optimized for * low heap usage. It uses the native Tcl allocator underneath, * though, but it is not very MT-friendly. Therefore, you might @@ -73,10 +69,11 @@ # define FREE free # define REALLOC realloc # define tdomstrdup strdup # endif /* TCL_MEM_DEBUG */ #endif /* USE_NORMAL_ALLOCATOR */ +#define TMALLOC(t) (t*)MALLOC(sizeof(t)) #if defined(TCL_MEM_DEBUG) || defined(NS_AOLSERVER) static void* my_malloc(size_t size){return Tcl_Alloc(size);} static void my_free(void *ptr){Tcl_Free((char*)ptr);} static void* my_realloc(void *ptr,size_t size){return Tcl_Realloc(ptr,size);} @@ -562,12 +559,12 @@ | domLineColumn | \-------------------------------------------------------------------------*/ typedef struct domLineColumn { - int line; - int column; + long line; + long column; } domLineColumn; /*-------------------------------------------------------------------------- @@ -701,10 +698,16 @@ | domAddCallback | \-------------------------------------------------------------------------*/ typedef int (*domAddCallback) (domNode * node, void * clientData); typedef void (*domFreeCallback) (domNode * node, void * clientData); + +/*-------------------------------------------------------------------------- +| Forward declaration +| +\-------------------------------------------------------------------------*/ +typedef struct SchemaData_ SchemaData; /*-------------------------------------------------------------------------- | Function prototypes | \-------------------------------------------------------------------------*/ @@ -729,11 +732,13 @@ Tcl_Channel channel, const char *baseurl, Tcl_Obj *extResolver, int useForeignDTD, int paramEntityParsing, - StructureData *sdata, +#ifndef TDOM_NO_SCHEMA + SchemaData *sdata, +#endif Tcl_Interp *interp, int *status); void domFreeDocument (domDocument *doc, domFreeCallback freeCB, @@ -805,11 +810,11 @@ char **prefixMappings); domNS * domLookupURI (domNode *node, char *uri); domNS * domGetNamespaceByIndex (domDocument *doc, int nsIndex); domNS * domNewNamespace (domDocument *doc, const char *prefix, const char *namespaceURI); -int domGetLineColumn (domNode *node, int *line, int *column); +int domGetLineColumn (domNode *node, long *line, long *column); int domXPointerChild (domNode * node, int all, int instance, domNodeType type, char *element, char *attrName, char *attrValue, int attrLen, domAddCallback addCallback, void * clientData); @@ -835,10 +840,11 @@ int domIsNAME (const char *name); int domIsPINAME (const char *name); int domIsQNAME (const char *name); int domIsNCNAME (const char *name); int domIsChar (const char *str); +char * domClearString (char *str, int *haveToFree); int domIsBMPChar (const char *str); int domIsComment (const char *str); int domIsCDATA (const char *str); int domIsPIValue (const char *str); void domCopyTo (domNode *node, domNode *parent, int copyNS); Index: generic/domalloc.c ================================================================== --- generic/domalloc.c +++ generic/domalloc.c @@ -1,11 +1,8 @@ /*--------------------------------------------------------------------------- | Copyright (C) 1999-2000 Jochen C. Loewer (loewerj@hotmail.com) +---------------------------------------------------------------------------- -| -| $Id$ -| | | A special memory allocator, which uses pre-allocated / bit masked | based administration of memory blocks with fixed sizes, like | DOM nodes. This will hopefully save some memory. | Index: generic/domalloc.h ================================================================== --- generic/domalloc.h +++ generic/domalloc.h @@ -1,11 +1,8 @@ /*--------------------------------------------------------------------------- | Copyright (C) 1999-2000 Jochen C. Loewer (loewerj@hotmail.com) +---------------------------------------------------------------------------- -| -| $Id$ -| | | A special memory allocator, which uses pre-allocated / bit masked | based administration of memory block with fixed sizes, like | DOM nodes. This will hopefully save some memory. | Index: generic/domlock.c ================================================================== --- generic/domlock.c +++ generic/domlock.c @@ -1,11 +1,9 @@ /*---------------------------------------------------------------------------- | Copyright (C) 1999 Jochen C. Loewer (loewerj@hotmail.com) +----------------------------------------------------------------------------- | -| $Id$ -| | The contents of this file are subject to the Mozilla Public License | Version 2.0 (the "License"); you may not use this file except in | compliance with the License. You may obtain a copy of the License at | http://www.mozilla.org/MPL/ | Index: generic/domxpath.c ================================================================== --- generic/domxpath.c +++ generic/domxpath.c @@ -1,11 +1,8 @@ /*---------------------------------------------------------------------------- | Copyright (c) 1999-2001 Jochen Loewer (loewerj@hotmail.com) |----------------------------------------------------------------------------- -| -| $Id$ -| | | A XPath implementation (lexer/parser/evaluator) for tDOM, | the DOM implementation for Tcl. | Based on November 16 1999 Recommendation of the W3C | (http://www.w3.org/TR/1999/REC-xslt-19991116) @@ -262,10 +259,32 @@ if (rs->type == StringResult) { if (rs->string) FREE((char*)rs->string); } rs->type = EmptyResult; } + +void +xpathRSReset ( + xpathResultSet *rs, + domNode *node + ) +{ + if (rs->type == StringResult) FREE(rs->string); + if (node) { + if (!rs->nodes) { + rs->nodes = (domNode**)MALLOC( INITIAL_SIZE*sizeof(domNode*)); + rs->allocated = INITIAL_SIZE; + } + rs->nodes[0] = node; + rs->nr_nodes = 1; + rs->type = xNodeSetResult; + } else { + rs->nr_nodes = 0; + if (rs->nodes) rs->type = xNodeSetResult; + else rs->type = EmptyResult; + } +} void rsPrint ( xpathResultSet *rs ) { int i = 0,l; char tmp[80]; switch (rs->type) { case EmptyResult: @@ -675,11 +694,11 @@ char **errMsg ) { int l, allocated; int i, k, start, offset; - char delim, *ps, save, tmpErr[80]; + char delim, *ps, save, tmpErr[80], *tailptr; const char *uri; XPathTokens tokens; int token = EOS; @@ -1109,12 +1128,18 @@ && ( tokens[l].intvalue == LONG_MAX || tokens[l].intvalue == LONG_MIN)) { token = REALNUMBER; } } - tokens[l].realvalue = (double)atof(ps); + tokens[l].realvalue = strtod(ps, &tailptr); xpath[i--] = save; + if (tokens[l].realvalue == 0.0 && tailptr == ps) { + sprintf (tmpErr, "Number value too large " + "at position %d", i); + *errMsg = tdomstrdup (tmpErr); + return tokens; + } } else { sprintf (tmpErr, "Unexpected character '%c' at " "position %d", xpath[i], i); *errMsg = tdomstrdup (tmpErr); return tokens; @@ -2282,11 +2307,11 @@ if (tokens != NULL) xpathFreeTokens (tokens); return XPATH_LEX_ERR; } DDBG( for (i=0; tokens[i].token != EOS; i++) { - fprintf(stderr, "%3d %-12s %5ld %8.3f %5d %s\n", + fprintf(stderr, "%3d %-12s %5ld %8.3g %5d %s\n", i, token2str[tokens[i].token-LPAR], tokens[i].intvalue, tokens[i].realvalue, tokens[i].pos, @@ -2315,11 +2340,11 @@ memmove(*errMsg + len, " for '", 6); memmove(*errMsg + len+6, xpath, newlen); memmove(*errMsg + len+6+newlen, "' ", 3); for (i=0; tokens[i].token != EOS; i++) { - sprintf(tmp, "%s\n%3s%3d %-12s %5ld %09.3f %5d ", + sprintf(tmp, "%s\n%3s%3d %-12s %5ld %09.3g %5d ", (i==0) ? "\n\nParsed symbols:" : "", (i==l) ? "-->" : " ", i, token2str[tokens[i].token-LPAR], tokens[i].intvalue, @@ -2716,11 +2741,11 @@ if (IS_NAN (rs->realvalue)) return tdomstrdup ("NaN"); else if (IS_INF (rs->realvalue)) { if (IS_INF (rs->realvalue) == 1) return tdomstrdup ("Infinity"); else return tdomstrdup ("-Infinity"); } - sprintf(tmp, "%f", rs->realvalue); + sprintf(tmp, "%g", rs->realvalue); /* strip trailing 0 and . */ len = strlen(tmp); for (; (len > 0) && (tmp[len-1] == '0'); len--) tmp[len-1] = '\0'; if ((len > 0) && (tmp[len-1] == '.')) tmp[len-1] = '\0'; return (tdomstrdup(tmp)); @@ -4455,11 +4480,18 @@ break; case Mod: if ((int)dRight == 0) { rsSetNaN (result); } else { - rsSetInt (result, ((int)dLeft) % ((int)dRight)); + if (dRight < LONG_MIN - 0.1 + || dRight > LONG_MAX + 0.1 + || dLeft < LONG_MIN - 0.1 + || dLeft > LONG_MAX + 0.1) { + rsSetNaN (result); + } else { + rsSetInt (result, ((long)dLeft) % ((long)dRight)); + } } break; default: break; } xpathRSFree (&rightResult); @@ -5224,10 +5256,72 @@ DBG(rsPrint( result );) return 0; } /* xpathEval */ + +int +xpathEvalAst ( + ast t, + xpathResultSet *nodeList, + domNode *node, + xpathCBs * cbs, + xpathResultSet *rs, + char **errMsg + ) +{ + int i, rc, first = 1, docOrder = 1; + xpathResultSet savedContext; + savedContext = *nodeList; + + while (t) { + DBG (fprintf (stderr, "xpathEvalAst: eval step '%s'\n", + astType2str[t->type]);) + if (t->type == Pred) { + *errMsg = "Pred step not expected now!"; + return XPATH_EVAL_ERR; + } + if (first) { + rc = xpathEvalStepAndPredicates (t, nodeList, node, + node, 0, &docOrder, + cbs, rs, errMsg); + CHECK_RC; + first = 0; + } else { + DBG( fprintf(stderr, "doing location step nodeList->nr_nodes=%d \n", + nodeList->nr_nodes); + ) + if (rs->type != xNodeSetResult) { + *nodeList = savedContext; + return 0; + } + + *nodeList = *rs; + xpathRSReset (rs, NULL); + for (i=0; i < nodeList->nr_nodes; i++) { + rc = xpathEvalStepAndPredicates (t, nodeList, + nodeList->nodes[i], + node, i, &docOrder, NULL, + rs, errMsg); + if (rc) { + *nodeList = savedContext; + return rc; + } + } + } + DBG( fprintf(stderr, "result after location step: \n"); ) + DBG( rsPrint( result); ) + + t = t->next; + /* skip the already processed Predicate parts */ + while (t && t->type == Pred) t = t->next; + docOrder = 1; + } + *nodeList = savedContext; + return 0; +} + /*---------------------------------------------------------------------------- | xpathMatches | \---------------------------------------------------------------------------*/ int xpathMatches ( Index: generic/domxpath.h ================================================================== --- generic/domxpath.h +++ generic/domxpath.h @@ -1,12 +1,9 @@ /*---------------------------------------------------------------------------- | Copyright (c) 1999 Jochen Loewer (loewerj@hotmail.com) |----------------------------------------------------------------------------- | -| $Id$ -| -| | A (partial) XPath implementation (lexer/parser/evaluator) for tDOM, | the DOM implementation for Tcl. | Based on the August 13 working draft of the W3C | (http://www.w3.org/1999/08/WD-xpath-19990813.html) | @@ -173,10 +170,12 @@ double xpathGetPrio (ast t); int xpathEval (domNode *node, domNode *exprContext, char *xpath, char **prefixMappings, xpathCBs *cbs, xpathParseVarCB *parseVarCB, Tcl_HashTable *catch, char **errMsg, xpathResultSet *rs); +int xpathEvalAst (ast t, xpathResultSet *nodeList, domNode *node, + xpathCBs *cbs, xpathResultSet *rs, char **errMsg); int xpathMatches (ast steps, domNode * exprContext, domNode *nodeToMatch, xpathCBs *cbs, char **errMsg ); int xpathEvalSteps (ast steps, xpathResultSet *nodeList, @@ -186,11 +185,12 @@ xpathResultSet *result, char **errMsg); #define xpathRSInit(x) (x)->type = EmptyResult; \ (x)->intvalue = 0; \ (x)->nr_nodes = 0; -void xpathRSFree (xpathResultSet *rs ); +void xpathRSFree (xpathResultSet *rs); +void xpathRSReset (xpathResultSet *rs, domNode *ode); int xpathFuncBoolean (xpathResultSet *rs); double xpathFuncNumber (xpathResultSet *rs, int *NaN); char * xpathFuncString (xpathResultSet *rs); char * xpathFuncStringForNode (domNode *node); @@ -208,8 +208,23 @@ void rsAddNodeFast ( xpathResultSet *rs, domNode *node ); void rsCopy ( xpathResultSet *to, xpathResultSet *from ); /* This function is only used for debugging code */ void rsPrint ( xpathResultSet *rs ); + +/* This function is used (outside of tcldom.c) only by schema.c. It + * has to have a prototype somewhere. */ +int tcldom_xpathFuncCallBack ( + void *clientData, + char *functionName, + domNode *ctxNode, + int position, + xpathResultSet *nodeList, + domNode *exprContext, + int argc, + xpathResultSets *args, + xpathResultSet *result, + char **errMsg + ); #endif Index: generic/domxslt.c ================================================================== --- generic/domxslt.c +++ generic/domxslt.c @@ -1,11 +1,8 @@ /*---------------------------------------------------------------------------- | Copyright (c) 2000 Jochen Loewer (loewerj@hotmail.com) |----------------------------------------------------------------------------- -| -| $Id$ -| | | A XSLT implementation for tDOM, according to the W3C | recommendation (16 Nov 1999). | See http://www.w3.org/TR/1999/REC-xslt-19991116 for details. | @@ -543,21 +540,21 @@ char ** errMsg) { Tcl_DString dStr; char buffer[1024]; const char *baseURI; - int line, column; + long line, column; Tcl_DStringInit (&dStr); baseURI = findBaseURI (node); if (baseURI) { Tcl_DStringAppend (&dStr, "In entity ", 10); Tcl_DStringAppend (&dStr, baseURI, -1); } if (node->nodeFlags & HAS_LINE_COLUMN) { domGetLineColumn (node, &line, &column); - sprintf (buffer, " at line %d, column %d:\n", line, column); + sprintf (buffer, " at line %ld, column %ld:\n", line, column); Tcl_DStringAppend (&dStr, buffer, -1); Tcl_DStringAppend (&dStr, str, -1); } else { if (baseURI) Tcl_DStringAppend (&dStr, ": ", 2); Tcl_DStringAppend (&dStr, str, -1); @@ -2860,11 +2857,11 @@ double precedence, char **errMsg ) { xsltTemplate *tpl, *t; - char *prioStr, *str, prefix[MAX_PREFIX_LEN]; + char *prioStr, *str, prefix[MAX_PREFIX_LEN], *tailptr; const char *localName; int rc, hnew; domNS *ns; Tcl_HashEntry *h; Tcl_DString dStr; @@ -2968,12 +2965,20 @@ tpl->precedence = precedence; tpl->next = NULL; prioStr = getAttr(node,"priority", a_prio); if (prioStr) { - tpl->prio = (double)atof(prioStr); - } + tpl->prio = strtod (prioStr, &tailptr); + if (tpl->prio == 0.0 && prioStr == tailptr) { + /* If the template has a name attribute, it is already stored in + in the namedTemplates hash table and will be freed. */ + if (!tpl->name) { + FREE ((char*)tpl); + } + return -1; + } + } sDoc = xs->subDocs; while (sDoc) { if (sDoc->doc == node->ownerDocument) break; sDoc = sDoc->next; @@ -5785,11 +5790,14 @@ } /* keep white space, no fiddling with the encoding (is this a good idea?) */ doc = domReadDocument (parser, xmlstring, len, 0, 0, storeLineColumn, 0, 0, NULL, chan, extbase, extResolver, 0, - (int) XML_PARAM_ENTITY_PARSING_ALWAYS, NULL, + (int) XML_PARAM_ENTITY_PARSING_ALWAYS, +#ifndef TDOM_NO_SCHEMA + NULL, +#endif interp, &resultcode); if (xsltDoc->extResolver) { Tcl_DecrRefCount (extResolver); } if (doc == NULL) { Index: generic/domxslt.h ================================================================== --- generic/domxslt.h +++ generic/domxslt.h @@ -1,13 +1,10 @@ /*---------------------------------------------------------------------------- | Copyright (c) 2000 Jochen Loewer (loewerj@hotmail.com) |----------------------------------------------------------------------------- | -| $Id$ -| -| -| A (partial) XSLT implementation for tDOM, according to the W3C +| A XSLT implementation for tDOM, according to the W3C | recommendation (16 Nov 1999, | http://www.w3.org/TR/1999/REC-xslt-19991116). | | | The contents of this file are subject to the Mozilla Public License Index: generic/nodecmd.c ================================================================== --- generic/nodecmd.c +++ generic/nodecmd.c @@ -1,11 +1,9 @@ /*---------------------------------------------------------------------------- | Copyright (C) 1999 Jochen C. Loewer (loewerj@hotmail.com) +----------------------------------------------------------------------------- | -| Rcsid: @(#)$Id$ -| | The contents of this file are subject to the Mozilla Public License | Version 2.0 (the "License"); you may not use this file except in | compliance with the License. You may obtain a copy of the License at | http://www.mozilla.org/MPL/ | Index: generic/nodecmd.h ================================================================== --- generic/nodecmd.h +++ generic/nodecmd.h @@ -1,11 +1,9 @@ /*---------------------------------------------------------------------------- | Copyright (C) 1999 Jochen C. Loewer (loewerj@hotmail.com) +----------------------------------------------------------------------------- | -| $Id$ - | The contents of this file are subject to the Mozilla Public License | Version 2.0 (the "License"); you may not use this file except in | compliance with the License. You may obtain a copy of the License at | http://www.mozilla.org/MPL/ | ADDED generic/schema.c Index: generic/schema.c ================================================================== --- /dev/null +++ generic/schema.c @@ -0,0 +1,8719 @@ +/*---------------------------------------------------------------------------- +| Copyright (c) 2018, 2019 Rolf Ade (rolf@pointsman.de) +|----------------------------------------------------------------------------- +| +| +| The contents of this file are subject to the Mozilla Public License +| Version 2.0 (the "License"); you may not use this file except in +| compliance with the License. You may obtain a copy of the License at +| http://www.mozilla.org/MPL/ +| +| Software distributed under the License is distributed on an "AS IS" +| basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the +| License for the specific language governing rights and limitations +| under the License. +| +| Contributor(s): +| +| +| written by Rolf Ade +| 2018-2020 +| +\---------------------------------------------------------------------------*/ + +#ifndef TDOM_NO_SCHEMA + +#include +#include +#include +#include +#include +#include + +#ifdef _MSC_VER +#include +#else +#include +#endif + +/* #define DEBUG */ +/* #define DDEBUG */ +/*---------------------------------------------------------------------------- +| Debug Macros +| +\---------------------------------------------------------------------------*/ +#ifdef DEBUG +# define DBG(x) x +#else +# define DBG(x) +#endif +#if defined(DEBUG) || defined(DDEBUG) +# define DDBG(x) x +#else +# define DDBG(x) +#endif + + +/*---------------------------------------------------------------------------- +| Choice/attribute handling method threshold +| +\---------------------------------------------------------------------------*/ +#ifndef TDOM_CHOICE_HASH_THRESHOLD +# define TDOM_CHOICE_HASH_THRESHOLD 5 +#endif +#ifndef TDOM_ATTRIBUTE_HASH_THRESHOLD +# define TDOM_ATTRIBUTE_HASH_THRESHOLD 5 +#endif +#ifndef TDOM_EXPAT_READ_SIZE +# define TDOM_EXPAT_READ_SIZE (1024*8) +#endif + +/*---------------------------------------------------------------------------- +| Initial buffer sizes +| +\---------------------------------------------------------------------------*/ +#ifndef CONTENT_ARRAY_SIZE_INIT +# define CONTENT_ARRAY_SIZE_INIT 20 +#endif +#ifndef ANON_PATTERN_ARRAY_SIZE_INIT +# define ANON_PATTERN_ARRAY_SIZE_INIT 256 +#endif +#ifndef URI_BUFFER_LEN_INIT +# define URI_BUFFER_LEN_INIT 128 +#endif +#ifndef ATTR_ARRAY_INIT +# define ATTR_ARRAY_INIT 4 +#endif +#ifndef WHITESPACETC_BUFFER_LEN_INIT +# define WHITESPACETC_BUFFER_LEN_INIT 200 +#endif + +/*---------------------------------------------------------------------------- +| Local defines +| +\---------------------------------------------------------------------------*/ +#ifndef O_BINARY +# ifdef _O_BINARY +# define O_BINARY _O_BINARY +# else +# define O_BINARY 0 +# endif +#endif +#if !defined(PTR2UINT) +# if defined(HAVE_UINTPTR_T) || defined(uintptr_t) +# define PTR2UINT(p) ((unsigned int)(uintptr_t)(p)) +# else +# define PTR2UINT(p) ((unsigned int)(p)) +# endif +#endif +#if !defined(UINT2PTR) +# if defined(HAVE_UINTPTR_T) || defined(uintptr_t) +# define UINT2PTR(p) ((void *)(uintptr_t)(p)) +# else +# define UINT2PTR(p) ((void *)(p)) +# endif +#endif +#ifndef TCL_MATCH_NOCASE +# define TCL_MATCH_NOCASE 1 +#endif + +/*---------------------------------------------------------------------------- +| Local typedefs +| +\---------------------------------------------------------------------------*/ + +typedef struct +{ + SchemaData *sdata; + Tcl_Interp *interp; + XML_Parser parser; + Tcl_DString *cdata; + int onlyWhiteSpace; + char *uri; + int maxUriLen; +} ValidateMethodData; + +typedef enum { + MATCH_GLOBAL = 1, + MATCH_ELEMENT_START, + MATCH_ELEMENT_END, + MATCH_TEXT, + MATCH_ATTRIBUTE_TEXT, + MATCH_DOM_KEYCONSTRAINT, + MATCH_DOM_XPATH_BOOLEAN +} ValidationAction; + +static char *ValidationAction2str[] = { + "NOT_USED", + "MATCH_GLOBAL", + "MATCH_ELEMENT_START", + "MATCH_ELEMENT_END", + "MATCH_TEXT", + "MATCH_ATTRIBUTE_TEXT", + "MATCH_DOM_KEYCONSTRAINT", + "MATCH_DOM_XPATH_BOOLEAN" +}; + +typedef enum { + DOM_KEYCONSTRAINT, + DOM_XPATH_BOOLEAN, + MISSING_ATTRIBUTE, + MISSING_ELEMENT_MATCH_START, + MISSING_ELEMENT_MATCH_END, + UNEXPECTED_TEXT, + MISSING_TEXT_MATCH_START, + MISSING_TEXT_MATCH_END, + UNEXPECTED_ROOT_ELEMENT, + UNEXPECTED_ELEMENT, + UNKNOWN_ATTRIBUTE, + INVALID_KEYREF_MATCH_START, + INVALID_KEYREF_MATCH_END, + INVALID_KEYREF_MATCH_TEXT, + UNKNOWN_ROOT_ELEMENT, + UNKOWN_GLOBAL_ID, + UNKOWN_ID, + INVALID_ATTRIBUTE_VALUE, + INVALID_VALUE +} ValidationErrorType; + +static char *ValidationErrorType2str[] = { + "DOM_KEYCONSTRAINT", + "DOM_XPATH_BOOLEAN", + "MISSING_ATTRIBUTE", + "MISSING_ELEMENT", + "MISSING_ELEMENT", + "UNEXPECTED_TEXT", + "MISSING_TEXT", + "MISSING_TEXT", + "UNEXPECTED_ROOT_ELEMENT", + "UNEXPECTED_ELEMENT", + "UNKNOWN_ATTRIBUTE", + "INVALID_KEYREF", + "INVALID_KEYREF", + "INVALID_KEYREF", + "UNKNOWN_ROOT_ELEMENT", + "UNKOWN_GLOBAL_ID", + "UNKOWN_ID", + "INVALID_ATTRIBUTE_VALUE", + "INVALID_VALUE" +}; + +/*---------------------------------------------------------------------------- +| Recovering related flage +| +\---------------------------------------------------------------------------*/ + +#define RECOVER_FLAG_REWIND 1 +#define RECOVER_FLAG_DONT_REPORT 2 +#define RECOVER_FLAG_IGNORE 4 +#define RECOVER_FLAG_MATCH_END_CONTINUE 8 + +/*---------------------------------------------------------------------------- +| [schemacmd info expected] related flags +| +\---------------------------------------------------------------------------*/ + +#define EXPECTED_IGNORE_MATCHED 1 +#define EXPECTED_ONLY_MANDATORY 2 +#define EXPECTED_PROBE_MAYSKIP 4 + +/*---------------------------------------------------------------------------- +| domKeyConstraint related flage +| +\---------------------------------------------------------------------------*/ + +#define DKC_FLAG_IGNORE_EMPTY_FIELD_SET 1 +#define DKC_FLAG_BOOLEAN 2 + +/*---------------------------------------------------------------------------- +| Macros +| +\---------------------------------------------------------------------------*/ +#define SetResult(str) Tcl_ResetResult(interp); \ + Tcl_SetStringObj(Tcl_GetObjResult(interp), (str), -1) +#define SetResultV(str) if (!sdata->evalError) { \ + Tcl_ResetResult(interp); \ + Tcl_SetStringObj(Tcl_GetObjResult(interp), (str), -1); \ + } +#define SetResult3(str1,str2,str3) Tcl_ResetResult(interp); \ + Tcl_AppendResult(interp, (str1), (str2), (str3), NULL) +#define SetResult3V(str1,str2,str3) if (!sdata->evalError) { \ + Tcl_ResetResult(interp); \ + Tcl_AppendResult(interp, (str1), (str2), (str3), NULL); \ + } +#define SetIntResult(i) Tcl_ResetResult(interp); \ + Tcl_SetIntObj(Tcl_GetObjResult(interp), (i)) +#define SetLongResult(i) Tcl_ResetResult(interp); \ + Tcl_SetLongObj(Tcl_GetObjResult(interp), (i)) +#define SetBooleanResult(i) Tcl_ResetResult(interp); \ + Tcl_SetBooleanObj(Tcl_GetObjResult(interp), (i)) + +#define SPACE(c) IS_XML_WHITESPACE ((c)) + +#define checkNrArgs(l,h,err) if (objc < l || objc > h) { \ + SetResult (err); \ + return TCL_ERROR; \ + } + +#if defined(DEBUG) || defined(DDEBUG) +static char *Schema_CP_Type2str[] = { + "ANY", + "NAME", + "CHOICE", + "INTERLEAVE", + "PATTERN", + "TEXT", + "VIRTUAL", + "KEYSPACE_START", + "KEYSPACE_END" +}; +static char *Schema_Quant_Type2str[] = { + "ONE", + "OPT", + "REP", + "PLUS", + "NM", + "ERROR" +}; +#endif + + +#ifndef TCL_THREADS + static SchemaData *activeSchemaData = 0; +# define GETASI activeSchemaData +# define SETASI(v) activeSchemaData = v +#else + static Tcl_ThreadDataKey activeSchemaData; +# define GETASI *(SchemaData**) Tcl_GetThreadData(&activeSchemaData, \ + sizeof(SchemaData*)) +static void SetActiveSchemaData (SchemaData *v) +{ + SchemaData **schemaInfoPtr = Tcl_GetThreadData(&activeSchemaData, + sizeof (SchemaData*)); + *schemaInfoPtr = v; +} +# define SETASI(v) SetActiveSchemaData (v) +#endif + +#define CHECK_SI \ + if (!sdata) { \ + SetResult ("Command called outside of schema context"); \ + return TCL_ERROR; \ + } \ + if (sdata->isTextConstraint) { \ + SetResult ("Command called in invalid schema context"); \ + return TCL_ERROR; \ + } + +#define CHECK_TI \ + if (!sdata) { \ + SetResult ("Command called outside of schema context"); \ + return TCL_ERROR; \ + } \ + if (!sdata->isTextConstraint) { \ + SetResult ("Command called in invalid schema context"); \ + return TCL_ERROR; \ + } + +#define CHECK_TOPLEVEL \ + if (sdata->defineToplevel) { \ + SetResult("Command not allowed at top level " \ + "in schema define evaluation"); \ + return TCL_ERROR; \ + } + +#define CHECK_RECURSIVE_CALL \ + if (clientData != NULL) { \ + savedsdata = GETASI; \ + if (savedsdata == sdata) { \ + SetResult ("This recursive call is not allowed"); \ + return TCL_ERROR; \ + } \ + } else if (!sdata->defineToplevel) { \ + SetResult ("Command only allowed at lop level"); \ + return TCL_ERROR; \ + } + +#define CHECK_EVAL \ + if (sdata->currentEvals) { \ + SetResult ("This method is not allowed in nested evaluation"); \ + return TCL_ERROR; \ + } + +#define CHECK_REWIND \ + if (sdata->recoverFlags & RECOVER_FLAG_REWIND) { \ + rewindStack (sdata); \ + sdata->recoverFlags &= ~RECOVER_FLAG_REWIND; \ + } \ + +#define REMEMBER_PATTERN(pattern) \ + if (sdata->numPatternList == sdata->patternListSize) { \ + sdata->patternList = (SchemaCP **) REALLOC ( \ + sdata->patternList, \ + sizeof (SchemaCP*) * sdata->patternListSize * 2); \ + sdata->patternListSize *= 2; \ + } \ + sdata->patternList[sdata->numPatternList] = pattern; \ + sdata->numPatternList++; + + +#define ADD_CONSTRAINT(sdata, sc) \ + sc = TMALLOC (SchemaConstraint); \ + memset (sc, 0, sizeof (SchemaConstraint)); \ + if (sdata->cp->nc == sdata->contentSize) { \ + sdata->cp->content = \ + REALLOC (sdata->cp->content, \ + 2 * sdata->contentSize \ + * sizeof (SchemaCP*)); \ + sdata->cp->quants = \ + REALLOC (sdata->cp->quants, \ + 2 * sdata->contentSize \ + * sizeof (SchemaQuant)); \ + sdata->contentSize *= 2; \ + } \ + sdata->cp->content[sdata->cp->nc] = (SchemaCP *) sc; \ + sdata->cp->quants[sdata->cp->nc] = SCHEMA_CQUANT_ONE; \ + sdata->cp->nc++; \ + +#define maxOne(quant) \ + ((quant) == SCHEMA_CQUANT_ONE || (quant) == SCHEMA_CQUANT_OPT) ? 1 : 0 + +#define minOne(quant) \ + ((quant) == SCHEMA_CQUANT_ONE || (quant) == SCHEMA_CQUANT_PLUS) ? 1 : 0 + +#define mayRepeat(quant) \ + ((quant) == SCHEMA_CQUANT_REP || (quant) == SCHEMA_CQUANT_PLUS) ? 1 : 0 + +#define mayMiss(quant) \ + ((quant) == SCHEMA_CQUANT_REP || (quant) == SCHEMA_CQUANT_OPT) ? 1 : 0 + +#define hasMatched(quant,hm) \ + (hm) == 0 ? mayMiss(quant) : 1 + +#define mustMatch(quant,hm) \ + (hm) == 0 ? minOne(quant) : 0 + + +#define getContext(cp, ac, hm) \ + cp = se->pattern; \ + ac = se->activeChild; \ + hm = se->hasMatched; \ + if (hm && maxOne (cp->quants[ac])) { \ + ac += + 1; \ + hm = 0; \ + } \ + + +#define updateStack(sdata,se,ac) \ + if (!(sdata->recoverFlags & RECOVER_FLAG_REWIND)) { \ + se->activeChild = ac; \ + se->hasMatched = 1; \ + } \ + + +#ifndef TCL_THREADS +SchemaData * +tdomGetSchemadata (Tcl_Interp *interp) +{ + return activeSchemaData; +} +#else +SchemaData * +tdomGetSchemadata (void) +{ + return GETASI; +} +#endif + +static SchemaCP* +initSchemaCP ( + Schema_CP_Type type, + void *namespace, + char *name + ) +{ + SchemaCP *pattern; + + pattern = TMALLOC (SchemaCP); + memset (pattern, 0, sizeof(SchemaCP)); + pattern->type = type; + switch (type) { + case SCHEMA_CTYPE_NAME: + pattern->flags |= CONSTRAINT_TEXT_CHILD; + /* Fall thru. */ + case SCHEMA_CTYPE_PATTERN: + pattern->namespace = (char *)namespace; + pattern->name = name; + /* Fall thru. */ + case SCHEMA_CTYPE_CHOICE: + case SCHEMA_CTYPE_INTERLEAVE: + pattern->content = (SchemaCP**) MALLOC ( + sizeof(SchemaCP*) * CONTENT_ARRAY_SIZE_INIT + ); + pattern->quants = (SchemaQuant*) MALLOC ( + sizeof (SchemaQuant) * CONTENT_ARRAY_SIZE_INIT + ); + break; + case SCHEMA_CTYPE_TEXT: + /* content/quant will be allocated, if the cp in fact has + * constraints */ + break; + case SCHEMA_CTYPE_KEYSPACE_END: + case SCHEMA_CTYPE_KEYSPACE: + pattern->name = name; + break; + case SCHEMA_CTYPE_ANY: + pattern->namespace = namespace; + break; + case SCHEMA_CTYPE_VIRTUAL: + /* Do nothing */ + break; + } + return pattern; +} + +DDBG( +static void serializeCP ( + SchemaCP *pattern + ) +{ + fprintf (stderr, "CP %p type: %s\n", + pattern, Schema_CP_Type2str[pattern->type]); + switch (pattern->type) { + case SCHEMA_CTYPE_KEYSPACE_END: + case SCHEMA_CTYPE_KEYSPACE: + fprintf (stderr, "\tName: '%s'\n", pattern->name); + break; + case SCHEMA_CTYPE_NAME: + case SCHEMA_CTYPE_PATTERN: + fprintf (stderr, "\tName: '%s' Namespace: '%s'\n", + pattern->name, pattern->namespace); + if (pattern->flags & FORWARD_PATTERN_DEF) { + fprintf (stderr, "\tAnonymously defined NAME\n"); + } + if (pattern->flags & PLACEHOLDER_PATTERN_DEF) { + fprintf (stderr, "\tAs placeholder defined NAME\n"); + } + if (pattern->flags & LOCAL_DEFINED_ELEMENT) { + fprintf (stderr, "\tLocal defined NAME\n"); + } + if (pattern->flags & ELEMENTTYPE_DEF) { + fprintf (stderr, "\tElementtype '%s'\n", pattern->typeName); + } + /* Fall thru. */ + case SCHEMA_CTYPE_CHOICE: + case SCHEMA_CTYPE_INTERLEAVE: + fprintf (stderr, "\t%d childs\n", pattern->nc); + break; + case SCHEMA_CTYPE_ANY: + if (pattern->namespace) { + fprintf (stderr, "\tNamespace: '%s'\n", + pattern->namespace); + } + break; + case SCHEMA_CTYPE_TEXT: + case SCHEMA_CTYPE_VIRTUAL: + /* Do nothing */ + break; + } +} + +static void serializeQuant ( + SchemaQuant quant + ) +{ + fprintf (stderr, "Quant type: %s\n", + Schema_Quant_Type2str[quant]); +} + +static int getDeep ( + SchemaValidationStack *se + ) +{ + int i = 0; + while (se) { + if (se->pattern->type == SCHEMA_CTYPE_NAME) i++; + se = se->down; + } + return i; +} + +static void serializeStack ( + SchemaData *sdata + ) +{ + SchemaValidationStack *se; + + fprintf (stderr, "++++ Current validation stack:\n"); + se = sdata->stack; + while (se) { + serializeCP (se->pattern); + fprintf (stderr, "\tdeep: %d ac: %d hm: %d\n", + getDeep (se), se->activeChild, se->hasMatched); + se = se->down; + } + fprintf (stderr, "++++ Stack bottom\n"); +} +) + +/* DBG end */ + + +static void freedomKeyConstraints ( + domKeyConstraint *kc + ) +{ + domKeyConstraint *knext; + int i; + + while (kc) { + knext = kc->next; + if (kc->name) FREE (kc->name); + if (kc->emptyFieldSetValue) FREE (kc->emptyFieldSetValue); + xpathFreeAst (kc->selector); + for (i = 0; i < kc->nrFields; i++) { + xpathFreeAst (kc->fields[i]); + } + FREE (kc->fields); + FREE (kc); + kc = knext; + } +} + +static void freeSchemaCP ( + SchemaCP *pattern + ) +{ + int i; + SchemaConstraint *sc; + + switch (pattern->type) { + case SCHEMA_CTYPE_ANY: + /* do nothing */ + break; + case SCHEMA_CTYPE_VIRTUAL: + for (i = 0; i < pattern->nc; i++) { + Tcl_DecrRefCount ((Tcl_Obj *)pattern->content[i]); + } + FREE (pattern->content); + break; + case SCHEMA_CTYPE_TEXT: + for (i = 0; i < pattern->nc; i++) { + sc = (SchemaConstraint *) pattern->content[i]; + if (sc->freeData) { + (sc->freeData) (sc->constraintData); + } + FREE (pattern->content[i]); + } + /* Fall throu */ + default: + FREE (pattern->content); + FREE (pattern->quants); + if (pattern->attrs) { + for (i = 0; i < pattern->numAttr; i++) { + FREE (pattern->attrs[i]); + } + FREE (pattern->attrs); + } + freedomKeyConstraints (pattern->domKeys); + if (pattern->typedata) { + Tcl_DeleteHashTable ((Tcl_HashTable *) pattern->typedata); + FREE (pattern->typedata); + } + break; + } + if (pattern->defScript) { + Tcl_DecrRefCount (pattern->defScript); + } + if (pattern->associated) { + Tcl_DecrRefCount (pattern->associated); + } + FREE (pattern); +} + +static SchemaData* +initSchemaData ( + Tcl_Obj *cmdNameObj) +{ + SchemaData *sdata; + int hnew, len; + char *name; + + sdata = TMALLOC (SchemaData); + memset (sdata, 0, sizeof(SchemaData)); + name = Tcl_GetStringFromObj (cmdNameObj, &len); + sdata->self = Tcl_NewStringObj (name, len); + Tcl_IncrRefCount (sdata->self); + Tcl_InitHashTable (&sdata->element, TCL_STRING_KEYS); + Tcl_InitHashTable (&sdata->elementType, TCL_STRING_KEYS); + Tcl_InitHashTable (&sdata->prefix, TCL_STRING_KEYS); + Tcl_InitHashTable (&sdata->pattern, TCL_STRING_KEYS); + Tcl_InitHashTable (&sdata->attrNames, TCL_STRING_KEYS); + Tcl_InitHashTable (&sdata->namespace, TCL_STRING_KEYS); + Tcl_InitHashTable (&sdata->textDef, TCL_STRING_KEYS); + sdata->emptyNamespace = Tcl_CreateHashEntry ( + &sdata->namespace, "", &hnew); + sdata->patternList = (SchemaCP **) MALLOC ( + sizeof (SchemaCP*) * ANON_PATTERN_ARRAY_SIZE_INIT); + sdata->patternListSize = ANON_PATTERN_ARRAY_SIZE_INIT; + /* evalStub initialization */ + sdata->evalStub = (Tcl_Obj **) MALLOC (sizeof (Tcl_Obj*) * 4); + sdata->evalStub[0] = Tcl_NewStringObj("::namespace", 11); + Tcl_IncrRefCount (sdata->evalStub[0]); + sdata->evalStub[1] = Tcl_NewStringObj("eval", 4); + Tcl_IncrRefCount (sdata->evalStub[1]); + sdata->evalStub[2] = Tcl_NewStringObj("::tdom::schema", 14); + Tcl_IncrRefCount (sdata->evalStub[2]); + /* textStub initialization */ + sdata->textStub = (Tcl_Obj **) MALLOC (sizeof (Tcl_Obj*) * 4); + sdata->textStub[0] = Tcl_NewStringObj("::namespace", 11); + Tcl_IncrRefCount (sdata->textStub[0]); + sdata->textStub[1] = Tcl_NewStringObj("eval", 4); + Tcl_IncrRefCount (sdata->textStub[1]); + sdata->textStub[2] = Tcl_NewStringObj("::tdom::schema::text", 20); + Tcl_IncrRefCount (sdata->textStub[2]); + sdata->cdata = TMALLOC (Tcl_DString); + Tcl_DStringInit (sdata->cdata); + Tcl_InitHashTable (&sdata->ids, TCL_STRING_KEYS); + sdata->unknownIDrefs = 0; + Tcl_InitHashTable (&sdata->idTables, TCL_STRING_KEYS); + Tcl_InitHashTable (&sdata->keySpaces, TCL_STRING_KEYS); + sdata->choiceHashThreshold = TDOM_CHOICE_HASH_THRESHOLD; + sdata->attributeHashThreshold = TDOM_ATTRIBUTE_HASH_THRESHOLD; + return sdata; +} + +static void schemaInstanceDelete ( + ClientData clientData + ) +{ + SchemaData *sdata = (SchemaData *) clientData; + unsigned int i; + SchemaValidationStack *down; + Tcl_HashEntry *h; + Tcl_HashSearch search; + SchemaDocKey *dk; + SchemaKeySpace *ks; + + /* Protect the clientData to be freed inside (even nested) + * Tcl_Eval*() calls to avoid invalid mem access and postpone the + * cleanup until the Tcl_Eval*() calls are finished (done in + * tDOM_schemaInstanceCmd()). */ + if (sdata->currentEvals || sdata->inuse > 0) { + sdata->cleanupAfterUse = 1; + return; + } + Tcl_DecrRefCount (sdata->self); + if (sdata->start) FREE (sdata->start); + if (sdata->prefixns) { + i = 0; + while (sdata->prefixns[i]) { + FREE (sdata->prefixns[i]); + i++; + } + FREE (sdata->prefixns); + } + Tcl_DeleteHashTable (&sdata->namespace); + Tcl_DeleteHashTable (&sdata->element); + Tcl_DeleteHashTable (&sdata->elementType); + Tcl_DeleteHashTable (&sdata->prefix); + Tcl_DeleteHashTable (&sdata->pattern); + Tcl_DeleteHashTable (&sdata->attrNames); + Tcl_DeleteHashTable (&sdata->textDef); + for (i = 0; i < sdata->numPatternList; i++) { + freeSchemaCP (sdata->patternList[i]); + } + FREE (sdata->patternList); + FREE (sdata->quants); + while (sdata->stack) { + down = sdata->stack->down; + if (sdata->stack->interleaveState) + FREE (sdata->stack->interleaveState); + FREE (sdata->stack); + sdata->stack = down; + } + while (sdata->lastMatchse) { + down = sdata->lastMatchse->down; + if (sdata->lastMatchse->interleaveState) + FREE (sdata->lastMatchse->interleaveState); + FREE (sdata->lastMatchse); + sdata->lastMatchse = down; + } + while (sdata->stackPool) { + down = sdata->stackPool->down; + /* interleaveState always got cleand up at puting se back to + * pool */ + FREE (sdata->stackPool); + sdata->stackPool = down; + } + Tcl_DecrRefCount (sdata->evalStub[0]); + Tcl_DecrRefCount (sdata->evalStub[1]); + Tcl_DecrRefCount (sdata->evalStub[2]); + FREE (sdata->evalStub); + Tcl_DecrRefCount (sdata->textStub[0]); + Tcl_DecrRefCount (sdata->textStub[1]); + Tcl_DecrRefCount (sdata->textStub[2]); + FREE (sdata->textStub); + Tcl_DStringFree (sdata->cdata); + FREE (sdata->cdata); + if (sdata->reportCmd) { + Tcl_DecrRefCount (sdata->reportCmd); + } + Tcl_DeleteHashTable (&sdata->ids); + for (h = Tcl_FirstHashEntry (&sdata->idTables, &search); + h != NULL; + h = Tcl_NextHashEntry (&search)) { + dk = Tcl_GetHashValue (h); + Tcl_DeleteHashTable (&dk->ids); + FREE (dk); + } + Tcl_DeleteHashTable (&sdata->idTables); + for (h = Tcl_FirstHashEntry (&sdata->keySpaces, &search); + h != NULL; + h = Tcl_NextHashEntry (&search)) { + ks = Tcl_GetHashValue (h); + if (ks->active) { + Tcl_DeleteHashTable (&ks->ids); + } + FREE (ks); + } + Tcl_DeleteHashTable (&sdata->keySpaces); + if (sdata->wsbufLen) { + FREE (sdata->wsbuf); + } + FREE (sdata); +} + +static void +cleanupLastPattern ( + SchemaData *sdata, + unsigned int from + ) +{ + unsigned int i; + char *name; + Tcl_HashTable *hashTable; + Tcl_HashEntry *h; + + SchemaCP *this, *previous, *current; + + for (i = from; i < sdata->numPatternList; i++) { + this = sdata->patternList[i]; + hashTable = NULL; + name = NULL; + if (this->type == SCHEMA_CTYPE_NAME) { + /* Local defined elements aren't saved under their local + * name bucket in the sdata->element hash table. */ + if (this->flags & LOCAL_DEFINED_ELEMENT) { + freeSchemaCP (sdata->patternList[i]); + continue; + } + if (this->flags & ELEMENTTYPE_DEF) { + hashTable = &sdata->elementType; + name = this->typeName; + } else { + hashTable = &sdata->element; + name = this->name; + } + } + if (this->type == SCHEMA_CTYPE_PATTERN) { + hashTable = &sdata->pattern; + name = this->name; + } + if (name && hashTable) { + if (this->flags & FORWARD_PATTERN_DEF) { + sdata->forwardPatternDefs--; + } + h = Tcl_FindHashEntry (hashTable, name); + previous = NULL; + current = Tcl_GetHashValue (h); + while (current != NULL && current != this) { + previous = current; + current = current->next; + } + if (previous) { + if (current->next) { + previous->next = current->next; + } else { + previous->next = NULL; + } + } else { + if (current && current->next) { + Tcl_SetHashValue (h, current->next); + } else { + Tcl_DeleteHashEntry (h); + } + } + } + freeSchemaCP (sdata->patternList[i]); + } + sdata->numPatternList = from; +} + +static void +addToContent ( + SchemaData *sdata, + SchemaCP *pattern, + SchemaQuant quant, + int n, + int m + ) +{ + SchemaCP *wrapperCP; + SchemaCP *savedCP = NULL; + unsigned int savedContenSize; + + if (sdata->cp->type == SCHEMA_CTYPE_NAME + && sdata->cp->flags & CONSTRAINT_TEXT_CHILD + && (pattern->type != SCHEMA_CTYPE_TEXT + || pattern->nc == 0)) { + sdata->cp->flags &= ~CONSTRAINT_TEXT_CHILD; + } + if (sdata->cp->type == SCHEMA_CTYPE_CHOICE + || sdata->cp->type == SCHEMA_CTYPE_INTERLEAVE) { + if (pattern->type == SCHEMA_CTYPE_CHOICE) { + if (pattern->flags & MIXED_CONTENT) { + sdata->cp->flags |= MIXED_CONTENT; + } + wrapperCP = initSchemaCP (SCHEMA_CTYPE_PATTERN, NULL, NULL); + REMEMBER_PATTERN (wrapperCP); + wrapperCP->content[0] = pattern; + wrapperCP->quants[0] = SCHEMA_CQUANT_ONE; + wrapperCP->nc = 1; + pattern = wrapperCP; + } + if (sdata->cp->type == SCHEMA_CTYPE_CHOICE + && quant != SCHEMA_CQUANT_ONE) { + wrapperCP = initSchemaCP (SCHEMA_CTYPE_PATTERN, NULL, NULL); + REMEMBER_PATTERN (wrapperCP); + if (sdata->cp->nc == sdata->contentSize) { + sdata->cp->content = + REALLOC (sdata->cp->content, + 2 * sdata->contentSize + * sizeof (SchemaCP*)); + sdata->cp->quants = + REALLOC (sdata->cp->quants, + 2 * sdata->contentSize + * sizeof (SchemaQuant)); + sdata->contentSize *= 2; + } + sdata->cp->content[sdata->cp->nc] = wrapperCP; + sdata->cp->quants[sdata->cp->nc] = SCHEMA_CQUANT_ONE; + sdata->cp->nc++; + savedCP = sdata->cp; + savedContenSize = sdata->contentSize; + sdata->cp = wrapperCP; + sdata->contentSize = CONTENT_ARRAY_SIZE_INIT; + } + } + if (quant == SCHEMA_CQUANT_NM) { + int i; + int newChilds = (n >= m) ? n : m; + while (sdata->cp->nc + newChilds >= sdata->contentSize) { + sdata->cp->content = + REALLOC (sdata->cp->content, + 2 * sdata->contentSize + * sizeof (SchemaCP*)); + sdata->cp->quants = + REALLOC (sdata->cp->quants, + 2 * sdata->contentSize + * sizeof (SchemaQuant)); + sdata->contentSize *= 2; + } + for (i = 0; i < n; i++) { + sdata->cp->content[sdata->cp->nc+i] = pattern; + sdata->cp->quants[sdata->cp->nc+i] = SCHEMA_CQUANT_ONE; + } + for (i = n; i < m; i++) { + sdata->cp->content[sdata->cp->nc+i] = pattern; + sdata->cp->quants[sdata->cp->nc+i] = SCHEMA_CQUANT_OPT; + } + sdata->cp->nc = sdata->cp->nc + newChilds; + } else { + if (sdata->cp->nc == sdata->contentSize) { + sdata->cp->content = + REALLOC (sdata->cp->content, + 2 * sdata->contentSize + * sizeof (SchemaCP*)); + sdata->cp->quants = + REALLOC (sdata->cp->quants, + 2 * sdata->contentSize + * sizeof (SchemaQuant)); + sdata->contentSize *= 2; + } + sdata->cp->content[sdata->cp->nc] = pattern; + sdata->cp->quants[sdata->cp->nc] = quant; + sdata->cp->nc++; + } + if (savedCP) { + sdata->cp = savedCP; + sdata->contentSize = savedContenSize; + } +} + +static SchemaValidationStack * +getStackElement ( + SchemaData *sdata, + SchemaCP *pattern + ) +{ + SchemaValidationStack *stackElm; + + if (sdata->stackPool) { + stackElm = sdata->stackPool; + sdata->stackPool = stackElm->down; + } else { + stackElm = TMALLOC (SchemaValidationStack); + } + memset (stackElm, 0, sizeof (SchemaValidationStack)); + stackElm->pattern = pattern; + return stackElm; +} + +static void +repoolStackElement ( + SchemaData *sdata, + SchemaValidationStack *se + ) +{ + if (se->interleaveState) { + FREE (se->interleaveState); + se->interleaveState = NULL; + } + se->down = sdata->stackPool; + sdata->stackPool = se; +} + +static void +pushToStack ( + SchemaData *sdata, + SchemaCP *pattern + ) +{ + SchemaValidationStack *se, *nextse; + DBG(fprintf(stderr, "push to Stack:\n");serializeCP(pattern)); + if (pattern->type == SCHEMA_CTYPE_NAME && sdata->lastMatchse) { + se = sdata->lastMatchse; + while (se) { + nextse = se->down; + repoolStackElement (sdata, se); + se = nextse; + } + sdata->lastMatchse = NULL; + } + se = getStackElement (sdata, pattern); + se->down = sdata->stack; + if (pattern->type == SCHEMA_CTYPE_INTERLEAVE) { + se->interleaveState = MALLOC (sizeof (int) * pattern->nc); + memset (se->interleaveState, 0, sizeof (int) * pattern->nc); + } + sdata->stack = se; +} + +static void +popFromStack ( + SchemaData *sdata, + SchemaValidationStack **stack + ) +{ + SchemaValidationStack *se; + DBG(fprintf(stderr, "popFromStack:\n"); serializeCP((*stack)->pattern)); + se = (*stack)->down; + repoolStackElement (sdata, *stack); + *stack = se; +} + +static void +popStack ( + SchemaData *sdata + ) +{ + SchemaValidationStack *se, *nextse; + DBG(fprintf(stderr, "popStack:\n"); serializeCP(sdata->stack->pattern)); + if (sdata->stack->pattern->type == SCHEMA_CTYPE_NAME) { + se = sdata->lastMatchse; + while (se) { + nextse = se->down; + repoolStackElement (sdata, se); + se = nextse; + } + sdata->lastMatchse = NULL; + se = sdata->stack->down; + repoolStackElement (sdata, sdata->stack); + sdata->stack = se; + } else { + if (sdata->stack->hasMatched) { + se = sdata->stack->down; + sdata->stack->down = sdata->lastMatchse; + sdata->lastMatchse = sdata->stack; + sdata->stack = se; + } else { + se = sdata->stack->down; + repoolStackElement (sdata, sdata->stack); + sdata->stack = se; + } + } +} + +static void +finalizeElement ( + SchemaData *sdata, + int ac + ) +{ + SchemaValidationStack *se; + SchemaCP *cp, *cp1; + int i; + + se = sdata->stack; + cp = se->pattern; + if (cp->type == SCHEMA_CTYPE_NAME || cp->type == SCHEMA_CTYPE_PATTERN) { + for (i = ac; i < cp->nc; i++) { + cp1 = cp->content[ac]; + if (cp1->type == SCHEMA_CTYPE_KEYSPACE) { + if (!cp1->keySpace->active) { + Tcl_InitHashTable (&cp1->keySpace->ids, + TCL_STRING_KEYS); + cp1->keySpace->active = 1; + cp1->keySpace->unknownIDrefs = 0; + } else { + cp1->keySpace->active++; + } + } else if (cp->content[ac]->type == SCHEMA_CTYPE_KEYSPACE_END) { + cp1->keySpace->active--; + if (!cp1->keySpace->active) { + cp1->keySpace->unknownIDrefs = 0; + Tcl_DeleteHashTable (&cp1->keySpace->ids); + } + } + } + } + popStack (sdata); + /* cp is still the pattern from stack top before the popStack */ + if (cp->type != SCHEMA_CTYPE_NAME) { + finalizeElement (sdata, sdata->stack->activeChild + 1); + } +} + +static void +rewindStack ( + SchemaData *sdata + ) +{ + SchemaValidationStack *se; + + while (sdata->lastMatchse) { + se = sdata->lastMatchse; + sdata->lastMatchse = se->down; + se->down = sdata->stack; + sdata->stack = se; + } +} + +static int +recover ( + Tcl_Interp *interp, + SchemaData *sdata, + ValidationErrorType errorType, + const char *name, + const char *ns, + char *text, + int ac + ) +{ + Tcl_Obj *cmdPtr; + int rc; + SchemaValidationStack *se; + + if (!sdata->reportCmd || sdata->evalError) return 0; + if (sdata->recoverFlags & RECOVER_FLAG_DONT_REPORT) return 1; + /* If non SCHEMA_CTYPE_NAME and the pattern hasn't already matched + * that's a pattern pushed on stack to look for (probe) if it + * matches (or allows empty match). Even if the pattern fail it + * may be optional; recovering is done at the caller level in case + * the pattern isn't optional. */ + if (sdata->stack + && sdata->stack->pattern->type != SCHEMA_CTYPE_NAME + && sdata->stack->activeChild == 0 + && sdata->stack->hasMatched == 0) return 0; + cmdPtr = Tcl_DuplicateObj (sdata->reportCmd); + Tcl_IncrRefCount(cmdPtr); + Tcl_ListObjAppendElement (interp, cmdPtr, + sdata->self); + Tcl_ListObjAppendElement ( + interp, cmdPtr, + Tcl_NewStringObj (ValidationErrorType2str[errorType], -1) + ); + /* In case of unknown element the name/ns arguments of recover() + * are NULL, but sdata->vname/sdata->vns are already + * pre-filled. */ + if (name) sdata->vname = name; + if (ns) sdata->vns = ns; + sdata->vtext = text; + switch (errorType) { + case DOM_KEYCONSTRAINT: + sdata->vaction = MATCH_DOM_KEYCONSTRAINT; + break; + case DOM_XPATH_BOOLEAN: + sdata->vaction = MATCH_DOM_XPATH_BOOLEAN; + break; + case MISSING_ATTRIBUTE: + case UNKNOWN_ATTRIBUTE: + case MISSING_ELEMENT_MATCH_START: + case MISSING_TEXT_MATCH_START: + case INVALID_KEYREF_MATCH_START: + case UNEXPECTED_ROOT_ELEMENT: + case UNKNOWN_ROOT_ELEMENT: + case UNEXPECTED_ELEMENT: + sdata->vaction = MATCH_ELEMENT_START; + break; + case MISSING_TEXT_MATCH_END: + case INVALID_KEYREF_MATCH_END: + case MISSING_ELEMENT_MATCH_END: + if (sdata->stack) { + se = sdata->stack; + while (se->pattern->type != SCHEMA_CTYPE_NAME) { + se = se->down; + } + sdata->vname = se->pattern->name; + sdata->vns = se->pattern->namespace; + } + sdata->vaction = MATCH_ELEMENT_END; + break; + case UNEXPECTED_TEXT: + sdata->vaction = MATCH_TEXT; + break; + case INVALID_KEYREF_MATCH_TEXT: + case INVALID_VALUE: + if (sdata->stack) { + se = sdata->stack; + while (se->pattern->type != SCHEMA_CTYPE_NAME) { + se = se->down; + } + sdata->vname = se->pattern->name; + sdata->vns = se->pattern->namespace; + } + sdata->vaction = MATCH_TEXT; + break; + case UNKOWN_GLOBAL_ID: + case UNKOWN_ID: + sdata->vaction = MATCH_GLOBAL; + break; + case INVALID_ATTRIBUTE_VALUE: + sdata->vaction = MATCH_ATTRIBUTE_TEXT; + break; + } + sdata->currentEvals++; + rc = Tcl_EvalObjEx (interp, cmdPtr, + TCL_EVAL_GLOBAL | TCL_EVAL_DIRECT); + sdata->currentEvals--; + sdata->vaction = 0; + if (name) sdata->vname = name; + if (ns) sdata->vns = ns; + sdata->vtext = NULL; + Tcl_DecrRefCount (cmdPtr); + if (rc != TCL_OK) { + sdata->evalError = 1; + return 0; + } + switch (errorType) { + case MISSING_ELEMENT_MATCH_START: + if (strcmp (Tcl_GetStringResult (interp), "ignore") == 0) { + sdata->recoverFlags |= RECOVER_FLAG_IGNORE; + return 1; + } else if (strcmp (Tcl_GetStringResult (interp), "vanish") == 0) { + sdata->recoverFlags |= RECOVER_FLAG_REWIND; + sdata->skipDeep = 1; + return 1; + } else { + /* Rewind stack to last match and ignore the just opened + * Element. */ + finalizeElement (sdata, ac+1); + sdata->skipDeep = 2; + } + break; + case UNEXPECTED_ELEMENT: + if (strcmp (Tcl_GetStringResult (interp), "vanish") == 0) { + sdata->recoverFlags |= RECOVER_FLAG_REWIND; + sdata->skipDeep = 1; + return 1; + } else { + finalizeElement (sdata, ac+1); + sdata->skipDeep = 2; + } + break; + case UNEXPECTED_TEXT: + sdata->recoverFlags |= RECOVER_FLAG_REWIND; + break; + case MISSING_ELEMENT_MATCH_END: + case MISSING_TEXT_MATCH_END: + if (strcmp (Tcl_GetStringResult (interp), "ignore") == 0) { + sdata->recoverFlags |= RECOVER_FLAG_MATCH_END_CONTINUE; + } else { + sdata->recoverFlags |= RECOVER_FLAG_DONT_REPORT; + } + break; + case DOM_KEYCONSTRAINT: + case DOM_XPATH_BOOLEAN: + case MISSING_ATTRIBUTE: + case MISSING_TEXT_MATCH_START: + case UNEXPECTED_ROOT_ELEMENT: + case UNKNOWN_ATTRIBUTE: + case INVALID_KEYREF_MATCH_START: + case INVALID_KEYREF_MATCH_END: + case INVALID_KEYREF_MATCH_TEXT: + case UNKNOWN_ROOT_ELEMENT: + case UNKOWN_GLOBAL_ID: + case UNKOWN_ID: + case INVALID_ATTRIBUTE_VALUE: + case INVALID_VALUE: + break; + } + return 1; +} + +/* The cp argument must be type SCHEMA_CTYPE_TEXT */ +static int +checkText ( + Tcl_Interp *interp, + void *clientData, + char *text + ) +{ + int i; + SchemaCP *cp = (SchemaCP *) clientData; + SchemaConstraint *sc; + + /* Look also at oneOfImpl */ + for (i = 0; i < cp->nc; i++) { + sc = (SchemaConstraint *) cp->content[i]; + if (!(sc->constraint) (interp, sc->constraintData, text)) { + return 0; + } + } + return 1; +} + +/* The argument ac points to the child of the current top-most stack + * element pattern which is to evaluate. */ +static int +evalVirtual ( + Tcl_Interp *interp, + SchemaData *sdata, + int ac + ) +{ + int rc; + SchemaCP *cp; + + cp = sdata->stack->pattern->content[ac]; + sdata->currentEvals++; + rc = Tcl_EvalObjv (interp, cp->nc, (Tcl_Obj **) cp->content, + TCL_EVAL_GLOBAL); + sdata->currentEvals--; + if (rc != TCL_OK) { + sdata->evalError = 1; + return 0; + } + return 1; +} + +/* Check, if the pattern to probe does not call itself (even + * indirectly) without a match inbetween.*/ +static int inline +recursivePattern ( + SchemaValidationStack *se, + SchemaCP *pattern + ) +{ + int rc = 0; + + while (se && se->pattern->type != SCHEMA_CTYPE_NAME) { + if (!se->hasMatched && se->pattern == pattern) { + rc = 1; + break; + } + se = se->down; + } + return rc; +} + +static int +matchElementStart ( + Tcl_Interp *interp, + SchemaData *sdata, + char *name, + char *namespace + ) +{ + SchemaCP *cp, *candidate, *icp; + int hm, ac, i, mayskip, thismayskip, rc; + int isName = 0; + SchemaValidationStack *se; + Tcl_HashEntry *h; + + if (!sdata->stack) return 0; + se = sdata->stack; + getContext (cp, ac, hm); + + switch (cp->type) { + case SCHEMA_CTYPE_NAME: + isName = 1; + /* fall through */ + case SCHEMA_CTYPE_PATTERN: + while (ac < cp->nc) { + candidate = cp->content[ac]; + mayskip = 0; + switch (candidate->type) { + case SCHEMA_CTYPE_TEXT: + if (candidate->nc) { + if (!checkText (interp, candidate, "")) { + if (recover (interp, sdata, MISSING_TEXT_MATCH_START, + name, namespace, NULL, ac)) { + mayskip = 1; + break; + } + return 0; + } + } + break; + + case SCHEMA_CTYPE_ANY: + if (candidate->namespace && + candidate->namespace != namespace) { + break; + } + updateStack (sdata, se, ac); + sdata->skipDeep = 1; + /* See comment in tDOM_probeElement: sdata->vname and + * sdata->vns may be pre-filled. We reset it here.*/ + sdata->vname = NULL; + sdata->vns = NULL; + return 1; + + case SCHEMA_CTYPE_NAME: + DBG(fprintf (stderr, "name: %s ns: %s candidate name: %s " + "candidate ns: %s\n", name, namespace, + candidate->name, candidate->namespace)); + if (candidate->name == name + && candidate->namespace == namespace) { + pushToStack (sdata, candidate); + updateStack (sdata, se, ac); + return 1; + } + break; + + case SCHEMA_CTYPE_CHOICE: + if (candidate->typedata) { + h = Tcl_FindHashEntry ((Tcl_HashTable *)candidate->typedata, + name); + if (h) { + icp = Tcl_GetHashValue (h); + if (icp->namespace == namespace) { + pushToStack (sdata, icp); + updateStack (sdata, se, ac); + return 1; + } + } + /* TODO: Short-cut in case of no match (looking + * for emtpy match, recovering). For now fall + * throu to simple, serial approach. */ + } + for (i = 0; i < candidate->nc; i++) { + icp = candidate->content[i]; + switch (icp->type) { + case SCHEMA_CTYPE_TEXT: + break; + + case SCHEMA_CTYPE_ANY: + if (icp->namespace && icp->namespace != namespace) { + break; + } + updateStack (sdata, se, ac); + sdata->skipDeep = 1; + /* See comment in tDOM_probeElement: sdata->vname + * and sdata->vns may be pre-filled. We reset it + * here.*/ + sdata->vname = NULL; + sdata->vns = NULL; + return 1; + + case SCHEMA_CTYPE_NAME: + if (icp->name == name + && icp->namespace == namespace) { + pushToStack (sdata, icp); + updateStack (sdata, se, ac); + return 1; + } + break; + + case SCHEMA_CTYPE_CHOICE: + Tcl_Panic ("MIXED or CHOICE child of MIXED or CHOICE"); + + case SCHEMA_CTYPE_PATTERN: + if (recursivePattern (se, icp)) { + mayskip = 1; + continue; + } + /* fall throu */ + case SCHEMA_CTYPE_INTERLEAVE: + pushToStack (sdata, icp); + rc = matchElementStart (interp, sdata, name, namespace); + if (rc == 1) { + updateStack (sdata, se, ac); + return 1; + } + popStack (sdata); + if (rc == -1) mayskip = 1; + break; + + case SCHEMA_CTYPE_VIRTUAL: + Tcl_Panic ("Virtual constrain in MIXED or CHOICE"); + + case SCHEMA_CTYPE_KEYSPACE_END: + case SCHEMA_CTYPE_KEYSPACE: + Tcl_Panic ("Keyspace constrain in MIXED or CHOICE"); + + } + if (!mayskip && mayMiss (candidate->quants[i])) + mayskip = 1; + } + break; + + case SCHEMA_CTYPE_VIRTUAL: + if (evalVirtual (interp, sdata, ac)) { + hm = 1; + break; + } + else return 0; + + case SCHEMA_CTYPE_PATTERN: + if (recursivePattern (se, candidate)) { + mayskip = 1; + break; + } + /* fall throu */ + case SCHEMA_CTYPE_INTERLEAVE: + pushToStack (sdata, candidate); + rc = matchElementStart (interp, sdata, name, namespace); + if (rc == 1) { + updateStack (sdata, se, ac); + return 1; + } + popStack (sdata); + if (rc == -1) mayskip = 1; + break; + + case SCHEMA_CTYPE_KEYSPACE_END: + candidate->keySpace->active--; + if (!candidate->keySpace->active) { + if (candidate->keySpace->unknownIDrefs) { + if (!recover (interp, sdata, + INVALID_KEYREF_MATCH_START, name, + namespace, NULL, ac)) { + return 0; + } + candidate->keySpace->unknownIDrefs = 0; + } + Tcl_DeleteHashTable (&candidate->keySpace->ids); + } + ac++; + hm = 0; + continue; + + case SCHEMA_CTYPE_KEYSPACE: + if (!candidate->keySpace->active) { + Tcl_InitHashTable (&candidate->keySpace->ids, + TCL_STRING_KEYS); + candidate->keySpace->active = 1; + candidate->keySpace->unknownIDrefs = 0; + } else { + candidate->keySpace->active++; + } + ac++; + hm = 0; + continue; + } + if (!mayskip && mustMatch (cp->quants[ac], hm)) { + if (recover (interp, sdata, MISSING_ELEMENT_MATCH_START, name, + namespace, NULL, ac)) { + if (sdata->recoverFlags & RECOVER_FLAG_IGNORE) { + /* We pretend the ac content particle had + * matched. */ + updateStack (sdata, se, ac); + } + return 1; + } + return 0; + } + ac++; + hm = 0; + } + if (isName) { + if (recover (interp, sdata, UNEXPECTED_ELEMENT, name, namespace, + NULL, 0)) { + return 1; + } + return 0; + } + return -1; + + case SCHEMA_CTYPE_KEYSPACE: + case SCHEMA_CTYPE_KEYSPACE_END: + case SCHEMA_CTYPE_VIRTUAL: + case SCHEMA_CTYPE_CHOICE: + case SCHEMA_CTYPE_TEXT: + case SCHEMA_CTYPE_ANY: + /* Never pushed onto stack */ + Tcl_Panic ("Invalid CTYPE onto the validation stack!"); + + case SCHEMA_CTYPE_INTERLEAVE: + mayskip = 1; + for (i = 0; i < cp->nc; i++) { + thismayskip = 0; + if (se->interleaveState[i]) { + if (maxOne (cp->quants[i])) continue; + } + icp = cp->content[i]; + switch (icp->type) { + case SCHEMA_CTYPE_TEXT: + if (icp->nc) { + if (checkText (interp, icp, "")) { + thismayskip = 1; + } + } else { + thismayskip = 1; + } + break; + + case SCHEMA_CTYPE_ANY: + if (icp->namespace && icp->namespace != namespace) { + break; + } + sdata->skipDeep = 1; + se->hasMatched = 1; + se->interleaveState[i] = 1; + /* See comment in tDOM_probeElement: sdata->vname and + * sdata->vns may be pre-filled. We reset it here.*/ + sdata->vname = NULL; + sdata->vns = NULL; + return 1; + + case SCHEMA_CTYPE_NAME: + if (icp->name == name + && icp->namespace == namespace) { + pushToStack (sdata, icp); + se->hasMatched = 1; + se->interleaveState[i] = 1; + return 1; + } + break; + + case SCHEMA_CTYPE_CHOICE: + Tcl_Panic ("MIXED or CHOICE child of INTERLEAVE"); + + case SCHEMA_CTYPE_PATTERN: + if (recursivePattern (se, icp)) { + thismayskip = 1; + break; + } + /* fall throu */ + case SCHEMA_CTYPE_INTERLEAVE: + pushToStack (sdata, icp); + rc = matchElementStart (interp, sdata, name, namespace); + if (rc == 1) { + if (!(sdata->recoverFlags & RECOVER_FLAG_REWIND)) { + se->hasMatched = 1; + se->interleaveState[i] = 1; + } + return 1; + } + popStack (sdata); + if (rc == -1) thismayskip = 1; + break; + + case SCHEMA_CTYPE_VIRTUAL: + Tcl_Panic ("Virtual constraint child of INTERLEAVE"); + break; + + case SCHEMA_CTYPE_KEYSPACE_END: + case SCHEMA_CTYPE_KEYSPACE: + Tcl_Panic ("Keyspace constraint child of INTERLEAVE"); + break; + + } + if (!thismayskip && minOne (cp->quants[i])) mayskip = 0; + } + if (mayskip) break; + if (recover (interp, sdata, MISSING_ELEMENT_MATCH_START, name, + namespace, NULL, cp->nc)) { + if (sdata->recoverFlags & RECOVER_FLAG_IGNORE) { + /* We mark the first so far not matched mandatory + * interleave child cp as matched */ + for (i = 0; i < cp->nc; i++) { + if (!se->interleaveState[i]) { + if (minOne (cp->quants[i])) { + se->interleaveState[i] = 1; + break; + } + } + } + } + return 1; + } + return 0; + } + return -1; +} + +static void * +getNamespacePtr ( + SchemaData *sdata, + char *ns + ) +{ + Tcl_HashEntry *h; + int hnew; + + if (!ns) return NULL; + h = Tcl_FindHashEntry (&sdata->prefix, ns); + if (h) { + return Tcl_GetHashValue (h); + } + h = Tcl_CreateHashEntry (&sdata->namespace, ns, &hnew); + if (h != sdata->emptyNamespace) { + return Tcl_GetHashKey (&sdata->namespace, h); + } + return NULL; +} + +int +tDOM_probeElement ( + Tcl_Interp *interp, + SchemaData *sdata, + const char *name, + void *namespace + ) +{ + Tcl_HashEntry *h; + void *namespacePtr, *namePtr; + SchemaCP *pattern; + int rc = 1, reportError; + + if (sdata->skipDeep) { + sdata->skipDeep++; + return TCL_OK; + } + if (sdata->validationState == VALIDATION_FINISHED) { + SetResult ("Validation finished."); + return TCL_ERROR; + } + + DBG( + fprintf (stderr, "tDOM_probeElement: look if '%s' in ns '%s' match\n", + name, (char *)namespace); + ); + + if (namespace) { + h = Tcl_FindHashEntry (&sdata->namespace, namespace); + } else { + h = NULL; + } + if (h) { + namespacePtr = Tcl_GetHashKey (&sdata->namespace, h); + } else { + if (namespace) { + /* This namespace isn't known at all by the schema; this + * element may only match an any condition. If it does we + * know only later. So we use namePtr and namespacePtr + * both NULL that match nothing else in the schema and + * will be able to look if there is such a possible any + * match in the schema. */ + rc = 0; + /* If there isn't a matching any cp this is a validation + * error. To have the node name/namespace information + * available in case of recovering we prefill the sdata + * struct here.*/ + sdata->vname = name; + sdata->vns = namespace; + } + namespacePtr = NULL; + } + if (!rc) { + /* Already the provided namespace isn't known to the schema, + * so the name in that namespace of course also. */ + namePtr = NULL; + } else { + h = Tcl_FindHashEntry (&sdata->element, name); + if (h) { + namePtr = Tcl_GetHashKey (&sdata->element, h); + } else { + namePtr = NULL; + /* Prefill in case of validation error. See above. */ + sdata->vname = name; + } + } + + if (sdata->validationState == VALIDATION_READY) { + /* The root of the tree to check. */ + if (sdata->start) { + if (strcmp (name, sdata->start) != 0) { + if (recover (interp, sdata, UNEXPECTED_ROOT_ELEMENT, name, + namespace, NULL, 0)) { + sdata->validationState = VALIDATION_FINISHED; + return TCL_OK; + } + SetResult ("Root element doesn't match"); + return TCL_ERROR; + } + if (namespace) { + if (!sdata->startNamespace|| + strcmp (namespace, sdata->startNamespace) != 0) { + if (recover (interp, sdata, UNEXPECTED_ROOT_ELEMENT, name, + namespace, NULL, 0)) { + sdata->validationState = VALIDATION_FINISHED; + return TCL_OK; + } + SetResult ("Root element namespace doesn't match"); + return TCL_ERROR; + } + } else { + if (sdata->startNamespace) { + if (recover (interp, sdata, UNEXPECTED_ROOT_ELEMENT, name, + namespace, NULL, 0)) { + sdata->validationState = VALIDATION_FINISHED; + return TCL_OK; + } + SetResult ("Root element namespace doesn't match"); + return TCL_ERROR; + } + } + } + reportError = 0; + if (h) { + pattern = (SchemaCP *) Tcl_GetHashValue (h); + while (pattern) { + if (pattern->namespace == namespacePtr) { + if (pattern->flags & PLACEHOLDER_PATTERN_DEF + || pattern->flags & FORWARD_PATTERN_DEF) { + reportError = 1; + } + break; + } + pattern = pattern->next; + } + } else { + pattern = NULL; + } + sdata->validationState = VALIDATION_STARTED; + if (reportError || pattern == NULL) { + if (recover (interp, sdata, UNKNOWN_ROOT_ELEMENT, name, namespace, + NULL, 0)) { + sdata->skipDeep = 1; + return TCL_OK; + } + SetResult ("Unknown element"); + return TCL_ERROR; + } + pushToStack (sdata, pattern); + return TCL_OK; + } + + /* The normal case: we're inside the tree */ + /* In case of recovering and if the user wants a required cp to be + * treated as matched (or in other words: that the validation + * engine should ignore the mandatory state of the cp) we unwind + * the call stack to have updated stack elements, to be able to + * pretend, we have seen the mandatory cp. Now try to match the + * open element from this stack state. */ + while (1) { + rc = matchElementStart (interp, sdata, (char *) namePtr, + namespacePtr); + while (rc == -1) { + popStack (sdata); + rc = matchElementStart (interp, sdata, (char *) namePtr, + namespacePtr); + }; + if (rc) { + DBG( + fprintf (stderr, "tDOM_probeElement: element '%s' match\n", + name); + serializeStack (sdata); + fprintf (stderr, "\n"); + ); + if (sdata->recoverFlags & RECOVER_FLAG_IGNORE) { + sdata->recoverFlags &= ~RECOVER_FLAG_IGNORE; + continue; + } + CHECK_REWIND; + return TCL_OK; + } + break; + } + DBG( + fprintf (stderr, "element '%s' DOESN'T match\n", name); + serializeStack (sdata); + fprintf (stderr, "\n"); + ); + if (!sdata->evalError) { + SetResult ("Element \""); + if (namespacePtr) { + Tcl_AppendResult (interp, namespacePtr, ":", NULL); + } + Tcl_AppendResult (interp, name, "\" doesn't match", NULL); + } + return TCL_ERROR; +} + +int probeAttribute ( + Tcl_Interp *interp, + SchemaData *sdata, + const char *name, + const char *ns, + char *value, + int *isrequired + ) +{ + int i; + SchemaCP *cp; + Tcl_HashTable *t; + Tcl_HashEntry *h; + SchemaAttr *attr; + + cp = sdata->stack->pattern; + *isrequired = 0; + if (cp->typedata) { + t = (Tcl_HashTable *) cp->typedata; + h = Tcl_FindHashEntry (t, name); + if (!h) return 0; + attr = (SchemaAttr *) Tcl_GetHashValue (h); + while (attr && attr->namespace != ns) { + attr = attr->next; + } + if (!attr) return 0; + if (attr->cp) { + if (!checkText (interp, attr->cp, value)) { + if (!recover (interp, sdata, INVALID_ATTRIBUTE_VALUE, name, + ns, value, 0)) { + SetResult3V ("Attribute value doesn't match for " + "attribute '", name , "'"); + return 0; + } + } + } + if (attr->required) *isrequired = 1; + return 1; + } + for (i = 0; i < cp->numAttr; i++) { + if (cp->attrs[i]->namespace == ns + && cp->attrs[i]->name == name) { + if (cp->attrs[i]->cp) { + if (!checkText (interp, cp->attrs[i]->cp, value)) { + if (!recover (interp, sdata, INVALID_ATTRIBUTE_VALUE, name, + ns, value, i)) { + SetResult3V ("Attribute value doesn't match for " + "attribute '", name , "'"); + return 0; + } + } + } + if (cp->attrs[i]->required) *isrequired = 1; + return 1; + } + } + return 0; +} + +int tDOM_probeAttributes ( + Tcl_Interp *interp, + SchemaData *sdata, + const char **attr + ) +{ + char **atPtr, *ln, *namespace, *ns; + int i, j, found, nsatt, req, reqAttr = 0; + SchemaCP *cp; + Tcl_HashEntry *h; + + cp = sdata->stack->pattern; + for (atPtr = (char **) attr; atPtr[0] && atPtr[1]; atPtr += 2) { + found = 0; + ln = atPtr[0]; + j = 0; + while (*ln && *ln != '\xFF') { + j++, ln++; + } + if (*ln == '\xFF') { + namespace = atPtr[0]; + namespace[j] = '\0'; + ln++; + nsatt = 1; + } else { + namespace = NULL; + ln = atPtr[0]; + nsatt = 0; + } + h = Tcl_FindHashEntry (&sdata->attrNames, ln); + if (!h) goto unknowncleanup; + ln = Tcl_GetHashKey (&sdata->attrNames, h); + ns = NULL; + if (namespace) { + h = Tcl_FindHashEntry (&sdata->namespace, namespace); + if (!h) goto unknowncleanup; + ns = Tcl_GetHashKey (&sdata->namespace, h); + } + found = probeAttribute (interp, sdata, ln, ns, atPtr[1], &req); + reqAttr += req; + unknowncleanup: + if (!found) { + if (!recover (interp, sdata, UNKNOWN_ATTRIBUTE, ln, namespace, + NULL, 0)) { + if (!sdata->evalError) { + if (nsatt) { + SetResult ("Unknown attribute \""); + Tcl_AppendResult (interp, namespace, ":", ln, "\"", + NULL); + } else { + SetResult3 ("Unknown attribute \"", ln, "\""); + } + } + if (nsatt) namespace[j] = '\xFF'; + return TCL_ERROR; + } + } + if (nsatt) namespace[j] = '\xFF'; + } + if (reqAttr != cp->numReqAttr) { + /* Lookup the missing attribute(s) */ + if (!sdata->evalError) { + SetResult ("Missing mandatory attribute(s):"); + } + for (i = 0; i < cp->numAttr; i++) { + if (!cp->attrs[i]->required) continue; + found = 0; + for (atPtr = (char **) attr; atPtr[0] && atPtr[1]; atPtr += 2) { + ln = atPtr[0]; + if (cp->attrs[i]->namespace) { + j = 0; + while (*ln && *ln != '\xFF') { + j++, ln++; + } + if (*ln == '\xFF') { + namespace = atPtr[0]; + namespace[j] = '\0'; + ln++; + nsatt = 1; + } else { + continue; + } + if (strcmp (cp->attrs[i]->namespace, namespace) != 0) { + if (nsatt) namespace[j] = '\xFF'; + continue; + } + if (nsatt) namespace[j] = '\xFF'; + } + if (strcmp (ln, cp->attrs[i]->name) == 0) { + found = 1; + break; + } + } + if (!found) { + if (!recover (interp, sdata, MISSING_ATTRIBUTE, + cp->attrs[i]->name, cp->attrs[i]->namespace, + NULL, i)) { + if (cp->attrs[i]->namespace) { + Tcl_AppendResult (interp, " ", cp->attrs[i]->namespace, + ":", cp->attrs[i]->name, NULL); + } else { + Tcl_AppendResult (interp, " ", cp->attrs[i]->name, NULL); + } + } + } + } + if (!sdata->reportCmd) { + return TCL_ERROR; + } + } + return TCL_OK; +} + +int tDOM_probeDomAttributes ( + Tcl_Interp *interp, + SchemaData *sdata, + domAttrNode *attr + ) +{ + domAttrNode *atPtr; + int i, found, req, reqAttr = 0; + const char *ns, *ln; + SchemaCP *cp; + Tcl_HashEntry *h; + + cp = sdata->stack->pattern; + atPtr = attr; + while (atPtr) { + if (atPtr->nodeFlags & IS_NS_NODE) goto nextAttr; + found = 0; + if (atPtr->namespace) { + ns = domNamespaceURI ((domNode *)atPtr); + /* A namespaced attribute must always have a prefix */ + ln = atPtr->nodeName; + while (*ln) { + if (*ln == ':') { + ln++; + break; + } + ln++; + } + } else { + ns = NULL; + ln = atPtr->nodeName; + } + h = Tcl_FindHashEntry (&sdata->attrNames, ln); + if (!h) goto unknown; + ln = Tcl_GetHashKey (&sdata->attrNames, h); + if (ns) { + h = Tcl_FindHashEntry (&sdata->namespace, ns); + if (!h) goto unknown; + ns = Tcl_GetHashKey (&sdata->namespace, h); + } else { + ns = NULL; + } + found = probeAttribute (interp, sdata, ln, ns, atPtr->nodeValue, &req); + reqAttr += req; + unknown: + if (!found) { + if (!recover (interp, sdata, UNKNOWN_ATTRIBUTE, ln, ns, NULL, 0)) { + if (!sdata->evalError) { + if (ns) { + SetResult ("Unknown attribute \""); + Tcl_AppendResult (interp, ns, ":", atPtr->nodeName, + "\"", NULL); + } else { + SetResult3 ("Unknown attribute \"", atPtr->nodeName, + "\""); + } + sdata->validationState = VALIDATION_ERROR; + } + return TCL_ERROR; + } + } + nextAttr: + atPtr = atPtr->nextSibling; + } + if (reqAttr != cp->numReqAttr) { + /* Lookup the missing attribute(s) */ + if (!sdata->evalError) { + SetResult ("Missing mandatory attribute(s):"); + } + for (i = 0; i < cp->numAttr; i++) { + if (!cp->attrs[i]->required) continue; + found = 0; + atPtr = attr; + while (atPtr) { + if (cp->attrs[i]->namespace) { + if (!atPtr->namespace) goto nextAttr2; + ns = domNamespaceURI ((domNode *)atPtr); + if (strcmp (ns, cp->attrs[i]->namespace) != 0) { + goto nextAttr2; + } + ln = atPtr->nodeName; + while (*ln) { + if (*ln == ':') { + ln++; + break; + } + ln++; + } + } else { + if (atPtr->namespace) goto nextAttr2; + ln = atPtr->nodeName; + } + if (strcmp (ln, cp->attrs[i]->name) == 0) { + found = 1; + break; + } + nextAttr2: + atPtr = atPtr->nextSibling; + } + if (!found) { + if (!recover (interp, sdata, MISSING_ATTRIBUTE, + cp->attrs[i]->name, cp->attrs[i]->namespace, + NULL, i)) { + if (!sdata->evalError) { + if (cp->attrs[i]->namespace) { + Tcl_AppendResult (interp, " ", + cp->attrs[i]->namespace, ":", + cp->attrs[i]->name, NULL); + } else { + Tcl_AppendResult (interp, " ", cp->attrs[i]->name, + NULL); + } + } + } + } + } + if (!sdata->reportCmd) { + sdata->validationState = VALIDATION_ERROR; + return TCL_ERROR; + } + } + return TCL_OK; +} +int probeEventAttribute ( + Tcl_Interp *interp, + SchemaData *sdata, + Tcl_Obj *attr, + int len + ) +{ + int i, found, req, reqAttr = 0; + char *name, *ns; + SchemaCP *cp; + Tcl_HashEntry *h; + Tcl_Obj *attname, *attns, *attvalue; + + cp = sdata->stack->pattern; + for (i = 0; i < len; i += 2) { + found = 0; + ns = NULL; + name = NULL; + attns = NULL; + Tcl_ListObjIndex (interp, attr, i, &attname); + Tcl_ListObjIndex (interp, attr, i+1, &attvalue); + if (Tcl_ListObjLength (interp, attname, &len) == TCL_OK) { + if (len == 2) { + Tcl_ListObjIndex (interp, attname, 1, &attns); + Tcl_ListObjIndex (interp, attname, 0, &attname); + } + } + h = Tcl_FindHashEntry (&sdata->attrNames, Tcl_GetString (attname)); + if (!h) goto unknown; + name = Tcl_GetHashKey (&sdata->attrNames, h); + if (attns) { + h = Tcl_FindHashEntry (&sdata->namespace, Tcl_GetString (attns)); + if (!h) goto unknown; + ns = Tcl_GetHashKey (&sdata->namespace, h); + } + found = probeAttribute (interp, sdata, name, ns, + Tcl_GetString (attvalue), &req); + reqAttr += req; + unknown: + if (!found) { + if (!recover (interp, sdata, UNKNOWN_ATTRIBUTE, + Tcl_GetString (attname), Tcl_GetString (attns), + NULL, 0)) { + if (ns) { + SetResult ("Unknown attribute \""); + Tcl_AppendResult (interp, ns, ":", name, "\"", NULL); + } else { + SetResult3 ("Unknown attribute \"", name, "\""); + } + sdata->validationState = VALIDATION_ERROR; + return TCL_ERROR; + } + } + } + if (reqAttr != cp->numReqAttr) { + SetResult ("Missing mandatory attribute(s)"); + return TCL_ERROR; + } + return TCL_OK; +} + +/* Returns either -1, 0, 1, 2 + + -1 means a pattern or an interleave ended may end, look further at + parents next sibling. + + 0 means rewind with validation error. + + 1 means element content may end here. + + 2 means recovering requested further error reporting about missing childs + in the current element. To be able to to answer a [info expected] on + the occasion of the next error, we update the stack in this case + and let tDOM_probeElementEnd restart checkElementEnd again with this + stack state. +*/ +static int checkElementEnd ( + Tcl_Interp *interp, + SchemaData *sdata + ) +{ + SchemaValidationStack *se; + SchemaCP *cp, *ic; + int hm, ac, i, thismayskip, mayskip = 0, rc; + int isName = 0; + + DBG(fprintf (stderr, "checkElementEnd:\n"); + serializeStack(sdata);); + se = sdata->stack; + getContext (cp, ac, hm); + + if (cp->type == SCHEMA_CTYPE_INTERLEAVE) { + ac = 0; hm = 0; mayskip = 1; + } + switch (cp->type) { + case SCHEMA_CTYPE_NAME: + isName = 1; + /* Fall through */ + case SCHEMA_CTYPE_INTERLEAVE: + case SCHEMA_CTYPE_PATTERN: + if (ac < cp->nc && (hasMatched (cp->quants[ac], hm))) { + DBG(fprintf (stderr, "ac %d has matched, skiping to next ac\n", ac)); + ac++; hm = 0; + } + while (ac < cp->nc) { + DBG(fprintf (stderr, "ac %d hm %d mayMiss: %d\n", + ac, hm, mayMiss (cp->quants[ac]))); + if (se->interleaveState && se->interleaveState[ac]) { + ac++; continue; + } + if (mayMiss (cp->quants[ac])) { + ac++; continue; + } + switch (cp->content[ac]->type) { + case SCHEMA_CTYPE_KEYSPACE_END: + /* Don't happen as INTERLEAVE child */ + cp->content[ac]->keySpace->active--; + if (!cp->content[ac]->keySpace->active) { + if (cp->content[ac]->keySpace->unknownIDrefs) { + if (!recover (interp, sdata, INVALID_KEYREF_MATCH_END, + NULL, NULL, + cp->content[ac]->keySpace->name, 0)) { + return 0; + } + cp->content[ac]->keySpace->unknownIDrefs = 0; + } + Tcl_DeleteHashTable (&cp->content[ac]->keySpace->ids); + } + break; + + case SCHEMA_CTYPE_KEYSPACE: + /* Don't happen as INTERLEAVE child */ + if (!cp->content[ac]->keySpace->active) { + Tcl_InitHashTable (&cp->content[ac]->keySpace->ids, + TCL_STRING_KEYS); + cp->content[ac]->keySpace->active = 1; + cp->content[ac]->keySpace->unknownIDrefs = 0; + } else { + cp->content[ac]->keySpace->active++; + } + break; + + case SCHEMA_CTYPE_TEXT: + if (cp->content[ac]->nc) { + if (!checkText (interp, cp->content[ac], "")) { + if (recover (interp, sdata, MISSING_TEXT_MATCH_END, + NULL, NULL, NULL, ac)) { + break; + } + return 0; + } + } + break; + + case SCHEMA_CTYPE_CHOICE: + /* Don't happen as INTERLEAVE child */ + thismayskip = 0; + for (i = 0; i < cp->content[ac]->nc; i++) { + if (mayMiss (cp->content[ac]->quants[i])) { + thismayskip = 1; + break; + } + ic = cp->content[ac]->content[i]; + switch (ic->type) { + case SCHEMA_CTYPE_TEXT: + if (ic->nc) { + if (!checkText (interp, ic, "")) { + continue; + } + } + thismayskip = 1; + break; + + case SCHEMA_CTYPE_NAME: + case SCHEMA_CTYPE_ANY: + continue; + + case SCHEMA_CTYPE_PATTERN: + if (recursivePattern (se, ic)) { + thismayskip = 1; + break; + } + /* fall throu */ + case SCHEMA_CTYPE_INTERLEAVE: + pushToStack (sdata, ic); + if (checkElementEnd (interp, sdata) == -1) { + thismayskip = 1; + } + popStack (sdata); + break; + + case SCHEMA_CTYPE_KEYSPACE_END: + case SCHEMA_CTYPE_KEYSPACE: + case SCHEMA_CTYPE_VIRTUAL: + case SCHEMA_CTYPE_CHOICE: + Tcl_Panic ("Invalid CTYPE in MIXED or CHOICE"); + + } + if (thismayskip) break; + } + if (thismayskip) break; + if (!recover (interp, sdata, MISSING_ELEMENT_MATCH_END, NULL, + NULL, NULL, 0)) { + return 0; + } + if (sdata->recoverFlags & RECOVER_FLAG_MATCH_END_CONTINUE) { + updateStack (sdata, se, ac); + return 2; + } + break; + + case SCHEMA_CTYPE_VIRTUAL: + if (evalVirtual (interp, sdata, ac)) break; + else return 0; + + case SCHEMA_CTYPE_PATTERN: + if (recursivePattern (se, cp->content[ac])) { + break; + } + /* fall throu */ + case SCHEMA_CTYPE_INTERLEAVE: + pushToStack (sdata, cp->content[ac]); + rc = checkElementEnd (interp, sdata); + if (rc == 0) { + popStack (sdata); + if (sdata->stack->pattern->type == SCHEMA_CTYPE_NAME + || sdata->stack->activeChild + || sdata->stack->hasMatched) { + if (recover (interp, sdata, MISSING_ELEMENT_MATCH_END, + NULL, NULL, NULL, 0)) { + if (sdata->recoverFlags & + RECOVER_FLAG_MATCH_END_CONTINUE) { + updateStack (sdata, se, ac); + return 2; + } + break; + } + } + return 0; + } + if (rc == 2) { + updateStack (sdata, se, ac); + return 2; + } + popStack (sdata); + break; + + case SCHEMA_CTYPE_ANY: + case SCHEMA_CTYPE_NAME: + if (recover (interp, sdata, MISSING_ELEMENT_MATCH_END, + NULL, NULL, NULL, 0)) { + if (sdata->recoverFlags & RECOVER_FLAG_MATCH_END_CONTINUE) { + updateStack (sdata, se, ac); + return 2; + } + break; + } + return 0; + } + ac++; + } + if (se->interleaveState) { + if (!mayskip) return 0; + } + if (isName) return 1; + return -1; + + case SCHEMA_CTYPE_KEYSPACE_END: + case SCHEMA_CTYPE_KEYSPACE: + case SCHEMA_CTYPE_VIRTUAL: + case SCHEMA_CTYPE_CHOICE: + case SCHEMA_CTYPE_TEXT: + case SCHEMA_CTYPE_ANY: + /* Never pushed onto stack */ + Tcl_Panic ("Invalid CTYPE onto the validation stack!"); + + } + /* Not reached */ + return 0; +} + +static int +checkDocKeys ( + Tcl_Interp *interp, + SchemaData *sdata + ) +{ + Tcl_HashEntry *h, *h1; + Tcl_HashSearch search, search1; + int haveErrMsg = 0; + SchemaDocKey *dk; + + if (sdata->evalError) return 0; + if (sdata->unknownIDrefs) { + if (!recover (interp, sdata, UNKOWN_ID, NULL, NULL, NULL, 0)) { + haveErrMsg = 1; + SetResult ("References to unknown IDs:"); + for (h = Tcl_FirstHashEntry (&sdata->ids, &search); + h != NULL; + h = Tcl_NextHashEntry (&search)) { + if (Tcl_GetHashValue (h) == 0) { + Tcl_AppendResult (interp, " '", + Tcl_GetHashKey (&sdata->ids, h), + "'", NULL); + } + } + } + } + if (sdata->idTables.numEntries) { + for (h = Tcl_FirstHashEntry (&sdata->idTables, &search); + h != NULL; + h = Tcl_NextHashEntry (&search)) { + dk = Tcl_GetHashValue (h); + if (dk->unknownIDrefs) { + if (!recover (interp, sdata, UNKOWN_GLOBAL_ID, NULL, NULL, + NULL, 0)) { + if (haveErrMsg) { + Tcl_AppendResult (interp, "\n", NULL); + } else { + haveErrMsg = 1; + } + Tcl_AppendResult (interp, + "References to unknown IDs in ID space '", + Tcl_GetHashKey (&sdata->idTables, h), + "':", NULL); + for (h1 = Tcl_FirstHashEntry (&dk->ids, &search1); + h1 != NULL; + h1 = Tcl_NextHashEntry (&search1)) { + if (Tcl_GetHashValue (h1) == 0) { + Tcl_AppendResult (interp, " '", + Tcl_GetHashKey (&dk->ids, h1), + "'", NULL); + } + } + } + } + } + } + if (haveErrMsg) { + sdata->validationState = VALIDATION_ERROR; + return 0; + } + return 1; +} + +int +tDOM_probeElementEnd ( + Tcl_Interp *interp, + SchemaData *sdata + ) +{ + int rc; + + DBG(if (sdata->stack) { + fprintf (stderr, "tDOM_probeElementEnd: look if current stack top can " + " end name: '%s' deep: %d\n", + sdata->stack->pattern->name, getDeep (sdata->stack)); + } else {fprintf (stderr, "stack is NULL\n");} + ); + + if (sdata->skipDeep) { + sdata->skipDeep--; + return TCL_OK; + } + if (sdata->validationState == VALIDATION_FINISHED) { + SetResult ("Validation finished"); + return TCL_ERROR; + } + if (sdata->validationState == VALIDATION_READY) { + SetResult ("No validation started"); + return TCL_ERROR; + } + if (sdata->validationState == VALIDATION_ERROR) { + return TCL_ERROR; + } + + while (1) { + rc = checkElementEnd (interp, sdata); + while (rc == -1) { + popStack (sdata); + rc = checkElementEnd (interp, sdata); + } + sdata->recoverFlags &= ~RECOVER_FLAG_DONT_REPORT; + if (rc == 2) { + sdata->recoverFlags &= ~RECOVER_FLAG_MATCH_END_CONTINUE; + continue; + } + if (rc == 1) { + popStack (sdata); + if (sdata->stack == NULL) { + /* End of the first pattern (the tree root) without error. */ + /* Check for unknown ID references */ + if (!checkDocKeys (interp, sdata)) { + return TCL_ERROR; + } + /* We have successfully finished validation */ + sdata->validationState = VALIDATION_FINISHED; + } + DBG( + fprintf(stderr, "tDOM_probeElementEnd: _CAN_ end here.\n"); + serializeStack (sdata); + ); + return TCL_OK; + } + break; + } + SetResultV ("Missing mandatory content"); + sdata->validationState = VALIDATION_ERROR; + DBG( + fprintf(stderr, "tDOM_probeElementEnd: CAN'T end here.\n"); + serializeStack (sdata); + ); + return TCL_ERROR; +} + +static int +matchText ( + Tcl_Interp *interp, + SchemaData *sdata, + char *text + ) +{ + SchemaCP *cp, *candidate, *ic; + SchemaValidationStack *se; + int ac, hm, isName = 0, i, mayskip; + + DBG(fprintf (stderr, "matchText called with text '%s'\n", text)); + + se = sdata->stack; + getContext (cp, ac, hm); + while (1) { + switch (cp->type) { + case SCHEMA_CTYPE_NAME: + isName = 1; + /* Fall through */ + case SCHEMA_CTYPE_PATTERN: + while (ac < cp->nc) { + candidate = cp->content[ac]; + switch (candidate->type) { + case SCHEMA_CTYPE_TEXT: + if (checkText (interp, candidate, text)) { + updateStack (sdata, se, ac); + return 1; + } + if (sdata->evalError) return 0; + if (recover (interp, sdata, INVALID_VALUE, NULL, NULL, + text, ac)) { + updateStack (sdata, se, ac); + return 1; + } + SetResult ("Invalid text content"); + return 0; + + case SCHEMA_CTYPE_CHOICE: + if (candidate->flags & MIXED_CONTENT) { + updateStack (sdata, se, ac); + return 1; + } + for (i = 0; i < candidate->nc; i++) { + ic = candidate->content[i]; + switch (ic->type) { + case SCHEMA_CTYPE_TEXT: + if (checkText (interp, ic, text)) { + updateStack (sdata, se, ac); + return 1; + } + break; + + case SCHEMA_CTYPE_NAME: + case SCHEMA_CTYPE_ANY: + break; + + case SCHEMA_CTYPE_PATTERN: + if (recursivePattern (se, ic)) { + break; + } + /* fall throu */ + case SCHEMA_CTYPE_INTERLEAVE: + pushToStack (sdata, ic); + if (matchText (interp, sdata, text)) { + updateStack (sdata, se, ac); + return 1; + } + popStack (sdata); + break; + + case SCHEMA_CTYPE_VIRTUAL: + Tcl_Panic ("Virtual constrain in MIXED or" + " CHOICE"); + + case SCHEMA_CTYPE_CHOICE: + Tcl_Panic ("MIXED or CHOICE child of MIXED or" + " CHOICE"); + + case SCHEMA_CTYPE_KEYSPACE_END: + case SCHEMA_CTYPE_KEYSPACE: + Tcl_Panic ("Keyspace constrain in MIXED or" + " CHOICE"); + + } + } + if (mustMatch (cp->quants[ac], hm)) { + if (recover (interp, sdata, UNEXPECTED_TEXT, + NULL, NULL, text, 0)) { + return 1; + } + SetResultV ("Unexpected text content"); + return 0; + } + break; + + case SCHEMA_CTYPE_PATTERN: + if (recursivePattern (se, candidate)) { + break; + } + /* fall throu */ + case SCHEMA_CTYPE_INTERLEAVE: + pushToStack (sdata, candidate); + if (matchText (interp, sdata, text)) { + updateStack (sdata, se, ac); + return 1; + } + popStack (sdata); + if (mustMatch (cp->quants[ac], hm)) { + if (recover (interp, sdata, UNEXPECTED_TEXT, + NULL, NULL, text, 0)) { + return 1; + } + SetResultV ("Unexpected text content"); + return 0; + } + break; + + case SCHEMA_CTYPE_VIRTUAL: + if (!evalVirtual (interp, sdata, ac)) return 0; + break; + + case SCHEMA_CTYPE_KEYSPACE: + if (!cp->content[ac]->keySpace->active) { + Tcl_InitHashTable (&cp->content[ac]->keySpace->ids, + TCL_STRING_KEYS); + cp->content[ac]->keySpace->active = 1; + cp->content[ac]->keySpace->unknownIDrefs = 0; + } else { + cp->content[ac]->keySpace->active++; + } + break; + + case SCHEMA_CTYPE_KEYSPACE_END: + cp->content[ac]->keySpace->active--; + if (!cp->content[ac]->keySpace->active) { + if (cp->content[ac]->keySpace->unknownIDrefs) { + if (!recover (interp, sdata, + INVALID_KEYREF_MATCH_TEXT, NULL, + NULL, text, ac)) { + return 0; + } + cp->content[ac]->keySpace->unknownIDrefs = 0; + } + Tcl_DeleteHashTable (&cp->content[ac]->keySpace->ids); + } + break; + + case SCHEMA_CTYPE_NAME: + case SCHEMA_CTYPE_ANY: + if (mustMatch (cp->quants[ac], hm)) { + if (recover (interp, sdata, UNEXPECTED_TEXT, + NULL, NULL, text, ac)) { + return 1; + } + SetResultV ("Unexpected text content"); + return 0; + } + break; + + } + ac++; + } + if (isName) { + if (recover (interp, sdata, UNEXPECTED_TEXT, NULL, + NULL, text, 0)) { + return 1; + } + SetResultV ("Unexpected text content"); + return 0; + } + popStack (sdata); + se = sdata->stack; + getContext (cp, ac, hm); + ac++; + continue; + + case SCHEMA_CTYPE_KEYSPACE: + case SCHEMA_CTYPE_KEYSPACE_END: + case SCHEMA_CTYPE_VIRTUAL: + case SCHEMA_CTYPE_CHOICE: + case SCHEMA_CTYPE_TEXT: + case SCHEMA_CTYPE_ANY: + /* Never pushed onto stack */ + Tcl_Panic ("Invalid CTYPE onto the validation stack!"); + break; + + case SCHEMA_CTYPE_INTERLEAVE: + mayskip = 1; + for (i = 0; i < cp->nc; i++) { + if (se->interleaveState[i]) { + if (maxOne (cp->quants[i])) continue; + } else { + if (minOne (cp->quants[i])) mayskip = 0; + } + ic = cp->content[i]; + switch (ic->type) { + case SCHEMA_CTYPE_TEXT: + if (checkText (interp, ic, text)) { + if (!(sdata->recoverFlags & RECOVER_FLAG_REWIND)) { + se->hasMatched = 1; + se->interleaveState[i] = 1; + } + return 1; + } + break; + + case SCHEMA_CTYPE_NAME: + case SCHEMA_CTYPE_ANY: + break; + + case SCHEMA_CTYPE_PATTERN: + if (recursivePattern (se, ic)) { + break; + } + /* fall throu */ + case SCHEMA_CTYPE_INTERLEAVE: + pushToStack (sdata, ic); + if (matchText (interp, sdata, text)) { + updateStack (sdata, se, ac); + return 1; + } + popStack (sdata); + break; + + case SCHEMA_CTYPE_CHOICE: + Tcl_Panic ("MIXED or CHOICE child of INTERLEAVE"); + + case SCHEMA_CTYPE_KEYSPACE_END: + case SCHEMA_CTYPE_KEYSPACE: + Tcl_Panic ("Keyspace child of INTERLEAVE"); + + case SCHEMA_CTYPE_VIRTUAL: + break; + + } + } + if (!mayskip) { + if (recover (interp, sdata, UNEXPECTED_TEXT, NULL, NULL, text, + ac)) { + return 1; + } + SetResultV ("Unexpected text content"); + return 0; + } + popStack (sdata); + se = sdata->stack; + getContext (cp, ac, hm); + ac++; + continue; + } + /* Not reached, but this is inside a while (1) {} loop ...*/ + break; + } + /* Not reached, but at least makes the compiler happy. */ + return 0; +} + +int +tDOM_probeText ( + Tcl_Interp *interp, + SchemaData *sdata, + char *text, + int *only_whites + ) +{ + int myonly_whites; + char *pc; + + DBG(fprintf (stderr, "tDOM_probeText started, text: '%s'\n", text);) + if (sdata->skipDeep) { + return TCL_OK; + } + if (sdata->validationState == VALIDATION_FINISHED) { + SetResult ("Validation finished"); + return TCL_ERROR; + } + if (sdata->validationState == VALIDATION_READY) { + SetResult ("No validation started"); + return TCL_ERROR; + } + + if (sdata->stack->pattern->flags & CONSTRAINT_TEXT_CHILD) { + if (!*text && sdata->stack->pattern->nc == 0) { + return TCL_OK; + } + if (matchText (interp, sdata, text)) { + CHECK_REWIND; + return TCL_OK; + } + } else { + if (only_whites) { + myonly_whites = *only_whites; + } else { + myonly_whites = 1; + pc = text; + while (SPACE (*pc)) pc++; + if (*pc) myonly_whites = 0; + } + if (myonly_whites) return TCL_OK; + if (matchText (interp, sdata, text)) { + CHECK_REWIND; + return TCL_OK; + } + } + if (!sdata->evalError) { + SetResult ("Text content doesn't match"); + } + return TCL_ERROR; +} + +static void +startElement( + void *userData, + const char *name, + const char **atts +) +{ + ValidateMethodData *vdata = (ValidateMethodData *) userData; + SchemaData *sdata; + char *namespace; + const char *s; + int i = 0; + + DBG(fprintf (stderr, "startElement: '%s'\n", name);) + sdata = vdata->sdata; + if (!sdata->skipDeep && sdata->stack && Tcl_DStringLength (vdata->cdata)) { + if (tDOM_probeText (vdata->interp, sdata, + Tcl_DStringValue (vdata->cdata), NULL) != TCL_OK) { + sdata->validationState = VALIDATION_ERROR; + XML_StopParser (vdata->parser, 0); + Tcl_DStringSetLength (vdata->cdata, 0); + vdata->onlyWhiteSpace = 1; + return; + } + Tcl_DStringSetLength (vdata->cdata, 0); + vdata->onlyWhiteSpace = 1; + } + s = name; + while (*s && *s != '\xFF') { + i++; s++; + } + namespace = NULL; + if (*s == '\xFF') { + s++; + if (i) { + if (i >= vdata->maxUriLen - 1) { + vdata->uri = (char *) REALLOC (vdata->uri, vdata->maxUriLen * 2); + vdata->maxUriLen *= 2; + } + memcpy (vdata->uri, name, i); + vdata->uri[i] = '\0'; + namespace = vdata->uri; + } + } else { + s = name; + } + + if (tDOM_probeElement (vdata->interp, sdata, s, namespace) + != TCL_OK) { + sdata->validationState = VALIDATION_ERROR; + XML_StopParser (vdata->parser, 0); + return; + } + if (sdata->skipDeep == 0 + && (atts[0] || (sdata->stack && sdata->stack->pattern->attrs))) { + if (tDOM_probeAttributes (vdata->interp, sdata, atts) + != TCL_OK) { + sdata->validationState = VALIDATION_ERROR; + XML_StopParser (vdata->parser, 0); + } + } +} + +static void +endElement ( + void *userData, + const char *name +) +{ + ValidateMethodData *vdata = (ValidateMethodData *) userData; + SchemaData *sdata; + + DBG(fprintf (stderr, "endElement: '%s'\n", name);) + sdata = vdata->sdata; + if (sdata->validationState == VALIDATION_ERROR) { + return; + } + if (!sdata->skipDeep && sdata->stack && Tcl_DStringLength (vdata->cdata)) { + if (tDOM_probeText (vdata->interp, sdata, + Tcl_DStringValue (vdata->cdata), NULL) != TCL_OK) { + sdata->validationState = VALIDATION_ERROR; + XML_StopParser (vdata->parser, 0); + Tcl_DStringSetLength (vdata->cdata, 0); + vdata->onlyWhiteSpace = 1; + return; + } + } + if (Tcl_DStringLength (vdata->cdata)) { + Tcl_DStringSetLength (vdata->cdata, 0); + vdata->onlyWhiteSpace = 1; + } + if (tDOM_probeElementEnd (vdata->interp, sdata) + != TCL_OK) { + sdata->validationState = VALIDATION_ERROR; + XML_StopParser (vdata->parser, 0); + } +} + +static void +characterDataHandler ( + void *userData, + const char *s, + int len +) +{ + ValidateMethodData *vdata = (ValidateMethodData *) userData; + const char *pc; + + if (vdata->onlyWhiteSpace) { + int i = 0; + pc = s; + while (i < len) { + if ( (*pc == ' ') || + (*pc == '\n') || + (*pc == '\r') || + (*pc == '\t') ) { + pc++; + i++; + continue; + } + vdata->onlyWhiteSpace = 0; + break; + } + } + Tcl_DStringAppend (vdata->cdata, s, len); +} + +static int +validateString ( + Tcl_Interp *interp, + SchemaData *sdata, + char *xmlstr, + int len + ) +{ + XML_Parser parser; + char sep = '\xFF'; + ValidateMethodData vdata; + Tcl_DString cdata; + Tcl_Obj *resultObj; + char sl[50], sc[50]; + int result; + + parser = XML_ParserCreate_MM (NULL, MEM_SUITE, &sep); + vdata.interp = interp; + vdata.sdata = sdata; + vdata.parser = parser; + sdata->parser = parser; + Tcl_DStringInit (&cdata); + vdata.cdata = &cdata; + vdata.onlyWhiteSpace = 1; + vdata.uri = (char *) MALLOC (URI_BUFFER_LEN_INIT); + vdata.maxUriLen = URI_BUFFER_LEN_INIT; + XML_SetUserData (parser, &vdata); + XML_SetElementHandler (parser, startElement, endElement); + XML_SetCharacterDataHandler (parser, characterDataHandler); + + if (XML_Parse (parser, xmlstr, len, 1) != XML_STATUS_OK + || sdata->validationState == VALIDATION_ERROR) { + resultObj = Tcl_NewObj (); + sprintf(sl, "%ld", XML_GetCurrentLineNumber(parser)); + sprintf(sc, "%ld", XML_GetCurrentColumnNumber(parser)); + if (sdata->validationState == VALIDATION_ERROR) { + Tcl_AppendStringsToObj (resultObj, "error \"", + Tcl_GetStringResult (interp), + "\" at line ", sl, " character ", sc, NULL); + } else { + Tcl_AppendStringsToObj (resultObj, "error \"", + XML_ErrorString(XML_GetErrorCode(parser)), + "\" at line ", sl, " character ", sc, NULL); + } + Tcl_SetObjResult (interp, resultObj); + result = TCL_ERROR; + } else { + result = TCL_OK; + } + sdata->parser = NULL; + XML_ParserFree (parser); + Tcl_DStringFree (&cdata); + FREE (vdata.uri); + return result; +} + +static int +validateFile ( + Tcl_Interp *interp, + SchemaData *sdata, + Tcl_Obj *filenameObj + ) +{ + XML_Parser parser; + char sep = '\xFF'; + ValidateMethodData vdata; + Tcl_DString cdata; + Tcl_Obj *resultObj; + char sl[50], sc[50]; + char *filename; + int result, fd; + Tcl_DString translatedFilename; + + parser = XML_ParserCreate_MM (NULL, MEM_SUITE, &sep); + vdata.interp = interp; + vdata.sdata = sdata; + vdata.parser = parser; + sdata->parser = parser; + Tcl_DStringInit (&cdata); + vdata.cdata = &cdata; + vdata.onlyWhiteSpace = 1; + vdata.uri = (char *) MALLOC (URI_BUFFER_LEN_INIT); + vdata.maxUriLen = URI_BUFFER_LEN_INIT; + XML_SetUserData (parser, &vdata); + XML_SetElementHandler (parser, startElement, endElement); + XML_SetCharacterDataHandler (parser, characterDataHandler); + + filename = Tcl_TranslateFileName (interp, Tcl_GetString (filenameObj), + &translatedFilename); + if (filename == NULL) { + result = TCL_ERROR; + goto cleanup; + } + fd = open(filename, O_BINARY|O_RDONLY); + if (fd < 0) { + Tcl_ResetResult (interp); + Tcl_AppendResult (interp, "error opening file \"", + filename, "\"", (char *) NULL); + result = TCL_ERROR; + goto cleanup; + } + for (;;) { + int nread; + char *fbuf = XML_GetBuffer (parser, TDOM_EXPAT_READ_SIZE); + if (!fbuf) { + close (fd); + Tcl_ResetResult (interp); + Tcl_SetResult (interp, "Out of memory\n", NULL); + result = TCL_ERROR; + goto cleanup; + } + nread = read(fd, fbuf, TDOM_EXPAT_READ_SIZE); + if (nread < 0) { + close (fd); + Tcl_ResetResult (interp); + Tcl_AppendResult (interp, "error reading from file \"", + filename, "\"", (char *) NULL); + result = TCL_ERROR; + goto cleanup; + } + result = XML_ParseBuffer (parser, nread, nread == 0); + if (result != XML_STATUS_OK || !nread + || sdata->validationState == VALIDATION_ERROR) { + close (fd); + break; + } + } + if (result != XML_STATUS_OK + || sdata->validationState == VALIDATION_ERROR) { + resultObj = Tcl_NewObj (); + sprintf(sl, "%ld", XML_GetCurrentLineNumber(parser)); + sprintf(sc, "%ld", XML_GetCurrentColumnNumber(parser)); + if (sdata->validationState == VALIDATION_ERROR) { + Tcl_AppendStringsToObj (resultObj, "error \"", + Tcl_GetStringResult (interp), + "\" at line ", sl, " character ", sc, NULL); + } else { + Tcl_AppendStringsToObj (resultObj, "error \"", + XML_ErrorString(XML_GetErrorCode(parser)), + "\" at line ", sl, " character ", sc, NULL); + } + Tcl_SetObjResult (interp, resultObj); + result = TCL_ERROR; + } else { + Tcl_DStringFree (&translatedFilename); + result = TCL_OK; + } +cleanup: + Tcl_DStringFree (&translatedFilename); + sdata->parser = NULL; + XML_ParserFree (parser); + Tcl_DStringFree (&cdata); + FREE (vdata.uri); + return result; +} + +static int +validateChannel ( + Tcl_Interp *interp, + SchemaData *sdata, + Tcl_Channel channel + ) +{ + XML_Parser parser; + char sep = '\xFF'; + ValidateMethodData vdata; + Tcl_DString cdata; + Tcl_Obj *resultObj, *bufObj; + char sl[50], sc[50], *str; + int result = TCL_OK, len, done, tclLen, rc; + + parser = XML_ParserCreate_MM (NULL, MEM_SUITE, &sep); + vdata.interp = interp; + vdata.sdata = sdata; + vdata.parser = parser; + sdata->parser = parser; + Tcl_DStringInit (&cdata); + vdata.cdata = &cdata; + vdata.onlyWhiteSpace = 1; + vdata.uri = (char *) MALLOC (URI_BUFFER_LEN_INIT); + vdata.maxUriLen = URI_BUFFER_LEN_INIT; + XML_SetUserData (parser, &vdata); + XML_SetElementHandler (parser, startElement, endElement); + XML_SetCharacterDataHandler (parser, characterDataHandler); + + bufObj = Tcl_NewObj(); + Tcl_SetObjLength (bufObj, 6144); + do { + len = Tcl_ReadChars (channel, bufObj, 1024, 0); + done = (len < 1024); + str = Tcl_GetStringFromObj(bufObj, &tclLen); + rc = XML_Parse (parser, str, tclLen, done); + if (rc != XML_STATUS_OK + || sdata->validationState == VALIDATION_ERROR) { + resultObj = Tcl_NewObj (); + sprintf(sl, "%ld", XML_GetCurrentLineNumber(parser)); + sprintf(sc, "%ld", XML_GetCurrentColumnNumber(parser)); + if (sdata->validationState == VALIDATION_ERROR) { + Tcl_AppendStringsToObj (resultObj, "error \"", + Tcl_GetStringResult (interp), + "\" at line ", sl, " character ", sc, + NULL); + } else { + Tcl_AppendStringsToObj (resultObj, "error \"", + XML_ErrorString(XML_GetErrorCode(parser)), + "\" at line ", sl, " character ", sc, + NULL); + } + Tcl_SetObjResult (interp, resultObj); + result = TCL_ERROR; + break; + } + } while (!done); + Tcl_DecrRefCount (bufObj); + sdata->parser = NULL; + XML_ParserFree (parser); + Tcl_DStringFree (&cdata); + FREE (vdata.uri); + return result; +} + +static void +schemaxpathRSFree ( + xpathResultSet *rs + ) +{ + if (rs->type == StringResult) FREE (rs->string); + FREE (rs->nodes); +} + +static int +checkdomKeyConstraints ( + Tcl_Interp *interp, + SchemaData *sdata, + domNode *node + ) +{ + xpathResultSet nodeList, rs, frs; + domKeyConstraint *kc; + domNode *n; + domAttrNode *attr; + int rc, i, j, hnew, len, skip, first; + char *errMsg = NULL, *keystr, *efsv; + Tcl_HashTable htable; + Tcl_DString dStr; + xpathCBs cbs; + + kc = sdata->stack->pattern->domKeys; + memset (&nodeList, 0, sizeof (xpathResultSet)); + nodeList.type = EmptyResult; + memset (&rs, 0, sizeof (xpathResultSet)); + rs.type = EmptyResult; + memset (&frs, 0, sizeof (xpathResultSet)); + frs.type = EmptyResult; + Tcl_DStringInit (&dStr); + xpathRSReset (&nodeList, node); + cbs.funcCB = tcldom_xpathFuncCallBack; + cbs.funcClientData = interp; + cbs.varCB = NULL; + cbs.varClientData = NULL; + while (kc) { + xpathRSReset (&rs, NULL); + rc = xpathEvalAst (kc->selector, &nodeList, node, &cbs, &rs, &errMsg); + if (rc) { + SetResult (errMsg); + goto booleanErrorCleanup; + } + if (kc->flags & DKC_FLAG_BOOLEAN) { + i = xpathFuncBoolean (&rs); + if (!i) { + if (!recover (interp, sdata, DOM_XPATH_BOOLEAN, kc->name, + NULL, NULL, 0)) { + SetResultV ("INVALID_DOM_XPATH_BOOLEAN"); + goto booleanErrorCleanup; + } + } + kc = kc->next; + continue; + } + if (rs.type == EmptyResult) goto nextConstraint; + if (rs.type != xNodeSetResult) { + SetResult ("INVALID_DOM_KEYCONSTRAINT"); + goto errorCleanup; + } + Tcl_InitHashTable (&htable, TCL_STRING_KEYS); + for (i = 0; i < rs.nr_nodes; i++) { + n = rs.nodes[i]; + if (n->nodeType != ELEMENT_NODE) { + SetResult ("INVALID_DOM_KEYCONSTRAINT"); + goto errorCleanup; + } + xpathRSReset (&nodeList, n); + if (kc->nrFields == 1) { + xpathRSReset (&frs, NULL); + rc = xpathEvalAst (kc->fields[0], &nodeList, n, &cbs, &frs, + &errMsg); + if (rc) { + SetResult (errMsg); + goto errorCleanup; + } + if (frs.type != xNodeSetResult && frs.type != EmptyResult) { + SetResult ("INVALID_DOM_KEYCONSTRAINT"); + goto errorCleanup; + } + if (frs.type == EmptyResult || frs.nr_nodes == 0) { + if (kc->flags & DKC_FLAG_IGNORE_EMPTY_FIELD_SET) { + continue; + } + efsv = ""; + if (kc->emptyFieldSetValue) { + efsv = kc->emptyFieldSetValue; + } + Tcl_CreateHashEntry (&htable, efsv, &hnew); + if (!hnew) { + if (recover (interp, sdata, DOM_KEYCONSTRAINT, + kc->name, NULL, efsv, 0)) { + break; + } + SetResultV ("DOM_KEYCONSTRAINT"); + goto errorCleanup; + } + continue; + } + if (frs.nr_nodes != 1) { + if (recover (interp, sdata, DOM_KEYCONSTRAINT, kc->name, + NULL, NULL, 0)) { + break; + } + SetResultV ("DOM_KEYCONSTRAINT"); + goto errorCleanup; + } + if (frs.nodes[0]->nodeType != ELEMENT_NODE + && frs.nodes[0]->nodeType != ATTRIBUTE_NODE) { + SetResult ("INVALID_DOM_KEYCONSTRAINT"); + goto errorCleanup; + } + if (frs.nodes[0]->nodeType == ATTRIBUTE_NODE) { + attr = (domAttrNode *) frs.nodes[0]; + Tcl_CreateHashEntry (&htable, attr->nodeValue, &hnew); + if (!hnew) { + if (recover (interp, sdata, DOM_KEYCONSTRAINT, + kc->name, NULL, attr->nodeValue, 0)) { + break; + } + SetResultV ("DOM_KEYCONSTRAINT"); + goto errorCleanup; + } + } else { + keystr = xpathGetStringValue (frs.nodes[0], &len); + Tcl_CreateHashEntry (&htable, keystr, &hnew); + if (!hnew) { + if (recover (interp, sdata, DOM_KEYCONSTRAINT, + kc->name, NULL, keystr, 0)) { + FREE(keystr); + break; + } + FREE(keystr); + SetResultV ("DOM_KEYCONSTRAINT"); + goto errorCleanup; + } + FREE(keystr); + } + } else { + Tcl_DStringSetLength (&dStr, 0); + skip = 0; + first = 1; + for (j = 0; j < kc->nrFields; j++) { + xpathRSReset (&frs, NULL); + rc = xpathEvalAst (kc->fields[j], &nodeList, n, &cbs, + &frs, &errMsg); + if (rc) { + SetResult (errMsg); + goto errorCleanup; + } + if (frs.type != xNodeSetResult + && frs.type != EmptyResult) { + SetResult ("INVALID_DOM_KEYCONSTRAINT"); + goto errorCleanup; + } + if (frs.type == EmptyResult || frs.nr_nodes == 0) { + if (kc->flags & DKC_FLAG_IGNORE_EMPTY_FIELD_SET) { + continue; + } + if (kc->emptyFieldSetValue) { + if (first) first = 0; + else Tcl_DStringAppend (&dStr, ":", 1); + Tcl_DStringAppend (&dStr, kc->emptyFieldSetValue, + kc->efsv_len); + } else { + if (first) first = 0; + else Tcl_DStringAppend (&dStr, ":", 1); + } + continue; + } + if (frs.nr_nodes != 1) { + if (recover (interp, sdata, DOM_KEYCONSTRAINT, + kc->name, NULL, NULL, 0)) { + skip = 1; + break; + } + SetResultV ("DOM_KEYCONSTRAINT"); + goto errorCleanup; + } + if (frs.nodes[0]->nodeType != ELEMENT_NODE + && frs.nodes[0]->nodeType != ATTRIBUTE_NODE) { + SetResult ("INVALID_DOM_KEYCONSTRAINT"); + goto errorCleanup; + } + if (first) first = 0; + else Tcl_DStringAppend (&dStr, ":", 1); + if (frs.nodes[0]->nodeType == ATTRIBUTE_NODE) { + attr = (domAttrNode *) frs.nodes[0]; + Tcl_DStringAppend (&dStr, attr->nodeValue, + attr->valueLength); + } else { + keystr = xpathGetStringValue (frs.nodes[0], &len); + Tcl_DStringAppend (&dStr, keystr, len); + FREE (keystr); + } + } + if (skip) break; + Tcl_CreateHashEntry (&htable, Tcl_DStringValue (&dStr), &hnew); + if (!hnew) { + if (recover (interp, sdata, DOM_KEYCONSTRAINT, + kc->name, NULL, Tcl_DStringValue (&dStr), + 0)) { + break; + } + SetResultV ("DOM_KEYCONSTRAINT"); + goto errorCleanup; + } + } + } + Tcl_DeleteHashTable (&htable); + nextConstraint: + kc = kc->next; + } + schemaxpathRSFree (&frs); + schemaxpathRSFree (&rs); + schemaxpathRSFree (&nodeList); + return TCL_OK; + +errorCleanup: + Tcl_DeleteHashTable (&htable); +booleanErrorCleanup: + schemaxpathRSFree (&frs); + schemaxpathRSFree (&rs); + schemaxpathRSFree (&nodeList); + return TCL_ERROR; +} + +static int +validateDOM ( + Tcl_Interp *interp, + SchemaData *sdata, + domNode *node + ) +{ + char *ln; + domNode *savednode, *savedinsideNode; + + if (node->namespace) { + if (node->ownerDocument->namespaces[node->namespace-1]->prefix[0] == '\0') { + ln = node->nodeName; + } else { + ln = node->nodeName; + while (*ln && (*ln != ':')) { + ln++; + } + if (*ln == ':') { + ln++; + } else { + /* Ups? */ + ln = node->nodeName; + } + } + } else { + ln = node->nodeName; + } + savednode = sdata->node; + sdata->node = node; + if (tDOM_probeElement (interp, sdata, ln, + node->namespace ? + node->ownerDocument->namespaces[node->namespace-1]->uri + : NULL) + != TCL_OK) { + return TCL_ERROR; + } + /* In case of UNKNOWN_ROOT_ELEMENT and reportCmd is set + * sdata->stack is NULL. */ + if (!sdata->stack) return TCL_OK; + if (sdata->skipDeep == 0) { + if (node->firstAttr) { + if (tDOM_probeDomAttributes (interp, sdata, node->firstAttr) + != TCL_OK) { + return TCL_ERROR; + } + } else { + if (sdata->stack->pattern->numReqAttr) { + /* tDOM_probeDomAttributes fills interp result with a + * msg which required attributes are missing in case + * of no reportCmd. In case of reportCmd + * tDOM_probeDomAttributes() returns only error in the + * case of error in called scripts. */ + if (tDOM_probeDomAttributes (interp, sdata, NULL) != TCL_OK) { + return TCL_ERROR; + } + } + } + } + + if (sdata->stack->pattern->domKeys) { + if (checkdomKeyConstraints (interp, sdata, node) != TCL_OK) + return TCL_ERROR; + } + + savedinsideNode = sdata->insideNode; + sdata->insideNode = node; + node = node->firstChild; + while (node) { + switch (node->nodeType) { + case ELEMENT_NODE: + if (Tcl_DStringLength (sdata->cdata)) { + if (tDOM_probeText (interp, sdata, + Tcl_DStringValue (sdata->cdata), NULL) != TCL_OK) + return TCL_ERROR; + Tcl_DStringSetLength (sdata->cdata, 0); + } + if (validateDOM (interp, sdata, node) != TCL_OK) return TCL_ERROR; + break; + + case TEXT_NODE: + case CDATA_SECTION_NODE: + if (node == node->parentNode->firstChild + && node == node->parentNode->lastChild) { + Tcl_DStringAppend (sdata->cdata, + ((domTextNode *) node)->nodeValue, + ((domTextNode *) node)->valueLength); + if (tDOM_probeText (interp, sdata, + Tcl_DStringValue (sdata->cdata), NULL) != TCL_OK) { + Tcl_DStringSetLength (sdata->cdata, 0); + return TCL_ERROR; + } + Tcl_DStringSetLength (sdata->cdata, 0); + break; + } + Tcl_DStringAppend (sdata->cdata, + ((domTextNode *) node)->nodeValue, + ((domTextNode *) node)->valueLength); + break; + + case COMMENT_NODE: + case PROCESSING_INSTRUCTION_NODE: + /* They are just ignored by validation. */ + break; + + default: + SetResult ("Unexpected node type in validateDOM!"); + return TCL_ERROR; + } + node = node->nextSibling; + } + if (Tcl_DStringLength (sdata->cdata)) { + if (tDOM_probeText (interp, sdata, Tcl_DStringValue (sdata->cdata), + NULL) != TCL_OK) return TCL_ERROR; + Tcl_DStringSetLength (sdata->cdata, 0); + } + if (tDOM_probeElementEnd (interp, sdata) != TCL_OK) return TCL_ERROR; + sdata->node = savednode; + sdata->insideNode = savedinsideNode; + return TCL_OK; +} + +static void +schemaReset ( + SchemaData *sdata + ) +{ + Tcl_HashEntry *h; + Tcl_HashSearch search; + SchemaDocKey *dk; + SchemaKeySpace *ks; + + while (sdata->stack) popStack (sdata); + while (sdata->lastMatchse) popFromStack (sdata, &sdata->lastMatchse); + sdata->recoverFlags = 0; + sdata->validationState = VALIDATION_READY; + sdata->skipDeep = 0; + sdata->evalError = 0; + sdata->vaction = 0; + sdata->vname = NULL; + sdata->vns = NULL; + sdata->vtext = NULL; + Tcl_DStringSetLength (sdata->cdata, 0); + if (sdata->ids.numEntries) { + Tcl_DeleteHashTable (&sdata->ids); + Tcl_InitHashTable (&sdata->ids, TCL_STRING_KEYS); + sdata->unknownIDrefs = 0; + } + if (sdata->idTables.numEntries) { + for (h = Tcl_FirstHashEntry (&sdata->idTables, &search); + h != NULL; + h = Tcl_NextHashEntry (&search)) { + dk = Tcl_GetHashValue (h); + if ((&dk->ids)->numEntries) { + Tcl_DeleteHashTable (&dk->ids); + Tcl_InitHashTable (&dk->ids, TCL_STRING_KEYS); + dk->unknownIDrefs = 0; + } + } + } + if (sdata->keySpaces.numEntries) { + for (h = Tcl_FirstHashEntry (&sdata->keySpaces, &search); + h != NULL; + h = Tcl_NextHashEntry (&search)) { + ks = Tcl_GetHashValue (h); + if (ks->active && ks->ids.numEntries) { + Tcl_DeleteHashTable (&ks->ids); + Tcl_InitHashTable (&ks->ids, TCL_STRING_KEYS); + } + ks->unknownIDrefs = 0; + ks->active = 0; + } + } + sdata->parser = NULL; + sdata->node = NULL; + sdata->insideNode = NULL; +} + +void +tDOM_schemaReset ( + SchemaData *sdata, + int lookforCleanup + ) +{ + if (lookforCleanup) { + if (sdata->cleanupAfterUse && sdata->inuse == 0 + && sdata->currentEvals == 0) { + schemaInstanceDelete (sdata); + return; + } + } + schemaReset (sdata); +} + +static int +evalConstraints ( + Tcl_Interp *interp, + SchemaData *sdata, + SchemaCP *cp, + Tcl_Obj *script + ) +{ + int result, savedIsTextConstraint; + SchemaCP *savedCP; + unsigned int savedContenSize; + + /* Save some state of sdata .. */ + savedCP = sdata->cp; + savedContenSize = sdata->contentSize; + savedIsTextConstraint = sdata->isTextConstraint; + /* ... and prepare sdata for definition evaluation. */ + sdata->cp = cp; + sdata->contentSize = CONTENT_ARRAY_SIZE_INIT; + sdata->isTextConstraint = 1; + sdata->textStub[3] = script; + sdata->currentEvals++; + result = Tcl_EvalObjv (interp, 4, sdata->textStub, TCL_EVAL_GLOBAL); + sdata->currentEvals--; + /* ... and restore the previously saved sdata states */ + sdata->isTextConstraint = savedIsTextConstraint; + sdata->cp = savedCP; + sdata->contentSize = savedContenSize; + return result; +} + +/* cp must be of type SCHEMA_CTYPE_NAME for useful results */ +static Tcl_Obj* +serializeElementName ( + Tcl_Interp *interp, + SchemaCP *cp + ) +{ + Tcl_Obj *rObj; + + rObj = Tcl_NewObj(); + Tcl_ListObjAppendElement (interp, rObj, Tcl_NewStringObj (cp->name, -1)); + if (cp->namespace) { + Tcl_ListObjAppendElement (interp, rObj, + Tcl_NewStringObj (cp->namespace, -1)); + } + return rObj; +} + +static Tcl_Obj* +serializeElementTypeName ( + Tcl_Interp *interp, + SchemaCP *cp + ) +{ + Tcl_Obj *rObj; + + rObj = Tcl_NewObj(); + Tcl_ListObjAppendElement (interp, rObj, Tcl_NewStringObj (cp->typeName, -1)); + if (cp->namespace) { + Tcl_ListObjAppendElement (interp, rObj, + Tcl_NewStringObj (cp->namespace, -1)); + } + return rObj; +} + +/* cp must be of type SCHEMA_CTYPE_ANY for useful results */ +static Tcl_Obj* +serializeAnyCP ( + Tcl_Interp *interp, + SchemaCP *cp + ) +{ + Tcl_Obj *rObj; + + rObj = Tcl_NewObj(); + Tcl_ListObjAppendElement (interp, rObj, Tcl_NewStringObj ("", 5)); + if (cp->namespace) { + Tcl_ListObjAppendElement (interp, rObj, + Tcl_NewStringObj (cp->namespace, -1)); + } else { + Tcl_ListObjAppendElement (interp, rObj, Tcl_NewObj()); + } + return rObj; +} + +/* The cp argument may be NULL. If it isn't NULL cp must be of type + * SCHEMA_CTYPE_TEXT for useful results */ +static Tcl_Obj* +serializeTextCP ( + Tcl_Interp *interp, + SchemaCP *cp + ) +{ + Tcl_Obj *rObj; + + rObj = Tcl_NewObj(); + Tcl_ListObjAppendElement (interp, rObj, Tcl_NewStringObj ("#text", 5)); + Tcl_ListObjAppendElement (interp, rObj, Tcl_NewObj()); + return rObj; +} + +static Tcl_Obj* +serializeElementEnd ( + Tcl_Interp *interp + ) +{ + Tcl_Obj *rObj; + + rObj = Tcl_NewObj(); + Tcl_ListObjAppendElement (interp, rObj, + Tcl_NewStringObj ("", 12)); + Tcl_ListObjAppendElement (interp, rObj, Tcl_NewObj()); + return rObj; +} + +static void +definedElements ( + Tcl_HashTable *htable, + Tcl_Interp *interp + ) +{ + Tcl_Obj *rObj, *elmObj; + Tcl_HashEntry *h; + Tcl_HashSearch search; + SchemaCP *cp; + + rObj = Tcl_GetObjResult (interp); + for (h = Tcl_FirstHashEntry (htable, &search); + h != NULL; + h = Tcl_NextHashEntry (&search)) { + cp = (SchemaCP *) Tcl_GetHashValue (h); + while (cp) { + if (cp->flags & FORWARD_PATTERN_DEF + || cp->flags & PLACEHOLDER_PATTERN_DEF) { + cp = cp->next; + continue; + } + elmObj = serializeElementName (interp, cp); + Tcl_ListObjAppendElement (interp, rObj, elmObj); + cp = cp->next; + } + } +} + +static void +definedElementtypes ( + SchemaData *sdata, + Tcl_Interp *interp + ) +{ + Tcl_Obj *rObj, *elmObj; + Tcl_HashEntry *h; + Tcl_HashSearch search; + SchemaCP *cp; + + rObj = Tcl_GetObjResult (interp); + for (h = Tcl_FirstHashEntry (&sdata->elementType, &search); + h != NULL; + h = Tcl_NextHashEntry (&search)) { + cp = (SchemaCP *) Tcl_GetHashValue (h); + while (cp) { + if (cp->flags & FORWARD_PATTERN_DEF + || cp->flags & PLACEHOLDER_PATTERN_DEF) { + cp = cp->next; + continue; + } + if (cp->flags & FORWARD_PATTERN_DEF + || cp->flags & PLACEHOLDER_PATTERN_DEF) continue; + elmObj = serializeElementTypeName (interp, cp); + Tcl_ListObjAppendElement (interp, rObj, elmObj); + cp = cp->next; + } + } +} + +static int +getNextExpectedWorker ( + SchemaData *sdata, + SchemaValidationStack *se, + Tcl_Interp *interp, + Tcl_HashTable *seenCPs, + Tcl_Obj *rObj, + int expectedFlags + ) +{ + int ac, hm, i, hnew, mustMatch, mayskip, rc = 1; + int probeMayskip = 0; + SchemaCP *cp, *ic, *jc; + SchemaValidationStack *se1; + + if (expectedFlags & EXPECTED_PROBE_MAYSKIP) { + probeMayskip = 1; + } + getContext (cp, ac, hm); + if ((expectedFlags & EXPECTED_IGNORE_MATCHED + || expectedFlags & EXPECTED_ONLY_MANDATORY) + && hm) { + ac++; + hm = 0; + } else { + if (hm && maxOne(cp->quants[ac])) { + ac++; + hm = 0; + } + } + switch (cp->type) { + case SCHEMA_CTYPE_INTERLEAVE: + ac = 0; + mustMatch = 0; + /* Fall through */ + case SCHEMA_CTYPE_NAME: + case SCHEMA_CTYPE_PATTERN: + while (ac < cp->nc) { + if (se->interleaveState + && se->interleaveState[ac] + && maxOne (cp->quants[ac])) { + ac++; + hm = 0; + continue; + } + if (expectedFlags & EXPECTED_ONLY_MANDATORY + && !(mustMatch (cp->quants[ac], hm))) { + ac++; + hm = 0; + continue; + } + ic = cp->content[ac]; + mayskip = 0; + switch (ic->type) { + case SCHEMA_CTYPE_NAME: + if (probeMayskip) break; + Tcl_ListObjAppendElement (interp, rObj, + serializeElementName (interp, ic)); + break; + case SCHEMA_CTYPE_PATTERN: + if (recursivePattern (se, ic)) { + break; + } + /* Fall through */ + case SCHEMA_CTYPE_INTERLEAVE: + if (expectedFlags & EXPECTED_ONLY_MANDATORY + && !se->hasMatched) { + expectedFlags |= EXPECTED_PROBE_MAYSKIP; + se1 = getStackElement (sdata, ic); + mayskip = getNextExpectedWorker (sdata, se1, interp, + seenCPs, rObj, + expectedFlags); + repoolStackElement (sdata, se1); + if (!probeMayskip) { + expectedFlags &= ~EXPECTED_PROBE_MAYSKIP; + } + if (mayskip) break; + } + if (probeMayskip) break; + Tcl_CreateHashEntry (seenCPs, ic, &hnew); + if (hnew) { + se1 = getStackElement (sdata, ic); + mayskip = getNextExpectedWorker (sdata, se1, interp, + seenCPs, rObj, + expectedFlags); + repoolStackElement (sdata, se1); + } + break; + + case SCHEMA_CTYPE_ANY: + if (probeMayskip) break; + if (!(expectedFlags & EXPECTED_ONLY_MANDATORY) + || minOne (cp->quants[ac])) { + Tcl_ListObjAppendElement (interp, rObj, + serializeAnyCP (interp, ic)); + } + break; + + case SCHEMA_CTYPE_TEXT: + if (ic->nc == 0 || checkText (interp, ic, "")) { + mayskip = 1; + } + if (probeMayskip) break; + if (!(expectedFlags & EXPECTED_ONLY_MANDATORY) + || mayskip == 0) { + Tcl_ListObjAppendElement (interp, rObj, + serializeTextCP (interp, ic)); + } + break; + + case SCHEMA_CTYPE_CHOICE: + if (probeMayskip) { + for (i = 0; i < ic->nc; i++) { + if (mayMiss (ic->quants[i])) { + mayskip = 1; + break; + } + jc = ic->content[i]; + switch (jc->type) { + case SCHEMA_CTYPE_PATTERN: + if (recursivePattern (se, ic)) { + mayskip = 1; + break; + } + /* fall throu */ + case SCHEMA_CTYPE_INTERLEAVE: + se1 = getStackElement (sdata, ic); + mayskip = getNextExpectedWorker ( + sdata, se1, interp, seenCPs, rObj, + expectedFlags + ); + repoolStackElement (sdata, se1); + break; + case SCHEMA_CTYPE_TEXT: + if (ic->nc == 0 || checkText (interp, ic, "")) { + mayskip = 1; + } + break; + default: + break; + } + if (mayskip) break; + } + break; + } + if (ic->flags & MIXED_CONTENT) { + if (!(expectedFlags & EXPECTED_ONLY_MANDATORY)) { + Tcl_ListObjAppendElement ( + interp, rObj, serializeTextCP (interp, NULL)); + } + } + for (i = 0; i < ic->nc; i++) { + jc = ic->content[i]; + switch (jc->type) { + case SCHEMA_CTYPE_NAME: + if (!(expectedFlags & EXPECTED_ONLY_MANDATORY) + || minOne (cp->quants[i])) { + Tcl_ListObjAppendElement ( + interp, rObj, serializeElementName (interp, jc) + ); + } + break; + case SCHEMA_CTYPE_PATTERN: + if (recursivePattern (se, jc)) { + break; + } + /* Fall through */ + case SCHEMA_CTYPE_INTERLEAVE: + Tcl_CreateHashEntry (seenCPs, jc, &hnew); + if (hnew) { + se1 = getStackElement (sdata, jc); + mayskip = getNextExpectedWorker ( + sdata, se1, interp, seenCPs, rObj, + expectedFlags + ); + repoolStackElement (sdata, se1); + } + break; + case SCHEMA_CTYPE_ANY: + if (!(expectedFlags & EXPECTED_ONLY_MANDATORY) + || minOne (cp->quants[i])) { + Tcl_ListObjAppendElement ( + interp, rObj, serializeAnyCP (interp, jc) + ); + } + break; + case SCHEMA_CTYPE_TEXT: + if (!(expectedFlags & EXPECTED_ONLY_MANDATORY) + || minOne (cp->quants[i])) { + Tcl_ListObjAppendElement ( + interp, rObj, serializeTextCP (interp, jc) + ); + } + break; + case SCHEMA_CTYPE_CHOICE: + Tcl_Panic ("MIXED or CHOICE child of MIXED or CHOICE"); + + case SCHEMA_CTYPE_VIRTUAL: + case SCHEMA_CTYPE_KEYSPACE: + case SCHEMA_CTYPE_KEYSPACE_END: + break; + } + } + break; + + case SCHEMA_CTYPE_VIRTUAL: + case SCHEMA_CTYPE_KEYSPACE: + case SCHEMA_CTYPE_KEYSPACE_END: + mayskip = 1; + break; + } + if (cp->type == SCHEMA_CTYPE_INTERLEAVE) { + if (!mustMatch && minOne(cp->quants[ac])) mustMatch = 1; + } else { + if (!mayskip && !hm && minOne (cp->quants[ac])) break; + } + ac++; + hm = 0; + } + if (cp->type == SCHEMA_CTYPE_NAME) { + if (ac == cp->nc) { + /* The curently open element can end here, no + * mandatory elements missing. + * The element end is always mandatory.*/ + Tcl_ListObjAppendElement ( + interp, rObj, serializeElementEnd (interp) + ); + } + rc = 0; + } else if (cp->type == SCHEMA_CTYPE_INTERLEAVE) { + if (mustMatch) rc = 0; + } else { + /* SCHEMA_CTYPE_PATTERN */ + if (ac < cp->nc) rc = 0; + } + break; + + case SCHEMA_CTYPE_ANY: + case SCHEMA_CTYPE_CHOICE: + case SCHEMA_CTYPE_TEXT: + case SCHEMA_CTYPE_VIRTUAL: + case SCHEMA_CTYPE_KEYSPACE: + case SCHEMA_CTYPE_KEYSPACE_END: + Tcl_Panic ("Invalid CTYPE onto the validation stack!"); + } + return rc; +} + +static Tcl_Obj * +unifyMatchList ( + Tcl_Interp *interp, + Tcl_HashTable *htable, + Tcl_Obj *list + ) +{ + int len, i, hnew; + Tcl_HashEntry *h; + Tcl_Obj *rObj, *thisObj; + Tcl_HashSearch search; + + rObj = Tcl_NewObj(); + Tcl_ListObjLength (interp, list, &len); + if (len == 0) return rObj; + if (len == 1) { + Tcl_ListObjIndex (interp, list, 0, &thisObj); + Tcl_ListObjAppendElement (interp, rObj, thisObj); + return rObj; + } + Tcl_InitHashTable (htable, TCL_STRING_KEYS); + for (i = 0; i < len; i++) { + Tcl_ListObjIndex (interp, list, i, &thisObj); + h = Tcl_CreateHashEntry (htable, Tcl_GetString (thisObj), &hnew); + if (hnew) { + Tcl_SetHashValue (h, thisObj); + } + } + for (h = Tcl_FirstHashEntry (htable, &search); + h != NULL; + h = Tcl_NextHashEntry (&search)) { + Tcl_ListObjAppendElement (interp, rObj, Tcl_GetHashValue (h)); + } + Tcl_DeleteHashTable (htable); + return rObj; +} + +static void +getNextExpected ( + SchemaData *sdata, + Tcl_Interp *interp, + int expectedFlags + ) +{ + int remainingLastMatch, count, rc; + Tcl_Obj *rObj; + Tcl_HashTable localHash; + SchemaValidationStack *se; + + rObj = Tcl_NewObj(); + Tcl_InitHashTable (&localHash, TCL_ONE_WORD_KEYS); + remainingLastMatch = 0; + if (sdata->lastMatchse) { + se = sdata->lastMatchse; + while (se->down) { + remainingLastMatch++; + se = se->down; + } + while (se && getNextExpectedWorker (sdata, se, interp, &localHash, rObj, + expectedFlags)) { + if (remainingLastMatch) { + count = 1; + se = sdata->lastMatchse; + while (count < remainingLastMatch) { + se = se->down; + count++; + } + remainingLastMatch--; + } else break; + } + } + + se = sdata->stack; + while (se) { + if (!se->hasMatched && se->pattern->type != SCHEMA_CTYPE_NAME) { + se = se->down; + continue; + } + rc = getNextExpectedWorker (sdata, se, interp, &localHash, rObj, + expectedFlags); + if (se->pattern->type == SCHEMA_CTYPE_NAME) break; + se = se->down; + if (!rc) break; + } + Tcl_DeleteHashTable (&localHash); + Tcl_SetObjResult (interp, unifyMatchList (interp, &localHash, rObj)); + Tcl_DecrRefCount (rObj); +} + +static int +schemaInstanceInfoCmd ( + SchemaData *sdata, + Tcl_Interp *interp, + int objc, + Tcl_Obj *const objv[] + ) +{ + int methodIndex, expectedFlags; + long line, column; + Tcl_HashEntry *h; + SchemaCP *cp; + SchemaValidationStack *se; + void *ns; + Tcl_Obj *rObj; + + static const char *schemaInstanceInfoMethods[] = { + "validationstate", "vstate", "definedElements", "stack", "toplevel", + "expected", "definition", "validationaction", "vaction", "line", + "column", "domNode", "nrForwardDefinitions", "typedefinition", + "definedElementtypes", "patterndefinition", "definedPatterns", NULL + }; + enum schemaInstanceInfoMethod { + m_validationstate, m_vstate, m_definedElements, m_stack, m_toplevel, + m_expected, m_definition, m_validationaction, m_vaction, m_line, + m_column, m_domNode, m_nrForwardDefinitions, m_typedefinition, + m_definedElementtypes, m_patterndefinition, m_definedPatterns + }; + + static const char *schemaInstanceInfoStackMethods[] = { + "top", "inside", "associated", NULL + }; + enum schemaInstanceInfoStackMethod { + m_top, m_inside, m_associated + }; + + static const char *schemaInstanceInfoVactionMethods[] = { + "name", "namespace", "text", NULL + }; + enum schemaInstanceInfoVactionMethod { + m_name, m_namespace, m_text + }; + + static const char *schemaInstanceInfoExpectedOptions[] = { + "-ignorematched", "-onlymandatory", NULL + }; + enum schemaInstanceInfoExpectedOption + { + o_ignorematched, o_onlymandatory + }; + + if (objc < 2) { + Tcl_WrongNumArgs (interp, 1, objv, "subcommand ?arguments?"); + return TCL_ERROR; + } + + if (Tcl_GetIndexFromObj (interp, objv[1], schemaInstanceInfoMethods, + "method", 0, &methodIndex) + != TCL_OK) { + return TCL_ERROR; + } + + Tcl_ResetResult (interp); + switch ((enum schemaInstanceInfoMethod) methodIndex) { + case m_validationstate: + case m_vstate: + switch (sdata->validationState) { + case VALIDATION_READY: + SetResult ("READY"); + break; + case VALIDATION_STARTED: + SetResult ("VALIDATING"); + break; + case VALIDATION_FINISHED: + SetResult ("FINISHED"); + break; + default: + SetResult ("Internal error: Invalid validation state"); + return TCL_ERROR; + } + break; + + case m_definedElements: + if (objc != 2) { + Tcl_WrongNumArgs (interp, 1, objv, "definedElements"); + return TCL_ERROR; + } + definedElements (&sdata->element, interp); + break; + + case m_definedPatterns: + if (objc != 2) { + Tcl_WrongNumArgs (interp, 1, objv, "definedPatterns"); + return TCL_ERROR; + } + definedElements (&sdata->pattern, interp); + break; + + case m_definedElementtypes: + if (objc != 2) { + Tcl_WrongNumArgs (interp, 1, objv, "definedElementtypes"); + return TCL_ERROR; + } + definedElementtypes (sdata, interp); + break; + + case m_stack: + if (objc != 3) { + Tcl_WrongNumArgs (interp, 2, objv, "top|inside"); + return TCL_ERROR; + } + if (Tcl_GetIndexFromObj (interp, objv[2], + schemaInstanceInfoStackMethods, + "method", 0, &methodIndex) + != TCL_OK) { + return TCL_ERROR; + } + if (!sdata->stack) { + return TCL_OK; + } + se = sdata->stack; + switch ((enum schemaInstanceInfoStackMethod) methodIndex) { + case m_inside: + rObj = Tcl_NewObj(); + while (se) { + if (se->pattern->type == SCHEMA_CTYPE_NAME) { + Tcl_ListObjAppendElement (interp, rObj, + serializeElementName (interp, se->pattern)); + } + se = se->down; + } + Tcl_SetObjResult (interp, rObj); + return TCL_OK; + + case m_top: + while (se->pattern->type != SCHEMA_CTYPE_NAME) { + se = se->down; + } + rObj = serializeElementName (interp, se->pattern); + Tcl_SetObjResult (interp, rObj); + return TCL_OK; + + case m_associated: + if (!se->pattern->associated) { + return TCL_OK; + } + Tcl_SetObjResult (interp, se->pattern->associated); + return TCL_OK; + } + + case m_toplevel: + if (objc != 2) { + Tcl_WrongNumArgs (interp, 2, objv, ""); + return TCL_ERROR; + } + if (!sdata->currentEvals) { + SetResult ("not called while schema evaluation"); + return TCL_ERROR; + } + if (!sdata->defineToplevel && sdata->currentEvals > 1) { + SetBooleanResult (0); + } else { + SetBooleanResult (1); + } + return TCL_OK; + + case m_expected: + if (objc < 2 && objc > 4) { + Tcl_WrongNumArgs (interp, 2, objv, "?-ignorematched? ?-onlymandatory?"); + return TCL_ERROR; + } + if (sdata->validationState == VALIDATION_ERROR + || sdata->validationState == VALIDATION_FINISHED) { + return TCL_OK; + } + expectedFlags = 0; + while (objc > 2) { + if (Tcl_GetIndexFromObj (interp, objv[2], + schemaInstanceInfoExpectedOptions, + "option", 0, &methodIndex) + != TCL_OK) { + return TCL_ERROR; + } + switch ((enum schemaInstanceInfoExpectedOption) methodIndex) { + case o_ignorematched: + expectedFlags |= EXPECTED_IGNORE_MATCHED; + break; + case o_onlymandatory: + expectedFlags |= EXPECTED_ONLY_MANDATORY; + break; + } + objv++; + objc--; + } + if (!sdata->stack) { + if (sdata->start) { + Tcl_AppendElement (interp, sdata->start); + if (sdata->startNamespace) { + Tcl_AppendElement (interp, sdata->startNamespace); + } + } else { + definedElements (&sdata->element, interp); + } + } else { + getNextExpected (sdata, interp, expectedFlags); + } + break; + + case m_definition: + if (objc < 3 && objc > 4) { + Tcl_WrongNumArgs (interp, 1, objv, "name ?namespace?"); + return TCL_ERROR; + } + h = Tcl_FindHashEntry (&sdata->element, Tcl_GetString (objv[2])); + if (!h) { + SetResult ("Unknown element definition"); + return TCL_ERROR; + } + cp = Tcl_GetHashValue (h); + ns = NULL; + if (objc == 4) { + ns = getNamespacePtr (sdata, Tcl_GetString (objv[3])); + } + while (cp && cp->namespace != ns) { + cp = cp->next; + } + if (!cp + || cp->flags & LOCAL_DEFINED_ELEMENT + || cp->flags & PLACEHOLDER_PATTERN_DEF) { + SetResult ("Unknown element definition"); + return TCL_ERROR; + } + Tcl_AppendElement (interp, "defelement"); + Tcl_AppendElement (interp, cp->name); + if (cp->namespace) { + Tcl_AppendElement (interp, cp->namespace); + } + if (cp->defScript) { + Tcl_AppendElement (interp, Tcl_GetString (cp->defScript)); + } + break; + + case m_patterndefinition: + if (objc < 3 && objc > 4) { + Tcl_WrongNumArgs (interp, 1, objv, "name ?namespace?"); + return TCL_ERROR; + } + h = Tcl_FindHashEntry (&sdata->pattern, Tcl_GetString (objv[2])); + if (!h) { + SetResult ("Unknown pattern definition"); + return TCL_ERROR; + } + cp = Tcl_GetHashValue (h); + ns = NULL; + if (objc == 4) { + ns = getNamespacePtr (sdata, Tcl_GetString (objv[3])); + } + while (cp && cp->namespace != ns) { + cp = cp->next; + } + if (!cp + || cp->flags & LOCAL_DEFINED_ELEMENT + || cp->flags & PLACEHOLDER_PATTERN_DEF) { + SetResult ("Unknown pattern definition"); + return TCL_ERROR; + } + Tcl_AppendElement (interp, "defpattern"); + Tcl_AppendElement (interp, cp->name); + if (cp->namespace) { + Tcl_AppendElement (interp, cp->namespace); + } + if (cp->defScript) { + Tcl_AppendElement (interp, Tcl_GetString (cp->defScript)); + } + break; + + case m_typedefinition: + if (objc < 3 && objc > 4) { + Tcl_WrongNumArgs (interp, 1, objv, "name ?namespace?"); + return TCL_ERROR; + } + h = Tcl_FindHashEntry (&sdata->elementType, Tcl_GetString (objv[2])); + if (!h) { + SetResult ("Unknown elementtype definition"); + return TCL_ERROR; + } + cp = Tcl_GetHashValue (h); + ns = NULL; + if (objc == 4) { + ns = getNamespacePtr (sdata, Tcl_GetString (objv[3])); + } + while (cp && cp->namespace != ns) { + cp = cp->next; + } + if (!cp + || cp->flags & LOCAL_DEFINED_ELEMENT + || cp->flags & PLACEHOLDER_PATTERN_DEF) { + SetResult ("Unknown elementtype definition"); + return TCL_ERROR; + } + Tcl_AppendElement (interp, "defelementtype"); + Tcl_AppendElement (interp, cp->typeName); + Tcl_AppendElement (interp, cp->name); + if (cp->namespace) { + Tcl_AppendElement (interp, cp->namespace); + } + if (cp->defScript) { + Tcl_AppendElement (interp, Tcl_GetString (cp->defScript)); + } + break; + + case m_vaction: + case m_validationaction: + if (sdata->validationState != VALIDATION_STARTED + || sdata->currentEvals == 0) { + SetResult ("NONE"); + break; + } + if (objc == 2) { + SetResult (ValidationAction2str[sdata->vaction]); + break; + } + if (objc != 3) { + Tcl_WrongNumArgs (interp, 2, objv, "?name|namespace|text?"); + return TCL_ERROR; + } + if (Tcl_GetIndexFromObj (interp, objv[2], + schemaInstanceInfoVactionMethods, + "method", 0, &methodIndex) + != TCL_OK) { + return TCL_ERROR; + } + switch ((enum schemaInstanceInfoVactionMethod) methodIndex) { + case m_name: + SetResult (sdata->vname); + break; + case m_namespace: + SetResult (sdata->vns); + break; + case m_text: + SetResult (sdata->vtext); + break; + } + break; + + case m_line: + if (!sdata->parser && !sdata->node) break; + if (sdata->parser) { + SetLongResult (XML_GetCurrentLineNumber (sdata->parser)); + break; + } + if (domGetLineColumn(sdata->node, &line, &column) < 0) break; + SetLongResult (line); + break; + + case m_column: + if (!sdata->parser && !sdata->node) break; + if (sdata->parser) { + SetLongResult (XML_GetCurrentColumnNumber (sdata->parser)); + break; + } + if (domGetLineColumn(sdata->node, &line, &column) < 0) break; + SetLongResult (column); + break; + + case m_domNode: + if (!sdata->node) break; + /* We distinguish between calls from reportCmd and others + * (from scripts called with the tcl cmd). */ + if (sdata->vaction) { + /* This is the case: called from reportCmd. */ + return tcldom_setInterpAndReturnVar (interp, sdata->node, 0, NULL); + } else { + /* This is the case: called from a with tcl called script. */ + return tcldom_setInterpAndReturnVar (interp, sdata->insideNode, 0, NULL); + } + break; + + case m_nrForwardDefinitions: + if (objc != 2) { + Tcl_WrongNumArgs(interp, 2, objv, ""); + return TCL_ERROR; + } + SetIntResult(sdata->forwardPatternDefs); + break; + + } + return TCL_OK; +} + +static void +attributeLookupPreparation ( + SchemaData *sdata, + SchemaCP *cp + ) +{ + Tcl_HashTable *t; + int i, hnew; + Tcl_HashEntry *h; + SchemaAttr *attr; + + if (cp->numAttr <= sdata->attributeHashThreshold) return; + t = TMALLOC (Tcl_HashTable); + Tcl_InitHashTable (t, TCL_STRING_KEYS); + for (i = 0; i < cp->numAttr; i++) { + h = Tcl_CreateHashEntry (t, cp->attrs[i]->name, &hnew); + if (hnew) { + Tcl_SetHashValue (h, cp->attrs[i]); + } else { + attr = (SchemaAttr *) Tcl_GetHashValue (h); + cp->attrs[i]->next = attr->next; + attr->next = cp->attrs[i]; + } + } + cp->typedata = (void *)t; +} + +/* This implements the script interface to the created schema commands. + + Since validation may call out to tcl scripts those scripts may + delete the schema command (which just validates input by calling + out to a tcl script). This is handled by tcl evaluation level + counting and postponing the schema data deletion until back on top. + + After any code by this function that may have called out to a tcl + script it is important not to return locally but to signal the + return value with the result variable and ensure to reach the code + at the end of tDOM_schemaInstanceCmd. + */ +int +tDOM_schemaInstanceCmd ( + ClientData clientData, + Tcl_Interp *interp, + int objc, + Tcl_Obj *const objv[] + ) +{ + int methodIndex, keywordIndex, hnew, hnew1, patternIndex; + int result = TCL_OK, forwardDef = 0, i = 0, j, mode; + int savedDefineToplevel, type, len, n; + unsigned int savedNumPatternList; + SchemaData *savedsdata = NULL, *sdata = (SchemaData *) clientData; + Tcl_HashTable *hashTable; + Tcl_HashEntry *h, *h1; + SchemaCP *pattern, *thiscp, *current = NULL; + void *namespacePtr, *savedNamespacePtr; + char *xmlstr, *errMsg; + domDocument *doc; + domNode *node; + Tcl_Obj *attData; + Tcl_Channel chan = NULL; + + static const char *schemaInstanceMethods[] = { + "defelement", "defpattern", "start", "event", "delete", + "reset", "define", "validate", "domvalidate", "deftexttype", + "info", "reportcmd", "prefixns", "validatefile", + "validatechannel", "defelementtype", "set", + NULL + }; + enum schemaInstanceMethod { + m_defelement, m_defpattern, m_start, m_event, m_delete, + m_reset, m_define, m_validate, m_domvalidate, m_deftexttype, + m_info, m_reportcmd, m_prefixns, m_validatefile, + m_validatechannel, m_defelementtype, m_set + }; + + static const char *eventKeywords[] = { + "start", "end", "text", NULL + }; + enum eventKeyword + { + k_elementstart, k_elementend, k_text + }; + + static const char *setKeywords[] = { + "choiceHashThreshold", "attributeHashThreshold", NULL + }; + enum setKeyword + { + s_choiceHashThreshold, s_attributeHashThreshold + }; + + if (sdata == NULL) { + /* Inline defined defelement, defelementtype, defpattern, + * deftexttype, start or prefixns */ + sdata = GETASI; + CHECK_SI; + if (!sdata->defineToplevel && sdata->currentEvals > 1) { + SetResult ("Command not allowed in nested schema define script"); + return TCL_ERROR; + } + i = 1; + } + if (objc + i < 2) { + Tcl_WrongNumArgs (interp, 1, objv, "subcommand ?arguments?"); + return TCL_ERROR; + } + + + if (Tcl_GetIndexFromObj (interp, objv[1-i], schemaInstanceMethods, + "method", 0, &methodIndex) + != TCL_OK) { + return TCL_ERROR; + } + + Tcl_ResetResult (interp); + switch ((enum schemaInstanceMethod) methodIndex) { + case m_defelement: + case m_defpattern: + CHECK_RECURSIVE_CALL + if (objc != 4-i && objc != 5-i) { + Tcl_WrongNumArgs (interp, 1-i, objv, "" + " ?? pattern"); + return TCL_ERROR; + } + if ((enum schemaInstanceMethod) methodIndex == m_defelement) { + hashTable = &sdata->element; + type = SCHEMA_CTYPE_NAME; + } else { + hashTable = &sdata->pattern; + type = SCHEMA_CTYPE_PATTERN; + } + savedNumPatternList = sdata->numPatternList; + namespacePtr = NULL; + patternIndex = 3-i; + if (objc == 5-i) { + patternIndex = 4-i; + namespacePtr = getNamespacePtr (sdata, Tcl_GetString (objv[3-i])); + } + h = Tcl_CreateHashEntry (hashTable, Tcl_GetString (objv[2-i]), &hnew); + pattern = NULL; + if (!hnew) { + pattern = (SchemaCP *) Tcl_GetHashValue (h); + while (pattern) { + if (pattern->namespace == namespacePtr) { + if (pattern->flags & FORWARD_PATTERN_DEF + || pattern->flags & PLACEHOLDER_PATTERN_DEF) { + forwardDef = 1; + break; + } + if ((enum schemaInstanceMethod) methodIndex + == m_defelement) { + SetResult ("Element already defined " + "in this namespace"); + } else { + SetResult ("Pattern already defined " + "in this namespace"); + } + return TCL_ERROR; + } + pattern = pattern->next; + } + } + if (pattern == NULL) { + pattern = initSchemaCP (type, namespacePtr, + Tcl_GetHashKey (hashTable, h)); + if (!hnew) { + current = (SchemaCP *) Tcl_GetHashValue (h); + pattern->next = current; + } + REMEMBER_PATTERN (pattern); + Tcl_SetHashValue (h, pattern); + } + + SETASI(sdata); + savedDefineToplevel = sdata->defineToplevel; + savedNamespacePtr = sdata->currentNamespace; + sdata->defineToplevel = 0; + sdata->currentNamespace = namespacePtr; + sdata->cp = pattern; + sdata->numAttr = 0; + sdata->numReqAttr = 0; + sdata->currentAttrs = NULL; + sdata->contentSize = CONTENT_ARRAY_SIZE_INIT; + sdata->evalStub[3] = objv[patternIndex]; + sdata->currentEvals++; + result = Tcl_EvalObjv (interp, 4, sdata->evalStub, TCL_EVAL_GLOBAL); + sdata->currentEvals--; + sdata->currentNamespace = NULL; + pattern->attrs = sdata->currentAttrs; + pattern->numAttr = sdata->numAttr; + pattern->numReqAttr = sdata->numReqAttr; + if (result == TCL_OK) { + if (pattern->numAttr) { + attributeLookupPreparation (sdata, pattern); + } + if (forwardDef) { + if (pattern->flags & FORWARD_PATTERN_DEF) { + sdata->forwardPatternDefs--; + pattern->flags &= ~FORWARD_PATTERN_DEF; + } + pattern->flags &= ~PLACEHOLDER_PATTERN_DEF; + } + pattern->defScript = objv[patternIndex]; + Tcl_IncrRefCount (pattern->defScript); + } else { + if (forwardDef) { + pattern->nc = 0; + } + cleanupLastPattern (sdata, savedNumPatternList); + } + sdata->defineToplevel = savedDefineToplevel; + sdata->currentNamespace = savedNamespacePtr; + if (!savedDefineToplevel) { + SETASI(savedsdata); + } + break; + + case m_define: + CHECK_EVAL + if (objc != 3) { + Tcl_WrongNumArgs (interp, 2, objv, ""); + return TCL_ERROR; + } + if (clientData) { + savedsdata = GETASI; + if (savedsdata == sdata) { + SetResult ("Recursive call of schema command is not allowed"); + return TCL_ERROR; + } + } + SETASI(sdata); + savedNumPatternList = sdata->numPatternList; + sdata->currentNamespace = 0; + sdata->cp = NULL; + sdata->contentSize = 0; + sdata->defineToplevel = 1; + sdata->evalStub[3] = objv[2]; + sdata->currentEvals++; + result = Tcl_EvalObjv (interp, 4, sdata->evalStub, TCL_EVAL_GLOBAL); + sdata->currentEvals--; + if (result != TCL_OK) { + cleanupLastPattern (sdata, savedNumPatternList); + } + sdata->defineToplevel = 0; + SETASI(savedsdata); + break; + + case m_deftexttype: + CHECK_RECURSIVE_CALL + if (objc != 4-i) { + Tcl_WrongNumArgs (interp, 2-i, objv, "" + " "); + return TCL_ERROR; + } + h = Tcl_CreateHashEntry (&sdata->textDef, Tcl_GetString (objv[2-i]), + &hnew); + if (!hnew) { + SetResult ("There is already a text type definition with this " + "name"); + return TCL_ERROR; + } + pattern = initSchemaCP (SCHEMA_CTYPE_CHOICE, NULL, NULL); + pattern->type = SCHEMA_CTYPE_TEXT; + REMEMBER_PATTERN (pattern) + SETASI(sdata); + savedDefineToplevel = sdata->defineToplevel; + result = evalConstraints (interp, sdata, pattern, objv[3-i]); + sdata->defineToplevel = savedDefineToplevel; + if (!savedDefineToplevel) { + SETASI(savedsdata); + } + if (result == TCL_OK) { + Tcl_SetHashValue (h, pattern); + } else { + Tcl_DeleteHashEntry (h); + } + break; + + case m_start: + CHECK_RECURSIVE_CALL + if (objc < 3-i || objc > 4-i) { + Tcl_WrongNumArgs (interp, 2-i, objv, "" + " ??"); + return TCL_ERROR; + } + if (sdata->start) { + FREE (sdata->start); + } + if (objc == 3-i && strcmp (Tcl_GetString (objv[2-i]), "") == 0) { + sdata->startNamespace = NULL; + sdata->start = NULL; + break; + } + sdata->start = tdomstrdup (Tcl_GetString (objv[2-i])); + if (objc == 4-i) { + sdata->startNamespace = + getNamespacePtr (sdata, Tcl_GetString (objv[3-i])); + } + break; + + case m_event: + CHECK_EVAL + if (objc < 3) { + Tcl_WrongNumArgs (interp, 2, objv, "" + " ??"); + return TCL_ERROR; + } + if (Tcl_GetIndexFromObj (interp, objv[2], eventKeywords, + "keyword", 0, &keywordIndex) + != TCL_OK) { + return TCL_ERROR; + } + switch ((enum eventKeyword) keywordIndex) { + case k_elementstart: + if (objc < 4 && objc > 6) { + Tcl_WrongNumArgs (interp, 3, objv, "" + "?? ??"); + return TCL_ERROR; + } + namespacePtr = NULL; + len = 0; + attData = NULL; + if (objc == 6) { + namespacePtr = getNamespacePtr (sdata, + Tcl_GetString (objv[5])); + } + if (objc >= 5) { + if (Tcl_ListObjLength (interp, objv[4], &len) != TCL_OK) { + if (objc == 6) { + SetResult ("Invalid attribute information"); + return TCL_ERROR; + } else { + namespacePtr = + getNamespacePtr (sdata, Tcl_GetString (objv[4])); + len = 0; + } + } else { + if (len == 1) { + namespacePtr = + getNamespacePtr (sdata, Tcl_GetString (objv[4])); + len = 0; + } else if (len % 2 != 0) { + SetResult ("Invalid attribute information"); + return TCL_ERROR; + } else { + attData = objv[4]; + } + } + } + result = tDOM_probeElement (interp, sdata, Tcl_GetString (objv[3]), + namespacePtr); + /* In case of UNKNOWN_ROOT_ELEMENT and reportCmd is set + * sdata->stack is NULL. */ + if (!sdata->stack) break; + if (sdata->skipDeep == 0 && result == TCL_OK) { + result = probeEventAttribute (interp, sdata, attData, len); + } + break; + + case k_elementend: + if (objc != 3) { + Tcl_WrongNumArgs (interp, 3, objv, "No arguments expected."); + return TCL_ERROR; + } + result = tDOM_probeElementEnd (interp, sdata); + break; + + case k_text: + if (objc != 4) { + Tcl_WrongNumArgs (interp, 3, objv, ""); + return TCL_ERROR; + } + result = tDOM_probeText (interp, sdata, Tcl_GetString (objv[3]), NULL); + break; + } + break; + + case m_delete: + if (objc != 2) { + Tcl_WrongNumArgs(interp, 2, objv, ""); + return TCL_ERROR; + } + Tcl_DeleteCommand(interp, Tcl_GetString(objv[0])); + /* We return immediately here to avoid clashes with postponed + sdata cleanup at the end of the function. */ + return TCL_OK; + + case m_reset: + CHECK_EVAL + schemaReset (sdata); + break; + + case m_validate: + CHECK_EVAL + if (objc < 3 || objc > 4) { + Tcl_WrongNumArgs (interp, 2, objv, " ?resultVarName?"); + return TCL_ERROR; + } + if (sdata->validationState != VALIDATION_READY) { + SetResult ("The schema command is busy"); + return TCL_ERROR; + } + xmlstr = Tcl_GetStringFromObj (objv[2], &len); + if (validateString (interp, sdata, xmlstr, len) == TCL_OK) { + SetBooleanResult (1); + if (objc == 4) { + Tcl_SetVar (interp, Tcl_GetString (objv[3]), "", 0); + } + } else { + if (objc == 4) { + Tcl_SetVar (interp, Tcl_GetString (objv[3]), + Tcl_GetStringResult (interp), 0); + } + if (sdata->evalError) { + result = TCL_ERROR; + } else { + SetBooleanResult (0); + } + } + schemaReset (sdata); + break; + + case m_validatefile: + CHECK_EVAL + if (objc < 3 || objc > 4) { + Tcl_WrongNumArgs (interp, 2, objv, " ?resultVarName?"); + return TCL_ERROR; + } + if (sdata->validationState != VALIDATION_READY) { + SetResult ("The schema command is busy"); + return TCL_ERROR; + } + if (validateFile (interp, sdata, objv[2]) == TCL_OK) { + SetBooleanResult (1); + if (objc == 4) { + Tcl_SetVar (interp, Tcl_GetString (objv[3]), "", 0); + } + } else { + if (objc == 4) { + Tcl_SetVar (interp, Tcl_GetString (objv[3]), + Tcl_GetStringResult (interp), 0); + } + if (sdata->evalError) { + result = TCL_ERROR; + } else { + SetBooleanResult (0); + } + } + schemaReset (sdata); + break; + + case m_validatechannel: + CHECK_EVAL + if (objc < 3 || objc > 4) { + Tcl_WrongNumArgs (interp, 2, objv, " ?resultVarName?"); + return TCL_ERROR; + } + if (sdata->validationState != VALIDATION_READY) { + SetResult ("The schema command is busy"); + return TCL_ERROR; + } + chan = Tcl_GetChannel(interp, Tcl_GetString (objv[2]), &mode); + if (chan == NULL) { + SetResult ("The channel argument isn't a tcl channel"); + return TCL_ERROR; + } + if (validateChannel (interp, sdata, chan) == TCL_OK) { + SetBooleanResult (1); + if (objc == 4) { + Tcl_SetVar (interp, Tcl_GetString (objv[3]), "", 0); + } + } else { + if (objc == 4) { + Tcl_SetVar (interp, Tcl_GetString (objv[3]), + Tcl_GetStringResult (interp), 0); + } + if (sdata->evalError) { + result = TCL_ERROR; + } else { + SetBooleanResult (0); + } + } + schemaReset (sdata); + break; + + case m_domvalidate: + CHECK_EVAL + if (objc < 3 || objc > 4) { + Tcl_WrongNumArgs (interp, 2, objv, " ?resultVarName?"); + return TCL_ERROR; + } + doc = tcldom_getDocumentFromName (interp, Tcl_GetString (objv[2]), + &errMsg); + if (doc) { + node = doc->documentElement; + } else { + node = tcldom_getNodeFromObj (interp, objv[2]); + if (!node) { + SetResult ("The second argument must be either a " + "document or a element node"); + return TCL_ERROR; + } + } + if (validateDOM (interp, sdata, node) == TCL_OK) { + SetBooleanResult (1); + if (objc == 4) { + Tcl_SetVar (interp, Tcl_GetString (objv[3]), "", 0); + } + } else { + if (objc == 4) { + Tcl_SetVar (interp, Tcl_GetString (objv[3]), + Tcl_GetStringResult (interp), 0); + } + SetBooleanResult (0); + } + schemaReset (sdata); + break; + + case m_info: + objv++; + objc--; + result = schemaInstanceInfoCmd (sdata, interp, objc, objv); + break; + + case m_reportcmd: + if (objc == 2) { + if (sdata->reportCmd) { + Tcl_SetObjResult (interp, sdata->reportCmd); + } else { + Tcl_SetObjResult (interp, Tcl_NewObj()); + } + break; + } + if (objc != 3) { + Tcl_WrongNumArgs (interp, 2, objv, ""); + return TCL_ERROR; + } + if (sdata->reportCmd) { + Tcl_DecrRefCount (sdata->reportCmd); + } + if (strlen (Tcl_GetString (objv[2])) == 0) { + sdata->reportCmd = NULL; + } else { + sdata->reportCmd = objv[2]; + Tcl_IncrRefCount (sdata->reportCmd); + } + break; + + case m_prefixns: + CHECK_RECURSIVE_CALL + if (objc != 2-i && objc != 3-i) { + Tcl_WrongNumArgs (interp, 2-i, objv, "?prefixUriList?"); + return TCL_ERROR; + } + if (!i) {objc--; objv++;} + result = tcldom_prefixNSlist (&sdata->prefixns, interp, objc, objv, + "prefixns"); + if (sdata->prefix.numEntries) { + Tcl_DeleteHashTable (&sdata->prefix); + Tcl_InitHashTable (&sdata->prefix, TCL_STRING_KEYS); + } + if (result == TCL_OK && sdata->prefixns) { + j = 0; + while (sdata->prefixns[j]) { + h1 = Tcl_CreateHashEntry (&sdata->prefix, + sdata->prefixns[j], &hnew); + /* This means: First prefix mapping wins */ + if (hnew) { + h = Tcl_CreateHashEntry (&sdata->namespace, + sdata->prefixns[j+1], &hnew); + Tcl_SetHashValue (h1, Tcl_GetHashKey (&sdata->namespace, + h)); + } + j += 2; + } + } + break; + + case m_defelementtype: + CHECK_RECURSIVE_CALL + if (objc != 5-i && objc != 6-i) { + Tcl_WrongNumArgs (interp, 1-i, objv, " " + " ?? pattern"); + return TCL_ERROR; + } + savedNumPatternList = sdata->numPatternList; + namespacePtr = NULL; + patternIndex = 4-i; + if (objc == 6-i) { + patternIndex = 5-i; + namespacePtr = getNamespacePtr (sdata, Tcl_GetString (objv[4-i])); + } + h = Tcl_CreateHashEntry (&sdata->elementType , Tcl_GetString (objv[2-i]), + &hnew); + pattern = NULL; + if (!hnew) { + pattern = (SchemaCP *) Tcl_GetHashValue (h); + while (pattern) { + if (pattern->namespace == namespacePtr) { + if (pattern->flags & FORWARD_PATTERN_DEF) { + forwardDef = 1; + break; + } + SetResult ("Element type already defined in this " + "namespace"); + return TCL_ERROR; + } + pattern = pattern->next; + } + } + h1 = Tcl_CreateHashEntry (&sdata->element , Tcl_GetString (objv[3-i]), + &hnew1); + if (hnew1) { + thiscp = initSchemaCP (SCHEMA_CTYPE_NAME, namespacePtr, + Tcl_GetString (objv[3-i])); + REMEMBER_PATTERN (thiscp); + thiscp->flags |= PLACEHOLDER_PATTERN_DEF; + Tcl_SetHashValue (h1, thiscp); + } + if (pattern == NULL) { + pattern = initSchemaCP (SCHEMA_CTYPE_NAME, namespacePtr, + Tcl_GetHashKey (&sdata->element, h1)); + pattern->flags |= ELEMENTTYPE_DEF; + pattern->typeName = Tcl_GetHashKey (&sdata->elementType, h); + if (!hnew) { + current = (SchemaCP *) Tcl_GetHashValue (h); + pattern->next = current; + } + REMEMBER_PATTERN (pattern); + Tcl_SetHashValue (h, pattern); + } + + SETASI(sdata); + savedDefineToplevel = sdata->defineToplevel; + savedNamespacePtr = sdata->currentNamespace; + sdata->defineToplevel = 0; + sdata->currentNamespace = namespacePtr; + sdata->cp = pattern; + sdata->numAttr = 0; + sdata->numReqAttr = 0; + sdata->currentAttrs = NULL; + sdata->contentSize = CONTENT_ARRAY_SIZE_INIT; + sdata->evalStub[3] = objv[patternIndex]; + sdata->currentEvals++; + result = Tcl_EvalObjv (interp, 4, sdata->evalStub, TCL_EVAL_GLOBAL); + sdata->currentEvals--; + sdata->currentNamespace = NULL; + pattern->attrs = sdata->currentAttrs; + pattern->numAttr = sdata->numAttr; + pattern->numReqAttr = sdata->numReqAttr; + if (result == TCL_OK) { + if (pattern->numAttr) { + attributeLookupPreparation (sdata, pattern); + } + if (forwardDef) { + sdata->forwardPatternDefs--; + pattern->name = Tcl_GetHashKey (&sdata->element, h1); + pattern->flags &= ~FORWARD_PATTERN_DEF; + } + pattern->defScript = objv[patternIndex]; + Tcl_IncrRefCount (pattern->defScript); + } else { + if (forwardDef) { + pattern->nc = 0; + } + cleanupLastPattern (sdata, savedNumPatternList); + } + sdata->defineToplevel = savedDefineToplevel; + sdata->currentNamespace = savedNamespacePtr; + if (!savedDefineToplevel) { + SETASI(savedsdata); + } + break; + + case m_set: + if (objc < 3 || objc > 4) { + Tcl_WrongNumArgs (interp, 2, objv, "setting ?value?"); + return TCL_ERROR; + } + if (Tcl_GetIndexFromObj (interp, objv[2], setKeywords, + "setting", 0, &keywordIndex) + != TCL_OK) { + return TCL_ERROR; + } + switch ((enum setKeyword) keywordIndex) { + case s_choiceHashThreshold: + if (objc == 4) { + if (Tcl_GetIntFromObj (interp, objv[3], &n) != TCL_OK) { + SetResult ("Invalid threshold value"); + return TCL_ERROR; + } + if (n < 0) { + SetResult ("Invalid threshold value"); + return TCL_ERROR; + } + sdata->choiceHashThreshold = n; + } + SetIntResult (sdata->choiceHashThreshold); + case s_attributeHashThreshold: + if (objc == 4) { + if (Tcl_GetIntFromObj (interp, objv[3], &n) != TCL_OK) { + SetResult ("Invalid threshold value"); + return TCL_ERROR; + } + if (n < 0) { + SetResult ("Invalid threshold value"); + return TCL_ERROR; + } + sdata->attributeHashThreshold = n; + } + SetIntResult (sdata->attributeHashThreshold); + } + break; + + default: + Tcl_SetResult (interp, "unknown method", NULL); + result = TCL_ERROR; + break; + + } + if (sdata->cleanupAfterUse && sdata->currentEvals == 0 + && !(sdata->inuse > 0)) { + schemaInstanceDelete (sdata); + } + return result; +} + + +/* + *---------------------------------------------------------------------------- + * + * tDOM_SchemaObjCmd -- + * + * This procedure is invoked to process the "schema" command. + * See the user documentation for what it does. + * + * Results: + * A standard Tcl result. + * + * Side effects: + * + * + *---------------------------------------------------------------------------- + */ + +int +tDOM_SchemaObjCmd ( + ClientData clientData, + Tcl_Interp *interp, + int objc, + Tcl_Obj *const objv[] + ) +{ + int methodIndex, ind, result = TCL_OK; + SchemaData *sdata; + + static const char *schemaMethods[] = { + "create", NULL + }; + enum schemaMethod { + m_create + }; + + if (objc < 2 || objc > 3) { + Tcl_WrongNumArgs (interp, 1, objv, "subcommand ?argument?"); + return TCL_ERROR; + } + + if (objc == 2) { + methodIndex = m_create; + ind = 1; + } else { + if (Tcl_GetIndexFromObj (interp, objv[1], schemaMethods, + "method", 0, &methodIndex) + != TCL_OK) { + return TCL_ERROR; + } + ind = 2; + } + + Tcl_ResetResult (interp); + switch ((enum schemaMethod) methodIndex) { + case m_create: + sdata = initSchemaData (objv[ind]); + Tcl_CreateObjCommand (interp, Tcl_GetString(objv[ind]), + tDOM_schemaInstanceCmd, + (ClientData) sdata, + schemaInstanceDelete); + Tcl_SetObjResult (interp, objv[ind]); + break; + + default: + Tcl_SetResult (interp, "unknown method", NULL); + result = TCL_ERROR; + break; + + } + return result; +} + +static SchemaQuant +getQuant ( + Tcl_Interp *interp, + SchemaData *sdata, + Tcl_Obj *quantObj, + int *n, + int *m + ) +{ + char *quantStr; + int len; + Tcl_Obj *thisObj; + + *n = 0; + *m = 0; + if (!quantObj) { + return SCHEMA_CQUANT_ONE; + } + quantStr = Tcl_GetStringFromObj (quantObj, &len); + if (len == 1) { + switch (quantStr[0]) { + case '!': + return SCHEMA_CQUANT_ONE; + case '*': + return SCHEMA_CQUANT_REP; + case '?': + return SCHEMA_CQUANT_OPT; + case '+': + return SCHEMA_CQUANT_PLUS; + } + } + if (Tcl_ListObjLength (interp, quantObj, &len) != TCL_OK) { + SetResult ("Invalid quant specifier"); + return SCHEMA_CQUANT_ERROR; + } + if (len != 1 && len != 2) { + SetResult ("Invalid quant specifier"); + return SCHEMA_CQUANT_ERROR; + } + if (len == 1) { + if (Tcl_GetIntFromObj (interp, quantObj, n) != TCL_OK) { + SetResult ("Invalid quant specifier"); + return SCHEMA_CQUANT_ERROR; + } + if (*n < 1) { + SetResult ("Invalid quant specifier"); + return SCHEMA_CQUANT_ERROR; + } + if (*n == 1) { + return SCHEMA_CQUANT_ONE; + *n = 0; + } + return SCHEMA_CQUANT_NM; + } + /* The "list-ness" of the quantObj is already checked by the + * Tcl_ListObjLength() call above, no need to check result. */ + Tcl_ListObjIndex (interp, quantObj, 0, &thisObj); + if (Tcl_GetIntFromObj (interp, thisObj, n) != TCL_OK) { + SetResult ("Invalid quant specifier"); + return SCHEMA_CQUANT_ERROR; + } + if (*n < 0) { + SetResult ("Invalid quant specifier"); + return SCHEMA_CQUANT_ERROR; + } + Tcl_ListObjIndex (interp, quantObj, 1, &thisObj); + if (Tcl_GetIntFromObj (interp, thisObj, m) != TCL_OK) { + SetResult ("Invalid quant specifier"); + return SCHEMA_CQUANT_ERROR; + } + if (*n > *m) { + SetResult ("Invalid quant specifier"); + return SCHEMA_CQUANT_ERROR; + } + if (*n == 0 && *m == 1) { + return SCHEMA_CQUANT_OPT; + } + if (*n == 1 && *m == 1) { + return SCHEMA_CQUANT_ONE; + } + return SCHEMA_CQUANT_NM; +} + +/* Implements the schema definition command "any" */ +static int +AnyPatternObjCmd ( + ClientData clientData, + Tcl_Interp *interp, + int objc, + Tcl_Obj *const objv[] + ) +{ + SchemaData *sdata = GETASI; + SchemaCP *pattern; + SchemaQuant quant; + char *ns = NULL; + int n, m; + + CHECK_SI + CHECK_TOPLEVEL + checkNrArgs (1,3,"?namespace? ?quant?"); + if (objc == 1) { + quant = SCHEMA_CQUANT_ONE; + n = 0; m = 0; + } else if (objc == 2) { + quant = getQuant (interp, sdata, objv[1], &n, &m); + if (quant == SCHEMA_CQUANT_ERROR) { + ns = getNamespacePtr (sdata, Tcl_GetString (objv[1])); + quant = SCHEMA_CQUANT_ONE; + } + } else { + ns = getNamespacePtr (sdata, Tcl_GetString (objv[1])); + quant = getQuant (interp, sdata, objv[2], &n, &m); + if (quant == SCHEMA_CQUANT_ERROR) { + return TCL_ERROR; + } + } + pattern = initSchemaCP (SCHEMA_CTYPE_ANY, ns, NULL); + REMEMBER_PATTERN (pattern) + addToContent(sdata, pattern, quant, n, m); + return TCL_OK; +} + +static int +evalDefinition ( + Tcl_Interp *interp, + SchemaData *sdata, + Tcl_Obj *definition, + SchemaCP *pattern, + SchemaQuant quant, + int n, + int m + ) +{ + SchemaCP *savedCP; + SchemaAttr **savedCurrentAttrs; + unsigned int savedContenSize; + unsigned int savedAttrSize, savedNumAttr, savedNumReqAttr; + int result, i, onlyName, hnew; + Tcl_HashEntry *h; + Tcl_HashTable *t; + + /* Save some state of sdata .. */ + savedCP = sdata->cp; + savedContenSize = sdata->contentSize; + savedNumAttr = sdata->numAttr; + savedNumReqAttr = sdata->numReqAttr; + savedAttrSize = sdata->attrSize; + savedCurrentAttrs = sdata->currentAttrs; + /* ... and prepare sdata for definition evaluation. */ + sdata->cp = pattern; + sdata->contentSize = CONTENT_ARRAY_SIZE_INIT; + sdata->numAttr = 0; + sdata->numReqAttr = 0; + sdata->currentAttrs = NULL; + sdata->attrSize = 0; + + sdata->currentEvals++; + result = Tcl_EvalObjEx (interp, definition, TCL_EVAL_DIRECT); + sdata->currentEvals--; + + pattern->attrs = sdata->currentAttrs; + pattern->numAttr = sdata->numAttr; + pattern->numReqAttr = sdata->numReqAttr; + /* ... and restore the previously saved sdata states */ + sdata->cp = savedCP; + sdata->contentSize = savedContenSize; + sdata->numAttr = savedNumAttr; + sdata->numReqAttr = savedNumReqAttr; + sdata->currentAttrs = savedCurrentAttrs; + sdata->attrSize = savedAttrSize; + + if (result != TCL_OK) { + freeSchemaCP (pattern); + return result; + } + + REMEMBER_PATTERN (pattern); + if (pattern->numAttr) { + attributeLookupPreparation (sdata, pattern); + } + if (pattern->type == SCHEMA_CTYPE_CHOICE) { + onlyName = 1; + for (i = 0; i < pattern->nc; i++) { + if (pattern->content[i]->type != SCHEMA_CTYPE_NAME + && pattern->content[i]->type != SCHEMA_CTYPE_TEXT) { + onlyName = 0; + break; + } + } + if (onlyName && pattern->nc > sdata->choiceHashThreshold) { + t = TMALLOC (Tcl_HashTable); + Tcl_InitHashTable (t, TCL_ONE_WORD_KEYS); + hnew = 1; + for (i = 0; i < pattern->nc; i++) { + if (pattern->content[i]->type != SCHEMA_CTYPE_NAME) { + continue; + } + h = Tcl_CreateHashEntry (t, pattern->content[i]->name, &hnew); + if (!hnew) { + break; + } + Tcl_SetHashValue (h, pattern->content[i]); + } + if (hnew) { + pattern->typedata = (void *)t; + } else { + /* No simple lookup possible because of more than one + * element with the same local name belong to the + * choices. Rewind. */ + Tcl_DeleteHashTable (t); + FREE (t); + } + } + } + addToContent (sdata, pattern, quant, n, m); + return TCL_OK; +} + +/* Implements the schema definition commands "element", "elementtype" + * and "ref" */ +static int +NamedPatternObjCmd ( + ClientData clientData, + Tcl_Interp *interp, + int objc, + Tcl_Obj *const objv[] + ) +{ + SchemaData *sdata = GETASI; + Schema_CP_Type patternType = (Schema_CP_Type) clientData; + Tcl_HashTable *hashTable; + Tcl_HashEntry *h; + SchemaCP *pattern = NULL, *current; + SchemaQuant quant; + int hnew, n, m; + + CHECK_SI + CHECK_TOPLEVEL + if (clientData == 0) { + checkNrArgs (2,4,"Expected: elementName ?quant? ?pattern?"); + patternType = SCHEMA_CTYPE_NAME; + hashTable = &sdata->element; + } else if (clientData == (ClientData) 1) { + checkNrArgs (2,3,"Expected: elementtypeName ?quant?"); + patternType = SCHEMA_CTYPE_NAME; + hashTable = &sdata->elementType; + } else { + checkNrArgs (2,3,"Expected: patternName ?quant?"); + patternType = SCHEMA_CTYPE_PATTERN; + hashTable = &sdata->pattern; + } + + quant = getQuant (interp, sdata, objc == 2 ? NULL : objv[2], &n, &m); + if (quant == SCHEMA_CQUANT_ERROR) { + return TCL_ERROR; + } + h = Tcl_CreateHashEntry (hashTable, Tcl_GetString(objv[1]), &hnew); + if (objc < 4) { + /* Reference to an element, elementtype or pattern */ + if (!hnew) { + pattern = (SchemaCP *) Tcl_GetHashValue (h); + while (pattern) { + if (pattern->namespace == sdata->currentNamespace) { + break; + } + pattern = pattern->next; + } + } + if (!pattern) { + pattern = initSchemaCP ( + patternType, + sdata->currentNamespace, + Tcl_GetHashKey (hashTable, h) + ); + if (clientData == (ClientData) 1) { + pattern->typeName = pattern->name; + pattern->name = NULL; + pattern->flags |= ELEMENTTYPE_DEF; + } + pattern->flags |= FORWARD_PATTERN_DEF; + sdata->forwardPatternDefs++; + if (!hnew) { + current = (SchemaCP *) Tcl_GetHashValue (h); + pattern->next = current; + } + REMEMBER_PATTERN (pattern); + Tcl_SetHashValue (h, pattern); + } + addToContent (sdata, pattern, quant, n, m); + } else { + /* Local definition of this element */ + if (hnew) { + pattern = initSchemaCP( + SCHEMA_CTYPE_NAME, + sdata->currentNamespace, + Tcl_GetHashKey (hashTable, h) + ); + pattern->flags |= PLACEHOLDER_PATTERN_DEF; + REMEMBER_PATTERN (pattern); + Tcl_SetHashValue (h, pattern); + } + pattern = initSchemaCP ( + SCHEMA_CTYPE_NAME, + sdata->currentNamespace, + Tcl_GetHashKey (hashTable, h) + ); + pattern->flags |= LOCAL_DEFINED_ELEMENT; + return evalDefinition (interp, sdata, objv[3], pattern, quant, n, m); + } + return TCL_OK; +} + +/* Implements the schema definition commands "choice", "group", + * "interleave" and "mixed" */ +static int +AnonPatternObjCmd ( + ClientData clientData, + Tcl_Interp *interp, + int objc, + Tcl_Obj *const objv[] + ) +{ + SchemaData *sdata = GETASI; + Schema_CP_Type patternType; + SchemaQuant quant; + SchemaCP *pattern; + int n, m; + + CHECK_SI + CHECK_TOPLEVEL + checkNrArgs (2,3,"Expected: ?quant? definition"); + + quant = getQuant (interp, sdata, objc == 2 ? NULL : objv[1], &n, &m); + if (quant == SCHEMA_CQUANT_ERROR) { + return TCL_ERROR; + } + if (clientData == 0) { + patternType = SCHEMA_CTYPE_CHOICE; + } else if (clientData == (ClientData) 1) { + patternType = SCHEMA_CTYPE_CHOICE; + /* Default quant for mixed is * */ + if (objc == 2) { + quant = SCHEMA_CQUANT_REP; + } + } else if (clientData == (ClientData) 2) { + patternType = SCHEMA_CTYPE_INTERLEAVE; + } else { + patternType = SCHEMA_CTYPE_PATTERN; + } + + pattern = initSchemaCP (patternType, NULL, NULL); + if (clientData == (ClientData) 1) { + pattern->flags |= MIXED_CONTENT; + } + return evalDefinition (interp, sdata, objc == 2 ? objv[1] : objv[2], + pattern, quant, n, m); +} + +static int maybeAddAttr ( + Tcl_Interp *interp, + SchemaData *sdata, + Tcl_Obj *nameObj, + Tcl_Obj *namespaceObj, + Tcl_Obj *scriptObj, + int required, + SchemaCP *type + ) +{ + Tcl_HashEntry *h; + int hnew, i, result = TCL_OK; + char *name, *namespace = NULL; + SchemaAttr *attr; + SchemaCP *cp; + + if (namespaceObj) { + namespace = getNamespacePtr (sdata, + Tcl_GetString (namespaceObj)); + } + h = Tcl_CreateHashEntry (&sdata->attrNames, + Tcl_GetString (nameObj), &hnew); + name = Tcl_GetHashKey (&sdata->attrNames, h); + if (!hnew) { + /* Check, if there is already an attribute with this name + and namespace */ + for (i = 0; i < sdata->numAttr; i++) { + if (sdata->currentAttrs[i]->name == name + && sdata->currentAttrs[i]->namespace == namespace) { + /* Ignore the later attribute declaration */ + return TCL_OK; + } + } + } + attr = TMALLOC (SchemaAttr); + attr->namespace = namespace; + attr->name = name; + attr->next = NULL; + attr->required = required; + if (scriptObj) { + cp = initSchemaCP (SCHEMA_CTYPE_CHOICE, NULL, NULL); + cp->type = SCHEMA_CTYPE_TEXT; + REMEMBER_PATTERN (cp) + sdata->isAttributeConstaint = 1; + result = evalConstraints (interp, sdata, cp, scriptObj); + sdata->isAttributeConstaint = 0; + attr->cp = cp; + } else if (type) { + attr->cp = type; + } else { + attr->cp = NULL; + } + if (!sdata->currentAttrs) { + sdata->currentAttrs = MALLOC (sizeof(SchemaAttr*) + * ATTR_ARRAY_INIT); + sdata->attrSize = ATTR_ARRAY_INIT; + } else if (sdata->numAttr == sdata->attrSize) { + sdata->currentAttrs = + REALLOC (sdata->currentAttrs, 2 * sdata->attrSize + * sizeof (SchemaAttr)); + sdata->attrSize *= 2; + } + sdata->currentAttrs[sdata->numAttr] = attr; + sdata->numAttr++; + if (required) { + sdata->numReqAttr++; + } + return result; +} + +static int +AttributePatternObjCmd ( + ClientData clientData, + Tcl_Interp *interp, + int objc, + Tcl_Obj *const objv[] + ) +{ + SchemaData *sdata = GETASI; + char *str; + int len, required = 1; + Tcl_Obj *nsObj, *nameObj; + Tcl_HashEntry *h; + SchemaCP *type; + + CHECK_SI + CHECK_TOPLEVEL + + if (sdata->cp->type != SCHEMA_CTYPE_NAME) { + SetResult ("The commands attribute and nsattribute are only allowed toplevel in element definition scripts"); + return TCL_ERROR; + } + if (clientData) { + checkNrArgs (3,6,"Expected:" + " name namespace" + " | name namespace attquant" + " | name namespace ?attquant? " + " | name namespace ?attquant? \"type\" typename"); + nsObj = objv[2]; + } else { + checkNrArgs (2,5,"Expected:" + " name" + " | name attquant" + " | name ?attquant? " + " | name ?attquant? \"type\" typename"); + nsObj = NULL; + } + nameObj = objv[1]; + if (clientData) { + objv++; + objc--; + } + if (objc == 2) { + return maybeAddAttr (interp, sdata, nameObj, nsObj, NULL, 1, NULL); + } + str = Tcl_GetStringFromObj (objv[2], &len); + if (len == 1) { + if (str[0] == '?') { + required = 0; + } else if (str[0] != '!') { + SetResult ("Invalid attribute quant"); + return TCL_ERROR; + } + if (objc == 3) { + return maybeAddAttr (interp, sdata, nameObj, nsObj, NULL, + required, NULL); + } + objv++; + objc--; + str = Tcl_GetStringFromObj (objv[2], &len); + } + if (objc == 4) { + if (len != 4 + || strcmp("type", str) != 0) { + if (clientData) { + SetResult ("Expected:" + " name namespace" + " | name namespace attquant" + " | name namespace ?attquant? " + " | name namespace ?attquant? \"type\" typename"); + } else { + SetResult ("Expected:" + " name" + " | name attquant" + " | name ?attquant? " + " | name ?attquant? \"type\" typename"); + } + return TCL_ERROR; + } + h = Tcl_FindHashEntry (&sdata->textDef, Tcl_GetString (objv[3])); + if (!h) { + SetResult3 ("Unknown text type \"", Tcl_GetString (objv[3]), "\""); + return TCL_ERROR; + } + type = (SchemaCP *) Tcl_GetHashValue (h); + return maybeAddAttr (interp, sdata, nameObj, nsObj, NULL, + required, type); + } else { + return maybeAddAttr (interp, sdata, nameObj, nsObj, objv[2], + required, NULL); + } +} + +static int +NamespacePatternObjCmd ( + ClientData clientData, + Tcl_Interp *interp, + int objc, + Tcl_Obj *const objv[] + ) +{ + SchemaData *sdata = GETASI; + char *currentNamespace; + int result; + + CHECK_SI + CHECK_TOPLEVEL + checkNrArgs (3,3,"Expected: namespace pattern"); + + currentNamespace = sdata->currentNamespace; + sdata->currentNamespace = + getNamespacePtr (sdata, Tcl_GetString(objv[1])); + sdata->currentEvals++; + result = Tcl_EvalObjEx (interp, objv[2], TCL_EVAL_DIRECT); + sdata->currentEvals--; + sdata->currentNamespace = currentNamespace; + return result; +} + +static int +TextPatternObjCmd ( + ClientData clientData, + Tcl_Interp *interp, + int objc, + Tcl_Obj *const objv[] + ) +{ + SchemaData *sdata = GETASI; + SchemaQuant quant = SCHEMA_CQUANT_OPT; + SchemaCP *pattern; + Tcl_HashEntry *h; + int result = TCL_OK; + + CHECK_SI + CHECK_TOPLEVEL + checkNrArgs (1,3,"?? | type "); + if (objc == 1) { + pattern = initSchemaCP (SCHEMA_CTYPE_TEXT, NULL, NULL); + } else if (objc == 2) { + quant = SCHEMA_CQUANT_ONE; + pattern = initSchemaCP (SCHEMA_CTYPE_CHOICE, NULL, NULL); + pattern->type = SCHEMA_CTYPE_TEXT; + } else { + if (strcmp("type", Tcl_GetString (objv[1])) != 0) { + SetResult ("Expected: ?? | type "); + return TCL_ERROR; + } + h = Tcl_FindHashEntry (&sdata->textDef, Tcl_GetString (objv[2])); + if (!h) { + SetResult3 ("Unknown text type \"", Tcl_GetString (objv[2]), "\""); + return TCL_ERROR; + } + quant = SCHEMA_CQUANT_ONE; + pattern = (SchemaCP *) Tcl_GetHashValue (h); + } + if (objc == 2) { + result = evalConstraints (interp, sdata, pattern, objv[1]); + } + if (result == TCL_OK) { + if (objc < 3) { + REMEMBER_PATTERN (pattern) + } + addToContent (sdata, pattern, quant, 0, 0); + } else { + freeSchemaCP (pattern); + } + return result; +} + +static int +VirtualPatternObjCmd ( + ClientData clientData, + Tcl_Interp *interp, + int objc, + Tcl_Obj *const objv[] + ) +{ + SchemaData *sdata = GETASI; + SchemaCP *pattern; + int i; + + CHECK_SI + CHECK_TOPLEVEL + if (objc < 2) { + SetResult ("Expected: ?arg? ?arg? ..."); + return TCL_ERROR; + } + + if (sdata->cp->type != SCHEMA_CTYPE_NAME + && sdata->cp->type != SCHEMA_CTYPE_PATTERN) { + SetResult ("The \"tcl\" schema definition command is only " + "allowed in sequential context (defelement, " + "element, group or defpattern)"); + return TCL_ERROR; + } + + pattern = initSchemaCP (SCHEMA_CTYPE_VIRTUAL, NULL, NULL); + REMEMBER_PATTERN (pattern) + pattern->content = MALLOC (sizeof (Tcl_Obj*) * (objc-1)); + for (i = 0; i < objc-1; i++) { + pattern->content[i] = (SchemaCP *) objv[i+1]; + Tcl_IncrRefCount (objv[i+1]); + } + pattern->nc = objc-1; + addToContent (sdata, pattern, SCHEMA_CQUANT_ONE, 0, 0); + return TCL_OK; +} + +static int +SelfObjCmd ( + ClientData clientData, + Tcl_Interp *interp, + int objc, + Tcl_Obj *const objv[] + ) +{ + SchemaData *sdata = GETASI; + + CHECK_SI + CHECK_TOPLEVEL + if (objc != 1) { + SetResult ("No argument expected"); + return TCL_ERROR; + } + Tcl_SetObjResult (interp, Tcl_DuplicateObj (sdata->self)); + return TCL_OK; +} + +static int +domuniquePatternObjCmd ( + ClientData clientData, + Tcl_Interp *interp, + int objc, + Tcl_Obj *const objv[] + ) +{ + SchemaData *sdata = GETASI; + ast t; + char *errMsg = NULL; + domKeyConstraint *kc, *kc1; + int i, nrFields, flags = 0; + Tcl_Obj *elm; + + CHECK_SI + CHECK_TOPLEVEL + checkNrArgs (3, 6, "Expected: ?? ?\"IGNORE_EMPTY_FIELD_SET\"|(?\"EMPTY_FIELD_SET_VALUE\" cp->type != SCHEMA_CTYPE_NAME) { + SetResult ("The domunique schema definition command is only " + "allowed as direct child of an element."); + } + if (Tcl_ListObjLength (interp, objv[2], &nrFields) != TCL_OK) { + SetResult ("The argument must be a valid tcl list"); + return TCL_ERROR; + } + if (nrFields == 0) { + SetResult ("Non empty fieldlist argument expected."); + return TCL_ERROR; + } + if (objc == 5) { + if (strcmp (Tcl_GetString (objv[4]), "IGNORE_EMPTY_FIELD_SET") != 0) { + SetResult3 ("Unknown flag '", Tcl_GetString (objv[4]), "'"); + return TCL_ERROR; + } + flags |= DKC_FLAG_IGNORE_EMPTY_FIELD_SET; + } + if (objc == 6) { + if (strcmp (Tcl_GetString (objv[4]), "EMPTY_FIELD_SET_VALUE") != 0) { + SetResult3 ("Unknown flag '", Tcl_GetString (objv[4]), "'"); + return TCL_ERROR; + } + } + + if (xpathParse (Tcl_GetString (objv[1]), NULL, XPATH_EXPR, + sdata->prefixns, NULL, &t, &errMsg) < 0) { + SetResult3 ("Error in selector xpath: '", errMsg, ""); + FREE (errMsg); + return TCL_ERROR; + } + + kc = TMALLOC (domKeyConstraint); + memset (kc, 0, sizeof (domKeyConstraint)); + kc->fields = MALLOC (sizeof (ast) * nrFields); + memset (kc->fields, 0, sizeof (ast) * nrFields); + kc->nrFields = nrFields; + kc->selector = t; + kc->flags = flags; + for (i = 0; i < nrFields; i++) { + Tcl_ListObjIndex (interp, objv[2], i, &elm); + if (xpathParse (Tcl_GetString (elm), NULL, XPATH_EXPR, + sdata->prefixns, NULL, &t, &errMsg) < 0) { + SetResult3 ("Error in field xpath: '", errMsg, ""); + FREE (errMsg); + xpathFreeAst (t); + freedomKeyConstraints (kc); + return TCL_ERROR; + } + kc->fields[i] = t; + } + if (objc >= 4) { + kc->name = tdomstrdup (Tcl_GetString (objv[3])); + } + if (objc == 6) { + kc->emptyFieldSetValue = tdomstrdup (Tcl_GetString (objv[5])); + kc->efsv_len = strlen (kc->emptyFieldSetValue); + } + /* Apppend to end so that the constraints are checked in + * definition order */ + if (sdata->cp->domKeys) { + kc1 = sdata->cp->domKeys; + while (1) { + if (kc1->next) kc1 = kc1->next; + else break; + } + kc1->next = kc; + } else { + sdata->cp->domKeys = kc; + } + return TCL_OK; +} + +static int +domxpathbooleanPatternObjCmd ( + ClientData clientData, + Tcl_Interp *interp, + int objc, + Tcl_Obj *const objv[] + ) +{ + SchemaData *sdata = GETASI; + ast t; + char *errMsg = NULL; + domKeyConstraint *kc, *kc1; + + CHECK_SI + CHECK_TOPLEVEL + checkNrArgs (2, 3, "Expected: ??"); + if (sdata->cp->type != SCHEMA_CTYPE_NAME) { + SetResult ("The domxpathboolean schema definition command is only " + "allowed as direct child of an element."); + } + if (xpathParse (Tcl_GetString (objv[1]), NULL, XPATH_EXPR, + sdata->prefixns, NULL, &t, &errMsg) < 0) { + SetResult3 ("Error in selector xpath: '", errMsg, ""); + FREE (errMsg); + return TCL_ERROR; + } + + kc = TMALLOC (domKeyConstraint); + memset (kc, 0, sizeof (domKeyConstraint)); + kc->selector = t; + kc->flags |= DKC_FLAG_BOOLEAN; + if (objc == 3) { + kc->name = tdomstrdup (Tcl_GetString (objv[2])); + } + /* Apppend to end so that the constraints are checked in + * definition order */ + if (sdata->cp->domKeys) { + kc1 = sdata->cp->domKeys; + while (1) { + if (kc1->next) kc1 = kc1->next; + else break; + } + kc1->next = kc; + } else { + sdata->cp->domKeys = kc; + } + return TCL_OK; +} + +static int +keyspacePatternObjCmd ( + ClientData clientData, + Tcl_Interp *interp, + int objc, + Tcl_Obj *const objv[] + ) +{ + SchemaData *sdata = GETASI; + SchemaCP *pattern; + int nrKeyspaces, i, hnew; + Tcl_Obj *ksObj; + SchemaKeySpace *ks; + Tcl_HashEntry *h; + + CHECK_SI + CHECK_TOPLEVEL + checkNrArgs (3, 3, "Expected: pattern"); + if (sdata->cp->type != SCHEMA_CTYPE_NAME + && sdata->cp->type != SCHEMA_CTYPE_PATTERN) { + SetResult ("The keyspace schema definition command is only " + "allowed in sequential context (defelement, " + "element or defpattern)"); + return TCL_ERROR; + } + if (Tcl_ListObjLength (interp, objv[1], &nrKeyspaces) != TCL_OK) { + SetResult ("The argument must be a valid tcl " + "list"); + return TCL_ERROR; + } + for (i = 0; i < nrKeyspaces; i++) { + Tcl_ListObjIndex (interp, objv[1], i, &ksObj); + h = Tcl_CreateHashEntry (&sdata->keySpaces, + Tcl_GetString (ksObj), &hnew); + if (hnew) { + ks = TMALLOC (SchemaKeySpace); + ks->name = Tcl_GetHashKey (&sdata->keySpaces, h); + ks->active = 0; + ks->unknownIDrefs = 0; + Tcl_SetHashValue (h, ks); + } else { + ks = Tcl_GetHashValue (h); + } + pattern = initSchemaCP (SCHEMA_CTYPE_KEYSPACE, + Tcl_GetString (ksObj), NULL); + pattern->keySpace = ks; + REMEMBER_PATTERN (pattern); + addToContent (sdata, pattern, SCHEMA_CQUANT_ONE, 0, 0); + } + sdata->currentEvals++; + if (Tcl_EvalObjEx (interp, objv[2], TCL_EVAL_DIRECT) != TCL_OK) { + return TCL_ERROR; + } + sdata->currentEvals--; + for (i = 0; i < nrKeyspaces; i++) { + Tcl_ListObjIndex (interp, objv[1], i, &ksObj); + h = Tcl_FindHashEntry (&sdata->keySpaces, Tcl_GetString(ksObj)); + pattern = initSchemaCP (SCHEMA_CTYPE_KEYSPACE_END, + Tcl_GetString (ksObj), NULL); + REMEMBER_PATTERN (pattern); + pattern->keySpace = Tcl_GetHashValue (h); + addToContent (sdata, pattern, SCHEMA_CQUANT_ONE, 0, 0); + } + return TCL_OK; +} + +static int +associatePatternObjCmd ( + ClientData clientData, + Tcl_Interp *interp, + int objc, + Tcl_Obj *const objv[] + ) +{ + SchemaData *sdata = GETASI; + + CHECK_SI + CHECK_TOPLEVEL + checkNrArgs (2, 2, "Expected: data"); + switch (sdata->cp->type) { + case SCHEMA_CTYPE_NAME: + case SCHEMA_CTYPE_PATTERN: + case SCHEMA_CTYPE_INTERLEAVE: + break; + default: + SetResult ("The associate schema definition command is only " + "allowed inside of global or local element, pattern or " + "interleval context"); + return TCL_ERROR; + } + if (sdata->cp->associated) { + Tcl_DecrRefCount (sdata->cp->associated); + } + sdata->cp->associated = objv[1]; + Tcl_IncrRefCount (sdata->cp->associated); + return TCL_OK; +} + +static int +integerImplXsd ( + Tcl_Interp *interp, + void *constraintData, + char *text + ) +{ + char *c = text; + if (*c == 0) return 0; + switch ((intptr_t)constraintData) { + case 0: + /* integer */ + if (*c == '-' || *c == '+') c++; + break; + case 1: + /* negativeInteger */ + if (*c != '-') return 0; + c++; + while (*c == '0') c++; + break; + case 2: + /* nonNegativeInteger */ + if (*c == '+') c++; + else if (*c == '-') { + c++; + if (*c == '0') { + c++; + while (*c == '0') c++; + if (*c == 0) return 1; + } + return 0; + } + break; + case 3: + /* nonPositiveInteger */ + if (*c == '-') c++; + else { + if (*c == '+') c++; + if (*c == 0) return 0; + while (*c == '0') c++; + if (*c == 0) return 1; + return 0; + } + break; + case 4: + /* positiveInteger */ + if (*c == '+') c++; + while (*c == '0') c++; + break; + } + if (*c == 0) return 0; + while (isdigit(*c)) { + c++; + } + if (*c != 0) return 0; + return 1; +} + +static int +integerImplTcl ( + Tcl_Interp *interp, + void *constraintData, + char *text + ) +{ + int n; + + if (Tcl_GetInt (interp, text, &n) != TCL_OK) { + return 0; + } + switch ((intptr_t)constraintData) { + case 0: + /* integer */ + break; + case 1: + /* negativeInteger */ + if (n >= 0) return 0; + break; + case 2: + /* nonNegativeInteger */ + if (n < 0) return 0; + break; + case 3: + /* nonPositiveInteger */ + if (n > 0) return 0; + break; + case 4: + /* positiveInteger */ + if (n <= 0) return 0; + break; + } + + return 1; +} + +static int +integerTCObjCmd ( + ClientData clientData, + Tcl_Interp *interp, + int objc, + Tcl_Obj *const objv[] + ) +{ + SchemaData *sdata = GETASI; + SchemaConstraint *sc; + int type; + + static const char *types[] = { + "xsd", "tcl", NULL + }; + enum typeSyms { + t_xsd, t_tcl + }; + + CHECK_TI + checkNrArgs (1,2,"?xsd|tcl?"); + if (objc == 1) { + type = t_xsd; + } else { + if (Tcl_GetIndexFromObj (interp, objv[1], types, "type", 0, &type) + != TCL_OK) { + return TCL_ERROR; + } + } + ADD_CONSTRAINT (sdata, sc) + switch ((enum typeSyms) type) { + case t_xsd: + sc->constraint = integerImplXsd; + break; + case t_tcl: + sc->constraint = integerImplTcl; + break; + } + sc->constraintData = clientData; + return TCL_OK; +} + +typedef struct +{ + int nrArg; + Tcl_Obj **evalStub; + SchemaData *sdata; +} tclTCData; + +static void +tclImplFree ( + void *constraintData + ) +{ + tclTCData *tcdata = constraintData; + int i; + + for (i = 0; i < tcdata->nrArg-1; i++) { + Tcl_DecrRefCount (tcdata->evalStub[i]); + } + FREE (tcdata->evalStub); + FREE (tcdata); +} + +static int +tclImpl ( + Tcl_Interp *interp, + void *constraintData, + char *text + ) +{ + tclTCData *tcdata = constraintData; + int result, bool; + + tcdata->evalStub[tcdata->nrArg-1] = Tcl_NewStringObj(text, -1); + Tcl_IncrRefCount (tcdata->evalStub[tcdata->nrArg-1]); + tcdata->sdata->currentEvals++; + result = Tcl_EvalObjv (interp, tcdata->nrArg, tcdata->evalStub, + TCL_EVAL_GLOBAL); + tcdata->sdata->currentEvals--; + Tcl_DecrRefCount (tcdata->evalStub[tcdata->nrArg-1]); + if (result != TCL_OK) { + tcdata->sdata->evalError = 1; + return 0; + } + result = Tcl_GetBooleanFromObj (interp, Tcl_GetObjResult (interp), &bool); + if (result != TCL_OK) { + return 0; + } + if (bool) { + return 1; + } + return 0; +} + +static int +tclTCObjCmd ( + ClientData clientData, + Tcl_Interp *interp, + int objc, + Tcl_Obj *const objv[] + ) +{ + SchemaData *sdata = GETASI; + SchemaConstraint *sc; + tclTCData *tcdata; + int i; + + CHECK_TI + if (objc < 2) { + SetResult ("Expected: tclcmd ?arg arg ...?"); + return TCL_ERROR; + } + ADD_CONSTRAINT (sdata, sc) + sc->constraint = tclImpl; + sc->freeData = tclImplFree; + tcdata = TMALLOC (tclTCData); + tcdata->nrArg = objc; + tcdata->evalStub = MALLOC (sizeof (Tcl_Obj*) * objc); + for (i = 1; i < objc; i++) { + tcdata->evalStub[i-1] = objv[i]; + Tcl_IncrRefCount (tcdata->evalStub[i-1]); + } + tcdata->sdata = sdata; + sc->constraintData = tcdata; + return TCL_OK; +} + +static void +fixedImplFree ( + void *constraintData + ) +{ + FREE (constraintData); +} + +static int +fixedImpl ( + Tcl_Interp *interp, + void *constraintData, + char *text + ) +{ + if (strcmp (text, (char *) constraintData) == 0) { + return 1; + } + return 0; +} + +static int +fixedTCObjCmd ( + ClientData clientData, + Tcl_Interp *interp, + int objc, + Tcl_Obj *const objv[] + ) +{ + SchemaData *sdata = GETASI; + SchemaConstraint *sc; + + CHECK_TI + checkNrArgs (2,2,"Expected: "); + ADD_CONSTRAINT (sdata, sc) + sc->constraint = fixedImpl; + sc->freeData = fixedImplFree; + sc->constraintData = tdomstrdup (Tcl_GetString (objv[1])); + return TCL_OK; +} + +static void +enumerationImplFree ( + void *constraintData + ) +{ + Tcl_HashTable *values = (Tcl_HashTable *) constraintData; + + Tcl_DeleteHashTable (values); + FREE (values); +} + +static int +enumerationImpl ( + Tcl_Interp *interp, + void *constraintData, + char *text + ) +{ + Tcl_HashTable *values = (Tcl_HashTable *) constraintData; + + if (Tcl_FindHashEntry(values, text)) return 1; + return 0; +} + +static int +enumerationTCObjCmd ( + ClientData clientData, + Tcl_Interp *interp, + int objc, + Tcl_Obj *const objv[] + ) +{ + SchemaData *sdata = GETASI; + SchemaConstraint *sc; + Tcl_HashTable *values; + int len, i, hnew; + Tcl_Obj *value; + + CHECK_TI + checkNrArgs (2,2,"Expected: "); + if (Tcl_ListObjLength (interp, objv[1], &len) != TCL_OK) { + SetResult ("The argument must be a valid tcl list"); + return TCL_ERROR; + } + ADD_CONSTRAINT (sdata, sc) + sc->constraint = enumerationImpl; + sc->freeData = enumerationImplFree; + values = TMALLOC (Tcl_HashTable); + Tcl_InitHashTable (values, TCL_STRING_KEYS); + for (i = 0; i < len; i++) { + Tcl_ListObjIndex (interp, objv[1], i, &value); + Tcl_CreateHashEntry (values, Tcl_GetString (value), &hnew); + } + sc->constraintData = values; + return TCL_OK; +} + +static void +matchImplFree ( + void *constraintData + ) +{ + Tcl_DecrRefCount ((Tcl_Obj *) constraintData); +} + +static int +matchImpl ( + Tcl_Interp *interp, + void *constraintData, + char *text + ) +{ + if (Tcl_StringCaseMatch (text, Tcl_GetString ((Tcl_Obj *) constraintData), 0)) + return 1; + return 0; +} + +static int +matchNocaseImpl ( + Tcl_Interp *interp, + void *constraintData, + char *text + ) +{ + if (Tcl_StringCaseMatch (text, Tcl_GetString ((Tcl_Obj *) constraintData), + TCL_MATCH_NOCASE)) + return 1; + return 0; +} + +static int +matchTCObjCmd ( + ClientData clientData, + Tcl_Interp *interp, + int objc, + Tcl_Obj *const objv[] + ) +{ + SchemaData *sdata = GETASI; + SchemaConstraint *sc; + + CHECK_TI + checkNrArgs (2,3,"Expected: ?-nocase? "); + if (objc == 3) { + if (strcmp ("-nocase", Tcl_GetString (objv[1])) != 0) { + SetResult ("Expected: ?-nocase? "); + return TCL_ERROR; + } + objv++; + } + ADD_CONSTRAINT (sdata, sc) + if (objc == 2) { + sc->constraint = matchImpl; + } else { + sc->constraint = matchNocaseImpl; + } + sc->freeData = matchImplFree; + Tcl_IncrRefCount (objv[1]); + sc->constraintData = objv[1]; + return TCL_OK; +} + +static void +regexpImplFree ( + void *constraintData + ) +{ + Tcl_DecrRefCount ((Tcl_Obj *) constraintData); +} + +static int +regexpImpl ( + Tcl_Interp *interp, + void *constraintData, + char *text + ) +{ + Tcl_Obj *textObj; + int rc; + + + textObj = Tcl_NewStringObj(text, -1); + rc = Tcl_RegExpMatchObj (interp, textObj, (Tcl_Obj *) constraintData); + Tcl_DecrRefCount (textObj); + /* rc may be 1, 0, -1 */ + if (rc == 1) { + return 1; + } + return 0; +} + +static int +regexpTCObjCmd ( + ClientData clientData, + Tcl_Interp *interp, + int objc, + Tcl_Obj *const objv[] + ) +{ + SchemaData *sdata = GETASI; + SchemaConstraint *sc; + + CHECK_TI + checkNrArgs (2,2,"Expected: "); + /* Compile it as syntax test (plus caches the complied regexp in + * the internal value) */ + if (!Tcl_GetRegExpFromObj (interp, objv[1], 0)) { + return TCL_ERROR; + } + ADD_CONSTRAINT (sdata, sc) + sc->constraint = regexpImpl; + sc->freeData = regexpImplFree; + Tcl_IncrRefCount (objv[1]); + sc->constraintData = objv[1]; + return TCL_OK; +} + +static int +nmtokenImpl ( + Tcl_Interp *interp, + void *constraintData, + char *text + ) +{ + char *p; + int clen, tokenSeen = 0; + + p = text; + /* Skip leading space */ + while (*p && *p == ' ') { + p++; + } + while (*p && *p != ' ') { + clen = UTF8_CHAR_LEN (*p); + if (!clen) { + SetResult ("Invalid UTF-8 character"); + return 0; + } + if (!UTF8_GET_NAMING_NMTOKEN (p, clen)) { + SetResult ("Attribute value isn't a NMTOKEN"); + return 0; + } + tokenSeen = 1; + p += clen; + } + /* Skip following space */ + while (*p && *p == ' ') { + p++; + } + if (*p) { + SetResult ("Attribute value isn't a NMTOKEN"); + return 0; + } + if (!*p && !tokenSeen) { + SetResult ("Missing NMTOKEN value"); + return 0; + } + return 1; +} + +static int +nmtokenTCObjCmd ( + ClientData clientData, + Tcl_Interp *interp, + int objc, + Tcl_Obj *const objv[] + ) +{ + SchemaData *sdata = GETASI; + SchemaConstraint *sc; + + CHECK_TI + checkNrArgs (1,1,"No arguments expected"); + ADD_CONSTRAINT (sdata, sc) + sc->constraint = nmtokenImpl; + return TCL_OK; +} + +static int +nmtokensImpl ( + Tcl_Interp *interp, + void *constraintData, + char *text + ) +{ + char *p; + int clen, tokenSeen = 0; + + p = text; + /* Skip leading space */ + while (*p && *p == ' ') { + p++; + } + while (*p) { + if (*p == ' ') { + p++; continue; + } + clen = UTF8_CHAR_LEN (*p); + if (!clen) { + SetResult ("Invalid UTF-8 character"); + return 0; + } + if (!UTF8_GET_NAMING_NMTOKEN (p, clen)) { + SetResult ("Invalid charcter: attribute value isn't a NMTOKENS"); + return 0; + } + tokenSeen = 1; + p += clen; + } + /* Any following space is already skipped above */ + if (!tokenSeen) { + SetResult ("Missing NMTOKENS value"); + return 0; + } + return 1; +} + +static int +nmtokensTCObjCmd ( + ClientData clientData, + Tcl_Interp *interp, + int objc, + Tcl_Obj *const objv[] + ) +{ + SchemaData *sdata = GETASI; + SchemaConstraint *sc; + + CHECK_TI + checkNrArgs (1,1,"No arguments expected"); + ADD_CONSTRAINT (sdata, sc) + sc->constraint = nmtokensImpl; + return TCL_OK; +} + +static int +numberImplXsd ( + Tcl_Interp *interp, + void *constraintData, + char *text + ) +{ + char *c = text; + if (!*c) return 0; + if (*c == '-' || *c == '+') c++; + while (isdigit(*c)) { + c++; + } + if (*c == '.') c++; + while (isdigit(*c)) { + c++; + } + if (*c) return 0; + return 1; +} + +static int +numberImplTcl ( + Tcl_Interp *interp, + void *constraintData, + char *text + ) +{ + double d; + + if (Tcl_GetDouble (interp, text, &d) != TCL_OK) { + return 0; + } + return 1; +} + +static int +numberTCObjCmd ( + ClientData clientData, + Tcl_Interp *interp, + int objc, + Tcl_Obj *const objv[] + ) +{ + SchemaData *sdata = GETASI; + SchemaConstraint *sc; + int type; + + static const char *types[] = { + "xsd", "tcl", NULL + }; + enum typeSyms { + t_xsd, t_tcl + }; + + CHECK_TI + checkNrArgs (1,2,"?xsd|tcl?"); + if (objc == 1) { + type = t_xsd; + } else { + if (Tcl_GetIndexFromObj (interp, objv[1], types, "type", 0, &type) + != TCL_OK) { + return TCL_ERROR; + } + } + ADD_CONSTRAINT (sdata, sc) + switch ((enum typeSyms) type) { + case t_xsd: + sc->constraint = numberImplXsd; + break; + case t_tcl: + sc->constraint = numberImplTcl; + break; + } + return TCL_OK; +} + +static int +booleanImplXsd ( + Tcl_Interp *interp, + void *constraintData, + char *text + ) +{ + char *c = text; + switch (*c) { + case '0': + case '1': + c++; + if (*c == 0) return 1; + break; + case 't': + if (strcmp (text, "true") == 0) return 1; + break; + case 'f': + if (strcmp (text, "false") == 0) return 1; + break; + } + return 0; +} + +static int +booleanImplTcl ( + Tcl_Interp *interp, + void *constraintData, + char *text + ) +{ + int b; + + if (Tcl_GetBoolean (interp, text, &b) != TCL_OK) { + return 0; + } + return 1; +} + +static int +booleanTCObjCmd ( + ClientData clientData, + Tcl_Interp *interp, + int objc, + Tcl_Obj *const objv[] + ) +{ + SchemaData *sdata = GETASI; + SchemaConstraint *sc; + int type; + + static const char *types[] = { + "xsd", "tcl", NULL + }; + enum typeSyms { + t_xsd, t_tcl + }; + + CHECK_TI + checkNrArgs (1,2,"?xsd|tcl?"); + if (objc == 1) { + type = t_xsd; + } else { + if (Tcl_GetIndexFromObj (interp, objv[1], types, "type", 0, &type) + != TCL_OK) { + return TCL_ERROR; + } + } + ADD_CONSTRAINT (sdata, sc) + switch ((enum typeSyms) type) { + case t_xsd: + sc->constraint = booleanImplXsd; + break; + case t_tcl: + sc->constraint = booleanImplTcl; + break; + } + return TCL_OK; +} + +static int +isodateImpl ( + Tcl_Interp *interp, + void *constraintData, + char *text + ) +{ + int i, y, m, d, h, min, s, zh, zm, seenNonzero = 0; + + if (constraintData < (void *)2) { + if (*text == '-') { + /* A bce date */ + text++; + } + i = 1; + /* Parse year */ + while (*text >= '0' && *text <= '9') { + if (*text > '0' && !seenNonzero) seenNonzero = i; + text++; + i++; + } + /* Premature end */ + if (i < 5) return 0; + if (i > 5) { + /* The year has more than 4 digits. Only allowed if in fact + * needed (no extra leading zeros). */ + if (seenNonzero > 1) return 0; + } + if (*text != '-') return 0; + /* We only need to know the modulo of the year for 4, 100 and 400, + * for this the 4 last letters are enough */ + y = atoi(text-4); + /* There isn't a year 0. it's either 0001 or -0001 */ + if (!seenNonzero) return 0; + text++; + /* Parse month */ + for (i = 0; i < 2; i++) { + if (*text < '0' || *text > '9') return 0; + text++; + } + if (*text != '-') return 0; + m = atoi(text-2); + if (m < 1 || m > 12) return 0; + text++; + /* Parse day */ + for (i = 0; i < 2; i++) { + if (*text < '0' || *text > '9') return 0; + text++; + } + d = atoi(text-2); + if (d < 1) return 0; + switch (m) { + case 1: + case 3: + case 5: + case 7: + case 8: + case 10: + case 12: + if (d > 31) return 0; + break; + case 4: + case 6: + case 9: + case 11: + if (d > 30) return 0; + break; + case 2: + if (y % 4 == 0 && (y % 100 != 0 || y % 400 == 0)) { + if (d > 29) return 0; + } else { + if (d > 28) return 0; + } + break; + } + } + /* Date part end */ + if (constraintData) { + if (constraintData == (void *)1) { + /* Time part starts */ + if (*text != 'T') return 0; + text++; + } + /* Parse hour part */ + if (*text < '0' || *text > '9') return 0; + h = (*text - 48) * 10; + text++; + if (*text < '0' || *text > '9') return 0; + h += (*text - 48); + if (h > 24) return 0; + text++; + if (*text != ':') return 0; + text++; + /* Parse minute part */ + if (*text < '0' || *text > '9') return 0; + min = (*text - 48) * 10; + text++; + if (*text < '0' || *text > '9') return 0; + min += (*text - 48); + if (min > 59) return 0; + text++; + if (*text != ':') return 0; + text++; + /* Parse seconds part */ + if (*text < '0' || *text > '9') return 0; + s = (*text - 48) * 10; + text++; + if (*text < '0' || *text > '9') return 0; + s += (*text - 48); + if (s > 59) return 0; + text++; + /* Check for optional fraction seconds part */ + if (*text == '.') { + if (h == 24) return 0; + text++; + /* Dangling decimal point is not allowed */ + if (*text < '0' || *text > '9') return 0; + text++; + while (*text >= '0' && *text <= '9') text++; + } + if (h == 24 && (min > 0 || s > 0)) return 0; + } + if (*text == '\0') return 1; + /* Parse optional time zone part */ + switch (*text) { + case 'Z': + text++; + if (*text != '\0') return 0; + break; + case '+': + case '-': + text++; + for (i = 0; i < 2; i++) { + if (*text < '0' || *text > '9') return 0; + text++; + } + if (*text != ':') return 0; + zh = atoi(text-2); + if (zh > 14) return 0; + text++; + for (i = 0; i < 2; i++) { + if (*text < '0' || *text > '9') return 0; + text++; + } + if (*text != '\0') return 0; + zm = atoi(text-2); + if (zh < 14) { + if (zm > 59) return 0; + } else { + if (zm != 0) return 0; + } + break; + default: + return 0; + } + return 1; +} + +static int +dateTCObjCmd ( + ClientData clientData, + Tcl_Interp *interp, + int objc, + Tcl_Obj *const objv[] + ) +{ + SchemaData *sdata = GETASI; + SchemaConstraint *sc; + + CHECK_TI + checkNrArgs (1,1,"No arguments expected"); + ADD_CONSTRAINT (sdata, sc) + sc->constraint = isodateImpl; + sc->constraintData = (void *) 0; + return TCL_OK; +} + +static int +dateTimeTCObjCmd ( + ClientData clientData, + Tcl_Interp *interp, + int objc, + Tcl_Obj *const objv[] + ) +{ + SchemaData *sdata = GETASI; + SchemaConstraint *sc; + + CHECK_TI + checkNrArgs (1,1,"No arguments expected"); + ADD_CONSTRAINT (sdata, sc) + sc->constraint = isodateImpl; + sc->constraintData = (void *) 1; + return TCL_OK; +} + +static int +timeTCObjCmd ( + ClientData clientData, + Tcl_Interp *interp, + int objc, + Tcl_Obj *const objv[] + ) +{ + SchemaData *sdata = GETASI; + SchemaConstraint *sc; + + CHECK_TI + checkNrArgs (1,1,"No arguments expected"); + ADD_CONSTRAINT (sdata, sc) + sc->constraint = isodateImpl; + sc->constraintData = (void *) 2; + return TCL_OK; +} + +static int +maxLengthImpl ( + Tcl_Interp *interp, + void *constraintData, + char *text + ) +{ + unsigned int maxlen = PTR2UINT(constraintData); + int len = 0, clen; + + while (*text != '\0') { + clen = UTF8_CHAR_LEN (*text); + if (!clen) { + SetResult ("Invalid UTF-8 character"); + return 0; + } + len++; + if (len > maxlen) return 0; + text += clen; + } + return 1; +} + +static int +maxLengthTCObjCmd ( + ClientData clientData, + Tcl_Interp *interp, + int objc, + Tcl_Obj *const objv[] + ) +{ + SchemaData *sdata = GETASI; + SchemaConstraint *sc; + int len; + + CHECK_TI + checkNrArgs (2,2,"Expected: "); + if (Tcl_GetIntFromObj (interp, objv[1], &len) != TCL_OK) { + SetResult ("Expected: "); + return TCL_ERROR; + } + if (len < 1) { + SetResult ("The maximum length must be at least 1"); + } + ADD_CONSTRAINT (sdata, sc) + sc->constraint = maxLengthImpl; + sc->constraintData = UINT2PTR(len); + return TCL_OK; +} + +static int +minLengthImpl ( + Tcl_Interp *interp, + void *constraintData, + char *text + ) +{ + unsigned int minlen = PTR2UINT(constraintData); + int len = 0, clen; + while (*text != '\0') { + clen = UTF8_CHAR_LEN (*text); + if (!clen) { + SetResult ("Invalid UTF-8 character"); + return 0; + } + len++; + if (len >= minlen) return 1; + text += clen; + } + return 0; +} + +static int +minLengthTCObjCmd ( + ClientData clientData, + Tcl_Interp *interp, + int objc, + Tcl_Obj *const objv[] + ) +{ + SchemaData *sdata = GETASI; + SchemaConstraint *sc; + int len; + + CHECK_TI + checkNrArgs (2,2,"Expected: "); + if (Tcl_GetIntFromObj (interp, objv[1], &len) != TCL_OK) { + SetResult ("Expected: "); + return TCL_ERROR; + } + if (len < 1) { + SetResult ("The minimum length must be at least 1"); + } + ADD_CONSTRAINT (sdata, sc) + sc->constraint = minLengthImpl; + sc->constraintData = UINT2PTR(len); + return TCL_OK; +} + +static int +oneOfImpl ( + Tcl_Interp *interp, + void *constraintData, + char *text + ) +{ + SchemaCP *cp = (SchemaCP *) constraintData; + SchemaConstraint *sc; + int i; + + /* Look also at checkText */ + for (i = 0; i < cp->nc; i++) { + sc = (SchemaConstraint *) cp->content[i]; + if ((sc->constraint) (interp, sc->constraintData, text)) { + return 1; + } + } + return 0; +} + +static int +oneOfTCObjCmd ( + ClientData clientData, + Tcl_Interp *interp, + int objc, + Tcl_Obj *const objv[] + ) +{ + SchemaData *sdata = GETASI; + SchemaCP *cp; + SchemaConstraint *sc; + int rc; + + CHECK_TI + checkNrArgs (2,2,"Expected: "); + + cp = initSchemaCP (SCHEMA_CTYPE_CHOICE, NULL, NULL); + cp->type = SCHEMA_CTYPE_TEXT; + REMEMBER_PATTERN (cp) + rc = evalConstraints (interp, sdata, cp, objv[1]); + if (rc == TCL_OK) { + ADD_CONSTRAINT (sdata, sc) + sc->constraint = oneOfImpl; + sc->constraintData = (void *)cp; + return TCL_OK; + } + return TCL_ERROR; +} + +static int +allOfTCObjCmd ( + ClientData clientData, + Tcl_Interp *interp, + int objc, + Tcl_Obj *const objv[] + ) +{ + SchemaData *sdata = GETASI; + SchemaCP *cp; + SchemaConstraint *sc; + int rc; + + CHECK_TI + checkNrArgs (2,2,"Expected: "); + + cp = initSchemaCP (SCHEMA_CTYPE_CHOICE, NULL, NULL); + cp->type = SCHEMA_CTYPE_TEXT; + REMEMBER_PATTERN (cp) + rc = evalConstraints (interp, sdata, cp, objv[1]); + if (rc == TCL_OK) { + ADD_CONSTRAINT (sdata, sc) + sc->constraint = checkText; + sc->constraintData = (void *)cp; + return TCL_OK; + } + return TCL_ERROR; +} + +static int +stripImpl ( + Tcl_Interp *interp, + void *constraintData, + char *text + ) +{ + SchemaCP *cp = (SchemaCP *) constraintData; + int rc, restore = 0; + char *end, saved; + + while(SPACE((unsigned char)*text)) text++; + if(*text != 0) { + /* Not white space only */ + /* Trim trailing space */ + end = text + strlen(text) - 1; + while(end > text && SPACE((unsigned char)*end)) end--; + saved = end[1]; + restore = 1; + end[1] = '\0'; + } + rc = checkText (interp, cp, text); + if (restore) end[1] = saved; + return rc; +} + +static int +stripTCObjCmd ( + ClientData clientData, + Tcl_Interp *interp, + int objc, + Tcl_Obj *const objv[] + ) +{ + SchemaData *sdata = GETASI; + SchemaCP *cp; + SchemaConstraint *sc; + int rc; + + CHECK_TI + checkNrArgs (2,2,"Expected: "); + + cp = initSchemaCP (SCHEMA_CTYPE_CHOICE, NULL, NULL); + cp->type = SCHEMA_CTYPE_TEXT; + REMEMBER_PATTERN (cp) + rc = evalConstraints (interp, sdata, cp, objv[1]); + if (rc == TCL_OK) { + ADD_CONSTRAINT (sdata, sc) + sc->constraint = stripImpl; + sc->constraintData = (void *)cp; + return TCL_OK; + } + return TCL_ERROR; +} + +static int +splitWhitespaceImpl ( + Tcl_Interp *interp, + void *constraintData, + char *text + ) +{ + SchemaCP *cp = (SchemaCP *) constraintData; + int rc = 0; + char *p, *end, saved = 0; + + p = text; + while (*p != 0) { + while(SPACE (*p)) p++; + if (*p == 0) break; + end = p; end++; + while (*end != 0 && !SPACE(*end)) end++; + saved = *end; + *end = 0; + rc = checkText (interp, cp, p); + *end = saved; + p = end; + if (!rc) break; + } + return rc; +} + +typedef struct +{ + int nrArg; + Tcl_Obj **evalStub; + SchemaData *sdata; + SchemaCP *cp; +} splitTclTCData; + + +static int +splitTclImpl ( + Tcl_Interp *interp, + void *constraintData, + char *text + ) +{ + splitTclTCData *tcdata = (splitTclTCData *) constraintData; + int rc, listlen, i; + Tcl_Obj *list, *listelm; + + tcdata->evalStub[tcdata->nrArg-1] = Tcl_NewStringObj(text, -1); + Tcl_IncrRefCount (tcdata->evalStub[tcdata->nrArg-1]); + tcdata->sdata->currentEvals++; + rc = Tcl_EvalObjv (interp, tcdata->nrArg, tcdata->evalStub, + TCL_EVAL_GLOBAL); + tcdata->sdata->currentEvals--; + Tcl_DecrRefCount (tcdata->evalStub[tcdata->nrArg-1]); + if (rc != TCL_OK) { + tcdata->sdata->evalError = 1; + return 0; + } + list = Tcl_GetObjResult (interp); + Tcl_IncrRefCount (list); + Tcl_ResetResult (interp); + if (Tcl_ListObjLength (interp, list, &listlen) != TCL_OK) { + Tcl_DecrRefCount (list); + tcdata->sdata->evalError = 1; + return 0; + } + rc = 0; + for (i = 0; i < listlen; i++) { + Tcl_ListObjIndex (interp, list, i, &listelm); + rc = checkText (interp, tcdata->cp, Tcl_GetString (listelm)); + if (!rc) break; + } + Tcl_DecrRefCount (list); + return rc; +} + +static void +splitTclImplFree ( + void *constraintData + ) +{ + splitTclTCData *tcdata = constraintData; + int i; + + for (i = 0; i < tcdata->nrArg-1; i++) { + Tcl_DecrRefCount (tcdata->evalStub[i]); + } + FREE (tcdata->evalStub); + FREE (tcdata); +} + +static int +splitTCObjCmd ( + ClientData clientData, + Tcl_Interp *interp, + int objc, + Tcl_Obj *const objv[] + ) +{ + SchemaData *sdata = GETASI; + SchemaCP *cp; + SchemaConstraint *sc; + int methodIndex, rc, i; + splitTclTCData *tcdata; + + static const char *methods[] = { + "whitespace", "tcl", NULL + }; + enum method { + m_whitespace, m_tcl + }; + + CHECK_TI + if (objc < 2) { + SetResult("Expected: ?type ?args?? "); + return TCL_ERROR; + } + + if (objc == 2) { + methodIndex = m_whitespace; + } else { + if (Tcl_GetIndexFromObj (interp, objv[1], methods, "type", 0, + &methodIndex) != TCL_OK) { + return TCL_ERROR; + } + } + switch ((enum method) methodIndex) { + case m_whitespace: + if (objc > 2) { + SetResult ("Type whitespace expects no argument."); + return TCL_ERROR; + } + break; + case m_tcl: + if (objc < 3) { + SetResult ("Expected: tclcmd ?arg ...?."); + return TCL_ERROR; + } + } + + cp = initSchemaCP (SCHEMA_CTYPE_CHOICE, NULL, NULL); + cp->type = SCHEMA_CTYPE_TEXT; + REMEMBER_PATTERN (cp) + rc = evalConstraints (interp, sdata, cp, objv[objc-1]); + if (rc != TCL_OK) { + return TCL_ERROR; + } + ADD_CONSTRAINT (sdata, sc) + switch ((enum method) methodIndex) { + case m_whitespace: + sc->constraint = splitWhitespaceImpl; + sc->constraintData = cp; + break; + case m_tcl: + sc->constraint = splitTclImpl; + sc->freeData = splitTclImplFree; + tcdata = TMALLOC (splitTclTCData); + tcdata->nrArg = objc - 2; + tcdata->evalStub = MALLOC (sizeof (Tcl_Obj*) * (objc-2)); + for (i = 2; i < objc -1; i++) { + tcdata->evalStub[i-2] = objv[i]; + Tcl_IncrRefCount (tcdata->evalStub[i-2]); + } + tcdata->sdata = sdata; + tcdata->cp = cp; + sc->constraintData = tcdata; + } + return TCL_OK; +} + +static int +idImpl ( + Tcl_Interp *interp, + void *constraintData, + char *text + ) +{ + SchemaData *sdata = (SchemaData *) constraintData; + int hnew; + Tcl_HashEntry *h; + + h = Tcl_CreateHashEntry (&sdata->ids, text, &hnew); + if (hnew) { + Tcl_SetHashValue (h, 1); + return 1; + } + if (Tcl_GetHashValue (h) == 0) { + Tcl_SetHashValue (h, 1); + sdata->unknownIDrefs--; + return 1; + } else { + /* Duplicate ID value */ + return 0; + } +} + +static int +docidImpl ( + Tcl_Interp *interp, + void *constraintData, + char *text + ) +{ + SchemaDocKey *dk = (SchemaDocKey *) constraintData; + int hnew; + Tcl_HashEntry *h; + + h = Tcl_CreateHashEntry (&dk->ids, text, &hnew); + if (hnew) { + Tcl_SetHashValue (h, 1); + return 1; + } + if (Tcl_GetHashValue (h) == 0) { + Tcl_SetHashValue (h, 1); + dk->unknownIDrefs--; + return 1; + } + /* Duplicate ID value */ + return 0; +} + +static int +idTCObjCmd ( + ClientData clientData, + Tcl_Interp *interp, + int objc, + Tcl_Obj *const objv[] + ) +{ + SchemaData *sdata = GETASI; + SchemaConstraint *sc; + Tcl_HashEntry *h; + int hnew; + SchemaDocKey *dk; + + CHECK_TI + checkNrArgs (1,2,"?key_space?"); + ADD_CONSTRAINT (sdata, sc) + if (objc == 1) { + sc->constraint = idImpl; + sc->constraintData = (void *)sdata; + } else { + h = Tcl_CreateHashEntry (&sdata->idTables, Tcl_GetString (objv[1]), + &hnew); + if (hnew) { + dk = TMALLOC (SchemaDocKey); + Tcl_InitHashTable (&dk->ids, TCL_STRING_KEYS); + dk->unknownIDrefs = 0; + Tcl_SetHashValue (h, dk); + } else { + dk = Tcl_GetHashValue (h); + } + sc->constraint = docidImpl; + sc->constraintData = (void *)dk; + } + return TCL_OK; +} + +static int +idrefImpl ( + Tcl_Interp *interp, + void *constraintData, + char *text + ) +{ + SchemaData *sdata = (SchemaData *) constraintData; + int hnew; + Tcl_HashEntry *h; + + h = Tcl_CreateHashEntry (&sdata->ids, text, &hnew); + if (hnew) { + Tcl_SetHashValue (h, 0); + sdata->unknownIDrefs++; + } + return 1; +} + +static int +docidrefImpl ( + Tcl_Interp *interp, + void *constraintData, + char *text + ) +{ + SchemaDocKey *dk = (SchemaDocKey *) constraintData; + int hnew; + Tcl_HashEntry *h; + + h = Tcl_CreateHashEntry (&dk->ids, text, &hnew); + if (hnew) { + Tcl_SetHashValue (h, 0); + dk->unknownIDrefs++; + } + return 1; +} + +static int +idrefTCObjCmd ( + ClientData clientData, + Tcl_Interp *interp, + int objc, + Tcl_Obj *const objv[] + ) +{ + SchemaData *sdata = GETASI; + SchemaConstraint *sc; + Tcl_HashEntry *h; + int hnew; + SchemaDocKey *dk; + + CHECK_TI + checkNrArgs (1,2,"?key_space?"); + ADD_CONSTRAINT (sdata, sc) + if (objc == 1) { + sc->constraint = idrefImpl; + sc->constraintData = (void *)sdata; + } else { + h = Tcl_CreateHashEntry (&sdata->idTables, Tcl_GetString (objv[1]), + &hnew); + if (hnew) { + dk = TMALLOC (SchemaDocKey); + Tcl_InitHashTable (&dk->ids, TCL_STRING_KEYS); + dk->unknownIDrefs = 0; + Tcl_SetHashValue (h, dk); + } else { + dk = Tcl_GetHashValue (h); + } + sc->constraint = docidrefImpl; + sc->constraintData = (void *)dk; + } + return TCL_OK; +} + +static int +keyImpl ( + Tcl_Interp *interp, + void *constraintData, + char *text + ) +{ + SchemaKeySpace *ks = (SchemaKeySpace *) constraintData; + int hnew; + Tcl_HashEntry *h; + + if (!ks->active) return 1; + h = Tcl_CreateHashEntry (&ks->ids, text, &hnew); + if (hnew) { + Tcl_SetHashValue (h, 1); + return 1; + } + if (Tcl_GetHashValue (h) == 0) { + Tcl_SetHashValue (h, 1); + ks->unknownIDrefs--; + return 1; + } else { + /* Duplicate ID value */ + return 0; + } +} + +static int +keyTCObjCmd ( + ClientData clientData, + Tcl_Interp *interp, + int objc, + Tcl_Obj *const objv[] + ) +{ + SchemaData *sdata = GETASI; + SchemaConstraint *sc; + Tcl_HashEntry *h; + int hnew; + SchemaKeySpace *ks; + + CHECK_TI + checkNrArgs (2,2,"key_space"); + ADD_CONSTRAINT (sdata, sc) + h = Tcl_CreateHashEntry (&sdata->keySpaces, Tcl_GetString (objv[1]), &hnew); + if (hnew) { + ks = TMALLOC (SchemaKeySpace); + ks->active = 0; + ks->unknownIDrefs = 0; + Tcl_SetHashValue (h, ks); + } else { + ks = Tcl_GetHashValue (h); + } + sc->constraint = keyImpl; + sc->constraintData = (void *) ks; + return TCL_OK; +} + +static int +keyrefImpl ( + Tcl_Interp *interp, + void *constraintData, + char *text + ) +{ + SchemaKeySpace *ks = (SchemaKeySpace *) constraintData; + int hnew; + Tcl_HashEntry *h; + + if (!ks->active) return 1; + h = Tcl_CreateHashEntry (&ks->ids, text, &hnew); + if (hnew) { + Tcl_SetHashValue (h, 0); + ks->unknownIDrefs++; + } + return 1; +} + +static int +keyrefTCObjCmd ( + ClientData clientData, + Tcl_Interp *interp, + int objc, + Tcl_Obj *const objv[] + ) +{ + SchemaData *sdata = GETASI; + SchemaConstraint *sc; + Tcl_HashEntry *h; + int hnew; + SchemaKeySpace *ks; + + CHECK_TI + checkNrArgs (2,2,"key_space"); + ADD_CONSTRAINT (sdata, sc) + h = Tcl_CreateHashEntry (&sdata->keySpaces, Tcl_GetString (objv[1]), + &hnew); + if (hnew) { + ks = TMALLOC (SchemaKeySpace); + Tcl_InitHashTable (&ks->ids, TCL_STRING_KEYS); + ks->unknownIDrefs = 0; + Tcl_SetHashValue (h, ks); + } else { + ks = Tcl_GetHashValue (h); + } + sc->constraint = keyrefImpl; + sc->constraintData = (void *)ks; + return TCL_OK; +} + +static int +base64Impl ( + Tcl_Interp *interp, + void *constraintData, + char *text + ) +{ + int chars = 0, equals = 0; + + while (*text != '\0') { + if (SPACE(*text)) { + text++; + continue; + } + if ( (*text >= 'A' && *text <= 'Z') + || (*text >= 'a' && *text <= 'z') + || (*text >= '0' && *text <= '9') + || (*text = '+') + || (*text = '/')) { + chars++; + text++; + continue; + } + if (equals < 2 && *text == '=') { + equals++; + text++; + continue; + } + break; + } + if (*text) { + return 0; + } + if ((chars + equals) % 4 != 0) { + return 0; + } + return 1; +} + +static int +base64TCObjCmd ( + ClientData clientData, + Tcl_Interp *interp, + int objc, + Tcl_Obj *const objv[] + ) +{ + SchemaData *sdata = GETASI; + SchemaConstraint *sc; + + CHECK_TI + checkNrArgs (1,1,"No arguments expected"); + ADD_CONSTRAINT (sdata, sc) + sc->constraint = base64Impl; + return TCL_OK; +} + +static int +nameImpl ( + Tcl_Interp *interp, + void *constraintData, + char *text + ) +{ + return domIsNAME (text); +} + +static int +nameTCObjCmd ( + ClientData clientData, + Tcl_Interp *interp, + int objc, + Tcl_Obj *const objv[] + ) +{ + SchemaData *sdata = GETASI; + SchemaConstraint *sc; + + CHECK_TI + checkNrArgs (1,1,"No arguments expected"); + ADD_CONSTRAINT (sdata, sc) + sc->constraint = nameImpl; + return TCL_OK; +} + +static int +ncnameImpl ( + Tcl_Interp *interp, + void *constraintData, + char *text + ) +{ + return domIsNCNAME (text); +} + +static int +ncnameTCObjCmd ( + ClientData clientData, + Tcl_Interp *interp, + int objc, + Tcl_Obj *const objv[] + ) +{ + SchemaData *sdata = GETASI; + SchemaConstraint *sc; + + CHECK_TI + checkNrArgs (1,1,"No arguments expected"); + ADD_CONSTRAINT (sdata, sc) + sc->constraint = ncnameImpl; + return TCL_OK; +} + +static int +qnameImpl ( + Tcl_Interp *interp, + void *constraintData, + char *text + ) +{ + return domIsQNAME (text); +} + +static int +qnameTCObjCmd ( + ClientData clientData, + Tcl_Interp *interp, + int objc, + Tcl_Obj *const objv[] + ) +{ + SchemaData *sdata = GETASI; + SchemaConstraint *sc; + + CHECK_TI + checkNrArgs (1,1,"No arguments expected"); + ADD_CONSTRAINT (sdata, sc) + sc->constraint = qnameImpl; + return TCL_OK; +} + +static int +hexBinaryImpl ( + Tcl_Interp *interp, + void *constraintData, + char *text + ) +{ + int count = 0; + + if (*text == 0) return 0; + while (*text) { + if ((*text >= '0' && *text <= '9') + || (*text >= 'A' && *text <= 'F') + || (*text >= 'a' && *text <= 'f')) { + text++; + count++; + } else return 0; + } + if (count % 2 == 0) return 1; + return 0; +} + +static int +hexBinaryTCObjCmd ( + ClientData clientData, + Tcl_Interp *interp, + int objc, + Tcl_Obj *const objv[] + ) +{ + SchemaData *sdata = GETASI; + SchemaConstraint *sc; + + CHECK_TI + checkNrArgs (1,1,"No arguments expected"); + ADD_CONSTRAINT (sdata, sc) + sc->constraint = hexBinaryImpl; + return TCL_OK; +} + +static int +unsignedIntTypesImpl ( + Tcl_Interp *interp, + void *constraintData, + char *text + ) +{ + char *c; + int count = 0; + int nrDigits[] = {3, 5, 10, 20}; + char *max[] = { + "255", + "65535", + "4294967295", + "18446744073709551615" + }; + + if (*text == '+') text++; + if (*text == 0) return 0; + if (*text == '0') { + text++; + while (*text == '0') text++; + if (*text == 0) return 1; + } + c = text; + while (*text) { + if (*text >= '0' && *text <= '9') { + text++; + count++; + } else return 0; + } + if (count < nrDigits[(intptr_t) constraintData]) return 1; + if (count == nrDigits[(intptr_t) constraintData]) { + if (strcmp (max[(intptr_t) constraintData], c) >= 0) { + return 1; + } + } + return 0; +} + +static int +unsignedIntTypesTCObjCmd ( + ClientData clientData, + Tcl_Interp *interp, + int objc, + Tcl_Obj *const objv[] + ) +{ + SchemaData *sdata = GETASI; + SchemaConstraint *sc; + + CHECK_TI + checkNrArgs (1,1,"No arguments expected"); + ADD_CONSTRAINT (sdata, sc) + sc->constraint = unsignedIntTypesImpl; + sc->constraintData = clientData; + return TCL_OK; +} + +static void +setvarImplFree ( + void *constraintData + ) +{ + FREE (constraintData); +} + +static int +setvarImpl ( + Tcl_Interp *interp, + void *constraintData, + char *text + ) +{ + char *varName = (char *)constraintData; + + if (!Tcl_SetVar (interp, varName, text, TCL_LEAVE_ERR_MSG)) { + return 0; + } + return 1; +} + +static int +setvarTCObjCmd ( + ClientData clientData, + Tcl_Interp *interp, + int objc, + Tcl_Obj *const objv[] + ) +{ + SchemaData *sdata = GETASI; + SchemaConstraint *sc; + + CHECK_TI + checkNrArgs (2,2,""); + ADD_CONSTRAINT (sdata, sc) + sc->constraint = setvarImpl; + sc->freeData = setvarImplFree; + sc->constraintData = tdomstrdup (Tcl_GetString (objv[1])); + return TCL_OK; +} + +typedef struct +{ + SchemaCP *cp; + SchemaData *sdata; +} WhitespaceTCData; + +static void +whitespaceImplFree ( + void *constraintData + ) +{ + WhitespaceTCData *wsdata = (WhitespaceTCData *) constraintData; + + FREE (wsdata); +} + +static int +whitespaceImplReplace ( + Tcl_Interp *interp, + void *constraintData, + char *text + ) +{ + WhitespaceTCData *wsdata = (WhitespaceTCData *) constraintData; + char *p, *c, *alloced; + SchemaData *sdata; + + sdata = wsdata->sdata; + p = text; + c = sdata->wsbuf; + alloced = sdata->wsbuf + sdata->wsbufLen; + while (*p) { + if (*p == '\t' || *p == '\n' || *p == '\r') { + *c = ' '; + } else { + *c = *p; + } + c++; + if (c == alloced) { + sdata->wsbuf = REALLOC (sdata->wsbuf, 2 * sdata->wsbufLen); + c = sdata->wsbuf + sdata->wsbufLen; + sdata->wsbufLen *= 2; + alloced = sdata->wsbuf + sdata->wsbufLen; + } + p++; + } + *c = '\0'; + return checkText (interp, wsdata->cp, sdata->wsbuf); +} + +static int +whitespaceImplCollapse ( + Tcl_Interp *interp, + void *constraintData, + char *text + ) +{ + WhitespaceTCData *wsdata = (WhitespaceTCData *) constraintData; + char *p, *c, *alloced; + SchemaData *sdata; + + sdata = wsdata->sdata; + p = text; + c = sdata->wsbuf; + alloced = sdata->wsbuf + sdata->wsbufLen; + while (SPACE(*p)) p++; + while (*p) { + if (SPACE (*p)) { + *c = ' '; + c++; + if (c == alloced) { + sdata->wsbuf = REALLOC (sdata->wsbuf, 2 * sdata->wsbufLen); + c = sdata->wsbuf + sdata->wsbufLen; + sdata->wsbufLen *= 2; + alloced = sdata->wsbuf + sdata->wsbufLen; + } + p++; + while (SPACE (*p)) p++; + if (!*p) c--; + } else { + *c = *p; + c++; + if (c == alloced) { + sdata->wsbuf = REALLOC (sdata->wsbuf, 2 * sdata->wsbufLen); + c = sdata->wsbuf + sdata->wsbufLen; + sdata->wsbufLen *= 2; + alloced = sdata->wsbuf + sdata->wsbufLen; + } + p++; + } + } + *c = '\0'; + return checkText (interp, wsdata->cp, wsdata->sdata->wsbuf); +} + +static int +whitespaceTCObjCmd ( + ClientData clientData, + Tcl_Interp *interp, + int objc, + Tcl_Obj *const objv[] + ) +{ + SchemaData *sdata = GETASI; + SchemaCP *cp; + SchemaConstraint *sc; + int type; + WhitespaceTCData *wsdata; + + static const char *types[] = { + "preserve", "replace", "collapse", NULL + }; + enum typeSyms { + t_preserve, t_replace, t_collapse + }; + + CHECK_TI + checkNrArgs (3,3,"(\"preserve\"|\"replace\"|\"collapse\") " + ""); + if (Tcl_GetIndexFromObj (interp, objv[1], types, "type", 0, &type) + != TCL_OK) { + return TCL_ERROR; + } + cp = initSchemaCP (SCHEMA_CTYPE_CHOICE, NULL, NULL); + cp->type = SCHEMA_CTYPE_TEXT; + REMEMBER_PATTERN (cp) + if (evalConstraints (interp, sdata, cp, objv[2]) != TCL_OK) { + return TCL_ERROR; + } + if (type == t_preserve) { + ADD_CONSTRAINT (sdata, sc) + sc->constraint = checkText; + sc->constraintData = (void *)cp; + return TCL_OK; + } + ADD_CONSTRAINT (sdata, sc) + sc->freeData = whitespaceImplFree; + if (sdata->wsbufLen == 0) { + sdata->wsbuf = (char *) MALLOC (WHITESPACETC_BUFFER_LEN_INIT); + sdata->wsbufLen = WHITESPACETC_BUFFER_LEN_INIT; + } + wsdata = TMALLOC (WhitespaceTCData); + wsdata->sdata = sdata; + wsdata->cp = cp; + sc->constraintData = (void *)wsdata; + if (type == t_replace) { + sc->constraint = whitespaceImplReplace; + } else { + sc->constraint = whitespaceImplCollapse; + } + return TCL_OK; +} + +static int +notImpl ( + Tcl_Interp *interp, + void *constraintData, + char *text + ) +{ + SchemaCP *cp = (SchemaCP *) constraintData; + SchemaConstraint *sc; + int i; + + /* Look also at checkText and oneOfImpl */ + for (i = 0; i < cp->nc; i++) { + sc = (SchemaConstraint *) cp->content[i]; + if ((sc->constraint) (interp, sc->constraintData, text)) { + return 0; + } + } + return 1; +} + +static int +notTCObjCmd ( + ClientData clientData, + Tcl_Interp *interp, + int objc, + Tcl_Obj *const objv[] + ) +{ + SchemaData *sdata = GETASI; + SchemaCP *cp; + SchemaConstraint *sc; + int rc; + + CHECK_TI + checkNrArgs (2,2,"Expected: "); + + cp = initSchemaCP (SCHEMA_CTYPE_CHOICE, NULL, NULL); + cp->type = SCHEMA_CTYPE_TEXT; + REMEMBER_PATTERN (cp) + rc = evalConstraints (interp, sdata, cp, objv[1]); + if (rc == TCL_OK) { + ADD_CONSTRAINT (sdata, sc) + sc->constraint = notImpl; + sc->constraintData = (void *)cp; + return TCL_OK; + } + return TCL_ERROR; +} + +static int +durationImpl ( + Tcl_Interp *interp, + void *constraintData, + char *text + ) +{ + /* PnYnMnDTnHnMnS */ + int p, n, seen = 0, seenT = 0; + char des[9] = " YMDTHMS"; + + if (*text == '-') { + /* Negative duration is allowed */ + text++; + } + if (*text != 'P') return 0; + text++; + p = 0; + while (*text) { + n = 0; + while (*text >= '0' && *text <= '9') { + n++; + text++; + } + if (!*text) return 0; + if (*text == '.') { + if (p < 4 || !n) return 0; + text++; + if (!*text) return 0; + /* Ensure at least one digit after . */ + if (*text < '0' || *text > '9') return 0; + text++; + while (*text >= '0' && *text <= '9') text++; + if (*text != 'S') return 0; + text++; + if (*text) return 0; + return 1; + } + for (; p < 8; p++) { + if (*text == des[p]) break; + } + if (p == 4) { + if (n) return 0; + seenT = 1; + text++; + if (!*text) return 0; + continue; + } else { + if (!n) return 0; + seen = 1; + } + if (p > 4 && !seenT) return 0; + if (p == 8 || !seen) return 0; + text++; + } + if (!p) return 0; + return 1; +} + +static int +durationTCObjCmd ( + ClientData clientData, + Tcl_Interp *interp, + int objc, + Tcl_Obj *const objv[] + ) +{ + SchemaData *sdata = GETASI; + SchemaConstraint *sc; + + CHECK_TI + checkNrArgs (1,1,"No arguments expected"); + ADD_CONSTRAINT (sdata, sc) + sc->constraint = durationImpl; + return TCL_OK; +} + +static int +lengthImpl ( + Tcl_Interp *interp, + void *constraintData, + char *text + ) +{ + unsigned int length = PTR2UINT(constraintData); + int len = 0, clen; + while (*text != '\0') { + clen = UTF8_CHAR_LEN (*text); + if (!clen) { + SetResult ("Invalid UTF-8 character"); + return 0; + } + len++; + if (len > length) return 0; + text += clen; + } + if (len == length) return 1; + return 0; +} + +static int +lengthTCObjCmd ( + ClientData clientData, + Tcl_Interp *interp, + int objc, + Tcl_Obj *const objv[] + ) +{ + SchemaData *sdata = GETASI; + SchemaConstraint *sc; + int len; + + CHECK_TI + checkNrArgs (2,2,"Expected: "); + if (Tcl_GetIntFromObj (interp, objv[1], &len) != TCL_OK) { + SetResult ("Expected: "); + return TCL_ERROR; + } + if (len < 0) { + SetResult ("The length must be at least 0"); + } + ADD_CONSTRAINT (sdata, sc) + sc->constraint = lengthImpl; + sc->constraintData = UINT2PTR(len); + return TCL_OK; +} + +static int +dateObjCmd ( + ClientData clientData, + Tcl_Interp *interp, + int objc, + Tcl_Obj *const objv[] + ) +{ + checkNrArgs (2,2,""); + Tcl_SetObjResult (interp, + Tcl_NewBooleanObj ( + isodateImpl (interp, NULL, + Tcl_GetString (objv[1])))); + return TCL_OK; +} + +static int +dateTimeObjCmd ( + ClientData clientData, + Tcl_Interp *interp, + int objc, + Tcl_Obj *const objv[] + ) +{ + checkNrArgs (2,2,""); + Tcl_SetObjResult (interp, + Tcl_NewBooleanObj ( + isodateImpl (interp, (void *) 1, + Tcl_GetString (objv[1])))); + return TCL_OK; +} + +static int +timeObjCmd ( + ClientData clientData, + Tcl_Interp *interp, + int objc, + Tcl_Obj *const objv[] + ) +{ + checkNrArgs (2,2,""); + Tcl_SetObjResult (interp, + Tcl_NewBooleanObj ( + isodateImpl (interp, (void *) 2, + Tcl_GetString (objv[1])))); + return TCL_OK; +} + +static int +durationObjCmd ( + ClientData clientData, + Tcl_Interp *interp, + int objc, + Tcl_Obj *const objv[] + ) +{ + checkNrArgs (2,2,""); + Tcl_SetObjResult (interp, + Tcl_NewBooleanObj ( + durationImpl (interp, NULL, + Tcl_GetString (objv[1])))); + return TCL_OK; +} + +void +tDOM_SchemaInit ( + Tcl_Interp *interp + ) +{ + Tcl_CreateObjCommand (interp, "tdom::schema", tDOM_SchemaObjCmd, + NULL, NULL); + + /* Inline definition commands. */ + Tcl_CreateObjCommand (interp, "tdom::schema::defelement", + tDOM_schemaInstanceCmd, NULL, NULL); + Tcl_CreateObjCommand (interp, "tdom::schema::defelementtype", + tDOM_schemaInstanceCmd, NULL, NULL); + Tcl_CreateObjCommand (interp, "tdom::schema::defpattern", + tDOM_schemaInstanceCmd, NULL, NULL); + Tcl_CreateObjCommand (interp, "tdom::schema::deftexttype", + tDOM_schemaInstanceCmd, NULL, NULL); + Tcl_CreateObjCommand (interp, "tdom::schema::start", + tDOM_schemaInstanceCmd, NULL, NULL); + Tcl_CreateObjCommand (interp, "tdom::schema::prefixns", + tDOM_schemaInstanceCmd, NULL, NULL); + + /* The "any" definition command. */ + Tcl_CreateObjCommand (interp, "tdom::schema::any", + AnyPatternObjCmd, NULL, NULL); + + /* The named pattern commands "element", "elementtype" and + * "ref". */ + Tcl_CreateObjCommand (interp, "tdom::schema::element", + NamedPatternObjCmd, (ClientData) 0, NULL); + Tcl_CreateObjCommand (interp, "tdom::schema::elementtype", + NamedPatternObjCmd, (ClientData) 1, NULL); + Tcl_CreateObjCommand (interp, "tdom::schema::ref", + NamedPatternObjCmd, (ClientData) 2, NULL); + + /* The anonymous pattern commands "choise", "mixed", "interleave" + * and "group". */ + Tcl_CreateObjCommand (interp, "tdom::schema::choice", + AnonPatternObjCmd, (ClientData) 0, NULL); + Tcl_CreateObjCommand (interp, "tdom::schema::mixed", + AnonPatternObjCmd, (ClientData) 1, NULL); + Tcl_CreateObjCommand (interp, "tdom::schema::interleave", + AnonPatternObjCmd, (ClientData) 2, NULL); + Tcl_CreateObjCommand (interp, "tdom::schema::group", + AnonPatternObjCmd, (ClientData) 3, NULL); + + /* The "attribute", "nsattribute", "namespace" and "text" + * definition commands. */ + Tcl_CreateObjCommand (interp, "tdom::schema::attribute", + AttributePatternObjCmd, NULL, NULL); + Tcl_CreateObjCommand (interp, "tdom::schema::nsattribute", + AttributePatternObjCmd, (ClientData) 1, NULL); + Tcl_CreateObjCommand (interp, "tdom::schema::namespace", + NamespacePatternObjCmd, NULL, NULL); + Tcl_CreateObjCommand (interp, "tdom::schema::text", + TextPatternObjCmd, NULL, NULL); + + /* The 'virtual' "tcl" and the "self" definition command */ + Tcl_CreateObjCommand (interp, "tdom::schema::tcl", + VirtualPatternObjCmd, NULL, NULL); + Tcl_CreateObjCommand (interp, "tdom::schema::self", + SelfObjCmd, NULL, NULL); + + /* XPath contraints for DOM validation */ + Tcl_CreateObjCommand (interp,"tdom::schema::domunique", + domuniquePatternObjCmd, NULL, NULL); + Tcl_CreateObjCommand (interp,"tdom::schema::domxpathboolean", + domxpathbooleanPatternObjCmd, NULL, NULL); + + /* Local key constraints */ + Tcl_CreateObjCommand (interp, "tdom::schema::keyspace", + keyspacePatternObjCmd, NULL, NULL); + + /* The associate command */ + Tcl_CreateObjCommand (interp,"tdom::schema::associate", + associatePatternObjCmd, NULL, NULL); + + /* The text constraint commands */ + Tcl_CreateObjCommand (interp,"tdom::schema::text::integer", + integerTCObjCmd, (ClientData) 0, NULL); + Tcl_CreateObjCommand (interp,"tdom::schema::text::negativeInteger", + integerTCObjCmd, (ClientData) 1, NULL); + Tcl_CreateObjCommand (interp,"tdom::schema::text::nonNegativeInteger", + integerTCObjCmd, (ClientData) 2, NULL); + Tcl_CreateObjCommand (interp,"tdom::schema::text::nonPositiveInteger", + integerTCObjCmd, (ClientData) 3, NULL); + Tcl_CreateObjCommand (interp,"tdom::schema::text::positiveInteger", + integerTCObjCmd, (ClientData) 4, NULL); + Tcl_CreateObjCommand (interp, "tdom::schema::text::tcl", + tclTCObjCmd, NULL, NULL); + Tcl_CreateObjCommand (interp, "tdom::schema::text::fixed", + fixedTCObjCmd, NULL, NULL); + Tcl_CreateObjCommand (interp, "tdom::schema::text::enumeration", + enumerationTCObjCmd, NULL, NULL); + Tcl_CreateObjCommand (interp, "tdom::schema::text::match", + matchTCObjCmd, NULL, NULL); + Tcl_CreateObjCommand (interp, "tdom::schema::text::regexp", + regexpTCObjCmd, NULL, NULL); + Tcl_CreateObjCommand (interp, "tdom::schema::text::nmtoken", + nmtokenTCObjCmd, NULL, NULL); + Tcl_CreateObjCommand (interp, "tdom::schema::text::nmtokens", + nmtokensTCObjCmd, NULL, NULL); + Tcl_CreateObjCommand (interp,"tdom::schema::text::number", + numberTCObjCmd, NULL, NULL); + Tcl_CreateObjCommand (interp,"tdom::schema::text::boolean", + booleanTCObjCmd, NULL, NULL); + Tcl_CreateObjCommand (interp,"tdom::schema::text::date", + dateTCObjCmd, NULL, NULL); + Tcl_CreateObjCommand (interp,"tdom::schema::text::dateTime", + dateTimeTCObjCmd, NULL, NULL); + Tcl_CreateObjCommand (interp,"tdom::schema::text::time", + timeTCObjCmd, NULL, NULL); + Tcl_CreateObjCommand (interp,"tdom::schema::text::duration", + durationTCObjCmd, NULL, NULL); + Tcl_CreateObjCommand (interp,"tdom::schema::text::maxLength", + maxLengthTCObjCmd, NULL, NULL); + Tcl_CreateObjCommand (interp,"tdom::schema::text::minLength", + minLengthTCObjCmd, NULL, NULL); + Tcl_CreateObjCommand (interp,"tdom::schema::text::oneOf", + oneOfTCObjCmd, NULL, NULL); + Tcl_CreateObjCommand (interp,"tdom::schema::text::allOf", + allOfTCObjCmd, NULL, NULL); + Tcl_CreateObjCommand (interp,"tdom::schema::text::strip", + stripTCObjCmd, NULL, NULL); + Tcl_CreateObjCommand (interp,"tdom::schema::text::split", + splitTCObjCmd, NULL, NULL); + Tcl_CreateObjCommand (interp,"tdom::schema::text::id", + idTCObjCmd, NULL, NULL); + Tcl_CreateObjCommand (interp,"tdom::schema::text::idref", + idrefTCObjCmd, NULL, NULL); + Tcl_CreateObjCommand (interp,"tdom::schema::text::base64", + base64TCObjCmd, NULL, NULL); + Tcl_CreateObjCommand (interp,"tdom::schema::text::key", + keyTCObjCmd, NULL, NULL); + Tcl_CreateObjCommand (interp,"tdom::schema::text::keyref", + keyrefTCObjCmd, NULL, NULL); + Tcl_CreateObjCommand (interp,"tdom::schema::text::name", + nameTCObjCmd, NULL, NULL); + Tcl_CreateObjCommand (interp,"tdom::schema::text::ncname", + ncnameTCObjCmd, NULL, NULL); + Tcl_CreateObjCommand (interp,"tdom::schema::text::qname", + qnameTCObjCmd, NULL, NULL); + Tcl_CreateObjCommand (interp,"tdom::schema::text::hexBinary", + hexBinaryTCObjCmd, NULL, NULL); + Tcl_CreateObjCommand (interp,"tdom::schema::text::unsignedByte", + unsignedIntTypesTCObjCmd, (ClientData) 0, NULL); + Tcl_CreateObjCommand (interp,"tdom::schema::text::unsignedShort", + unsignedIntTypesTCObjCmd, (ClientData) 1, NULL); + Tcl_CreateObjCommand (interp,"tdom::schema::text::unsignedInt", + unsignedIntTypesTCObjCmd, (ClientData) 2, NULL); + Tcl_CreateObjCommand (interp,"tdom::schema::text::unsignedLong", + unsignedIntTypesTCObjCmd, (ClientData) 3, NULL); + Tcl_CreateObjCommand (interp,"tdom::schema::text::setvar", + setvarTCObjCmd, (ClientData) 3, NULL); + Tcl_CreateObjCommand (interp,"tdom::schema::text::whitespace", + whitespaceTCObjCmd, (ClientData) 3, NULL); + Tcl_CreateObjCommand (interp,"tdom::schema::text::not", + notTCObjCmd, (ClientData) 3, NULL); + Tcl_CreateObjCommand (interp,"tdom::schema::text::length", + lengthTCObjCmd, (ClientData) 3, NULL); + + /* Exposed text type commands */ + Tcl_CreateObjCommand (interp,"tdom::type::date", + dateObjCmd, NULL, NULL); + Tcl_CreateObjCommand (interp,"tdom::type::dateTime", + dateTimeObjCmd, NULL, NULL); + Tcl_CreateObjCommand (interp,"tdom::type::time", + timeObjCmd, NULL, NULL); + Tcl_CreateObjCommand (interp,"tdom::type::duration", + durationObjCmd, NULL, NULL); + +} + + +#endif /* #ifndef TDOM_NO_SCHEMA */ ADDED generic/schema.h Index: generic/schema.h ================================================================== --- /dev/null +++ generic/schema.h @@ -0,0 +1,263 @@ +/*---------------------------------------------------------------------------- +| Copyright (c) 2018 Rolf Ade (rolf@pointsman.de) +|----------------------------------------------------------------------------- +| +| +| The contents of this file are subject to the Mozilla Public License +| Version 2.0 (the "License"); you may not use this file except in +| compliance with the License. You may obtain a copy of the License at +| http://www.mozilla.org/MPL/ +| +| Software distributed under the License is distributed on an "AS IS" +| basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the +| License for the specific language governing rights and limitations +| under the License. +| +| Contributor(s): +| +| +| written by Rolf Ade +| 2018-2020 +| +\---------------------------------------------------------------------------*/ + +#ifndef __SCHEMA_H__ +#define __SCHEMA_H__ + +#include +#include + +typedef enum { + SCHEMA_CTYPE_ANY, + SCHEMA_CTYPE_NAME, + SCHEMA_CTYPE_CHOICE, + SCHEMA_CTYPE_INTERLEAVE, + SCHEMA_CTYPE_PATTERN, + SCHEMA_CTYPE_TEXT, + SCHEMA_CTYPE_VIRTUAL, + SCHEMA_CTYPE_KEYSPACE, + SCHEMA_CTYPE_KEYSPACE_END, +} Schema_CP_Type; + +typedef enum { + SCHEMA_CQUANT_ONE, + SCHEMA_CQUANT_OPT, + SCHEMA_CQUANT_REP, + SCHEMA_CQUANT_PLUS, + SCHEMA_CQUANT_NM, + SCHEMA_CQUANT_ERROR, +} SchemaQuant; + +typedef int (*SchemaConstraintFunc) (Tcl_Interp *interp, + void *constraintData, char *text); +typedef void (*SchemaConstraintFreeFunc) (void *constraintData); + +typedef struct +{ + void *constraintData; + SchemaConstraintFunc constraint; + SchemaConstraintFreeFunc freeData; +} SchemaConstraint; + +typedef struct SchemaAttr +{ + char *namespace; + char *name; + int required; + struct SchemaAttr *next; + struct SchemaCP *cp; +} SchemaAttr; + +typedef unsigned int SchemaFlags; + +/* The SchemaFlags flags */ +#define FORWARD_PATTERN_DEF 1 +#define PLACEHOLDER_PATTERN_DEF 2 +#define AMBIGUOUS_PATTERN 4 +#define LOCAL_DEFINED_ELEMENT 8 +#define CONSTRAINT_TEXT_CHILD 16 +#define MIXED_CONTENT 32 +#define ELEMENTTYPE_DEF 64 + +typedef struct domKeyConstraint { + char *name; + ast selector; + ast *fields; + int nrFields; + int flags; + char *emptyFieldSetValue; + int efsv_len; + struct domKeyConstraint *next; +} domKeyConstraint; + +typedef struct +{ + char *name; + int active; + Tcl_HashTable ids; + int unknownIDrefs; +} SchemaKeySpace; + +typedef struct SchemaCP +{ + Schema_CP_Type type; + char *namespace; + char *name; + char *typeName; + struct SchemaCP *next; + SchemaFlags flags; + struct SchemaCP **content; + SchemaQuant *quants; + unsigned int nc; + void *typedata; + SchemaAttr **attrs; + unsigned int numAttr; + unsigned int numReqAttr; + domKeyConstraint *domKeys; + SchemaKeySpace *keySpace; + Tcl_Obj *defScript; + Tcl_Obj *associated; +} SchemaCP; + +typedef struct SchemaValidationStack +{ + SchemaCP *pattern; + struct SchemaValidationStack *next; + struct SchemaValidationStack *down; + int activeChild; + int hasMatched; + int *interleaveState; +} SchemaValidationStack; + +typedef enum { + VALIDATION_READY, + VALIDATION_STARTED, + VALIDATION_ERROR, + VALIDATION_FINISHED +} ValidationState; + +typedef struct +{ + Tcl_HashTable ids; + int unknownIDrefs; +} SchemaDocKey; + +typedef struct SchemaData_ +{ + Tcl_Obj *self; + char *start; + char *startNamespace; + Tcl_HashTable element; + Tcl_HashTable elementType; + Tcl_HashTable namespace; + Tcl_HashEntry *emptyNamespace; + char **prefixns; + Tcl_HashTable prefix; + Tcl_HashTable pattern; + Tcl_HashTable attrNames; + Tcl_HashTable textDef; + SchemaCP **patternList; + unsigned int numPatternList; + unsigned int patternListSize; + unsigned int forwardPatternDefs; + SchemaQuant *quants; + int inuse; + int currentEvals; + int cleanupAfterUse; + int evalError; + Tcl_Obj *reportCmd; + SchemaValidationStack *lastMatchse; + int recoverFlags; + Tcl_Obj **evalStub; + Tcl_Obj **textStub; + char *currentNamespace; + int defineToplevel; + int isTextConstraint; + int isAttributeConstaint; + SchemaCP *cp; + unsigned int contentSize; + SchemaAttr **currentAttrs; + unsigned int numAttr; + unsigned int numReqAttr; + unsigned int attrSize; + SchemaValidationStack *stack; + SchemaValidationStack *stackPool; + ValidationState validationState; + int vaction; + const char *vname; + const char *vns; + const char *vtext; + unsigned int skipDeep; + Tcl_DString *cdata; + Tcl_HashTable ids; + int unknownIDrefs; + Tcl_HashTable idTables; + Tcl_HashTable keySpaces; + XML_Parser parser; + domNode *node; + domNode *insideNode; + int choiceHashThreshold; + int attributeHashThreshold; + char *wsbuf; + int wsbufLen; +} SchemaData; + +int +tDOM_schemaInstanceCmd ( + ClientData clientData, + Tcl_Interp *interp, + int objc, + Tcl_Obj *const objv[] + ); + +void tDOM_SchemaInit ( + Tcl_Interp *interp + ); + +int +tDOM_probeElement ( + Tcl_Interp *interp, + SchemaData *sdata, + const char *name, + void *namespace + ); + +int +tDOM_probeAttributes ( + Tcl_Interp *interp, + SchemaData *sdata, + const char **attr + ); + +typedef struct domDocument domDocument; +typedef struct domNode domNode; +typedef struct domAttrNode domAttrNode; +typedef struct domTextNode domTextNode; + +int tDOM_probeDomAttributes ( + Tcl_Interp *interp, + SchemaData *sdata, + domAttrNode *attr + ); + +int +tDOM_probeElementEnd ( + Tcl_Interp * interp, + SchemaData *sdata + ); + +int +tDOM_probeText ( + Tcl_Interp *interp, + SchemaData *sdata, + char *text, + int *only_whites + ); + +void +tDOM_schemaReset ( + SchemaData *sdata, + int lookforCleanup + ); + +#endif DELETED generic/structure.c Index: generic/structure.c ================================================================== --- generic/structure.c +++ /dev/null @@ -1,1957 +0,0 @@ -/*---------------------------------------------------------------------------- -| Copyright (c) 2018 Rolf Ade (rolf@pointsman.de) -|----------------------------------------------------------------------------- -| -| -| The contents of this file are subject to the Mozilla Public License -| Version 2.0 (the "License"); you may not use this file except in -| compliance with the License. You may obtain a copy of the License at -| http://www.mozilla.org/MPL/ -| -| Software distributed under the License is distributed on an "AS IS" -| basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the -| License for the specific language governing rights and limitations -| under the License. -| -| Contributor(s): -| -| -| written by Rolf Ade -| November 2018 -| -\---------------------------------------------------------------------------*/ - -#ifndef TDOM_NO_STRUCTURE - -#include -#include - -/* #define DEBUG */ -/*---------------------------------------------------------------------------- -| Debug Macros -| -\---------------------------------------------------------------------------*/ -#ifdef DEBUG -# define DBG(x) x -#else -# define DBG(x) -#endif - -/*---------------------------------------------------------------------------- -| Initial buffer sizes -| -\---------------------------------------------------------------------------*/ -#ifndef CONTENT_ARRAY_SIZE_INIT -# define CONTENT_ARRAY_SIZE_INIT 20 -#endif -#ifndef ANON_PATTERN_ARRAY_SIZE_INIT -# define ANON_PATTERN_ARRAY_SIZE_INIT 256 -#endif -#ifndef QUANTS_ARRAY_SIZE_INIT -# define QUANTS_ARRAY_SIZE_INIT 8 -#endif -#ifndef STACK_SIZE_INIT -# define STACK_SIZE_INIT 16 -#endif -#ifndef STACK_LIST_SIZE_INIT -# define STACK_LIST_SIZE_INIT 64 -#endif -#ifndef URI_BUFFER_LEN_INIT -# define URI_BUFFER_LEN_INIT 128 -#endif - -/*---------------------------------------------------------------------------- -| Local typedefs -| -\---------------------------------------------------------------------------*/ - -typedef struct -{ - StructureData *sdata; - Tcl_Interp *interp; - XML_Parser parser; - Tcl_DString *cdata; - char *uri; - int maxUriLen; -} ValidateMethodData; - -/*---------------------------------------------------------------------------- -| Macros -| -\---------------------------------------------------------------------------*/ -#define TMALLOC(t) (t*)MALLOC(sizeof(t)) - -#define SetResult(str) Tcl_ResetResult(interp); \ - Tcl_SetStringObj(Tcl_GetObjResult(interp), (str), -1) -#define SetResult3(str1,str2,str3) Tcl_ResetResult(interp); \ - Tcl_AppendResult(interp, (str1), (str2), (str3), NULL) -#define SetIntResult(i) Tcl_ResetResult(interp); \ - Tcl_SetIntObj(Tcl_GetObjResult(interp), (i)) -#define SetBooleanResult(i) Tcl_ResetResult(interp); \ - Tcl_SetBooleanObj(Tcl_GetObjResult(interp), (i)) - -#define checkNrArgs(l,h,err) if (objc < l || objc > h) { \ - SetResult (err); \ - return TCL_ERROR; \ - } - -#ifdef DEBUG -static char *Structure_CP_Type2str[] = { - "EMPTY", - "ANY", - "MIXED", - "NAME", - "CHOICE", - "INTERLEAVE", - "PATTERN", - "GROUP", - "TEXT" -}; -static char *Structure_Quant_Type2str[] = { - "ONE", - "OPT", - "REP", - "PLUS", - "N", - "NM" -}; -#endif - - -/* The StructureFlags flags */ -#define FORWARD_PATTERN_DEF 1 -#define PLACEHOLDER_PATTERN_DEF 2 -#define AMBIGUOUS_PATTERN 4 -#define LOCAL_DEFINED_ELEMENT 8 - -/* Pointer to heap-allocated shared quants. */ -static StructureQuant QuantOne; -static StructureQuant *quantOne = &QuantOne; - -static StructureQuant QuantOpt; -static StructureQuant *quantOpt = &QuantOpt; - -static StructureQuant QuantRep; -static StructureQuant *quantRep = &QuantRep; - -static StructureQuant QuantPlus; -static StructureQuant *quantPlus = &QuantPlus; - -#ifndef TCL_THREADS - static StructureData *activeStructureData = 0; -# define GETASI activeStructureData -# define SETASI(v) activeStructureData = v -#else - static Tcl_ThreadDataKey activeStructureData; -# define GETASI *(StructureData**) Tcl_GetThreadData(&activeStructureData, \ - sizeof(StructureData*)) -static void SetActiveStructureData (StructureData *v) -{ - StructureData **structureInfoPtr = Tcl_GetThreadData(&activeStructureData, - sizeof (StructureData*)); - *structureInfoPtr = v; -} -# define SETASI(v) SetActiveStructureData (v) -#endif - - -#define CHECK_SI \ - if (!sdata) { \ - SetResult ("Command called outside of grammar context."); \ - return TCL_ERROR; \ - } - -#define CHECK_TOPLEVEL \ - if (sdata->defineToplevel) { \ - SetResult("Command not allowed at top level " \ - "in grammar define evaluation"); \ - return TCL_ERROR; \ - } - -#define CHECK_SI_CONTEXT \ - if (sdata->isAttribute) { \ - SetResult ("Command called in invalid grammar context."); \ - return TCL_ERROR; \ - } - -#define ADD_TO_CONTENT(pattern,quant) \ - checkForAmbiguousness (pattern); \ - if (sdata->numChildren == sdata->contentSize) { \ - sdata->currentContent = \ - REALLOC (sdata->currentContent, \ - 2 * sdata->contentSize \ - * sizeof (StructureCP*)); \ - sdata->currentQuants = \ - REALLOC (sdata->currentQuants, \ - 2 * sdata->contentSize \ - * sizeof (StructureQuant*)); \ - sdata->contentSize *= 2; \ - } \ - sdata->currentContent[sdata->numChildren] = (pattern); \ - sdata->currentQuants[sdata->numChildren] = quant; \ - sdata->numChildren++; \ - -#define REMEMBER_PATTERN(pattern) \ - if (sdata->numPatternList == sdata->patternListSize) { \ - sdata->patternList = (StructureCP **) MALLOC ( \ - sizeof (StructureCP*) * sdata->patternListSize * 2); \ - sdata->patternListSize *= 2; \ - } \ - sdata->patternList[sdata->numPatternList] = pattern; \ - sdata->numPatternList++; - -static StructureCP* -initStructureCP ( - Structure_CP_Type type, - void *namespace, - char *name - ) -{ - StructureCP *pattern; - - pattern = TMALLOC (StructureCP); - memset (pattern, 0, sizeof(StructureCP)); - pattern->type = type; - switch (type) { - case STRUCTURE_CTYPE_NAME: - case STRUCTURE_CTYPE_PATTERN: - pattern->namespace = (char *)namespace; - pattern->name = name; - /* Fall thru. */ - case STRUCTURE_CTYPE_GROUP: - case STRUCTURE_CTYPE_MIXED: - case STRUCTURE_CTYPE_CHOICE: - case STRUCTURE_CTYPE_INTERLEAVE: - pattern->content = (StructureCP**) MALLOC ( - sizeof(StructureCP*) * CONTENT_ARRAY_SIZE_INIT - ); - pattern->quants = (StructureQuant**) MALLOC ( - sizeof (StructureQuant*) * CONTENT_ARRAY_SIZE_INIT - ); - break; - case STRUCTURE_CTYPE_EMPTY: - case STRUCTURE_CTYPE_ANY: - case STRUCTURE_CTYPE_TEXT: - /* Do nothing */ - break; - } - return pattern; -} - -DBG( -static void serializeCP ( - StructureCP *pattern - ) -{ - fprintf (stderr, "CP type: %s\n", - Structure_CP_Type2str[pattern->type]); - switch (pattern->type) { - case STRUCTURE_CTYPE_NAME: - case STRUCTURE_CTYPE_PATTERN: - case STRUCTURE_CTYPE_GROUP: - fprintf (stderr, "\tName: '%s' Namespace: '%s'\n", - pattern->name,pattern->namespace); - if (pattern->flags & FORWARD_PATTERN_DEF) { - fprintf (stderr, "\tAnonymously defined NAME\n"); - } - if (pattern->flags & PLACEHOLDER_PATTERN_DEF) { - fprintf (stderr, "\tAs placeholder defined NAME\n"); - } - if (pattern->flags & LOCAL_DEFINED_ELEMENT) { - fprintf (stderr, "\tAs placeholder defined NAME\n"); - } - /* Fall thru. */ - case STRUCTURE_CTYPE_MIXED: - case STRUCTURE_CTYPE_CHOICE: - case STRUCTURE_CTYPE_INTERLEAVE: - fprintf (stderr, "\t%d childs\n", pattern->numChildren); - break; - case STRUCTURE_CTYPE_EMPTY: - case STRUCTURE_CTYPE_ANY: - case STRUCTURE_CTYPE_TEXT: - /* Do nothing */ - break; - } -} - -static void serializeQuant ( - StructureQuant *quant - ) -{ - fprintf (stderr, "Quant type: %s n: %d m: %d\n", - Structure_Quant_Type2str[quant->type], quant->minOccur, quant->maxOccur); -} - -static void serializeStack ( - StructureData *sdata - ) -{ - int i = sdata->stackPtr-1; - - fprintf (stderr, "++++ Current validation stack (size %d):\n", i+1); - while (i >= 0) { - serializeCP (sdata->stack[i]->pattern); - fprintf (stderr, "deep: %d matched: %d ac: %d nm: %d\n", - sdata->stack[i]->deep, sdata->stack[i]->acNrMatched, - sdata->stack[i]->activeChild, sdata->stack[i]->nrMatched); - i--; - } - fprintf (stderr, "++++ Stack bottom\n"); -} -) - -/* DBG end */ - -static void freeStructureCP ( - StructureCP *pattern - ) -{ - switch (pattern->type) { - case STRUCTURE_CTYPE_EMPTY: - case STRUCTURE_CTYPE_ANY: - /* do nothing */ - break; - default: - FREE (pattern->content); - FREE (pattern->quants); - break; - } - FREE (pattern); -} - -static StructureData* -initStructureData () -{ - StructureData *sdata; - int hnew; - - sdata = TMALLOC (StructureData); - memset (sdata, 0, sizeof(StructureData)); - Tcl_InitHashTable (&sdata->element, TCL_STRING_KEYS); - Tcl_InitHashTable (&sdata->pattern, TCL_STRING_KEYS); - Tcl_InitHashTable (&sdata->namespace, TCL_STRING_KEYS); - sdata->emptyNamespace = Tcl_CreateHashEntry ( - &sdata->namespace, "", &hnew); - sdata->patternList = (StructureCP **) MALLOC ( - sizeof (StructureCP*) * ANON_PATTERN_ARRAY_SIZE_INIT); - sdata->patternListSize = ANON_PATTERN_ARRAY_SIZE_INIT; - sdata->quants = (StructureQuant **) MALLOC ( - sizeof (StructureQuant*) * QUANTS_ARRAY_SIZE_INIT); - sdata->quantsSize = QUANTS_ARRAY_SIZE_INIT; - sdata->stack = (StructureValidationStack **) MALLOC ( - sizeof (StructureValidationStack *) * STACK_SIZE_INIT); - sdata->stackSize = STACK_SIZE_INIT; - sdata->stackList = (StructureValidationStack **) MALLOC ( - sizeof (StructureValidationStack *) * STACK_LIST_SIZE_INIT); - sdata->stackListSize = STACK_LIST_SIZE_INIT; - sdata->evalStub = (Tcl_Obj **) (MALLOC (sizeof (Tcl_Obj*) * 4)); - sdata->evalStub[0] = Tcl_NewStringObj("::namespace", 11); - Tcl_IncrRefCount (sdata->evalStub[0]); - sdata->evalStub[1] = Tcl_NewStringObj("eval", 4); - Tcl_IncrRefCount (sdata->evalStub[1]); - sdata->evalStub[2] = Tcl_NewStringObj("::tdom::structure", 17); - Tcl_IncrRefCount (sdata->evalStub[2]); - return sdata; -} - -static void structureInstanceDelete ( - ClientData clientData - ) -{ - StructureData *sdata = (StructureData *) clientData; - unsigned int i; - - if (sdata->start) FREE (sdata->start); - if (sdata->startNamespace) FREE (sdata->startNamespace); - Tcl_DeleteHashTable (&sdata->namespace); - Tcl_DeleteHashTable (&sdata->element); - Tcl_DeleteHashTable (&sdata->pattern); - for (i = 0; i < sdata->numPatternList; i++) { - freeStructureCP (sdata->patternList[i]); - } - FREE (sdata->patternList); - for (i = 0; i < sdata->numQuants; i++) { - FREE (sdata->quants[i]); - } - FREE (sdata->quants); - FREE (sdata->stack); - for (i = 0; i < sdata->numStackAllocated; i++) { - FREE (sdata->stackList[i]); - } - FREE (sdata->stackList); - Tcl_DecrRefCount (sdata->evalStub[0]); - Tcl_DecrRefCount (sdata->evalStub[1]); - Tcl_DecrRefCount (sdata->evalStub[2]); - FREE (sdata->evalStub); - FREE (sdata); -} - -static void -cleanupLastPattern ( - StructureData *sdata, - unsigned int from - ) -{ - unsigned int i; - Tcl_HashTable *hashTable; - Tcl_HashEntry *entryPtr; - StructureCP *this, *previous, *current; - - for (i = from; i < sdata->numPatternList; i++) { - this = sdata->patternList[i]; - hashTable = NULL; - if (this->type == STRUCTURE_CTYPE_NAME) { - hashTable = &sdata->element; - } - if (this->type == STRUCTURE_CTYPE_PATTERN) { - hashTable = &sdata->pattern; - } - if (hashTable) { - if (this->flags & FORWARD_PATTERN_DEF) { - sdata->forwardPatternDefs--; - } - entryPtr = Tcl_FindHashEntry (hashTable, this->name); - previous = NULL; - current = Tcl_GetHashValue (entryPtr); - while (current != NULL && current != this) { - previous = current; - current = current->next; - } - if (previous) { - if (current->next) { - previous->next = current->next; - } else { - previous->next = NULL; - } - } else { - if (current) { - Tcl_SetHashValue (entryPtr, current->next); - } else { - Tcl_DeleteHashEntry (entryPtr); - } - } - } - freeStructureCP (sdata->patternList[i]); - } - sdata->numPatternList = from; -} - -static void -checkForAmbiguousness ( - StructureCP *pattern - ) -{ - /* As long as we don't know otherwise we assume any pattern to be - * ambiguous. */ - pattern->flags |= AMBIGUOUS_PATTERN; -} - -static void -pushToStack ( - StructureData *sdata, - StructureCP *pattern, - int deep - ) -{ - StructureValidationStack *stackElm; - - if (sdata->numStackList < sdata->numStackAllocated) { - stackElm = sdata->stackList[sdata->numStackList]; - } else { - if (sdata->stackPtr == sdata->stackSize) { - sdata->stack = REALLOC ( - sdata->stack, - sizeof (StructureValidationStack *) * 2 * sdata->stackSize); - sdata->stackSize *= 2; - } - if (sdata->stackListSize == sdata->numStackList) { - sdata->stackList = REALLOC ( - sdata->stackList, - sizeof (StructureValidationStack *) * 2 * sdata->stackListSize); - sdata->stackListSize *= 2; - } - stackElm = TMALLOC (StructureValidationStack); - sdata->numStackAllocated++; - sdata->stackList[sdata->numStackList] = stackElm; - } - sdata->numStackList++; - memset (stackElm, 0, sizeof (StructureValidationStack)); - stackElm->pattern = pattern; - stackElm->deep = deep; - sdata->stack[sdata->stackPtr] = stackElm; - sdata->stackPtr++; -} - -#define maxOne(quant) \ - ((quant) == quantOne || (quant) == quantOpt) ? 1 : 0 - -#define minOne(quant) \ - ((quant) == quantOne || (quant) == quantPlus) || (quant->type == STRUCTURE_CQUANT_NM && (quant)->minOccur > 0) ? 1 : 0 - -#define mayMiss(quant) \ - ((quant) == quantOpt || (quant) == quantRep) || (quant->type == STRUCTURE_CQUANT_NM && (quant)->minOccur == 0) ? 1 : 0 - -#define mayRepeat(quant) \ - ((quant) == quantRep || (quant) == quantPlus) ? 1 : 0 - -#define mustMatch(quant,nr) \ - (nr) == 0 ? minOne(quant) \ - : (quant->type == STRUCTURE_CQUANT_NM && quant->minOccur < (nr)) ? 1 : 0 - -#define hasMatched(quant,nr) \ - (nr) == 0 ? 0 : ((nr) == 1 && (quant == quantOne || quant == quantOpt) ? 1 : quant->maxOccur == (nr)) - -#define getContext(parent, ac, nm) \ - parent = sdata->stack[sdata->stackPtr-1]->pattern; \ - ac = sdata->stack[sdata->stackPtr-1]->activeChild; \ - nm = sdata->stack[sdata->stackPtr-1]->nrMatched; - -#define updateStack(sdata,stackPtr,newac,newnm) \ - sdata->stack[stackPtr-1]->activeChild = newac; \ - sdata->stack[stackPtr-1]->nrMatched = newnm; - -#define popStack(sdata) sdata->stackPtr-- - -#define waterMark(sdata) sdata->stack[sdata->stackPtr-1]->stacklistWatermark = sdata->numStackList - 1 -#define restoreWaterMark(sdata) sdata->numStackList = sdata->stack[sdata->stackPtr-1]->stacklistWatermark - -static int -matchNamePattern ( - StructureData *sdata, - StructureCP *pattern, - int currentDeep - ) -{ - StructureCP *parent, *candidate; - int nm, ac, startac, savedStackPtr, rc, i; - int isName = 0, loopOver = 0; - - /* The caller must ensure pattern->type = STRUCTURE_CTYPE_NAME */ - - getContext (parent, ac, nm); - - if (hasMatched (parent->quants[ac], nm)) {ac++; nm = 0;} - - DBG( - fprintf (stderr, "matchNamePattern: ac: %d nm: %d stack:\n", ac, nm); - serializeStack (sdata); - ) - - switch (parent->type) { - case STRUCTURE_CTYPE_NAME: - isName = 1; - /* fall through */ - case STRUCTURE_CTYPE_GROUP: - case STRUCTURE_CTYPE_PATTERN: - startac = ac; - loopOverContent: - while (ac < parent->numChildren) { - candidate = parent->content[ac]; - switch (candidate->type) { - case STRUCTURE_CTYPE_EMPTY: - /* The empty pattern never match an element, successfully */ - ac++; - nm = 0; - break; - - case STRUCTURE_CTYPE_ANY: - updateStack (sdata, sdata->stackPtr, ac, nm+1); - return 1; - - case STRUCTURE_CTYPE_NAME: - if (candidate == pattern - || strcmp (candidate->name, pattern->name) == 0) { - updateStack (sdata, sdata->stackPtr, ac, nm+1); - if (loopOver) { - sdata->stack[sdata->stackPtr-2]->nrMatched++; - } - /* We need to push the element only onto the stack - * if it has non-empty content. But how many real - * life XML vocabularies does have EMPTY - * elements? Should we check for this? */ - pushToStack (sdata, candidate, currentDeep + 1); - waterMark (sdata); - return 1; - } - if (mustMatch (parent->quants[ac], nm)) return 0; - ac++; - nm = 0; - break; - - case STRUCTURE_CTYPE_TEXT: - if (mustMatch (parent->quants[ac], nm)) return 0; - ac++; - nm = 0; - break; - - case STRUCTURE_CTYPE_GROUP: - case STRUCTURE_CTYPE_PATTERN: - case STRUCTURE_CTYPE_MIXED: - case STRUCTURE_CTYPE_INTERLEAVE: - case STRUCTURE_CTYPE_CHOICE: - savedStackPtr = sdata->stackPtr; - pushToStack (sdata, candidate, currentDeep); - rc = matchNamePattern (sdata, pattern, currentDeep); - if (rc == 1) { - updateStack (sdata, savedStackPtr, ac, nm+1); - return 1; - } - popStack (sdata); - if (rc == 0) return 0; - if (mustMatch (parent->quants[ac], nm)) return 0; - ac++; - nm = 0; - break; - } - } - if (isName) { - /* No match, but any remaining possible childs tested */ - return 0; - } else { - /* No match, but also no explicit error. */ - /* We finished a non atomic pattern (GROUP or PATTERN) and - * increment the nrMatched of that inside its parent. */ - - /* Check, if we have to restart the parent pattern (look - for match right from the start) because of quant. */ - if (startac) { - /* It only make sense to look for a match from the - * start if the start active child wasn't already 0*/ - StructureQuant *parentQuant; - parentQuant = sdata->stack[sdata->stackPtr-2]-> - pattern->quants[sdata->stack[sdata->stackPtr-2]->activeChild]; - if (mayRepeat (parentQuant)) { - ac = 0; - nm = 0; - startac = 0; - loopOver = 1; - DBG(fprintf (stderr, "... loopOverContent\n")); - goto loopOverContent; - } else { - if (!maxOne (parentQuant)) { - if (sdata->stack[sdata->stackPtr-2]->nrMatched - < parentQuant->maxOccur) { - ac = 0; - nm = 0; - startac = 0; - loopOver = 1; - DBG(fprintf (stderr, "... loopOverContent\n")); - goto loopOverContent; - } - } - - } - } - return -1; - } - - case STRUCTURE_CTYPE_TEXT: - if (mustMatch (parent->quants[ac], nm)) return 0; - break; - - case STRUCTURE_CTYPE_ANY: - case STRUCTURE_CTYPE_EMPTY: - /* Never pushed onto stack */ - Tcl_Panic ("Invalid CTYPE onto the validation stack!"); - - case STRUCTURE_CTYPE_INTERLEAVE: - fprintf (stderr, "matchNamePattern: STRUCTURE_CTYPE_INTERLEAVE to be implemented\n"); - return 0; - - case STRUCTURE_CTYPE_MIXED: - case STRUCTURE_CTYPE_CHOICE: - for (i = 0; i < parent->numChildren; i++) { - candidate = parent->content[i]; - - switch (candidate->type) { - case STRUCTURE_CTYPE_EMPTY: - /* The empty pattern never match an element */ - break; - - case STRUCTURE_CTYPE_ANY: - return 1; - - case STRUCTURE_CTYPE_TEXT: - /* An elememt never match text. */ - break; - - case STRUCTURE_CTYPE_NAME: - if (candidate == pattern - || strcmp (candidate->name, pattern->name) == 0) { - updateStack (sdata, sdata->stackPtr, 0, nm+1); - pushToStack (sdata, candidate, currentDeep + 1); - return 1; - } - break; - - case STRUCTURE_CTYPE_GROUP: - case STRUCTURE_CTYPE_PATTERN: - case STRUCTURE_CTYPE_MIXED: - case STRUCTURE_CTYPE_INTERLEAVE: - case STRUCTURE_CTYPE_CHOICE: - savedStackPtr = sdata->stackPtr; - pushToStack (sdata, candidate, currentDeep); - rc = matchNamePattern (sdata, pattern, currentDeep); - if (rc == 1) { - /* Matched */ - updateStack (sdata, savedStackPtr, 0, nm+1); - return 1; - } - popStack (sdata); - break; - } - - } - /* No match, but the pattern may be optional or has already - * matched often enough. Check this on caller level. */ - return -1; - } - return 0; -} - -int -probeElement ( - Tcl_Interp *interp, - StructureData *sdata, - const char *name, - void *namespace - ) -{ - Tcl_HashEntry *entryPtr; - void *namespacePtr; - StructureCP *pattern; - int savedStackPtr, activeStack, currentDeep, rc; - - if (sdata->validationState == VALIDATION_FINISHED) { - SetResult ("Validation finished."); - return TCL_ERROR; - } - - if (namespace) { - entryPtr = Tcl_FindHashEntry (&sdata->namespace, (char *)namespace); - if (!entryPtr) { - SetResult ("No elements defined in this namespace"); - return TCL_ERROR; - } - if (entryPtr == sdata->emptyNamespace) { - namespacePtr = NULL; - } else { - namespacePtr = Tcl_GetHashKey (&sdata->namespace, entryPtr); - } - } else { - namespacePtr = NULL; - } - - entryPtr = Tcl_FindHashEntry (&sdata->element, name); - if (!entryPtr) { - SetResult3 ("\"", name, "\" isn't a defined element name in grammar."); - return TCL_ERROR; - } - pattern = (StructureCP *) Tcl_GetHashValue (entryPtr); - while (pattern) { - if (pattern->namespace == namespacePtr) { - break; - } - pattern = pattern->next; - } - if (!pattern) { - SetResult ("No such element definition."); - return TCL_ERROR; - } - - if (sdata->validationState == VALIDATION_READY) { - /* The root of the tree to check. */ - if (sdata->start) { - if (strcmp (name, sdata->start) != 0) { - SetResult ("Root element doesn't match."); - return TCL_ERROR; - } - if (namespace) { - if (!sdata->startNamespace || - strcmp (namespace, sdata->startNamespace) != 0) { - SetResult ("Root element namespace doesn't match"); - return TCL_ERROR; - } - } else { - if (sdata->startNamespace) { - SetResult ("Root element namespace doesn't match"); - return TCL_ERROR; - } - } - } - pushToStack (sdata, pattern, 0); - sdata->validationState = VALIDATION_STARTED; - return TCL_OK; - } - - /* The normal case: we're inside the tree */ - savedStackPtr = sdata->stackPtr; - activeStack = savedStackPtr; - currentDeep = sdata->stack[activeStack-1]->deep; - - DBG( - fprintf (stderr, "probeElement: look if '%s' match\n", pattern->name); - ); - - while ((rc = matchNamePattern (sdata, pattern, currentDeep)) == -1) { - activeStack--; - if (activeStack < 0 || sdata->stack[activeStack]->deep < currentDeep) { - break; - } - sdata->stackPtr = activeStack + 1; - } - if (rc == 1) { - DBG( - fprintf (stderr, "probeElement: element '%s' match\n", name); - serializeStack (sdata); - fprintf (stderr, "\n"); - ); - return TCL_OK; - } - sdata->stackPtr = savedStackPtr; - DBG( - fprintf (stderr, "element '%s' DOESN'T match\n", name); - serializeStack (sdata); - fprintf (stderr, "\n"); - ); - SetResult3 ("Element \"", name, "\" doesn't match"); - return TCL_ERROR; -} - -static int checkElementEnd ( - StructureData *sdata - ) -{ - StructureCP *parent; - int nm, ac; - int isName = 0; - - getContext (parent, ac, nm); - - switch (parent->type) { - case STRUCTURE_CTYPE_NAME: - if (sdata->stackPtr == 1) return 1; - isName = 1; - /* fall through */ - case STRUCTURE_CTYPE_GROUP: - case STRUCTURE_CTYPE_PATTERN: - while (ac < parent->numChildren) { - if (mustMatch (parent->quants[ac], nm)) { - return 0; - } - ac ++; - nm = 0; - } - if (isName) return 1; - else return -1; - - case STRUCTURE_CTYPE_TEXT: - case STRUCTURE_CTYPE_ANY: - case STRUCTURE_CTYPE_EMPTY: - /* Never pushed onto stack */ - Tcl_Panic ("Invalid CTYPE onto the validation stack!"); - return 0; - - case STRUCTURE_CTYPE_INTERLEAVE: - fprintf (stderr, "checkElementEnd: STRUCTURE_CTYPE_INTERLEAVE to be implemented\n"); - return 0; - - case STRUCTURE_CTYPE_MIXED: - case STRUCTURE_CTYPE_CHOICE: - return -1; - } - return 0; -} - -int -probeElementEnd ( - Tcl_Interp *interp, - StructureData *sdata - ) -{ - int activeStack, savedStackPtr, rc, currentDeep; - - if (sdata->validationState == VALIDATION_FINISHED) { - SetResult ("Validation finished."); - return TCL_ERROR; - } - if (sdata->validationState == VALIDATION_READY) { - SetResult ("No validation started"); - return TCL_ERROR; - } - - savedStackPtr = sdata->stackPtr; - activeStack = savedStackPtr; - currentDeep = sdata->stack[activeStack-1]->deep; - - DBG( - fprintf (stderr, "probeElementEnd: look if current stack top can end " - " name: '%s' currentDeep: %d\n", - sdata->stack[sdata->stackPtr-1]->pattern->name, currentDeep); - serializeStack (sdata); - ); - - while ((rc = checkElementEnd (sdata)) == -1) { - activeStack--; - if (activeStack < 1 || sdata->stack[activeStack]->deep < currentDeep) { - break; - } - popStack(sdata); - } - - if (rc != 1) { - sdata->stackPtr = savedStackPtr; - SetResult ("Missing mandatory element\n"); - DBG( - fprintf(stderr, "probeElementEnd: CAN'T end here.\n"); - serializeStack (sdata); - ); - return TCL_ERROR; - } - - restoreWaterMark(sdata); - popStack(sdata); - DBG( - fprintf(stderr, "probeElementEnd: ended here.\n"); - serializeStack (sdata); - ); - if (sdata->stackPtr == 0) { - /* End of the first pattern (the tree root) without error. - We have successfully ended validation */ - sdata->validationState = VALIDATION_FINISHED; - } - - return TCL_OK; -} - -static int -checkText ( - Tcl_Interp *interp, - StructureCP *cp, - char *text - ) -{ - - return TCL_OK; -} - -int -probeText ( - Tcl_Interp *interp, - StructureData *sdata, - char *text - ) -{ - StructureCP *parent; - int ac, nm, only_whites; - char *pc; - - DBG(fprintf (stderr, "probeText started, text: '%s'\n", text);) - if (sdata->validationState == VALIDATION_FINISHED) { - SetResult ("Validation finished."); - return TCL_ERROR; - } - if (sdata->validationState == VALIDATION_READY) { - SetResult ("No validation started"); - return TCL_ERROR; - } - - getContext (parent, ac, nm); - - while (ac < parent->numChildren) { - if (parent->content[ac]->type == STRUCTURE_CTYPE_TEXT - || mustMatch (parent->quants[ac], nm)) break; - ac++; - nm = 0; - } - if (ac < parent->numChildren) { - if (parent->content[ac]->type == STRUCTURE_CTYPE_TEXT) { - return checkText (interp, parent->content[ac], text); - } - } - /* If we are here then there isn't a matching TEXT cp. Check, if - * this is white space only between tags. */ - only_whites = 1; - pc = text; - while (*pc) { - if ( (*pc == ' ') || - (*pc == '\n') || - (*pc == '\r') || - (*pc == '\t') ) { - pc++; - continue; - } - only_whites = 0; - break; - } - if (only_whites) return TCL_OK; - return TCL_ERROR; -} - -static void -startElement( - void *userData, - const char *name, - const char **atts -) -{ - ValidateMethodData *vdata = (ValidateMethodData *) userData; - char *namespace; - const char *s; - int i = 0; - - DBG(fprintf (stderr, "startElement: '%s'\n", name);) - if (Tcl_DStringLength (vdata->cdata)) { - if (probeText (vdata->interp, vdata->sdata, - Tcl_DStringValue (vdata->cdata)) != TCL_OK) { - XML_StopParser (vdata->parser, 0); - } - } - s = name; - while (*s && *s != '\xFF') { - i++; s++; - } - namespace = NULL; - if (*s == '\xFF') { - s++; - if (i) { - if (i >= vdata->maxUriLen - 1) { - vdata->uri = (char *) REALLOC (vdata->uri, vdata->maxUriLen * 2); - vdata->maxUriLen *= 2; - } - memcpy (vdata->uri, name, i); - vdata->uri[i] = '\0'; - namespace = vdata->uri; - } - } else { - s = name; - } - - if (probeElement (vdata->interp, vdata->sdata, s, namespace) - != TCL_OK) { - XML_StopParser (vdata->parser, 0); - } -} - -static void -endElement ( - void *userData, - const char *name -) -{ - ValidateMethodData *vdata = (ValidateMethodData *) userData; - - DBG(fprintf (stderr, "endElement: '%s'\n", name);) - if (Tcl_DStringLength (vdata->cdata)) { - if (probeText (vdata->interp, vdata->sdata, - Tcl_DStringValue (vdata->cdata)) != TCL_OK) { - XML_StopParser (vdata->parser, 0); - } - } - if (probeElementEnd (vdata->interp, vdata->sdata) - != TCL_OK) { - XML_StopParser (vdata->parser, 0); - } -} - -static void -characterDataHandler ( - void *userData, - const char *s, - int len -) -{ - ValidateMethodData *vdata = (ValidateMethodData *) userData; - - Tcl_DStringAppend (vdata->cdata, s, len); -} - -static int -validateString ( - Tcl_Interp *interp, - StructureData *sdata, - char *xmlstr, - int len - ) -{ - XML_Parser parser; - char sep = '\xFF'; - ValidateMethodData vdata; - Tcl_DString cdata; - Tcl_Obj *resultObj; - char sl[50], sc[50]; - int result; - - parser = XML_ParserCreate_MM (NULL, MEM_SUITE, &sep); - vdata.interp = interp; - vdata.sdata = sdata; - vdata.parser = parser; - Tcl_DStringInit (&cdata); - vdata.cdata = &cdata; - vdata.uri = (char *) MALLOC (URI_BUFFER_LEN_INIT); - vdata.maxUriLen = URI_BUFFER_LEN_INIT; - XML_SetUserData (parser, &vdata); - XML_SetElementHandler (parser, startElement, endElement); - XML_SetCharacterDataHandler (parser, characterDataHandler); - - if (XML_Parse (parser, xmlstr, len, 1) != XML_STATUS_OK) { - resultObj = Tcl_NewObj (); - sprintf(sl, "%ld", XML_GetCurrentLineNumber(parser)); - sprintf(sc, "%ld", XML_GetCurrentColumnNumber(parser)); - Tcl_AppendStringsToObj (resultObj, "error \"", - Tcl_GetStringResult (interp),"\" at line ", - sl, " character ", sc, NULL); - Tcl_SetObjResult (interp, resultObj); - result = TCL_ERROR; - } else { - result = TCL_OK; - } - XML_ParserFree (parser); - Tcl_DStringFree (&cdata); - FREE (vdata.uri); - return result; -} - -int -structureInstanceCmd ( - ClientData clientData, - Tcl_Interp *interp, - int objc, - Tcl_Obj *const objv[] - ) -{ - int methodIndex, keywordIndex, hnew, patternIndex; - int result = TCL_OK, forwardDef = 0, i = 0; - int savedDefineToplevel, type, len; - unsigned int savedNumPatternList; - StructureData *sdata = (StructureData *) clientData; - Tcl_HashTable *hashTable; - Tcl_HashEntry *entryPtr; - StructureCP *pattern, *current = NULL; - void *namespacePtr, *savedNamespacePtr; - char *xmlstr; - - static const char *structureInstanceMethods[] = { - "defelement", "defpattern", "start", "event", "delete", - "nrForwardDefinitions", "state", "reset", "define", - "validate", NULL - }; - enum structureInstanceMethod { - m_defelement, m_defpattern, m_start, m_event, m_delete, - m_nrForwardDefinitions, m_state, m_reset, m_define, - m_validate - }; - - static const char *eventKeywords[] = { - "start", "end", "text", NULL - }; - - enum eventKeyword - { - k_elementstart, k_elementend, k_text - }; - - if (objc < 2) { - Tcl_WrongNumArgs (interp, 1, objv, "subcommand ?arguments?"); - return TCL_ERROR; - } - - if (sdata == NULL) { - /* Inline defined defelement, defpattern or start */ - sdata = GETASI; - CHECK_SI; - i = 1; - } - - if (Tcl_GetIndexFromObj (interp, objv[1-i], structureInstanceMethods, - "method", 0, &methodIndex) - != TCL_OK) { - return TCL_ERROR; - } - - Tcl_ResetResult (interp); - switch ((enum structureInstanceMethod) methodIndex) { - case m_defelement: - case m_defpattern: - if (objc != 4-i && objc != 5-i) { - Tcl_WrongNumArgs (interp, 1-i, objv, "" - " ?? pattern"); - return TCL_ERROR; - } - if ((enum structureInstanceMethod) methodIndex == m_defelement) { - hashTable = &sdata->element; - type = STRUCTURE_CTYPE_NAME; - } else { - hashTable = &sdata->pattern; - type = STRUCTURE_CTYPE_PATTERN; - } - savedNumPatternList = sdata->numPatternList; - namespacePtr = NULL; - patternIndex = 3-i; - if (objc == 5-i) { - patternIndex = 4-i; - entryPtr = Tcl_CreateHashEntry (&sdata->namespace, - Tcl_GetString (objv[3-i]), &hnew); - if (entryPtr != sdata->emptyNamespace) { - namespacePtr = Tcl_GetHashKey (&sdata->namespace, - entryPtr); - } - } - entryPtr = Tcl_CreateHashEntry (hashTable, - Tcl_GetString (objv[2-i]), &hnew); - pattern = NULL; - if (!hnew) { - pattern = (StructureCP *) Tcl_GetHashValue (entryPtr); - while (pattern) { - if (pattern->namespace == namespacePtr) { - if (pattern->flags & FORWARD_PATTERN_DEF - || pattern->flags & PLACEHOLDER_PATTERN_DEF) { - forwardDef = 1; - break; - } - if ((enum structureInstanceMethod) methodIndex - == m_defelement) { - SetResult ("Element already defined " - "in this namespace."); - } else { - SetResult ("Pattern already defined " - "in this namespace."); - } - return TCL_ERROR; - } - pattern = pattern->next; - } - } - if (pattern == NULL) { - pattern = initStructureCP (type, namespacePtr, - Tcl_GetHashKey (hashTable, entryPtr)); - if (!hnew) { - current = (StructureCP *) Tcl_GetHashValue (entryPtr); - pattern->next = current; - } - REMEMBER_PATTERN (pattern); - Tcl_SetHashValue (entryPtr, pattern); - } - - if (!sdata->defineToplevel) { - SETASI(sdata); - } - savedDefineToplevel = sdata->defineToplevel; - savedNamespacePtr = sdata->currentNamespace; - sdata->defineToplevel = 0; - sdata->currentNamespace = namespacePtr; - sdata->currentContent = pattern->content; - sdata->currentQuants = pattern->quants; - sdata->numChildren = 0; - sdata->contentSize = CONTENT_ARRAY_SIZE_INIT; - sdata->evalStub[3] = objv[patternIndex]; - result = Tcl_EvalObjv (interp, 4, sdata->evalStub, - TCL_EVAL_DIRECT | TCL_EVAL_GLOBAL); - sdata->currentNamespace = NULL; - pattern->content = sdata->currentContent; - pattern->quants = sdata->currentQuants; - pattern->numChildren = sdata->numChildren; - if (result == TCL_OK) { - if (forwardDef) { - if (pattern->flags & FORWARD_PATTERN_DEF) { - sdata->forwardPatternDefs--; - pattern->flags &= ~FORWARD_PATTERN_DEF; - } - pattern->flags &= ~PLACEHOLDER_PATTERN_DEF; - } - } else { - cleanupLastPattern (sdata, savedNumPatternList); - } - sdata->defineToplevel = savedDefineToplevel; - sdata->currentNamespace = savedNamespacePtr; - if (!savedDefineToplevel) { - SETASI(0); - } - break; - - case m_define: - if (objc != 3) { - Tcl_WrongNumArgs (interp, 2, objv, ""); - return TCL_ERROR; - } - SETASI(sdata); - savedNumPatternList = sdata->numPatternList; - sdata->currentNamespace = 0; - sdata->currentContent = NULL; - sdata->currentQuants = NULL; - sdata->numChildren = 0; - sdata->contentSize = 0; - sdata->defineToplevel = 1; - sdata->evalStub[3] = objv[2]; - result = Tcl_EvalObjv (interp, 4, sdata->evalStub, - TCL_EVAL_DIRECT | TCL_EVAL_GLOBAL); - if (result != TCL_OK) { - cleanupLastPattern (sdata, savedNumPatternList); - } - sdata->defineToplevel = 0; - SETASI(0); - break; - - case m_start: - if (objc < 3-i || objc > 3-i) { - Tcl_WrongNumArgs (interp, 2-i, objv, "" - " ??"); - return TCL_ERROR; - } - if (sdata->start) { - FREE (sdata->start); - } - if (objc == 3-i && strcmp (Tcl_GetString (objv[2-i]), "") == 0) { - if (sdata->startNamespace) { - FREE (sdata->startNamespace); - } - sdata->start = NULL; - break; - } - sdata->start = tdomstrdup (Tcl_GetString (objv[2-i])); - if (objc == 4-i) { - if (sdata->startNamespace) { - FREE (sdata->startNamespace); - } - sdata->startNamespace = - tdomstrdup (Tcl_GetString (objv[3-i])); - } - break; - - case m_event: - if (objc < 3) { - Tcl_WrongNumArgs (interp, 2, objv, "" - " ??"); - return TCL_ERROR; - } - if (Tcl_GetIndexFromObj (interp, objv[2], eventKeywords, - "keyword", 0, &keywordIndex) - != TCL_OK) { - return TCL_ERROR; - } - switch ((enum eventKeyword) keywordIndex) { - case k_elementstart: - if (objc < 4 && objc > 6) { - Tcl_WrongNumArgs (interp, 3, objv, "" - "?? ??"); - return TCL_ERROR; - } - if (objc == 6) { - entryPtr = Tcl_FindHashEntry (&sdata->namespace, - Tcl_GetString (objv[5])); - if (entryPtr && entryPtr != sdata->emptyNamespace) { - namespacePtr = Tcl_GetHashKey (&sdata->namespace, - entryPtr); - } else { - namespacePtr = NULL; - } - } else { - namespacePtr = NULL; - } - result = probeElement (interp, sdata, Tcl_GetString (objv[3]), - namespacePtr); - break; - case k_elementend: - if (objc != 3) { - Tcl_WrongNumArgs (interp, 3, objv, "No arguments expected."); - return TCL_ERROR; - } - result = probeElementEnd (interp, sdata); - break; - - case k_text: - if (objc != 4) { - Tcl_WrongNumArgs (interp, 3, objv, ""); - return TCL_ERROR; - } - result = probeText (interp, sdata, Tcl_GetString (objv[3])); - break; - } - break; - - case m_delete: - if (objc != 2) { - Tcl_WrongNumArgs(interp, 2, objv, ""); - return TCL_ERROR; - } - Tcl_DeleteCommand(interp, Tcl_GetString(objv[0])); - break; - - case m_nrForwardDefinitions: - if (objc != 2) { - Tcl_WrongNumArgs(interp, 2, objv, ""); - return TCL_ERROR; - } - SetIntResult(sdata->forwardPatternDefs); - break; - - case m_state: - switch (sdata->validationState) { - case VALIDATION_READY: - SetResult ("READY"); - break; - case VALIDATION_STARTED: - SetResult ("VALIDATING"); - break; - case VALIDATION_FINISHED: - SetResult ("FINISHED"); - break; - default: - SetResult ("Internal error: Invalid validation state."); - return TCL_ERROR; - } - break; - - case m_reset: - sdata->stackPtr = 0; - sdata->validationState = VALIDATION_READY; - break; - - case m_validate: - if (objc < 3 || objc > 4) { - Tcl_WrongNumArgs (interp, 2, objv, " ?resultVarName?"); - return TCL_ERROR; - } - xmlstr = Tcl_GetStringFromObj (objv[2], &len); - if (validateString (interp, sdata, xmlstr, len) == TCL_OK) { - SetBooleanResult (1); - } else { - if (objc == 4) { - Tcl_SetVar (interp, Tcl_GetString (objv[3]), - Tcl_GetStringResult (interp), 0); - } - SetBooleanResult (0); - } - break; - - default: - Tcl_SetResult (interp, "unknown method", NULL); - result = TCL_ERROR; - break; - - } - return result; -} - - -/* - *---------------------------------------------------------------------------- - * - * tDOM_StructureObjCmd -- - * - * This procedure is invoked to process the "structure" command. - * See the user documentation for what it does. - * - * Results: - * A standard Tcl result. - * - * Side effects: - * - * - *---------------------------------------------------------------------------- - */ - -int -tDOM_StructureObjCmd ( - ClientData clientData, - Tcl_Interp *interp, - int objc, - Tcl_Obj *const objv[] - ) -{ - int methodIndex, result = TCL_OK; - StructureData *sdata; - - static const char *structureMethods[] = { - "create", NULL - }; - enum structureMethod { - m_create - }; - - if (objc < 2 || objc > 3) { - Tcl_WrongNumArgs (interp, 1, objv, "subcommand ?argument?"); - return TCL_ERROR; - } - - if (objc == 2) { - methodIndex = m_create; - } else { - if (Tcl_GetIndexFromObj (interp, objv[1], structureMethods, - "method", 0, &methodIndex) - != TCL_OK) { - return TCL_ERROR; - } - } - - Tcl_ResetResult (interp); - switch ((enum structureMethod) methodIndex) { - case m_create: - sdata = initStructureData (); - Tcl_CreateObjCommand (interp, Tcl_GetString(objv[2]), - structureInstanceCmd, - (ClientData) sdata, - structureInstanceDelete); - Tcl_SetObjResult (interp, objv[2]); - break; - - default: - Tcl_SetResult (interp, "unknown method", NULL); - result = TCL_ERROR; - break; - - } - return result; -} - - -static StructureQuant * -initStructureQuant ( - StructureData * sdata, - Structure_Content_Quant quantType, - int n, - int m - ) -{ - StructureQuant * quant; - - quant = TMALLOC (StructureQuant); - quant->type = quantType; - quant->minOccur = n; - quant->maxOccur = m; - if (sdata->numQuants == sdata->quantsSize) { - sdata->quants = REALLOC ( - sdata->quants, - sizeof (StructureQuant*) * 2 * sdata->quantsSize - ); - sdata->quantsSize *= 2; - } - sdata->quants[sdata->numQuants] = quant; - sdata->numQuants++; - return quant; -} - - -static StructureQuant * -getQuant ( - Tcl_Interp *interp, - StructureData *sdata, - Tcl_Obj *quantObj - ) -{ - char *quantStr; - int len, n, m; - Tcl_Obj *thisObj; - - if (!quantObj) { - return quantOne; - } - quantStr = Tcl_GetStringFromObj (quantObj, &len); - if (len == 1) { - switch (quantStr[0]) { - case '!': - return quantOne; - case '*': - return quantRep; - case '?': - return quantOpt; - case '+': - return quantPlus; - } - } - if (Tcl_ListObjLength (interp, quantObj, &len) != TCL_OK) { - SetResult ("Invalid quant specifier."); - return NULL; - } - if (len != 1 && len != 2) { - SetResult ("Invalid quant specifier."); - return NULL; - } - if (len == 1) { - if (Tcl_GetIntFromObj (interp, quantObj, &n) != TCL_OK) { - SetResult ("Invalid quant specifier."); - return NULL; - } - if (n < 1) { - SetResult ("Invalid quant specifier."); - return NULL; - } - if (n == 1) { - return quantOne; - } - return initStructureQuant (sdata, STRUCTURE_CQUANT_NM, n, n); - } - /* The "list-ness" of the quantObj is already checked by the - * Tcl_ListObjLength() call above, no need to check result. */ - Tcl_ListObjIndex (interp, quantObj, 0, &thisObj); - if (Tcl_GetIntFromObj (interp, thisObj, &n) != TCL_OK) { - SetResult ("Invalid quant specifier."); - return NULL; - } - if (n < 0) { - SetResult ("Invalid quant specifier."); - return NULL; - } - Tcl_ListObjIndex (interp, quantObj, 1, &thisObj); - if (Tcl_GetIntFromObj (interp, thisObj, &m) != TCL_OK) { - SetResult ("Invalid quant specifier."); - return NULL; - } - if (n >= m) { - SetResult ("Invalid quant specifier."); - return NULL; - } - if (n == 0 && m == 1) { - return quantOpt; - } - return initStructureQuant (sdata, STRUCTURE_CQUANT_NM, n, m); -} - -/* Implements the grammar definition commands "empty" and "any" */ -static int -EmptyAnyPatternObjCmd ( - ClientData clientData, - Tcl_Interp *interp, - int objc, - Tcl_Obj *const objv[] - ) -{ - StructureData *sdata = GETASI; - StructureCP *pattern; - - CHECK_SI - CHECK_TOPLEVEL - checkNrArgs (1,1,"No arguments expected."); - pattern = initStructureCP ((Structure_CP_Type) clientData, - NULL, NULL); - REMEMBER_PATTERN (pattern) - ADD_TO_CONTENT (pattern, quantRep) - return TCL_OK; -} - -static int -evalDefinition ( - Tcl_Interp *interp, - StructureData *sdata, - Tcl_Obj *definition, - StructureCP *pattern, - StructureQuant *quant - ) -{ - StructureCP **savedCurrentContent; - StructureQuant **savedCurrentQuant; - unsigned int savedNumChildren, savedContenSize; - int result; - - /* Save some state of sdata .. */ - savedCurrentContent = sdata->currentContent; - savedCurrentQuant = sdata->currentQuants; - savedNumChildren = sdata->numChildren; - savedContenSize = sdata->contentSize; - /* ... and prepare sdata for definition evaluation. */ - sdata->currentContent = pattern->content; - sdata->currentQuants = pattern->quants; - sdata->numChildren = 0; - sdata->contentSize = CONTENT_ARRAY_SIZE_INIT; - - result = Tcl_EvalObjEx (interp, definition, TCL_EVAL_DIRECT); - - /* Save the definition evaluation results to the pattern ... */ - pattern->content = sdata->currentContent; - pattern->quants = sdata->currentQuants; - pattern->numChildren = sdata->numChildren; - /* ... and restore the previously saved sdata states */ - sdata->currentContent = savedCurrentContent; - sdata->currentQuants = savedCurrentQuant; - sdata->numChildren = savedNumChildren; - sdata->contentSize = savedContenSize; - - if (result == TCL_OK) { - REMEMBER_PATTERN (pattern); - ADD_TO_CONTENT (pattern, quant); - } else { - freeStructureCP (pattern); - } - return result; -} - -/* Implements the grammar definition commands "element" and "ref" */ -static int -NamedPatternObjCmd ( - ClientData clientData, - Tcl_Interp *interp, - int objc, - Tcl_Obj *const objv[] - ) -{ - StructureData *sdata = GETASI; - Structure_CP_Type patternType = (Structure_CP_Type) clientData; - Tcl_HashTable *hashTable; - Tcl_HashEntry *entryPtr; - StructureCP *pattern = NULL, *current; - StructureQuant *quant; - int hnew; - - CHECK_SI - CHECK_TOPLEVEL - if (patternType == STRUCTURE_CTYPE_NAME) { - checkNrArgs (2,4,"Expected: elementName ?quant? ?pattern?"); - hashTable = &sdata->element; - } else { - checkNrArgs (2,3,"Expected: patternName ?quant?"); - hashTable = &sdata->pattern; - } - - quant = getQuant (interp, sdata, objc == 2 ? NULL : objv[2]); - if (!quant) { - return TCL_ERROR; - } - entryPtr = Tcl_CreateHashEntry (hashTable, - Tcl_GetString(objv[1]), &hnew); - if (objc < 4) { - /* Reference to an element or pattern */ - if (!hnew) { - pattern = (StructureCP *) Tcl_GetHashValue (entryPtr); - while (pattern) { - if (pattern->namespace == sdata->currentNamespace) { - break; - } - pattern = pattern->next; - } - } - if (!pattern) { - pattern = initStructureCP ( - patternType, - sdata->currentNamespace, - Tcl_GetHashKey (hashTable, entryPtr) - ); - pattern->flags |= FORWARD_PATTERN_DEF; - sdata->forwardPatternDefs++; - if (!hnew) { - current = (StructureCP *) Tcl_GetHashValue (entryPtr); - pattern->next = current; - } - REMEMBER_PATTERN (pattern); - Tcl_SetHashValue (entryPtr, pattern); - } - ADD_TO_CONTENT (pattern, quant); - } else { - /* Local definition of this element */ - if (hnew) { - pattern = initStructureCP ( - STRUCTURE_CTYPE_NAME, - sdata->currentNamespace, - Tcl_GetHashKey (hashTable, entryPtr) - ); - pattern->flags |= PLACEHOLDER_PATTERN_DEF; - REMEMBER_PATTERN (pattern); - Tcl_SetHashValue (entryPtr, pattern); - } - pattern = initStructureCP ( - STRUCTURE_CTYPE_NAME, - sdata->currentNamespace, - Tcl_GetHashKey (hashTable, entryPtr) - ); - pattern->flags |= LOCAL_DEFINED_ELEMENT; - return evalDefinition (interp, sdata, objv[3], pattern, quant); - } - return TCL_OK; -} - -/* Implements the grammar definition commands "choice", "group", - * "interleave" and "mixed" */ -static int -AnonPatternObjCmd ( - ClientData clientData, - Tcl_Interp *interp, - int objc, - Tcl_Obj *const objv[] - ) -{ - StructureData *sdata = GETASI; - Structure_CP_Type patternType = (Structure_CP_Type) clientData; - StructureQuant *quant; - StructureCP *pattern; - - CHECK_SI - CHECK_TOPLEVEL - checkNrArgs (2,3,"Expected: ?quant? definition"); - quant = getQuant (interp, sdata, objc == 2 ? NULL : objv[1]); - if (!quant) { - return TCL_ERROR; - } - - pattern = initStructureCP (patternType, NULL, NULL); - - return evalDefinition (interp, sdata, objc == 2 ? objv[1] : objv[2], - pattern, quant); -} - -static int -AttributePatternObjCmd ( - ClientData clientData, - Tcl_Interp *interp, - int objc, - Tcl_Obj *const objv[] - ) -{ - - return TCL_OK; -} - -static int -NamespacePatternObjCmd ( - ClientData clientData, - Tcl_Interp *interp, - int objc, - Tcl_Obj *const objv[] - ) -{ - StructureData *sdata = GETASI; - char *currentNamespace; - Tcl_HashEntry *entryPtr; - int hnew, result; - - CHECK_SI - CHECK_TOPLEVEL - checkNrArgs (3,3,"Expected: namespace pattern"); - - currentNamespace = sdata->currentNamespace; - entryPtr = Tcl_CreateHashEntry (&sdata->namespace, - objv[1], &hnew); - if (entryPtr == sdata->emptyNamespace) { - sdata->currentNamespace = NULL; - } else { - sdata->currentNamespace = (char *) - Tcl_GetHashKey (&sdata->namespace, entryPtr); - } - result = Tcl_EvalObjEx (interp, objv[2], TCL_EVAL_DIRECT); - sdata->currentNamespace = currentNamespace; - return result; -} - -static int -TextPatternObjCmd ( - ClientData clientData, - Tcl_Interp *interp, - int objc, - Tcl_Obj *const objv[] - ) -{ - StructureData *sdata = GETASI; - StructureCP *pattern; - - CHECK_SI - CHECK_TOPLEVEL - checkNrArgs (1,1,"No arguments expected."); - pattern = initStructureCP ((Structure_CP_Type) clientData, - NULL, NULL); - REMEMBER_PATTERN (pattern) - ADD_TO_CONTENT (pattern, quantOne) - return TCL_OK; -} - -void -tDOM_StructureInit ( - Tcl_Interp *interp - ) -{ - memset (quantOne, 0, sizeof (StructureQuant)); - quantOne->type = STRUCTURE_CQUANT_ONE; - memset (quantOpt, 0, sizeof (StructureQuant)); - quantOpt->type = STRUCTURE_CQUANT_OPT; - memset (quantRep, 0, sizeof (StructureQuant)); - quantRep->type = STRUCTURE_CQUANT_REP; - memset (quantPlus, 0, sizeof (StructureQuant)); - quantPlus->type = STRUCTURE_CQUANT_PLUS; - - /* Inline definition commands. */ - Tcl_CreateObjCommand (interp, "tdom::structure::defelement", - structureInstanceCmd, NULL, NULL); - Tcl_CreateObjCommand (interp, "tdom::structure::defpattern", - structureInstanceCmd, NULL, NULL); - Tcl_CreateObjCommand (interp, "tdom::structure::start", - structureInstanceCmd, NULL, NULL); - - /* The "empty" and "any" definition commands. */ - Tcl_CreateObjCommand (interp, "tdom::structure::empty", - EmptyAnyPatternObjCmd, - (ClientData) STRUCTURE_CTYPE_EMPTY, NULL); - Tcl_CreateObjCommand (interp, "tdom::structure::any", - EmptyAnyPatternObjCmd, - (ClientData) STRUCTURE_CTYPE_ANY, NULL); - - /* The named pattern commands "element" and "ref". */ - Tcl_CreateObjCommand (interp, "tdom::structure::element", - NamedPatternObjCmd, - (ClientData) STRUCTURE_CTYPE_NAME, NULL); - Tcl_CreateObjCommand (interp, "tdom::structure::ref", - NamedPatternObjCmd, - (ClientData) STRUCTURE_CTYPE_PATTERN, NULL); - /* The anonymous pattern commands "choise", "mixed", "interleave" - * and "group". */ - Tcl_CreateObjCommand (interp, "tdom::structure::choice", - AnonPatternObjCmd, - (ClientData) STRUCTURE_CTYPE_CHOICE, NULL); - Tcl_CreateObjCommand (interp, "tdom::structure::mixed", - AnonPatternObjCmd, - (ClientData) STRUCTURE_CTYPE_MIXED, NULL); - Tcl_CreateObjCommand (interp, "tdom::structure::interleave", - AnonPatternObjCmd, - (ClientData) STRUCTURE_CTYPE_INTERLEAVE, NULL); - Tcl_CreateObjCommand (interp, "tdom::structure::group", - AnonPatternObjCmd, - (ClientData) STRUCTURE_CTYPE_GROUP, NULL); - - /* The "attribute", "namespace" and "text" definition commands. */ - Tcl_CreateObjCommand (interp, "tdom::structure::attribute", - AttributePatternObjCmd, NULL, NULL); - Tcl_CreateObjCommand (interp, "tdom::structure::namespace", - NamespacePatternObjCmd, NULL, NULL); - Tcl_CreateObjCommand (interp, "tdom::structure::text", - TextPatternObjCmd, NULL, NULL); -} - -# else /* #ifndef TDOM_NO_STRUCTURE */ -int -structureInstanceCmd ( - ClientData clientData, - Tcl_Interp *interp, - int objc, - Tcl_Obj *const objv[] - ) -{ - return TCL_OK; -} - -int -probeElement ( - Tcl_Interp *interp, - StructureData *sdata, - char *name, - void *namespace - ) -{ - return TCL_OK; -} - -int -probeElementEnd ( - Tcl_Interp * interp, - StructureData *sdata - ) -{ - return TCL_OK; -} - -int -probeText ( - Tcl_Interp *interp, - StructureData *sdata, - char *text - ) -{ - return TCL_OK; -} - -#endif /* #ifndef TDOM_NO_STRUCTURE */ DELETED generic/structure.h Index: generic/structure.h ================================================================== --- generic/structure.h +++ /dev/null @@ -1,162 +0,0 @@ -/*---------------------------------------------------------------------------- -| Copyright (c) 2018 Rolf Ade (rolf@pointsman.de) -|----------------------------------------------------------------------------- -| -| -| The contents of this file are subject to the Mozilla Public License -| Version 2.0 (the "License"); you may not use this file except in -| compliance with the License. You may obtain a copy of the License at -| http://www.mozilla.org/MPL/ -| -| Software distributed under the License is distributed on an "AS IS" -| basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the -| License for the specific language governing rights and limitations -| under the License. -| -| Contributor(s): -| -| -| written by Rolf Ade -| November 2018 -| -\---------------------------------------------------------------------------*/ - -#ifndef __STRUCTURE_H__ -#define __STRUCTURE_H__ - -typedef enum { - STRUCTURE_CTYPE_EMPTY, - STRUCTURE_CTYPE_ANY, - STRUCTURE_CTYPE_MIXED, - STRUCTURE_CTYPE_NAME, - STRUCTURE_CTYPE_CHOICE, - STRUCTURE_CTYPE_INTERLEAVE, - STRUCTURE_CTYPE_PATTERN, - STRUCTURE_CTYPE_GROUP, - STRUCTURE_CTYPE_TEXT -} Structure_CP_Type; - -typedef enum { - STRUCTURE_CQUANT_ONE, - STRUCTURE_CQUANT_OPT, - STRUCTURE_CQUANT_REP, - STRUCTURE_CQUANT_PLUS, - STRUCTURE_CQUANT_NM -} Structure_Content_Quant; - -typedef unsigned int QuantFlags; - -typedef struct -{ - Structure_Content_Quant type; - int minOccur; - int maxOccur; -} StructureQuant; - -typedef unsigned int StructureFlags; - -typedef struct StructureCP -{ - Structure_CP_Type type; - char *namespace; - char *name; - struct StructureCP *next; - StructureFlags flags; - struct StructureCP **content; - StructureQuant **quants; - unsigned int numChildren; -} StructureCP; - -typedef struct StructureValidationStack -{ - StructureCP *pattern; - struct StructureValidationStack *next; - struct StructureValidationStack *down; - int activeChild; - int deep; - int nrMatched; - unsigned int stacklistWatermark; -} StructureValidationStack; - -typedef enum { - VALIDATION_READY, - VALIDATION_STARTED, - VALIDATION_FINISHED -} ValidationState; - -typedef struct -{ - char *start; - char *startNamespace; - Tcl_HashTable element; - Tcl_HashTable namespace; - Tcl_HashEntry *emptyNamespace; - Tcl_HashTable pattern; - StructureCP **patternList; - unsigned int numPatternList; - unsigned int patternListSize; - unsigned int forwardPatternDefs; - StructureQuant **quants; - unsigned int numQuants; - unsigned int quantsSize; - Tcl_Obj **evalStub; - char *currentNamespace; - char *currentAttributeNamespace; - int defineToplevel; - int isAttribute; - StructureCP **currentContent; - StructureQuant **currentQuants; - unsigned int numChildren; - unsigned int contentSize; - StructureValidationStack **stack; - int stackSize; - int stackPtr; - ValidationState validationState; - StructureValidationStack **stackList; - unsigned int numStackList; - unsigned int stackListSize; - unsigned int numStackAllocated; -} StructureData; - -int -structureInstanceCmd ( - ClientData clientData, - Tcl_Interp *interp, - int objc, - Tcl_Obj *const objv[] - ); - -int tDOM_StructureObjCmd ( - ClientData clientData, - Tcl_Interp *interp, - int objc, - Tcl_Obj *CONST objv[] - ); - -void tDOM_StructureInit ( - Tcl_Interp *interp - ); - -int -probeElement ( - Tcl_Interp *interp, - StructureData *sdata, - const char *name, - void *namespace - ); - -int -probeElementEnd ( - Tcl_Interp * interp, - StructureData *sdata - ); - -int -probeText ( - Tcl_Interp *interp, - StructureData *sdata, - char *text - ); - - -#endif Index: generic/tcldom.c ================================================================== --- generic/tcldom.c +++ generic/tcldom.c @@ -1,11 +1,8 @@ /*---------------------------------------------------------------------------- | Copyright (c) 1999 Jochen Loewer (loewerj@hotmail.com) +----------------------------------------------------------------------------- -| -| $Id$ -| | | A DOM implementation for Tcl using James Clark's expat XML parser | | | The contents of this file are subject to the Mozilla Public License @@ -49,11 +46,11 @@ #include #include #include #include #include -#include +#include #include /* #define DEBUG */ /*---------------------------------------------------------------------------- | Debug Macros @@ -163,10 +160,12 @@ #define SERIALIZE_ESCAPE_NON_ASCII 8 #define SERIALIZE_HTML_ENTITIES 16 #define SERIALIZE_ESCAPE_ALL_QUOT 32 #define SERIALIZE_NO_GT_ESCAPE 64 #define SERIALIZE_NO_EMPTY_ELEMENT_TAG 128 +#define SERIALIZE_INDENT_WITH_TAB 256 +#define SERIALIZE_INDENT_ATTR_WITH_TAB 512 /*---------------------------------------------------------------------------- | Module Globals | \---------------------------------------------------------------------------*/ @@ -221,10 +220,12 @@ " setStoreLineColumn ?boolean? \n" " setNameCheck ?boolean? \n" " setTextCheck ?boolean? \n" " setObjectCommands ?(automatic|token|command)? \n" " isCharData string \n" + " clearString string \n" + " isBMPCharData string \n" " isComment string \n" " isCDATA string \n" " isPIValue string \n" " isName string \n" " isQName string \n" @@ -242,11 +243,11 @@ " createElementNS uri tagName ?objVar? \n" " createCDATASection data ?objVar? \n" " createTextNode text ?objVar? \n" " createComment text ?objVar? \n" " createProcessingInstruction target data ?objVar? \n" - " asXML ?-indent ? ?-channel ? ?-escapeNonASCII? ?-escapeAllQuot? ?-doctypeDeclaration ?\n" + " asXML ?-indent ? ?-channel ? ?-escapeNonASCII? ?-escapeAllQuot? ?-doctypeDeclaration ?\n" " asHTML ?-channel ? ?-escapeNonASCII? ?-htmlEntities?\n" " asText \n" " asJSON ?-indent ? \n" " getDefaultOutputMethod \n" " publicId ?publicId? \n" @@ -339,11 +340,11 @@ " delete \n" " getLine \n" " getColumn \n" " @ ?defaultValue? \n" " asList \n" - " asXML ?-indent ? ?-channel ? ?-escapeNonASCII? ?-escapeAllQuot? ?-doctypeDeclaration ?\n" + " asXML ?-indent ? ?-channel ? ?-escapeNonASCII? ?-escapeAllQuot? ?-doctypeDeclaration ?\n" " asHTML ?-channel ? ?-escapeNonASCII? ?-htmlEntities?\n" " asText \n" " asJSON ?-indent ? \n" " appendFromList nestedList \n" " appendFromScript script \n" @@ -398,31 +399,16 @@ /*---------------------------------------------------------------------------- | Prototypes for procedures defined later in this file: | \---------------------------------------------------------------------------*/ -#if (TCL_MAJOR_VERSION == 8) && (TCL_MINOR_VERSION <= 3) -/* - * Before Tcl 8.4, Tcl_VarTraceProc and Tcl_CmdDeleteProc were not - * CONST84'ified. When compiling with -DTCL_NO_DEPRECATED, CONST84 is - * gone, therefore we can't use the function type definitions of - * Tcl_VarTraceProc and Tcl_CmdDeleteProc for these old version. - * - */ -static char * tcldom_docTrace( - ClientData clientData, Tcl_Interp *interp, - const char *part1, const char *part2, int flags); -static void tcldom_docCmdDeleteProc(ClientData clientData); -#else static Tcl_VarTraceProc tcldom_docTrace; static Tcl_CmdDeleteProc tcldom_docCmdDeleteProc; -#endif static void tcldom_treeAsJSON(Tcl_Obj *jstring, domNode *node, Tcl_Channel channel, int indent, - int level, - int inside); + int outputFlags, int level, int inside); #ifdef TCL_THREADS static int tcldom_EvalLocked(Tcl_Interp* interp, Tcl_Obj** objv, domDocument* doc, int flag); @@ -676,11 +662,10 @@ /*---------------------------------------------------------------------------- | tcldom_setInterpAndReturnVar | \---------------------------------------------------------------------------*/ -static int tcldom_setInterpAndReturnVar ( Tcl_Interp *interp, domNode *node, int setVariable, Tcl_Obj *var_name @@ -1239,11 +1224,13 @@ NULL, NULL, extResolver, 0, (int) XML_PARAM_ENTITY_PARSING_ALWAYS, +#ifndef TDOM_NO_SCHEMA NULL, +#endif interp, &resultcode); if (extResolver) { Tcl_DecrRefCount(extResolver); } @@ -1392,11 +1379,10 @@ /*---------------------------------------------------------------------------- | tcldom_xpathFuncCallBack | \---------------------------------------------------------------------------*/ -static int tcldom_xpathFuncCallBack ( void *clientData, char *functionName, domNode *ctxNode, int position, @@ -2515,13 +2501,17 @@ if (clen == 4) { unicode = ((pc[0] & 0x07) << 18) + ((pc[1] & 0x3F) << 12) + ((pc[2] & 0x3F) << 6) + (pc[3] & 0x3F); + } else if (clen == 3) { + unicode = ((pc[0] & 0x0F) << 12) + + ((pc[1] & 0x3F) << 6) + + (pc[2] & 0x3F); } else { - unicode = 0; - Tcl_UtfToUniChar(pc, (Tcl_UniChar*)&unicode); + unicode = ((pc[0] & 0x1F) << 6) + + (pc[1] & 0x3F); } AP('&') AP('#') sprintf(charRef, "%d", unicode); for (i = 0; i < (int)strlen(charRef); i++) { AP(charRef[i]); @@ -2583,11 +2573,13 @@ domNode *node, Tcl_Channel chan, int escapeNonASCII, int htmlEntities, int doctypeDeclaration, - int noEscaping + int noEscaping, + int onlyContents, + int breakLines ) { int empty, scriptTag, outputFlags = 0; domNode *child; domAttrNode *attrs; @@ -2625,11 +2617,12 @@ writeChars(htmlString, chan, ">\n", 2); } child = doc->rootNode->firstChild; while (child) { tcldom_treeAsHTML(htmlString, child, chan, escapeNonASCII, - htmlEntities, doctypeDeclaration, 0); + htmlEntities, doctypeDeclaration, 0, 0, + breakLines); child = child->nextSibling; } return; } @@ -2679,14 +2672,10 @@ return; } tcldom_tolower(node->nodeName, tag, 80); - writeChars(htmlString, chan, "<", 1); - writeChars(htmlString, chan, tag, -1); - - /*----------------------------------------------------------- | check for HTML tags, that must be handled special: | empty tags and script tags (todo: HTML tags with | URI attributes, to do escaping of Non-ASCII chars | in the URI). @@ -2709,31 +2698,39 @@ case 'p': if (!strcmp(tag,"param")) {empty = 1;} break; case 's': if (!strcmp(tag,"script") || !strcmp(tag,"style")) {scriptTag = 1;} break; } - - attrs = node->firstAttr; - while (attrs) { - tcldom_tolower(attrs->nodeName, attrName, 80); - writeChars(htmlString, chan, " ", 1); - writeChars (htmlString, chan, attrName, -1); - writeChars(htmlString, chan, "=\"", 2); - tcldom_AppendEscaped(htmlString, chan, attrs->nodeValue, -1, - outputFlags | SERIALIZE_FOR_ATTR); - writeChars(htmlString, chan, "\"", 1); - attrs = attrs->nextSibling; - } - writeChars(htmlString, chan, ">", 1); - - + if (!onlyContents) { + writeChars(htmlString, chan, "<", 1); + writeChars(htmlString, chan, tag, -1); + + attrs = node->firstAttr; + while (attrs) { + tcldom_tolower(attrs->nodeName, attrName, 80); + writeChars(htmlString, chan, " ", 1); + writeChars (htmlString, chan, attrName, -1); + writeChars(htmlString, chan, "=\"", 2); + tcldom_AppendEscaped(htmlString, chan, attrs->nodeValue, -1, + outputFlags | SERIALIZE_FOR_ATTR); + writeChars(htmlString, chan, "\"", 1); + attrs = attrs->nextSibling; + } + if (breakLines) { + writeChars(htmlString, chan, "\n>", 2); + } else { + writeChars(htmlString, chan, ">", 1); + } + } + if (empty) { /* strange ! should not happen ! */ child = node->firstChild; while (child != NULL) { tcldom_treeAsHTML(htmlString, child, chan, escapeNonASCII, - htmlEntities, doctypeDeclaration, scriptTag); + htmlEntities, doctypeDeclaration, scriptTag, 0, + breakLines); child = child->nextSibling; } return; } @@ -2743,21 +2740,24 @@ && (child->nodeType != TEXT_NODE)) { writeChars(htmlString, chan, "\n", 1); } while (child != NULL) { tcldom_treeAsHTML(htmlString, child, chan, escapeNonASCII, - htmlEntities, doctypeDeclaration, scriptTag); + htmlEntities, doctypeDeclaration, scriptTag, 0, + breakLines); child = child->nextSibling; } if ((node->firstChild != NULL) && (node->firstChild != node->lastChild) && (node->lastChild->nodeType != TEXT_NODE)) { writeChars(htmlString, chan, "\n", 1); } } - writeChars(htmlString, chan, "", 1); + if (!onlyContents) { + writeChars(htmlString, chan, "", 1); + } } /*---------------------------------------------------------------------------- | tcldom_treeAsXML @@ -2887,12 +2887,18 @@ writeChars(xmlString, chan, "]]>", 3); return; } if ((indent != -1) && doIndent) { - for(i=0; inodeType == COMMENT_NODE) { writeChars(xmlString, chan, " @@ -6354,10 +6354,13 @@

features to make handling of the HTML style attribute more convenient.

+ +

features to make handling of the HTML style +attribute more convenient.

Index: tests/dom.test ================================================================== --- tests/dom.test +++ tests/dom.test @@ -178,10 +178,23 @@ lappend result $errMsg $doc delete unset doc set result } {1 {can't set "doc": var is read-only}} + +test dom-1.25 {Doc var} { + dom parse doc + dom parse doc + unset doc +} {} + +test dom-1.26 {Doc var} { + dom parse doc + set result [catch {$doc documentElement doc}] + unset doc + set result +} {1} test dom-2.1 {Don't quash white space at start or end of non white space content} { set doc [dom parse { some content }] @@ -1046,10 +1059,31 @@ test dom-3.41 {isPIValue} { dom isPIValue "some invalid processing instruction data?>" } {0} +test dom-3.43 {clearString} { + set result [list] + foreach str { + \u0001 + a\u0002 + \u0003b + a\u0004b + a\u0004\u0005b + a\u0004c\u0005b + a\u0004d\u0005\u0006b + a\u0004d\u0005\uD800\uD801\uD802_foo_bar + \uD800\uD801\uD802_foo_bar_baz\uD802_didum\uDFFF + \uD800\uD801\uD802_foo_bar_baz\uD802_didum\uE000 + \u0004\u0005\uDABC + abc + } { + lappend result [dom clearString $str] + } + set result +} [list {} a b ab ab acb adb ad_foo_bar _foo_bar_baz_didum _foo_bar_baz_didum\uE000 {} abc] + test dom-4.1 {-useForeignDTD 0} { set doc [dom parse -useForeignDTD 0 {}] $doc delete } {} Index: tests/domDoc.test ================================================================== --- tests/domDoc.test +++ tests/domDoc.test @@ -316,10 +316,62 @@ $root setAttribute attr "foo\"bar" set result [$doc asXML -indent none] $doc delete set result } {} + +test domDoc-1.32 {asXML -indent tabs} { + set doc [dom parse {}] + set result [$doc asXML -indent tabs] + $doc delete + set result +} "\n\t\n\t\t\n\t\n\n" + +test domDoc-1.33 {asXML -indent tabs} { + set doc [dom parse {}] + set result [$doc asXML -indent tabs] + $doc delete + set result +} "\n\t\n\t\t\n\t\n\t\n\t\t\n\t\t\t\n\t\t\n\t\n\t\n\n" + +test domDoc-1.34 {asXML -indent tabs -noEmptyElementTag} { + set doc [dom parse {}] + set result [$doc asXML -indent tabs -noEmptyElementTag] + $doc delete + set result +} "\n\t\n\t\t\n\t\n\t\n\t\t\n\t\t\t\n\t\t\n\t\n\t\n\n" + +test domDoc-1.35 {asXML -indent tabs -indentAttrs tabs} { + set doc [dom parse {}] + set result [$doc asXML -indent tabs -indentAttrs tabs] + $doc delete + set result +} "\n\t\n\t\t\n\t\n\t\n\t\t\n\t\t\t\n\t\t\n\t\n\t\n\n" + +test domDoc-1.36 {asXML -indent tabs -indentAttrs } { + set doc [dom parse {}] + set result [$doc asXML -indent tabs -indentAttrs 2] + $doc delete + set result +} "\n\t\n\t\t\n\t\n\t\n\t\t\n\t\t\t\n\t\t\n\t\n\t\n\n" + +test domDoc-1.37 {asHTML -onlyContents} { + set doc [dom parse {

boo

}] + set result [[$doc documentElement] asHTML -onlyContents] + $doc delete + set result +} {

boo

} + +test domDoc-1.38 {asHTML -breakLines} { + set doc [dom parse {

boo

}] + set result [$doc asHTML -breakLines] + $doc delete + set result +} {

boo

} set doc [dom parse ] test domDoc-2.1 {publicId - no publicId there} { $doc publicId @@ -1393,11 +1445,11 @@ set doc [dom createDocument foo] set result [catch {$doc selectNodesNamespaces wrong} errMsg] lappend result $errMsg $doc delete set result -} {1 {The optional argument to the selectNodesNamespaces method must be a 'prefix namespace' pairs list}} +} {1 {The optional argument to selectNodesNamespaces must be a 'prefix namespace' pairs list}} test domDoc-25.5 {selectNodesNamespaces} { set doc [dom parse { Index: tests/domNode.test ================================================================== --- tests/domNode.test +++ tests/domNode.test @@ -1226,10 +1226,23 @@ lappend result [$removedNode previousSibling] $doc delete set result } {y {}} +test domNode-12.11 {cloneNode -deep w/ disableOutputEscaping} { + dom parse "" doc + $doc createTextNode "a b" textnode + $textnode disableOutputEscaping 1 + $doc documentElement root + $root firstChild td + $td appendChild $textnode + $root appendChild [$td cloneNode -deep] + set result [$doc asXML -indent none] + $doc delete + set result +} {a ba b} + namespace eval nodeCmds { dom createNodeCmd elementNode e1 dom createNodeCmd elementNode e2 dom createNodeCmd commentNode c dom createNodeCmd textNode t @@ -2384,10 +2397,46 @@ set root [$doc documentElement] set result [$root getAttributeNS "ns1" attr1] $doc delete set result } {p:attr1Value} + +test domNode-28.2 {getAttributeNS - default value} { + set doc [dom parse { +}] + set root [$doc documentElement] + set result [$root getAttributeNS "not" attr1 "default"] + $doc delete + set result +} {default} + +test domNode-28.3 {getAttributeNS - default value} { + set doc [dom parse { +}] + set root [$doc documentElement] + set result [$root getAttributeNS "not" notexisting "some default"] + $doc delete + set result +} {some default} + +test domNode-28.4 {getAttributeNS - default value} { + set doc [dom parse { +}] + set root [$doc documentElement] + set result [$root getAttributeNS "ns1" notexisting "some other default"] + $doc delete + set result +} {some other default} proc domAppendChild {parent name} { $parent ownerDocument doc $doc createElement $name node $parent appendChild $node Index: tests/domjson.test ================================================================== --- tests/domjson.test +++ tests/domjson.test @@ -388,10 +388,46 @@ set doc [dom parse -json "\"a\\u0000\\u0001\\u0002\\u0003\\u0004\\u0005\\u0006\\u0007\\u0008\\u0009\\u000A\\u000B\\u000C\\u000D\\u000E\\u000F\\u0010\\u0011\\u0012\\u0013\\u0014\\u0015\\u0016\\u0017\\u0018\\u0019\\u001A\\u001B\\u001C\\u001D\\u001E\\u001F\\u0020b\""] set result [$doc asJSON] $doc delete set result } {"a\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007\b\t\n\u000b\f\r\u000e\u000f\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019\u001a\u001b\u001c\u001d\u001e\u001f b"} + +test json-6.6 {asJSON -indent} { + set doc [dom parse -json {{"a":{"aa":[1,2,3,4,"abc"]},"b":"bvalue"}}] + set result [$doc asJSON -indent 2] + $doc delete + set result +} {{ + "a": { + "aa": [ + 1, + 2, + 3, + 4, + "abc" + ] + }, + "b": "bvalue" +}} + +test json-6.7 {asJSON -indent} { + set doc [dom parse -json {{"a":{"aa":[1,2,3,4,"abc"]},"b":"bvalue"}}] + set result [$doc asJSON -indent tabs] + $doc delete + set result +} {{ + "a": { + "aa": [ + 1, + 2, + 3, + 4, + "abc" + ] + }, + "b": "bvalue" +}} test json-7.1 {jsonType} { set doc [dom parse {foo}] set root [$doc documentElement] set result [list] Index: tests/entity.test ================================================================== --- tests/entity.test +++ tests/entity.test @@ -126,10 +126,15 @@ ]> } $parser free set ::extrefhandlerCalled } {1} + +test entity-3.4 {cget -useForeignDTD} { + set parser [expat entity-4.4 -useForeignDTD 1] + $parser cget -useForeignDTD +} 1 proc extrefhandler-4 {args} { global notexistendpath # Search for a not existing file path set base /ae124 Index: tests/loadtdom.tcl ================================================================== --- tests/loadtdom.tcl +++ tests/loadtdom.tcl @@ -12,10 +12,12 @@ } else { package require Tcl 8.4- } package require tcltest 2.2 namespace import ::tcltest::* +catch {tcltest::loadTestedCommands} + if {[catch {package require -exact tdom 0.9.2}]} { if {[catch {load [file join [file dir [info script]] ../unix/libtdom0.9.2.so]}]} { error "Unable to load the appropriate tDOM version!" } } Index: tests/namespace.test ================================================================== --- tests/namespace.test +++ tests/namespace.test @@ -103,10 +103,26 @@ xmlns:x='urn:schema'> } list $::result [eval keysort $::nsdecls] } {{{} http://www.zveno.com/Schemas x urn:schema urn:schema:Test http://www.zveno.com/Schemas:Test} {}} +test ns-1.5 {Place of -namespace option in arg list} { + set ::result {} + set ::nsdecls {} + + catch {rename xml::ns-1.5 {}} + set parser [xml::parser ns-1.4 \ + -startnamespacedeclcommand NSDeclStart \ + -namespace \ + -elementstartcommand EStart] + $parser parse { + +} + list $::result [eval keysort $::nsdecls] +} {{{} http://tdom.org/Schemas x urn:schema urn:schema:Test http://tdom.org/Schemas:Test} {}} + test ns-2.0 {Multiple namespace declarations, same prefix} { set ::result {} set ::nsdecls {} catch {rename xml::ns-2.0 {}} @@ -124,13 +140,83 @@ } list $::result [eval keysort $::nsdecls] } {{Test x http://www.zveno.com/Schemas http://www.zveno.com/Schemas:Test http://www.zveno.com/Schemas:y x urn:schema urn:schema:Test urn:schema:z} {}} + +test ns-3.1 {-namespaceseparator} { + set result "" + + catch {rename xml::ns-3.1 {}} + set parser [xml::parser ns-3.1 \ + -namespace \ + -namespaceseparator = \ + -elementstartcommand EStart] + $parser parse { + + + + + + + + +} + set result +} {Test http://tdom.org/Schemas=Test http://tdom.org/Schemas=y urn:schema=Test urn:schema=z} + +test ns-3.2 {-namespaceseparator} { + set result "" + + catch {rename xml::ns-3.2 {}} + set parser [xml::parser ns-3.2 \ + -namespace \ + -namespaceseparator "" \ + -elementstartcommand EStart] + $parser parse { + + + + + + + + +} + set result +} "Test http://tdom.org/SchemasTest http://tdom.org/Schemasy urn:schemaTest urn:schemaz" + +test ns-3.3 {-namespaceseparator} { + set result "" + + catch {rename xml::ns-3.3 {}} + set parser [xml::parser ns-3.3 \ + -namespace \ + -namespaceseparator \x00 \ + -elementstartcommand EStart] + $parser parse { + + + + + + + + +} + set result +} "Test http://tdom.org/SchemasTest http://tdom.org/Schemasy urn:schemaTest urn:schemaz" + +test ns-3.4 {-namespaceseparator} { + catch {rename xml::ns-3.4 {}} + set parser [xml::parser ns-3.4 \ + -namespaceseparator =] + $parser cget -namespaceseparator +} = foreach parser [info commands ns-*] { $parser free } # cleanup ::tcltest::cleanupTests return Index: tests/parser.test ================================================================== --- tests/parser.test +++ tests/parser.test @@ -206,10 +206,116 @@ test parser-1.17 {parser delete} { expat parser-1.17 parser-1.17 delete } {} + +proc cdh-1.18 {data} { + if {[string trim $data] ne ""} { + append ::result "cdh:$data" + } +} +proc dh-1.18 {data} { + if {[string trim $data] ne ""} { + append ::result "dh:$data" + } +} + +test parser-1.18 {parser option -noexpand} { + catch {rename parser-1.18 {}} + set parser [expat parser-1.18] + $parser configure \ + -noexpand 1 \ + -defaultcommand dh-1.18 \ + -characterdatacommand cdh-1.18 + set result "" + $parser parse { + + ]> + foo&xxx;bar} + set result +} {cdh:foodh:&xxx;cdh:bar} + +test parser-1.19 {parser option -noexpand} { + catch {rename parser-1.19 {}} + set parser [expat parser-1.19] + $parser configure \ + -noexpand 0 \ + -defaultcommand dh-1.18 \ + -characterdatacommand cdh-1.18 + set result "" + $parser parse { + + ]> + foo&xxx;bar} + set result +} {cdh:foothis was the xxx entitybar} + +test parser-1.20 {parser option -noexpand} { + catch {rename parser-1.20 {}} + set parser [expat parser-1.20] + $parser configure \ + -noexpand 1 \ + -characterdatacommand cdh-1.18 + set result "" + $parser parse { + + ]> + foo&xxx;bar} + set result +} {cdh:foocdh:bar} + +test parser-1.21 {parser option -noexpand} { + catch {rename parser-1.21 {}} + set parser [expat parser-1.21] + $parser configure \ + -noexpand 1 \ + -defaultcommand dh-1.18 + set result "" + $parser parse { + + ]> + foo&xxx;bar} + set result +} {dh:&xxx;} + +test parser-1.22 {parser option -noexpand} { + catch {rename parser-1.22 {}} + set parser [expat parser-1.18] + $parser configure \ + -noexpand 1 \ + -defaultcommand dh-1.18 + set result "" + $parser parse { + + ]> + foo&xxx;bar} + set result +} {dh:&xxx;} + +test parser-1.23 {Unknown option flag} { + catch {rename xml::parser-1.23 {}} + catch { + set parser [xml::parser parser-1.23 \ + -elementstartcommand EStart \ + -boo] + } +} 1 + +test parser-1.24 {Missing option argument} { + catch {rename xml::parser-1.24 {}} + catch { + set parser [xml::parser parser-1.23 \ + -elementstartcommand] + + } +} 1 # Test break return code from callback test parser-2.1 {break in callback} { catch {unset ::started} @@ -624,11 +730,11 @@ } test parser-12.1 {currentmarkup method} { catch {unset result} set result "" - set p [expat parser-12.1 -noexpand] + set p [expat parser-12.1] $p configure \ -elementstartcommand [list elementstart-12.1 $p] \ -elementendcommand [list elementend-12.1 $p] $p parse {textfoo + + foo + + } { + lappend result [s validate $xml ] + } + s delete + set result +} {1 0 0 1} + +test schema-1.14 {define start w/ namespace} { + tdom::schema create s + s start doc http://foo.bar + s defelement doc http://foo.bar { + element a + element b + } + foreach elm {a b} { + s defelement $elm http://foo.bar {} + } + set result [list] + foreach xml { + {} + {} + {} + {
} + } { + lappend result [s validate $xml] + } + s delete + set result +} {1 1 1 0} + +test schema-1.14a {define start w/ namespace} { + tdom::schema create s + s prefixns {ns1 http://foo.bar} + s start doc ns1 + s defelement doc ns1 { + element a + element b + } + foreach elm {a b} { + s defelement $elm ns1 {} + } + set result [list] + foreach xml { + {} + {} + {} + {} + } { + lappend result [s validate $xml] + } + s delete + set result +} {1 1 1 0} + +test schema-1.15 {call structure constraint outside define/defelement} { + set result [catch {tdom::schema::element foo} errMsg] + lappend result $errMsg + tdom::schema create grammar + lappend result [catch {tdom::schema::element foo} errMsg] + lappend result $errMsg + lappend result [catch {grammar define {::tdom::schema::element foo}} errMsg] + lappend result $errMsg + lappend result [catch {grammar defelement bar {::tdom::schema::element foo}} errMsg] + lappend result $errMsg + grammar delete + set result +} {1 {Command called outside of schema context} 1 {Command called outside of schema context} 1 {Command not allowed at top level in schema define evaluation} 0 {}} + +test schema-1.16 {call another schema cmd in a schema definition script} { + tdom::schema create s1 + s1 define { + defelement s1a { + element s1b * + element s1c + } + ::tdom::schema ::s2 + s2 define { + defelement s1a { + element s1b * + element s1c + } + } + defelement s1b { + element s1b1 + } + } + set result [list] + foreach xml { + + + + + } { + lappend result [s1 validate $xml] + lappend result [s2 validate $xml] + } + s1 delete + s2 delete + set result +} {0 0 0 1 1 1 1 0} + +test schema-1.17 {call schema cmd evaluation in his own schema definition script} { + tdom::schema create s1 + set result [catch {s1 define { + defelement s1a { + s1 defelement s1b { + element s1b1 + } + element s1b * + element s1c + } + }} errMsg] + s1 delete + set result +} 1 + +test schema-1.18 {delete schema cmd in definition script} { + tdom::schema create s + s define { + defelement e { + s delete + element e1 1 { + set ::result [catch {s delete}] + } + } + } + lappend result [info commands s] +} {1 {}} + +test schema-1.19 {call top level schema cmd in definition script} { + tdom::schema create s + set result [catch {s define { + defelement e { + element e1 1 { + deftexttype foo {minLength 1} + defelement bar {} + } + element bar + } + }}] + lappend result [info commands s] + s delete + set result +} {1 s} + +test schema-1.20 {call top level schema cmd in definition script} { + tdom::schema create s + set result [catch {s defelement e { + element e1 1 { + deftexttype foo {minLength 1} + defelement bar {} + } + element bar + } + }] + lappend result [info commands s] + s delete + set result +} {1 s} + +test schema-1.21 {Create other schema cmd in definition script} { + tdom::schema create s1 + s1 defelement e { + element e1 1 {} + element e1 1 { + ::tdom::schema create ::s2 + ::s2 define { + defelement s2 { + element s2e + element s2ee + } + foreach e {s2e s2ee} { + defelement $e {text} + } + } + } + } + set result [info commands s1] + lappend result [info commands s2] + foreach xml { + + foo + } { + lappend result [s1 validate $xml] + lappend result [s2 validate $xml] + } + s2 delete + s1 delete + set result +} {s1 s2 1 0 0 1} + +test schema-1.22 {nrForwardDefinitions} { + tdom::schema create s + set result [list] + s define { + defelement e { + lappend ::result [s info nrForwardDefinitions] + element e1 + lappend ::result [s info nrForwardDefinitions] + element e1 + lappend ::result [s info nrForwardDefinitions] + element e2 + lappend ::result [s info nrForwardDefinitions] + } + foreach e {e1 e2} { + defelement $e {text} + lappend ::result [s info nrForwardDefinitions] + } + } + s delete + set result +} {0 1 1 2 1 0} + +test schema-1.23 {prefixns} { + tdom::schema create s + set result [list] + lappend result [s prefixns] + lappend result [s prefixns {a b}] + lappend result [s prefixns] + lappend result [s prefixns {a b a b c d}] + lappend result [s prefixns {}] + lappend result [s prefixns ""] + lappend result [catch {s prefixns a b c} errMsg] + lappend result $errMsg + lappend result [catch {s prefixns {a b c}} errMsg] + lappend result $errMsg + lappend result [catch {s prefixns "a \{"} errMsg] + lappend result $errMsg + s delete + set result +} {{} {a b} {a b} {a b a b c d} {} {} 1 {wrong # args: should be "s prefixns ?prefixUriList?"} 1 {The optional argument to prefixns must be a 'prefix namespace' pairs list} 1 {The optional argument to prefixns must be a 'prefix namespace' pairs list}} + +test schema-1.24 {prefixns} { + tdom::schema create s + set result [list] + lappend result [s define prefixns] + lappend result [s define {prefixns {a b}}] + lappend result [s define {prefixns}] + lappend result [s define {prefixns {a b a b c d}}] + lappend result [s define {prefixns {}}] + lappend result [s define {prefixns ""}] + lappend result [catch {s define {prefixns a b c}} errMsg] + lappend result $errMsg + lappend result [catch {s define {prefixns {a b c}}} errMsg] + lappend result $errMsg + lappend result [catch {s define {prefixns "a \{"}} errMsg] + lappend result $errMsg + s delete + set result +} {{} {a b} {a b} {a b a b c d} {} {} 1 {wrong # args: should be "prefixns ?prefixUriList?"} 1 {The optional argument to prefixns must be a 'prefix namespace' pairs list} 1 {The optional argument to prefixns must be a 'prefix namespace' pairs list}} + +test schema-1.25 {prefixns} { + set result [list] + set schema { + defelement doc ns1 { + element e + } + } + set xml {} + # 1 + tdom::schema create s + s define $schema + lappend result [s validate $xml] + s delete + # 2 + tdom::schema create s + s prefixns {ns1 http://tdom.org/test} + s define $schema + lappend result [s validate $xml] + s delete + # 3 + tdom::schema create s + s prefixns {ns1 http://foo.bar} + s define $schema + lappend result [s validate $xml] + s delete + # 4 + tdom::schema create s + s prefixns {ns1 http://tdom.org/test ns1 http://foo.bar} + s define $schema + lappend result [s validate $xml] + s delete + # 5 + tdom::schema create s + s prefixns {ns1 http://foo.bar ns1 http://tdom.org/test} + s define $schema + lappend result [s validate $xml] + s delete + # 6 + tdom::schema create s + s prefixns {ns1 http://foo.bar} + s prefixns {ns1 http://tdom.org/test ns1 http://foo.bar} + s define $schema + lappend result [s validate $xml] + s delete + # 7 + tdom::schema create s + s define { + prefixns {ns1 http://tdom.org/test} + defelement doc ns1 { + element e + } + prefixns {ns2 http://foo.bar} + defelement e ns2 {text {minLength 1}} + } + lappend result [s validate $xml] + s delete + # 8 + tdom::schema create s + s define { + prefixns {ns1 http://tdom.org/test} + defelement doc ns1 { + namespace http://foo.bar { + element e + } + } + prefixns {ns2 http://foo.bar} + defelement e ns2 {text {minLength 1}} + } + lappend result [s validate $xml] + # 9 + lappend result [s validate {}] + # 10 + lappend result [s validate {foo}] + s delete + # 11 + tdom::schema create s + s define { + prefixns {ns1 http://tdom.org/test ns2 http://foo.bar} + defelement doc ns1 { + namespace ns2 { + element e + } + } + prefixns {ns2 http://foo.bar} + defelement e ns2 {text {minLength 1}} + } + lappend result [s validate $xml] + # 12 + lappend result [s validate {}] + # 13 + lappend result [s validate {foo}] + s delete + set result +} {0 1 0 1 0 1 1 0 0 1 0 0 1} + +test schema-1.26 {prefixns} { + tdom::schema create s + set result [list] + lappend result [catch { + s defelement doc { + prefixns {a http://foo.bar} + namespace a { + element e + } + } + } errMsg] + lappend result $errMsg + lappend result [catch { + s defelement doc { + namespace a { + element e + } + prefixns {a http://foo.bar} + } + } errMsg] + lappend result $errMsg + lappend result [catch { + s define { + defelement doc { + prefixns {a http://foo.bar} + namespace a { + element e + } + } + } + } errMsg] + lappend result $errMsg + lappend result [catch { + s define { + defelement doc { + s prefixns {a http://foo.bar} + namespace a { + element e + } + } + } + } errMsg] + lappend result $errMsg + s delete + set result +} {1 {Command only allowed at lop level} 1 {Command only allowed at lop level} 1 {Command not allowed in nested schema define script} 1 {This recursive call is not allowed}} + +test schema-1.27 {prefixns} { + tdom::schema create s + s define { + prefixns {a http:://some.uri} + defelement doc a {} + } + set result [s validate {} errMsg] + lappend result $errMsg + s delete + set result +} {0 {error "Unknown element" at line 1 character 20}} + +test schema-1.28 {defelement} { + tdom::schema s + set result [catch { + s defelement e { + defelement a { + element b + } + } + }] + s delete + set result +} 1 + +test schema-1.29 {defelement} { + tdom::schema s + catch { + s defelement e { + element a + element b + error "some" + } + } + s defelement e { + element a + element b + } + set result [list] + foreach xml { + +
+ + + } { + lappend result [s validate $xml] + } + s delete + set result +} {0 0 1 0} + +test schema-1.30 {recurive allowed element} { + tdom::schema s + s define { + defelement doc { + element n + } + defelement n { + element n ? + } + } + set xml "" + # That's 200000 (and one) nesting level + append xml [string repeat "" 20000] + append xml "" + append xml [string repeat "" 20000] + append xml "" + set result [s validate $xml] + s delete + set result +} 1 + +test schema-1.31 {recurive allowed element} { + tdom::schema s + s define { + defelement doc { + element n + } + defelement n { + element n ? + } + } + set xml "" + # That's 200000 (and one) nesting level + append xml [string repeat "" 20000] + append xml "" + append xml [string repeat "" 20000] + append xml "" + set result [s validate $xml errMsg] + s delete + list $result $errMsg +} {0 {error "Element "a" doesn't match" at line 1 character 600009}} + +test schema-1.32 {Unknown root element} { + tdom::schema s + s define { + defelement e { + element doc ? { + element e + } + } + } + set result [s validate ] + s delete + set result +} 0 + +test schema-1.33 {Error after local defined element} { + tdom::schema s + set result [catch { + s define { + defelement a { + element b ! { + element c ! {} + error "triggered" + } + element a ! { + element c ! {} + } + error + } + } + }] + s delete + set result +} 1 + +test schema-1.34 {defelement nested in defelement nested in define} { + tdom::schema s + set result [catch { + s define { + defelement a { + defelement b { + element c ! {} + } + } + } + } errMsg] + s delete + lappend result $errMsg +} {1 {Command not allowed in nested schema define script}} + +test schema-1.35 {deftexttype nested in deftexttype nested in define} { + tdom::schema s + set result [catch { + s define { + deftexttype foo { + minLength 2 + ::tdom::schema::deftexttype bar { + maxLength 2 + } + } + } + } errMsg] + s define { + deftexttype foo { + minLength 2 + } + deftexttype bar { + maxLength 2 + } + } + s delete + lappend result $errMsg +} {1 {Command called in invalid schema context}} + +test schema-2.1 {grammar definition: ref} { + tdom::schema create grammar + grammar defpattern thisPattern { + element a + element b + } + grammar defpattern thatPattern { + element c + element d + } + grammar defelement doc { + ref thisPattern + ref thatPattern ? + } + grammar delete +} {} + +test schema-2.2 {grammar definition: ref} { + tdom::schema create grammar + set result [grammar info nrForwardDefinitions] + grammar defelement doc { + ref thisPattern + ref thatPattern ? + } + lappend result [grammar info nrForwardDefinitions] + grammar delete + set result +} {0 2} + +test schema-2.3 {forward defined ref} { + set defs { + { + ref thisPattern ? + } + { + ref thatPattern + } + { + ref thisPattern ? + ref thatPattern + } + { + ref thisPattern ? + element a + } + { + ref thatPattern + element a + } + } + set xmlinput { + + + + } + set result [list] + foreach def $defs { + tdom::schema create s + s defelement doc $def + foreach xml $xmlinput { + lappend result [s validate $xml errMsg] + } + s delete + } + set result +} {1 0 0 1 0 0 1 0 0 0 1 0 0 1 0} + +test schema-2.3a {forward defined ref} { + tdom::schema s + s defelement doc { + ref some + element a + } + set result [s validate ] + lappend result [s info nrForwardDefinitions] + s delete + set result +} {1 2} + +test schema-2.4 {forward definded element} { + set defs { + { + element thisElement ? + } + { + element thatElement + } + { + element thisElement ? + element thatElement + } + { + element thisElement ? + element a + } + { + element thatElement + element a + } + } + set xmlinput { + + + + } + set result [list] + foreach def $defs { + tdom::schema create s + s defelement doc $def + foreach xml $xmlinput { + lappend result [s validate $xml errMsg] + } + s delete + } + set result +} {1 0 0 0 0 0 0 0 0 0 1 0 0 0 0} + +test schema-3.1 {grammar definition: choice} { + tdom::schema create grammar + grammar defelement doc { + element elm + choice { + element fooElem + element barElem + + } + choice ? { + element one {2 3} + element two + } + element three + } + grammar delete +} {} + +test schema-3.2 {grammar definition: choice} { + tdom::schema create grammar + grammar defpattern thisPattern { + element elm + choice { + element fooElem + element barElem + + } + choice ? { + element one {2 3} + element two + } + element three + } + grammar delete +} {} + +proc pullValidate {g xml} { + tdom::pullparser pp + pp input $xml + while {[pp next] ne "END_DOCUMENT"} { + switch [pp state] { + "START_TAG" { + $g event start [pp tag] + } + "END_TAG" { + $g event end + } + "TEXT" { + $g event text [pp text] + } + } + } +} + +test schema-4.1 {validation} { + tdom::schema create grammar + grammar defelement doc { + element e1 + element e2 * + } + foreach e {e1 e2} { + grammar defelement $e {} + } + pullValidate grammar { + + } + if {[grammar info vstate] ne "FINISHED"} { + error "Wrong state." + } + grammar reset + pullValidate grammar { + + } + if {[grammar info validationstate] ne "FINISHED"} { + error "Wrong state." + } + grammar reset + pullValidate grammar { + + } + if {[grammar info vstate] ne "FINISHED"} { + error "Wrong state." + } + grammar delete +} {} + +test schema-4.1a {validation} { + tdom::schema create s + s defelement doc { + element e1 + element e2 * + } + foreach e {e1 e2} { + s defelement $e {} + } + set result [list] + foreach xml { + + + + } { + lappend result [s validate $xml] + } + s delete + set result +} {1 1 1} + +test schema-4.2 {validation} { + tdom::schema create s + s defelement doc { + element e1 * + } + s defelement e1 { + element ee1 + element ee2 + } + foreach e {ee1 ee2} { + s defelement $e {} + } + set result [list] + foreach xml { + + + + + + } { + lappend result [s validate $xml] + } + s delete + set result +} {1 0 1 1 0} + +test schema-4.3 {validation} { + tdom::schema s + s define { + defelement addressBook { + element card * + } + defelement card { + element name + element email + } + foreach e {name email} { + defelement $e {text} + } + } + set result [s validate { + + + John Smith + js@example.com + + + Fred Bloggs + fb@example.net + + + }] + s delete + set result +} 1 + +proc schema-4.4 {scmd} { + global result + catch {$scmd event start foo} errMsg + lappend result $errMsg +} + +test schema-4.4 {event on itself in called script} { + tdom::schema s + s defelement doc { + element a ? + tcl schema-4.4 [self] + element b ? + } + set result [list] + foreach xml { + + + + } { + lappend result [s validate $xml] + } + s delete + set result +} {{This method is not allowed in nested evaluation} 1 {This method is not allowed in nested evaluation} 1 {This method is not allowed in nested evaluation} 1} + +proc schema-4.5 {scmd} { + global result + $scmd event start foo +} + +test schema-4.5 {event on itself in called script} { + tdom::schema s + s defelement doc { + element a ? + tcl schema-4.5 [self] + element b ? + } + set result [list] + foreach xml { + + + + } { + lappend result [catch {s validate $xml errMsg} errMsg] + lappend result $errMsg + } + s delete + set result +} {1 {error "This method is not allowed in nested evaluation" at line 1 character 6} 1 {error "This method is not allowed in nested evaluation" at line 1 character 15} 1 {error "This method is not allowed in nested evaluation" at line 1 character 13}} + +test schema-4.6 {event start with namespace} { + tdom::schema s + s defelement doc http://tdom.org/test { + element a ! text + } + s event start doc http://tdom.org/test + s event start a http://tdom.org/test + s event text "some text" + s event end + s event end + s delete +} {} + +test schema-4.7 {event start with namespace} { + tdom::schema s + s defelement doc http://tdom.org/test { + element a 1 { + attribute att1 + } + } + s event start doc http://tdom.org/test + set result [catch {s event start a http://tdom.org/test} errMsg] + lappend result $errMsg + s delete + set result +} {1 {Missing mandatory attribute(s)}} + +test schema-4.8 {event start with namespace} { + tdom::schema s + s defelement doc http://tdom.org/test { + element a 1 { + attribute att1 + } + } + s event start doc http://tdom.org/test + s event start a {att1 "some data"} http://tdom.org/test + s event end + s event end + s delete +} {} + +test schema-4.9 {event start with namespace w/ namespaced attribute} { + tdom::schema s + s defelement doc http://tdom.org/test { + element a 1 { + nsattribute att1 http://tdom.org/test + } + } + s event start doc http://tdom.org/test + s event start a {{att1 http://tdom.org/test} "some data"} http://tdom.org/test + s event end + s event end +} {} + +proc schema-4.10 {scmd} { + error "Error raised in schema-4.10" +} +test schema-4.10 {event - tcl error in called script} { + tdom::schema s + s defelement doc { + tcl schema-4.10 [self] + element a + } + s event start doc + set result [catch {s event start a} errMsg] + lappend result $errMsg + s delete + set result +} {1 {Error raised in schema-4.10}} + +test schema-4.11 {event - invalid root} { + tdom::schema s + s defelement doc {} + s reportcmd dummycallback + s event start doo + s delete +} {} + +test schema-4.12 {event - text without root} { + tdom::schema s + s defelement doc {} + s reportcmd dummycallback + set result [catch {s event text foo} errMsg] + lappend result $errMsg + s delete + set result +} {1 {No validation started}} + +test schema-5.1 {dom parse -validateCmd} { + set result [catch { + [dom parse -validateCmd tdom::schema ] + }] +} 1 + +test schema-5.2 {dom parse -validateCmd} { + tdom::schema create grammar + grammar defelement doc { + element e1 + element e2 * + } + foreach e {e1 e2} { + grammar defelement $e {} + } + dom parse -validateCmd grammar { + + } doc + $doc delete + dom parse -validateCmd grammar { + + } doc + $doc delete + dom parse -validateCmd grammar { + + } doc + $doc delete +} {} + +proc schema-5.3 {base systemId publicId} { + return [list "string" "" ""] +} + +test schema-5.3 {dom parse -validateCmd} { + tdom::schema create grammar + grammar defelement doc { + element e1 + element e2 * + } + foreach e {e1 e2} { + grammar defelement $e {} + } + set result [catch {dom parse -validateCmd grammar \ + -externalentitycommand schema-5.3 { + + ]> + &e1;} doc} errMsg] + grammar delete + set result +} 1 + +test schema-5.4 {define} { + tdom::schema create grammar + grammar define { + defelement elm1 { + element a + element b + } + defelement a { + element c + } + defelement b {} + defelement c {} + } + set doc [dom parse -validateCmd grammar { + + }] + $doc delete + grammar delete +} {} + +test schema-5.5 {validate tmml doc files} { + tdom::schema s + set docdir [file join [file dir [info script]] ../doc] + set file [file join $docdir tmml.schema] + set fd [open $file] + set tmmlschema [read $fd] + close $fd + s define $tmmlschema + set result {} + foreach tmmlfile { + domDoc.xml + domNode.xml + dom.xml + expatapi.xml + expat.xml + pullparser.xml + schema.xml + tdomcmd.xml + } { + set file [file join $docdir $tmmlfile] + set fd [open $file] + set tmmldoc [read $fd] + close $fd + lappend result [s validate $tmmldoc] + } + s delete + set result +} {1 1 1 1 1 1 1 1} + +test schema-6.1 {expat parser with -validateCmd} { + tdom::schema create grammar + grammar defelement doc { + element e1 + element e2 * + } + foreach e {e1 e2} { + grammar defelement $e {} + } + ::xml::parser p -validateCmd grammar + set result [catch {p parse {}} errMsg] + p delete + grammar delete + set result +} 1 + +test schema-6.2 {expat parser with -validateCmd} { + tdom::schema create grammar + grammar defelement doc { + element e1 + element e2 * + } + foreach e {e1 e2} { + grammar defelement $e {} + } + ::xml::parser p -validateCmd grammar -final 0 + set result [list] + p parse {} errMsg] + lappend result $errMsg + lappend result [grammar info vstate] + p parse {1/>} + p configure -final 1 + p reset + lappend result [grammar validate ] + grammar delete + p delete + set result +} {1 {The schema command is busy} VALIDATING 1} + +test schema-6.3 {expat parser with -validateCmd} { + tdom::schema create grammar + grammar defelement doc { + element e1 + element e2 * + } + foreach e {e1 e2} { + grammar defelement $e {} + } + ::xml::parser p -validateCmd grammar -final 0 + set result [list] + p parse {} errMsg] + lappend result $errMsg + lappend result [grammar info vstate] + p parse {c>} + p configure -final 1 + p reset + lappend result [grammar validate ] + grammar delete + p delete + set result +} {0 1 READY 1} + +test schema-6.4 {expat parser with -validateCmd} { + tdom::schema create grammar + grammar defelement doc { + element e1 + element e2 * + } + foreach e {e1 e2} { + grammar defelement $e {} + } + ::xml::parser p -validateCmd grammar -final 0 + set result [list] + p parse {} errMsg] + lappend result $errMsg + lappend result [grammar info vstate] + p parse {c} + p parse {>} + p configure -final 1 + p reset + lappend result [grammar validate ] + grammar delete + p delete + set result +} {0 1 READY 1} + +proc elementstart-6.5 {name attList} { + lappend ::result $name +} + +test schema-6.5 {expat parser with -validateCmd} { + tdom::schema create grammar + grammar defelement doc { + element e1 + element e2 * + } + foreach e {e1 e2} { + grammar defelement $e {} + } + ::xml::parser p -validateCmd grammar -final 0\ + -elementstartcommand elementstart-6.5 + set result [list] + p parse {} + p configure -final 1 + p reset + lappend result [grammar validate ] + grammar delete + p delete + set result +} {doc e1 1} + +proc elementstart-6.6 {name attList} { + lappend ::result $name + if {$name eq "doc"} { + grammar delete + } +} + +test schema-6.6 {expat parser with -validateCmd} { + tdom::schema create grammar + grammar defelement doc { + element e1 + element e2 * + } + foreach e {e1 e2} { + grammar defelement $e {} + } + ::xml::parser p -validateCmd grammar -final 0\ + -elementstartcommand elementstart-6.6 + set result [list] + p parse {} + p configure -final 1 + p reset + lappend result [info command grammar] + p delete + set result +} {doc e1 {}} + +test schema-7.1 {group} { + tdom::schema create grammar + grammar defelement doc { + element e1 + group ! { + element e1 + element e2 + } + element e2 * + } + foreach e {e1 e2} { + grammar defelement $e {} + } + dom parse -validateCmd grammar { + + } doc + $doc delete + grammar delete +} {} + +test schema-7.1.1 {group} { + tdom::schema create grammar + grammar define { + defelement doc { + element e1 + group ! { + element e1 + element e2 + } + group ! { + element e1 + element e2 + } + element e2 * + } + foreach e {e1 e2} { + defelement $e {} + } + } + dom parse -validateCmd grammar { + + } doc + $doc delete + grammar delete +} {} + +test schema-7.2 {group} { + tdom::schema create grammar + grammar defelement doc { + element e1 + group 2 { + element e1 + element e2 + } + element e2 * + } + foreach e {e1 e2} { + grammar defelement $e {} + } + dom parse -validateCmd grammar { + + } doc + $doc delete + grammar delete +} {} + +test schema-7.2.1 {group} { + tdom::schema create grammar + grammar define { + defelement doc { + element e1 + group 2 { + element e1 + element e2 + } + element e2 * + } + foreach e {e1 e2} { + defelement $e {} + } + } + dom parse -validateCmd grammar { + + } doc + $doc delete + grammar delete +} {} + +test schema-7.3 {group with inline defined element} { + tdom::schema create grammar + grammar define { + defelement doc { + element e1 + group 2 { + element e1 1 { + element e2 + } + element e2 + } + element e2 * + } + foreach e {e1 e2} { + defelement $e {} + } + } + dom parse -validateCmd grammar { + + } doc + $doc delete + grammar delete +} {} + +test schema-7.4 {group with inline defined element} { + tdom::schema create grammar + grammar define { + defelement doc { + group { + element e1 + element e1 1 { + element e2 + } + element e2 + } + } + foreach e {e1 e2} { + defelement $e {} + } + } + dom parse -validateCmd grammar { + + } doc + $doc delete + grammar delete +} {} + +test schema-7.5 {group with inline defined element} { + tdom::schema create grammar + grammar define { + defelement doc { + group { + element e1 + element e1 1 { + element e2 + } + element e2 + } + } + foreach e {e1 e2} { + defelement $e {} + } + } + ::xml::parser p -validateCmd grammar + p parse { + + } + p delete + grammar delete +} {} + +test schema-7.6 {nested groups via refs} { + tdom::schema create grammar + grammar define { + defpattern a foouri { + group { + element e1 + element e1 1 { + element e2 + } + element e2 + } + element e3 ? + } + defpattern b foouri { + element b1 3 + group 3 { + element b2 + ref a + } + } + foreach e {e1 e2 e3 b1 b2} { + defelement $e foouri {} + } + defelement doc foouri { + group { + ref a + ref b + } + } + } + set result [grammar validate { + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + }] + grammar delete + set result +} 1 + +test schema-7.7 {nested groups via refs} { + tdom::schema create grammar + grammar define { + defpattern a { + group { + element e1 + element e1 1 { + element e2 + } + element e2 + } + element e3 ? + } + defpattern b { + element b1 * + group 1 { + element b2 + ref a + } + } + foreach e {e1 e2 e3 b1 b2} { + defelement $e {} + } + defelement doc { + group 2 { + ref b + } + } + } + set doc [dom parse -validateCmd grammar { + + + + + + + + + + + + + + + + + + + + + + }] + $doc delete + set result [grammar validate { + + + + + + + + + + + + + + + + + + + + + + + } msg] + grammar delete + set result +} 1 + +test schema-7.8 {nested groups via refs} { + tdom::schema create grammar + grammar define { + defpattern a foouri { + group { + element e1 + element e1 1 { + element e2 + } + element e2 + } + element e3 ? + } + foreach e {e1 e2 e3 b1 b2} { + defelement $e foouri {} + } + defelement doc foouri { + group { + ref a + } + } + } + set doc [dom parse -validateCmd grammar { + + + + + + + + + + + }] + $doc delete + grammar delete +} {} + +test schema-7.9 {loop over seq} { + tdom::schema create grammar + grammar define { + defelement doc { + group * { + element a + element b + } + element c + } + foreach e {a b c} { + defelement $e {} + } + } + set result [grammar validate ] + grammar delete + set result +} 1 + +test schema-7.10 {loop over seq} { + tdom::schema create grammar + grammar define { + defelement doc { + group { + element a + element b + } + element c + } + foreach e {a b c} { + defelement $e {} + } + } + set result [grammar validate ] + grammar delete + set result +} 0 + +test schema-7.10a {loop over seq} { + tdom::schema create grammar + set result [catch {grammar define { + defelement doc { + group 2 { + element a + element b + } + element c + foreach e {a b c} { + defelement $e {} + } + } + }}] + grammar delete + set result +} 1 + +test schema-7.10b {loop over seq} { + tdom::schema create grammar + grammar define { + defelement doc { + group { + element a + element b + } + element c + } + foreach e {a b c} { + defelement $e {} + } + } + set result [grammar validate errMsg] + grammar delete + set result +} 0 + +test schema-7.10c {loop over seq} { + tdom::schema create grammar + grammar define { + defelement doc { + group { + element a + element b + } + element c + } + foreach e {a b c} { + defelement $e {} + } + } + set result [catch { + set doc [dom parse -validateCmd grammar ] + }] + grammar delete + set result +} 1 + +test schema-7.11 {loop over seq} { + tdom::schema create grammar + grammar define { + defelement doc { + group * { + element a + element b + } + element c + } + foreach e {a b c} { + defelement $e {} + } + } + set result [list] + foreach xml { + + + + + } { + lappend result [grammar validate $xml] + } + grammar delete + set result +} {1 1 1 0} + +test schema-7.11b {loop over seq} { + tdom::schema create grammar + grammar define { + defelement doc { + group 2 { + element a ? + element b ? + } + element c + } + foreach e {a b c} { + defelement $e {} + } + } + set result [list] + foreach xml { + + + + + } { + lappend result [grammar validate $xml] + } + grammar delete + set result +} {1 1 1 0} + +test schema-7.12 {loop over seq} { + tdom::schema create grammar + grammar define { + defelement doc { + group { + element a + element b + } + element c + } + foreach e {a b c} { + defelement $e {} + } + } + set result [grammar validate errMsg] + lappend result [grammar validate ] + lappend result [grammar validate ] + lappend result [grammar validate ] + lappend result [grammar validate ] + grammar delete + set result +} {0 0 1 0 0} + +test schema-7.13 {long sequence} { + tdom::schema create s + s define { + defelement doc { + for {set i 1} {$i < 200} {incr i} { + element e$i + } + } + for {set i 1} {$i < 200} {incr i} { + defelement e$i {element a} + } + defelement a {} + } + set xml "" + for {set i 1} {$i < 200} {incr i} { + append xml "" + } + append xml "" + set result [s validate $xml] + s delete + set result +} 1 + + +test schema-7.14 {mixed} { + tdom::schema create s + s define { + defelement doc { + mixed { + element a + element b + } + } + foreach e {a b} { + defelement $e {} + } + } + set result [list] + foreach xml { + + text + text + + some + some + } { + lappend result [s validate $xml] + } + s delete + set result +} {1 1 1 1 1 0} + +test schema-7.14a {mixed} { + tdom::schema create s + s define { + defelement doc { + mixed ! { + element a + element b + } + } + foreach e {a b} { + defelement $e {} + } + } + set result [list] + foreach xml { + text + text + + {to much} + some + + } { + lappend result [s validate $xml] + } + s delete + set result +} {1 0 1 0 0 0} + +test schema-7.14b {mixed} { + tdom::schema create s + s define { + defelement doc { + mixed ! { + element a * + element b + } + } + foreach e {a b} { + defelement $e {} + } + } + set result [list] + foreach xml { + text + text + + + + {to much} + + some + + } { + lappend result [s validate $xml] + } + s delete + set result +} {1 0 1 1 1 0 0 0 0} + +test schema-7.15 {choice with optional choices} { + tdom::schema create s + s define { + defelement doc { + choice { + element a * + element b * + } + element c + } + foreach e {a b c} { + defelement $e {} + } + } + set result [list] + foreach xml { + + + + + + + + } { + lappend result [s validate $xml] + } + s delete + set result +} {0 0 1 0 1 1 1} + +test schema-7.15a {choice with optional choices} { + tdom::schema create s + s define { + defelement doc { + choice { + element a * + element b * + } + } + foreach e {a b} { + defelement $e {} + } + } + set result [list] + foreach xml { + + + + + + + + } { + lappend result [s validate $xml] + } + s delete + set result +} {1 1 0 1 0 0 1} + +test schema-7.15b {choice with optional choices} { + tdom::schema create s + s define { + defelement doc { + choice { + element a * + element b + } + } + foreach e {a b} { + defelement $e {} + } + } + set result [list] + foreach xml { + + + + + + + + } { + lappend result [s validate $xml] + } + s delete + set result +} {1 1 0 1 0 0 1} + +test schema-7.16 {choice with optional choices} { + tdom::schema create s + s define { + defelement doc { + choice { + element a * + group * { + element aa + element ab ? + } + } + element c + } + foreach e {a aa ab c} { + defelement $e {} + } + } + set result [list] + foreach xml { + + + + + + + + + + } { + lappend result [s validate $xml] + } + s delete + set result +} {0 0 1 0 1 1 1 1 1} + +test schema-7.17 {choice with optional choices} { + tdom::schema create s + s define { + defelement doc { + choice { + element a * + group { + element aa + element ab ? + } + } + element c + } + foreach e {a aa ab c} { + defelement $e {} + } + } + set result [list] + foreach xml { + + + + + + + + + + } { + lappend result [s validate $xml] + } + s delete + set result +} {0 0 1 0 1 1 0 0 1} + +test schema-7.18 {choice} { + tdom::schema create s + s define { + defelement doc { + choice { + element a + group { + element aa + element ab ? + } + } + element c + } + foreach e {a aa ab c} { + defelement $e {} + } + } + set result [list] + foreach xml { + + + + + + + + + + } { + lappend result [s validate $xml] + } + s delete + set result +} {0 0 1 0 0 1 0 0 0} + +test schema-7.19 {choice with quantified choice} { + tdom::schema create s + s define { + defelement doc { + choice { + element a {0 2} + group { + element aa + element ab ? + } + } + element c + } + foreach e {a aa ab c} { + defelement $e {} + } + } + set result [list] + foreach xml { + + + + + + + + + + + + } { + lappend result [s validate $xml] + } + s delete + set result +} {0 0 1 1 0 0 0 1 0 0 1} + +test schema-7.20 {group with only optional content} { + tdom::schema create s + s define { + defelement doc { + element a + group { + element b ? + element c ? + } + } + foreach e {a b c} { + defelement $e {} + } + } + set result [list] + foreach xml { + + + + + + + + } { + lappend result [s validate $xml] + } + s delete + set result +} {0 1 1 0 1 1 0} + +test schema-7.21 {group with only optional content} { + set def { + group + { + element c ? + element a ? + element b ? + } + element d + } + set result [list] + tdom::schema s + s defelement doc $def + foreach xml { + + + + + + + + + + + } { + lappend result [s validate $xml] + } + s delete + set result +} {0 0 1 1 1 1 1 1 1 0} + +test schema-7.22 {Constraint text content in seq} { + tdom::schema s + s defelement doc { + element a + text { + minLength 4 + } + element b + } + set result [list] + foreach xml { + + 1234 + 123 + 12345 + { } + { } + } { + lappend result [s validate $xml] + } + s delete + set result +} {0 1 0 1 0 0} + +test schema-7.23 {Whitespace in implicit defined element} { + tdom::schema s + s defelement doc { + element a + } + set result [list] + foreach xml { + + + + { } + { } + { } + {12} + { } + { } + } { + lappend result [s validate $xml] + } + s delete + set result +} {0 1 1 1 1 0 0 0 0} + +test schema-7.23a {Whitespace in implicit defined element} { + tdom::schema s + s defelement doc { + element a + } + set result [list] + foreach xml { + { } + } { + lappend result [s validate $xml] + } + s delete + set result +} {0} + +test schema-8.1 {validate method} { + tdom::schema create grammar + grammar defelement doc { + element e1 + element e2 * + } + foreach e {e1 e2} { + grammar defelement $e {} + } + set result [grammar validate ] + lappend result [grammar validate errMsg] + lappend result [grammar validate errMsg] + lappend result [grammar validate errMsg] + lappend result [grammar validate errMsg] + grammar delete + set result +} {1 0 1 1 0} + +test schema-8.2 {validate method} { + tdom::schema create grammar + grammar defelement doc foouri { + element e1 + element e2 * + } + foreach e {e1 e2} { + grammar defelement $e foouri {} + } + set result [grammar validate {}] + lappend result [grammar validate {} errMsg] + grammar delete + set result +} {1 0} + +test schema-8.3 {validate method: white space between elements} { + tdom::schema create grammar + grammar define { + defpattern a { + group { + element e1 + element e1 1 { + element e2 + } + element e2 + } + element e3 ? + } + defpattern b { + element b1 * + group 2 { + element b2 + ref a + } + } + foreach e {e1 e2 e3 b1 b2} { + defelement $e {} + } + defelement doc { + group { + ref b + } + } + } + set result [grammar validate { + + + + + + + + + + + + + + + + + + + + + + + } msg] + grammar delete + set result +} 1 + +test schema-8.4 {illegal text} { + tdom::schema create grammar + grammar define { + defelement doc { + group * { + element a + element b + } + element c + } + foreach e {a b c} { + defelement $e {} + } + } + set result [grammar validate wrong errMsg] + grammar delete + set result +} 0 + +test schema-8.5 {illegal text - expat not signaling XML_STATUS_SUSPENDED although XML_StopParser() was called in handler, again.} { + tdom::schema create grammar + grammar define { + defelement doc { + group * { + element a + element b + } + element c + } + foreach e {a b c} { + defelement $e {} + } + } + set result [grammar validate wrong errMsg] + grammar delete + set result +} 0 + +test schema-8.6 {} { + tdom::schema create s + s define { + defelement doc {} + } + set result [s validate ] + lappend result [s validate ] + s start mydoc + lappend result [s validate ] + s delete + set result +} {1 0 0} + +proc schema-8.7 {scmd} { + global result + lappend result "in schema-8.7" + $scmd delete + error "this is deliberate" +} +test schema-8.7 {Delete schema cmd in script called by validation} { + set result "" + lappend result [info commands s] + tdom::schema s + lappend result [info commands s] + s defelement doc { + tcl schema-8.7 [self] + } + lappend result [catch {s validate } errMsg] + lappend result $errMsg + lappend result [info commands s] + lappend result [catch {s delete}] +} {{} s {in schema-8.7} 1 {error "this is deliberate" at line 1 character 6} {} 1} + +test schema-9.1 {choice} { + tdom::schema create grammar + grammar define { + defelement doc foouri { + choice * { + element e1 + element e2 + } + } + foreach e {e1 e2} { + defelement $e foouri {} + } + } + set result [grammar validate {}] + lappend result [grammar validate {}] + lappend result [grammar validate {}] + lappend result [grammar validate {}] + lappend result [grammar validate {}] + lappend result [grammar validate {}] + grammar delete + set result +} {1 1 1 1 1 1} + +test schema-9.2 {group} { + tdom::schema create grammar + grammar define { + defelement doc foouri { + group { + element e1 + element e2 * + } + } + foreach e {e1 e2} { + defelement $e foouri {} + } + } + set result [grammar validate {}] + lappend result [grammar validate {}] + lappend result [grammar validate {}] + lappend result [grammar validate {}] + lappend result [grammar validate {}] + lappend result [grammar validate {}] + lappend result [grammar validate {}] + grammar delete + set result +} {0 1 0 0 0 0 1} + +test schema-9.3 {choice} { + tdom::schema create grammar + grammar define { + defelement doc foouri { + choice * { + element e1 + group { + element e2 + element e3 + } + } + } + foreach e {e1 e2} { + defelement $e foouri {} + } + } + set result [grammar validate {}] + lappend result [grammar validate {}] + lappend result [grammar validate {}] + lappend result [grammar validate {}] + lappend result [grammar validate {}] + lappend result [grammar validate {}] + lappend result [grammar validate {}] + grammar delete + set result +} {1 1 1 1 1 1 0} + +test schema-9.4 {choice} { + tdom::schema create grammar + grammar define { + defelement doc foouri { + choice 2 { + element e1 + group { + element e2 + element e3 + } + } + } + foreach e {e1 e2 e3} { + defelement $e foouri {} + } + } + set result [grammar validate {}] + lappend result [grammar validate {}] + lappend result [grammar validate {}] + lappend result [grammar validate {}] + lappend result [grammar validate {}] + lappend result [grammar validate {}] + lappend result [grammar validate {}] + lappend result [grammar validate {}] + grammar delete + set result +} {0 0 0 1 1 1 1 0} + +test schema-9.5 {choice as choice child} { + tdom::schema create grammar + grammar define { + defelement doc { + choice { + element e1 + element e2 + choice { + element e2 + element e3 + } + } + } + foreach e {e1 e2 e3} { + defelement $e foouri {} + } + } + set result [list] + foreach xml { + + + + + + + } { + lappend result [grammar validate $xml] + } + grammar delete + set result +} {0 1 0 1 1 0} + +test schema-9.6 {mixed as choice child} { + tdom::schema create grammar + grammar define { + defelement doc { + choice { + element e1 + element e2 + mixed { + element e2 + element e3 + } + } + } + foreach e {e1 e2 e3} { + defelement $e foouri {} + } + } + set result [list] + foreach xml { + + {} + {} + {} + {} + {} + } { + lappend result [grammar validate $xml] + } + grammar delete + set result +} {1 1 0 1 1 0} + +test schema-9.7 {choice as mixed child} { + tdom::schema create grammar + grammar define { + defelement doc { + mixed { + element e1 + element e2 + choice { + element e2 + element e3 + } + } + } + foreach e {e1 e2 e3} { + defelement $e foouri {} + } + } + set result [list] + foreach xml { + + {} + {} + {} + {} + {} + } { + lappend result [grammar validate $xml] + } + grammar delete + set result +} {1 1 1 1 1 0} + +test schema-9.8 {choice as choice child} { + tdom::schema create grammar + grammar define { + defelement doc { + choice { + element e1 + element e2 + choice 2 { + element e3 + element e4 + } + } + } + } + set result [list] + foreach xml { + + {} + {} + {} + {} + {} + {} + } { + lappend result [grammar validate $xml] + } + grammar delete + set result +} {0 1 0 1 1 1 0} + +test schema-9.9 {choice with optional cp belong the choices} { + tdom::schema create grammar + grammar define { + defelement doc { + element e1 + choice { + element e2 + element e3 ? + } + element e4 ? + } + } + set result [list] + foreach xml { + + {} + {} + {} + {} + {} + {} + } { + lappend result [grammar validate $xml] + } + grammar delete + set result +} {0 1 1 1 1 1 1} + +test schema-9.10 {choice with may choices} { + tdom::schema create grammar + grammar define { + defelement doc { + element e1 + choice * { + for {set i 1} {$i <= 20} {incr i} { + element ee$i + } + } + element e2 ? + } + } + set result [list] + foreach xml { + + {} + {} + {} + {} + {} + {} + } { + lappend result [grammar validate $xml] + } + grammar delete + set result +} {0 1 1 1 1 0 1} + +test schema-9.11 {choice with may choices} { + tdom::schema create grammar + grammar define { + defelement doc { + element e1 + choice * { + for {set i 1} {$i <= 20} {incr i} { + namespace foo { + element ee$i + } + element ee$i + } + } + element e2 ? + } + } + set result [list] + foreach xml { + {} + {} + {} + {} + {} + {} + {} + } { + lappend result [grammar validate $xml] + } + grammar delete + set result +} {0 1 1 1 1 0 1} + +test schema-10.1 {any} { + tdom::schema create s + s define { + defelement doc { + element a + any + element b + } + defelement a {} + defelement b {} + } + set result [list] + foreach xml { + + text + } { + lappend result [s validate $xml] + } + s delete + set result +} {1 1} + +test schema-10.2 {any} { + tdom::schema create s + s define { + defelement doc { + element a + any 1 + element b + } + defelement a {} + defelement b {} + } + set result [s validate {}] + lappend result [s validate {}] + lappend result [s validate {}] + lappend result [s validate {text}] + s delete + set result +} {1 0 0 1} + +test schema-10.3 {any} { + tdom::schema create s + s define { + defelement doc { + element a + any ? + element b + } + defelement a {} + defelement b {} + } + set result [s validate {}] + lappend result [s validate {}] + lappend result [s validate {}] + lappend result [s validate {text}] + s delete + set result +} {1 0 0 1} + +test schema-10.4 {any} { + tdom::schema create s + s define { + defelement doc { + element a + any 2 + element b + } + defelement a {} + defelement b {} + } + set result [list] + foreach xml { + {} + {} + {} + {text} + } { + lappend result [s validate $xml] + } + s delete + set result +} {0 1 0 0} + +test schema-10.5 {any} { + tdom::schema create s + s define { + defelement doc { + element a + any http://foo.bar 2 + element b + } + defelement a {} + defelement b {} + } + set result [list] + foreach xml { + {} + {} + {} + {text} + {some} + {some} + {some} + } { + lappend result [s validate $xml] + } + s delete + set result +} {0 0 0 0 1 1 0} + +test schema-10.6 {any} { + tdom::schema create s + s define { + defelement doc { + any + } + } + set result [list] + foreach xml { + {} + } { + lappend result [s validate $xml] + } + s delete + set result +} {1} + +test schema-11.1 {attribute} { + tdom::schema create s + s define { + defelement doc { + attribute attr1 + attribute attr2 ? + } + } + set result [s validate {}] + lappend result [s validate {}] + lappend result [s validate {}] + lappend result [s validate {}] + s delete + set result +} {1 1 0 0} + +test schema-11.1a {attribute} { + tdom::schema create s + s define { + defelement doc { + attribute attr1 + attribute attr2 ? + } + } + set result [list] + foreach xml { + {} + {} + {} + {} + } { + lappend result [catch {set doc [dom parse -validateCmd s $xml]} errMsg] + catch {$doc delete} + s reset + } + s delete + set result +} {0 0 1 1} + +test schema-11.1b {attribute} { + tdom::schema create s + s define { + defelement doc { + attribute attr1 + attribute attr2 ? + } + } + ::xml::parser p -validateCmd s + set result [list] + foreach xml { + {} + {} + {} + {} + } { + lappend result [catch {p parse $xml} errMsg] + p reset + s reset + } + s delete + p delete + set result +} {0 0 1 1} + +test schema-11.2 {attribute} { + tdom::schema create s + s define { + defelement e { + attribute attr1 + element e 1 { + attribute attr3 ? + attribute attr4 ! + } + attribute attr2 ? + } + } + set result [s validate {}] + lappend result [s validate {}] + lappend result [s validate {}] + lappend result [s validate {}] + lappend result [s validate {}] + s delete + set result +} {1 1 0 1 0} + +test schema-11.2a {attribute} { + tdom::schema create s + s define { + defelement e { + attribute attr1 + element e 1 { + attribute attr3 ? + attribute attr4 ! + } + attribute attr2 ? + } + } + set result [list] + foreach xml { + {} + {} + {} + {} + {} + } { + lappend result [catch {set doc [dom parse -validateCmd s $xml]} errMsg] + catch {$doc delete} + s reset + } + s delete + set result +} {0 0 1 0 1} + +test schema-11.2b {attribute} { + tdom::schema create s + s define { + defelement e { + attribute attr1 + element e 1 { + attribute attr3 ? + attribute attr4 ! + } + attribute attr2 ? + } + } + ::xml::parser p -validateCmd s + set result [list] + foreach xml { + {} + {} + {} + {} + {} + } { + lappend result [catch {p parse $xml} errMsg] + p reset + s reset + } + p delete + s delete + set result +} {0 0 1 0 1} + +test schema-11.3 {attribute} { + tdom::schema create s + s define { + defelement e { + attribute attr1 + attribute attr3 ? + attribute attr4 ! + attribute attr2 ? + } + } + set result [s validate errMsg] + lappend result $errMsg + s delete + set result +} {0 {error "Missing mandatory attribute(s): attr1 attr4" at line 1 character 4}} + +test schema-11.3a {attribute} { + tdom::schema create s + s define { + defelement e { + attribute attr1 + attribute attr3 ? + attribute attr4 ! + attribute attr2 ? + } + } + set result [catch {dom parse -validateCmd s } errMsg] + lappend result $errMsg + s delete + set result +} {1 {Missing mandatory attribute(s): attr1 attr4, referenced at line 1 character 4}} + +test schema-11.3b {attribute} { + tdom::schema create s + s define { + defelement e { + attribute attr1 + attribute attr3 ? + attribute attr4 ! + attribute attr2 ? + } + } + ::xml::parser p -validateCmd s + set result [catch {p parse } errMsg] + lappend result $errMsg + p delete + s delete + set result +} {1 {Missing mandatory attribute(s): attr1 attr4}} + +test schema-11.4 {attribute} { + tdom::schema create s + s define { + defelement doc { + element e 1 { + attribute foo + nsattribute lang http://www.w3.org/XML/1998/namespace ? + } + } + } + set result [s validate {} errMsg] + s delete + lappend result $errMsg +} {1 {}} + +test schema-11.4_1 {attribute} { + tdom::schema create s + s prefixns {1 http://www.w3.org/XML/1998/namespace} + s define { + defelement doc { + element e 1 { + attribute foo + nsattribute lang 1 ? + } + } + } + set result [s validate {} errMsg] + s delete + lappend result $errMsg +} {1 {}} + +test schema-11.4a {attribute} { + tdom::schema create s + s define { + defelement doc { + element e 1 { + attribute foo + nsattribute lang http://www.w3.org/XML/1998/namespace ? + } + } + } + set result [catch {set doc [dom parse -validateCmd s {}]}] + s delete + $doc delete + set result +} 0 + +test schema-11.4b {attribute} { + tdom::schema create s + s define { + defelement doc { + element e 1 { + attribute foo + nsattribute lang http://www.w3.org/XML/1998/namespace + } + } + } + set result [s validate {} errMsg] + s delete + lappend result $errMsg +} {1 {}} + +test schema-11.5 {nsattribute} { + tdom::schema create s + s define { + defelement doc { + element e 1 { + attribute foo + nsattribute lang http://www.w3.org/XML/1998/namespace ? + } + } + } + set result [catch {set doc [dom parse -validateCmd s {}]}] + s delete + $doc delete + set result +} 0 + +test schema-11.5a {nsattribute} { + tdom::schema create s + s prefixns {ns1 http://www.w3.org/XML/1998/namespace} + s define { + defelement doc { + element e 1 { + attribute foo + nsattribute lang ns1 ? + } + } + } + set result [catch {set doc [dom parse -validateCmd s {}]}] + s delete + $doc delete + set result +} 0 + +test schema-11.6 {nsattribute} { + tdom::schema create s + s define { + defelement doc { + element e 1 { + attribute foo + nsattribute lang http://www.w3.org/XML/1998/namespace + } + } + } + set result [list] + foreach xml { + {} + {} + {} + {} + } { + lappend result [catch {set doc [dom parse -validateCmd s $xml]} errMsg] + lappend result $errMsg + s reset + } + s delete + set result +} {1 {Missing mandatory attribute(s): http://www.w3.org/XML/1998/namespace:lang, referenced at line 1 character 19} 1 {Missing mandatory attribute(s): foo, referenced at line 1 character 23} 1 {Unknown attribute "unknown", referenced at line 1 character 24} 1 {Missing mandatory attribute(s): foo http://www.w3.org/XML/1998/namespace:lang, referenced at line 1 character 9}} + +test schema-11.6 {nsattribute} { + tdom::schema create s + s prefixns {ns1 http://www.w3.org/XML/1998/namespace} + s define { + defelement doc { + element e 1 { + attribute foo + nsattribute lang ns1 + } + } + } + set result [list] + foreach xml { + {} + {} + {} + {} + } { + lappend result [catch {set doc [dom parse -validateCmd s $xml]} errMsg] + lappend result $errMsg + s reset + } + s delete + set result +} {1 {Missing mandatory attribute(s): http://www.w3.org/XML/1998/namespace:lang, referenced at line 1 character 19} 1 {Missing mandatory attribute(s): foo, referenced at line 1 character 23} 1 {Unknown attribute "unknown", referenced at line 1 character 24} 1 {Missing mandatory attribute(s): foo http://www.w3.org/XML/1998/namespace:lang, referenced at line 1 character 9}} + +test schema-11.7 {attribute} { + set defs { + {defelement doc {attribute foo}} + {defelement doc {group {attribute foo}}} + {defpattern some {attribute foo}} + {defelement doc {element {attribute foo}}} + } + set result [list] + foreach def $defs { + tdom::schema create s + lappend result [catch {s define $def}] + s delete + } + set result +} {0 1 1 0} + +test schema-11.8 {attribute} { + tdom::schema s + s define { + defelement doc { + element e ! { + attribute abc + attribute def + attribute ghi + attribute jkl + attribute mno + attribute pqr + } + } + } + set result [list] + foreach xml { + {} + {} + {} + } { + lappend result [s validate $xml] + } + s delete + set result +} {1 0 0} + +test schema-11.8a {attribute} { + tdom::schema s + s define { + defelement doc { + element e ! { + attribute abc + attribute def + attribute ghi + attribute optional ? + attribute jkl + attribute mno + attribute pqr + } + } + } + set result [list] + foreach xml { + {} + {} + {} + {} + {} + {} + } { + lappend result [s validate $xml] + } + s delete + set result +} {1 0 0 1 0 0} + +proc schema-11.8b {scmd errType} { + lappend ::result $errType + lappend ::result [$scmd info vaction name] + lappend ::result [$scmd info vaction namespace] +} + +test schema-11.8b {attribute} { + tdom::schema s + s define { + defelement doc { + element e ! { + attribute abc + attribute def + attribute ghi + attribute optional ? + attribute jkl + attribute mno + attribute pqr + } + } + } + s reportcmd schema-11.8b + set result [list] + foreach xml { + {} + {} + {} + {} + {} + {} + } { + lappend result [s validate $xml] + } + s delete + set result +} {1 MISSING_ATTRIBUTE mno {} 1 UNKNOWN_ATTRIBUTE unknown {} 1 1 MISSING_ATTRIBUTE mno {} 1 UNKNOWN_ATTRIBUTE unknown {} 1} + +test schema-11.9 {attribute} { + tdom::schema s + s define { + prefixns {ns1 http://foo.bar ns2 http://foo.grill ns3 http://bar.grill} + defelement doc { + element e ! { + nsattribute abc ns1 + nsattribute abc ns2 + attribute abc + attribute def + attribute optional ? + nsattribute optional ns3 ? + attribute ghi + attribute jkl + attribute mno + attribute pqr + } + } + } + set result [list] + foreach xml { + {} + {} + {} + {} + {} + {} + } { + lappend result [s validate $xml] + } + s delete + set result +} {0 1 0 0 1 0} + +test schema-11.10 {attribute} { + tdom::schema s + s define { + prefixns {ns1 http://foo.bar ns2 http://foo.grill} + defelement doc { + element e ! { + nsattribute abc ns1 + nsattribute abc ns2 + attribute abc + attribute def + attribute ghi + attribute jkl + attribute mno + attribute pqr + } + } + } + set result [list] + foreach xml { + {} + {} + {} + } { + dom parse $xml doc + lappend result [s domvalidate $doc] + $doc delete + } + s delete + set result +} {0 1 0} + +test schema-11.10a {attribute} { + tdom::schema s + s define { + prefixns {ns1 http://foo.bar ns2 http://foo.grill ns3 http://bar.grill} + defelement doc { + element e ! { + nsattribute abc ns1 + nsattribute abc ns2 + attribute abc + attribute def + attribute optional ? + nsattribute optional ns3 ? + attribute ghi + attribute jkl + attribute mno + attribute pqr + } + } + } + s reportcmd schema-11.8b + set result [list] + foreach xml { + {} + {} + {} + {} + {} + {} + {} + } { + lappend result [s validate $xml] + } + s delete + set result +} {MISSING_ATTRIBUTE abc {} 1 1 MISSING_ATTRIBUTE abc http://foo.bar 1 UNKNOWN_ATTRIBUTE abc http://bar.grill 1 MISSING_ATTRIBUTE abc {} 1 1 UNKNOWN_ATTRIBUTE abc http://bar.grill 1} + +proc schema-11.11 {scmd errType} { + lappend ::result $errType +} +test schema-11.11 {attribute - required missing} { + tdom::schema s + s defelement doc { + element a + { + attribute mode + } + } + s reportcmd schema-11.11 + set result "" + set doc [dom parse ] + lappend result [s domvalidate $doc] + $doc delete + s delete + set result +} {MISSING_ATTRIBUTE 1} + +test schema-12.1 {domvalidate} { + tdom::schema s + s define { + defelement addressBook { + element card * + } + defelement card { + element name + element email + } + foreach e {name email} { + defelement $e {text} + } + } + set doc [dom parse { + + + John Smith + js@example.com + + + Fred Bloggs + fb@example.net + + + }] + set result [s domvalidate $doc] + lappend result [s domvalidate [$doc documentElement]] + lappend result [s domvalidate [[$doc documentElement] firstChild]] + lappend result [s domvalidate [[[$doc documentElement] firstChild] firstChild]] + $doc delete + s delete + set result +} {1 1 1 1} + +test schema-12.2 {domvalidate} { + tdom::schema s + s define { + defelement addressBook { + element card * + } + defelement card { + element name + element email + } + foreach e {name email} { + defelement $e {text} + } + } + set doc [dom parse { + + + John Smith + js@example.com + + + Fred Bloggs + fb@example.net + John Smith + + + }] + set result [s domvalidate $doc errMsg] + lappend result $errMsg + $doc delete + s delete + set result +} {0 {Element "some" doesn't match}} + +test schema-12.3 {domvalidate w/ attribute} { + tdom::schema s + s define { + defelement doc { + attribute type {fixed "1.2"} + element a + element b + } + foreach e {a b} { + defelement $e {} + } + } + set result [list] + foreach xml { + {} + {} + {} + {} + {} + } { + set doc [dom parse $xml] + lappend result [s domvalidate [$doc documentElement]] + lappend result [s validate $xml] + $doc delete + } + s delete + set result +} {1 1 0 0 0 0 0 0 0 0} + +test schema-12.4 {domvalidate w/ text} { + tdom::schema s + s define { + defelement doc { + attribute type {fixed "1.2"} + element a + element b + } + foreach e {a b} { + defelement $e text + } + } + set result [list] + foreach xml { + {} + {content} + {contentsome text} + {textcontentsome text} + {some text} + } { + set doc [dom parse $xml] + lappend result [s domvalidate [$doc documentElement]] + lappend result [s validate $xml] + $doc delete + } + s delete + set result +} {1 1 1 1 1 1 0 0 0 0} + +test schema-12.5 {domvalidate doch w/ xml namespace} { + tdom::schema s + s define { + defelement addressBook http://foo.bar { + element card * + } + defelement card http://foo.bar { + element name + element email + } + foreach e {name email} { + defelement $e http://foo.bar {text} + } + } + set doc [dom parse { + + + John Smith + js@example.com + + + Fred Bloggs + fb@example.net + + + }] + set result [s domvalidate $doc] + lappend result [s domvalidate [$doc documentElement]] + lappend result [s domvalidate [[$doc documentElement] firstChild]] + lappend result [s domvalidate [[[$doc documentElement] firstChild] firstChild]] + $doc delete + set doc [dom parse { + + + John Smith + js@example.com + + + Fred Bloggs + fb@example.net + + +}] + lappend result [s domvalidate $doc] + lappend result [s domvalidate [$doc documentElement]] + lappend result [s domvalidate [[$doc documentElement] firstChild]] + lappend result [s domvalidate [[[$doc documentElement] firstChild] firstChild]] + $doc delete + s delete + set result +} {1 1 1 1 1 1 1 1} + +test schema-12.5a {domvalidate doc w/ xml namespace} { + tdom::schema s + s prefixns {fb http://foo.bar} + s define { + defelement addressBook fb { + element card * + } + defelement card fb { + element name + element email + } + foreach e {name email} { + defelement $e fb {text} + } + } + set doc [dom parse { + + + John Smith + js@example.com + + + Fred Bloggs + fb@example.net + + + }] + set result [s domvalidate $doc] + lappend result [s domvalidate [$doc documentElement]] + lappend result [s domvalidate [[$doc documentElement] firstChild]] + lappend result [s domvalidate [[[$doc documentElement] firstChild] firstChild]] + $doc delete + set doc [dom parse { + + + John Smith + js@example.com + + + Fred Bloggs + fb@example.net + + +}] + lappend result [s domvalidate $doc] + lappend result [s domvalidate [$doc documentElement]] + lappend result [s domvalidate [[$doc documentElement] firstChild]] + lappend result [s domvalidate [[[$doc documentElement] firstChild] firstChild]] + $doc delete + s delete + set result +} {1 1 1 1 1 1 1 1} + +test schema-12.6 {domvalidate only root} { + tdom::schema s + s reportcmd dummycallback + s start doc + set doc [dom parse ] + set result [s domvalidate $doc] + s defelement doc {} + lappend result [s domvalidate $doc] + s delete + $doc delete + set result +} {1 1} + +test schema-12.7 {domvalidate invalid root} { + tdom::schema s + s start doc + s reportcmd dummycallback + set doc [dom parse ] + set result [s domvalidate $doc] + s delete + $doc delete + set result +} 1 + +test schema-13.1 {XML namespaces} { + tdom::schema create s + s defelement doc ns1 { + # Forward defined element inherits child namespace + element elm1 + element elm2 + } + s defelement elm1 ns2 {} + s defelement elm1 ns1 { + choice { + element fooElem + element barElem + + } + } + s defelement elm2 ns1 {} + s defelement fooElem ns1 {} + s defelement barElem ns1 {} + set result [list] + foreach xml { + {} + {} + {} + {} + {} + } { + lappend result [s validate $xml] + } + s delete + set result +} {0 1 1 1 0} + +test schema-13.2 {XML namespaces} { + tdom::schema create s + s defelement doc ns1 { + namespace ns2 { + element elm1 + } + # Forward defined element inherits child namespace + element elm2 + } + s defelement elm1 ns2 {} + s defelement elm1 ns1 { + choice { + element fooElem + element barElem + + } + } + s defelement elm2 ns1 {} + s defelement fooElem ns1 {} + s defelement barElem ns1 {} + set result [list] + foreach xml { + {} + {} + {} + {} + {} + } { + lappend result [s validate $xml] + } + s delete + set result +} {0 0 0 0 1} + +test schema-13.3 {Not namespaced elements inside namespaced ones} { + tdom::schema s + s define { + defelement doc ns1 { + namespace "" { + element e + } + } + defelement e {text {fixed "here"}} + } + set result "" + foreach xml { + {here} + {here} + {here} + {here} + } { + lappend result [s validate $xml] + } + s delete + set result +} {1 1 1 0} + +test schema-14.1 {text: integer} { + tdom::schema s + s defelement doc { + text { + integer + } + } + set result [list] + foreach xml { + + + 5 + eeee + 56666 + { } + { 97 } + } { + lappend result [s validate $xml] + } + s delete + set result +} {0 0 1 0 1 0 0} + +test schema-14.1.1 {text: integer} { + tdom::schema s + s defelement doc { + text { + integer tcl + } + } + set result [list] + foreach xml { + + + 5 + eeee + 56666 + { } + { +34 } + {034} + {0034 } + {0xAB} + } { + lappend result [s validate $xml] + } + s delete + set result +} {0 0 1 0 1 0 1 1 1 1} + +test schema-14.1.2 {text: integer} { + tdom::schema s + s defelement doc { + text { + integer xsd + } + } + set result [list] + foreach xml { + + + 5 + eeee + 56666 + { } + { +34 } + {034} + {0034 } + {0xAB} + } { + lappend result [s validate $xml] + } + s delete + set result +} {0 0 1 0 1 0 0 1 0 0} + + +proc proc-14.2 {param text} { + if {$text in {one two tree}} { + return true + } + return false +} + +test schema-14.2 {text: tcl} {8.5} { + tdom::schema s + s define { + defelement doc { + element a + element b + } + defelement a { + text {tcl string is lower -strict} + } + defelement b { + text {tcl proc-14.2 foo} + } + } + set result [list] + foreach xml { + + + abctwo + aBctwo + abcfour + } { + lappend result [s validate $xml] + } + s delete + set result +} {0 0 1 0 0} + +test schema-14.3 {attribute text: tcl} {8.5} { + tdom::schema s + s define { + defelement doc { + element e 1 { + attribute a ! {tcl string is lower -strict} + attribute b ? {tcl proc-14.2 foo} + } + } + } + set result [list] + foreach xml { + {} + {} + {} + {} + } { + lappend result [s validate $xml] + } + s delete + set result +} {1 0 0 1} + +test schema-14.4 {text: fixed} { + tdom::schema s + s define { + defelement doc { + element e * + } + defelement e { + attribute a ! {fixed enabled} + text {fixed something} + } + } + set result [list] + foreach xml { + + {something} + {something} + {something else} + {somethingsomething} + {somethingnot} + } { + lappend result [s validate $xml] + } + s delete + set result +} {1 1 0 0 0 0} + +test schema-14.5 {text: enumeration} { + tdom::schema s + s define { + defelement doc { + element e * + } + defelement e { + attribute a {enumeration {enabled disabled}} + text {enumeration {enabled disabled "a third"}} + } + } + set result [list] + foreach xml { + + {disabled} + {disableda third} + {something} + {something else} + {enabled disabled} + } { + lappend result [s validate $xml] + } + s delete + set result +} {1 1 1 0 0 0} + +test schema-14.6 {text: match (glob style)} { + tdom::schema s + s define { + defelement doc { + element e * + } + defelement e { + text {match {[a-zA-Z]*1[_!]}} + } + } + set result [list] + foreach xml { + + {disabled1_} + {dis able1_} + {something} + {a1!} + {a1!/} + } { + lappend result [s validate $xml] + } + s delete + set result +} {1 1 1 0 1 0} + +test schema-14.6a {text: match (glob style) -nocase} { + tdom::schema s + s define { + defelement doc { + element e * + } + defelement e { + text {match -nocase {[A-Z]*1[_!]}} + } + } + set result [list] + foreach xml { + + {disabled1_} + {dis able1_} + {something} + {a1!} + {a1!/} + } { + lappend result [s validate $xml] + } + s delete + set result +} {1 1 1 0 1 0} + +test schema-14.7 {text: regexp} { + tdom::schema s + s define { + defelement doc { + element e * + } + defelement e { + text {regexp {^[a-zA-Z]*1[_!]$}} + } + } + set result [list] + foreach xml { + {disabled1_} + {dis able1_} + {something} + {a1!} + {a1!/} + } { + lappend result [s validate $xml] + } + s delete + set result +} {1 0 0 1 0} + +test schema-14.8 {text: nmtoken, nmtokens} { + tdom::schema s + s define { + defelement doc { + attribute a {nmtoken} + attribute b {nmtokens} + attribute c ? + } + } + set result [list] + foreach xml { + {} + {} + {} + {} + {} + {} + {} + {} + {} + {} + {} + {} + {} + {} + {} + } { + lappend result [s validate $xml] + } + s delete + set result +} {1 1 1 0 0 1 1 1 1 1 1 1 0 0 0} + +test schema-14.9 {text: date} { + tdom::schema s + s define { + defelement doc { + text date + } + } + set result [list] + foreach xml { + + + foo + 1 + 12 + 1234-12-31 + 1234-14-31 + 1234-12-00 + 1234-02-31 + 2000-02-29 + 2001-02-29 + 2004-02-29 + -2004-02-29 + 1900-02-29 + 1234-02-01 + 1234-08-10 + 1234-08-222 + { 1234-08-22} + {1234-08-22 } + 11234-08-22 + 0000-02-01 + 10000-08-22 + 10000-02-29 + 10000-02-29Z + 2012-03-07Z + {2012-03-07Z } + 2012-03-07a + 2012-03-07+ + 2012-03-07+00:00 + 2012-03-07-00:00 + 2012-03-07+02:00 + 2012-03-07+02:70 + 2012-03-07+12:30 + 2012-03-07+14:30 + 2012-03-07+14:00 + 2012-03-07-14:00 + 2012-03-07-14:01 + 2012-03-07-2:30 + 2012-03-07-02:30Z + {2012-03-07-02:30 } + 02027-02-01 + } { + lappend result [s validate $xml] + } + s delete + set result +} {0 0 0 0 0 1 0 0 0 1 0 1 1 0 1 1 0 0 0 1 0 1 1 1 1 0 0 0 1 1 1 0 1 0 1 1 0 0 0 0 0} + +test schema-14.10 {text: number tcl} { + tdom::schema s + s define { + defelement doc { + text {number tcl} + } + } + set result [list] + foreach xml { + + + { } + foo + 1 + 12 + 1234-12-31 + -14.23 + .777 + -1.2e5 + { -1.2e5 } + { -1.2e5 e} + } { + lappend result [s validate $xml] + } + s delete + set result +} {0 0 0 0 1 1 0 1 1 1 1 0} + +test schema-14.10a {text: number xsd} { + tdom::schema s + s define { + defelement doc { + text number + } + } + set result [list] + foreach xml { + + + { } + foo + 1 + { 1} + {1 } + { 1 } + 12 + 1234-12-31 + -14.23 + .777 + -1.2e5 + { -1.2e5 } + { -1.2e5 e} + } { + lappend result [s validate $xml] + } + s delete + set result +} {0 0 0 0 1 0 0 0 1 0 1 1 0 0 0} + +test schema-14.11 {text: maxLength} { + tdom::schema s + s define { + defelement doc { + text { + maxLength 6 + } + } + } + set result [list] + foreach xml { + + + foo + 1 + 12 + 1234-12-31 + -14.23 + 👮ሴሴሴሴሴ + 👮ሴሴሴሴሴ👮 + } { + lappend result [s validate $xml] + } + s delete + set result +} {1 1 1 1 1 0 1 1 0} + +test schema-14.12 {text: maxLength} { + tdom::schema s + s define { + defelement doc { + text {minLength 6} + } + } + set result [list] + foreach xml { + + + foo + 1 + 12 + 1234-12-31 + -14.23 + 👮ሴሴሴሴ + 👮ሴሴሴሴሴ + 👮ሴሴሴሴሴ👮 + } { + lappend result [s validate $xml] + } + s delete + set result +} {0 0 0 0 0 1 1 0 1 1} + +test schema-14.13 {text: two constraints} { + tdom::schema s + s define { + defelement doc { + text { + minLength 6 + maxLength 8 + } + } + } + set result [list] + foreach xml { + foo + 1 + 12 + 1234-12-31 + -14.23 + 👮ሴሴሴሴ + 👮ሴሴሴሴሴ + 👮ሴሴሴሴሴ👮 + 1234567890 + 12345678901234567890 + } { + lappend result [s validate $xml] + } + s delete + set result +} {0 0 0 0 1 0 1 1 0 0} + +test schema-14.14 {text: one of two types} { + tdom::schema s + s define { + defelement doc { + choice { + text { + minLength 1 + maxLength 3 + } + text {date} + } + } + } + set result [list] + foreach xml { + + + foo + 1 + 12 + 1234-12-31 + -14.23 + 👮ሴሴሴሴ + 1234-12 + 12345678901234567890 + } { + lappend result [s validate $xml] + } + s delete + set result +} {0 0 1 1 1 1 0 0 0 0} + +test schema-14.15 {text: oneOf} { + tdom::schema s + s define { + defelement doc { + text { + oneOf { + maxLength 3 + date + } + } + } + } + set result [list] + foreach xml { + + + foo + 1 + 12 + 1234-12-31 + -14.23 + 👮ሴሴሴሴ + 1234-12 + 12345678901234567890 + } { + lappend result [s validate $xml] + } + s delete + set result +} {1 1 1 1 1 1 0 0 0 0} + +test schema-14.16 {text: oneOf} { + tdom::schema s + s define { + defelement doc { + text { + minLength 1 + oneOf { + maxLength 3 + date + } + } + } + } + set result [list] + foreach xml { + + + foo + 1 + 12 + 1234-12-31 + -14.23 + 👮ሴሴሴሴ + 1234-12 + 12345678901234567890 + } { + lappend result [s validate $xml] + } + s delete + set result +} {0 0 1 1 1 1 0 0 0 0} + +test schema-14.17 {text: oneOf w/ allOf} { + tdom::schema s + s define { + defelement doc { + text { + minLength 1 + oneOf { + allOf { + maxLength 3 + minLength 1 + } + date + } + } + } + } + set result [list] + foreach xml { + + + foo + 1 + 12 + 1234-12-31 + -14.23 + 👮ሴሴሴሴ + 1234-12 + 12345678901234567890 + } { + lappend result [s validate $xml] + } + s delete + set result +} {0 0 1 1 1 1 0 0 0 0} + +test schema-14.18 {deftexttype} { + tdom::schema s + s deftexttype len2-4 { + minLength 2 + maxLength 4 + } + s defelement doc { + element e ! {text type len2-4} + } + set result [list] + foreach xml { + + + + { } + {1} + {12} + { } + {123} + {1234} + {1234 } + {12345} + {123ሴ} + } { + lappend result [s validate $xml] + set rc [catch {dom parse -validateCmd s $xml doc}] + if {$rc == 0} { + $doc delete + } + lappend result $rc + } + s delete + set result +} {0 1 0 1 0 1 0 1 0 1 1 0 1 0 1 0 1 0 0 1 0 1 1 0} + +test schema-14.18a {deftexttype} { + tdom::schema s + s define { + deftexttype len2-4 { + minLength 2 + maxLength 4 + } + defelement doc { + element e ! {text type len2-4} + } + } + set result [list] + foreach xml { + + + + { } + {1} + {12} + { } + {123} + {1234} + {1234 } + {12345} + {123ሴ} + } { + lappend result [s validate $xml] + set rc [catch {dom parse -validateCmd s $xml doc}] + if {$rc == 0} { + $doc delete + } + lappend result $rc + } + s delete + set result +} {0 1 0 1 0 1 0 1 0 1 1 0 1 0 1 0 1 0 0 1 0 1 1 0} + +test schema-14.18b {deftexttype} { + tdom::schema s + s define { + deftexttype len2-4 { + minLength 2 + maxLength 4 + } + tdom::schema s1 + s1 define { + deftexttype len2-4 { + minLength 2 + maxLength 4 + } + defelement doc { + element e ! {text type len2-4} + } + } + defelement doc { + element e ! {text type len2-4} + } + } + set result [list] + foreach xml { + + + + { } + {1} + {12} + { } + {123} + {1234} + {1234 } + {12345} + {123ሴ} + } { + lappend result [s validate $xml] + lappend result [s1 validate $xml] + set rc [catch {dom parse -validateCmd s $xml doc}] + if {$rc == 0} { + $doc delete + } + lappend result $rc + set rc [catch {dom parse -validateCmd s1 $xml doc}] + if {$rc == 0} { + $doc delete + } + lappend result $rc + } + s1 delete + s delete + set result +} {0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 0 0 1 1 0 0 1 1 1 1 0 0} + + +test schema-14.19 {deftexttype} { + tdom::schema s + s deftexttype len2-4 { + minLength 2 + maxLength 4 + } + s defelement doc { + element e + } + s defelement e { + attribute this type len2-4 + attribute foo ? type len2-4 + } + set result [list] + foreach xml { + + {} + {} + {} + {} + {} + {} + {} + {} + {} + } { + lappend result [s validate $xml errMsg] + set rc [catch {dom parse -validateCmd s $xml doc}] + if {$rc == 0} { + $doc delete + } + lappend result $rc + } + s delete + set result +} {0 1 0 1 1 0 0 1 1 0 0 1 1 0 0 1 0 1 0 1} + +test schema-14.19a {deftexttype} { + tdom::schema s + s deftexttype len2-4 { + minLength 2 + maxLength 4 + } + s defelement doc { + element e ! { + attribute this type len2-4 + attribute foo ? type len2-4 + } + } + set result [list] + foreach xml { + + {} + {} + {} + {} + {} + {} + {} + {} + {} + } { + lappend result [s validate $xml] + set rc [catch {dom parse -validateCmd s $xml doc}] + if {$rc == 0} { + $doc delete + } + lappend result $rc + } + s delete + set result +} {0 1 0 1 1 0 0 1 1 0 0 1 1 0 0 1 0 1 0 1} + +test schema-14.20 {deftexttype} { + tdom::schema s + s deftexttype len2-4 { + minLength 2 + maxLength 4 + } + s defelement doc { + element e ! { + nsattribute this http://tdom.org/test { + minLength 2 + maxLength 4 + } + nsattribute foo http://tdom.org/test ? type len2-4 + } + } + set result [list] + foreach xml { + + {} + {} + {} + {} + {} + {} + {} + {} + {} + } { + lappend result [s validate $xml] + } + s delete + set result +} {0 0 1 0 1 0 1 0 0 0} + +test schema-14.20a {deftexttype} { + tdom::schema s + s deftexttype len2-4 { + minLength 2 + maxLength 4 + } + s define { + prefixns { + ns2 http://tdom.org/test + nsfoo http://foo.bar + ns2 http://baz.boo + } + defelement doc { + element e ! { + nsattribute this ns2 { + minLength 2 + maxLength 4 + } + nsattribute foo ns2 ? type len2-4 + } + } + } + set result [list] + foreach xml { + + {} + {} + {} + {} + {} + {} + {} + {} + {} + } { + lappend result [s validate $xml] + } + s delete + set result +} {0 0 1 0 1 0 1 0 0 0} + +test schema-14.21 {strip} { + tdom::schema s + s define { + defelement a { + text { + strip { + minLength 3 + maxLength 5 + } + } + } + } + set result [list] + foreach xml { + + + { } + { 3 } + {123} + { 123 } + { 123 } + {1234} + {12345} + {123456} + { 12 34 } + } { + lappend result [s validate $xml] + } + s delete + set result +} {0 0 0 0 1 1 1 1 1 0 1} + +test schema-14.22 {split} { + tdom::schema s + s define { + defelement doc { + element a 1 { + text { + split { + number + } + } + } + } + } + set result [list] + foreach xml { + + + { } + {1} + {-2.1} + { -2.1 + } + {-a} + {-a b c} + { 1 2 3.5} + { 1 a 3.5} + {1 2 fooo} + {1 2 fooo } + } { + lappend result [s validate $xml] + } + s delete + set result +} {0 0 0 1 1 1 0 0 1 0 0 0} + +proc schema-14.23 {text} { + return [split $text] +} + +test schema-14.23 {split} { + tdom::schema s + s define { + defelement doc { + element a 1 { + text { + split tcl schema-14.23 { + number + } + } + } + } + } + set result [list] + foreach xml { + + + { } + {1} + {-2.1} + { -2.1 + } + {-a} + {-a b c} + {1 2 3.5} + { 1 a 3.5} + {1 2 fooo} + {1 2 3 -4.5} + } { + lappend result [s validate $xml errMsg] + } + s delete + set result +} {0 0 0 1 1 0 0 0 0 0 0 1} + +proc schema-14.24 {text} { + global schema-14.24 + switch ${schema-14.24} { + 1 {return {1 2 3}} + 2 {return {-23.4 .5}} + 3 {return {0 a 5}} + default {error "Unexpected value of the global var schema-14.24."} + } +} + +test schema-14.24 {split} { + set schema-14.24 0 + tdom::schema s + s define { + defelement doc { + element a 1 { + text { + split tcl schema-14.24 { + number + } + } + } + } + } + set result [list] + foreach xml { + { } + {-a} + {1 2 3 -4.5} + } { + incr schema-14.24 + lappend result [s validate $xml errMsg] + } + s delete + set result +} {1 1 0} + +proc schema-14.24a {arg1 arg2 text} { + global schema-14.24a + if {$arg1 ne "foo" || $arg2 ne "bar"} { + error "Unexpected args" + } + switch ${schema-14.24a} { + 1 {return {1 2 3}} + 2 {return {-23.4 .5}} + 3 {return {0 a 5}} + default {error "Unexpected value of the global var schema-14.24."} + } +} + +test schema-14.24a {split} { + set schema-14.24a 0 + tdom::schema s + s define { + defelement doc { + element a 1 { + text { + split tcl schema-14.24a foo bar { + number + } + } + } + } + } + set result [list] + foreach xml { + { } + {-a} + {1 2 3 -4.5} + } { + incr schema-14.24a + lappend result [s validate $xml] + } + s delete + set result +} {1 1 0} + +test schema-14.25 {element content id/idref} { + tdom::schema s + s define { + defelement doc { + interleave { + element id * + element idref * + } + } + defelement id {text id} + defelement idref {text idref} + } + set result [list] + foreach xml { + + abc + abc + abcabc + abcabc + abcabcabc + abcabcabc + {abcabcab c} + abcabcabc + abc123 + } { + lappend result [s validate $xml] + } + s delete + set result +} {1 1 0 1 1 1 1 0 0 0} + +test schema-14.26 {attribute id/idref} { + tdom::schema s + s define { + defelement doc { + interleave { + element id * + element idref * + } + } + defelement id {attribute id id} + defelement idref {attribute idref idref} + } + set result [list] + foreach xml { + + {} + {} + {} + {} + {} + {} + {} + {} + {} + } { + lappend result [s validate $xml] + } + s delete + set result +} {1 1 0 1 1 1 1 0 0 0} + +test schema-14.27 {base64} { + tdom::schema s + s define { + defelement doc { + text base64 + } + } + set result [list] + foreach xml { + + {ZVL1} + {zvL1} + {zvü1} + {0a BED E+9} + {ub1sU3==} + {abc} + {===} + } { + lappend result [s validate $xml] + } + s delete + set result +} {1 1 1 0 1 1 0 0} + +test schema-14.28 {element content id/idref} { + tdom::schema s + s define { + defelement doc { + interleave { + element id * + element idref * + element ida * + element idrefa * + } + } + defelement id {text id} + defelement idref {text idref} + defelement ida {text {id a}} + defelement idrefa {text {idref a}} + } + set result [list] + foreach xml { + + abcabc + abc + abcabc + 1abcabcfooabc + abcabcabcabc + abcabcabcabc + } { + lappend result [s validate $xml] + } + s delete + set result +} {1 1 0 0 0 1 1} + +test schema-14.29 {element content id/idref} { + tdom::schema s + s define { + defelement doc { + interleave { + element id * + element idref * + element ida * + element idrefa * + } + } + defelement id {text {id b}} + defelement idref {text {idref b}} + defelement ida {text {id a}} + defelement idrefa {text {idref a}} + } + set result [list] + foreach xml { + + abcabc + abc + abcabc + 1abcabcfooabc + abcabcabcabc + abcabcabcabc + } { + lappend result [s validate $xml] + } + s delete + set result +} {1 1 0 0 0 1 1} + +test schema-14.30 {text: boolean (xsd)} { + tdom::schema s + s defelement doc { + text boolean + } + set result [list] + foreach xml { + + + 5 + 00 + 01 + 1 + 11 + false + {false } + False + FALSE + true + { true} + TrUe + } { + lappend result [s validate $xml] + } + s delete + set result +} {0 0 0 0 0 1 0 1 0 0 0 1 0 0} + +test schema-14.30a {text: boolean (xsd)} { + tdom::schema s + s defelement doc { + text {boolean xsd} + } + set result [list] + foreach xml { + + + 5 + 00 + 01 + 1 + 11 + false + {false } + False + FALSE + true + { true} + TrUe + } { + lappend result [s validate $xml] + } + s delete + set result +} {0 0 0 0 0 1 0 1 0 0 0 1 0 0} + +test schema-14.31 {text: boolean (tcl)} { + tdom::schema s + s defelement doc { + text {boolean tcl} + } + set result [list] + foreach xml { + + + 5 + 0 + 01 + 1 + 11 + false + f + no + {no } + n + { n } + {false } + False + FALSE + true + { true} + TrUe + ON + } { + lappend result [s validate $xml] + } + s delete + set result +} {0 0 0 1 0 1 0 1 1 1 0 1 0 0 1 1 1 0 1 1} + +test schema-14.32 {text: negativeInteger} { + tdom::schema s + s defelement doc { + text negativeInteger + } + set result [list] + foreach xml { + + 5782 + 3 + +2 + +002 + 1 + 01 + +0 + +000 + 0 + -0 + -000 + -002 + -1 + -12345 + - + + + { } + { -23 } + } { + lappend result [s validate $xml] + } + s delete + set result +} {0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0} + +test schema-14.32.1 {text: negativeInteger tcl} { + tdom::schema s + s defelement doc { + text {negativeInteger tcl} + } + set result [list] + foreach xml { + + 5782 + 3 + +2 + +002 + 1 + 01 + +0 + +000 + 0 + -0 + -000 + -002 + -1 + -12345 + - + + + { } + { -23 } + } { + lappend result [s validate $xml] + } + s delete + set result +} {0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 1} + +test schema-14.33 {text: nonNegativeInteger} { + tdom::schema s + s defelement doc { + text nonNegativeInteger + } + set result [list] + foreach xml { + + 5782 + 3 + +2 + +002 + 1 + 01 + +0 + +000 + 0 + -0 + -000 + -002 + -1 + -12345 + - + + + { } + } { + lappend result [s validate $xml] + } + s delete + set result +} {0 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0} + +test schema-14.33.1 {text: nonNegativeInteger tcl} { + tdom::schema s + s defelement doc { + text {nonNegativeInteger tcl} + } + set result [list] + foreach xml { + + 5782 + 3 + +2 + +002 + 1 + 01 + +0 + +000 + 0 + -0 + -000 + -002 + -1 + -12345 + - + + + { } + } { + lappend result [s validate $xml] + } + s delete + set result +} {0 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0} + +test schema-14.34 {text: nonPositiveInteger} { + tdom::schema s + s defelement doc { + text nonPositiveInteger + } + set result [list] + foreach xml { + + 5782 + 3 + +2 + +002 + 1 + 01 + +0 + +000 + 0 + -0 + -000 + -002 + -1 + -12345 + - + + + { } + } { + lappend result [s validate $xml] + } + s delete + set result +} {0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 0 0 0} + +test schema-14.34.1 {text: nonPositiveInteger tcl} { + tdom::schema s + s defelement doc { + text {nonPositiveInteger tcl} + } + set result [list] + foreach xml { + + 5782 + 3 + +2 + +002 + 1 + 01 + +0 + +000 + 0 + -0 + -000 + -002 + -1 + -12345 + - + + + { } + } { + lappend result [s validate $xml] + } + s delete + set result +} {0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 0 0 0} + +test schema-14.35 {text: positiveInteger} { + tdom::schema s + s defelement doc { + text positiveInteger + } + set result [list] + foreach xml { + + 5782 + 3 + +2 + +002 + 1 + 01 + +0 + +000 + 0 + -0 + -000 + -002 + -1 + -12345 + - + + + { } + } { + lappend result [s validate $xml] + } + s delete + set result +} {0 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0} + +test schema-14.35.1 {text: positiveInteger tcl} { + tdom::schema s + s defelement doc { + text {positiveInteger tcl} + } + set result [list] + foreach xml { + + 5782 + 3 + +2 + +002 + 1 + 01 + +0 + +000 + 0 + -0 + -000 + -002 + -1 + -12345 + - + + + { } + } { + lappend result [s validate $xml] + } + s delete + set result +} {0 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0} + +test schema-14.36 {text: hexBinary} { + tdom::schema s + s defelement doc { + text {hexBinary} + } + set result [list] + foreach xml { + + 5782 + 3ABCDEF0 + +2 + 2 + abcd + abcde + abcdef + abcdefg + { a0123b} + {a0123b } + a0123b + } { + lappend result [s validate $xml] + } + s delete + set result +} {0 1 1 0 0 1 0 1 0 0 0 1} + +test schema-14.37 {text: unsignedByte} { + tdom::schema s + s defelement doc { + text {unsignedByte} + } + set result [list] + foreach xml { + + 7 + +255 + -255 + -000255 + 256 + 65535 + 000000000000000065535 + 65536 + 4294967295 + 00000000000000004294967295 + 4294967296 + 18446744073709551615 + 018446744073709551615 + 18446744073709551616 + 28446744073709551614 + 3ABCDEF0 + { a0123b} + {a0123b } + a0123b + 1.2 + } { + lappend result [s validate $xml] + } + s delete + set result +} {0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0} + +test schema-14.38 {text: unsignedShort} { + tdom::schema s + s defelement doc { + text {unsignedShort} + } + set result [list] + foreach xml { + + 7 + +255 + -255 + -000255 + 256 + 65535 + 000000000000000065535 + 65536 + 4294967295 + 00000000000000004294967295 + 4294967296 + 18446744073709551615 + 018446744073709551615 + 18446744073709551616 + 28446744073709551614 + 3ABCDEF0 + { a0123b} + {a0123b } + a0123b + 1.2 + } { + lappend result [s validate $xml] + } + s delete + set result +} {0 1 1 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0} + +test schema-14.39 {text: unsignedInt} { + tdom::schema s + s defelement doc { + text {unsignedInt} + } + set result [list] + foreach xml { + + 7 + +255 + -255 + -000255 + 256 + 65535 + 000000000000000065535 + 65536 + 4294967295 + 00000000000000004294967295 + 4294967296 + 18446744073709551615 + 018446744073709551615 + 18446744073709551616 + 28446744073709551614 + 3ABCDEF0 + { a0123b} + {a0123b } + a0123b + 1.2 + } { + lappend result [s validate $xml] + } + s delete + set result +} {0 1 1 0 0 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0} + +test schema-14.40 {text: unsignedLong} { + tdom::schema s + s defelement doc { + text {unsignedLong} + } + set result [list] + foreach xml { + + 7 + +255 + -255 + -000255 + 256 + 65535 + 000000000000000065535 + 65536 + 4294967295 + 00000000000000004294967295 + 4294967296 + 18446744073709551615 + 018446744073709551615 + 18446744073709551616 + 28446744073709551614 + 3ABCDEF0 + { a0123b} + {a0123b } + a0123b + 1.2 + } { + lappend result [s validate $xml] + } + s delete + set result +} {0 1 1 0 0 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0} + +test schema-14.41 {text constrains commands outside text constraint} {8.5} { + set cmds [info command tdom::schema::text::*] + set result {} + tdom::schema s + foreach cmd $cmds { + lappend result [catch {$cmd "some text"}] + lappend result [catch { + s define [subst "{$cmd}"] + } errMsg] + lappend result [catch { + s define [subst { + start doc + $cmd + }] + } errMsg] + lappend result [catch { + s define [subst { + start doc + defelement doc { + $cmd + } + }] + } errMsg] + } + if {$result eq [lrepeat [expr {[llength $cmds] * 4}] 1]} { + set result 1 + } else { + set result 0 + } + set result +} 1 + +test schema-14.43 {text constraint setvar} { + tdom::schema s + namespace eval ::schema-14.43 { } + s defelement doc { + text { + setvar from_schema-14.43 + setvar ::schema-14.43::foo + } + } + s validate "this" + s delete + list ${::schema-14.43::foo} ${from_schema-14.43} +} {this this} + +test schema-14.44 {text constraint setvar} { + tdom::schema s + namespace eval ::schema-14.43 { } + s defelement doc { + element a ! {text {setvar from_schema-14.44}} + element b ! {text {setvar from_schema-14.44}} + } + set result [s validate "ab"] + s delete + lappend result ${from_schema-14.44} +} {1 b} + +test schema-14.45 {text constraint whitespace} { + tdom::schema s + s defelement doc { + text { + whitespace preserve { + oneOf { + fixed foo + allOf { + minLength 5 + integer + } + } + } + } + } + set result [list] + foreach xml { + + + foo + 12345 + 1234 + 1234a + } { + lappend result [s validate $xml] + } + s delete + set result +} {0 0 1 1 0 0} + +test schema-14.46 {text constraint whitespace} { + tdom::schema s + s defelement doc { + text { + whitespace replace { + fixed "foo bar" + } + } + } + set result [list] + foreach xml { + + + {foo bar} + {foo +bar} + {foo bar} + {foo bar} + } { + lappend result [s validate $xml] + } + s delete + set result +} {0 0 1 1 1 0} + +test schema-14.47 {text constraint whitespace} { + tdom::schema s + s defelement doc { + text { + whitespace collapse { + fixed "foo bar" + } + } + } + set result [list] + foreach xml { + + + {foo bar} + {foo +bar} + {foo bar} + {foo bar} + { foo bar } + { foo bar rr} + } { + lappend result [s validate $xml] + } + s delete + set result +} {0 0 1 1 1 1 1 0} + +test schema-14.48 {text constraint whitespace} { + tdom::schema s + s defelement doc { + text { + whitespace preserve { + fixed "foo[string repeat " " 300]bar" + } + } + } + set xmls { + + } + lappend xmls "foo[string repeat " " 300]bar" + set result [list] + foreach xml $xmls { + lappend result [s validate $xml] + } + s delete + set result +} {0 1} + +test schema-14.49 {text constraint whitespace} { + tdom::schema s + s defelement doc { + text { + whitespace collapse { + fixed "foo [string repeat "x" 1200]bar" + } + } + } + set xmls { + + } + lappend xmls "[string repeat " " 300]foo[string repeat " " 300][string repeat "x" 1200]bar[string repeat " " 300]" + set result [list] + foreach xml $xmls { + lappend result [s validate $xml] + } + s delete + set result +} {0 1} + +test schema-14.50 {text constraint whitespace} { + tdom::schema s + s defelement doc { + element b ! { + text { + whitespace replace { + fixed "foo[string repeat " " 400]bar" + } + } + } + } + set xml + append xml foo [string repeat " \t " 100] bar + append xml + set result [s validate $xml] + s delete + set result +} 1 + +test schema-14.51 {text constraint whitespace} { + tdom::schema s + s defelement doc { + element a ! { + text { + whitespace collapse { + fixed "foo [string repeat "x" 1200]bar" + } + } + } + element b ! { + text { + whitespace replace { + fixed "foo[string repeat " " 8000]bar" + } + } + } + } + set xml + append xml [string repeat " " 20] foo " " [string repeat x 1200] bar \ + [string repeat " " 8000] + append xml foo [string repeat " \t " 2000] bar + append xml + set result [s validate $xml] + s delete + set result +} 1 + +test schema-14.52 {text constraint whitespace} { + tdom::schema s + s defelement doc { + element a + { + text { + not { + fixed foo + fixed bar + } + } + } + } + set result "" + foreach xml { + foo + bar + grill + + grill + bar + } { + lappend result [s validate $xml] + } + s delete + set result +} {0 0 1 1 1 0} + +test schema-14.54 {text constraint dateTime} { + tdom::schema s + s define { + defelement doc { + text dateTime + } + } + set result "" + foreach xml { + + + foo + 1 + 2020-07-08T15:58:17 + 2020-07-08T15:20:00 + 2020-07-08T15:20:17.7 + 2020-07-08T15:58:17+02:00 + 2020-07-08T15:20:17.789 + 2020-07-08T15:20:17.7890 + 2020-07-08T15:20:17.0 + 2020-07-08T15:20:17. + 2020-07-08T15:20:17.+02:00 + 2020-07-08T15:20:17.Z + 2020-07-08T15:20:17+Z + 2020-07-08T00:20 + 2020-07-08T00:60:00 + 2020-07-08T24:00:00 + 2020-07-08T24:00:00.1 + 2020-07-08T24:01:00 + 2020-07-08T24:00:01 + 2020-12-2215:20:00 + 2020-12-22 + 2020-07-08T15:20:17.789+02:00 + 2020-07-08T15:20:17-02:00 + 2020-07-08T15:20:17-02:00.0 + 2020-07-08T15:20:17.0-02:00 + " 2020-07-08T15:20:17.0-02:00" + "2020-07-08T15:20:17.0-02:00 " + } { + lappend result [s validate $xml] + } + s delete + set result +} {0 0 0 0 1 1 1 1 1 1 1 0 0 0 0 0 0 1 0 0 0 0 0 1 1 0 1 0 0} + +test schema-14.55 {text constraint time} { + tdom::schema s + s define { + defelement doc { + text time + } + } + set result "" + foreach xml { + + + foo + 1 + 15:58:17 + 15:20:00 + 15:20:17.7 + 15:58:17+02:00 + 15:20:17.789 + 15:20:17.7890 + 15:20:17.0 + 15:20:17. + 15:20:17.+02:00 + 15:20:17.Z + 15:20:17+Z + 00:20 + 00:60:00 + 24:00:00 + 24:00:00.1 + 24:01:00 + 24:00:01 + 15:20:17.789+02:00 + 15:20:17-02:00 + 15:20:17-02:00.0 + 15:20:17.0-02:00 + " 15:20:17.0-02:00" + "T15:20:17.0-02:00 " + } { + lappend result [s validate $xml] + } + s delete + set result +} {0 0 0 0 1 1 1 1 1 1 1 0 0 0 0 0 0 1 0 0 0 1 1 0 1 0 0} + +test schema-14.56 {length} { + tdom::schema s + s defelement doc { + element e ! { + text {length 2} + } + } + set result [list] + foreach xml { + + + {1} + {12} + { } + {123} + {1ሴ} + } { + lappend result [s validate $xml] + set rc [catch {dom parse -validateCmd s $xml doc}] + if {$rc == 0} { + $doc delete + } + lappend result $rc + } + s delete + set result +} {0 1 0 1 0 1 1 0 1 0 0 1 1 0} + +test schema-14.57 {length} { + tdom::schema s + s defelement doc { + element e ! { + text {length 0} + } + } + set result [list] + foreach xml { + + + {1} + {12} + { } + } { + lappend result [s validate $xml] + } + s delete + set result +} {1 1 0 0 0} + +test schema-14.58 {text constraint command syntax} { + tdom::schema s + s deftexttype len2-4 { + minLength 2 + maxLength 4 + } + set result [catch {s defelement doc { + element e ! {text typs len2-4} + }}] + s delete + set result +} 1 + +test schema-14.59 {Tcl error in text constraint script} { + tdom::schema s + s defelement doc { + element a + } + set result [catch { + s defelement a { + text {error "triggered"} + } + }] + s delete + set result +} 1 + +test schema-14.60 {Empty element} { + tdom::schema s + s defelement doc { + element a + } + s defelement a { + attribute att ? + } + ::xml::parser p -validateCmd s + set result [list] + foreach xml { + + + { } + { } + { } + { } + } { + lappend result [s validate $xml] + lappend result [catch {p parse $xml}] + set doc "" + lappend result [catch {set doc [dom parse -validateCmd s $xml]}] + if {$doc ne ""} { + $doc delete + } + } + s delete + p delete + set result +} {0 1 1 1 0 0 1 0 0 1 0 0 1 0 0 0 1 1} + +test schema-14.61 {Empty element} { + tdom::schema s + s defelement doc { + element a + } + s defelement a { + attribute att ? + text + } + ::xml::parser p -validateCmd s + set result [list] + foreach xml { + + + { } + { } + { } + { } + } { + lappend result [s validate $xml] + lappend result [catch {p parse $xml}] + set doc "" + lappend result [catch {set doc [dom parse -validateCmd s $xml]}] + if {$doc ne ""} { + $doc delete + } + } + s delete + p delete + set result +} {0 1 1 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0} + +test schema-14.62 {Empty element} { + tdom::schema s + s defelement doc { + element a + } + ::xml::parser p -validateCmd s + set result [list] + foreach xml { + + + { } + { } + { } + { } + } { + lappend result [s validate $xml] + lappend result [catch {p parse $xml}] + set doc "" + lappend result [catch {set doc [dom parse -validateCmd s $xml]}] + if {$doc ne ""} { + $doc delete + } + } + s delete + p delete + set result +} {0 1 1 1 0 0 1 0 0 1 0 0 0 1 1 0 1 1} + +test schema-15.1 {constraint cmd tcl} { + tdom::schema s + s define { + defelement a { + tcl append ::schema-15.1 [self] + element b + tcl append ::schema-15.1 [self] + } + } + set ::schema-15.1 "" + set result [s validate {} msg] + s delete + lappend result $msg ${::schema-15.1} + set result +} {1 {} ss} + +proc schema-15.2-astart {args} { + append ::schema-15.2 astart +} + +proc schema-15.2-aend {args} { + append ::schema-15.2 aend +} + +test schema-15.2 {constraint cmd tcl} { + tdom::schema s + s define { + defelement doc { + element a * + } + defelement a { + tcl schema-15.2-astart + element b ! text + element c ! text + tcl schema-15.2-aend + } + } + set schema-15.2 "" + set result [s validate {foobar} msg] + s delete + lappend result $msg ${schema-15.2} + set result +} {1 {} astartaendastartaend} + +proc schema-15.3 {type cmd} { + lappend ::schema-15.3 $type [$cmd info stack top] +} + +test schema-15.3 {constraint cmd tcl} {8.5} { + tdom::schema s + s define { + defelement doc { + element a * + } + defelement a { + tcl schema-15.3 astart [self] + element b ! text + element c ! text + tcl schema-15.3 aend [self] + } + } + set schema-15.3 "" + set result [s validate {foobar} msg] + s delete + lappend result $msg {*}${schema-15.3} + set result +} {1 {} astart a aend a astart a aend a} + +proc schema-15.4 {text cmd} { + if {$text ne "in docContent"} {error "unexpected text argument"} + set ::schema-15.4 [$cmd info stack inside] +} +test schema-15.4 {constraint cmd tcl} { + tdom::schema s + s define { + defelement doc { + ref docContent + } + defpattern docContent { + element a + tcl schema-15.4 "in docContent" [self] + text + element b + } + } + set schema-15.4 "" + set result [s validate {foo}] + s delete + lappend result [set schema-15.4] + set result +} {1 doc} + +test schema-16.1 {interleave} { + tdom::schema s + s define { + defelement doc { + interleave { + element a + element b + element c + } + } + foreach e {a b c} { + defelement $e {} + } + } + set result [list] + foreach xml { + + + + + + + 12 + } { + lappend result [s validate $xml] + } + s delete + set result +} {0 1 1 1 0 0 0} + +# It's in fact a missing feature: handling ambiguity. +# test schema-16.2 {interleave} {knownBug} { +# tdom::schema s +# s define { +# defelement doc { +# interleave { +# element a 1 { +# attribute type {fixed foo} +# } +# element a 1 { +# attribute type {fixed bar} +# } +# element a 1 { +# attribute type {fixed grill} +# } +# } +# } +# foreach e {a b c} { +# defelement $e {} +# } +# } +# set result [list] +# foreach xml { +# +# {} +# {} +# {} +# {} +# {} +# 12 +# } { +# lappend result [s validate $xml] +# } +# s delete +# set result +# } {0 1 1 1 0 0} + +test schema-16.3 {interleave} { + tdom::schema s + s define { + defelement doc { + interleave { + element a + element b + + element c + } + } + foreach e {a b c} { + defelement $e {} + } + } + set result [list] + foreach xml { + + + + + + + 12 + } { + lappend result [s validate $xml] + } + s delete + set result +} {0 1 1 1 1 0 0} + +test schema-16.4 {interleave} { + tdom::schema s + s define { + defelement doc { + interleave { + element a + element b ? + element c + } + } + foreach e {a b c} { + defelement $e {} + } + } + set result [list] + foreach xml { + + + + + + + 12 + } { + lappend result [s validate $xml] + } + s delete + set result +} {0 1 1 1 0 1 0} + +test schema-16.5 {interleave} { + tdom::schema s + s define { + defelement doc { + interleave { + element a + element b * + element c + } + } + foreach e {a b c} { + defelement $e {} + } + } + set result [list] + foreach xml { + + + + + + + 12 + } { + lappend result [s validate $xml] + } + s delete + set result +} {0 1 1 1 1 1 0} + +test schema-16.6 {interleave} { + tdom::schema s + s define { + foreach e {a b1 b2 c} { + defelement $e {} + } + defelement doc { + interleave { + element a + group * { + element b1 + element b2 + } + element c + } + } + } + set result [list] + foreach xml { + + + + + + + + 12 + } { + lappend result [s validate $xml] + } + s delete + set result +} {0 1 1 1 0 1 1 0} + +test schema-16.7 {interleave} { + tdom::schema s + s define { + foreach e {a b1 b2 c} { + defelement $e {} + } + defelement doc { + interleave { + element a + group { + element b1 + element b2 + } + element c + } + } + } + set result [list] + foreach xml { + + + + + + + + 12 + } { + lappend result [s validate $xml] + } + s delete + set result +} {0 1 1 1 0 0 0 0} + +test schema-16.8 {interleave} { + tdom::schema s + s define { + foreach e {a b1 b2 c} { + defelement $e {} + } + defelement doc { + interleave { + element a + group ? { + element b1 + element b2 + } + element c + } + } + } + set result [list] + foreach xml { + + + + + + + + 12 + } { + lappend result [s validate $xml] + } + s delete + set result +} {0 1 1 1 0 0 1 0} + +test schema-16.9 {interleave} { + tdom::schema s + s define { + foreach e {a b1 b2 c} { + defelement $e {} + } + defelement doc { + interleave { + element a + group + { + element b1 + element b2 + } + element c + } + } + } + set result [list] + foreach xml { + + + + + + + + 12 + } { + lappend result [s validate $xml] + } + s delete + set result +} {0 1 1 1 0 1 0 0} + +test schema-16.10 {interleave} { + tdom::schema s + s define { + foreach e {a b1 b2 c} { + defelement $e {} + } + defelement doc { + interleave { + element a + group ? { + element b1 + element b2 + } + element c + } + } + } + set result [list] + foreach xml { + + + + + + + + 12 + } { + lappend result [s validate $xml] + } + s delete + set result +} {0 1 1 1 0 0 1 0} + +test schema-16.11 {interleave} { + tdom::schema s + s define { + foreach e {a b1 b2 c} { + defelement $e {} + } + defelement doc { + interleave { + element a + choice { + element b1 + element b2 + } + element c + } + } + } + set result [list] + foreach xml { + + + + + + + + 12 + } { + lappend result [s validate $xml] + } + s delete + set result +} {0 1 1 1 0 0 0 0} + +test schema-16.12 {interleave} { + tdom::schema s + s define { + foreach e {a b1 b2 c} { + defelement $e {} + } + defelement doc { + interleave { + element a + choice ? { + element b1 + element b2 + } + element c + } + } + } + set result [list] + foreach xml { + + + + + + + + 12 + } { + lappend result [s validate $xml] + } + s delete + set result +} {0 1 1 1 0 0 1 0} + +test schema-16.13 {interleave} { + tdom::schema s + s define { + foreach e {a b1 b2 c} { + defelement $e {} + } + defelement doc { + interleave { + element a + choice + { + element b1 + element b2 + } + element c + } + } + } + set result [list] + foreach xml { + + + + + + + + 12 + } { + lappend result [s validate $xml] + } + s delete + set result +} {0 1 1 1 1 1 0 0} + +test schema-16.14 {interleave} { + tdom::schema s + s define { + foreach e {a b1 b2 c} { + defelement $e {} + } + defelement doc { + interleave { + element a + choice * { + element b1 + element b2 + } + element c + } + } + } + set result [list] + foreach xml { + + + + + + + + 12 + } { + lappend result [s validate $xml] + } + s delete + set result +} {0 1 1 1 1 1 1 0} + +test schema-16.15 {interleave} { + tdom::schema s + s define { + foreach e {a b1 b11 b2 c} { + defelement $e {} + } + defelement doc { + interleave { + element a + choice * { + element b1 + group { + element b11 + element b2 + } + } + element c + } + } + } + set result [list] + foreach xml { + + + + + + + + 12 + } { + lappend result [s validate $xml] + } + s delete + set result +} {0 1 0 1 0 1 1 0} + + +test schema-16.16 {interleave} { + tdom::schema s + s define { + foreach e {a b1 b11 b2 c} { + defelement $e {} + } + defelement items { + interleave { + element a + element b ? + } + element c + } + defelement doc { + element items + + } + } + set result [list] + foreach xml { + {} + {} + {} + } { + lappend result [s validate $xml errMsg] + } + s delete + set result +} {1 1 0} + +test schema-16.17 {interleave with all child cp optional} { + tdom::schema s + s defelement doc { + interleave { + element a ? + element b ? + element c ? + } + element d + } + set result [list] + foreach xml { + + + + + + + + + + + } { + lappend result [s validate $xml] + } + s delete + set result +} {0 1 1 1 1 1 1 1 0 1} + +test schema-16.18 {interleave with all content cp optional} { + tdom::schema s + s defelement doc { + interleave { + element a ? + element b ? + choice { + element c ? + element c1 ? + element c2 ? + } + } + } + set result [list] + foreach xml { + + + + + + + + + + + + } { + lappend result [s validate $xml] + } + s delete + set result +} {1 1 1 1 1 1 1 0 1 1 0} + +test schema-16.19 {interleave with all child cp optional} { + tdom::schema s + s defelement doc { + interleave { + element a ? + element b ? + choice { + element c ? + element c1 ? + element c2 ? + } + } + element d + } + set result [list] + foreach xml { + + + + + + + + + + + } { + lappend result [s validate $xml] + } + s delete + set result +} {0 1 1 1 1 1 1 1 0 1} + +test schema-16.20 {interleave with all child cp optional} { + tdom::schema s + s defelement doc { + interleave { + element a ? + element b ? + group { + element c ? + element c1 ? + element c2 ? + } + } + element d + } + set result [list] + foreach xml { + + + + + + + + + + + } { + lappend result [s validate $xml] + } + s delete + set result +} {0 1 1 1 1 1 1 1 0 1} + +test schema-16.21 {interleave with all child cp optional} { + tdom::schema s + s defelement doc { + interleave { + element a ? + element b ? + group { + element c ? + element c1 ? + element c2 ? + } + } + } + set result [list] + foreach xml { + + + + + + + + + + + + + + + + } { + lappend result [s validate $xml] + } + s delete + set result +} {1 1 1 1 1 1 1 0 1 1 0 1 0 1 0} + +test schema-16.22 {interleave} { + tdom::schema s + s defelement doc { + interleave { + element a + element b * + } + } + set result [list] + foreach xml { + + + + + + + + + } { + lappend result [s validate $xml] + } + s delete + set result +} {0 1 0 1 1 1 1 0} + +test schema-17.1 {info} { + tdom::schema s + s define { + foreach e {a b1 b11 b2 c} { + defelement $e {} + } + } + set result [lsort [s info definedElements]] + s delete + set result +} {a b1 b11 b2 c} + +test schema-17.2 {info} { + tdom::schema s + s define { + defelement b { + element b1 + element b2 + } + defelement a { + element a1 + element a2 + } + } + set result [lsort [s info definedElements]] + s delete + set result +} {a b} + +test schema-17.3 {info} { + tdom::schema s + s define { + defelement b { + element b1 1 text + element a + element b2 + } + defelement a { + element a1 + element a2 + } + } + set result [lsort [s info definedElements]] + s delete + set result +} {a b} + +test schema-17.3a {info definedElements} { + tdom::schema s + s define { + prefixns {ns1 http://ns1.foo ns2 http://ns2.foo} + defelement b ns1 { + element b1 1 text + element a + element b2 + } + defelement b ns2 { + element b1 1 text + element a + element b2 + } + defelement b { + element b1 1 text + element a + element b2 + } + defelement a { + element a1 + element a2 + } + } + set result [lsort -command sortcps [s info definedElements]] + s delete + set result +} {a b {b http://ns1.foo} {b http://ns2.foo}} + +test schema-17.4 {info} { + tdom::schema s + s define { + defelement b { + element b1 1 text + element a + element b2 + } + defelement a { + element a1 + element a2 + } + } + set result [s info definition b] + s delete + set result +} {defelement b { + element b1 1 text + element a + element b2 + }} + +test schema-17.5 {info expected} { + tdom::schema s + s define { + defelement doc { + choice ? { + element a + element c + element b + } + element toplevel ? + element musthave + element aftermust + } + } + s event start doc + set result [s info expected] + s delete + lsort $result +} {a b c musthave toplevel} + +test schema-17.5a {info expected -ignorematched} { + tdom::schema s + s define { + defelement doc { + choice ? { + element a + element c + element b + } + element toplevel ? + element musthave + element aftermust + } + } + s event start doc + set result [s info expected -ignorematched] + s delete + lsort $result +} {a b c musthave toplevel} + +test schema-17.5b {info expected} { + tdom::schema s + s define { + defelement doc { + choice ? { + element a + element c + element b + } + element toplevel ? + element musthave + element aftermust + } + } + s event start doc + set result [s info expected -onlymandatory] + s delete + lsort $result +} {musthave} + +test schema-17.6 {info expected} { + tdom::schema s + s prefixns {foo http://foo.bar} + s define { + defelement doc { + choice ? { + element a + element c + element b + } + element toplevel ? + namespace foo { + element musthave + } + element aftermust + } + } + s event start doc + set result [s info expected] + s delete + lsort $result +} {a b c {musthave http://foo.bar} toplevel} + +test schema-17.6a {info expected -ignorematched} { + tdom::schema s + s prefixns {foo http://foo.bar} + s define { + defelement doc { + choice ? { + element a + element c + element b + } + element toplevel ? + namespace foo { + element musthave + } + element aftermust + } + } + s event start doc + set result [s info expected -ignorematched] + s delete + lsort $result +} {a b c {musthave http://foo.bar} toplevel} + +test schema-17.6b {info expected -onlymandatory} { + tdom::schema s + s prefixns {foo http://foo.bar} + s define { + defelement doc { + choice ? { + element a + element c + element b + } + element toplevel ? + namespace foo { + element musthave + } + element aftermust + } + } + s event start doc + set result [s info expected -onlymandatory] + s delete + lsort $result +} {{musthave http://foo.bar}} + +test schema-17.7 {info expected} {listformat} { + tdom::schema s + s prefixns {foo http://foo.bar} + s define { + defelement doc { + mixed { + element a + element c + element b + } + element toplevel ? + namespace foo { + element musthave + } + element aftermust + } + } + s event start doc + set result [s info expected] + s delete + lsort $result +} {a b c {musthave http://foo.bar} toplevel {{#text} {}}} + +test schema-17.7a {info expected -ignorematched} {listformat} { + tdom::schema s + s prefixns {foo http://foo.bar} + s define { + defelement doc { + mixed { + element a + element c + element b + } + element toplevel ? + namespace foo { + element musthave + } + element aftermust + } + } + s event start doc + set result [s info expected -ignorematched] + s delete + lsort $result +} {a b c {musthave http://foo.bar} toplevel {{#text} {}}} + +test schema-17.7b {info expected -onlymandatory} { + tdom::schema s + s prefixns {foo http://foo.bar} + s define { + defelement doc { + mixed { + element a + element c + element b + } + element toplevel ? + namespace foo { + element musthave + } + element aftermust + } + } + s event start doc + set result [s info expected -onlymandatory] + s delete + lsort $result +} {{musthave http://foo.bar}} + +test schema-17.8 {info expected} {8.5} { + tdom::schema s + s defelement doc { + choice ? { + element a + element c + element b + } + element toplevel ? + element musthave + element aftermust + } + set result [s info expected] + s define { + foreach elm {a b c} { + defelement $elm {} + } + } + lappend result {*}[lsort [s info expected]] + s event start doc + lappend result {*}[lsort [s info expected]] + s event start c + s event end + lappend result {*}[lsort [s info expected]] + s delete + set result +} {doc a b c doc a b c musthave toplevel musthave toplevel} + +test schema-17.8a {info expected -ignorematched} {8.5} { + tdom::schema s + s defelement doc { + choice ? { + element a + element c + element b + } + element toplevel ? + element musthave + element aftermust + } + set result [s info expected -ignorematched] + s define { + foreach elm {a b c} { + defelement $elm {} + } + } + lappend result {*}[lsort [s info expected -ignorematched]] + s event start doc + lappend result {*}[lsort [s info expected -ignorematched]] + s event start c + s event end + lappend result {*}[lsort [s info expected -ignorematched]] + s delete + set result +} {doc a b c doc a b c musthave toplevel musthave toplevel} + +test schema-17.8b {info expected -onlymandatory} {8.5} { + tdom::schema s + s defelement doc { + choice ? { + element a + element c + element b + } + element toplevel ? + element musthave + element aftermust + } + set result [s info expected -ignorematched] + s define { + foreach elm {a b c} { + defelement $elm {} + } + } + lappend result {*}[lsort [s info expected -onlymandatory]] + s event start doc + lappend result {*}[lsort [s info expected -onlymandatory]] + s event start c + s event end + lappend result {*}[lsort [s info expected -onlymandatory]] + s delete + set result +} {doc a b c doc musthave musthave} + +proc schema-17.9 {scmd} { + global result + foreach e [lsort [$scmd info expected]] { + lappend result $e + } +} +test schema-17.9 {info expected from scripted constrain} { + tdom::schema s + s define { + defpattern some { + element a ? + group ? { + element b ? + tcl schema-17.9 [self] + } + element c + } + defelement doc { + ref some ? + element may ? + element must + } + } + set result "" + lappend result [s validate {}] + s delete + set result +} {a b c may must 1} + +test schema-17.9.1 {info expected from scripted constrain} { + tdom::schema s + s define { + defpattern some { + element a ? + group ? { + element b ? + tcl schema-17.9 [self] + } + element c + } + defelement doc { + element othermay ? + ref some ? + element may ? + element must + } + } + set result "" + lappend result [s validate {}] + s delete + set result +} {a b c may must othermay 1} + +proc schema-17.9a {scmd} { + global result + foreach e [lsort [$scmd info expected -onlymandatory]] { + lappend result $e + } +} +test schema-17.9a {info expected from scripted constrain} { + tdom::schema s + s define { + defpattern some { + element a ? + group ? { + element b ? + tcl schema-17.9a [self] + } + element c + } + defelement doc { + ref some ? + element may ? + element must + } + } + set result "" + lappend result [s validate {}] + s delete + set result +} {must 1} + +test schema-17.9a.1 {info expected from scripted constrain} { + tdom::schema s + s define { + defpattern some { + element a ? + group ? { + element b ? + tcl schema-17.9a [self] + } + choice ! { + element c1 + ref some ? + } + } + defelement doc { + ref some ? + element may ? + element must + } + } + set result "" + lappend result [s validate {}] + s delete + set result +} {must 1} + +test schema-17.10 {info expected interleave} {8.5} { + set defs { + { + interleave { + element a ? + element b + element c ? + } + element d + } + { + interleave { + element a ? + element b ? + element c ? + } + element d + } + { + interleave ? { + element a ? + element b + element c ? + } + element d + } + } + set result [list] + foreach def $defs { + tdom::schema s + s defelement doc $def + s event start doc + lappend result {*}[lsort [s info expected]] + s delete + } + set result +} {a b c a b c d a b c d} + +test schema-17.10a {info expected interleave} {8.5} { + set defs { + { + interleave { + element a ? + element b + element c ? + } + element d + } + { + interleave { + element a ? + element b ? + element c ? + } + element d + } + { + interleave ? { + element a ? + element b + element c ? + } + element d + } + } + set result [list] + foreach def $defs { + tdom::schema s + s defelement doc $def + s event start doc + lappend result {*}[lsort [s info expected -ignorematched]] + s delete + } + set result +} {a b c a b c d a b c d} + +test schema-17.11 {info expected} { + set defs { + { + group + { + element c ? + element a ? + element b ? + } + element d + } + } + set result [list] + foreach def $defs { + tdom::schema s + s defelement doc $def + s event start doc + s event start b + s event end + set result [lsort [s info expected]] + s delete + } + set result +} {a b c d} + +test schema-17.11a {info expected} { + set defs { + { + group + { + element c ? + element a ? + element b ? + } + element d + } + } + set result [list] + foreach def $defs { + tdom::schema s + s defelement doc $def + s event start doc + s event start b + s event end + set result [lsort [s info expected -ignorematched]] + s delete + } + set result +} {d} + +test schema-17.12 {info expected} {8.5} { + tdom::schema s + s define { + prefixns {ns1 http://foo.bar} + defelement doc { + element a + any + any ns1 ? + element b ? + } + } + s event start doc + s event start a + s event end + set result [lsort [s info expected]] + s event start something + s event end + lappend result {*}[lsort [s info expected]] + s delete + set result +} {{ {}} { http://foo.bar} { {}} b} + +test schema-17.12a {info expected} {8.5} { + tdom::schema s + s define { + prefixns {ns1 http://foo.bar} + defelement doc { + element a + any + any ns1 ? + element b ? + } + } + s event start doc + s event start a + s event end + set result [lsort [s info expected -ignorematched]] + s event start something + s event end + lappend result {*}[lsort [s info expected -ignorematched]] + s delete + set result +} {{ {}} { http://foo.bar} { {}} b} + +proc schema-17.13 {scmd args} { + global fromReportCmd + set fromReportCmd [lsort [$scmd info expected]] +} + +test schema-17.13 {info expected} {8.5} { + set defs { + { + element a + element b ? + } + { + element a ? + element b + } + { + element a ? + element b ? + } + } + set xmlinput { + + + + + + + } + set result [list] + set defnr 0 + foreach def $defs { + tdom::schema s + s defelement doc $def + s reportcmd schema-17.13 + set xmlnr 0 + foreach xml $xmlinput { + set fromReportCmd "" + lappend result $defnr/$xmlnr: [s validate $xml errMsg] + lappend result {*}$fromReportCmd + incr xmlnr + } + s delete + incr defnr + } + set result +} {0/0: 1 a 0/1: 1 0/2: 1 a 0/3: 1 0/4: 1 a 0/5: 1 { {}} b 1/0: 1 a b 1/1: 1 b 1/2: 1 1/3: 1 1/4: 1 a b 1/5: 1 b 2/0: 1 2/1: 1 2/2: 1 2/3: 1 2/4: 1 { {}} a b 2/5: 1 { {}} b} + +proc schema-17.13a {scmd args} { + global fromReportCmd + set fromReportCmd [lsort [$scmd info expected -ignorematched]] +} +test schema-17.13a {info expected} {8.5} { + set defs { + { + element a + element b ? + } + { + element a ? + element b + } + { + element a ? + element b ? + } + } + set xmlinput { + + + + + + + } + set result [list] + set defnr 0 + foreach def $defs { + tdom::schema s + s defelement doc $def + s reportcmd schema-17.13a + set xmlnr 0 + foreach xml $xmlinput { + set fromReportCmd "" + lappend result $defnr/$xmlnr: [s validate $xml errMsg] + lappend result {*}$fromReportCmd + incr xmlnr + } + s delete + incr defnr + } + set result +} {0/0: 1 a 0/1: 1 0/2: 1 a 0/3: 1 0/4: 1 a 0/5: 1 { {}} b 1/0: 1 a b 1/1: 1 b 1/2: 1 1/3: 1 1/4: 1 a b 1/5: 1 b 2/0: 1 2/1: 1 2/2: 1 2/3: 1 2/4: 1 { {}} a b 2/5: 1 { {}} b} + +proc schema-17.14 {scmd args} { + global result + foreach e [lsort [$scmd info expected]] { + lappend result $e + } +} +test schema-17.14 {info expected} { + set defs { + { + group + { + element c ? + element a ? + element b ? + } + tcl schema-17.14 [self] + element d + } + } + set result [list] + foreach def $defs { + tdom::schema s + s reportcmd schema-17.14 + s defelement doc $def + s event start doc + s event start unknownElement + s delete + } + set result +} {a b c d a b c d} + +proc schema-17.14a {scmd args} { + global result + foreach e [lsort [$scmd info expected -ignorematched]] { + lappend result $e + } +} +test schema-17.14a {info expected} { + set defs { + { + group + { + element c ? + element a ? + element b ? + } + tcl schema-17.14 [self] + element d + } + } + set result [list] + foreach def $defs { + tdom::schema s + s reportcmd schema-17.14 + s defelement doc $def + s event start doc + s event start unknownElement + s delete + } + set result +} {a b c d a b c d} + +proc schema-17.15 {type cmd} { + lappend ::result $type [$cmd info stack inside] +} + +test schema-17.15 {info inside} { + tdom::schema s + s define { + defelement doc { + element a * + } + defelement a { + tcl schema-17.15 astart [self] + element b ! text + element c ! text + tcl schema-17.15 aend [self] + } + } + set result {} + s validate {foobar} + s delete + set result +} {astart {a doc} aend {a doc} astart {a doc} aend {a doc}} + +test schema-17.16 {info expected} {8.5} { + tdom::schema s + s defelement doc { + element a + group { + group { + group { + element aaaa + element bbbb ? + } + element bbb ? + } + element bb ? + } + element b + } + set result [list] + foreach xml { + + + + } { + lappend result [s validate $xml] + } + s reportcmd schema-17.13 + foreach xml { + + + + } { + set fromReportCmd "" + lappend result [s validate $xml] + lappend result {*}$fromReportCmd + } + s delete + set result +} {0 0 1 1 aaaa 1 b bb bbb bbbb 1} + +test schema-17.16_1{info expected} {8.5} { + tdom::schema s + s defelement doc { + element a + group { + group { + group { + element aaaa + element bbbb ? + } + element bbb ? + } + element bb ? + } + element b + } + set result [list] + foreach xml { + + + + } { + lappend result [s validate $xml] + } + s reportcmd schema-17.13 + foreach xml { + + + + } { + set fromReportCmd "" + lappend result [s validate $xml] + lappend result {*}$fromReportCmd + } + s delete + set result +} {0 0 1 1 aaaa 1 b bb bbb bbbb 1} + +test schema-17.16a {info expected} {8.5} { + tdom::schema s + s defelement doc { + element a + group { + group { + group { + element aaaa * + element bbbb ? + } + element bbb ? + } + element bb ? + } + element b + } + set result [list] + foreach xml { + + + + } { + lappend result [s validate $xml] + } + s reportcmd schema-17.13a + foreach xml { + + + + } { + set fromReportCmd "" + lappend result [s validate $xml] + lappend result {*}$fromReportCmd + } + s delete + set result +} {0 0 1 1 aaaa b bb bbb bbbb 1 b bb bbb bbbb 1} + +test schema-17.16a_1 {info expected} {8.5} { + tdom::schema s + s defelement doc { + element a + group { + group { + group { + element aaaa * + element bbbb ? + } + element bbb ? + } + element bb ? + } + element b + } + set result [list] + foreach xml { + + + + } { + lappend result [s validate $xml] + } + s reportcmd schema-17.13a + foreach xml { + + + + } { + set fromReportCmd "" + lappend result [s validate $xml] + lappend result {*}$fromReportCmd + } + s delete + set result +} {0 0 1 1 aaaa b bb bbb bbbb 1 b bb bbb bbbb 1} + +test schema-17.16b {info expected} {8.5} { + tdom::schema s + s defelement doc { + element a + group { + group { + group { + element aaaa ? + element bbbb ? + } + element bbb ? + } + element bb ? + } + element b + } + set result [list] + foreach xml { + + + + } { + lappend result [s validate $xml] + } + s reportcmd schema-17.13 + foreach xml { + + + + } { + set fromReportCmd "" + lappend result [s validate $xml] + lappend result {*}$fromReportCmd + } + s delete + set result +} {0 0 1 1 aaaa b bb bbb bbbb 1 b bb bbb bbbb 1} + +test schema-17.16c {info expected} {8.5} { + tdom::schema s + s defelement doc { + element a + group { + group { + group { + element aaaa + + element bbbb ? + } + element bbb ? + } + element bb ? + } + element b + } + set result [list] + foreach xml { + + + + } { + lappend result [s validate $xml] + } + s reportcmd schema-17.13 + foreach xml { + + + + } { + set fromReportCmd "" + lappend result [s validate $xml] + lappend result {*}$fromReportCmd + } + s delete + set result +} {0 0 1 1 aaaa 1 aaaa b bb bbb bbbb 1} + +proc schema-17.17 {scmd args} { + global fromReportCmd + set fromReportCmd [list [$scmd info line] [$scmd info column]] +} +test schema-17.17 {info expected} {8.5} { + tdom::schema s + s defelement doc { + element a + group { + group { + group { + element aaaa + + element bbbb ? + } + element bbb ? + } + element bb ? + } + element b + } + set result [list] + foreach xml { + + + + } { + lappend result [s validate $xml] + } + s reportcmd schema-17.17 + foreach xml { + + + + } { + set fromReportCmd "" + lappend result [s validate $xml] + lappend result {*}$fromReportCmd + } + s delete + set result +} {0 0 1 1 1 9 1 1 16 1} + +test schema-17.18 {info typedefinition} { + tdom::schema s + s prefixns {ns http://my.foo} + s defelementtype a b ns { + elementtype a + elementtype a2 + } + set result [s info typedefinition a ns] + s delete + set result +} {defelementtype a b http://my.foo { + elementtype a + elementtype a2 + }} + +proc schema-17.19 {schemacmd} { + lappend ::result [$schemacmd info stack associated] +} +test schema-17.19 {info stack associated} { + tdom::schema s + s defelement doc { + element a + + } + s defelement a { + associate "fo bar baz" + tcl schema-17.19 [self] + } + set result [list] + foreach xml { + + + } { + lappend result [s validate $xml] + + } + s delete + set result +} {{fo bar baz} 1 {fo bar baz} {fo bar baz} 1} + +test schema-17.19a {info stack associated} { + tdom::schema s + s defelement doc { + element a + + } + s defelement a { + associate "fo bar baz" + tcl schema-17.19 [self] + element b + } + set result [list] + foreach xml { + + + } { + lappend result [s validate $xml] + + } + s delete + set result +} {{fo bar baz} 1 {fo bar baz} {fo bar baz} 1} + +proc schema-17.20 {schemacmd args} { + lappend ::result [$schemacmd info stack associated] +} +test schema-17.20 {info stack associated} { + tdom::schema s + s defelement doc { + element a + + } + s defelement a { + associate "fo bar baz" + # Only local defined + element b ? + } + s reportcmd schema-17.20 + set result [list] + foreach xml { + + + + + + } { + lappend result [s validate $xml] + } + s delete + set result +} {{} 1 1 1 {fo bar baz} 1 {} 1} + +proc schema-17.21 {scmd errorInfo} { + lappend ::result [$scmd info expected] +} +test schema-17.21 {info expected} { + tdom::schema s + s defelement doc { + element a + {} + element b ! {} + } + s reportcmd schema-17.21 + set result "" + lappend result [s validate {}] + s delete + set result +} {{a b} 1} + +proc schema-17.21a {scmd errorInfo} { + lappend ::result [$scmd info expected -ignorematched] +} +test schema-17.21a {info expected} { + tdom::schema s + s defelement doc { + element a + {} + element b ! {} + } + s reportcmd schema-17.21a + set result "" + lappend result [s validate {}] + s delete + set result +} {b 1} + +proc schema-17.22 {scmd errorInfo} { + global fromReportCmd + if {[$scmd info vaction] eq "MATCH_ELEMENT_START"} { + lappend fromReportCmd "matching [$scmd info vaction name]" "expecting [lsort [$scmd info expected]]" + if {$errorInfo eq "MISSING_ELEMENT"} { + return ignore + } + } else { + lappend fromReportCmd "END_EVENT expecting [$scmd info expected]" + } +} +test schema-17.22 {return "ignore" from recover script for MISSING_ELEMENT_MATCH_START} {8.5} { + set defs { + { + element a + element b + element c + } + } + set xmlinput { + + + + + + + + + + } + set result [list] + set defnr 0 + foreach def $defs { + tdom::schema s + s defelement doc $def + s reportcmd schema-17.22 + set xmlnr 0 + foreach xml $xmlinput { + set fromReportCmd "" + lappend result $defnr/$xmlnr: [s validate $xml errMsg] + lappend result {*}$fromReportCmd + incr xmlnr + } + s delete + incr defnr + } + set result +} {0/0: 1 {END_EVENT expecting a} 0/1: 1 {END_EVENT expecting b} 0/2: 1 {matching b} {expecting a} {END_EVENT expecting c} 0/3: 1 {matching c} {expecting a} {matching c} {expecting b} 0/4: 1 {END_EVENT expecting c} 0/5: 1 {matching c} {expecting b} 0/6: 1 {matching b} {expecting a} 0/7: 1 {matching unknown} {expecting a} {matching unknown} {expecting b} {matching unknown} {expecting c} {matching unknown} {expecting { {}}} 0/8: 1 {matching unknown} {expecting b} {matching unknown} {expecting c} {matching unknown} {expecting { {}}}} + +proc schema-17.23 {scmd errorInfo} { + global fromReportCmd + if {[$scmd info vaction] eq "MATCH_ELEMENT_START"} { + lappend fromReportCmd "matching [$scmd info vaction name]" "expecting [lsort [$scmd info expected]]" + if {$errorInfo in {"MISSING_ELEMENT" "UNEXPECTED_ELEMENT"}} { + return vanish + } + } else { + lappend fromReportCmd "END_EVENT expecting [$scmd info expected]" + } +} +test schema-17.23 {return "vanish" from recover handler} {8.5} { + set def { + defelement doc { + element a + ref b + element d ? + } + defpattern b { + element b + ref c + } + defpattern c { + element c + + } + } + set xmlinput { + + + + + + + + + + + + + + + + + foocontentfoocontent + + } + set result [list] + tdom::schema s + s define $def + s reportcmd schema-17.23 + set xmlnr 0 + foreach xml $xmlinput { + set fromReportCmd "" + lappend result $xmlnr: [s validate $xml errMsg] + lappend result {*}$fromReportCmd + incr xmlnr + } + s delete + set result +} {0: 1 {END_EVENT expecting a} 1: 1 {END_EVENT expecting b} 2: 1 {matching b} {expecting a} {END_EVENT expecting a} 3: 1 {matching c} {expecting a} {END_EVENT expecting a} 4: 1 {END_EVENT expecting c} 5: 1 {matching c} {expecting b} {END_EVENT expecting b} 6: 1 {matching b} {expecting a} {matching c} {expecting a} {END_EVENT expecting a} 7: 1 {matching unknown} {expecting a} {END_EVENT expecting a} 8: 1 {matching unknown} {expecting b} {END_EVENT expecting b} 9: 1 {matching unknown} {expecting b} 10: 1 {matching unknown} {expecting b} 11: 1 {matching unknown} {expecting c} 12: 1 {matching unknown} {expecting c} 13: 1 {matching unknown} {expecting { {}} c d} 14: 1 {matching unknown} {expecting { {}} c d} 15: 1 {matching unknown} {expecting c} {matching unknown1} {expecting { {}} c d} {matching unknown2} {expecting { {}}} {matching unknown3} {expecting { {}}} 16: 1 {matching unknown} {expecting b} {matching unknown} {expecting c} 17: 1 {matching unknown1} {expecting c} {matching unknown2} {expecting c}} + +test schema-17.24 {info patterndefinition} { + tdom::schema s + set result "" + s defpattern foo {element bar; element baz} + lappend result [s info patterndefinition foo] + s defpattern foo someNamespace {element e1; element e2} + lappend result [s info patterndefinition foo someNamespace] + lappend result [catch {s info patterndefinition dontexists} errMsg] + lappend result $errMsg + lappend result [catch {s info patterndefinition foo wrongNamespace} errMsg] + lappend result $errMsg + s delete + set result +} {{defpattern foo {element bar; element baz}} {defpattern foo someNamespace {element e1; element e2}} 1 {Unknown pattern definition} 1 {Unknown pattern definition}} + + +test schema-17.25 {info definedPatterns} { + tdom::schema create grammar + grammar defpattern thisPattern { + element a + element b + } + grammar defpattern thatPattern someNamespace { + element c + element d + } + grammar defelement doc { + ref thisPattern + ref thatPattern ? + } + set result [lsort -index 0 [grammar info definedPatterns]] + grammar delete + set result +} {{thatPattern someNamespace} thisPattern} + +proc schema-17.26 {scmd errorInfo} { + global fromReportCmd + if {$errorInfo eq "MISSING_ELEMENT" && [$scmd info vaction] eq "MATCH_ELEMENT_END"} { + lappend fromReportCmd "END_EVENT [$scmd info vaction name]" "expecting [lsort [$scmd info expected]]" + return "ignore" + } else { + lappend fromReportCmd "[$scmd info vaction] expecting [$scmd info expected]" + } +} + +test schema-17.26 {return "ignore" from recover handler for element end event} {8.5} { + tdom::schema s + s define { + defelement doc { + element a + ref bpat + element d + } + defpattern bpat { + element b + ref c + } + defpattern c { + element c + + } + } + s reportcmd schema-17.26 + set result "" + set xmlnr 0 + foreach xml { + + + + + + + } { + set ::fromReportCmd "" + lappend result $xmlnr: [s validate $xml errMsg] + lappend result {*}$fromReportCmd + incr xmlnr + } + s delete + set result +} {0: 1 {END_EVENT doc} {expecting a} {END_EVENT doc} {expecting b} {END_EVENT doc} {expecting d} 1: 1 {END_EVENT doc} {expecting b} {END_EVENT doc} {expecting d} 2: 1 {END_EVENT doc} {expecting c} {END_EVENT doc} {expecting d} 3: 1 {MATCH_ELEMENT_START expecting c} 4: 1 5: 1} + +test schema-17.27 {return "ignore" from recover handler for element end event} {8.5} { + tdom::schema s + s define { + defelement doc { + element a + element b + element c + element d + } + } + s reportcmd schema-17.26 + set result "" + set xmlnr 0 + foreach xml { + + + + + + + } { + set ::fromReportCmd "" + lappend result $xmlnr: [s validate $xml errMsg] + lappend result {*}$fromReportCmd + incr xmlnr + } + s delete + set result +} {0: 1 {END_EVENT doc} {expecting a} {END_EVENT doc} {expecting b} {END_EVENT doc} {expecting c} {END_EVENT doc} {expecting d} 1: 1 {END_EVENT doc} {expecting b} {END_EVENT doc} {expecting c} {END_EVENT doc} {expecting d} 2: 1 {END_EVENT doc} {expecting c} {END_EVENT doc} {expecting d} 3: 1 {MATCH_ELEMENT_START expecting c} 4: 1 5: 1 {MATCH_ELEMENT_START expecting d}} + +proc schema-17.28 {userarg scmd errType} { + append ::result $userarg $scmd $errType +} + +test schema-17.28 {reportcmd with additional args} { + tdom::schema s + s defelement doc { + element a + } + s reportcmd "schema-17.28 foo" + set result "" + s validate }] + lappend result $rc + s delete + set result +} {s MISSING_TEXT 1} + +test schema-18.1a {reportcmd} { + tdom::schema s + s define { + defelement doc { + element e + text {minLength 1} + element e + } + } + s reportcmd schema-18 + set result "" + set rc [s validate {}] + lappend result $rc + s delete + set result +} {s MISSING_TEXT 1} + +test schema-18.2 {reportcmd} { + tdom::schema s + s define { + defelement doc { + element a + element b + element c + } + } + s reportcmd schema-18 + set result "" + set rc [s validate {}] + lappend result $rc + s delete + set result +} {s MISSING_ELEMENT 1} + +test schema-18.3 {reportcmd} { + tdom::schema s + s define { + defelement doc { + element a + } + } + s reportcmd schema-18 + set result "" + foreach xml { + + baz + bazgrill + + } { + set rc [s validate $xml] + lappend result $rc + } + s delete + set result +} {s UNKNOWN_ROOT_ELEMENT 1 s UNKNOWN_ROOT_ELEMENT 1 s UNKNOWN_ROOT_ELEMENT 1 s UNKNOWN_ROOT_ELEMENT 1} + +test schema-18.4 {reportcmd} { + tdom::schema s + s define { + defelement doc { + element items * { + element item * { + attribute ref {integer} + } + } + } + } + s reportcmd schema-18 + set result [list] + foreach xml { + {} + {} + } { + lappend result [s validate $xml] + } + s delete + set result +} {1 s INVALID_ATTRIBUTE_VALUE s INVALID_ATTRIBUTE_VALUE 1} + +test schema-18.5 {reportcmd} { + tdom::schema s + s define { + defelement doc { + element items * { + element item * { + text {minLength 2} + } + } + } + } + s reportcmd schema-18 + set result [list] + foreach xml { + {1} + {1} + {>12ab} + + } { + lappend result [s validate $xml] + } + s delete + set result +} {s INVALID_VALUE 1 s INVALID_VALUE s MISSING_TEXT 1 1} + +test schema-18.6 {reportcmd} { + tdom::schema s + s define { + defelement item { + text { + key lang + minLength 2 + } + } + defelement items { + keyspace lang { + element item + + } + } + defelement doc { + element items + + } + } + s reportcmd schema-18 + set result [list] + foreach xml { + {12ab} + {1212} + {1212abcd} + {1212abcd1212} + } { + lappend result [s validate $xml] + } + s delete + set result +} {1 s INVALID_VALUE 1 s INVALID_VALUE 1 s INVALID_VALUE s INVALID_VALUE 1} + +proc schema-18.7 {args} { + global result + lappend result "tclcallback" +} + +test schema-18.7 {reportcmd} { + tdom::schema s + s define { + defelement a {} + defelement b {} + defelement c {} + defelement items { + interleave { + element a + element b + } + tcl schema-18.7 + element c + } + defelement doc { + element items + + } + } + s reportcmd schema-18 + set result [list] + foreach xml { + {} + {} + {} + {} + } { + lappend result [s validate $xml] + } + s delete + set result +} {tclcallback 1 tclcallback tclcallback 1 tclcallback s MISSING_ELEMENT tclcallback 1 tclcallback s MISSING_ELEMENT tclcallback s MISSING_ELEMENT 1} + +test schema-18.8 {reportcmd} { + tdom::schema s + s define { + defelement a {} + defelement b {} + defelement c {} + defelement items { + element a + element b + element c + } + defelement doc { + element items + + } + } + s reportcmd schema-18 + set result [list] + foreach xml { + {} + } { + lappend result [s validate $xml] + } + s delete + set result +} {s MISSING_ELEMENT s MISSING_ELEMENT 1} + +test schema-18.9 {reportcmd} { + tdom::schema s + s define { + defelement a {} + defelement b {} + defelement c {} + defelement doc { + group + { + element a + element b + element c + } + } + } + s reportcmd schema-18 + set result [list] + foreach xml { + {} + } { + lappend result [s validate $xml] + } + s delete + set result +} {s MISSING_ELEMENT 1} + +test schema-18.10 {reportcmd} { + tdom::schema s + s define { + defelement a {} + defelement b {} + defelement c {} + defelement doc { + group + { + element a + element b + group + { + element c + } + } + } + } + s reportcmd schema-18 + set result [list] + foreach xml { + {} + } { + lappend result [s validate $xml] + } + s delete + set result +} {s MISSING_ELEMENT 1} + +test schema-18.11 {reportcmd} { + tdom::schema s + s define { + defelement a {} + defelement b {} + defelement c {} + defelement doc { + element a + element b + element c + } + } + s reportcmd schema-18 + set result [list] + foreach xml { + + + + + + + } { + lappend result [s validate $xml] + } + s delete + set result +} {1 s MISSING_ELEMENT 1 s MISSING_ELEMENT 1 s MISSING_ELEMENT 1 s MISSING_ELEMENT 1 s UNEXPECTED_ELEMENT 1} + +test schema-18.12 {non existing reportcmd cmd} { + tdom::schema s + s defelement doc { + element a + } + s reportcmd ::tdom::_dontExists_ + set result [catch {s validate } errMsg] + lappend result $errMsg + s delete + set result +} {1 {error "invalid command name "::tdom::_dontExists_"" at line 1 character 6}} + +proc 18-13 {scmd errType} { + global result + lappend result {reportcmd called} +} + +test schema-18.13 {reportcmd} { + tdom::schema s + s define { + defelement header { + group { + choice { + group { + element prevlocs + element latestloc ? + } + group { + element latestloc + element prevlocs ? + } + } + } + } + } + s reportcmd 18-13 + set result [list] + foreach xml { +
+
+
+
+
+ } { + lappend result [s validate $xml] + } + s delete + set result +} {{reportcmd called} 1 1 1 1 1} + +proc schema-18.14 {scmd errortype} { + lappend ::result $errortype + lappend ::result [$scmd info expected] + lappend ::result [$scmd info vaction] + lappend ::result [$scmd info vaction name] + lappend ::result [$scmd info vaction namespace] + lappend ::result [$scmd info vaction text] +} +test schema-18.14 {info vaction in reportcmd} {listformat} { + tdom::schema s + s reportcmd schema-18.14 + s define { + defelement doc { + element e + { + attribute attr1 { + fixed on + } + text { + minLength 4 + } + } + } + } + set result [list] + foreach xml { + + + 123 + {1234} + } { + lappend result [s validate $xml] + } + s delete + set result +} {MISSING_ELEMENT e MATCH_ELEMENT_END doc {} {} 1 MISSING_ELEMENT e MATCH_ELEMENT_START b {} {} 1 MISSING_ATTRIBUTE {{{#text} {}}} MATCH_ELEMENT_START attr1 {} {} INVALID_VALUE {{{#text} {}}} MATCH_TEXT e {} 123 1 INVALID_ATTRIBUTE_VALUE {{{#text} {}}} MATCH_ATTRIBUTE_TEXT attr1 {} off 1} + +test schema-18.15 {info vaction in reportcmd} { + tdom::schema s + s reportcmd schema-18.14 + s define { + defelement doc { + element e + { + attribute attr1 + attribute attr2 ? { + minLength 3 + } + } + } + } + set result [list] + foreach xml { + {} + {} + {} + } { + lappend result [s validate $xml] + } + s delete + set result +} {1 INVALID_ATTRIBUTE_VALUE {{ {}}} MATCH_ATTRIBUTE_TEXT attr2 {} a MISSING_ATTRIBUTE {{ {}}} MATCH_ELEMENT_START attr1 {} {} 1 UNKNOWN_ATTRIBUTE {{ {}}} MATCH_ELEMENT_START foo {} {} MISSING_ATTRIBUTE {{ {}}} MATCH_ELEMENT_START attr1 {} {} 1} + +proc appendtoresult {scmd errortype} { + lappend ::result $errortype +} +test schema-18.16 {unexpected text} { + set defs { + { + defelement doc { + ref r1 + } + defpattern r1 { + element e ? {} + } + } + { + defelement doc { + element e ? {} + } + } + } + set result [list] + foreach def $defs { + tdom::schema s + s reportcmd appendtoresult + s define $def + lappend result [s validate {unexpected text}] + s delete + } + set result +} {UNEXPECTED_TEXT 1 UNEXPECTED_TEXT 1} + +test schema-18.17 {unexpected text} { + tdom::schema s + s reportcmd appendtoresult + s define { + defelement doc { + ref r1 + element c ! {} + } + defpattern r1 { + element a ! {} + element b ! {} + } + } + set result [list] + foreach xml { + unexpected_text +
unexpected_text + unexpected_text + unexpected_text + } { + lappend result [s validate $xml] + } + s delete + set result +} {UNEXPECTED_TEXT MISSING_ELEMENT 1 UNEXPECTED_TEXT MISSING_ELEMENT 1 UNEXPECTED_TEXT MISSING_ELEMENT 1 UNEXPECTED_TEXT 1} + +proc schema-18.18 {scmd errortype} { + lappend ::result $errortype + lappend ::result [$scmd info expected] +} +test schema-18.18 {missing element at MATCH_ELEMENT_END} { + set defs { + { + defelement doc { + ref r1 + } + defpattern r1 { + element a ! {} + element b ! {} + } + } + { + defelement doc { + element a 1 {} + element b 1 {} + } + } + { + defelement doc { + element a0 ! {} + ref r1 + } + defpattern r1 { + element a ! {} + element b ! {} + } + } + { + defelement doc { + element a0 ! {} + ref r1 + element b0 ! {} + } + defpattern r1 { + element a ! {} + element b ! {} + } + } + } + set result [list] + foreach def $defs { + tdom::schema s + s reportcmd schema-18.18 + s define $def + lappend result [s validate {}] + s delete + } + set result +} {MISSING_ELEMENT a 1 MISSING_ELEMENT a 1 MISSING_ELEMENT a0 1 MISSING_ELEMENT a0 1} + +test schema-18.19 {unexpected text} { + tdom::schema s + s reportcmd appendtoresult + s define { + defelement doc { + ref r1 ? + element c ? {} + } + defpattern r1 { + element a ? {} + element b ? {} + } + } + set result [list] + foreach xml { + unexpected_text + unexpected_text + unexpected_text + unexpected_text + unexpected_text + unexpected_text + } { + lappend result [s validate $xml] + } + s delete + set result +} {UNEXPECTED_TEXT 1 UNEXPECTED_TEXT 1 UNEXPECTED_TEXT 1 UNEXPECTED_TEXT 1 UNEXPECTED_TEXT 1 UNEXPECTED_TEXT 1} + +test schema-18.20 {Missing element on element end} { + tdom::schema s + s reportcmd appendtoresult + s define { + defelement doc { + element a * { + element b ! {} + element c ! {} + } + } + } + set result [list] + foreach xml { + + + + unexpected_text + unexpected_text + + + unexpected + } { + lappend result [s validate $xml] + } + s delete + set result +} {1 1 MISSING_ELEMENT 1 UNEXPECTED_TEXT MISSING_ELEMENT 1 UNEXPECTED_TEXT MISSING_ELEMENT 1 MISSING_ELEMENT 1 MISSING_ELEMENT MISSING_ELEMENT 1 MISSING_ELEMENT UNEXPECTED_TEXT 1} + +test schema-18.21 {reportcmd argument handling} { + tdom::schema s + set result "" + lappend result [s reportcmd] + s reportcmd "" + lappend result [s reportcmd] + s reportcmd dummycallback + lappend result [s reportcmd] + s reportcmd "" + s reportcmd "" + lappend result [s reportcmd] + s reportcmd dummycallback + lappend result [s reportcmd] + s delete + set result +} {{} {} dummycallback {} dummycallback} + +proc schema-18.22 {that scmd errorType} { + lappend ::result $that $errorType +} +test schema-18.22 {reportcmd with arguments} { + tdom::schema s + s reportcmd "schema-18.22 this" + s defelement doc { + element a + element b + } + set result "" + lappend result [s validate {}] + s delete + set result +} {this MISSING_ELEMENT 1} + +proc validatedSAX {g xml {keepEmpties 1}} { + set args [list -validateCmd $g] + if {!$keepEmpties} { + lappend args -ignorewhitespace 1 + } + xml::parser p {*}$args + set rc [catch {p parse $xml} errMsg] + p delete + return $rc +} + +proc validatedDOM {g xml {keepEmpties 0}} { + set args [list -validateCmd $g] + if {$keepEmpties} { + lappend args -keepEmpties + } + set rc [catch { + set doc [dom parse {*}$args $xml] + } errMsg] + if {$doc ne ""} { + $doc delete + } + return $rc +} + +proc postValidation {g xml} { + set doc [dom parse $xml] + set rc [$g domvalidate $doc errMsg] + #puts "error : $errMsg" + $doc delete + return $rc +} + +test schema-19.1 {keyspace} { + tdom::schema s + s define { + defelement doc { + element items * { + keyspace ref { + element item * { + attribute ref ? { + key ref + } + } + } + } + } + } + set result [list] + foreach xml { + {} + {} + {} + {} + {} + {} + } { + lappend result [s validate $xml] + } + s delete + set result +} {1 0 1 1 1 0} + +test schema-19.2 {keyspace} { + tdom::schema s + s define { + defelement doc { + element items * { + keyspace ref { + element item * { + attribute ref ? { + key ref + } + } + } + } + } + } + s reportcmd schema-18 + set result [list] + foreach xml { + {} + {} + } { + lappend result [s validate $xml] + } + s delete + set result +} {s INVALID_ATTRIBUTE_VALUE s INVALID_ATTRIBUTE_VALUE 1 1} + +test schema-19.3 {keyspace} { + tdom::schema s + s define { + defelement doc { + element items * + } + defelement items { + keyspace my { + element item * + } + } + defelement item { + attribute id ? { + key my + } + attribute ref ? { + keyref my + } + } + } + s reportcmd schema-18 + set result [list] + foreach xml { + {} + {} + {} + {} + } { + lappend result [s validate $xml] + } + s delete + set result +} {1 1 s INVALID_KEYREF 1 s INVALID_KEYREF 1} + +proc log19.4 {msg} { + lappend ::result $msg +} +proc report19.4 {scmd errortype} { + lappend ::result $errortype +} +test schema-19.4 {keyspace w/ recover} { + tdom::schema s + s define { + defelement doc { + element m * { + tcl log19.4 "before a" + element a ? { + keyspace lang { + element a1 ? { + attribute lang ? {key lang} + } + } + keyspace lang { + element a2 ? {text {key lang}} + } + } + tcl log19.4 "before b" + element b ? { + keyspace lang { + element b1 ? { + attribute lang ? {key lang} + } + } + } + } + } + } + s reportcmd report19.4 + set result [list] + foreach xml { + {} + } { + lappend result [s validate $xml] + } + s delete + set result +} {{before a} UNEXPECTED_ELEMENT {before b} {before a} {before b} UNEXPECTED_ELEMENT 1} + +test schema-20.1 {domunique} { + set schema { + prefixns {ns1 http://tdom.org/test} + defelement doc { + domunique ${::schema-20.1} @ref + } + } + set result [list] + foreach ::schema-20.1 { + a + ./../a + /foo + a/b + {a | b} + a|b + (a|b) + {a/b/c | b/c/d | c/d/e} + .//a + //a + a/@ref + a/b/c + {a//b[1]/c} + (.//b|a)/c + ns1:a + a/.//b/c + {} + { } + " + " + } { + tdom::schema s + lappend result [catch {s define $schema} errMsg] + #puts $errMsg + s delete + } + set result +} {0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1} + +test schema-20.2 {domunique} { + tdom::schema s + s define { + defelement doc { + domunique item @ref + element item * { + attribute ref ? + } + } + } + set result [list] + foreach xml { + {} + {} + {} + {} + } { + lappend result [postValidation s $xml] + } + s delete + set result +} {1 0 1 0} + +test schema-20.2a {domunique} { + tdom::schema s + s define { + defelement doc { + domunique item @ref itemrefkey IGNORE_EMPTY_FIELD_SET + element item * { + attribute ref ? + } + } + } + set result [list] + foreach xml { + {} + {} + {} + {} + } { + lappend result [postValidation s $xml] + } + s delete + set result +} {1 0 1 1} + +test schema-20.2b {domunique} { + tdom::schema s + s define { + defelement doc { + domunique item @ref itemrefkey EMPTY_FIELD_SET_VALUE abc + element item * { + attribute ref ? + } + } + } + set result [list] + foreach xml { + {} + {} + {} + {} + } { + lappend result [postValidation s $xml] + } + s delete + set result +} {1 0 0 0} + +test schema-20.3 {domunique} { + tdom::schema s + s define { + defelement doc { + element items * { + element item * { + attribute ref ? + } + domunique item @ref + } + } + } + set result [list] + foreach xml { + {} + {} + {} + {} + {} + {} + } { + lappend result [postValidation s $xml] + } + s delete + set result +} {1 0 1 1 1 0} + +test schema-20.4 {domunique} { + tdom::schema s + s define { + defelement doc { + domunique item {@ref @id} + element item * { + attribute ref ? + attribute id ? + } + } + } + set result [list] + foreach xml { + {} + {} + {} + {} + {} + } { + lappend result [postValidation s $xml] + } + s delete + set result +} {1 0 1 0 1} + +test schema-20.5 {domunique} { + tdom::schema s + s define { + defelement doc { + domunique item ref + element item * { + element ref ! text + } + } + } + set result [list] + foreach xml { + {1foo} + {11} + } { + lappend result [postValidation s $xml] + } + s delete + set result +} {1 0} + +proc schema-20.6 {scmd errortype} { + lappend ::result $errortype \ + [$scmd info vaction name] \ + [$scmd info vaction text] \ + [[$scmd info domNode] nodeName] +} + +test schema-20.6 {domunique} { + tdom::schema s + s define { + defelement doc { + domunique item ref itemunique + element item * { + element ref ! text + } + } + } + s reportcmd schema-20.6 + set result [list] + foreach xml { + {1foo} + {foofoo} + } { + lappend result [postValidation s $xml] + } + s delete + set result +} {1 DOM_KEYCONSTRAINT itemunique foo doc 1} + +test schema-20.7 {domunique} { + tdom::schema s + set result [catch {s define { + defelement doc { + domunique item {} + element item * { + attribute ref ? + } + } + }}] + s delete + set result +} {1} + +test schema-21.1 {CONTENT_ARRAY_SIZE_INIT} { + tdom::schema s + s defelement doc { + for {set i 1} {$i <= 30} {incr i} { + element e ? + } + } + set result [list] + foreach xml [list \ + [string repeat 9] \ + [string repeat 27] \ + [string repeat 37]] { + lappend result [s validate $xml] + } + s delete + set result +} {1 1 1 0} + +test schema-22.1 {defelementtype} { + tdom::schema s + s defelementtype a_type a { + element e1 + } + s defelement doc { + elementtype a_type + } + set result [list] + foreach xml { + + + + } { + lappend result [s validate $xml] + } + s delete + set result +} {0 0 1} + +test schema-22.2 {defelementtype} { + tdom::schema s + s defelement doc { + elementtype a_type + } + s defelementtype a_type a { + element e1 + } + set result [list] + foreach xml { + + + + } { + lappend result [s validate $xml] + } + s delete + set result +} {0 0 1} + +test schema-22.3 {defelementtype} { + tdom::schema s + s defelement doc { + elementtype a + elementtype a2 + } + s defelementtype a a { + element e1 + } + s defelementtype a2 a { + element e2 + } + set result [list] + foreach xml { + + + + + + + } { + lappend result [s validate $xml] + } + s delete + set result +} {0 0 0 1 0 0} + +test schema-22.4 {defelementtype} { + tdom::schema s + catch {s defelement doc { + elementtype a + elementtype a2 + error "my" + }} + s defelement doc { + elementtype a + elementtype a2 + } + catch {s defelementtype a a { + element e1 + error my + }} + s defelementtype a a { + element e1 + } + catch {s defelementtype a2 a { + element e2 + error my + }} + s defelementtype a2 a { + element e2 + } + set result [list] + foreach xml { + + + + + + + } { + lappend result [s validate $xml] + } + s delete + set result +} {0 0 0 1 0 0} + +test schema-22.5 {defelementtype} { + tdom::schema s + s prefixns {ns http://my.foo} + s defelement doc ns { + elementtype a + elementtype a2 + } + s defelementtype a a ns { + element e1 + } + s defelementtype a2 a ns { + element e2 + } + set result [list] + foreach xml { + {} + {} + {} + {} + {} + {} + } { + lappend result [s validate $xml] + } + s delete + set result +} {0 0 0 1 0 0} + +test schema-22.6 {defelementtype} { + tdom::schema s + s prefixns {ns http://my.foo} + s defelement doc ns { + elementtype a + elementtype a2 + } + s defelementtype a a ns { + elementtype e1 + } + s defelementtype a2 a ns { + elementtype e2 + } + set result [lsort -index 0 [s info definedElementtypes]] + s delete + set result +} {{a http://my.foo} {a2 http://my.foo}} + +test schema-22.6 {info definedElementtypes} { + tdom::schema s + s prefixns {ns1 http://ns1.foo ns2 http://ns2.foo} + s defelementtype a a ns1 { + elementtype e1 + } + s defelementtype a a ns2 { + elementtype e2 + } + set result [lsort -command sortcps [s info definedElementtypes]] + s delete + set result +} {{a http://ns1.foo} {a http://ns2.foo}} + +test schema-22.7 {defelementtype} { + tdom::schema s + s defelement doc { + elementtype e1type + elementtype e2type * + } + foreach e {e1 e2} { + s defelementtype ${e}type $e {} + } + set result [list] + foreach xml { + + + + + + + + } { + lappend result [s validate $xml] + } + s delete + set result +} {0 1 1 1 1 0 0} + +test schema-22.8 {defelementtype} { + tdom::schema s + s defelementtype doctype doc { + elementtype e1type + elementtype e2type * + } + foreach e {e1 e2} { + s defelementtype ${e}type $e {} + } + set result [list] + foreach xml { + + + + + + + + } { + lappend result [s validate $xml] + } + s delete + set result +} {0 0 0 0 0 0 0} + +test schema-22.9 {defelementtype} { + tdom::schema s + s defelement doc { + elementtype e1type + elementtype e2type * + } + set result [list] + foreach xml { + + {} + + grill + + + + } { + lappend result [s validate $xml] + } + s delete + set result +} {0 0 0 0 0 0 0} + +test schema-23.1 {validatefile} { + tdom::schema s + s define { + set fd [open [file join [file dir [info script]] ../doc/tmml.schema] r] + eval [read $fd] + close $fd + } + set result [s validatefile [file join [file dir [info script]] ../doc/schema.xml]] + s delete + set result +} 1 + +test schema-24.1 {validatechannel} { + tdom::schema s + s define { + set fd [open [file join [file dir [info script]] ../doc/tmml.schema] r] + eval [read $fd] + close $fd + } + set fd [open [file join [file dir [info script]] ../doc/schema.xml] r] + set result [s validatechannel $fd] + close $fd + s delete + set result +} 1 + +test schema-25.1 {domxpathboolean} { + tdom::schema s + s define { + defelement doc { + element width ! text + element length ! text + element height ! text + domxpathboolean "width * length * height <= 20000" volumeconstraint + } + } + set result [list] + foreach xml { + 135 + 2000.0100.02.0 + 2000.0100.0-2 + 2.33.57.6 + 11foo + 112000-01-01 + + } { + lappend result [postValidation s $xml] + } + s delete + set result +} {1 0 1 1 0 0 0} + +test schema-25.2 {domxpathboolean} { + tdom::schema s + s prefixns { + this http://that.org + other http://this.org + } + + s define { + defelement doc this { + element width ! text + namespace other { + element length ! text + } + element height ! text + domxpathboolean "this:width * other:length * this:height <= 20000" volumeconstraint + } + } + set result [list] + foreach xml { + {135} + {2000.0100.02.0} + {2000.0100.0-2} + {2.33.57.6} + {11foo} + {112000-01-01} + {} + } { + lappend result [postValidation s $xml] + } + s delete + set result +} {1 0 1 1 0 0 0} + +proc schema-25.3 {scmd errortype} { + lappend ::result $errortype [$scmd info vaction name] +} +test schema-25.3 {domxpathboolean} { + tdom::schema s + s define { + defelement doc { + element width ! text + element length ! text + element height ! text + domxpathboolean "width * length * height <= 20000" volumeconstraint + } + } + s reportcmd schema-25.3 + set result [list] + foreach xml { + 135 + 2000.0100.02.0 + 2000.0100.0-2 + 2.33.57.6 + 11foo + 112000-01-01 + + } { + lappend result [postValidation s $xml] + } + s delete + set result +} {1 DOM_XPATH_BOOLEAN volumeconstraint 1 1 1 DOM_XPATH_BOOLEAN volumeconstraint 1 DOM_XPATH_BOOLEAN volumeconstraint 1 DOM_XPATH_BOOLEAN volumeconstraint 1} + +test schema-25.4 {domxpathboolean} { + tdom::schema s + s define { + defelement doc { + element width ! text + element length ! text + element height ! text + domxpathboolean "width * length * height <= 20000" volume + domunique width|length|height . unique + domxpathboolean "width < length and length < height" sequence + } + } + s reportcmd schema-25.3 + set result [list] + set nr 1 + foreach xml { + 135 + 2000.0100.02.0 + 2000.0100.0-2 + 2.33.57.6 + 11foo + 112000-01-01 + + } { + lappend result "Nr$nr:" + incr nr + lappend result [postValidation s $xml] + } + s delete + set result +} {Nr1: 1 Nr2: DOM_XPATH_BOOLEAN volume DOM_XPATH_BOOLEAN sequence 1 Nr3: DOM_XPATH_BOOLEAN sequence 1 Nr4: 1 Nr5: DOM_XPATH_BOOLEAN volume DOM_KEYCONSTRAINT unique DOM_XPATH_BOOLEAN sequence 1 Nr6: DOM_XPATH_BOOLEAN volume DOM_KEYCONSTRAINT unique DOM_XPATH_BOOLEAN sequence 1 Nr7: DOM_XPATH_BOOLEAN volume DOM_KEYCONSTRAINT unique DOM_XPATH_BOOLEAN sequence 1} + +test schema-25.5 {domxpathboolean - xpath argument invalid} { + tdom::schema s + set result [catch { + s defelement doc { + domxpathboolean "a + + b" + } + } errMsg] + lappend result $errMsg + s delete + set result +} {1 {Error in selector xpath: 'NodeTest: Expected "WCARDNAME" for 'a + + b' + +Parsed symbols: + 0 WCARDNAME 0 000000000 0 a + 1 PLUS 0 000000000 2 + 2 PLUS 0 000000000 4 + 3 WCARDNAME 0 000000000 6 b}} + +proc ::dom::xpathFunc::compare {ctxNode pos nodeListType nodeList args} { + if {[llength $args] != 4} { + error "XPath function date: Expected two arguments but got + [expr {[llength $args] / 2}]" + } + lassign $args arg1Typ arg1Value arg2Typ arg2Value + set arg1 [::dom::xpathFuncHelper::coerce2string $arg1Typ $arg1Value] + set arg2 [::dom::xpathFuncHelper::coerce2string $arg2Typ $arg2Value] + return [list number [string compare $arg1 $arg2]] +} + +proc schema-25.6 {scmd errorType} { + lappend ::result $errorType [$scmd info vaction name] +} +test schema-25.6 {domxpathboolean - scripted XPath function} {8.5} { + tdom::schema s + s reportcmd schema-25.6 + s define { + defelement doc { + element a ! { + text + domxpathboolean {compare('foo','bar') > 0} first + domxpathboolean {compare('foo','bar') < 0} second + } + } + } + set doc [dom parse {2020-07-30}] + set result "" + lappend result [s domvalidate $doc] + set result +} {DOM_XPATH_BOOLEAN second 1} + +proc schema-26.1 {scmd} { + lappend ::result "fromtcl: [[$scmd info domNode] nodeName]" +} + +test schema-26.1 {info domNode} { + tdom::schema s + s defelement doc { + tcl schema-26.1 [self] + element e ? + } + set result "" + lappend result [s info domNode] + foreach xml { + + + {unexpected text} + {unexpected text} + {unexpected text} + + } { + dom parse $xml doc + lappend result [s domvalidate $doc] + $doc delete + } + s delete + set result +} {{} {fromtcl: doc} 1 {fromtcl: doc} 1 {fromtcl: doc} 0 {fromtcl: doc} 0 {fromtcl: doc} 0 {fromtcl: doc} 0} + + +proc schema-26.2 {scmd errortype} { + lappend ::result $errortype [[$scmd info domNode] nodeName] +} +test schema-26.2 {info domNode} { + tdom::schema s + s defelement doc { + tcl schema-26.1 [self] + element e ? + } + s reportcmd schema-26.2 + set result "" + lappend result [s info domNode] + foreach xml { + + + {unexpected text} + {unexpected text} + {unexpected text} + + } { + dom parse $xml doc + lappend result [s domvalidate $doc] + $doc delete + } + s delete + set result +} {{} {fromtcl: doc} 1 {fromtcl: doc} 1 {fromtcl: doc} UNEXPECTED_TEXT doc {fromtcl: doc} 1 {fromtcl: doc} UNEXPECTED_TEXT doc {fromtcl: doc} 1 {fromtcl: doc} UNEXPECTED_TEXT doc {fromtcl: doc} UNEXPECTED_ELEMENT unknown 1 {fromtcl: doc} UNEXPECTED_ELEMENT unknown 1} + +proc schema-26.3 {scmd errortype} { + lappend ::result $errortype [$scmd info domNode] +} +test schema-26.3 {info domNode} { + tdom::schema s + s defelement doc { + tcl schema-26.3 [self] "fromTcl" + element e ? + } + s reportcmd schema-26.3 + set result "" + lappend result [s info domNode] + foreach xml { + + + {unexpected text} + {unexpected text} + {unexpected text} + + } { + lappend result [s validate $xml] + } + s delete + set result +} {{} fromTcl {} 1 fromTcl {} 1 fromTcl {} UNEXPECTED_TEXT {} fromTcl {} 1 fromTcl {} UNEXPECTED_TEXT {} fromTcl {} 1 fromTcl {} UNEXPECTED_TEXT {} fromTcl {} UNEXPECTED_ELEMENT {} 1 fromTcl {} UNEXPECTED_ELEMENT {} 1} + +proc schema-27.1 {args} { + lappend ::result [::tdom::type::time 23:24:45] +} + +test schema-27.1 {Called from evaluated code} { + tdom::schema s + s defelement doc { + tcl schema-27.1 + element e 1 + } + set result "" + lappend result [s validate ] + s delete + set result +} {1 1} + +test schema-27.2 {Called from evaluated code} { + tdom::schema s + s defelement doc { + text { + tcl schema-27.1 + } + } + set result "" + lappend result [s validate foo] + s delete + set result +} {1 1} + +test schema-27.3 {Called from recover script} { + tdom::schema s + s defelement doc { + element e 1 + } + s reportcmd schema-27.1 + set result "" + lappend result [s validate ] + s delete + set result +} {1 1} + +test schema-27.4 {Called as part of validation} { + tdom::schema s + s defelement doc { + tcl schema-27.1 + element e 1 + } + set result "" + lappend result [s validate ] + s delete + set result +} {1 1} + +test schema-27.5 {Called during schema script evaluation} { + tdom::schema s + set result "" + s defelement doc { + set ::result [::tdom::type::time 12:20:00] + element e 1 + } + s delete + set result +} 1 + + +test schema-27.6 {date outside schema context} { + set result {} + foreach txt { + "" + foo + 1 + 12 + 1234-12-31 + 1234-14-31 + 1234-12-00 + 1234-02-31 + 2000-02-29 + 2001-02-29 + 2004-02-29 + -2004-02-29 + 1900-02-29 + 1234-02-01 + 1234-08-10 + 1234-08-222 + " 1234-08-22" + "1234-08-22 " + 11234-08-22 + 0000-02-01 + 10000-08-22 + 10000-02-29 + 10000-02-29Z + 2012-03-07Z + "2012-03-07Z " + 2012-03-07a + 2012-03-07+ + 2012-03-07+00:00 + 2012-03-07-00:00 + 2012-03-07+02:00 + 2012-03-07+02:70 + 2012-03-07+12:30 + 2012-03-07+14:30 + 2012-03-07+14:00 + 2012-03-07-14:00 + 2012-03-07-14:01 + 2012-03-07-2:30 + 2012-03-07-02:30Z + "2012-03-07-02:30 " + 02027-02-01 + } { + lappend result [tdom::type::date $txt] + } + set result +} {0 0 0 0 1 0 0 0 1 0 1 1 0 1 1 0 0 0 1 0 1 1 1 1 0 0 0 1 1 1 0 1 0 1 1 0 0 0 0 0} + + +test schema-27.7 {dateTime outside schema context} { + set result "" + foreach txt { + "" + foo + 1 + 2020-07-08T15:58:17 + 2020-07-08T15:20:00 + 2020-07-08T15:20:17.7 + 2020-07-08T15:58:17+02:00 + 2020-07-08T15:20:17.789 + 2020-07-08T15:20:17.7890 + 2020-07-08T15:20:17.0 + 2020-07-08T15:20:17. + 2020-07-08T15:20:17.+02:00 + 2020-07-08T15:20:17.Z + 2020-07-08T15:20:17+Z + 2020-07-08T00:20 + 2020-07-08T00:60:00 + 2020-07-08T24:00:00 + 2020-07-08T24:00:00.1 + 2020-07-08T24:01:00 + 2020-07-08T24:00:01 + 2020-12-2215:20:00 + 2020-12-22 + 2020-07-08T15:20:17.789+02:00 + 2020-07-08T15:20:17-02:00 + 2020-07-08T15:20:17-02:00.0 + 2020-07-08T15:20:17.0-02:00 + " 2020-07-08T15:20:17.0-02:00" + "2020-07-08T15:20:17.0-02:00 " + } { + lappend result [tdom::type::dateTime $txt] + } + set result +} {0 0 0 1 1 1 1 1 1 1 0 0 0 0 0 0 1 0 0 0 0 0 1 1 0 1 0 0} + +test schema-27.8 {time outside schema context} { + set result "" + foreach txt { + "" + foo + 1 + 07:15:00 + 07:15:00.023 + 07:15:00+05:00 + 07:15:00Z + 00:00:00 + 24:00:00 + 7:15:00 + 07:15 + 07:15.4:23 + 12:60:12 + 12:61:12 + 12:71:12 + 24:31:12 + 25:31:12 + 55:31:12 + 12:31:60 + 12:31:61 + 12:31:77 + } { + lappend result [tdom::type::time $txt] + } + set result +} {0 0 0 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0} + +test schema-27.9 {duration outside schema context} { + set result "" + foreach txt { + "" + foo + 1 + P2Y6M5DT12H35M30S + P1DT2H + P20M + PT20M + P0Y20M0D + P0Y + -P60D + PT1M30.5S + P-20M + P20MT + P1YM5D + P15.5Y + P1D2H + 1Y2M + P2M1Y + P + PT15.S + PT.5S + } { + lappend result [tdom::type::duration $txt] + } + set result +} {0 0 0 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0} + +} DELETED tests/structure.test Index: tests/structure.test ================================================================== --- tests/structure.test +++ /dev/null @@ -1,857 +0,0 @@ -# Features covered: Structure validation -# -# Tested functionalities: -# structure-1.*: Basics, interface -# structure-2.*: Grammar definition ref -# structure-3.*: Grammar definition choice -# structure-4.*: Script level validation with event -# structure-5.*: dom parse -validateCmd -# structure-6.*: expat parser -validateCmd -# structure-7.*: Validation checks. -# structure-8.*: tdom::structure validate method -# -# Copyright (c) 2018 Rolf Ade. - -source [file join [file dir [info script]] loadtdom.tcl] - -test structure-1.1 {create} { - tdom::structure create grammar - grammar start doc - grammar delete -} {} - -test structure-1.2 {grammar cmd outside context} { - catch {tdom::structure::element} -} {1} - -test structure-1.3 {grammar cmd} { - tdom::structure create grammar - grammar defpattern somePattern { - element foo ! - } - grammar delete -} {} - -test structure-1.4 {grammar cmd} { - tdom::structure create grammar - grammar defpattern somePattern { - for {set i 0} {$i < 100} {incr i} { - element foo$i ! - } - } - grammar delete -} {} - -test structure-1.5 {grammar cmd} { - tdom::structure create grammar - grammar defelement doc { - element elm1 - element elm2 * - } - grammar defelement elm1 empty - grammar defelement elm2 empty - grammar delete -} {} - -test structure-1.6 {quants} { - tdom::structure create grammar - grammar defelement doc { - element elm1 - element elm2 * - element elm3 ! - element elm4 + - element elm5 ? - element elm6 1 - element elm7 5 - element elm8 12 - element elm9 {0 3} - element elm9 {1 12} - element elm10 "8 " - } - grammar delete -} {} - -test structure-1.7 {quants} { - tdom::structure create grammar - grammar defelement doc { - for {set i 0} {$i < 100} {incr i} { - element elm$i [list $i [expr {$i + 1}]] - } - } - grammar delete -} {} - -test structure-1.8 {Same element name in different Namespaces} { - tdom::structure create grammar - grammar defelement doc { - element elm1 - element elm2 - } - grammar defelement doc ns1 { - # Forward defined element inherits child namespace - element elm1 - element elm2 - } - grammar defelement doc ns2 { - # Forward defined element inherits child namespace - element elm1 - element elm2 - } - grammar defelement elm1 ns2 empty - grammar defelement elm2 ns2 any - set result [catch { - grammar defelement elm1 ns1 { - choice { - element fooElem - element barElem + - } - error - } - }] - grammar defelement elm1 ns1 any - grammar defelement elm2 ns1 empty - grammar delete - set result -} 1 - -test structure-1.9 {Same element name in different Namespaces} { - tdom::structure create grammar - set result [catch { - grammar defelement doc { - element elm1 - element elm2 - } - grammar defelement doc ns1 { - # Forward defined element inherits child namespace - element elm1 - element elm2 - } - grammar defelement doc ns2 { - # Forward defined element inherits child namespace - element elm1 - element elm2 - } - grammar defelement elm1 ns2 empty - grammar defelement elm2 ns2 any - grammar defelement elm1 ns1 { - choice { - element fooElem - element barElem + - } - error - } - }] - grammar delete - set result -} 1 - -test structure-1.10 {Local element definition} { - tdom::structure create grammar - grammar defelement doc { - element elm1 - element elm1 1 { - element a - element b - } - } - grammar defelement c text - grammar defelement d text - grammar defelement elm1 { - element c - element d - } - grammar delete -} {} - -test structure-1.11 {define} { - tdom::structure create grammar - set result [catch {grammar define { - element elm1 - }} errMsg] - grammar delete - lappend result $errMsg -} {1 {Command not allowed at top level in grammar define evaluation}} - -test structure-1.12 {define} { - tdom::structure create grammar - set result [catch {grammar define { - defelement elm1 { - element a - element b - } - element elm1 - }} errMsg] - grammar delete - lappend result $errMsg -} {1 {Command not allowed at top level in grammar define evaluation}} - -test structure-2.1 {grammar definition: ref} { - tdom::structure create grammar - grammar defpattern thisPattern { - element a - element b - } - grammar defpattern thatPattern { - element c - element d - } - grammar defelement doc { - ref thisPattern - ref thatPattern ? - } - grammar delete -} {} - -test structure-2.2 {grammar definition: ref} { - tdom::structure create grammar - set result [grammar nrForwardDefinitions] - grammar defelement doc { - ref thisPattern - ref thatPattern ? - } - lappend result [grammar nrForwardDefinitions] - grammar delete - set result -} {0 2} - -test structure-3.1 {grammar definition: choice} { - tdom::structure create grammar - grammar defelement doc { - element elm - choice { - element fooElem - element barElem + - } - choice ? { - element one {2 3} - element two - } - element three - } - grammar delete -} {} - -test structure-3.2 {grammar definition: choice} { - tdom::structure create grammar - grammar defpattern thisPattern { - element elm - choice { - element fooElem - element barElem + - } - choice ? { - element one {2 3} - element two - } - element three - } - grammar delete -} {} - -proc pullValidate {g xml} { - tdom::pullparser pp - pp input $xml - while {[pp next] ne "END_DOCUMENT"} { - switch [pp state] { - "START_TAG" { - $g event start [pp tag] - } - "END_TAG" { - $g event end - } - "TEXT" { - $g event text [pp text] - } - } - } -} - -test structure-4.1 {validation} { - tdom::structure create grammar - grammar defelement doc { - element e1 - element e2 * - } - foreach e {e1 e2} { - grammar defelement $e {} - } - pullValidate grammar { - - } - if {[grammar state] ne "FINISHED"} { - error "Wrong state." - } - grammar reset - pullValidate grammar { - - } - if {[grammar state] ne "FINISHED"} { - error "Wrong state." - } - grammar reset - pullValidate grammar { - - } - if {[grammar state] ne "FINISHED"} { - error "Wrong state." - } - grammar delete -} {} - -test structure-5.1 {dom parse -validateCmd} { - set result [catch { - [dom parse -validateCmd tdom::structure ] - }] -} 1 - -test structure-5.2 {dom parse -validateCmd} { - tdom::structure create grammar - grammar defelement doc { - element e1 - element e2 * - } - foreach e {e1 e2} { - grammar defelement $e {} - } - dom parse -validateCmd grammar { - - } doc - if {[grammar state] ne "FINISHED"} { - error "Wrong state." - } - $doc delete - grammar reset - dom parse -validateCmd grammar { - - } doc - if {[grammar state] ne "FINISHED"} { - error "Wrong state." - } - $doc delete - grammar reset - dom parse -validateCmd grammar { - - } doc - if {[grammar state] ne "FINISHED"} { - error "Wrong state." - } - $doc delete - grammar delete -} {} - -proc structure-5.3 {base systemId publicId} { - return [list "string" "" ""] -} - -test structure-5.3 {dom parse -validateCmd} { - tdom::structure create grammar - grammar defelement doc { - element e1 - element e2 * - } - foreach e {e1 e2} { - grammar defelement $e {} - } - set result [catch {dom parse -validateCmd grammar \ - -externalentitycommand structure-5.3 { - - ]> - &e1;} doc} errMsg] - grammar delete - set result -} 1 - -test structure-5.4 {define} { - tdom::structure create grammar - grammar define { - defelement elm1 { - element a - element b - } - defelement a { - element c - } - defelement b {} - defelement c {empty} - } - set doc [dom parse -validateCmd grammar { - - }] - $doc delete - grammar delete -} {} - - -test structure-6.1 {expat parser with -validateCmd} { - tdom::structure create grammar - grammar defelement doc { - element e1 - element e2 * - } - foreach e {e1 e2} { - grammar defelement $e {} - } - ::xml::parser p -validateCmd grammar - set result [catch {p parse {}} errMsg] - p delete - grammar delete - set result -} 1 - -test structure-7.1 {group} { - tdom::structure create grammar - grammar defelement doc { - element e1 - group ! { - element e1 - element e2 - } - group ! { - element e1 - element e2 - } - element e2 * - } - foreach e {e1 e2} { - grammar defelement $e {} - } - dom parse -validateCmd grammar { - - } doc - $doc delete - if {[grammar state] ne "FINISHED"} { - error "Wrong state." - } - grammar delete -} {} - -test structure-7.1.1 {group} { - tdom::structure create grammar - grammar define { - defelement doc { - element e1 - group ! { - element e1 - element e2 - } - group ! { - element e1 - element e2 - } - element e2 * - } - foreach e {e1 e2} { - defelement $e {} - } - } - dom parse -validateCmd grammar { - - } doc - $doc delete - if {[grammar state] ne "FINISHED"} { - error "Wrong state." - } - grammar delete -} {} - -test structure-7.2 {group} { - tdom::structure create grammar - grammar defelement doc { - element e1 - group 2 { - element e1 - element e2 - } - element e2 * - } - foreach e {e1 e2} { - grammar defelement $e {} - } - dom parse -validateCmd grammar { - - } doc - $doc delete - if {[grammar state] ne "FINISHED"} { - error "Wrong state." - } - grammar delete -} {} - -test structure-7.2.1 {group} { - tdom::structure create grammar - grammar define { - defelement doc { - element e1 - group 2 { - element e1 - element e2 - } - element e2 * - } - foreach e {e1 e2} { - grammar defelement $e {} - } - } - dom parse -validateCmd grammar { - - } doc - $doc delete - if {[grammar state] ne "FINISHED"} { - error "Wrong state." - } - grammar delete -} {} - -test structure-7.3 {group with inline defined element} { - tdom::structure create grammar - grammar define { - defelement doc { - element e1 - group 2 { - element e1 1 { - element e2 - } - element e2 - } - element e2 * - } - foreach e {e1 e2} { - grammar defelement $e {} - } - } - dom parse -validateCmd grammar { - - } doc - $doc delete - if {[grammar state] ne "FINISHED"} { - error "Wrong state." - } - grammar delete -} {} - -test structure-7.4 {group with inline defined element} { - tdom::structure create grammar - grammar define { - defelement doc { - group { - element e1 - element e1 1 { - element e2 - } - element e2 - } - } - foreach e {e1 e2} { - grammar defelement $e {} - } - } - dom parse -validateCmd grammar { - - } doc - $doc delete - if {[grammar state] ne "FINISHED"} { - error "Wrong state." - } - grammar delete -} {} - -test structure-7.5 {group with inline defined element} { - tdom::structure create grammar - grammar define { - defelement doc { - group { - element e1 - element e1 1 { - element e2 - } - element e2 - } - } - foreach e {e1 e2} { - grammar defelement $e {} - } - } - ::xml::parser p -validateCmd grammar - p parse { - - } - p delete - if {[grammar state] ne "FINISHED"} { - error "Wrong state." - } - grammar delete -} {} - -test structure-7.6 {nested groups via refs} { - tdom::structure create grammar - grammar define { - defpattern a foouri { - group { - element e1 - element e1 1 { - element e2 - } - element e2 - } - element e3 ? - } - defpattern b foouri { - element b1 * - group 2 { - element b2 - ref a - } - } - foreach e {e1 e2 e3 b1 b2} { - defelement $e foouri {} - } - defelement doc foouri { - group { - ref a - ref b 2 - } - } - } - set doc [dom parse -validateCmd grammar { - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - }] - $doc delete - if {[grammar state] ne "FINISHED"} { - error "Wrong state." - } - grammar delete -} {} - -test structure-7.7 {nested groups via refs} { - tdom::structure create grammar - grammar define { - defpattern a { - group { - element e1 - element e1 1 { - element e2 - } - element e2 - } - element e3 ? - } - defpattern b { - element b1 * - group 2 { - element b2 - ref a - } - } - foreach e {e1 e2 e3 b1 b2} { - defelement $e {} - } - defelement doc { - group { - ref b - } - } - } - set doc [dom parse -validateCmd grammar { - - - - - - - - - - - - - - - - - - - - - - - }] - $doc delete - if {[grammar state] ne "FINISHED"} { - error "Wrong state." - } - grammar delete -} {} - -test structure-7.8 {nested groups via refs} { - tdom::structure create grammar - grammar define { - defpattern a foouri { - group { - element e1 - element e1 1 { - element e2 - } - element e2 - } - element e3 ? - } - foreach e {e1 e2 e3 b1 b2} { - defelement $e foouri {} - } - defelement doc foouri { - group { - ref a - } - } - } - set doc [dom parse -validateCmd grammar { - - - - - - - - - - - }] - $doc delete - if {[grammar state] ne "FINISHED"} { - error "Wrong state." - } - grammar delete -} {} - -test structure-7.9 {loop over seq} { - tdom::structure create grammar - grammar define { - defelement doc { - group ? { - element a - element b - } - element c - } - foreach e {a b c} { - defelement $e {} - } - } - set result [grammar validate ] - grammar delete - set result -} 1 - -test structure-7.10 {loop over seq} {knownBug} { - tdom::structure create grammar - grammar define { - defelement doc { - group 2 { - element a - element b - } - element c - foreach e {a b c} { - defelement $e {} - } - } - } - set result [grammar validate ] - grammar delete - set result -} 1 - -test structure-8.1 {validate method} { - tdom::structure create grammar - grammar defelement doc { - element e1 - element e2 * - } - foreach e {e1 e2} { - grammar defelement $e {} - } - set result [grammar validate ] - if {[grammar state] ne "FINISHED"} { - error "Wrong state." - } - grammar reset - lappend result [grammar validate errMsg] - grammar delete - set result -} {1 0} - -test structure-8.2 {validate method} { - tdom::structure create grammar - grammar defelement doc foouri { - element e1 - element e2 * - } - foreach e {e1 e2} { - grammar defelement $e foouri {} - } - set result [grammar validate {}] - if {[grammar state] ne "FINISHED"} { - error "Wrong state." - } - grammar reset - lappend result [grammar validate {} errMsg] - grammar delete - set result -} {1 0} - -test structure-9.1 {choice} { - tdom::structure create grammar - grammar define { - defelement doc foouri { - choice * { - element e1 - element e2 * - } - } - foreach e {e1 e2} { - defelement $e foouri {} - } - } - grammar validate {} - grammar reset - grammar validate {} - grammar reset - grammar validate {} - grammar reset - grammar validate {} - grammar delete -} {} - Index: tests/xpath.bench ================================================================== --- tests/xpath.bench +++ tests/xpath.bench @@ -79,10 +79,48 @@ $root selectNodes {e1[myfunc() = '']} } -post { $doc delete } +} + +foreach nrOf {1 10 50 100} { + + bench -desc "string()" -pre { + dom createDocument root doc + $doc documentElement root + $root appendFromScript { + for {set x 0} {$x < $nrOf} {incr x} { + e1 + } + } + $root selectNodes -cache 1 string(e1) + } -body { + $root selectNodes -cache 1 string(e1) + } -post { + $doc delete + } + +} + +foreach nrOf {1 10 50 100} { + + bench -desc "count()" -pre { + dom createDocument root doc + $doc documentElement root + $root appendFromScript { + for {set x 0} {$x < $nrOf} {incr x} { + e1 + } + } + $root selectNodes -cache 1 count(e1) + } -body { + $root selectNodes -cache 1 count(e1) + } -post { + $doc delete + } + } dom createNodeCmd elementNode e2 dom createDocument root doc Index: tests/xpath.test ================================================================== --- tests/xpath.test +++ tests/xpath.test @@ -546,26 +546,26 @@ set result [catch {$root selectNodes {*[1}} errMsg] list $result $errMsg } {1 {Predicate: Expected "RBRACKET" for '*[1' Parsed symbols: - 0 WCARDNAME 0 00000.000 0 * - 1 LBRACKET 0 00000.000 1 - 2 INTNUMBER 1 00001.000 2 }} + 0 WCARDNAME 0 000000000 0 * + 1 LBRACKET 0 000000000 1 + 2 INTNUMBER 1 000000001 2 }} test xpath-5.2 {erroneous XPath expr: missing right brace in predicate} { set result [catch {$root selectNodes {*[1][@attr}} errMsg] list $result $errMsg } {1 {Predicate: Expected "RBRACKET" for '*[1][@attr' Parsed symbols: - 0 WCARDNAME 0 00000.000 0 * - 1 LBRACKET 0 00000.000 1 - 2 INTNUMBER 1 00001.000 2 - 3 RBRACKET 0 00000.000 3 - 4 LBRACKET 0 00000.000 4 - 5 ATTRIBUTE 0 00000.000 9 attr}} + 0 WCARDNAME 0 000000000 0 * + 1 LBRACKET 0 000000000 1 + 2 INTNUMBER 1 000000001 2 + 3 RBRACKET 0 000000000 3 + 4 LBRACKET 0 000000000 4 + 5 ATTRIBUTE 0 000000000 9 attr}} test xpath-5.3 {erroneous XPath expr: missing left brace in predicate} { catch {$root selectNodes {*1]}} } {1} @@ -1072,17 +1072,17 @@ $doc delete set result } {1 {Predicate: Expected "RBRACKET" for 'a[b %nodeName='another value']' Parsed symbols: - 0 WCARDNAME 0 00000.000 0 a - 1 LBRACKET 0 00000.000 1 - 2 WCARDNAME 0 00000.000 2 b ---> 3 WCARDNAME 1 00000.000 12 with spaces - 4 EQUAL 0 00000.000 13 - 5 LITERAL 0 00000.000 28 another value - 6 RBRACKET 0 00000.000 29 }} + 0 WCARDNAME 0 000000000 0 a + 1 LBRACKET 0 000000000 1 + 2 WCARDNAME 0 000000000 2 b +--> 3 WCARDNAME 1 000000000 12 with spaces + 4 EQUAL 0 000000000 13 + 5 LITERAL 0 000000000 28 another value + 6 RBRACKET 0 000000000 29 }} test xpath-5.47 {Element name injected with tcl variable} { set doc [dom parse -json {{"a":{"":"the value"},"a":{"":"another value"}}}] set nodeName "" set node [$doc selectNodes {a[%nodeName='another value']}] @@ -1177,10 +1177,47 @@ lappend result [$doc selectNodes string(%nodeName0/%nodeName1)] lappend result [$doc selectNodes string(a/a/b)] $doc delete set result } {a/b b} + +test xpath-5.57 {afl-fuzz found seg fault in reporting error in invalid expr} { + set doc [dom createDocument doc] + catch {$doc selectNodes /[string repeat 1 2500]} + catch {$doc selectNodes /[string repeat 1 250]} + $doc delete +} {} + +test xpath-5.58 {afl-fuzz found seg fault in reporting error in invalid expr} { + set doc [dom createDocument doc] + catch {$doc selectNodes concat([string repeat 1 250],1,1)} + $doc delete +} {} + +test xpath-5.59 {afl-fuzz found floating point exception in mod calulation} { + set doc [dom createDocument doc] + set result [list] + lappend result [$doc selectNodes "1111111111 mod -1"] + lappend result [$doc selectNodes "111111111111111111111111111111111111111 mod -1"] + $doc delete + set result +} {0 NaN} + +test xpath-5.60 {afl-fuzz found floating point exception in mod calulation} { + set doc [dom createDocument doc] + set result [list] + for {set i 1} {$i < 20} {incr i} { + for {set j 1} {$j < 20} {incr j} { + set this [$doc selectNodes "$i mod $j"] + if {$this != ($i % $j)} { + lappend result [list $i $j $this [expr "$i % $j"]] + } + } + } + $doc delete + set result +} {} set doc [dom parse { asub2 asub3 @@ -1199,11 +1236,11 @@ append result "[$node text] " } set result } {asub1 asub2 asub3 asub4 bsub1 bsub2 } -$doc delete +catch {$doc delete} set doc [dom parse { Index: tests/xslt.test ================================================================== --- tests/xslt.test +++ tests/xslt.test @@ -1151,18 +1151,18 @@ $xsltdoc delete set errMsg } {The 'current' function is not allowed in Pattern. for '*[current() != 'notthis']' Parsed symbols: - 0 WCARDNAME 0 00000.000 0 * - 1 LBRACKET 0 00000.000 1 - 2 FUNCTION 0 00000.000 8 current - 3 LPAR 0 00000.000 9 - 4 RPAR 0 00000.000 10 - 5 NOTEQ 0 00000.000 13 - 6 LITERAL 0 00000.000 23 notthis - 7 RBRACKET 0 00000.000 24 } + 0 WCARDNAME 0 000000000 0 * + 1 LBRACKET 0 000000000 1 + 2 FUNCTION 0 000000000 8 current + 3 LPAR 0 000000000 9 + 4 RPAR 0 000000000 10 + 5 NOTEQ 0 000000000 13 + 6 LITERAL 0 000000000 23 notthis + 7 RBRACKET 0 000000000 24 } set xslt-8.2.xml { Index: win/makefile.vc ================================================================== --- win/makefile.vc +++ win/makefile.vc @@ -41,12 +41,11 @@ $(TMP_DIR)\tclexpat.obj \ $(TMP_DIR)\tcldom.obj \ $(TMP_DIR)\tclpull.obj \ $(TMP_DIR)\tdomStubInit.obj\ $(TMP_DIR)\tdomStubLib.obj \ - $(TMP_DIR)\tdominit.obj \ - $(TMP_DIR)\loadlibrary.obj + $(TMP_DIR)\tdominit.obj PRJ_STUBOBJS = $(TMP_DIR)\tdomStubLib.obj PRJ_DEFINES = \ -D _CRT_SECURE_NO_DEPRECATE -D _CRT_NONSTDC_NO_DEPRECATE \ DELETED win/mkd.bat Index: win/mkd.bat ================================================================== --- win/mkd.bat +++ /dev/null @@ -1,13 +0,0 @@ -@echo off -rem RCS: @(#) $Id$ - -if exist %1\nul goto end - -md %1 -if errorlevel 1 goto end - -echo Created directory %1 - -:end - - Index: xe/README ================================================================== --- xe/README +++ xe/README @@ -1,15 +1,12 @@ -XE needs saves the upper input window in the file ~/.xe-input, if -it is called without arguments. Otherwise the first argument -gives the file name for the saved input windos. +XE saves the upper input window in the file ~/.xe-input, if it is +called without arguments. Otherwise the first argument gives the file +name for the saved input windos. -To start playing with XE copy you could do either: +To start playing with xe you could do either: 1) cp xe-input ~/.xe-input xe 2) xe xe-input - -Latter should be more appropriate for Wn32 users. - Index: xe/xe ================================================================== --- xe/xe +++ xe/xe @@ -1,6 +1,6 @@ -#!/opt/tcl/bin/wish +#!/usr/bin/env wish #---------------------------------------------------------------------------- # Copyright (c) 1999 - 2000 Jochen C. Loewer (loewerj@hotmail.com) #---------------------------------------------------------------------------- # # A XML/DOM/XPath evaluator/viewer... featuring the Tk text widget. @@ -21,19 +21,10 @@ # The Initial Developer of the Original Code is Jochen Loewer # Portions created by Jochen Loewer are Copyright (C) 1998, 1999 # Jochen Loewer. All Rights Reserved. # # Contributor(s): -# -# -# -# $Log$ -# Revision 1.1 2002/02/22 01:05:35 rolf -# Initial revision -# -# -# # # written by Jochen Loewer # December, 1999 # #