⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xmlschemastypes.c

📁 libxml,在UNIX/LINUX下非常重要的一个库,为XML相关应用提供方便.目前上载的是最新版本,若要取得最新版本,请参考里面的readme.
💻 C
📖 第 1 页 / 共 5 页
字号:
/* * schemastypes.c : implementation of the XML Schema Datatypes *             definition and validity checking * * See Copyright for the status of this software. * * Daniel Veillard <veillard@redhat.com> */#define IN_LIBXML#include "libxml.h"#ifdef LIBXML_SCHEMAS_ENABLED#include <string.h>#include <libxml/xmlmemory.h>#include <libxml/parser.h>#include <libxml/parserInternals.h>#include <libxml/hash.h>#include <libxml/valid.h>#include <libxml/xpath.h>#include <libxml/uri.h>#include <libxml/xmlschemas.h>#include <libxml/schemasInternals.h>#include <libxml/xmlschemastypes.h>#ifdef HAVE_MATH_H#include <math.h>#endif#define DEBUG#ifndef LIBXML_XPATH_ENABLEDextern double xmlXPathNAN;extern double xmlXPathPINF;extern double xmlXPathNINF;#endif#define TODO 								\    xmlGenericError(xmlGenericErrorContext,				\	    "Unimplemented block at %s:%d\n",				\            __FILE__, __LINE__);#define XML_SCHEMAS_NAMESPACE_NAME \    (const xmlChar *)"http://www.w3.org/2001/XMLSchema"#define IS_WSP_REPLACE_CH(c)	((((c) == 0x9) || ((c) == 0xa)) || \				 ((c) == 0xd))#define IS_WSP_SPACE_CH(c)	((c) == 0x20)#define IS_WSP_BLANK_CH(c) IS_BLANK_CH(c)/* Date value */typedef struct _xmlSchemaValDate xmlSchemaValDate;typedef xmlSchemaValDate *xmlSchemaValDatePtr;struct _xmlSchemaValDate {    long		year;    unsigned int	mon	:4;	/* 1 <=  mon    <= 12   */    unsigned int	day	:5;	/* 1 <=  day    <= 31   */    unsigned int	hour	:5;	/* 0 <=  hour   <= 23   */    unsigned int	min	:6;	/* 0 <=  min    <= 59	*/    double		sec;    unsigned int	tz_flag	:1;	/* is tzo explicitely set? */    int			tzo	:11;	/* -1440 <= tzo <= 1440 */};/* Duration value */typedef struct _xmlSchemaValDuration xmlSchemaValDuration;typedef xmlSchemaValDuration *xmlSchemaValDurationPtr;struct _xmlSchemaValDuration {    long	        mon;		/* mon stores years also */    long        	day;    double		sec;            /* sec stores min and hour also */};typedef struct _xmlSchemaValDecimal xmlSchemaValDecimal;typedef xmlSchemaValDecimal *xmlSchemaValDecimalPtr;struct _xmlSchemaValDecimal {    /* would use long long but not portable */    unsigned long lo;    unsigned long mi;    unsigned long hi;    unsigned int extra;    unsigned int sign:1;    unsigned int frac:7;    unsigned int total:8;};typedef struct _xmlSchemaValQName xmlSchemaValQName;typedef xmlSchemaValQName *xmlSchemaValQNamePtr;struct _xmlSchemaValQName {    xmlChar *name;    xmlChar *uri;};typedef struct _xmlSchemaValHex xmlSchemaValHex;typedef xmlSchemaValHex *xmlSchemaValHexPtr;struct _xmlSchemaValHex {    xmlChar     *str;    unsigned int total;};typedef struct _xmlSchemaValBase64 xmlSchemaValBase64;typedef xmlSchemaValBase64 *xmlSchemaValBase64Ptr;struct _xmlSchemaValBase64 {    xmlChar     *str;    unsigned int total;};struct _xmlSchemaVal {    xmlSchemaValType type;    union {	xmlSchemaValDecimal     decimal;        xmlSchemaValDate        date;        xmlSchemaValDuration    dur;	xmlSchemaValQName	qname;	xmlSchemaValHex		hex;	xmlSchemaValBase64	base64;	float			f;	double			d;	int			b;	xmlChar                *str;    } value;};static int xmlSchemaTypesInitialized = 0;static xmlHashTablePtr xmlSchemaTypesBank = NULL;/* * Basic types */static xmlSchemaTypePtr xmlSchemaTypeStringDef = NULL;static xmlSchemaTypePtr xmlSchemaTypeAnyTypeDef = NULL;static xmlSchemaTypePtr xmlSchemaTypeAnySimpleTypeDef = NULL;static xmlSchemaTypePtr xmlSchemaTypeDecimalDef = NULL;static xmlSchemaTypePtr xmlSchemaTypeDatetimeDef = NULL;static xmlSchemaTypePtr xmlSchemaTypeDateDef = NULL;static xmlSchemaTypePtr xmlSchemaTypeTimeDef = NULL;static xmlSchemaTypePtr xmlSchemaTypeGYearDef = NULL;static xmlSchemaTypePtr xmlSchemaTypeGYearMonthDef = NULL;static xmlSchemaTypePtr xmlSchemaTypeGDayDef = NULL;static xmlSchemaTypePtr xmlSchemaTypeGMonthDayDef = NULL;static xmlSchemaTypePtr xmlSchemaTypeGMonthDef = NULL;static xmlSchemaTypePtr xmlSchemaTypeDurationDef = NULL;static xmlSchemaTypePtr xmlSchemaTypeFloatDef = NULL;static xmlSchemaTypePtr xmlSchemaTypeBooleanDef = NULL;static xmlSchemaTypePtr xmlSchemaTypeDoubleDef = NULL;static xmlSchemaTypePtr xmlSchemaTypeHexBinaryDef = NULL;static xmlSchemaTypePtr xmlSchemaTypeBase64BinaryDef = NULL;static xmlSchemaTypePtr xmlSchemaTypeAnyURIDef = NULL;/* * Derived types */static xmlSchemaTypePtr xmlSchemaTypePositiveIntegerDef = NULL;static xmlSchemaTypePtr xmlSchemaTypeNonPositiveIntegerDef = NULL;static xmlSchemaTypePtr xmlSchemaTypeNegativeIntegerDef = NULL;static xmlSchemaTypePtr xmlSchemaTypeNonNegativeIntegerDef = NULL;static xmlSchemaTypePtr xmlSchemaTypeIntegerDef = NULL;static xmlSchemaTypePtr xmlSchemaTypeLongDef = NULL;static xmlSchemaTypePtr xmlSchemaTypeIntDef = NULL;static xmlSchemaTypePtr xmlSchemaTypeShortDef = NULL;static xmlSchemaTypePtr xmlSchemaTypeByteDef = NULL;static xmlSchemaTypePtr xmlSchemaTypeUnsignedLongDef = NULL;static xmlSchemaTypePtr xmlSchemaTypeUnsignedIntDef = NULL;static xmlSchemaTypePtr xmlSchemaTypeUnsignedShortDef = NULL;static xmlSchemaTypePtr xmlSchemaTypeUnsignedByteDef = NULL;static xmlSchemaTypePtr xmlSchemaTypeNormStringDef = NULL;static xmlSchemaTypePtr xmlSchemaTypeTokenDef = NULL;static xmlSchemaTypePtr xmlSchemaTypeLanguageDef = NULL;static xmlSchemaTypePtr xmlSchemaTypeNameDef = NULL;static xmlSchemaTypePtr xmlSchemaTypeQNameDef = NULL;static xmlSchemaTypePtr xmlSchemaTypeNCNameDef = NULL;static xmlSchemaTypePtr xmlSchemaTypeIdDef = NULL;static xmlSchemaTypePtr xmlSchemaTypeIdrefDef = NULL;static xmlSchemaTypePtr xmlSchemaTypeIdrefsDef = NULL;static xmlSchemaTypePtr xmlSchemaTypeEntityDef = NULL;static xmlSchemaTypePtr xmlSchemaTypeEntitiesDef = NULL;static xmlSchemaTypePtr xmlSchemaTypeNotationDef = NULL;static xmlSchemaTypePtr xmlSchemaTypeNmtokenDef = NULL;static xmlSchemaTypePtr xmlSchemaTypeNmtokensDef = NULL;/************************************************************************ *									* * 			Datatype error handlers				* *									* ************************************************************************//** * xmlSchemaTypeErrMemory: * @extra:  extra informations * * Handle an out of memory condition */static voidxmlSchemaTypeErrMemory(xmlNodePtr node, const char *extra){    __xmlSimpleError(XML_FROM_DATATYPE, XML_ERR_NO_MEMORY, node, NULL, extra);}/************************************************************************ *									* * 			Base types support				* *									* ************************************************************************//* * xmlSchemaInitBasicType: * @name:  the type name * @type:  the value type associated * * Initialize one primitive built-in type */static xmlSchemaTypePtrxmlSchemaInitBasicType(const char *name, xmlSchemaValType type, 		       xmlSchemaTypePtr baseType) {    xmlSchemaTypePtr ret;    ret = (xmlSchemaTypePtr) xmlMalloc(sizeof(xmlSchemaType));    if (ret == NULL) {        xmlSchemaTypeErrMemory(NULL, "could not initialize basic types");	return(NULL);    }    memset(ret, 0, sizeof(xmlSchemaType));    ret->name = (const xmlChar *)name;    ret->type = XML_SCHEMA_TYPE_BASIC;    ret->baseType = baseType;    /*    * Hack to reflect the variety.    */    if ((type == XML_SCHEMAS_IDREFS) ||	(type == XML_SCHEMAS_NMTOKENS) ||	(type == XML_SCHEMAS_ENTITIES)) 	ret->flags |= XML_SCHEMAS_TYPE_VARIETY_LIST;    else if ((type != XML_SCHEMAS_ANYTYPE) &&	(type != XML_SCHEMAS_ANYSIMPLETYPE))	ret->flags |= XML_SCHEMAS_TYPE_VARIETY_ATOMIC;    ret->contentType = XML_SCHEMA_CONTENT_BASIC;    switch (type) {	case XML_SCHEMAS_STRING:            	case XML_SCHEMAS_DECIMAL:    	case XML_SCHEMAS_DATE:    	case XML_SCHEMAS_DATETIME:    	case XML_SCHEMAS_TIME:    	case XML_SCHEMAS_GYEAR:    	case XML_SCHEMAS_GYEARMONTH:    	case XML_SCHEMAS_GMONTH:    	case XML_SCHEMAS_GMONTHDAY:    	case XML_SCHEMAS_GDAY:    	case XML_SCHEMAS_DURATION:    	case XML_SCHEMAS_FLOAT:    	case XML_SCHEMAS_DOUBLE:    	case XML_SCHEMAS_BOOLEAN:    	case XML_SCHEMAS_ANYURI:    	case XML_SCHEMAS_HEXBINARY:    	case XML_SCHEMAS_BASE64BINARY:		case XML_SCHEMAS_QNAME:		case XML_SCHEMAS_NOTATION:		    ret->flags |= XML_SCHEMAS_TYPE_BUILTIN_PRIMITIVE;	default:	break;    }    xmlHashAddEntry2(xmlSchemaTypesBank, ret->name,	             XML_SCHEMAS_NAMESPACE_NAME, ret);    ret->builtInType = type;    return(ret);}/* * xmlSchemaInitTypes: * * Initialize the default XML Schemas type library */voidxmlSchemaInitTypes(void){    if (xmlSchemaTypesInitialized != 0)        return;    xmlSchemaTypesBank = xmlHashCreate(40);        /*    * 3.4.7 Built-in Complex Type Definition    */    xmlSchemaTypeAnyTypeDef = xmlSchemaInitBasicType("anyType",                                                     XML_SCHEMAS_ANYTYPE, 						     NULL);    xmlSchemaTypeAnyTypeDef->baseType = xmlSchemaTypeAnyTypeDef;    xmlSchemaTypeAnyTypeDef->contentType = XML_SCHEMA_CONTENT_MIXED;    {	xmlSchemaWildcardPtr wild;	wild = (xmlSchemaWildcardPtr) xmlMalloc(sizeof(xmlSchemaWildcard));	if (wild == NULL) {	    xmlSchemaTypeErrMemory(NULL, "could not create an attribute wildcard on anyType");	    return;	}	memset(wild, 0, sizeof(xmlSchemaWildcard));	wild->any = 1;	wild->processContents = XML_SCHEMAS_ANY_LAX;	wild->minOccurs = 1;	wild->maxOccurs = 1;	xmlSchemaTypeAnyTypeDef->attributeWildcard = wild;    }    xmlSchemaTypeAnySimpleTypeDef = xmlSchemaInitBasicType("anySimpleType",                                                            XML_SCHEMAS_ANYSIMPLETYPE,							   xmlSchemaTypeAnyTypeDef);    /*    * primitive datatypes    */    xmlSchemaTypeStringDef = xmlSchemaInitBasicType("string",                                                    XML_SCHEMAS_STRING,						    xmlSchemaTypeAnySimpleTypeDef);    xmlSchemaTypeDecimalDef = xmlSchemaInitBasicType("decimal",                                                     XML_SCHEMAS_DECIMAL,						     xmlSchemaTypeAnySimpleTypeDef);    xmlSchemaTypeDateDef = xmlSchemaInitBasicType("date",                                                  XML_SCHEMAS_DATE,						  xmlSchemaTypeAnySimpleTypeDef);    xmlSchemaTypeDatetimeDef = xmlSchemaInitBasicType("dateTime",                                                      XML_SCHEMAS_DATETIME,						      xmlSchemaTypeAnySimpleTypeDef);    xmlSchemaTypeTimeDef = xmlSchemaInitBasicType("time",                                                  XML_SCHEMAS_TIME,						  xmlSchemaTypeAnySimpleTypeDef);    xmlSchemaTypeGYearDef = xmlSchemaInitBasicType("gYear",                                                   XML_SCHEMAS_GYEAR,						   xmlSchemaTypeAnySimpleTypeDef);    xmlSchemaTypeGYearMonthDef = xmlSchemaInitBasicType("gYearMonth",                                                        XML_SCHEMAS_GYEARMONTH,							xmlSchemaTypeAnySimpleTypeDef);    xmlSchemaTypeGMonthDef = xmlSchemaInitBasicType("gMonth",                                                    XML_SCHEMAS_GMONTH,						    xmlSchemaTypeAnySimpleTypeDef);    xmlSchemaTypeGMonthDayDef = xmlSchemaInitBasicType("gMonthDay",                                                       XML_SCHEMAS_GMONTHDAY,						       xmlSchemaTypeAnySimpleTypeDef);    xmlSchemaTypeGDayDef = xmlSchemaInitBasicType("gDay",                                                  XML_SCHEMAS_GDAY,						  xmlSchemaTypeAnySimpleTypeDef);    xmlSchemaTypeDurationDef = xmlSchemaInitBasicType("duration",                                                      XML_SCHEMAS_DURATION,						      xmlSchemaTypeAnySimpleTypeDef);    xmlSchemaTypeFloatDef = xmlSchemaInitBasicType("float",                                                   XML_SCHEMAS_FLOAT,						   xmlSchemaTypeAnySimpleTypeDef);    xmlSchemaTypeDoubleDef = xmlSchemaInitBasicType("double",                                                    XML_SCHEMAS_DOUBLE,						    xmlSchemaTypeAnySimpleTypeDef);    xmlSchemaTypeBooleanDef = xmlSchemaInitBasicType("boolean",                                                     XML_SCHEMAS_BOOLEAN,						     xmlSchemaTypeAnySimpleTypeDef);    xmlSchemaTypeAnyURIDef = xmlSchemaInitBasicType("anyURI",                                                    XML_SCHEMAS_ANYURI,						    xmlSchemaTypeAnySimpleTypeDef);    xmlSchemaTypeHexBinaryDef = xmlSchemaInitBasicType("hexBinary",                                                     XML_SCHEMAS_HEXBINARY,						     xmlSchemaTypeAnySimpleTypeDef);    xmlSchemaTypeBase64BinaryDef        = xmlSchemaInitBasicType("base64Binary", XML_SCHEMAS_BASE64BINARY,	xmlSchemaTypeAnySimpleTypeDef);    xmlSchemaTypeNotationDef = xmlSchemaInitBasicType("NOTATION",                                                    XML_SCHEMAS_NOTATION,						    xmlSchemaTypeAnySimpleTypeDef);        xmlSchemaTypeQNameDef = xmlSchemaInitBasicType("QName",                                                   XML_SCHEMAS_QNAME,						   xmlSchemaTypeAnySimpleTypeDef);    /*     * derived datatypes     */    xmlSchemaTypeIntegerDef = xmlSchemaInitBasicType("integer",                                                     XML_SCHEMAS_INTEGER,						     xmlSchemaTypeDecimalDef);    xmlSchemaTypeNonPositiveIntegerDef =        xmlSchemaInitBasicType("nonPositiveInteger",                               XML_SCHEMAS_NPINTEGER,			       xmlSchemaTypeIntegerDef);    xmlSchemaTypeNegativeIntegerDef =        xmlSchemaInitBasicType("negativeInteger", XML_SCHEMAS_NINTEGER,	xmlSchemaTypeNonPositiveIntegerDef);    xmlSchemaTypeLongDef =        xmlSchemaInitBasicType("long", XML_SCHEMAS_LONG,	xmlSchemaTypeIntegerDef);    xmlSchemaTypeIntDef = xmlSchemaInitBasicType("int", XML_SCHEMAS_INT,	xmlSchemaTypeLongDef);    xmlSchemaTypeShortDef = xmlSchemaInitBasicType("short",                                                   XML_SCHEMAS_SHORT,						   xmlSchemaTypeIntDef);    xmlSchemaTypeByteDef = xmlSchemaInitBasicType("byte",                                                  XML_SCHEMAS_BYTE,						  xmlSchemaTypeShortDef);    xmlSchemaTypeNonNegativeIntegerDef =        xmlSchemaInitBasicType("nonNegativeInteger",                               XML_SCHEMAS_NNINTEGER,			       xmlSchemaTypeIntegerDef);    xmlSchemaTypeUnsignedLongDef =        xmlSchemaInitBasicType("unsignedLong", XML_SCHEMAS_ULONG,	xmlSchemaTypeNonNegativeIntegerDef);    xmlSchemaTypeUnsignedIntDef =        xmlSchemaInitBasicType("unsignedInt", XML_SCHEMAS_UINT,	xmlSchemaTypeUnsignedLongDef);    xmlSchemaTypeUnsignedShortDef =        xmlSchemaInitBasicType("unsignedShort", XML_SCHEMAS_USHORT,	xmlSchemaTypeUnsignedIntDef);    xmlSchemaTypeUnsignedByteDef =        xmlSchemaInitBasicType("unsignedByte", XML_SCHEMAS_UBYTE,	xmlSchemaTypeUnsignedShortDef);    xmlSchemaTypePositiveIntegerDef =        xmlSchemaInitBasicType("positiveInteger", XML_SCHEMAS_PINTEGER,	xmlSchemaTypeNonNegativeIntegerDef);    xmlSchemaTypeNormStringDef = xmlSchemaInitBasicType("normalizedString",                                                        XML_SCHEMAS_NORMSTRING,							xmlSchemaTypeStringDef);    xmlSchemaTypeTokenDef = xmlSchemaInitBasicType("token",                                                   XML_SCHEMAS_TOKEN,						   xmlSchemaTypeNormStringDef);    xmlSchemaTypeLanguageDef = xmlSchemaInitBasicType("language",                                                      XML_SCHEMAS_LANGUAGE,						      xmlSchemaTypeTokenDef);    xmlSchemaTypeNameDef = xmlSchemaInitBasicType("Name",                                                  XML_SCHEMAS_NAME,						  xmlSchemaTypeTokenDef);    xmlSchemaTypeNmtokenDef = xmlSchemaInitBasicType("NMTOKEN",                                                     XML_SCHEMAS_NMTOKEN,						     xmlSchemaTypeTokenDef);                    xmlSchemaTypeNCNameDef = xmlSchemaInitBasicType("NCName",                                                    XML_SCHEMAS_NCNAME,						    xmlSchemaTypeNameDef);    xmlSchemaTypeIdDef = xmlSchemaInitBasicType("ID", XML_SCHEMAS_ID,	xmlSchemaTypeNCNameDef);    xmlSchemaTypeIdrefDef = xmlSchemaInitBasicType("IDREF",                                                   XML_SCHEMAS_IDREF,						   xmlSchemaTypeNCNameDef);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -