aboutsummaryrefslogtreecommitdiffstats
path: root/os400/libxmlrpg/HTMLparser.rpgle
blob: d4c5f8d9b8abc1105c30c718ac2acdd3029d7275 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
      * Summary: interface for an HTML 4.0 non-verifying parser
      * Description: this module implements an HTML 4.0 non-verifying parser
      *              with API compatible with the XML parser ones. It should
      *              be able to parse "real world" HTML, even if severely
      *              broken from a specification point of view.
      *
      * Copy: See Copyright for the status of this software.
      *
      * Author: Patrick Monnerat <pm@datasphere.ch>, DATASPHERE S.A.

      /if not defined(HTML_PARSER_H__)
      /define HTML_PARSER_H__

      /include "libxmlrpg/xmlversion"
      /include "libxmlrpg/xmlTypesC"
      /include "libxmlrpg/parser"

      /if defined(LIBXML_HTML_ENABLED)

      * Most of the back-end structures from XML and HTML are shared.

     d htmlParserCtxtPtr...
     d                 s                   based(######typedef######)
     d                                     like(xmlParserCtxtPtr)

     d htmlParserCtxt  ds                  based(htmlParserCtxtPtr)
     d                                     likeds(xmlParserCtxt)

     d htmlParserNodeInfoPtr...
     d                 s                   based(######typedef######)
     d                                     like(xmlParserNodeInfoPtr)

     d htmlParserNodeInfo...
     d                 ds                  based(htmlParserNodeInfoPtr)
     d                                     likeds(xmlParserNodeInfo)

     d htmlSAXHandlerPtr...
     d                 s                   based(######typedef######)
     d                                     like(xmlSAXHandlerPtr)

     d htmlSAXHandler  ds                  based(htmlSAXHandlerPtr)
     d                                     likeds(xmlSAXHandler)

     d htmlParserInputPtr...
     d                 s                   based(######typedef######)
     d                                     like(xmlParserInputPtr)

     d htmlParserInput...
     d                 ds                  based(htmlParserInputPtr)
     d                                     likeds(xmlParserInput)

     d htmlDocPtr      s                   based(######typedef######)
     d                                     like(xmlDocPtr)

     d htmlNodePtr     s                   based(######typedef######)
     d                                     like(xmlNodePtr)

      * Internal description of an HTML element, representing HTML 4.01
      * and XHTML 1.0 (which share the same structure).

     d htmlElemDescPtr...
     d                 s               *   based(######typedef######)

     d htmlElemDesc    ds                  based(htmlElemDescPtr)
     d                                     align qualified
     d  name                           *                                        const char *
     d  startTag                           like(xmlCchar)                       Start tag implied ?
     d  endTag                             like(xmlCchar)                       End tag implied ?
     d  saveEndTag                         like(xmlCchar)                       Save end tag ?
     d  empty                              like(xmlCchar)                       Empty element ?
     d  depr                               like(xmlCchar)                       Deprecated element ?
     d  dtd                                like(xmlCchar)                       Loose DTD/Frameset
     d  isinline                           like(xmlCchar)                       Block 0/inline elem?
     d  desc                           *                                        const char *
      *
      * New fields encapsulating HTML structure
      *
      * Bugs:
      *      This is a very limited representation.  It fails to tell us when
      *      an element *requires* subelements (we only have whether they're
      *      allowed or not), and it doesn't tell us where CDATA and PCDATA
      *      are allowed.  Some element relationships are not fully represented:
      *      these are flagged with the word MODIFIER
      *
     d  subelts                        *                                        const char * *
     d  defaultsubelt                  *                                        const char *
     d  attrs_opt                      *                                        const char * *
     d  attrs_depr                     *                                        const char * *
     d  attrs_req                      *                                        const char * *

      * Internal description of an HTML entity.

     d htmlEntityDescPtr...
     d                 s               *   based(######typedef######)

     d htmlEntityDesc...
     d                 ds                  based(htmlEntityDescPtr)
     d                                     align qualified
     d  value                        10u 0                                      Unicode char value
     d  name                           *                                        const char *
     d  desc                           *                                        const char *

      * There is only few public functions.

     d htmlTagLookup   pr                  extproc('htmlTagLookup')
     d                                     like(htmlElemDescPtr)                const
     d  tag                            *   value options(*string)               const xmlChar *

     d htmlEntityLookup...
     d                 pr                  extproc('htmlEntityLookup')
     d                                     like(htmlEntityDescPtr)              const
     d  name                           *   value options(*string)               const xmlChar *

     d htmlEntityValueLookup...
     d                 pr                  extproc('htmlEntityValueLookup')
     d                                     like(htmlEntityDescPtr)              const
     d  value                        10u 0 value

     d htmlIsAutoClosed...
     d                 pr            10i 0 extproc('htmlIsAutoClosed')
     d  doc                                value like(htmlDocPtr)
     d  elem                               value like(htmlNodePtr)

     d htmlAutoCloseTag...
     d                 pr            10i 0 extproc('htmlAutoCloseTag')
     d  doc                                value like(htmlDocPtr)
     d  name                           *   value options(*string)               const xmlChar *
     d  elem                               value like(htmlNodePtr)

     d htmlParseEntityRef...
     d                 pr                  extproc('htmlParseEntityRef')
     d                                     like(htmlEntityDescPtr)              const
     d  ctxt                               value like(htmlParserCtxtPtr)
     d  str                            *                                        const xmlChar *(*)

     d htmlParseCharRef...
     d                 pr            10i 0 extproc('htmlParseCharRef')
     d  ctxt                               value like(htmlParserCtxtPtr)

     d htmlParseElement...
     d                 pr                  extproc('htmlParseElement')
     d  ctxt                               value like(htmlParserCtxtPtr)

     d htmlNewParserCtxt...
     d                 pr                  extproc('htmlNewParserCtxt')
     d                                     like(htmlParserCtxtPtr)

     d htmlCreateMemoryParserCtxt...
     d                 pr                  extproc('htmlCreateMemoryParserCtxt')
     d                                     like(htmlParserCtxtPtr)
     d  buffer                         *   value options(*string)               const char *
     d  size                         10i 0 value

     d htmlParseDocument...
     d                 pr            10i 0 extproc('htmlParseDocument')
     d  ctxt                               value like(htmlParserCtxtPtr)

     d htmlSAXParseDoc...
     d                 pr                  extproc('htmlSAXParseDoc')
     d                                     like(htmlDocPtr)
     d  cur                            *   value options(*string)               xmlChar *
     d  encoding                       *   value options(*string)               const char *
     d  sax                                value like(htmlSAXHandlerPtr)
     d  userData                       *   value                                void *

     d htmlParseDoc    pr                  extproc('htmlParseDoc')
     d                                     like(htmlDocPtr)
     d  cur                            *   value options(*string)               xmlChar *
     d  encoding                       *   value options(*string)               const char *

     d htmlSAXParseFile...
     d                 pr                  extproc('htmlSAXParseFile')
     d                                     like(htmlDocPtr)
     d  filename                       *   value options(*string)               const char *
     d  encoding                       *   value options(*string)               const char *
     d  sax                                value like(htmlSAXHandlerPtr)
     d  userData                       *   value                                void *

     d htmlParseFile   pr                  extproc('htmlParseFile')
     d                                     like(htmlDocPtr)
     d  filename                       *   value options(*string)               const char *
     d  encoding                       *   value options(*string)               const char *

     d UTF8ToHtml      pr            10i 0 extproc('UTF8ToHtml')
     d  out                       65535    options(*varsize)                    unsigned char []
     d  outlen                       10i 0
     d  in                             *   value options(*string)               const unsigned char*
     d  inlen                        10i 0

     d htmlEncodeEntities...
     d                 pr            10i 0 extproc('htmlEncodeEntities')
     d  out                       65535    options(*varsize)                    unsigned char []
     d  outlen                       10i 0
     d  in                             *   value options(*string)               const unsigned char*
     d  inlen                        10i 0
     d  quoteChar                    10i 0 value

     d htmlIsScriptAttribute...
     d                 pr            10i 0 extproc('htmlIsScriptAttribute')
     d  name                           *   value options(*string)               const xmlChar *

     d htmlHandleOmittedElem...
     d                 pr            10i 0 extproc('htmlHandleOmittedElem')
     d  val                          10i 0 value

      /if defined(LIBXML_PUSH_ENABLED)

      * Interfaces for the Push mode.

     d htmlCreatePushParserCtxt...
     d                 pr                  extproc('htmlCreatePushParserCtxt')
     d                                     like(htmlParserCtxtPtr)
     d  sax                                value like(htmlSAXHandlerPtr)
     d  user_data                      *   value                                void *
     d  chunk                          *   value options(*string)               const char *
     d  size                         10i 0 value
     d  filename                       *   value options(*string)               const char *
     d  enc                                value like(xmlCharEncoding)

     d htmlParseChunk  pr            10i 0 extproc('htmlParseChunk')
     d  ctxt                               value like(htmlParserCtxtPtr)
     d  chunk                          *   value options(*string)               const char *
     d  size                         10i 0 value
     d  terminate                    10i 0 value
      /endif                                                                    LIBXML_PUSH_ENABLED

     d htmlFreeParserCtxt...
     d                 pr                  extproc('htmlFreeParserCtxt')
     d  ctxt                               value like(htmlParserCtxtPtr)

      * New set of simpler/more flexible APIs

      * xmlParserOption:
      *
      * This is the set of XML parser options that can be passed down
      * to the xmlReadDoc() and similar calls.

     d htmlParserOption...
     d                 s             10i 0 based(######typedef######)           enum
     d  HTML_PARSE_RECOVER...                                                   Relaxed parsing
     d                 c                   X'00000001'
     d  HTML_PARSE_NODEFDTD...                                                  No default doctype
     d                 c                   X'00000004'
     d  HTML_PARSE_NOERROR...                                                   No error reports
     d                 c                   X'00000020'
     d  HTML_PARSE_NOWARNING...                                                 No warning reports
     d                 c                   X'00000040'
     d  HTML_PARSE_PEDANTIC...                                                  Pedantic err reports
     d                 c                   X'00000080'
     d  HTML_PARSE_NOBLANKS...                                                  Remove blank nodes
     d                 c                   X'00000100'
     d  HTML_PARSE_NONET...                                                     Forbid net access
     d                 c                   X'00000800'
     d  HTML_PARSE_NOIMPLIED...                                                 No implied html/body
     d                 c                   X'00002000'
     d  HTML_PARSE_COMPACT...                                                   compact small txtnod
     d                 c                   X'00010000'
     d  HTML_PARSE_IGNORE_ENC...                                                Ignore encoding hint
     d                 c                   X'00200000'

     d htmlCtxtReset   pr                  extproc('htmlCtxtReset')
     d ctxt                                value like(htmlParserCtxtPtr)

     d htmlCtxtUseOptions...
     d                 pr            10i 0 extproc('htmlCtxtUseOptions')
     d ctxt                                value like(htmlParserCtxtPtr)
     d options                       10i 0 value

     d htmlReadDoc     pr                  extproc('htmlReadDoc')
     d                                     like(htmlDocPtr)
     d  cur                            *   value options(*string)               const xmlChar *
     d  URL                            *   value options(*string)               const char *
     d  encoding                       *   value options(*string)               const char *
     d  options                      10i 0 value

     d htmlReadFile    pr                  extproc('htmlReadFile')
     d                                     like(htmlDocPtr)
     d  URL                            *   value options(*string)               const char *
     d  encoding                       *   value options(*string)               const char *
     d  options                      10i 0 value

     d htmlReadMemory  pr                  extproc('htmlReadMemory')
     d                                     like(htmlDocPtr)
     d  buffer                         *   value options(*string)               const char *
     d  size                         10i 0 value
     d  URL                            *   value options(*string)               const char *
     d  encoding                       *   value options(*string)               const char *
     d  options                      10i 0 value

     d htmlReadFd      pr                  extproc('htmlReadFd')
     d                                     like(htmlDocPtr)
     d  fd                           10i 0 value
     d  URL                            *   value options(*string)               const char *
     d  encoding                       *   value options(*string)               const char *
     d  options                      10i 0 value

     d htmlReadIO      pr                  extproc('htmlReadIO')
     d                                     like(htmlDocPtr)
     d  ioread                             value like(xmlInputReadCallback)
     d  ioclose                            value like(xmlInputCloseCallback)
     d  ioctx                          *   value                                void *
     d  URL                            *   value options(*string)               const char *
     d  encoding                       *   value options(*string)               const char *
     d  options                      10i 0 value

     d htmlCtxtReadDoc...
     d                 pr                  extproc('htmlCtxtReadDoc')
     d                                     like(htmlDocPtr)
     d  ctxt                               value like(xmlParserCtxtPtr)
     d  cur                            *   value options(*string)               const xmlChar *
     d  URL                            *   value options(*string)               const char *
     d  encoding                       *   value options(*string)               const char *
     d  options                      10i 0 value

     d htmlCtxtReadFile...
     d                 pr                  extproc('htmlCtxtReadFile')
     d                                     like(htmlDocPtr)
     d  ctxt                               value like(xmlParserCtxtPtr)
     d  filename                       *   value options(*string)               const char *
     d  encoding                       *   value options(*string)               const char *
     d  options                      10i 0 value

     d htmlCtxtReadMemory...
     d                 pr                  extproc('htmlCtxtReadMemory')
     d                                     like(htmlDocPtr)
     d  ctxt                               value like(xmlParserCtxtPtr)
     d  buffer                         *   value options(*string)               const char *
     d  size                         10i 0 value
     d  URL                            *   value options(*string)               const char *
     d  encoding                       *   value options(*string)               const char *
     d  options                      10i 0 value

     d htmlCtxtReadFd  pr                  extproc('htmlCtxtReadFd')
     d                                     like(htmlDocPtr)
     d  ctxt                               value like(xmlParserCtxtPtr)
     d  fd                           10i 0 value
     d  URL                            *   value options(*string)               const char *
     d  encoding                       *   value options(*string)               const char *
     d  options                      10i 0 value

     d htmlCtxtReadIO  pr                  extproc('htmlCtxtReadIO')
     d                                     like(htmlDocPtr)
     d  ctxt                               value like(xmlParserCtxtPtr)
     d  ioread                             value like(xmlInputReadCallback)
     d  ioclose                            value like(xmlInputCloseCallback)
     d  ioctx                          *   value                                void *
     d  URL                            *   value options(*string)               const char *
     d  encoding                       *   value options(*string)               const char *
     d  options                      10i 0 value

      * Further knowledge of HTML structure

     d htmlStatus      s             10i 0 based(######typedef######)           enum
     d  HTML_NA        c                   X'0000'                              No check at all
     d  HTML_INVALID   c                   X'0001'
     d  HTML_DEPRECATED...
     d                 c                   X'0002'
     d  HTML_VALID     c                   X'0004'
     d  HTML_REQUIRED  c                   X'000C'                              HTML_VALID ored-in

      * Using htmlElemDesc rather than name here, to emphasise the fact
      *  that otherwise there's a lookup overhead

     d htmlAttrAllowed...
     d                 pr                  extproc('htmlAttrAllowed')
     d                                     like(htmlStatus)
     d  #param1                            value like(htmlElemDescPtr)          const
     d  #param2                        *   value options(*string)               const xmlChar *
     d  #param3                      10i 0 value

     d htmlElementAllowedHere...
     d                 pr            10i 0 extproc('htmlElementAllowedHere')
     d  #param1                            value like(htmlElemDescPtr)          const
     d  #param2                        *   value options(*string)               const xmlChar *

     d htmlElementStatusHere...
     d                 pr                  extproc('htmlElementStatusHere')
     d                                     like(htmlStatus)
     d  #param1                            value like(htmlElemDescPtr)          const
     d  #param2                            value like(htmlElemDescPtr)          const

     d htmlNodeStatus  pr                  extproc('htmlNodeStatus')
     d                                     like(htmlStatus)
     d  #param1                            value like(htmlNodePtr)
     d  #param2                      10i 0 value

      * C macros implemented as procedures for ILE/RPG support.

     d htmlDefaultSubelement...
     d                 pr              *   extproc('__htmlDefaultSubelement')   const char *
     d  elt                            *   value                                const htmlElemDesc *

     d htmlElementAllowedHereDesc...
     d                 pr            10i 0 extproc(
     d                                     '__htmlElementAllowedHereDesc')
     d  parent                         *   value                                const htmlElemDesc *
     d  elt                            *   value                                const htmlElemDesc *

     d htmlRequiredAttrs...
     d                 pr              *   extproc('__htmlRequiredAttrs')        const char * *
     d  elt                            *   value                                const htmlElemDesc *

      /endif                                                                    LIBXML_HTML_ENABLED
      /endif                                                                    HTML_PARSER_H__