~ubuntu-branches/ubuntu/feisty/fpc/feisty

« back to all changes in this revision

Viewing changes to packages/extra/univint/CFXMLParser.pas

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Werner
  • Date: 2007-01-27 20:08:50 UTC
  • mfrom: (1.2.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20070127200850-9mrptaqqjsx9nwa7
Tags: 2.0.4-5
* Fixed Build-Depends.
* Add myself to Uploaders in debian/control.
* Make sure that the sources are really patched before building them.
* Build unit 'libc' on powerpc too.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
{       CFXMLParser.h
 
2
        Copyright (c) 1998-2005, Apple, Inc. All rights reserved.
 
3
}
 
4
{         Pascal Translation Updated:  Peter N Lewis, <peter@stairways.com.au>, November 2005 }
 
5
{
 
6
    Modified for use with Free Pascal
 
7
    Version 200
 
8
    Please report any bugs to <gpc@microbizz.nl>
 
9
}
 
10
 
 
11
{$mode macpas}
 
12
{$packenum 1}
 
13
{$macro on}
 
14
{$inline on}
 
15
{$CALLING MWPASCAL}
 
16
 
 
17
unit CFXMLParser;
 
18
interface
 
19
{$setc UNIVERSAL_INTERFACES_VERSION := $0342}
 
20
{$setc GAP_INTERFACES_VERSION := $0200}
 
21
 
 
22
{$ifc not defined USE_CFSTR_CONSTANT_MACROS}
 
23
    {$setc USE_CFSTR_CONSTANT_MACROS := TRUE}
 
24
{$endc}
 
25
 
 
26
{$ifc defined CPUPOWERPC and defined CPUI386}
 
27
        {$error Conflicting initial definitions for CPUPOWERPC and CPUI386}
 
28
{$endc}
 
29
{$ifc defined FPC_BIG_ENDIAN and defined FPC_LITTLE_ENDIAN}
 
30
        {$error Conflicting initial definitions for FPC_BIG_ENDIAN and FPC_LITTLE_ENDIAN}
 
31
{$endc}
 
32
 
 
33
{$ifc not defined __ppc__ and defined CPUPOWERPC}
 
34
        {$setc __ppc__ := 1}
 
35
{$elsec}
 
36
        {$setc __ppc__ := 0}
 
37
{$endc}
 
38
{$ifc not defined __i386__ and defined CPUI386}
 
39
        {$setc __i386__ := 1}
 
40
{$elsec}
 
41
        {$setc __i386__ := 0}
 
42
{$endc}
 
43
 
 
44
{$ifc defined __ppc__ and __ppc__ and defined __i386__ and __i386__}
 
45
        {$error Conflicting definitions for __ppc__ and __i386__}
 
46
{$endc}
 
47
 
 
48
{$ifc defined __ppc__ and __ppc__}
 
49
        {$setc TARGET_CPU_PPC := TRUE}
 
50
        {$setc TARGET_CPU_X86 := FALSE}
 
51
{$elifc defined __i386__ and __i386__}
 
52
        {$setc TARGET_CPU_PPC := FALSE}
 
53
        {$setc TARGET_CPU_X86 := TRUE}
 
54
{$elsec}
 
55
        {$error Neither __ppc__ nor __i386__ is defined.}
 
56
{$endc}
 
57
{$setc TARGET_CPU_PPC_64 := FALSE}
 
58
 
 
59
{$ifc defined FPC_BIG_ENDIAN}
 
60
        {$setc TARGET_RT_BIG_ENDIAN := TRUE}
 
61
        {$setc TARGET_RT_LITTLE_ENDIAN := FALSE}
 
62
{$elifc defined FPC_LITTLE_ENDIAN}
 
63
        {$setc TARGET_RT_BIG_ENDIAN := FALSE}
 
64
        {$setc TARGET_RT_LITTLE_ENDIAN := TRUE}
 
65
{$elsec}
 
66
        {$error Neither FPC_BIG_ENDIAN nor FPC_LITTLE_ENDIAN are defined.}
 
67
{$endc}
 
68
{$setc ACCESSOR_CALLS_ARE_FUNCTIONS := TRUE}
 
69
{$setc CALL_NOT_IN_CARBON := FALSE}
 
70
{$setc OLDROUTINENAMES := FALSE}
 
71
{$setc OPAQUE_TOOLBOX_STRUCTS := TRUE}
 
72
{$setc OPAQUE_UPP_TYPES := TRUE}
 
73
{$setc OTCARBONAPPLICATION := TRUE}
 
74
{$setc OTKERNEL := FALSE}
 
75
{$setc PM_USE_SESSION_APIS := TRUE}
 
76
{$setc TARGET_API_MAC_CARBON := TRUE}
 
77
{$setc TARGET_API_MAC_OS8 := FALSE}
 
78
{$setc TARGET_API_MAC_OSX := TRUE}
 
79
{$setc TARGET_CARBON := TRUE}
 
80
{$setc TARGET_CPU_68K := FALSE}
 
81
{$setc TARGET_CPU_MIPS := FALSE}
 
82
{$setc TARGET_CPU_SPARC := FALSE}
 
83
{$setc TARGET_OS_MAC := TRUE}
 
84
{$setc TARGET_OS_UNIX := FALSE}
 
85
{$setc TARGET_OS_WIN32 := FALSE}
 
86
{$setc TARGET_RT_MAC_68881 := FALSE}
 
87
{$setc TARGET_RT_MAC_CFM := FALSE}
 
88
{$setc TARGET_RT_MAC_MACHO := TRUE}
 
89
{$setc TYPED_FUNCTION_POINTERS := TRUE}
 
90
{$setc TYPE_BOOL := FALSE}
 
91
{$setc TYPE_EXTENDED := FALSE}
 
92
{$setc TYPE_LONGLONG := TRUE}
 
93
uses MacTypes,CFBase,CFArray,CFData,CFDictionary,CFTree,CFURL,CFXMLNode;
 
94
{$ALIGN POWER}
 
95
 
 
96
 
 
97
type
 
98
        CFXMLParserRef = ^SInt32; { an opaque 32-bit type }
 
99
        CFXMLParserRefPtr = ^CFXMLParserRef;
 
100
{ These are the various options you can configure the parser with.  These are
 
101
   chosen such that an option flag of 0 (kCFXMLParserNoOptions) leaves the XML
 
102
   as "intact" as possible (reports all structures; performs no replacements).
 
103
   Hence, to make the parser do the most work, returning only the pure element
 
104
   tree, set the option flag to kCFXMLParserAllOptions.
 
105
 
 
106
kCFXMLParserValidateDocument -
 
107
   validate the document against its grammar from the DTD, reporting any errors.
 
108
   Currently not supported.
 
109
 
 
110
kCFXMLParserSkipMetaData -
 
111
   silently skip over metadata constructs (the DTD and comments)
 
112
 
 
113
kCFXMLParserReplacePhysicalEntities -
 
114
   replace declared entities like &lt;.  Note that other than the 5 predefined
 
115
   entities (lt, gt, quot, amp, apos), these must be defined in the DTD.
 
116
   Currently not supported.
 
117
 
 
118
kCFXMLParserSkipWhitespace -
 
119
   skip over all whitespace that does not abut non-whitespace character data.
 
120
   In other words, given <foo>  <bar> blah </bar></foo>, the whitespace between
 
121
   foo's open tag and bar's open tag would be suppressed, but the whitespace
 
122
   around blah would be preserved.
 
123
 
 
124
kCFXMLParserAddImpliedAttributes -
 
125
   where the DTD specifies implied attribute-value pairs for a particular element,
 
126
   add those pairs to any occurances of the element in the element tree.
 
127
   Currently not supported.
 
128
}
 
129
 
 
130
type
 
131
        CFXMLParserOptions = SInt32;
 
132
const
 
133
        kCFXMLParserValidateDocument = 1 shl 0;
 
134
        kCFXMLParserSkipMetaData = 1 shl 1;
 
135
        kCFXMLParserReplacePhysicalEntities = 1 shl 2;
 
136
        kCFXMLParserSkipWhitespace = 1 shl 3;
 
137
        kCFXMLParserResolveExternalEntities = 1 shl 4;
 
138
        kCFXMLParserAddImpliedAttributes = 1 shl 5;
 
139
        kCFXMLParserAllOptions = $00FFFFFF;
 
140
        kCFXMLParserNoOptions = 0;
 
141
 
 
142
{ This list is expected to grow }
 
143
type
 
144
        CFXMLParserStatusCode = SInt32;
 
145
const
 
146
        kCFXMLStatusParseNotBegun       = -2;
 
147
        kCFXMLStatusParseInProgress     = -1;
 
148
        kCFXMLStatusParseSuccessful     = 0;
 
149
        kCFXMLErrorUnexpectedEOF        = 1;
 
150
        kCFXMLErrorUnknownEncoding      = 2;
 
151
        kCFXMLErrorEncodingConversionFailure = 3;
 
152
        kCFXMLErrorMalformedProcessingInstruction = 4;
 
153
        kCFXMLErrorMalformedDTD         = 5;
 
154
        kCFXMLErrorMalformedName        = 6;
 
155
        kCFXMLErrorMalformedCDSect      = 7;
 
156
        kCFXMLErrorMalformedCloseTag = 8;
 
157
        kCFXMLErrorMalformedStartTag = 9;
 
158
        kCFXMLErrorMalformedDocument = 10;
 
159
        kCFXMLErrorElementlessDocument = 11;
 
160
        kCFXMLErrorMalformedComment     = 12;
 
161
        kCFXMLErrorMalformedCharacterReference = 13;
 
162
        kCFXMLErrorMalformedParsedCharacterData = 14;
 
163
        kCFXMLErrorNoData                       = 15;
 
164
 
 
165
 
 
166
{  These functions are called as a parse progresses.
 
167
 
 
168
createXMLStructure -
 
169
  called as new XML structures are encountered by the parser.  May return NULL to indicate
 
170
  that the given structure should be skipped; if NULL is returned for a given structure,
 
171
  only minimal parsing is done for that structure (enough to correctly determine its end,
 
172
  and to extract any data necessary for the remainder of the parse, such as Entity definitions).
 
173
  createXMLStructure (or indeed, any of the tree-creation callbacks) will not be called for any
 
174
  children of the skipped structure.  The only exception is that the top-most element will always
 
175
  be reported even if NULL was returned for the document as a whole.  NOTE: for performance reasons,
 
176
  the node passed to createXMLStructure cannot be safely retained by the client; the node as
 
177
  a whole must be copied (via CFXMLNodeCreateCopy), or its contents must be extracted and copied.
 
178
 
 
179
addChild -
 
180
  called as children are parsed and are ready to be added to the tree.  If createXMLStructure
 
181
  returns NULL for a given structure, that structure is omitted entirely, and addChild will
 
182
  NOT be called for either a NULL child or parent.
 
183
 
 
184
endXMLStructure -
 
185
  called once a structure (and all its children) are completely parsed.  As elements are encountered,
 
186
  createXMLStructure is called for them first, then addChild to add the new structure to its parent,
 
187
  then addChild (potentially several times) to add the new structure's children to it, then finally 
 
188
  endXMLStructure to show that the structure has been fully parsed.
 
189
 
 
190
createXMLStructure, addChild, and endXMLStructure are all REQUIRED TO BE NON-NULL.
 
191
 
 
192
resolveExternalEntity -
 
193
  called when external entities are referenced (NOT when they are simply defined).  If the function
 
194
  pointer is NULL, the parser uses its internal routines to try and resolve the entity.  If the
 
195
  function pointer is set, and the function returns NULL, a place holder for the external entity
 
196
  is inserted into the tree.  In this manner, the parser's client can prevent any external network 
 
197
  or file accesses.
 
198
 
 
199
handleError - called as errors/warnings are encountered in the data stream.  At some point, we will
 
200
  have an enum of the expected errors, some of which will be fatal, others of which will not.  If
 
201
  the function pointer is NULL, the parser will silently attempt to recover.  The
 
202
  handleError function may always return false to force the parser to stop; if handleError returns
 
203
  true, the parser will attempt to recover (fatal errors will still cause the parse to abort
 
204
  immediately).
 
205
}
 
206
 
 
207
type
 
208
        CFXMLParserCreateXMLStructureCallBack = function( parser: CFXMLParserRef; nodeDesc: CFXMLNodeRef; info: UnivPtr ): UnivPtr;
 
209
        CFXMLParserAddChildCallBack = procedure( parser: CFXMLParserRef; parent: UnivPtr; child: UnivPtr; info: UnivPtr );
 
210
        CFXMLParserEndXMLStructureCallBack = procedure( parser: CFXMLParserRef; xmlType: UnivPtr; info: UnivPtr );
 
211
        CFXMLParserResolveExternalEntityCallBack = function( parser: CFXMLParserRef; var extID: CFXMLExternalID; info: UnivPtr ): CFDataRef;
 
212
        CFXMLParserHandleErrorCallBack = function( parser: CFXMLParserRef; error: CFXMLParserStatusCode; info: UnivPtr ): Boolean;
 
213
        CFXMLParserCallBacksPtr = ^CFXMLParserCallBacks;
 
214
        CFXMLParserCallBacks = record
 
215
                version: CFIndex;
 
216
                createXMLStructure: CFXMLParserCreateXMLStructureCallBack;
 
217
                addChild: CFXMLParserAddChildCallBack;
 
218
                endXMLStructure: CFXMLParserEndXMLStructureCallBack;
 
219
                resolveExternalEntity: CFXMLParserResolveExternalEntityCallBack;
 
220
                handleError: CFXMLParserHandleErrorCallBack;
 
221
        end;
 
222
 
 
223
type
 
224
        CFXMLParserRetainCallBack = function( info: {const} UnivPtr ): UnivPtr;
 
225
        CFXMLParserReleaseCallBack = procedure( info: {const} UnivPtr );
 
226
        CFXMLParserCopyDescriptionCallBack = function( info: {const} UnivPtr ): CFStringRef;
 
227
        CFXMLParserContextPtr = ^CFXMLParserContext;
 
228
        CFXMLParserContext = record
 
229
                version: CFIndex;
 
230
                info: UnivPtr;
 
231
                retain: CFXMLParserRetainCallBack;
 
232
                release: CFXMLParserReleaseCallBack;
 
233
                copyDescription: CFXMLParserCopyDescriptionCallBack;
 
234
        end;
 
235
 
 
236
function CFXMLParserGetTypeID: CFTypeID; external name '_CFXMLParserGetTypeID';
 
237
 
 
238
{ Creates a parser which will parse the given data with the given options.  xmlData may not be NULL. 
 
239
   dataSource should be the URL from which the data came, and may be NULL; it is used to resolve any
 
240
   relative references found in xmlData. versionOfNodes determines which version CFXMLNodes are produced
 
241
   by the parser; see CFXMLNode.h for more details.  callBacks are the callbacks called by the parser as
 
242
   the parse progresses; callBacks, callBacks->createXMLStructure, callBacks->addChild, and
 
243
   callBacks->endXMLStructure must all be non-NULL.  context determines what if any info pointer is
 
244
   passed to the callbacks as the parse progresses; context may be NULL.  }
 
245
function CFXMLParserCreate( allocator: CFAllocatorRef; xmlData: CFDataRef; dataSource: CFURLRef; parseOptions: CFOptionFlags; versionOfNodes: CFIndex; var callBacks: CFXMLParserCallBacks; var context: CFXMLParserContext ): CFXMLParserRef; external name '_CFXMLParserCreate';
 
246
 
 
247
{ Arguments as above, except that the data to be parsed is loaded directly 
 
248
   from dataSource.  dataSource may not be NULL.  }
 
249
function CFXMLParserCreateWithDataFromURL( allocator: CFAllocatorRef; dataSource: CFURLRef; parseOptions: CFOptionFlags; versionOfNodes: CFIndex; var callBacks: CFXMLParserCallBacks; var context: CFXMLParserContext ): CFXMLParserRef; external name '_CFXMLParserCreateWithDataFromURL';
 
250
 
 
251
procedure CFXMLParserGetContext( parser: CFXMLParserRef; var context: CFXMLParserContext ); external name '_CFXMLParserGetContext';
 
252
 
 
253
procedure CFXMLParserGetCallBacks( parser: CFXMLParserRef; var callBacks: CFXMLParserCallBacks ); external name '_CFXMLParserGetCallBacks';
 
254
 
 
255
function CFXMLParserGetSourceURL( parser: CFXMLParserRef ): CFURLRef; external name '_CFXMLParserGetSourceURL';
 
256
 
 
257
{ Returns the character index of the current parse location }
 
258
function CFXMLParserGetLocation( parser: CFXMLParserRef ): CFIndex; external name '_CFXMLParserGetLocation';
 
259
 
 
260
{ Returns the line number of the current parse location }
 
261
function CFXMLParserGetLineNumber( parser: CFXMLParserRef ): CFIndex; external name '_CFXMLParserGetLineNumber';
 
262
 
 
263
{ Returns the top-most object returned by the createXMLStructure callback }
 
264
function CFXMLParserGetDocument( parser: CFXMLParserRef ): UnivPtr; external name '_CFXMLParserGetDocument';
 
265
 
 
266
{ Get the status code or a user-readable description of the last error that occurred in a parse.
 
267
   If no error has occurred, a null description string is returned.  See the enum above for
 
268
   possible status returns }
 
269
function CFXMLParserGetStatusCode( parser: CFXMLParserRef ): CFXMLParserStatusCode; external name '_CFXMLParserGetStatusCode';
 
270
 
 
271
function CFXMLParserCopyErrorDescription( parser: CFXMLParserRef ): CFStringRef; external name '_CFXMLParserCopyErrorDescription';
 
272
 
 
273
{ Cause any in-progress parse to abort with the given error code and description.  errorCode
 
274
   must be positive, and errorDescription may not be NULL.  Cannot be called asynchronously
 
275
   (i.e. must be called from within a parser callback) }
 
276
procedure CFXMLParserAbort( parser: CFXMLParserRef; errorCode: CFXMLParserStatusCode; errorDescription: CFStringRef ); external name '_CFXMLParserAbort';
 
277
 
 
278
{ Starts a parse of the data the parser was created with; returns success or failure.
 
279
   Upon success, use CFXMLParserGetDocument() to get the product of the parse.  Upon
 
280
   failure, use CFXMLParserGetErrorCode() or CFXMLParserCopyErrorDescription() to get
 
281
   information about the error.  It is an error to call CFXMLParserParse() while a
 
282
   parse is already underway. }
 
283
function CFXMLParserParse( parser: CFXMLParserRef ): Boolean; external name '_CFXMLParserParse';
 
284
 
 
285
{ These functions provide a higher-level interface.  The XML data is parsed to a
 
286
   special CFTree (an CFXMLTree) with known contexts and callbacks.  See CFXMLNode.h
 
287
   for full details on using an CFXMLTree and the CFXMLNodes contained therein.
 
288
}
 
289
{ Parse to an CFXMLTreeRef.  parseOptions are as above. versionOfNodes determines
 
290
   what version CFXMLNodes are used to populate the tree.  }
 
291
function CFXMLTreeCreateFromData( allocator: CFAllocatorRef; xmlData: CFDataRef; dataSource: CFURLRef; parseOptions: CFOptionFlags; versionOfNodes: CFIndex ): CFXMLTreeRef; external name '_CFXMLTreeCreateFromData';
 
292
 
 
293
{ As above, with the additional by-reference pass of a CFDictionaryRef containing
 
294
   various error information (see below). The caller is responsible for releasing the
 
295
   returned dictionary. If the error dictionary is not desired, pass NULL. }
 
296
function CFXMLTreeCreateFromDataWithError( allocator: CFAllocatorRef; xmlData: CFDataRef; dataSource: CFURLRef; parseOptions: CFOptionFlags; versionOfNodes: CFIndex; var errorDict: CFDictionaryRef ): CFXMLTreeRef; external name '_CFXMLTreeCreateFromDataWithError';
 
297
(* AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER *)
 
298
 
 
299
{ Loads the data to be parsed directly from dataSource.  Arguments as above. }
 
300
function CFXMLTreeCreateWithDataFromURL( allocator: CFAllocatorRef; dataSource: CFURLRef; parseOptions: CFOptionFlags; versionOfNodes: CFIndex ): CFXMLTreeRef; external name '_CFXMLTreeCreateWithDataFromURL';
 
301
 
 
302
{ Generate the XMLData (ready to be written to whatever permanent storage is to be
 
303
   used) from an CFXMLTree.  Will NOT regenerate entity references (except those
 
304
   required for syntactic correctness) if they were replaced at the parse time;
 
305
   clients that wish this should walk the tree and re-insert any entity references
 
306
   that should appear in the final output file. }
 
307
function CFXMLTreeCreateXMLData( allocator: CFAllocatorRef; xmlTree: CFXMLTreeRef ): CFDataRef; external name '_CFXMLTreeCreateXMLData';
 
308
 
 
309
{ Escaping and unescaping XML entities in CFStrings. The standard XML entities
 
310
   are always replaced.  }
 
311
{ Creates a CFString by replacing entities that appear in the entities dictionary.
 
312
   Dictionary keys are the entities themselves, and the values should be CFStrings
 
313
   containing the expansion. Pass NULL for entitiesDictionary to indicate no entities
 
314
   other than the standard five. }
 
315
function CFXMLCreateStringByEscapingEntities( allocator: CFAllocatorRef; strng: CFStringRef; entitiesDictionary: CFDictionaryRef ): CFStringRef; external name '_CFXMLCreateStringByEscapingEntities';
 
316
(* AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER *)
 
317
 
 
318
function CFXMLCreateStringByUnescapingEntities( allocator: CFAllocatorRef; strng: CFStringRef; entitiesDictionary: CFDictionaryRef ): CFStringRef; external name '_CFXMLCreateStringByUnescapingEntities';
 
319
(* AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER *)
 
320
 
 
321
{ CFXMLTreeCreateFromDataWithError error dictionary key constants. }
 
322
var kCFXMLTreeErrorDescription: CFStringRef; external name '_kCFXMLTreeErrorDescription'; (* attribute const *)
 
323
(* AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER *)
 
324
    { value is a CFString containing the readable error string. }
 
325
 
 
326
var kCFXMLTreeErrorLineNumber: CFStringRef; external name '_kCFXMLTreeErrorLineNumber'; (* attribute const *)
 
327
(* AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER *)
 
328
    { value is a CFNumber containing the line on which the error appears. }
 
329
 
 
330
var kCFXMLTreeErrorLocation: CFStringRef; external name '_kCFXMLTreeErrorLocation'; (* attribute const *)
 
331
(* AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER *)
 
332
    { value is a CFNumber containing the byte location at which the error occurred. }
 
333
 
 
334
var kCFXMLTreeErrorStatusCode: CFStringRef; external name '_kCFXMLTreeErrorStatusCode'; (* attribute const *)
 
335
(* AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER *)
 
336
    { value is a CFNumber containing the error status code. }
 
337
 
 
338
 
 
339
end.