~ubuntu-branches/ubuntu/vivid/tidy/vivid-updates

« back to all changes in this revision

Viewing changes to include/tidy.h

  • Committer: Bazaar Package Importer
  • Author(s): Jason Thomas
  • Date: 2008-01-20 21:46:03 UTC
  • mfrom: (0.2.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20080120214603-oqicq5jwr1exrm55
Tags: 20080116cvs-2
* debian/control: build depends on xsltproc
  (closes: #461608)
* debian/tidy.preinst,postinst: add code to move old config file
  (closes: #461623)

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
  this-equivalent as 1st arg.
12
12
 
13
13
 
14
 
  Copyright (c) 1998-2005 World Wide Web Consortium
 
14
  Copyright (c) 1998-2007 World Wide Web Consortium
15
15
  (Massachusetts Institute of Technology, European Research 
16
16
  Consortium for Informatics and Mathematics, Keio University).
17
17
  All Rights Reserved.
19
19
  CVS Info :
20
20
 
21
21
    $Author: arnaud02 $ 
22
 
    $Date: 2005/04/08 09:11:12 $ 
23
 
    $Revision: 1.13 $ 
 
22
    $Date: 2007/02/07 11:02:54 $ 
 
23
    $Revision: 1.20 $ 
24
24
 
25
25
  Contributing Author(s):
26
26
 
107
107
typedef struct _TidyBuffer TidyBuffer;
108
108
 
109
109
 
 
110
/** @defgroup Memory  Memory Allocation
 
111
**
 
112
** Tidy uses a user provided allocator for all
 
113
** memory allocations.  If this allocator is
 
114
** not provided, then a default allocator is
 
115
** used which simply wraps standard C malloc/free
 
116
** calls.  These wrappers call the panic function
 
117
** upon any failure.  The default panic function
 
118
** prints an out of memory message to stderr, and
 
119
** calls exit(2).
 
120
**
 
121
** For applications in which it is unacceptable to
 
122
** abort in the case of memory allocation, then the
 
123
** panic function can be replaced with one which
 
124
** longjmps() out of the tidy code.  For this to
 
125
** clean up completely, you should be careful not
 
126
** to use any tidy methods that open files as these
 
127
** will not be closed before panic() is called.
 
128
**
 
129
** TODO: associate file handles with tidyDoc and
 
130
** ensure that tidyDocRelease() can close them all.
 
131
**
 
132
** Calling the withAllocator() family (
 
133
** tidyCreateWithAllocator, tidyBufInitWithAllocator,
 
134
** tidyBufAllocWithAllocator) allow settings custom
 
135
** allocators).
 
136
**
 
137
** All parts of the document use the same allocator.
 
138
** Calls that require a user provided buffer can
 
139
** optionally use a different allocator.
 
140
**
 
141
** For reference in designing a plug-in allocator,
 
142
** most allocations made by tidy are less than 100
 
143
** bytes, corresponding to attribute names/values, etc.
 
144
**
 
145
** There is also an additional class of much larger
 
146
** allocations which are where most of the data from
 
147
** the lexer is stored.  (It is not currently possible
 
148
** to use a separate allocator for the lexer, this
 
149
** would be a useful extension).
 
150
**
 
151
** In general, approximately 1/3rd of the memory
 
152
** used by tidy is freed during the parse, so if
 
153
** memory usage is an issue then an allocator that 
 
154
** can reuse this memory is a good idea.
 
155
**
 
156
** @{
 
157
*/
 
158
 
 
159
/** Prototype for the allocator's function table */
 
160
struct _TidyAllocatorVtbl;
 
161
/** The allocators function table */
 
162
typedef struct _TidyAllocatorVtbl TidyAllocatorVtbl;
 
163
 
 
164
/** Prototype for the allocator */
 
165
struct _TidyAllocator;
 
166
/** The allocator **/
 
167
typedef struct _TidyAllocator TidyAllocator;
 
168
 
 
169
/** An allocator's function table.  All functions here must
 
170
    be provided.
 
171
 */
 
172
struct _TidyAllocatorVtbl {
 
173
    /** Called to allocate a block of nBytes of memory */
 
174
    void* (TIDY_CALL *alloc)( TidyAllocator *self, size_t nBytes );
 
175
    /** Called to resize (grow, in general) a block of memory.
 
176
        Must support being called with NULL.
 
177
    */
 
178
    void* (TIDY_CALL *realloc)( TidyAllocator *self, void *block, size_t nBytes );
 
179
    /** Called to free a previously allocated block of memory */
 
180
    void (TIDY_CALL *free)( TidyAllocator *self, void *block);
 
181
    /** Called when a panic condition is detected.  Must support
 
182
        block == NULL.  This function is not called if either alloc 
 
183
        or realloc fails; it is up to the allocator to do this.
 
184
        Currently this function can only be called if an error is
 
185
        detected in the tree integrity via the internal function
 
186
        CheckNodeIntegrity().  This is a situation that can
 
187
        only arise in the case of a programming error in tidylib.
 
188
        You can turn off node integrity checking by defining
 
189
        the constant NO_NODE_INTEGRITY_CHECK during the build.
 
190
    **/
 
191
    void (TIDY_CALL *panic)( TidyAllocator *self, ctmbstr msg );
 
192
};
 
193
 
 
194
/** An allocator.  To create your own allocator, do something like
 
195
    the following:
 
196
    
 
197
    typedef struct _MyAllocator {
 
198
       TidyAllocator base;
 
199
       ...other custom allocator state...
 
200
    } MyAllocator;
 
201
    
 
202
    void* MyAllocator_alloc(TidyAllocator *base, void *block, size_t nBytes)
 
203
    {
 
204
        MyAllocator *self = (MyAllocator*)base;
 
205
        ...
 
206
    }
 
207
    (etc)
 
208
 
 
209
    static const TidyAllocatorVtbl MyAllocatorVtbl = {
 
210
        MyAllocator_alloc,
 
211
        MyAllocator_realloc,
 
212
        MyAllocator_free,
 
213
        MyAllocator_panic
 
214
    };
 
215
 
 
216
    myAllocator allocator;
 
217
    TidyDoc doc;
 
218
 
 
219
    allocator.base.vtbl = &MyAllocatorVtbl;
 
220
    ...initialise allocator specific state...
 
221
    doc = tidyCreateWithAllocator(&allocator);
 
222
    ...
 
223
 
 
224
    Although this looks slightly long winded, the advantage is that to create
 
225
    a custom allocator you simply need to set the vtbl pointer correctly.
 
226
    The vtbl itself can reside in static/global data, and hence does not
 
227
    need to be initialised each time an allocator is created, and furthermore
 
228
    the memory is shared amongst all created allocators.
 
229
*/
 
230
struct _TidyAllocator {
 
231
    const TidyAllocatorVtbl *vtbl;
 
232
};
 
233
 
 
234
/** Callback for "malloc" replacement */
 
235
typedef void* (TIDY_CALL *TidyMalloc)( size_t len );
 
236
/** Callback for "realloc" replacement */
 
237
typedef void* (TIDY_CALL *TidyRealloc)( void* buf, size_t len );
 
238
/** Callback for "free" replacement */
 
239
typedef void  (TIDY_CALL *TidyFree)( void* buf );
 
240
/** Callback for "out of memory" panic state */
 
241
typedef void  (TIDY_CALL *TidyPanic)( ctmbstr mssg );
 
242
 
 
243
 
 
244
/** Give Tidy a malloc() replacement */
 
245
TIDY_EXPORT Bool TIDY_CALL tidySetMallocCall( TidyMalloc fmalloc );
 
246
/** Give Tidy a realloc() replacement */
 
247
TIDY_EXPORT Bool TIDY_CALL tidySetReallocCall( TidyRealloc frealloc );
 
248
/** Give Tidy a free() replacement */
 
249
TIDY_EXPORT Bool TIDY_CALL tidySetFreeCall( TidyFree ffree );
 
250
/** Give Tidy an "out of memory" handler */
 
251
TIDY_EXPORT Bool TIDY_CALL tidySetPanicCall( TidyPanic fpanic );
 
252
 
 
253
/** @} end Memory group */
 
254
 
110
255
/** @defgroup Basic Basic Operations
111
256
**
112
257
** Tidy public interface
131
276
int main(int argc, char **argv )
132
277
{
133
278
  const char* input = "<title>Foo</title><p>Foo!";
134
 
  TidyBuffer output = {0};
135
 
  TidyBuffer errbuf = {0};
 
279
  TidyBuffer output;
 
280
  TidyBuffer errbuf;
136
281
  int rc = -1;
137
282
  Bool ok;
138
283
 
139
284
  TidyDoc tdoc = tidyCreate();                     // Initialize "document"
 
285
  tidyBufInit( &output );
 
286
  tidyBufInit( &errbuf );
140
287
  printf( "Tidying:\t\%s\\n", input );
141
288
 
142
289
  ok = tidyOptSetBool( tdoc, TidyXhtmlOut, yes );  // Convert to XHTML
172
319
*/
173
320
 
174
321
TIDY_EXPORT TidyDoc TIDY_CALL     tidyCreate(void);
 
322
TIDY_EXPORT TidyDoc TIDY_CALL     tidyCreateWithAllocator( TidyAllocator *allocator );
175
323
TIDY_EXPORT void TIDY_CALL        tidyRelease( TidyDoc tdoc );
176
324
 
177
325
/** Let application store a chunk of data w/ each Tidy instance.
178
326
**  Useful for callbacks.
179
327
*/
180
 
TIDY_EXPORT void TIDY_CALL        tidySetAppData( TidyDoc tdoc, ulong appData );
 
328
TIDY_EXPORT void TIDY_CALL        tidySetAppData( TidyDoc tdoc, void* appData );
181
329
 
182
330
/** Get application data set previously */
183
 
TIDY_EXPORT ulong TIDY_CALL       tidyGetAppData( TidyDoc tdoc );
 
331
TIDY_EXPORT void* TIDY_CALL       tidyGetAppData( TidyDoc tdoc );
184
332
 
185
333
/** Get release date (version) for current library */
186
334
TIDY_EXPORT ctmbstr TIDY_CALL     tidyReleaseDate(void);
221
369
 
222
370
/** Load a Tidy configuration file with the specified character encoding */
223
371
TIDY_EXPORT int TIDY_CALL         tidyLoadConfigEnc( TidyDoc tdoc, ctmbstr configFile,
224
 
                                           ctmbstr charenc );
 
372
                                                     ctmbstr charenc );
225
373
 
226
 
TIDY_EXPORT Bool TIDY_CALL        tidyFileExists( ctmbstr filename );
 
374
TIDY_EXPORT Bool TIDY_CALL        tidyFileExists( TidyDoc tdoc, ctmbstr filename );
227
375
 
228
376
 
229
377
/** Set the input/output character encoding for parsing markup.
393
541
   Input Source
394
542
*****************/
395
543
/** Input Callback: get next byte of input */
396
 
typedef int  (TIDY_CALL *TidyGetByteFunc)( ulong sourceData );
 
544
typedef int  (TIDY_CALL *TidyGetByteFunc)( void* sourceData );
397
545
 
398
546
/** Input Callback: unget a byte of input */
399
 
typedef void (TIDY_CALL *TidyUngetByteFunc)( ulong sourceData, byte bt );
 
547
typedef void (TIDY_CALL *TidyUngetByteFunc)( void* sourceData, byte bt );
400
548
 
401
549
/** Input Callback: is end of input? */
402
 
typedef Bool (TIDY_CALL *TidyEOFFunc)( ulong sourceData );
 
550
typedef Bool (TIDY_CALL *TidyEOFFunc)( void* sourceData );
403
551
 
404
552
/** End of input "character" */
405
553
#define EndOfStream (~0u)
410
558
typedef struct _TidyInputSource
411
559
{
412
560
  /* Instance data */
413
 
  ulong               sourceData;  /**< Input context.  Passed to callbacks */
 
561
  void*               sourceData;  /**< Input context.  Passed to callbacks */
414
562
 
415
563
  /* Methods */
416
564
  TidyGetByteFunc     getByte;     /**< Pointer to "get byte" callback */
442
590
   Output Sink
443
591
****************/
444
592
/** Output callback: send a byte to output */
445
 
typedef void (TIDY_CALL *TidyPutByteFunc)( ulong sinkData, byte bt );
 
593
typedef void (TIDY_CALL *TidyPutByteFunc)( void* sinkData, byte bt );
446
594
 
447
595
 
448
596
/** TidyOutputSink - accepts raw bytes of output
451
599
typedef struct _TidyOutputSink
452
600
{
453
601
  /* Instance data */
454
 
  ulong               sinkData;  /**< Output context.  Passed to callbacks */
 
602
  void*               sinkData;  /**< Output context.  Passed to callbacks */
455
603
 
456
604
  /* Methods */
457
605
  TidyPutByteFunc     putByte;   /**< Pointer to "put byte" callback */
490
638
 
491
639
/** @} end IO group */
492
640
 
493
 
 
494
 
/** @defgroup Memory  Memory Allocation
495
 
**
496
 
** By default, Tidy will use its own wrappers
497
 
** around standard C malloc/free calls. 
498
 
** These wrappers will abort upon any failures.
499
 
** If any are set, all must be set.
500
 
** Pass NULL to clear previous setting.
501
 
**
502
 
** May be used to set environment-specific allocators
503
 
** such as used by web server plugins, etc.
504
 
**
505
 
** @{
506
 
*/
507
 
 
508
 
/** Callback for "malloc" replacement */
509
 
typedef void* (TIDY_CALL *TidyMalloc)( size_t len );
510
 
/** Callback for "realloc" replacement */
511
 
typedef void* (TIDY_CALL *TidyRealloc)( void* buf, size_t len );
512
 
/** Callback for "free" replacement */
513
 
typedef void  (TIDY_CALL *TidyFree)( void* buf );
514
 
/** Callback for "out of memory" panic state */
515
 
typedef void  (TIDY_CALL *TidyPanic)( ctmbstr mssg );
516
 
 
517
 
/** Give Tidy a malloc() replacement */
518
 
TIDY_EXPORT Bool TIDY_CALL        tidySetMallocCall( TidyMalloc fmalloc );
519
 
/** Give Tidy a realloc() replacement */
520
 
TIDY_EXPORT Bool TIDY_CALL        tidySetReallocCall( TidyRealloc frealloc );
521
 
/** Give Tidy a free() replacement */
522
 
TIDY_EXPORT Bool TIDY_CALL        tidySetFreeCall( TidyFree ffree );
523
 
/** Give Tidy an "out of memory" handler */
524
 
TIDY_EXPORT Bool TIDY_CALL        tidySetPanicCall( TidyPanic fpanic );
525
 
 
526
 
/** @} end Memory group */
527
 
 
528
641
/* TODO: Catalog all messages for easy translation
529
642
TIDY_EXPORT ctmbstr     tidyLookupMessage( int errorNo );
530
643
*/
740
853
TIDY_EXPORT uint TIDY_CALL tidyNodeLine( TidyNode tnod );
741
854
TIDY_EXPORT uint TIDY_CALL tidyNodeColumn( TidyNode tnod );
742
855
 
 
856
/** @defgroup NodeIsElementName
 
857
**
 
858
** @deprecated The functions tidyNodeIs{ElementName} are deprecated and 
 
859
** should be replaced by tidyNodeGetId.
 
860
** @{
 
861
*/
743
862
TIDY_EXPORT Bool TIDY_CALL tidyNodeIsHTML( TidyNode tnod );
744
863
TIDY_EXPORT Bool TIDY_CALL tidyNodeIsHEAD( TidyNode tnod );
745
864
TIDY_EXPORT Bool TIDY_CALL tidyNodeIsTITLE( TidyNode tnod );
821
940
TIDY_EXPORT Bool TIDY_CALL tidyNodeIsU( TidyNode tnod );
822
941
TIDY_EXPORT Bool TIDY_CALL tidyNodeIsMENU( TidyNode tnod );
823
942
 
 
943
/** @} End NodeIsElementName group */
 
944
 
824
945
/** @} End NodeAsk group */
825
946
 
826
947
 
834
955
TIDY_EXPORT Bool TIDY_CALL tidyAttrIsEvent( TidyAttr tattr );
835
956
TIDY_EXPORT Bool TIDY_CALL tidyAttrIsProp( TidyAttr tattr );
836
957
 
 
958
/** @defgroup AttrIsAttributeName
 
959
**
 
960
** @deprecated The functions  tidyAttrIs{AttributeName} are deprecated and 
 
961
** should be replaced by tidyAttrGetId.
 
962
** @{
 
963
*/
837
964
TIDY_EXPORT Bool TIDY_CALL tidyAttrIsHREF( TidyAttr tattr );
838
965
TIDY_EXPORT Bool TIDY_CALL tidyAttrIsSRC( TidyAttr tattr );
839
966
TIDY_EXPORT Bool TIDY_CALL tidyAttrIsID( TidyAttr tattr );
880
1007
TIDY_EXPORT Bool TIDY_CALL tidyAttrIsCOLSPAN( TidyAttr tattr );
881
1008
TIDY_EXPORT Bool TIDY_CALL tidyAttrIsROWSPAN( TidyAttr tattr );
882
1009
 
 
1010
/** @} End AttrIsAttributeName group */
 
1011
 
883
1012
/** @} end AttrAsk group */
884
1013
 
885
1014
 
889
1018
** @{
890
1019
*/
891
1020
 
 
1021
TIDY_EXPORT TidyAttr TIDY_CALL tidyAttrGetById( TidyNode tnod, TidyAttrId attId );
892
1022
 
 
1023
/** @defgroup AttrGetAttributeName
 
1024
**
 
1025
** @deprecated The functions tidyAttrGet{AttributeName} are deprecated and 
 
1026
** should be replaced by tidyAttrGetById.
 
1027
** For instance, tidyAttrGetID( TidyNode tnod ) can be replaced by 
 
1028
** tidyAttrGetById( TidyNode tnod, TidyAttr_ID ). This avoids a potential
 
1029
** name clash with tidyAttrGetId for case-insensitive languages.
 
1030
** @{
 
1031
*/
893
1032
TIDY_EXPORT TidyAttr TIDY_CALL tidyAttrGetHREF( TidyNode tnod );
894
1033
TIDY_EXPORT TidyAttr TIDY_CALL tidyAttrGetSRC( TidyNode tnod );
895
1034
TIDY_EXPORT TidyAttr TIDY_CALL tidyAttrGetID( TidyNode tnod );
936
1075
TIDY_EXPORT TidyAttr TIDY_CALL tidyAttrGetCOLSPAN( TidyNode tnod );
937
1076
TIDY_EXPORT TidyAttr TIDY_CALL tidyAttrGetROWSPAN( TidyNode tnod );
938
1077
 
 
1078
/** @} End AttrGetAttributeName group */
939
1079
 
940
1080
/** @} end AttrGet group */
941
1081
 
943
1083
}  /* extern "C" */
944
1084
#endif
945
1085
#endif /* __TIDY_H__ */
 
1086
 
 
1087
/*
 
1088
 * local variables:
 
1089
 * mode: c
 
1090
 * indent-tabs-mode: nil
 
1091
 * c-basic-offset: 4
 
1092
 * eval: (c-set-offset 'substatement-open 0)
 
1093
 * end:
 
1094
 */