2017-12-14 14:20 UTC+0100 Aleksander Czajczynski (hb fki.pl)

* contrib/hbamf/amfenc.c
    * update amf3_Encode() serialize function with great idea of Przemek
      implemented recenly in hb_Serialize(). Checking garbage collector
      reference count can save time here too, unique arrays and hashes won't
      be indexed as references.

  * contrib/hbexpat/3rd/expat/*
    ! updated to 2.2.5 (from 2.2.1) using 3rdpatch.hb, expat.diff from
      Viktor's 3.4 fork was used - but (again) adapted for DOS 8.3 naming
      scheme. Also i've kept local patches for WinCE, OpenWatcom DOS/OS2,
      please test. Compilation in CPP mode is explicitly disabled for libexpat
      now, as upstream decided to ignore such use cases completly.

   * contrib/hbexpat/*
     * synced with Viktor's 3.4 fork

   + include/hbarc4.h
   * src/harbour.def
     + export ARC4 core routines like in 3.4 fork, updated expat lib reuses it.

   * contrib/hbtip/hbtip.hbp
     ! adapt *.hbx file specifier to hbmk2 3.2 syntax
This commit is contained in:
Aleksander Czajczynski
2017-12-14 14:21:03 +01:00
parent 2b4c4b3b5f
commit 6e3fe511f0
36 changed files with 3073 additions and 1974 deletions

View File

@@ -7,6 +7,30 @@
Entries may not always be in chronological/commit order.
See license at the end of file. */
2017-12-14 14:20 UTC+0100 Aleksander Czajczynski (hb fki.pl)
* contrib/hbamf/amfenc.c
* update amf3_Encode() serialize function with great idea of Przemek
implemented recenly in hb_Serialize(). Checking garbage collector
reference count can save time here too, unique arrays and hashes won't
be indexed as references.
* contrib/hbexpat/3rd/expat/*
! updated to 2.2.5 (from 2.2.1) using 3rdpatch.hb, expat.diff from
Viktor's 3.4 fork was used - but (again) adapted for DOS 8.3 naming
scheme. Also i've kept local patches for WinCE, OpenWatcom DOS/OS2,
please test. Compilation in CPP mode is explicitly disabled for libexpat
now, as upstream decided to ignore such use cases completly.
* contrib/hbexpat/*
* synced with Viktor's 3.4 fork
+ include/hbarc4.h
* src/harbour.def
+ export ARC4 core routines like in 3.4 fork, updated expat lib reuses it.
* contrib/hbtip/hbtip.hbp
! adapt *.hbx file specifier to hbmk2 3.2 syntax
2017-12-12 12:26 UTC+0100 Przemyslaw Czerpak (druzus/at/poczta.onet.pl)
* contrib/hbnf/fttext.c
* contrib/hbnf/hbnf.hbx

View File

@@ -1,5 +1,5 @@
/* Ilina Stoilkovska <anili100/at/gmail.com> 2011
* Aleksander Czajczynski <hb/at/fki.pl> 2011-2012
* Aleksander Czajczynski <hb/at/fki.pl> 2011-2017
*
* Encoding Harbour items to AMF3
*
@@ -33,6 +33,7 @@ typedef struct
HB_BOOL use_strstr;
HB_BOOL str_rtrim;
HB_SIZE strstr_count; /* used only when str_ref is disabled */
HB_SIZE objnref_count; /* items that should normally appear in obj_ref, but GC says that they are not referenced */
PHB_ITEM obj_ref;
PHB_ITEM str_ref;
PHB_ITEM strstr_ref;
@@ -270,7 +271,17 @@ static int amf3_add_index( amfContext * context, PHB_ITEM pHash, PHB_ITEM pItem
return -1;
}
pVal = hb_itemNew( NULL );
if( pHash == context->str_ref )
result = ( int ) ( hb_hashLen( pHash ) + context->strstr_count );
/* ->strstr_count > 0 only when some inner context inside
* user-defined conversion function uses only strstr mode
* like amf3_FromWA() function f.e. */
else if( pHash == context->obj_ref )
result = ( int ) ( hb_hashLen( pHash ) + context->objnref_count );
else
result = ( int ) ( hb_hashLen( pHash ) );
pVal = hb_itemPutNS( NULL, result );
if( ! hb_hashAdd( pHash, pKey, pVal ) )
{
@@ -281,10 +292,7 @@ static int amf3_add_index( amfContext * context, PHB_ITEM pHash, PHB_ITEM pItem
hb_itemRelease( pVal );
hb_itemRelease( pKey );
result = ( int ) ( hb_hashLen( pHash ) - 1 + context->strstr_count );
/* used only when some inner context inside
* conversion function uses only strstr mode
* like amf3_FromWA() function f.e. */
}
if( ( HB_IS_STRING( pItem ) || HB_IS_MEMO( pItem ) ) && context->use_strstr )
@@ -312,6 +320,7 @@ static int amf3_get_index( amfContext * context, PHB_ITEM pHash, PHB_ITEM pItem
{
PHB_ITEM pKey = hb_itemNew( NULL );
HB_SIZE nPos;
PHB_ITEM pVal;
_ref_realItemPtr( pKey, pItem );
if( ! HB_IS_POINTER( pKey ) && ! HB_IS_DOUBLE( pKey ) )
@@ -319,7 +328,15 @@ static int amf3_get_index( amfContext * context, PHB_ITEM pHash, PHB_ITEM pItem
hb_itemRelease( pKey );
return -1;
}
if( hb_hashScan( pHash, pKey, &nPos ) )
if( context->objnref_count )
{
pVal = hb_hashGetItemPtr( pHash, pKey, 0 );
hb_itemRelease( pKey );
if( pVal )
return ( int ) hb_itemGetNS( pVal );
}
else if( hb_hashScan( pHash, pKey, &nPos ) )
{
hb_itemRelease( pKey );
return ( int ) ( nPos - 1 );
@@ -483,11 +500,19 @@ static HB_BOOL amf3_encode_dynamic_dict( amfContext * context, PHB_ITEM pItem )
}
static HB_BOOL amf3_serialize_hash( amfContext * context, PHB_ITEM pItem )
{
if( context->use_refs )
{
if( hb_hashRefs( pItem ) > 1 )
{
HB_BOOL result = amf3_encode_reference( context, context->obj_ref, pItem, 0 );
if( result > -1 )
return result;
}
else
context->objnref_count++;
}
return amf3_encode_hash( context, pItem );
}
@@ -574,13 +599,11 @@ static HB_BOOL amf3_encode_array( amfContext * context, PHB_ITEM pItem )
PHB_ITEM pArrayItem;
int result;
pArrayItem = hb_itemNew( NULL );
hb_arrayGet( pItem, i, pArrayItem );
pArrayItem = hb_arrayGetItemPtr( pItem, i );
if( ! pArrayItem )
return HB_FALSE;
result = amf3_encode( context, pArrayItem );
hb_itemRelease( pArrayItem );
if( ! result )
return HB_FALSE;
}
@@ -589,11 +612,20 @@ static HB_BOOL amf3_encode_array( amfContext * context, PHB_ITEM pItem )
}
static HB_BOOL amf3_serialize_array( amfContext * context, PHB_ITEM pItem )
{
if( context->use_refs )
{
if( hb_arrayRefs( pItem ) > 1 )
{
int result = amf3_encode_reference( context, context->obj_ref, pItem, 0 );
if( result > -1 )
return result;
}
else
context->objnref_count++;
}
return amf3_encode_array( context, pItem );
}
@@ -909,10 +941,18 @@ static HB_BOOL amf3_serialize_object( amfContext * context, PHB_ITEM pItem )
return result;
}
if( context->use_refs )
{
if( hb_arrayRefs( pItem ) > 1 )
{
result = amf3_encode_reference( context, context->obj_ref, pItem, 0 );
if( result > -1 )
return result;
}
else
context->objnref_count++;
}
return amf3_encode_object( context, pItem );
}
@@ -1024,12 +1064,14 @@ static amfContext * context_setup( PHB_ITEM pFuncSym, HB_BOOL use_refs, HB_BOOL
context->obj_ref = outer_context->obj_ref;
context->str_ref = outer_context->str_ref;
context->class_ref = outer_context->class_ref;
context->objnref_count = outer_context->objnref_count;
}
else
{
context->obj_ref = hb_hashNew( NULL );
context->str_ref = hb_hashNew( NULL );
context->class_ref = hb_hashNew( NULL );
context->objnref_count = 0;
}
}
else
@@ -1068,7 +1110,9 @@ static amfContext * context_setup( PHB_ITEM pFuncSym, HB_BOOL use_refs, HB_BOOL
static void context_release( amfContext * context, amfContext * outer_context )
{
if( context->use_refs && ! ( outer_context && outer_context->use_refs ) )
if( outer_context && outer_context->use_refs )
outer_context->objnref_count = context->objnref_count;
else if( context->use_refs )
{
hb_itemRelease( context->obj_ref );
hb_itemRelease( context->str_ref );
@@ -1378,6 +1422,7 @@ HB_FUNC( AMF3_ENCODE )
context->use_refs = HB_TRUE;
context->conv_function = pFuncSym;
context->encode_ba = lBA;
context->objnref_count = 0;
/* "strstr" is another optional idea of catching similar strings,
key in this hash is not the pointer to C char, but the string

View File

@@ -1,7 +1,13 @@
#ifndef _HBCONF_H
#define _HBCONF_H
#include "hbdefs.h"
#include "hbapi.h"
#include "hbarc4.h"
#if defined( HB_FORCE_ARC4RANDOM )
# define HAVE_ARC4RANDOM_BUF
# define arc4random_buf hb_arc4random_buf
#endif
#if defined( HB_OS_WIN )
# define WIN32_LEAN_AND_MEAN

View File

@@ -1,5 +1,33 @@
/* Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd
See the file COPYING for copying permission.
/*
__ __ _
___\ \/ /_ __ __ _| |_
/ _ \\ /| '_ \ / _` | __|
| __// \| |_) | (_| | |_
\___/_/\_\ .__/ \__,_|\__|
|_| XML parser
Copyright (c) 1997-2000 Thai Open Source Software Center Ltd
Copyright (c) 2000-2017 Expat development team
Licensed under the MIT license:
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to permit
persons to whom the Software is furnished to do so, subject to the
following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
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. 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.
*/
#define ASCII_A 0x41

View File

@@ -1,5 +1,33 @@
/* Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd
See the file COPYING for copying permission.
/*
__ __ _
___\ \/ /_ __ __ _| |_
/ _ \\ /| '_ \ / _` | __|
| __// \| |_) | (_| | |_
\___/_/\_\ .__/ \__,_|\__|
|_| XML parser
Copyright (c) 1997-2000 Thai Open Source Software Center Ltd
Copyright (c) 2000-2017 Expat development team
Licensed under the MIT license:
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to permit
persons to whom the Software is furnished to do so, subject to the
following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
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. 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.
*/
/* 0x00 */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML,

View File

@@ -1,7 +1,75 @@
diff -urN expat.orig/xmlparse.c expat/xmlparse.c
--- expat.orig/xmlparse.c 2017-07-24 16:57:23.412595132 +0200
+++ expat/xmlparse.c 2017-07-24 16:57:23.412595132 +0200
@@ -15,6 +15,12 @@
diff --strip-trailing-cr -urN expat.orig/winconfi.h expat/winconfi.h
--- expat.orig/winconfi.h 2017-09-03 14:47:40.000000000 +0000
+++ expat/winconfi.h 2017-12-14 11:38:06.000000000 +0000
@@ -1,63 +1 @@
-/*
- __ __ _
- ___\ \/ /_ __ __ _| |_
- / _ \\ /| '_ \ / _` | __|
- | __// \| |_) | (_| | |_
- \___/_/\_\ .__/ \__,_|\__|
- |_| XML parser
-
- Copyright (c) 1997-2000 Thai Open Source Software Center Ltd
- Copyright (c) 2000-2017 Expat development team
- Licensed under the MIT license:
-
- Permission is hereby granted, free of charge, to any person obtaining
- a copy of this software and associated documentation files (the
- "Software"), to deal in the Software without restriction, including
- without limitation the rights to use, copy, modify, merge, publish,
- distribute, sublicense, and/or sell copies of the Software, and to permit
- persons to whom the Software is furnished to do so, subject to the
- following conditions:
-
- The above copyright notice and this permission notice shall be included
- in all copies or substantial portions of the Software.
-
- 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. 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.
-*/
-
-#ifndef WINCONFIG_H
-#define WINCONFIG_H
-
-#define WIN32_LEAN_AND_MEAN
-#include <windows.h>
-#undef WIN32_LEAN_AND_MEAN
-
-#include <memory.h>
-#include <string.h>
-
-
-#if defined(HAVE_EXPAT_CONFIG_H) /* e.g. MinGW */
-# include <expat_config.h>
-#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
-
-
-#endif /* !defined(HAVE_EXPAT_CONFIG_H) */
-
-
-#endif /* ndef WINCONFIG_H */
+#include "_hbconf.h"
diff --strip-trailing-cr -urN expat.orig/xmlparse.c expat/xmlparse.c
--- expat.orig/xmlparse.c 2017-10-31 16:20:31.000000000 +0000
+++ expat/xmlparse.c 2017-12-14 11:59:45.000000000 +0000
@@ -43,6 +43,12 @@
#ifdef _WIN32
#define getpid GetCurrentProcessId
@@ -14,23 +82,16 @@ diff -urN expat.orig/xmlparse.c expat/xmlparse.c
#else
#include <sys/time.h> /* gettimeofday() */
#include <sys/types.h> /* getpid() */
@@ -23,7 +29,9 @@
#define XML_BUILDING_EXPAT 1
-#ifdef _WIN32
+#ifdef HARBOUR_CONF
+#include "_hbconf.h"
+#elif defined(_WIN32)
@@ -56,7 +62,7 @@
#ifdef _WIN32
#include "winconfi.h"
#elif defined(HAVE_EXPAT_CONFIG_H)
#include <expat_config.h>
@@ -749,11 +757,11 @@
static int
writeRandomBytes_RtlGenRandom(void * target, size_t count) {
int success = 0; /* full count bytes written? */
- const HMODULE advapi32 = LoadLibrary("ADVAPI32.DLL");
+ const HMODULE advapi32 = LoadLibrary(TEXT("ADVAPI32.DLL"));
-#include <expat_config.h>
+#include <expat_co.h>
#endif /* ndef _WIN32 */
#include "ascii.h"
@@ -783,7 +789,7 @@
if (advapi32) {
const RTLGENRANDOM_FUNC RtlGenRandom
@@ -39,7 +100,7 @@ diff -urN expat.orig/xmlparse.c expat/xmlparse.c
if (RtlGenRandom) {
if (RtlGenRandom((PVOID)target, (ULONG)count) == TRUE) {
success = 1;
@@ -771,10 +779,21 @@
@@ -803,10 +809,21 @@
static unsigned long
gather_time_entropy(void)
{
@@ -62,43 +123,27 @@ diff -urN expat.orig/xmlparse.c expat/xmlparse.c
#else
struct timeval tv;
int gettimeofday_res;
@@ -793,7 +812,11 @@
static unsigned long
ENTROPY_DEBUG(const char * label, unsigned long entropy) {
+#ifdef _WINCE
+ const char * const EXPAT_ENTROPY_DEBUG = NULL;
+#else
const char * const EXPAT_ENTROPY_DEBUG = getenv("EXPAT_ENTROPY_DEBUG");
+#endif
if (EXPAT_ENTROPY_DEBUG && ! strcmp(EXPAT_ENTROPY_DEBUG, "1")) {
fprintf(stderr, "Entropy: %s --> 0x%0*lx (%lu bytes)\n",
label,
diff -urN expat.orig/xmlrole.c expat/xmlrole.c
--- expat.orig/xmlrole.c 2017-07-24 16:57:23.416595132 +0200
+++ expat/xmlrole.c 2017-07-24 16:57:23.456595133 +0200
@@ -4,7 +4,9 @@
#include <stddef.h>
-#ifdef _WIN32
+#ifdef HARBOUR_CONF
+#include "_hbconf.h"
+#elif defined(_WIN32)
diff --strip-trailing-cr -urN expat.orig/xmlrole.c expat/xmlrole.c
--- expat.orig/xmlrole.c 2017-09-03 14:47:40.000000000 +0000
+++ expat/xmlrole.c 2017-12-14 11:38:11.000000000 +0000
@@ -36,7 +36,7 @@
#include "winconfi.h"
#else
#ifdef HAVE_EXPAT_CONFIG_H
diff -urN expat.orig/xmltok.c expat/xmltok.c
--- expat.orig/xmltok.c 2017-07-24 16:57:23.460595133 +0200
+++ expat/xmltok.c 2017-07-24 16:57:23.476595134 +0200
@@ -4,7 +4,9 @@
-#include <expat_config.h>
+#include <expat_co.h>
#endif
#endif /* ndef _WIN32 */
#include <stddef.h>
-#ifdef _WIN32
+#ifdef HARBOUR_CONF
+#include "_hbconf.h"
+#elif defined(_WIN32)
diff --strip-trailing-cr -urN expat.orig/xmltok.c expat/xmltok.c
--- expat.orig/xmltok.c 2017-09-11 17:31:49.000000000 +0000
+++ expat/xmltok.c 2017-12-14 11:38:17.000000000 +0000
@@ -47,7 +47,7 @@
#include "winconfi.h"
#else
#ifdef HAVE_EXPAT_CONFIG_H
-#include <expat_config.h>
+#include <expat_co.h>
#endif
#endif /* ndef _WIN32 */

View File

@@ -1,5 +1,33 @@
/* Copyright (c) 1998, 1999, 2000 Thai Open Source Software Center Ltd
See the file COPYING for copying permission.
/*
__ __ _
___\ \/ /_ __ __ _| |_
/ _ \\ /| '_ \ / _` | __|
| __// \| |_) | (_| | |_
\___/_/\_\ .__/ \__,_|\__|
|_| XML parser
Copyright (c) 1997-2000 Thai Open Source Software Center Ltd
Copyright (c) 2000-2017 Expat development team
Licensed under the MIT license:
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to permit
persons to whom the Software is furnished to do so, subject to the
following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
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. 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.
*/
#ifndef Expat_INCLUDED
@@ -24,7 +52,6 @@ extern "C" {
struct XML_ParserStruct;
typedef struct XML_ParserStruct *XML_Parser;
/* Should this be defined using stdbool.h when C99 is available? */
typedef unsigned char XML_Bool;
#define XML_TRUE ((XML_Bool) 1)
#define XML_FALSE ((XML_Bool) 0)
@@ -1049,7 +1076,7 @@ XML_GetFeatureList(void);
*/
#define XML_MAJOR_VERSION 2
#define XML_MINOR_VERSION 2
#define XML_MICRO_VERSION 1
#define XML_MICRO_VERSION 5
#ifdef __cplusplus
}

View File

@@ -8,8 +8,10 @@
-hbx=
-warn=low
-cpp=no
-pic
loadlibr.c
xmlparse.c
xmlrole.c
xmltok.c
@@ -20,9 +22,8 @@ xmltok.c
{bcc}-cflag=-w-8008
{bcc}-cflag=-w-8066
# ORIGIN https://expat.sourceforge.net/
# VER 2.2.1
# URL https://downloads.sourceforge.net/project/expat/expat/2.2.1/expat-2.2.1.tar.bz2
# ORIGIN https://libexpat.github.io/
# URL https://downloads.sourceforge.net/project/expat/expat/2.2.5/expat-2.2.5.tar.bz2
# DIFF expat.diff
#
# MAP COPYING
@@ -38,6 +39,7 @@ xmltok.c
# MAP lib/iasciitab.h iasciita.h
# MAP lib/internal.h internal.h
# MAP lib/latin1tab.h latin1ta.h
# MAP lib/loadlibrary.c loadlibr.c
# MAP lib/nametab.h nametab.h
# MAP lib/siphash.h siphash.h
# MAP lib/utf8tab.h utf8tab.h

View File

@@ -0,0 +1 @@
#include "_hbconf.h"

View File

@@ -1,5 +1,33 @@
/* Copyright (c) 1998, 1999, 2000 Thai Open Source Software Center Ltd
See the file COPYING for copying permission.
/*
__ __ _
___\ \/ /_ __ __ _| |_
/ _ \\ /| '_ \ / _` | __|
| __// \| |_) | (_| | |_
\___/_/\_\ .__/ \__,_|\__|
|_| XML parser
Copyright (c) 1997-2000 Thai Open Source Software Center Ltd
Copyright (c) 2000-2017 Expat development team
Licensed under the MIT license:
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to permit
persons to whom the Software is furnished to do so, subject to the
following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
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. 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.
*/
#ifndef Expat_External_INCLUDED
@@ -93,7 +121,9 @@ 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

View File

@@ -1,5 +1,33 @@
/* Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd
See the file COPYING for copying permission.
/*
__ __ _
___\ \/ /_ __ __ _| |_
/ _ \\ /| '_ \ / _` | __|
| __// \| |_) | (_| | |_
\___/_/\_\ .__/ \__,_|\__|
|_| XML parser
Copyright (c) 1997-2000 Thai Open Source Software Center Ltd
Copyright (c) 2000-2017 Expat development team
Licensed under the MIT license:
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to permit
persons to whom the Software is furnished to do so, subject to the
following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
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. 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.
*/
/* Like asciitab.h, except that 0xD has code BT_S rather than BT_CR */

View File

@@ -18,6 +18,35 @@
Note: Use of these macros is based on judgement, not hard rules,
and therefore subject to change.
__ __ _
___\ \/ /_ __ __ _| |_
/ _ \\ /| '_ \ / _` | __|
| __// \| |_) | (_| | |_
\___/_/\_\ .__/ \__,_|\__|
|_| XML parser
Copyright (c) 1997-2000 Thai Open Source Software Center Ltd
Copyright (c) 2000-2017 Expat development team
Licensed under the MIT license:
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to permit
persons to whom the Software is furnished to do so, subject to the
following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
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. 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.
*/
#if defined(__GNUC__) && defined(__i386__) && !defined(__MINGW32__)
@@ -87,7 +116,7 @@ extern "C" {
void
align_limit_to_full_utf8_characters(const char * from, const char ** fromLimRef);
_INTERNAL_trim_to_complete_utf8_characters(const char * from, const char ** fromLimRef);
#ifdef __cplusplus

View File

@@ -1,5 +1,33 @@
/* Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd
See the file COPYING for copying permission.
/*
__ __ _
___\ \/ /_ __ __ _| |_
/ _ \\ /| '_ \ / _` | __|
| __// \| |_) | (_| | |_
\___/_/\_\ .__/ \__,_|\__|
|_| XML parser
Copyright (c) 1997-2000 Thai Open Source Software Center Ltd
Copyright (c) 2000-2017 Expat development team
Licensed under the MIT license:
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to permit
persons to whom the Software is furnished to do so, subject to the
following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
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. 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.
*/
/* 0x80 */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER,

View File

@@ -0,0 +1,143 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 2016 - 2017, Steve Holme, <steve_holme@hotmail.com>.
* 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 <windows.h>
#include <tchar.h>
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) */

View File

@@ -1,3 +1,35 @@
/*
__ __ _
___\ \/ /_ __ __ _| |_
/ _ \\ /| '_ \ / _` | __|
| __// \| |_) | (_| | |_
\___/_/\_\ .__/ \__,_|\__|
|_| XML parser
Copyright (c) 1997-2000 Thai Open Source Software Center Ltd
Copyright (c) 2000-2017 Expat development team
Licensed under the MIT license:
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to permit
persons to whom the Software is furnished to do so, subject to the
following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
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. 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.
*/
static const unsigned namingBitmap[] = {
0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000,

View File

@@ -2,9 +2,8 @@
* siphash.h - SipHash-2-4 in a single header file
* --------------------------------------------------------------------------
* Derived by William Ahern from the reference implementation[1] published[2]
* by Jean-Philippe Aumasson and Daniel J. Berstein. Licensed in kind.
* by Jean-Philippe Aumasson and Daniel J. Berstein.
* Minimal changes by Sebastian Pipping on top, details below.
* Minimal changes by Sebastian Pipping and Victor Stinner on top, see below.
* Licensed under the CC0 Public Domain Dedication license.
*
* 1. https://www.131002.net/siphash/siphash24.c
@@ -12,14 +11,25 @@
* --------------------------------------------------------------------------
* HISTORY:
*
* 2017-06-10 (Sebastian Pipping)
* 2017-07-25 (Vadim Zeitlin)
* - Fix use of SIPHASH_MAIN macro
*
* 2017-07-05 (Sebastian Pipping)
* - Use _SIP_ULL macro to not require a C++11 compiler if compiled as C++
* - Add const qualifiers at two places
* - Ensure <=80 characters line length (assuming tab width 4)
*
* 2017-06-23 (Victor Stinner)
* - Address Win64 compile warnings
*
* 2017-06-18 (Sebastian Pipping)
* - Clarify license note in the header
* - Address C89 issues:
* - Stop using inline keyword (and let compiler decide)
* - Turn integer suffix ULL to UL
* - Replace _Bool by int
* - Turn macro siphash24 into a function
* - Address invalid conversion (void pointer) by explicit cast
* - Address lack of stdint.h for Visual Studio 2003 to 2008
* - Always expose sip24_valid (for self-tests)
*
* 2012-11-04 - Born. (William Ahern)
@@ -76,7 +86,23 @@
#define SIPHASH_H
#include <stddef.h> /* 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;
#else
#include <stdint.h> /* 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))))
@@ -158,11 +184,12 @@ static void sip_round(struct siphash *H, const int rounds) {
} /* sip_round() */
static struct siphash *sip24_init(struct siphash *H, const struct sipkey *key) {
H->v0 = 0x736f6d6570736575UL ^ key->k[0];
H->v1 = 0x646f72616e646f6dUL ^ key->k[1];
H->v2 = 0x6c7967656e657261UL ^ key->k[0];
H->v3 = 0x7465646279746573UL ^ key->k[1];
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;
@@ -173,7 +200,8 @@ static struct siphash *sip24_init(struct siphash *H, const struct sipkey *key) {
#define sip_endof(a) (&(a)[sizeof (a) / sizeof *(a)])
static struct siphash *sip24_update(struct siphash *H, const void *src, size_t len) {
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;
@@ -198,7 +226,7 @@ static struct siphash *sip24_update(struct siphash *H, const void *src, size_t l
static uint64_t sip24_final(struct siphash *H) {
char left = H->p - H->buf;
const char left = (char)(H->p - H->buf);
uint64_t b = (H->c + left) << 56;
switch (left) {
@@ -222,7 +250,8 @@ static uint64_t sip24_final(struct siphash *H) {
} /* sip24_final() */
static uint64_t siphash24(const void *src, size_t len, const struct sipkey *key) {
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() */
@@ -310,10 +339,11 @@ static int sip24_valid(void) {
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");
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] = i;
in[i] = (unsigned char)i;
if (siphash24(in, i, &k) != SIP_U8TO64_LE(vectors[i]))
return 0;
@@ -323,12 +353,12 @@ static int sip24_valid(void) {
} /* sip24_valid() */
#if SIPHASH_MAIN
#ifdef SIPHASH_MAIN
#include <stdio.h>
int main(void) {
int ok = sip24_valid();
const int ok = sip24_valid();
if (ok)
puts("OK");

View File

@@ -1,7 +1,34 @@
/* Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd
See the file COPYING for copying permission.
*/
/*
__ __ _
___\ \/ /_ __ __ _| |_
/ _ \\ /| '_ \ / _` | __|
| __// \| |_) | (_| | |_
\___/_/\_\ .__/ \__,_|\__|
|_| XML parser
Copyright (c) 1997-2000 Thai Open Source Software Center Ltd
Copyright (c) 2000-2017 Expat development team
Licensed under the MIT license:
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to permit
persons to whom the Software is furnished to do so, subject to the
following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
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. 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.
*/
/* 0x80 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL,
/* 0x84 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL,

View File

@@ -1,40 +1 @@
/*================================================================
** Copyright 2000, Clark Cooper
** All rights reserved.
**
** This is free software. You are permitted to copy, distribute, or modify
** it under the terms of the MIT/X license (contained in the COPYING file
** with this distribution.)
*/
#ifndef WINCONFIG_H
#define WINCONFIG_H
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#undef WIN32_LEAN_AND_MEAN
#include <memory.h>
#include <string.h>
#if defined(HAVE_EXPAT_CONFIG_H) /* e.g. MinGW */
# include <expat_config.h>
#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
#endif /* !defined(HAVE_EXPAT_CONFIG_H) */
#endif /* ndef WINCONFIG_H */
#include "_hbconf.h"

File diff suppressed because it is too large Load Diff

View File

@@ -1,16 +1,42 @@
/* Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd
See the file COPYING for copying permission.
/*
__ __ _
___\ \/ /_ __ __ _| |_
/ _ \\ /| '_ \ / _` | __|
| __// \| |_) | (_| | |_
\___/_/\_\ .__/ \__,_|\__|
|_| XML parser
Copyright (c) 1997-2000 Thai Open Source Software Center Ltd
Copyright (c) 2000-2017 Expat development team
Licensed under the MIT license:
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to permit
persons to whom the Software is furnished to do so, subject to the
following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
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. 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.
*/
#include <stddef.h>
#ifdef HARBOUR_CONF
#include "_hbconf.h"
#elif defined(_WIN32)
#ifdef _WIN32
#include "winconfi.h"
#else
#ifdef HAVE_EXPAT_CONFIG_H
#include <expat_config.h>
#include <expat_co.h>
#endif
#endif /* ndef _WIN32 */
@@ -172,7 +198,14 @@ prolog1(PROLOG_STATE *state,
case XML_TOK_COMMENT:
return XML_ROLE_COMMENT;
case XML_TOK_BOM:
return XML_ROLE_NONE;
/* This case can never arise. To reach this role function, the
* parse must have passed through prolog0 and therefore have had
* some form of input, even if only a space. At that point, a
* byte order mark is no longer a valid character (though
* 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),
@@ -1287,6 +1320,26 @@ declClose(PROLOG_STATE *state,
return common(state, tok);
}
/* This function will only be invoked if the internal logic of the
* parser has broken down. It is used in two cases:
*
* 1: When the XML prolog has been finished. At this point the
* processor (the parser level above these role handlers) should
* switch from prologProcessor to contentProcessor and reinitialise
* the handler function.
*
* 2: When an error has been detected (via common() below). At this
* point again the processor should be switched to errorProcessor,
* which will never call a handler.
*
* The result of this is that error() can only be called if the
* processor switch failed to happen, which is an internal error and
* therefore we shouldn't be able to provoke it simply by using the
* library. It is a necessary backstop, however, so we merely exclude
* it from the coverage statistics.
*
* LCOV_EXCL_START
*/
static int PTRCALL
error(PROLOG_STATE *UNUSED_P(state),
int UNUSED_P(tok),
@@ -1296,6 +1349,7 @@ error(PROLOG_STATE *UNUSED_P(state),
{
return XML_ROLE_NONE;
}
/* LCOV_EXCL_STOP */
static int FASTCALL
common(PROLOG_STATE *state, int tok)

View File

@@ -1,5 +1,33 @@
/* Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd
See the file COPYING for copying permission.
/*
__ __ _
___\ \/ /_ __ __ _| |_
/ _ \\ /| '_ \ / _` | __|
| __// \| |_) | (_| | |_
\___/_/\_\ .__/ \__,_|\__|
|_| XML parser
Copyright (c) 1997-2000 Thai Open Source Software Center Ltd
Copyright (c) 2000-2017 Expat development team
Licensed under the MIT license:
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to permit
persons to whom the Software is furnished to do so, subject to the
following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
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. 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.
*/
#ifndef XmlRole_INCLUDED

View File

@@ -1,16 +1,53 @@
/* Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd
See the file COPYING for copying permission.
/*
__ __ _
___\ \/ /_ __ __ _| |_
/ _ \\ /| '_ \ / _` | __|
| __// \| |_) | (_| | |_
\___/_/\_\ .__/ \__,_|\__|
|_| XML parser
Copyright (c) 1997-2000 Thai Open Source Software Center Ltd
Copyright (c) 2000-2017 Expat development team
Licensed under the MIT license:
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to permit
persons to whom the Software is furnished to do so, subject to the
following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
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. 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.
*/
#include <stddef.h>
#include <string.h> /* memcpy */
#ifdef HARBOUR_CONF
#include "_hbconf.h"
#elif defined(_WIN32)
#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
#else
# include <stdbool.h>
#endif
#ifdef _WIN32
#include "winconfi.h"
#else
#ifdef HAVE_EXPAT_CONFIG_H
#include <expat_config.h>
#include <expat_co.h>
#endif
#endif /* ndef _WIN32 */
@@ -29,7 +66,6 @@
{ PREFIX(prologTok), PREFIX(contentTok), \
PREFIX(cdataSectionTok) IGNORE_SECTION_TOK_VTABLE }, \
{ PREFIX(attributeValueTok), PREFIX(entityValueTok) }, \
PREFIX(sameName), \
PREFIX(nameMatchesAscii), \
PREFIX(nameLength), \
PREFIX(skipS), \
@@ -326,7 +362,7 @@ enum { /* UTF8_cvalN is value of masked first byte of N byte sequence */
};
void
align_limit_to_full_utf8_characters(const char * from, const char ** fromLimRef)
_INTERNAL_trim_to_complete_utf8_characters(const char * from, const char ** fromLimRef)
{
const char * fromLim = *fromLimRef;
size_t walked = 0;
@@ -365,22 +401,37 @@ utf8_toUtf8(const ENCODING *UNUSED_P(enc),
const char **fromP, const char *fromLim,
char **toP, const char *toLim)
{
char *to;
const char *from;
const char *fromLimInitial = fromLim;
bool input_incomplete = false;
bool output_exhausted = false;
/* Avoid copying partial characters. */
align_limit_to_full_utf8_characters(*fromP, &fromLim);
/* Avoid copying partial characters (due to limited space). */
const ptrdiff_t bytesAvailable = fromLim - *fromP;
const ptrdiff_t bytesStorable = toLim - *toP;
if (bytesAvailable > bytesStorable) {
fromLim = *fromP + bytesStorable;
output_exhausted = true;
}
for (to = *toP, from = *fromP; (from < fromLim) && (to < toLim); from++, to++)
*to = *from;
*fromP = from;
*toP = to;
/* Avoid copying partial characters (from incomplete input). */
{
const char * const fromLimBefore = fromLim;
_INTERNAL_trim_to_complete_utf8_characters(*fromP, &fromLim);
if (fromLim < fromLimBefore) {
input_incomplete = true;
}
}
if (fromLim < fromLimInitial)
return XML_CONVERT_INPUT_INCOMPLETE;
else if ((to == toLim) && (from < fromLim))
{
const ptrdiff_t bytesToCopy = fromLim - *fromP;
memcpy(*toP, *fromP, bytesToCopy);
*fromP += bytesToCopy;
*toP += bytesToCopy;
}
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;
}
@@ -1021,7 +1072,11 @@ streqci(const char *s1, const char *s2)
if (ASCII_a <= c1 && c1 <= ASCII_z)
c1 += ASCII_A - ASCII_a;
if (ASCII_a <= c2 && c2 <= ASCII_z)
c2 += ASCII_A - ASCII_a;
/* The following line will never get executed. streqci() is
* only called from two places, both of which guarantee to put
* upper-case strings into s2.
*/
c2 += ASCII_A - ASCII_a; /* LCOV_EXCL_LINE */
if (c1 != c2)
return 0;
if (!c1)
@@ -1293,7 +1348,7 @@ XmlUtf8Encode(int c, char *buf)
};
if (c < 0)
return 0;
return 0; /* LCOV_EXCL_LINE: this case is always eliminated beforehand */
if (c < min2) {
buf[0] = (char)(c | UTF8_cval1);
return 1;
@@ -1316,7 +1371,7 @@ XmlUtf8Encode(int c, char *buf)
buf[3] = (char)((c & 0x3f) | 0x80);
return 4;
}
return 0;
return 0; /* LCOV_EXCL_LINE: this case too is eliminated before calling */
}
int FASTCALL
@@ -1409,9 +1464,8 @@ unknown_toUtf8(const ENCODING *enc,
return XML_CONVERT_OUTPUT_EXHAUSTED;
(*fromP)++;
}
do {
*(*toP)++ = *utf8++;
} while (--n != 0);
memcpy(*toP, utf8, n);
*toP += n;
}
}
@@ -1467,6 +1521,9 @@ XmlInitUnknownEncoding(void *mem,
else if (c < 0) {
if (c < -4)
return 0;
/* Multi-byte sequences need a converter function */
if (!convert)
return 0;
e->normal.type[i] = (unsigned char)(BT_LEAD2 - (c + 2));
e->utf8[i][0] = 0;
e->utf16[i] = 0;

View File

@@ -1,5 +1,33 @@
/* Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd
See the file COPYING for copying permission.
/*
__ __ _
___\ \/ /_ __ __ _| |_
/ _ \\ /| '_ \ / _` | __|
| __// \| |_) | (_| | |_
\___/_/\_\ .__/ \__,_|\__|
|_| XML parser
Copyright (c) 1997-2000 Thai Open Source Software Center Ltd
Copyright (c) 2000-2017 Expat development team
Licensed under the MIT license:
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to permit
persons to whom the Software is furnished to do so, subject to the
following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
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. 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.
*/
#ifndef XmlTok_INCLUDED
@@ -139,9 +167,6 @@ enum XML_Convert_Result {
struct encoding {
SCANNER scanners[XML_N_STATES];
SCANNER literalScanners[XML_N_LITERAL_TYPES];
int (PTRCALL *sameName)(const ENCODING *,
const char *,
const char *);
int (PTRCALL *nameMatchesAscii)(const ENCODING *,
const char *,
const char *,
@@ -232,8 +257,6 @@ struct encoding {
#define XmlEntityValueTok(enc, ptr, end, nextTokPtr) \
XmlLiteralTok(enc, XML_ENTITY_VALUE_LITERAL, ptr, end, nextTokPtr)
#define XmlSameName(enc, ptr1, ptr2) (((enc)->sameName)(enc, ptr1, ptr2))
#define XmlNameMatchesAscii(enc, ptr1, end1, ptr2) \
(((enc)->nameMatchesAscii)(enc, ptr1, end1, ptr2))

View File

@@ -1,8 +1,35 @@
/* Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd
See the file COPYING for copying permission.
/* This file is included!
__ __ _
___\ \/ /_ __ __ _| |_
/ _ \\ /| '_ \ / _` | __|
| __// \| |_) | (_| | |_
\___/_/\_\ .__/ \__,_|\__|
|_| XML parser
Copyright (c) 1997-2000 Thai Open Source Software Center Ltd
Copyright (c) 2000-2017 Expat development team
Licensed under the MIT license:
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to permit
persons to whom the Software is furnished to do so, subject to the
following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
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. 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.
*/
/* This file is included! */
#ifdef XML_TOK_IMPL_C
#ifndef IS_INVALID_CHAR
@@ -1198,8 +1225,14 @@ PREFIX(attributeValueTok)(const ENCODING *enc, const char *ptr,
const char *start;
if (ptr >= end)
return XML_TOK_NONE;
else if (! HAS_CHAR(enc, ptr, end))
return XML_TOK_PARTIAL;
else if (! HAS_CHAR(enc, ptr, end)) {
/* 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 XML_TOK_PARTIAL; /* LCOV_EXCL_LINE */
}
start = ptr;
while (HAS_CHAR(enc, ptr, end)) {
switch (BYTE_TYPE(enc, ptr)) {
@@ -1258,8 +1291,14 @@ PREFIX(entityValueTok)(const ENCODING *enc, const char *ptr,
const char *start;
if (ptr >= end)
return XML_TOK_NONE;
else if (! HAS_CHAR(enc, ptr, end))
return XML_TOK_PARTIAL;
else if (! HAS_CHAR(enc, ptr, end)) {
/* 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 XML_TOK_PARTIAL; /* LCOV_EXCL_LINE */
}
start = ptr;
while (HAS_CHAR(enc, ptr, end)) {
switch (BYTE_TYPE(enc, ptr)) {
@@ -1614,77 +1653,19 @@ PREFIX(predefinedEntityName)(const ENCODING *UNUSED_P(enc), const char *ptr,
return 0;
}
static int PTRCALL
PREFIX(sameName)(const ENCODING *enc, const char *ptr1, const char *ptr2)
{
for (;;) {
switch (BYTE_TYPE(enc, ptr1)) {
#define LEAD_CASE(n) \
case BT_LEAD ## n: \
if (*ptr1++ != *ptr2++) \
return 0;
LEAD_CASE(4) LEAD_CASE(3) LEAD_CASE(2)
#undef LEAD_CASE
/* fall through */
if (*ptr1++ != *ptr2++)
return 0;
break;
case BT_NONASCII:
case BT_NMSTRT:
#ifdef XML_NS
case BT_COLON:
#endif
case BT_HEX:
case BT_DIGIT:
case BT_NAME:
case BT_MINUS:
if (*ptr2++ != *ptr1++)
return 0;
if (MINBPC(enc) > 1) {
if (*ptr2++ != *ptr1++)
return 0;
if (MINBPC(enc) > 2) {
if (*ptr2++ != *ptr1++)
return 0;
if (MINBPC(enc) > 3) {
if (*ptr2++ != *ptr1++)
return 0;
}
}
}
break;
default:
if (MINBPC(enc) == 1 && *ptr1 == *ptr2)
return 1;
switch (BYTE_TYPE(enc, ptr2)) {
case BT_LEAD2:
case BT_LEAD3:
case BT_LEAD4:
case BT_NONASCII:
case BT_NMSTRT:
#ifdef XML_NS
case BT_COLON:
#endif
case BT_HEX:
case BT_DIGIT:
case BT_NAME:
case BT_MINUS:
return 0;
default:
return 1;
}
}
}
/* not reached */
}
static int PTRCALL
PREFIX(nameMatchesAscii)(const ENCODING *UNUSED_P(enc), const char *ptr1,
const char *end1, const char *ptr2)
{
for (; *ptr2; ptr1 += MINBPC(enc), ptr2++) {
if (end1 - ptr1 < MINBPC(enc))
return 0;
if (end1 - ptr1 < MINBPC(enc)) {
/* This line cannot be executed. THe incoming data has already
* been tokenized once, so imcomplete 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))
return 0;
}

View File

@@ -1,6 +1,33 @@
/*
Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd
See the file COPYING for copying permission.
__ __ _
___\ \/ /_ __ __ _| |_
/ _ \\ /| '_ \ / _` | __|
| __// \| |_) | (_| | |_
\___/_/\_\ .__/ \__,_|\__|
|_| XML parser
Copyright (c) 1997-2000 Thai Open Source Software Center Ltd
Copyright (c) 2000-2017 Expat development team
Licensed under the MIT license:
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to permit
persons to whom the Software is furnished to do so, subject to the
following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
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. 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.
*/
enum {

View File

@@ -1,8 +1,35 @@
/* Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd
See the file COPYING for copying permission.
/* This file is included!
__ __ _
___\ \/ /_ __ __ _| |_
/ _ \\ /| '_ \ / _` | __|
| __// \| |_) | (_| | |_
\___/_/\_\ .__/ \__,_|\__|
|_| XML parser
Copyright (c) 1997-2000 Thai Open Source Software Center Ltd
Copyright (c) 2000-2017 Expat development team
Licensed under the MIT license:
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to permit
persons to whom the Software is furnished to do so, subject to the
following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
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. 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.
*/
/* This file is included! */
#ifdef XML_TOK_NS_C
const ENCODING *

View File

@@ -75,6 +75,11 @@
#include "hbexpat.ch"
#if defined( HB_OS_DARWIN ) && defined( __clang__ )
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wunguarded-availability"
#endif
#define _VAR_xUserData 0
#define _VAR_xEncodingHandlerData 1
#define _VAR_bStartElementHandler 2
@@ -109,12 +114,12 @@ typedef struct _HB_EXPAT
/* Skeleton wrapper for all single handler setters */
#define HB_EXPAT_SETHANDLER( _nameu_, _name_ ) \
HB_FUNC( XML_SET##_nameu_ ) \
{ \
if( PHB_EXPAT_is( 1 ) ) \
{ \
PHB_EXPAT hb_expat = PHB_EXPAT_par( 1 ); \
\
hb_expat_setvar( hb_expat, _VAR_b##_name_, hb_param( 2, HB_IT_BLOCK | HB_IT_SYMBOL ) ); \
if( hb_expat ) \
{ \
hb_expat_setvar( hb_expat, _VAR_b##_name_, hb_param( 2, HB_IT_EVALITEM ) ); \
\
XML_Set##_name_/* do not delete this */ ( hb_expat->parser, hb_expat->pVar[ _VAR_b##_name_ ] ? hb_expat_##_name_ : NULL ); \
\
@@ -128,7 +133,7 @@ typedef struct _HB_EXPAT
static void * XMLCALL hb_expat_xgrab( size_t size )
{
return hb_xgrab( size );
return size > 0 ? hb_xgrab( size ) : NULL;
}
static void XMLCALL hb_expat_xfree( void * p )
@@ -139,7 +144,7 @@ static void XMLCALL hb_expat_xfree( void * p )
static void * XMLCALL hb_expat_xrealloc( void * p, size_t size )
{
return hb_xrealloc( p, size );
return size > 0 ? ( p ? hb_xrealloc( p, size ) : hb_xgrab( size ) ) : NULL;
}
/* --- Callbacks --- */
@@ -361,10 +366,10 @@ static int XMLCALL hb_expat_UnknownEncodingHandler( void * userdata,
if( iResult == XML_STATUS_OK )
{
HB_UINT tmp;
HB_SIZE nPos;
for( tmp = 0; tmp < HB_SIZEOFARRAY( info->map ); ++tmp )
info->map[ tmp ] = hb_arrayGetNI( pPar2, tmp + 1 );
for( nPos = 0; nPos < HB_SIZEOFARRAY( info->map ); ++nPos )
info->map[ nPos ] = hb_arrayGetNI( pPar2, nPos + 1 );
/* NOTE: Not supported by wrapper layer yet. */
info->data = NULL;
@@ -647,7 +652,7 @@ static int XMLCALL hb_expat_NotStandaloneHandler( void * userdata )
static void PHB_EXPAT_free( PHB_EXPAT hb_expat, HB_BOOL bFree )
{
HB_UINT tmp;
unsigned int tmp;
for( tmp = 0; tmp < HB_SIZEOFARRAY( hb_expat->pVar ); ++tmp )
{
@@ -673,10 +678,8 @@ static HB_GARBAGE_FUNC( PHB_EXPAT_release )
/* Check if pointer is not NULL to avoid multiple freeing */
if( hb_expat_ptr && *hb_expat_ptr )
{
PHB_EXPAT hb_expat = *hb_expat_ptr;
/* Destroy the object */
PHB_EXPAT_free( hb_expat, HB_TRUE );
PHB_EXPAT_free( *hb_expat_ptr, HB_TRUE );
*hb_expat_ptr = NULL;
}
}
@@ -688,7 +691,7 @@ static HB_GARBAGE_FUNC( PHB_EXPAT_mark )
if( hb_expat_ptr && *hb_expat_ptr )
{
PHB_EXPAT hb_expat = *hb_expat_ptr;
HB_UINT tmp;
unsigned int tmp;
for( tmp = 0; tmp < HB_SIZEOFARRAY( hb_expat->pVar ); ++tmp )
{
@@ -704,11 +707,6 @@ static const HB_GC_FUNCS s_gcEXPATFuncs =
PHB_EXPAT_mark
};
static void * PHB_EXPAT_is( int iParam )
{
return hb_parptrGC( &s_gcEXPATFuncs, iParam );
}
static PHB_EXPAT PHB_EXPAT_par( int iParam )
{
void ** ph = ( void ** ) hb_parptrGC( &s_gcEXPATFuncs, iParam );
@@ -757,9 +755,8 @@ HB_FUNC( XML_PARSERCREATE )
if( parser )
{
PHB_EXPAT hb_expat = ( PHB_EXPAT ) hb_xgrab( sizeof( HB_EXPAT ) );
PHB_EXPAT hb_expat = ( PHB_EXPAT ) hb_xgrabz( sizeof( HB_EXPAT ) );
memset( hb_expat, 0, sizeof( HB_EXPAT ) );
hb_expat->parser = parser;
XML_SetUserData( hb_expat->parser, hb_expat );
@@ -773,8 +770,6 @@ HB_FUNC( XML_PARSERCREATE )
}
HB_FUNC( XML_PARSERRESET )
{
if( PHB_EXPAT_is( 1 ) )
{
PHB_EXPAT hb_expat = PHB_EXPAT_par( 1 );
@@ -789,36 +784,22 @@ HB_FUNC( XML_PARSERRESET )
hb_strfree( hEncoding );
}
}
else
hb_errRT_BASE( EG_ARG, 2020, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
#if defined( HB_LEGACY_LEVEL5 )
HB_FUNC( XML_PARSERFREE )
{
if( PHB_EXPAT_is( 1 ) )
{
void ** ph = ( void ** ) hb_parptrGC( &s_gcEXPATFuncs, 1 );
if( ph && *ph )
{
PHB_EXPAT hb_expat = ( PHB_EXPAT ) *ph;
/* Destroy the object */
PHB_EXPAT_free( hb_expat, HB_TRUE );
*ph = NULL;
}
}
else
hb_errRT_BASE( EG_ARG, 2020, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
#endif
HB_FUNC( XML_SETUSERDATA )
{
if( PHB_EXPAT_is( 1 ) )
{
PHB_EXPAT hb_expat = PHB_EXPAT_par( 1 );
if( hb_expat )
{
hb_expat_setvar( hb_expat, _VAR_xUserData, hb_param( 2, HB_IT_ANY ) );
hb_ret();
@@ -828,25 +809,23 @@ HB_FUNC( XML_SETUSERDATA )
}
HB_FUNC( XML_GETUSERDATA )
{
if( PHB_EXPAT_is( 1 ) )
{
PHB_EXPAT hb_expat = PHB_EXPAT_par( 1 );
if( hb_expat )
hb_itemReturnRelease( hb_itemNew( hb_expat->pVar[ _VAR_xUserData ] ) );
}
else
hb_errRT_BASE( EG_ARG, 2020, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( XML_SETELEMENTHANDLER )
{
if( PHB_EXPAT_is( 1 ) )
{
PHB_EXPAT hb_expat = PHB_EXPAT_par( 1 );
hb_expat_setvar( hb_expat, _VAR_bStartElementHandler, hb_param( 2, HB_IT_BLOCK | HB_IT_SYMBOL ) );
hb_expat_setvar( hb_expat, _VAR_bEndElementHandler, hb_param( 3, HB_IT_BLOCK | HB_IT_SYMBOL ) );
if( hb_expat )
{
hb_expat_setvar( hb_expat, _VAR_bStartElementHandler, hb_param( 2, HB_IT_EVALITEM ) );
hb_expat_setvar( hb_expat, _VAR_bEndElementHandler, hb_param( 3, HB_IT_EVALITEM ) );
XML_SetElementHandler( hb_expat->parser,
hb_expat->pVar[ _VAR_bStartElementHandler ] ? hb_expat_StartElementHandler : NULL,
@@ -859,13 +838,13 @@ HB_FUNC( XML_SETELEMENTHANDLER )
}
HB_FUNC( XML_SETCDATASECTIONHANDLER )
{
if( PHB_EXPAT_is( 1 ) )
{
PHB_EXPAT hb_expat = PHB_EXPAT_par( 1 );
hb_expat_setvar( hb_expat, _VAR_bStartCdataSectionHandler, hb_param( 2, HB_IT_BLOCK | HB_IT_SYMBOL ) );
hb_expat_setvar( hb_expat, _VAR_bEndCdataSectionHandler, hb_param( 3, HB_IT_BLOCK | HB_IT_SYMBOL ) );
if( hb_expat )
{
hb_expat_setvar( hb_expat, _VAR_bStartCdataSectionHandler, hb_param( 2, HB_IT_EVALITEM ) );
hb_expat_setvar( hb_expat, _VAR_bEndCdataSectionHandler, hb_param( 3, HB_IT_EVALITEM ) );
XML_SetCdataSectionHandler( hb_expat->parser,
hb_expat->pVar[ _VAR_bStartCdataSectionHandler ] ? hb_expat_StartCdataSectionHandler : NULL,
@@ -878,13 +857,13 @@ HB_FUNC( XML_SETCDATASECTIONHANDLER )
}
HB_FUNC( XML_SETNAMESPACEDECLHANDLER )
{
if( PHB_EXPAT_is( 1 ) )
{
PHB_EXPAT hb_expat = PHB_EXPAT_par( 1 );
hb_expat_setvar( hb_expat, _VAR_bStartNamespaceDeclHandler, hb_param( 2, HB_IT_BLOCK | HB_IT_SYMBOL ) );
hb_expat_setvar( hb_expat, _VAR_bEndNamespaceDeclHandler, hb_param( 3, HB_IT_BLOCK | HB_IT_SYMBOL ) );
if( hb_expat )
{
hb_expat_setvar( hb_expat, _VAR_bStartNamespaceDeclHandler, hb_param( 2, HB_IT_EVALITEM ) );
hb_expat_setvar( hb_expat, _VAR_bEndNamespaceDeclHandler, hb_param( 3, HB_IT_EVALITEM ) );
XML_SetNamespaceDeclHandler( hb_expat->parser,
hb_expat->pVar[ _VAR_bStartNamespaceDeclHandler ] ? hb_expat_StartNamespaceDeclHandler : NULL,
@@ -897,12 +876,12 @@ HB_FUNC( XML_SETNAMESPACEDECLHANDLER )
}
HB_FUNC( XML_SETUNKNOWNENCODINGHANDLER )
{
if( PHB_EXPAT_is( 1 ) )
{
PHB_EXPAT hb_expat = PHB_EXPAT_par( 1 );
hb_expat_setvar( hb_expat, _VAR_bUnknownEncodingHandler, hb_param( 2, HB_IT_BLOCK | HB_IT_SYMBOL ) );
if( hb_expat )
{
hb_expat_setvar( hb_expat, _VAR_bUnknownEncodingHandler, hb_param( 2, HB_IT_EVALITEM ) );
hb_expat_setvar( hb_expat, _VAR_xEncodingHandlerData, hb_param( 3, HB_IT_ANY ) );
XML_SetUnknownEncodingHandler( hb_expat->parser,
@@ -916,25 +895,21 @@ HB_FUNC( XML_SETUNKNOWNENCODINGHANDLER )
}
HB_FUNC( XML_PARSE )
{
if( PHB_EXPAT_is( 1 ) )
{
PHB_EXPAT hb_expat = PHB_EXPAT_par( 1 );
if( hb_expat )
hb_retni( XML_Parse( hb_expat->parser, hb_parcx( 2 ), ( int ) hb_parclen( 2 ), ( int ) hb_parl( 3 ) ) );
}
else
hb_errRT_BASE( EG_ARG, 2020, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( XML_GETERRORCODE )
{
if( PHB_EXPAT_is( 1 ) )
{
PHB_EXPAT hb_expat = PHB_EXPAT_par( 1 );
if( hb_expat )
hb_retni( ( int ) XML_GetErrorCode( hb_expat->parser ) );
}
else
hb_errRT_BASE( EG_ARG, 2020, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
@@ -945,58 +920,51 @@ HB_FUNC( XML_ERRORSTRING )
}
HB_FUNC( XML_GETCURRENTBYTEINDEX )
{
if( PHB_EXPAT_is( 1 ) )
{
PHB_EXPAT hb_expat = PHB_EXPAT_par( 1 );
if( hb_expat )
hb_retns( XML_GetCurrentByteIndex( hb_expat->parser ) );
}
else
hb_errRT_BASE( EG_ARG, 2020, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( XML_GETCURRENTLINENUMBER )
{
if( PHB_EXPAT_is( 1 ) )
{
PHB_EXPAT hb_expat = PHB_EXPAT_par( 1 );
if( hb_expat )
hb_retns( XML_GetCurrentLineNumber( hb_expat->parser ) );
}
else
hb_errRT_BASE( EG_ARG, 2020, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( XML_GETCURRENTCOLUMNNUMBER )
{
if( PHB_EXPAT_is( 1 ) )
{
PHB_EXPAT hb_expat = PHB_EXPAT_par( 1 );
if( hb_expat )
hb_retns( XML_GetCurrentColumnNumber( hb_expat->parser ) );
}
else
hb_errRT_BASE( EG_ARG, 2020, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( XML_GETCURRENTBYTECOUNT )
{
if( PHB_EXPAT_is( 1 ) )
{
PHB_EXPAT hb_expat = PHB_EXPAT_par( 1 );
if( hb_expat )
hb_retni( XML_GetCurrentByteCount( hb_expat->parser ) );
}
else
hb_errRT_BASE( EG_ARG, 2020, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( XML_SETBASE )
{
if( PHB_EXPAT_is( 1 ) )
{
PHB_EXPAT hb_expat = PHB_EXPAT_par( 1 );
if( hb_expat )
{
void * hBase;
hb_retni( ( int ) XML_SetBase( hb_expat->parser, hb_parstr_utf8( 1, &hBase, NULL ) ) );
@@ -1008,46 +976,41 @@ HB_FUNC( XML_SETBASE )
}
HB_FUNC( XML_GETBASE )
{
if( PHB_EXPAT_is( 1 ) )
{
PHB_EXPAT hb_expat = PHB_EXPAT_par( 1 );
if( hb_expat )
hb_retstr_utf8( XML_GetBase( hb_expat->parser ) );
}
else
hb_errRT_BASE( EG_ARG, 2020, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( XML_GETSPECIFIEDATTRIBUTECOUNT )
{
if( PHB_EXPAT_is( 1 ) )
{
PHB_EXPAT hb_expat = PHB_EXPAT_par( 1 );
if( hb_expat )
hb_retni( XML_GetSpecifiedAttributeCount( hb_expat->parser ) );
}
else
hb_errRT_BASE( EG_ARG, 2020, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( XML_GETIDATTRIBUTEINDEX )
{
if( PHB_EXPAT_is( 1 ) )
{
PHB_EXPAT hb_expat = PHB_EXPAT_par( 1 );
if( hb_expat )
hb_retni( XML_GetIdAttributeIndex( hb_expat->parser ) );
}
else
hb_errRT_BASE( EG_ARG, 2020, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( XML_SETENCODING )
{
if( PHB_EXPAT_is( 1 ) )
{
PHB_EXPAT hb_expat = PHB_EXPAT_par( 1 );
if( hb_expat )
{
void * hEncoding;
hb_retni( ( int ) XML_SetEncoding( hb_expat->parser,
@@ -1060,35 +1023,31 @@ HB_FUNC( XML_SETENCODING )
}
HB_FUNC( XML_SETPARAMENTITYPARSING )
{
if( PHB_EXPAT_is( 1 ) )
{
PHB_EXPAT hb_expat = PHB_EXPAT_par( 1 );
if( hb_expat )
hb_retni( XML_SetParamEntityParsing( hb_expat->parser, ( enum XML_ParamEntityParsing ) hb_parni( 2 ) ) );
}
else
hb_errRT_BASE( EG_ARG, 2020, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( XML_USEFOREIGNDTD )
{
if( PHB_EXPAT_is( 1 ) )
{
PHB_EXPAT hb_expat = PHB_EXPAT_par( 1 );
if( hb_expat )
hb_retni( ( int ) XML_UseForeignDTD( hb_expat->parser, ( XML_Bool ) hb_parl( 2 ) ) );
}
else
hb_errRT_BASE( EG_ARG, 2020, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( XML_SETRETURNNSTRIPLET )
{
if( PHB_EXPAT_is( 1 ) )
{
PHB_EXPAT hb_expat = PHB_EXPAT_par( 1 );
if( hb_expat )
{
XML_SetReturnNSTriplet( hb_expat->parser, hb_parni( 2 ) );
hb_ret();
@@ -1098,11 +1057,11 @@ HB_FUNC( XML_SETRETURNNSTRIPLET )
}
HB_FUNC( XML_DEFAULTCURRENT )
{
if( PHB_EXPAT_is( 1 ) )
{
PHB_EXPAT hb_expat = PHB_EXPAT_par( 1 );
if( hb_expat )
{
XML_DefaultCurrent( hb_expat->parser );
hb_ret();
@@ -1113,11 +1072,11 @@ HB_FUNC( XML_DEFAULTCURRENT )
HB_FUNC( XML_STOPPARSER )
{
if( PHB_EXPAT_is( 1 ) )
{
#if HB_EXPAT_VERS( 1, 95, 8 )
PHB_EXPAT hb_expat = PHB_EXPAT_par( 1 );
if( hb_expat )
{
#if HB_EXPAT_VERS( 1, 95, 8 )
hb_retni( ( int ) XML_StopParser( hb_expat->parser, ( XML_Bool ) hb_parl( 2 ) ) );
#else
hb_retni( HB_XML_ERROR_NOT_IMPLEMENTED_ );
@@ -1129,11 +1088,11 @@ HB_FUNC( XML_STOPPARSER )
HB_FUNC( XML_RESUMEPARSER )
{
if( PHB_EXPAT_is( 1 ) )
{
#if HB_EXPAT_VERS( 1, 95, 8 )
PHB_EXPAT hb_expat = PHB_EXPAT_par( 1 );
if( hb_expat )
{
#if HB_EXPAT_VERS( 1, 95, 8 )
hb_retni( ( int ) XML_ResumeParser( hb_expat->parser ) );
#else
hb_retni( HB_XML_ERROR_NOT_IMPLEMENTED_ );
@@ -1145,10 +1104,11 @@ HB_FUNC( XML_RESUMEPARSER )
HB_FUNC( XML_GETPARSINGSTATUS )
{
if( PHB_EXPAT_is( 1 ) )
PHB_EXPAT hb_expat = PHB_EXPAT_par( 1 );
if( hb_expat )
{
#if HB_EXPAT_VERS( 1, 95, 8 )
PHB_EXPAT hb_expat = PHB_EXPAT_par( 1 );
XML_ParsingStatus status;
XML_GetParsingStatus( hb_expat->parser, &status );
@@ -1166,11 +1126,11 @@ HB_FUNC( XML_GETPARSINGSTATUS )
HB_FUNC( XML_SETHASHSALT )
{
if( PHB_EXPAT_is( 1 ) )
{
#if HB_EXPAT_VERS( 2, 1, 0 )
PHB_EXPAT hb_expat = PHB_EXPAT_par( 1 );
if( hb_expat )
{
#if HB_EXPAT_VERS( 2, 1, 0 )
hb_retni( XML_SetHashSalt( hb_expat->parser, ( unsigned long ) hb_parnint( 2 ) ) );
#else
hb_retni( 0 );

View File

@@ -39,7 +39,6 @@ DYNAMIC XML_GetSpecifiedAttributeCount
DYNAMIC XML_GetUserData
DYNAMIC XML_Parse
DYNAMIC XML_ParserCreate
DYNAMIC XML_ParserFree
DYNAMIC XML_ParserReset
DYNAMIC XML_ResumeParser
DYNAMIC XML_SetAttlistDeclHandler
@@ -73,7 +72,7 @@ DYNAMIC XML_SetUserData
DYNAMIC XML_SetXMLDeclHandler
DYNAMIC XML_StopParser
DYNAMIC XML_UseForeignDTD
DYNAMIC __hb_XML_CdpU16Map
DYNAMIC __hb_XML_cdpU16Map
#if defined( __HBEXTREQ__ ) .OR. defined( __HBEXTERN__HBEXPAT__REQUEST )
#uncommand DYNAMIC <fncs,...> => EXTERNAL <fncs>

View File

@@ -44,6 +44,7 @@
*
*/
#include "hbapi.h"
#include "hbapicdp.h"
#include "hbapiitm.h"

View File

@@ -1,85 +1,82 @@
/*
*
* Copyright 2010 Viktor Szakats (vszakats.net/harbour)
*
*/
/* Copyright 2010 Viktor Szakats (vszakats.net/harbour) */
#require "hbexpat"
#include "simpleio.ch"
REQUEST HB_CODEPAGE_UTF8EX
PROCEDURE Main( cFileName )
LOCAL p := XML_ParserCreate()
LOCAL xData
LOCAL aUserData
LOCAL v1, v2, v3
IF cFileName == NIL
cFileName := hb_DirBase() + "test.xml"
ENDIF
hb_cdpSelect( "UTF8EX" )
hb_SetTermCP( hb_cdpTerm() )
OutStd( XML_ExpatVersion(), hb_eol() )
? XML_ExpatVersion()
XML_ExpatVersionInfo( @v1, @v2, @v3 )
OutStd( v1, v2, v3, hb_eol() )
? hb_ntos( v1 ) + "." + hb_ntos( v2 ) + "." + hb_ntos( v3 )
hb_XML_ExpatVersionInfo( @v1, @v2, @v3 )
OutStd( v1, v2, v3, hb_eol() )
? hb_ntos( v1 ) + "." + hb_ntos( v2 ) + "." + hb_ntos( v3 )
IF Empty( p )
OutErr( "Couldn't allocate memory for parser", hb_eol() )
? "Couldn't allocate memory for parser"
ErrorLevel( -1 )
RETURN
ENDIF
xData := Array( 1 )
xData[ 1 ] := 1
aUserData := Array( 1 )
aUserData[ 1 ] := 1
OutStd( XML_GetUserData( p ), hb_eol() )
XML_SetUserData( p, xData )
OutStd( ValType( XML_GetUserData( p ) ), hb_eol() )
? XML_GetUserData( p )
XML_SetUserData( p, aUserData )
? ValType( XML_GetUserData( p ) )
XML_SetElementHandler( p, {| x, e, a | cb_start( x, e, a ) }, {| x, e | cb_end( x, e ) } )
XML_SetCharacterDataHandler( p, {| x, d | cb_data( x, d ) } )
IF XML_Parse( p, MemoRead( cFileName ), .T. ) == HB_XML_STATUS_ERROR
OutErr( hb_StrFormat( e"Parse error at line %s:\n%s\n", ;
hb_ntos( XML_GetCurrentLineNumber( p ) ), ;
XML_ErrorString( XML_GetErrorCode( p ) ) ) )
IF XML_Parse( p, MemoRead( hb_defaultValue( cFileName, hb_DirBase() + "test.xml" ) ), .T. ) == HB_XML_STATUS_ERROR
? hb_StrFormat( e"Parse error at line %1$d:\n%2$s", ;
XML_GetCurrentLineNumber( p ), ;
XML_ErrorString( XML_GetErrorCode( p ) ) )
ErrorLevel( -1 )
RETURN
ENDIF
RETURN
STATIC PROCEDURE cb_start( xData, cElement, aAttr )
STATIC PROCEDURE cb_start( aUserData, cElement, aAttr )
LOCAL aItem
OutStd( Replicate( " ", xData[ 1 ] ), cElement )
? Replicate( " ", aUserData[ 1 ] ), cElement
IF ! Empty( aAttr )
FOR EACH aItem IN aAttr
OutStd( " " + aItem[ HB_XML_ATTR_cName ] + "='" + aItem[ HB_XML_ATTR_cValue ] + "'" )
?? "", aItem[ HB_XML_ATTR_cName ] + "='" + aItem[ HB_XML_ATTR_cValue ] + "'"
NEXT
ENDIF
OutStd( hb_eol() )
++xData[ 1 ]
++aUserData[ 1 ]
RETURN
STATIC PROCEDURE cb_end( xData, cElement )
STATIC PROCEDURE cb_end( aUserData, cElement )
HB_SYMBOL_UNUSED( xData )
HB_SYMBOL_UNUSED( aUserData )
HB_SYMBOL_UNUSED( cElement )
--xData[ 1 ]
--aUserData[ 1 ]
RETURN
STATIC PROCEDURE cb_data( xData, cData )
STATIC PROCEDURE cb_data( aUserData, cData )
HB_SYMBOL_UNUSED( xData )
HB_SYMBOL_UNUSED( aUserData )
IF ! Empty( cData )
OutStd( ">" + cData + "<" )
?? "", "'" + cData + "'"
ENDIF
RETURN

View File

@@ -78,7 +78,7 @@
<item row="2" column="5">
<widget class="QPushButton" name="buttonSaveAs">
<property name="text">
<string>SaveAs</string>
<string>Copyright © Text</string>
</property>
</widget>
</item>

View File

@@ -2,6 +2,8 @@
#require "hbexpat"
#include "simpleio.ch"
#define _D_aTree 1
#define _D_aNode 2
#define _D_MAX_ 2
@@ -12,7 +14,6 @@
#define _N_hAttr 4
#define _N_MAX_ 4
REQUEST HB_CODEPAGE_UTF8
REQUEST HB_CODEPAGE_UTF8EX
PROCEDURE Main( cFileName )
@@ -23,19 +24,16 @@ PROCEDURE Main( cFileName )
LOCAL v1, v2, v3
hb_cdpSelect( "UTF8EX" )
hb_SetTermCP( hb_cdpTerm() )
IF cFileName == NIL
cFileName := hb_DirBase() + "test.xml"
ENDIF
OutStd( XML_ExpatVersion() + hb_eol() )
? XML_ExpatVersion()
XML_ExpatVersionInfo( @v1, @v2, @v3 )
OutStd( hb_ntos( v1 ) + "." + hb_ntos( v2 ) + "." + hb_ntos( v3 ) + hb_eol() )
? hb_ntos( v1 ) + "." + hb_ntos( v2 ) + "." + hb_ntos( v3 )
hb_XML_ExpatVersionInfo( @v1, @v2, @v3 )
OutStd( hb_ntos( v1 ) + "." + hb_ntos( v2 ) + "." + hb_ntos( v3 ) + hb_eol() )
? hb_ntos( v1 ) + "." + hb_ntos( v2 ) + "." + hb_ntos( v3 )
IF Empty( p )
OutErr( "Couldn't allocate memory for parser" + hb_eol() )
? "Couldn't allocate memory for parser"
ErrorLevel( -1 )
RETURN
ENDIF
@@ -51,23 +49,27 @@ PROCEDURE Main( cFileName )
aNode[ _N_aParent ] := aUserData[ _D_aTree ]
OutStd( XML_GetUserData( p ) ) ; OutStd( hb_eol() )
? XML_GetUserData( p )
XML_SetUserData( p, aUserData )
OutStd( ValType( XML_GetUserData( p ) ) + hb_eol() )
? ValType( XML_GetUserData( p ) )
XML_SetElementHandler( p, {| x, e, a | cb_start( x, e, a ) }, {| x | cb_end( x ) } )
XML_SetCharacterDataHandler( p, {| x, d | cb_data( x, d ) } )
XML_SetUnknownEncodingHandler( p, {| x, e, i | cb_unknownencoding( x, e, i ) } )
XML_SetEndDoctypeDeclHandler( p, @cb_enddoctype() )
IF XML_Parse( p, MemoRead( cFileName ), .T. ) == HB_XML_STATUS_ERROR
OutErr( hb_StrFormat( e"Parse error at line %s:\n%s\n", ;
hb_ntos( XML_GetCurrentLineNumber( p ) ), ;
XML_ErrorString( XML_GetErrorCode( p ) ) ) )
IF XML_Parse( p, MemoRead( hb_defaultValue( cFileName, hb_DirBase() + "test.xml" ) ), .T. ) == HB_XML_STATUS_ERROR
? hb_StrFormat( e"Parse error at line %1$d:\n%2$s", ;
XML_GetCurrentLineNumber( p ), ;
XML_ErrorString( XML_GetErrorCode( p ) ) )
ErrorLevel( -1 )
RETURN
ENDIF
DUMP( aUserData[ _D_aTree ], 0 )
hb_MemoWrit( "json_raw.txt", hb_jsonEncode( aUserData[ _D_aTree ], .F. ) )
hb_MemoWrit( "json_hum.txt", hb_jsonEncode( aUserData[ _D_aTree ], .T. ) )
RETURN
STATIC PROCEDURE DUMP( hTree, n )
@@ -77,7 +79,7 @@ STATIC PROCEDURE DUMP( hTree, n )
FOR EACH aEl IN hTree[ _N_hChild ]
FOR EACH aNode IN aEl
OutStd( Replicate( " ", n ) + aEl:__enumKey() + ": '" + aNode[ _N_xValue ] + "'" + DUMPATTR( aNode[ _N_hAttr ] ) + hb_eol() )
? Replicate( " ", n ) + aEl:__enumKey() + ":", "'" + aNode[ _N_xValue ] + "'" + DUMPATTR( aNode[ _N_hAttr ] )
DUMP( aNode, n + 1 )
NEXT
NEXT
@@ -98,14 +100,16 @@ STATIC FUNCTION DUMPATTR( hAttr )
RETURN s
STATIC FUNCTION cb_enddoctype()
RETURN 0
STATIC FUNCTION cb_unknownencoding( xEData, cEncoding, aMap )
LOCAL aMyMap
HB_SYMBOL_UNUSED( xEData )
aMyMap := hb_XML_get_unicode_table( cEncoding )
IF ! Empty( aMyMap )
IF ! Empty( aMyMap := hb_XML_get_unicode_table( cEncoding ) )
ACopy( aMyMap, aMap )
RETURN HB_XML_STATUS_OK
ENDIF

View File

@@ -46,11 +46,11 @@
#include "hbextcdp.ch"
#define _UNI_NAME_NORM( s ) StrTran( StrTran( StrTran( s, "-" ), "." ), " " )
#define _UNI_NAME_NORM( s ) hb_StrReplace( s, "-. " )
FUNCTION hb_XML_get_unicode_table( cCP )
THREAD STATIC t_uni := NIL
THREAD STATIC t_uni
LOCAL cdp
@@ -62,9 +62,8 @@ FUNCTION hb_XML_get_unicode_table( cCP )
NEXT
ENDIF
cCP := _UNI_NAME_NORM( cCP )
IF cCP $ t_uni
RETURN __hb_XML_CdpU16Map( t_uni[ cCP ] )
IF ( cCP := _UNI_NAME_NORM( cCP ) ) $ t_uni
RETURN __hb_XML_cdpU16Map( t_uni[ cCP ] )
ENDIF
RETURN NIL

View File

@@ -6,7 +6,7 @@
-w3 -es2
-hbx=${hb_name}.hbx
${hb_name}.hbx
encurlc.c
mime.c

65
include/hbarc4.h Normal file
View File

@@ -0,0 +1,65 @@
/*
* Portable ARC4 PRNG, based on arc4random.c from Libevent.
* Harbour adaptation Copyright 2011 Tamas TEVESZ <ice@extreme.hu>
*/
/*
* Portable arc4random.c based on arc4random.c from OpenBSD.
* Portable version by Chris Davis, adapted for Libevent by Nick Mathewson
* Copyright (c) 2010 Chris Davis, Niels Provos, and Nick Mathewson
*/
/*
* Copyright (c) 1996, David Mazieres <dm@uun.org>
* Copyright (c) 2008, Damien Miller <djm@openbsd.org>
*
* 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" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/*
* Arc4 random number generator for OpenBSD.
*
* This code is derived from section 17.1 of Applied Cryptography,
* second edition, which describes a stream cipher allegedly
* compatible with RSA Labs "RC4" cipher (the actual description of
* which is a trade secret). The same algorithm is used as a stream
* cipher called "arcfour" in Tatu Ylonen's ssh package.
*
* Here the stream cipher has been modified always to include the time
* when initializing the state. That makes it impossible to
* regenerate the same random sequence twice, so this cannot be used
* for encryption, but will generate good random numbers.
*
* RC4 is a registered trademark of RSA Laboratories.
*/
/*
* Bit of a guesswork; possibly needs to be extended to other platforms,
* but on Unix-ish systems, seeding will fall back to using the
* /dev/random-variants.
*/
#ifndef ARC4_H
#define ARC4_H
#include "hbdefs.h"
HB_EXTERN_BEGIN
extern HB_EXPORT HB_U32 hb_arc4random( void );
extern HB_EXPORT void hb_arc4random_buf( void * _buf, HB_SIZE n );
extern HB_EXPORT HB_U32 hb_arc4random_uniform( HB_U32 upper_bound );
HB_EXTERN_END
#endif /* ARC4_H */

View File

@@ -1989,6 +1989,9 @@ gzungetc
gzvprintf
gzwrite
hb_adler32
hb_arc4random
hb_arc4random_buf
hb_arc4random_uniform
hb_arrayAdd
hb_arrayAddForward
hb_arrayBaseParams