mirror of
https://github.com/vxcontrol/lualibs-genx.git
synced 2026-07-01 17:54:37 -04:00
init
This commit is contained in:
Binary file not shown.
@@ -0,0 +1,21 @@
|
||||
Copyright (c) Tim Bray and Sun Microsystems, 2004.
|
||||
|
||||
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.
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
genx beta5 xml generator from http://www.tbray.org/ongoing/When/200x/2004/02/20/GenxStatus
|
||||
@@ -0,0 +1 @@
|
||||
gcc -shared -o ../../linux/bin/libgenx.so -s -O3 -Wall -pedantic genx.c charProps.c
|
||||
@@ -0,0 +1 @@
|
||||
gcc -shared -o ../../bin/genx.dll -s -O3 -Wall -pedantic genx.c charProps.c
|
||||
@@ -0,0 +1,378 @@
|
||||
/*
|
||||
* Copyright (c) 2004 by Tim Bray and Sun Microsystems. For copying
|
||||
* permission, see http://www.tbray.org/ongoing/genx/COPYING
|
||||
*/
|
||||
|
||||
/*
|
||||
* Construct character-properties tables for genx.
|
||||
* Quite likely there's a better way.
|
||||
* This version is generated semi-automatically from the source code of the
|
||||
* XML specification via emacs global replace and keyboard macros
|
||||
*/
|
||||
#include "genx.h"
|
||||
|
||||
static void charProp(char * p, int c, int prop)
|
||||
{
|
||||
p[c] |= prop;
|
||||
}
|
||||
|
||||
static void rangeProp(char * p, int start, int end, int prop)
|
||||
{
|
||||
int i;
|
||||
for (i = start; i <= end; i++)
|
||||
p[i] |= prop;
|
||||
}
|
||||
|
||||
void genxSetCharProps(char * p)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i <= 0xffff; i++)
|
||||
p[i] = 0;
|
||||
|
||||
/* per XML 1.0 */
|
||||
charProp(p, 0x9, GENX_XML_CHAR);
|
||||
charProp(p, 0xa, GENX_XML_CHAR);
|
||||
charProp(p, 0xd, GENX_XML_CHAR);
|
||||
rangeProp(p, 0x20, 0xd7ff, GENX_XML_CHAR);
|
||||
rangeProp(p, 0xe000, 0xfffd, GENX_XML_CHAR);
|
||||
|
||||
/* Letter ::= BaseChar | Ideographic */
|
||||
rangeProp(p, 0x0041, 0x005A, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0061, 0x007A, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x00C0, 0x00D6, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x00D8, 0x00F6, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x00F8, 0x00FF, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0100, 0x0131, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0134, 0x013E, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0141, 0x0148, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x014A, 0x017E, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0180, 0x01C3, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x01CD, 0x01F0, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x01F4, 0x01F5, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x01FA, 0x0217, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0250, 0x02A8, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x02BB, 0x02C1, GENX_LETTER|GENX_NAMECHAR);
|
||||
charProp(p, 0x0386, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0388, 0x038A, GENX_LETTER|GENX_NAMECHAR);
|
||||
charProp(p, 0x038C, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x038E, 0x03A1, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x03A3, 0x03CE, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x03D0, 0x03D6, GENX_LETTER|GENX_NAMECHAR);
|
||||
charProp(p, 0x03DA, GENX_LETTER|GENX_NAMECHAR);
|
||||
charProp(p, 0x03DC, GENX_LETTER|GENX_NAMECHAR);
|
||||
charProp(p, 0x03DE, GENX_LETTER|GENX_NAMECHAR);
|
||||
charProp(p, 0x03E0, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x03E2, 0x03F3, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0401, 0x040C, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x040E, 0x044F, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0451, 0x045C, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x045E, 0x0481, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0490, 0x04C4, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x04C7, 0x04C8, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x04CB, 0x04CC, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x04D0, 0x04EB, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x04EE, 0x04F5, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x04F8, 0x04F9, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0531, 0x0556, GENX_LETTER|GENX_NAMECHAR);
|
||||
charProp(p, 0x0559, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0561, 0x0586, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x05D0, 0x05EA, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x05F0, 0x05F2, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0621, 0x063A, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0641, 0x064A, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0671, 0x06B7, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x06BA, 0x06BE, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x06C0, 0x06CE, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x06D0, 0x06D3, GENX_LETTER|GENX_NAMECHAR);
|
||||
charProp(p, 0x06D5, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x06E5, 0x06E6, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0905, 0x0939, GENX_LETTER|GENX_NAMECHAR);
|
||||
charProp(p, 0x093D, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0958, 0x0961, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0985, 0x098C, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x098F, 0x0990, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0993, 0x09A8, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x09AA, 0x09B0, GENX_LETTER|GENX_NAMECHAR);
|
||||
charProp(p, 0x09B2, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x09B6, 0x09B9, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x09DC, 0x09DD, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x09DF, 0x09E1, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x09F0, 0x09F1, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0A05, 0x0A0A, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0A0F, 0x0A10, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0A13, 0x0A28, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0A2A, 0x0A30, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0A32, 0x0A33, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0A35, 0x0A36, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0A38, 0x0A39, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0A59, 0x0A5C, GENX_LETTER|GENX_NAMECHAR);
|
||||
charProp(p, 0x0A5E, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0A72, 0x0A74, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0A85, 0x0A8B, GENX_LETTER|GENX_NAMECHAR);
|
||||
charProp(p, 0x0A8D, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0A8F, 0x0A91, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0A93, 0x0AA8, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0AAA, 0x0AB0, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0AB2, 0x0AB3, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0AB5, 0x0AB9, GENX_LETTER|GENX_NAMECHAR);
|
||||
charProp(p, 0x0ABD, GENX_LETTER|GENX_NAMECHAR);
|
||||
charProp(p, 0x0AE0, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0B05, 0x0B0C, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0B0F, 0x0B10, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0B13, 0x0B28, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0B2A, 0x0B30, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0B32, 0x0B33, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0B36, 0x0B39, GENX_LETTER|GENX_NAMECHAR);
|
||||
charProp(p, 0x0B3D, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0B5C, 0x0B5D, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0B5F, 0x0B61, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0B85, 0x0B8A, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0B8E, 0x0B90, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0B92, 0x0B95, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0B99, 0x0B9A, GENX_LETTER|GENX_NAMECHAR);
|
||||
charProp(p, 0x0B9C, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0B9E, 0x0B9F, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0BA3, 0x0BA4, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0BA8, 0x0BAA, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0BAE, 0x0BB5, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0BB7, 0x0BB9, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0C05, 0x0C0C, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0C0E, 0x0C10, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0C12, 0x0C28, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0C2A, 0x0C33, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0C35, 0x0C39, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0C60, 0x0C61, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0C85, 0x0C8C, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0C8E, 0x0C90, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0C92, 0x0CA8, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0CAA, 0x0CB3, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0CB5, 0x0CB9, GENX_LETTER|GENX_NAMECHAR);
|
||||
charProp(p, 0x0CDE, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0CE0, 0x0CE1, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0D05, 0x0D0C, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0D0E, 0x0D10, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0D12, 0x0D28, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0D2A, 0x0D39, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0D60, 0x0D61, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0E01, 0x0E2E, GENX_LETTER|GENX_NAMECHAR);
|
||||
charProp(p, 0x0E30, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0E32, 0x0E33, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0E40, 0x0E45, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0E81, 0x0E82, GENX_LETTER|GENX_NAMECHAR);
|
||||
charProp(p, 0x0E84, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0E87, 0x0E88, GENX_LETTER|GENX_NAMECHAR);
|
||||
charProp(p, 0x0E8A, GENX_LETTER|GENX_NAMECHAR);
|
||||
charProp(p, 0x0E8D, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0E94, 0x0E97, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0E99, 0x0E9F, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0EA1, 0x0EA3, GENX_LETTER|GENX_NAMECHAR);
|
||||
charProp(p, 0x0EA5, GENX_LETTER|GENX_NAMECHAR);
|
||||
charProp(p, 0x0EA7, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0EAA, 0x0EAB, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0EAD, 0x0EAE, GENX_LETTER|GENX_NAMECHAR);
|
||||
charProp(p, 0x0EB0, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0EB2, 0x0EB3, GENX_LETTER|GENX_NAMECHAR);
|
||||
charProp(p, 0x0EBD, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0EC0, 0x0EC4, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0F40, 0x0F47, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0F49, 0x0F69, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x10A0, 0x10C5, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x10D0, 0x10F6, GENX_LETTER|GENX_NAMECHAR);
|
||||
charProp(p, 0x1100, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x1102, 0x1103, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x1105, 0x1107, GENX_LETTER|GENX_NAMECHAR);
|
||||
charProp(p, 0x1109, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x110B, 0x110C, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x110E, 0x1112, GENX_LETTER|GENX_NAMECHAR);
|
||||
charProp(p, 0x113C, GENX_LETTER|GENX_NAMECHAR);
|
||||
charProp(p, 0x113E, GENX_LETTER|GENX_NAMECHAR);
|
||||
charProp(p, 0x1140, GENX_LETTER|GENX_NAMECHAR);
|
||||
charProp(p, 0x114C, GENX_LETTER|GENX_NAMECHAR);
|
||||
charProp(p, 0x114E, GENX_LETTER|GENX_NAMECHAR);
|
||||
charProp(p, 0x1150, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x1154, 0x1155, GENX_LETTER|GENX_NAMECHAR);
|
||||
charProp(p, 0x1159, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x115F, 0x1161, GENX_LETTER|GENX_NAMECHAR);
|
||||
charProp(p, 0x1163, GENX_LETTER|GENX_NAMECHAR);
|
||||
charProp(p, 0x1165, GENX_LETTER|GENX_NAMECHAR);
|
||||
charProp(p, 0x1167, GENX_LETTER|GENX_NAMECHAR);
|
||||
charProp(p, 0x1169, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x116D, 0x116E, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x1172, 0x1173, GENX_LETTER|GENX_NAMECHAR);
|
||||
charProp(p, 0x1175, GENX_LETTER|GENX_NAMECHAR);
|
||||
charProp(p, 0x119E, GENX_LETTER|GENX_NAMECHAR);
|
||||
charProp(p, 0x11A8, GENX_LETTER|GENX_NAMECHAR);
|
||||
charProp(p, 0x11AB, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x11AE, 0x11AF, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x11B7, 0x11B8, GENX_LETTER|GENX_NAMECHAR);
|
||||
charProp(p, 0x11BA, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x11BC, 0x11C2, GENX_LETTER|GENX_NAMECHAR);
|
||||
charProp(p, 0x11EB, GENX_LETTER|GENX_NAMECHAR);
|
||||
charProp(p, 0x11F0, GENX_LETTER|GENX_NAMECHAR);
|
||||
charProp(p, 0x11F9, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x1E00, 0x1E9B, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x1EA0, 0x1EF9, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x1F00, 0x1F15, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x1F18, 0x1F1D, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x1F20, 0x1F45, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x1F48, 0x1F4D, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x1F50, 0x1F57, GENX_LETTER|GENX_NAMECHAR);
|
||||
charProp(p, 0x1F59, GENX_LETTER|GENX_NAMECHAR);
|
||||
charProp(p, 0x1F5B, GENX_LETTER|GENX_NAMECHAR);
|
||||
charProp(p, 0x1F5D, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x1F5F, 0x1F7D, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x1F80, 0x1FB4, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x1FB6, 0x1FBC, GENX_LETTER|GENX_NAMECHAR);
|
||||
charProp(p, 0x1FBE, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x1FC2, 0x1FC4, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x1FC6, 0x1FCC, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x1FD0, 0x1FD3, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x1FD6, 0x1FDB, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x1FE0, 0x1FEC, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x1FF2, 0x1FF4, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x1FF6, 0x1FFC, GENX_LETTER|GENX_NAMECHAR);
|
||||
charProp(p, 0x2126, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x212A, 0x212B, GENX_LETTER|GENX_NAMECHAR);
|
||||
charProp(p, 0x212E, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x2180, 0x2182, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x3041, 0x3094, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x30A1, 0x30FA, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x3105, 0x312C, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0xAC00, 0xD7A3, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x4E00, 0x9FA5, GENX_LETTER|GENX_NAMECHAR);
|
||||
charProp(p, 0x3007, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x3021, 0x3029, GENX_LETTER|GENX_NAMECHAR);
|
||||
|
||||
/*
|
||||
* NameChar ::=
|
||||
* Letter | Digit | '.' | '-' | '_' | ':' | CombiningChar | Extender
|
||||
*/
|
||||
rangeProp(p, 0x0030, 0x0039, GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0660, 0x0669, GENX_NAMECHAR);
|
||||
rangeProp(p, 0x06F0, 0x06F9, GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0966, 0x096F, GENX_NAMECHAR);
|
||||
rangeProp(p, 0x09E6, 0x09EF, GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0A66, 0x0A6F, GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0AE6, 0x0AEF, GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0B66, 0x0B6F, GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0BE7, 0x0BEF, GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0C66, 0x0C6F, GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0CE6, 0x0CEF, GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0D66, 0x0D6F, GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0E50, 0x0E59, GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0ED0, 0x0ED9, GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0F20, 0x0F29, GENX_NAMECHAR);
|
||||
|
||||
charProp(p, '.', GENX_NAMECHAR);
|
||||
charProp(p, '-', GENX_NAMECHAR);
|
||||
charProp(p, '_', GENX_NAMECHAR);
|
||||
|
||||
rangeProp(p, 0x0300, 0x0345, GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0360, 0x0361, GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0483, 0x0486, GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0591, 0x05A1, GENX_NAMECHAR);
|
||||
rangeProp(p, 0x05A3, 0x05B9, GENX_NAMECHAR);
|
||||
rangeProp(p, 0x05BB, 0x05BD, GENX_NAMECHAR);
|
||||
charProp(p, 0x05BF, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x05C1, 0x05C2, GENX_NAMECHAR);
|
||||
charProp(p, 0x05C4, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x064B, 0x0652, GENX_NAMECHAR);
|
||||
charProp(p, 0x0670, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x06D6, 0x06DC, GENX_NAMECHAR);
|
||||
rangeProp(p, 0x06DD, 0x06DF, GENX_NAMECHAR);
|
||||
rangeProp(p, 0x06E0, 0x06E4, GENX_NAMECHAR);
|
||||
rangeProp(p, 0x06E7, 0x06E8, GENX_NAMECHAR);
|
||||
rangeProp(p, 0x06EA, 0x06ED, GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0901, 0x0903, GENX_NAMECHAR);
|
||||
charProp(p, 0x093C, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x093E, 0x094C, GENX_NAMECHAR);
|
||||
charProp(p, 0x094D, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0951, 0x0954, GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0962, 0x0963, GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0981, 0x0983, GENX_NAMECHAR);
|
||||
charProp(p, 0x09BC, GENX_LETTER|GENX_NAMECHAR);
|
||||
charProp(p, 0x09BE, GENX_LETTER|GENX_NAMECHAR);
|
||||
charProp(p, 0x09BF, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x09C0, 0x09C4, GENX_NAMECHAR);
|
||||
rangeProp(p, 0x09C7, 0x09C8, GENX_NAMECHAR);
|
||||
rangeProp(p, 0x09CB, 0x09CD, GENX_NAMECHAR);
|
||||
charProp(p, 0x09D7, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x09E2, 0x09E3, GENX_NAMECHAR);
|
||||
charProp(p, 0x0A02, GENX_LETTER|GENX_NAMECHAR);
|
||||
charProp(p, 0x0A3C, GENX_LETTER|GENX_NAMECHAR);
|
||||
charProp(p, 0x0A3E, GENX_LETTER|GENX_NAMECHAR);
|
||||
charProp(p, 0x0A3F, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0A40, 0x0A42, GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0A47, 0x0A48, GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0A4B, 0x0A4D, GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0A70, 0x0A71, GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0A81, 0x0A83, GENX_NAMECHAR);
|
||||
charProp(p, 0x0ABC, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0ABE, 0x0AC5, GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0AC7, 0x0AC9, GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0ACB, 0x0ACD, GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0B01, 0x0B03, GENX_NAMECHAR);
|
||||
charProp(p, 0x0B3C, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0B3E, 0x0B43, GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0B47, 0x0B48, GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0B4B, 0x0B4D, GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0B56, 0x0B57, GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0B82, 0x0B83, GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0BBE, 0x0BC2, GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0BC6, 0x0BC8, GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0BCA, 0x0BCD, GENX_NAMECHAR);
|
||||
charProp(p, 0x0BD7, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0C01, 0x0C03, GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0C3E, 0x0C44, GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0C46, 0x0C48, GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0C4A, 0x0C4D, GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0C55, 0x0C56, GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0C82, 0x0C83, GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0CBE, 0x0CC4, GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0CC6, 0x0CC8, GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0CCA, 0x0CCD, GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0CD5, 0x0CD6, GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0D02, 0x0D03, GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0D3E, 0x0D43, GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0D46, 0x0D48, GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0D4A, 0x0D4D, GENX_NAMECHAR);
|
||||
charProp(p, 0x0D57, GENX_LETTER|GENX_NAMECHAR);
|
||||
charProp(p, 0x0E31, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0E34, 0x0E3A, GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0E47, 0x0E4E, GENX_NAMECHAR);
|
||||
charProp(p, 0x0EB1, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0EB4, 0x0EB9, GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0EBB, 0x0EBC, GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0EC8, 0x0ECD, GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0F18, 0x0F19, GENX_NAMECHAR);
|
||||
charProp(p, 0x0F35, GENX_LETTER|GENX_NAMECHAR);
|
||||
charProp(p, 0x0F37, GENX_LETTER|GENX_NAMECHAR);
|
||||
charProp(p, 0x0F39, GENX_LETTER|GENX_NAMECHAR);
|
||||
charProp(p, 0x0F3E, GENX_LETTER|GENX_NAMECHAR);
|
||||
charProp(p, 0x0F3F, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0F71, 0x0F84, GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0F86, 0x0F8B, GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0F90, 0x0F95, GENX_NAMECHAR);
|
||||
charProp(p, 0x0F97, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0F99, 0x0FAD, GENX_NAMECHAR);
|
||||
rangeProp(p, 0x0FB1, 0x0FB7, GENX_NAMECHAR);
|
||||
charProp(p, 0x0FB9, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x20D0, 0x20DC, GENX_NAMECHAR);
|
||||
charProp(p, 0x20E1, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x302A, 0x302F, GENX_NAMECHAR);
|
||||
charProp(p, 0x3099, GENX_LETTER|GENX_NAMECHAR);
|
||||
charProp(p, 0x309A, GENX_LETTER|GENX_NAMECHAR);
|
||||
|
||||
charProp(p, 0x00B7, GENX_LETTER|GENX_NAMECHAR);
|
||||
charProp(p, 0x02D0, GENX_LETTER|GENX_NAMECHAR);
|
||||
charProp(p, 0x02D1, GENX_LETTER|GENX_NAMECHAR);
|
||||
charProp(p, 0x0387, GENX_LETTER|GENX_NAMECHAR);
|
||||
charProp(p, 0x0640, GENX_LETTER|GENX_NAMECHAR);
|
||||
charProp(p, 0x0E46, GENX_LETTER|GENX_NAMECHAR);
|
||||
charProp(p, 0x0EC6, GENX_LETTER|GENX_NAMECHAR);
|
||||
charProp(p, 0x3005, GENX_LETTER|GENX_NAMECHAR);
|
||||
rangeProp(p, 0x3031, 0x3035, GENX_NAMECHAR);
|
||||
rangeProp(p, 0x309D, 0x309E, GENX_NAMECHAR);
|
||||
rangeProp(p, 0x30FC, 0x30FE, GENX_NAMECHAR);
|
||||
}
|
||||
+1940
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,287 @@
|
||||
|
||||
/*
|
||||
* genx - C-callable library for generating XML documents
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2004 by Tim Bray and Sun Microsystems. For copying
|
||||
* permission, see http://www.tbray.org/ongoing/genx/COPYING
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Note on error handling: genx routines mostly return
|
||||
* GENX_SUCCESS (guaranteed to be zero) in normal circumstances, one of
|
||||
* these other GENX_ values on a memory allocation or I/O failure or if the
|
||||
* call would result in non-well-formed output.
|
||||
* You can associate an error message with one of these codes explicitly
|
||||
* or with the most recent error using genxGetErrorMessage() and
|
||||
* genxLastErrorMessage(); see below.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
GENX_SUCCESS = 0,
|
||||
GENX_BAD_UTF8,
|
||||
GENX_NON_XML_CHARACTER,
|
||||
GENX_BAD_NAME,
|
||||
GENX_ALLOC_FAILED,
|
||||
GENX_BAD_NAMESPACE_NAME,
|
||||
GENX_INTERNAL_ERROR,
|
||||
GENX_DUPLICATE_PREFIX,
|
||||
GENX_SEQUENCE_ERROR,
|
||||
GENX_NO_START_TAG,
|
||||
GENX_IO_ERROR,
|
||||
GENX_MISSING_VALUE,
|
||||
GENX_MALFORMED_COMMENT,
|
||||
GENX_XML_PI_TARGET,
|
||||
GENX_MALFORMED_PI,
|
||||
GENX_DUPLICATE_ATTRIBUTE,
|
||||
GENX_ATTRIBUTE_IN_DEFAULT_NAMESPACE,
|
||||
GENX_DUPLICATE_NAMESPACE,
|
||||
GENX_BAD_DEFAULT_DECLARATION
|
||||
} genxStatus;
|
||||
|
||||
/* character types */
|
||||
#define GENX_XML_CHAR 1
|
||||
#define GENX_LETTER 2
|
||||
#define GENX_NAMECHAR 4
|
||||
|
||||
/* a UTF-8 string */
|
||||
typedef unsigned char * utf8;
|
||||
typedef const unsigned char * constUtf8;
|
||||
|
||||
/*
|
||||
* genx's own types
|
||||
*/
|
||||
typedef struct genxWriter_rec * genxWriter;
|
||||
typedef struct genxNamespace_rec * genxNamespace;
|
||||
typedef struct genxElement_rec * genxElement;
|
||||
typedef struct genxAttribute_rec * genxAttribute;
|
||||
|
||||
/*
|
||||
* Constructors, set/get
|
||||
*/
|
||||
|
||||
/*
|
||||
* Create a new writer. For generating multiple XML documents, it's most
|
||||
* efficient to re-use the same genx object. However, you can only write
|
||||
* one document at a time with a writer.
|
||||
* Returns NULL if it fails, which can only be due to an allocation failure.
|
||||
*/
|
||||
genxWriter genxNew(void * (*alloc)(void * userData, int bytes),
|
||||
void (* dealloc)(void * userData, void * data),
|
||||
void * userData);
|
||||
|
||||
/*
|
||||
* Dispose of a writer, freeing all associated memory
|
||||
*/
|
||||
void genxDispose(genxWriter w);
|
||||
|
||||
/*
|
||||
* Set/get
|
||||
*/
|
||||
|
||||
/*
|
||||
* The userdata pointer will be passed to memory-allocation
|
||||
* and I/O callbacks. If not set, genx will pass NULL
|
||||
*/
|
||||
void genxSetUserData(genxWriter w, void * userData);
|
||||
void * genxGetUserData(genxWriter w);
|
||||
|
||||
/*
|
||||
* User-provided memory allocator, if desired. For example, if you were
|
||||
* in an Apache module, you could arrange for genx to use ap_palloc by
|
||||
* making the pool accessible via the userData call.
|
||||
* The "dealloc" is to be used to free memory allocated with "alloc". If
|
||||
* alloc is provided but dealloc is NULL, genx will not attempt to free
|
||||
* the memory; this would be appropriate in an Apache context.
|
||||
* If "alloc" is not provided, genx routines use malloc() to allocate memory
|
||||
*/
|
||||
void genxSetAlloc(genxWriter w,
|
||||
void * (* alloc)(void * userData, int bytes));
|
||||
void genxSetDealloc(genxWriter w,
|
||||
void (* dealloc)(void * userData, void * data));
|
||||
void * (* genxGetAlloc(genxWriter w))(void * userData, int bytes);
|
||||
void (* genxGetDealloc(genxWriter w))(void * userData, void * data);
|
||||
|
||||
/*
|
||||
* Get the prefix associated with a namespace
|
||||
*/
|
||||
utf8 genxGetNamespacePrefix(genxNamespace ns);
|
||||
|
||||
/*
|
||||
* Declaration functions
|
||||
*/
|
||||
|
||||
/*
|
||||
* Declare a namespace. The provided prefix is the default but can be
|
||||
* overridden by genxAddNamespace. If no default prefiix is provided,
|
||||
* genx will generate one of the form g-%d.
|
||||
* On error, returns NULL and signals via statusp
|
||||
*/
|
||||
genxNamespace genxDeclareNamespace(genxWriter w,
|
||||
constUtf8 uri, constUtf8 prefix,
|
||||
genxStatus * statusP);
|
||||
|
||||
/*
|
||||
* Declare an element
|
||||
* If something failed, returns NULL and sets the status code via statusP
|
||||
*/
|
||||
genxElement genxDeclareElement(genxWriter w,
|
||||
genxNamespace ns, constUtf8 type,
|
||||
genxStatus * statusP);
|
||||
|
||||
/*
|
||||
* Declare an attribute
|
||||
*/
|
||||
genxAttribute genxDeclareAttribute(genxWriter w,
|
||||
genxNamespace ns,
|
||||
constUtf8 name, genxStatus * statusP);
|
||||
|
||||
/*
|
||||
* Writing XML
|
||||
*/
|
||||
|
||||
/*
|
||||
* Start a new document.
|
||||
*/
|
||||
genxStatus genxStartDocFile(genxWriter w, FILE * file);
|
||||
|
||||
/*
|
||||
* Caller-provided I/O package.
|
||||
* First form is for a null-terminated string.
|
||||
* for second, if you have s="abcdef" and want to send "abc", you'd call
|
||||
* sendBounded(userData, s, s + 3)
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
genxStatus (* send)(void * userData, constUtf8 s);
|
||||
genxStatus (* sendBounded)(void * userData, constUtf8 start, constUtf8 end);
|
||||
genxStatus (* flush)(void * userData);
|
||||
} genxSender;
|
||||
|
||||
genxStatus genxStartDocSender(genxWriter w, genxSender * sender);
|
||||
|
||||
/*
|
||||
* End a document. Calls "flush"
|
||||
*/
|
||||
genxStatus genxEndDocument(genxWriter w);
|
||||
|
||||
/*
|
||||
* Write a comment
|
||||
*/
|
||||
genxStatus genxComment(genxWriter w, constUtf8 text);
|
||||
|
||||
/*
|
||||
* Write a PI
|
||||
*/
|
||||
genxStatus genxPI(genxWriter w, constUtf8 target, constUtf8 text);
|
||||
|
||||
/*
|
||||
* Start an element
|
||||
*/
|
||||
genxStatus genxStartElementLiteral(genxWriter w,
|
||||
constUtf8 xmlns, constUtf8 type);
|
||||
|
||||
/*
|
||||
* Start a predeclared element
|
||||
* - element must have been declared
|
||||
*/
|
||||
genxStatus genxStartElement(genxElement e);
|
||||
|
||||
/*
|
||||
* Write an attribute
|
||||
*/
|
||||
genxStatus genxAddAttributeLiteral(genxWriter w, constUtf8 xmlns,
|
||||
constUtf8 name, constUtf8 value);
|
||||
|
||||
/*
|
||||
* Write a predeclared attribute
|
||||
*/
|
||||
genxStatus genxAddAttribute(genxAttribute a, constUtf8 value);
|
||||
|
||||
/*
|
||||
* add a namespace declaration
|
||||
*/
|
||||
genxStatus genxAddNamespace(genxNamespace ns, utf8 prefix);
|
||||
|
||||
/*
|
||||
* Clear default namespace declaration
|
||||
*/
|
||||
genxStatus genxUnsetDefaultNamespace(genxWriter w);
|
||||
|
||||
/*
|
||||
* Write an end tag
|
||||
*/
|
||||
genxStatus genxEndElement(genxWriter w);
|
||||
|
||||
/*
|
||||
* Write some text
|
||||
* You can't write any text outside the root element, except with
|
||||
* genxComment and genxPI
|
||||
*/
|
||||
genxStatus genxAddText(genxWriter w, constUtf8 start);
|
||||
genxStatus genxAddCountedText(genxWriter w, constUtf8 start, int byteCount);
|
||||
genxStatus genxAddBoundedText(genxWriter w, constUtf8 start, constUtf8 end);
|
||||
|
||||
/*
|
||||
* Write one character. The integer value is the Unicode character
|
||||
* value, as usually expressed in U+XXXX notation.
|
||||
*/
|
||||
genxStatus genxAddCharacter(genxWriter w, int c);
|
||||
|
||||
/*
|
||||
* Utility routines
|
||||
*/
|
||||
|
||||
/*
|
||||
* Return the Unicode character encoded by the UTF-8 pointed-to by the
|
||||
* argument, and advance the argument past the encoding of the character.
|
||||
* Returns -1 if the UTF-8 is malformed, in which case advances the
|
||||
* argument to point at the first byte past the point past the malformed
|
||||
* ones.
|
||||
*/
|
||||
int genxNextUnicodeChar(constUtf8 * sp);
|
||||
|
||||
/*
|
||||
* Scan a buffer allegedly full of UTF-8 encoded XML characters; return
|
||||
* one of GENX_SUCCESS, GENX_BAD_UTF8, or GENX_NON_XML_CHARACTER
|
||||
*/
|
||||
genxStatus genxCheckText(genxWriter w, constUtf8 s);
|
||||
|
||||
/*
|
||||
* return character status, the OR of GENX_XML_CHAR,
|
||||
* GENX_LETTER, and GENX_NAMECHAR
|
||||
*/
|
||||
int genxCharClass(genxWriter w, int c);
|
||||
|
||||
/*
|
||||
* Silently wipe any non-XML characters out of a chunk of text.
|
||||
* If you call this on a string before you pass it addText or
|
||||
* addAttribute, you will never get an error from genx unless
|
||||
* (a) there's a bug in your software, e.g. a malformed element name, or
|
||||
* (b) there's a memory allocation or I/O error
|
||||
* The output can never be longer than the input.
|
||||
* Returns true if any changes were made.
|
||||
*/
|
||||
int genxScrubText(genxWriter w, constUtf8 in, utf8 out);
|
||||
|
||||
/*
|
||||
* return error messages
|
||||
*/
|
||||
char * genxGetErrorMessage(genxWriter w, genxStatus status);
|
||||
char * genxLastErrorMessage(genxWriter w);
|
||||
|
||||
/*
|
||||
* return version
|
||||
*/
|
||||
char * genxGetVersion();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,3 @@
|
||||
gcc tgx.c -lgenx -L../../linux/bin -o tgx
|
||||
LD_LIBRARY_PATH=../../linux/bin ./tgx >/dev/null
|
||||
rm tgx
|
||||
@@ -0,0 +1,3 @@
|
||||
gcc tgx.c -lgenx -L../../bin -o tgx.exe
|
||||
./tgx.exe >/dev/null
|
||||
rm tgx.exe
|
||||
+1675
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,145 @@
|
||||
--genx xml generator binding.
|
||||
local ffi = require'ffi'
|
||||
local C = ffi.load'genx'
|
||||
local M = {C = C}
|
||||
require'genx_h'
|
||||
|
||||
local function checkh(w, statusP, h)
|
||||
if h ~= nil then return h end
|
||||
local s = C.genxGetErrorMessage(w, statusP[0])
|
||||
error(s ~= nil and ffi.string(s) or 'unknown error')
|
||||
end
|
||||
|
||||
local function checknz(w, status)
|
||||
if status == 0 then return end
|
||||
local s = C.genxGetErrorMessage(w, status)
|
||||
error(s ~= nil and ffi.string(s) or 'unknown error')
|
||||
end
|
||||
|
||||
local function nzcaller(f)
|
||||
return function(w, ...)
|
||||
return checknz(w, f(w, ...))
|
||||
end
|
||||
end
|
||||
|
||||
function M.version()
|
||||
return ffi.string(C.genxGetVersion())
|
||||
end
|
||||
|
||||
function M.new(alloc, dealloc, userdata)
|
||||
local w = C.genxNew(alloc, dealloc, userdata)
|
||||
assert(w ~= nil, 'out of memory')
|
||||
ffi.gc(w, C.genxDispose)
|
||||
return w
|
||||
end
|
||||
|
||||
local senders = {} --{[genxWriter] = genxSender}
|
||||
|
||||
function free_sender(w)
|
||||
local sender = senders[w]
|
||||
if not sender then return end
|
||||
sender.send:free()
|
||||
sender.sendBounded:free()
|
||||
sender.flush:free()
|
||||
senders[w] = nil
|
||||
end
|
||||
|
||||
local function free(w)
|
||||
C.genxDispose(ffi.gc(w, nil))
|
||||
free_sender(w)
|
||||
end
|
||||
|
||||
ffi.metatype('genxWriter_rec', {__index = {
|
||||
|
||||
free = free,
|
||||
|
||||
start_doc = function(w, f, ...)
|
||||
free_sender(w)
|
||||
if type(f) == 'function' then
|
||||
--f is called as either: f(s), f(s, sz), or f() to signal EOF.
|
||||
local sender = ffi.new'genxSender'
|
||||
sender.send = ffi.new('send_callback', function(_, s) f(s); return 0 end)
|
||||
sender.sendBounded = ffi.new('sendBounded_callback', function(_, p1, p2) f(p1, p2-p1); return 0 end)
|
||||
sender.flush = ffi.new('flush_callback', function() f(); return 0 end)
|
||||
senders[w] = sender
|
||||
checknz(w, C.genxStartDocSender(w, sender))
|
||||
else
|
||||
checknz(w, C.genxStartDocFile(w, f))
|
||||
end
|
||||
end,
|
||||
|
||||
end_doc = nzcaller(C.genxEndDocument),
|
||||
|
||||
ns = function(w, uri, prefix, statusP)
|
||||
statusP = statusP or ffi.new'genxStatus[1]'
|
||||
return checkh(w, statusP, C.genxDeclareNamespace(w, uri, prefix, statusP))
|
||||
end,
|
||||
|
||||
element = function(w, name, ns, statusP)
|
||||
statusP = statusP or ffi.new'genxStatus[1]'
|
||||
return checkh(w, statusP, C.genxDeclareElement(w, ns, name, statusP))
|
||||
end,
|
||||
|
||||
attr = function(w, name, ns, statusP)
|
||||
statusP = statusP or ffi.new'genxStatus[1]'
|
||||
return checkh(w, statusP, C.genxDeclareAttribute(w, ns, name, statusP))
|
||||
end,
|
||||
|
||||
comment = nzcaller(C.genxComment),
|
||||
|
||||
pi = nzcaller(C.genxPI),
|
||||
|
||||
start_element = function(w, e, ns, prefix)
|
||||
if type(ns) == 'string' then
|
||||
ns = w:ns(ns, prefix)
|
||||
end
|
||||
if type(e) == 'string' then
|
||||
e = w:element(e, ns)
|
||||
end
|
||||
checknz(w, C.genxStartElement(e))
|
||||
end,
|
||||
|
||||
add_attr = function(w, a, val, ns, prefix)
|
||||
if type(ns) == 'string' then
|
||||
ns = w:ns(ns, prefix)
|
||||
end
|
||||
if type(a) == 'string' then
|
||||
a = w:attr(a, ns)
|
||||
end
|
||||
checknz(w, C.genxAddAttribute(a, val))
|
||||
end,
|
||||
|
||||
add_ns = function(w, ns, prefix)
|
||||
if type(ns) == 'string' then
|
||||
ns = w:ns(ns, prefix)
|
||||
end
|
||||
checknz(w, C.genxAddNamespace(ns, prefix))
|
||||
end,
|
||||
|
||||
unset_default_namespace = nzcaller(C.genxUnsetDefaultNamespace),
|
||||
|
||||
end_element = nzcaller(C.genxEndElement),
|
||||
|
||||
text = function(w, s, sz)
|
||||
checknz(w, C.genxAddCountedText(w, s, sz or #s))
|
||||
end,
|
||||
|
||||
char = nzcaller(C.genxAddCharacter),
|
||||
|
||||
check_text = C.genxCheckText,
|
||||
|
||||
scrub_text = function(s_in)
|
||||
s_out = ffi.new('constUtf8[?]', #s_in + 1)
|
||||
if C.genxScrubText(s_in, s_out) ~= 0 then
|
||||
return ffi.string(s_out)
|
||||
else
|
||||
return s_in
|
||||
end
|
||||
end,
|
||||
|
||||
}, __gc = free})
|
||||
|
||||
if not ... then require'genx_demo' end
|
||||
|
||||
return M
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
---
|
||||
project: genx
|
||||
tagline: genx Lua+ffi binding (XML generation)
|
||||
---
|
||||
|
||||
v1.0 | genx beta5 | LuaJIT 2
|
||||
|
||||
## `local genx = require'genx'`
|
||||
|
||||
A ffi binding of [genx], a library for generating well-formed canonical XML documents, written by Tim Bray.
|
||||
|
||||
## Features:
|
||||
|
||||
* does all necessary XML escaping.
|
||||
* prevents generating text that isn't well-formed.
|
||||
* generates namespace prefixes.
|
||||
* produces Canonical XML, suitable for use with digital signatures.
|
||||
|
||||
## Limitations:
|
||||
|
||||
* only UTF8 encoding supported
|
||||
* no empty element tags
|
||||
* no `<!DOCTYPE>` declarations (write it yourself before calling `w:start_doc()`)
|
||||
* no pretty-printing (add linebreaks and indentation yourself with `w:text()` where needed)
|
||||
|
||||
## Example:
|
||||
|
||||
~~~{.lua}
|
||||
local w = genx.new()
|
||||
w:start_doc(io.stdout)
|
||||
w:start_element'root'
|
||||
w:text'hello'
|
||||
w:end_element()
|
||||
w:end_doc()
|
||||
w:free()
|
||||
~~~
|
||||
|
||||
------------------------------------------------------------ --------------------------------------------------------------------------------
|
||||
`genx.new() -> w` Create a new genx writer.
|
||||
`w:free()` Free the genx writer.
|
||||
`w:start_doc(file)` Start an XML document on a `FILE *` or Lua file object
|
||||
`w:start_doc(write)` Start an XML document on a write function to be called as `write([s[, size]])`
|
||||
`w:end_doc()` Flush pending updates and release the file handle
|
||||
`w:ns(uri[, prefix]) -> ns` Declare a namespace for reuse. The same namespace can be declared multiple times.
|
||||
`w:element(name[, ns | uri,prefix]) -> elem` Declare an element for reuse. The same element can be declared multiple times.
|
||||
`w:attr(name[, ns | uri,prefix]) -> attr` Declare an attribute for reuse. The same attribute can be declared multiple times.
|
||||
`w:comment(s)` Add a comment to the current XML stream.
|
||||
`w:pi(target, text)` Add a PI to the current XML stream.
|
||||
`w:start_element(elem | name [, ns | uri,prefix])` Start a new XML element.
|
||||
`w:end_element()` End the current element.
|
||||
`w:add_attr(attr, val[, ns | uri,prefix])` Add an attribute to the current element. Attributes are sorted by name in the output stream.
|
||||
`w:add_ns(ns | [uri,prefix])` Add a namespace to the current element.
|
||||
`w:unset_default_namespace()` Add a `xmlns=""` declaration to unset the default namespace declaration. This is a no-op if no default namespace is in effect.
|
||||
`w:text(s[, size])` Add utf-8 text.
|
||||
`w:char(char)` Add an unicode code point.
|
||||
`w:check_text(s) -> genxStatus` Check utf-8 text.
|
||||
`w:scrub_text(s) -> s` Scrub utf-8 text of invalid characters.
|
||||
------------------------------------------------------------ --------------------------------------------------------------------------------
|
||||
|
||||
See the [genx manual] for more info.
|
||||
|
||||
[genx]: http://www.tbray.org/ongoing/When/200x/2004/02/20/GenxStatus
|
||||
[genx manual]: http://www.tbray.org/ongoing/genx/docs/Guide.html
|
||||
@@ -0,0 +1,49 @@
|
||||
local genx = require'genx'
|
||||
local ffi = require'ffi'
|
||||
|
||||
print('version', genx.version())
|
||||
|
||||
local w = genx.new()
|
||||
|
||||
local ns1 = w:ns('ns1', 'pns1')
|
||||
local ns2 = w:ns('ns2', 'pns2')
|
||||
local body = w:element('body', ns1)
|
||||
local a1 = w:attr('a1')
|
||||
local a2 = w:attr('a2')
|
||||
|
||||
w:start_doc(io.stdout)
|
||||
w:start_element'root'
|
||||
w:text'hello'
|
||||
w:end_element()
|
||||
w:end_doc()
|
||||
print()
|
||||
|
||||
w:start_doc(function(s, sz)
|
||||
s = s and (sz and ffi.string(s, sz) or ffi.string(s)) or '\n!EOF\n'
|
||||
io.write(s)
|
||||
end)
|
||||
|
||||
w:start_element('html')
|
||||
w:add_ns(ns1)
|
||||
w:add_ns(ns2, 'g')
|
||||
|
||||
w:text'\n\t'
|
||||
w:start_element('head')
|
||||
w:add_attr('b', 'vb')
|
||||
w:add_attr('a', 'va')
|
||||
w:text'hello'
|
||||
w:end_element()
|
||||
w:text'\n\t'
|
||||
|
||||
w:start_element(body)
|
||||
w:add_attr(a1, 'v1')
|
||||
w:add_attr(a2, 'v2')
|
||||
w:text'hey'
|
||||
w:end_element()
|
||||
w:text'\n'
|
||||
|
||||
w:end_element()
|
||||
|
||||
w:end_doc()
|
||||
|
||||
w:free()
|
||||
+98
@@ -0,0 +1,98 @@
|
||||
--result of cpp genx.h from genx beta5
|
||||
local ffi = require'ffi'
|
||||
require'stdio_h'
|
||||
|
||||
ffi.cdef[[
|
||||
typedef enum
|
||||
{
|
||||
GENX_SUCCESS = 0,
|
||||
GENX_BAD_UTF8,
|
||||
GENX_NON_XML_CHARACTER,
|
||||
GENX_BAD_NAME,
|
||||
GENX_ALLOC_FAILED,
|
||||
GENX_BAD_NAMESPACE_NAME,
|
||||
GENX_INTERNAL_ERROR,
|
||||
GENX_DUPLICATE_PREFIX,
|
||||
GENX_SEQUENCE_ERROR,
|
||||
GENX_NO_START_TAG,
|
||||
GENX_IO_ERROR,
|
||||
GENX_MISSING_VALUE,
|
||||
GENX_MALFORMED_COMMENT,
|
||||
GENX_XML_PI_TARGET,
|
||||
GENX_MALFORMED_PI,
|
||||
GENX_DUPLICATE_ATTRIBUTE,
|
||||
GENX_ATTRIBUTE_IN_DEFAULT_NAMESPACE,
|
||||
GENX_DUPLICATE_NAMESPACE,
|
||||
GENX_BAD_DEFAULT_DECLARATION
|
||||
} genxStatus;
|
||||
|
||||
typedef unsigned char * utf8;
|
||||
typedef const unsigned char * constUtf8;
|
||||
|
||||
typedef struct genxWriter_rec_ genxWriter_rec, * genxWriter;
|
||||
typedef struct genxNamespace_rec_ genxNamespace_rec, * genxNamespace;
|
||||
typedef struct genxElement_rec_ genxElement_rec, * genxElement;
|
||||
typedef struct genxAttribute_rec_ genxAttribute_rec, * genxAttribute;
|
||||
|
||||
genxWriter genxNew(
|
||||
void * (* alloc)(void * userData, int bytes),
|
||||
void (* dealloc)(void * userData, void * data),
|
||||
void * userData);
|
||||
void genxDispose(genxWriter w);
|
||||
|
||||
void genxSetUserData(genxWriter w, void * userData);
|
||||
void * genxGetUserData(genxWriter w);
|
||||
void genxSetAlloc(genxWriter w, void * (* alloc)(void * userData, int bytes));
|
||||
void genxSetDealloc(genxWriter w, void (* dealloc)(void * userData, void * data));
|
||||
void * (* genxGetAlloc(genxWriter w))(void * userData, int bytes);
|
||||
void (* genxGetDealloc(genxWriter w))(void * userData, void * data);
|
||||
|
||||
utf8 genxGetNamespacePrefix(genxNamespace ns);
|
||||
|
||||
genxNamespace genxDeclareNamespace(genxWriter w,
|
||||
constUtf8 uri, constUtf8 prefix,
|
||||
genxStatus * statusP);
|
||||
|
||||
genxElement genxDeclareElement(genxWriter w,
|
||||
genxNamespace ns, constUtf8 type,
|
||||
genxStatus * statusP);
|
||||
|
||||
genxAttribute genxDeclareAttribute(genxWriter w,
|
||||
genxNamespace ns,
|
||||
constUtf8 name, genxStatus * statusP);
|
||||
|
||||
genxStatus genxStartDocFile(genxWriter w, FILE * file);
|
||||
|
||||
typedef genxStatus (* send_callback)(void * userData, constUtf8 s);
|
||||
typedef genxStatus (* sendBounded_callback)(void * userData, constUtf8 start, constUtf8 end);
|
||||
typedef genxStatus (* flush_callback)(void * userData);
|
||||
|
||||
typedef struct {
|
||||
send_callback send;
|
||||
sendBounded_callback sendBounded;
|
||||
flush_callback flush;
|
||||
} genxSender;
|
||||
|
||||
genxStatus genxStartDocSender(genxWriter w, genxSender * sender);
|
||||
genxStatus genxEndDocument(genxWriter w);
|
||||
genxStatus genxComment(genxWriter w, constUtf8 text);
|
||||
genxStatus genxPI(genxWriter w, constUtf8 target, constUtf8 text);
|
||||
genxStatus genxStartElementLiteral(genxWriter w, constUtf8 xmlns, constUtf8 type);
|
||||
genxStatus genxStartElement(genxElement e);
|
||||
genxStatus genxAddAttributeLiteral(genxWriter w, constUtf8 xmlns, constUtf8 name, constUtf8 value);
|
||||
genxStatus genxAddAttribute(genxAttribute a, constUtf8 value);
|
||||
genxStatus genxAddNamespace(genxNamespace ns, constUtf8 prefix); // NOTE: prefix changed from utf8 to constUtf8
|
||||
genxStatus genxUnsetDefaultNamespace(genxWriter w);
|
||||
genxStatus genxEndElement(genxWriter w);
|
||||
genxStatus genxAddText(genxWriter w, constUtf8 start);
|
||||
genxStatus genxAddCountedText(genxWriter w, constUtf8 start, int byteCount);
|
||||
genxStatus genxAddBoundedText(genxWriter w, constUtf8 start, constUtf8 end);
|
||||
genxStatus genxAddCharacter(genxWriter w, int c);
|
||||
int genxNextUnicodeChar(constUtf8 * sp);
|
||||
genxStatus genxCheckText(genxWriter w, constUtf8 s);
|
||||
int genxCharClass(genxWriter w, int c);
|
||||
int genxScrubText(genxWriter w, constUtf8 in, utf8 out);
|
||||
char * genxGetErrorMessage(genxWriter w, genxStatus status);
|
||||
char * genxLastErrorMessage(genxWriter w);
|
||||
char * genxGetVersion();
|
||||
]]
|
||||
Binary file not shown.
Reference in New Issue
Block a user