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

« back to all changes in this revision

Viewing changes to src/streamio.c

  • 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:
1
1
/* streamio.c -- handles character stream I/O
2
2
 
3
 
  (c) 1998-2005 (W3C) MIT, ERCIM, Keio University
 
3
  (c) 1998-2007 (W3C) MIT, ERCIM, Keio University
4
4
  See tidy.h for the copyright notice.
5
5
 
6
6
  CVS Info :
7
7
 
8
8
    $Author: arnaud02 $ 
9
 
    $Date: 2005/07/22 15:54:58 $ 
10
 
    $Revision: 1.30 $ 
 
9
    $Date: 2007/07/22 09:33:26 $ 
 
10
    $Revision: 1.42 $ 
11
11
 
12
12
  Wrapper around Tidy input source and output sink
13
13
  that calls appropriate interfaces, and applies
46
46
static void EncodeIbm858( uint c, StreamOut* out );
47
47
static void EncodeLatin0( uint c, StreamOut* out );
48
48
 
 
49
static uint DecodeIbm850(uint c);
 
50
static uint DecodeLatin0(uint c);
 
51
 
 
52
static uint PopChar( StreamIn *in );
 
53
 
49
54
/******************************
50
55
** Static (duration) Globals
51
56
******************************/
56
61
    FSM_ASCII,
57
62
    DEFAULT_NL_CONFIG,
58
63
#ifdef TIDY_WIN32_MLANG_SUPPORT
59
 
    (ulong)NULL,
 
64
    NULL,
60
65
#endif
61
66
    FileIO,
62
 
    { 0, filesink_putByte }
 
67
    { 0, TY_(filesink_putByte) }
63
68
};
64
69
 
65
70
static StreamOut stdoutStreamOut = 
68
73
    FSM_ASCII,
69
74
    DEFAULT_NL_CONFIG,
70
75
#ifdef TIDY_WIN32_MLANG_SUPPORT
71
 
    (ulong)NULL,
 
76
    NULL,
72
77
#endif
73
78
    FileIO,
74
 
    { 0, filesink_putByte }
 
79
    { 0, TY_(filesink_putByte) }
75
80
};
76
81
 
77
 
StreamOut* StdErrOutput(void)
 
82
StreamOut* TY_(StdErrOutput)(void)
78
83
{
79
84
  if ( stderrStreamOut.sink.sinkData == 0 )
80
 
      stderrStreamOut.sink.sinkData = (ulong) stderr;
 
85
      stderrStreamOut.sink.sinkData = stderr;
81
86
  return &stderrStreamOut;
82
87
}
83
88
 
84
 
StreamOut* StdOutOutput(void)
 
89
#if 0
 
90
StreamOut* TY_(StdOutOutput)(void)
85
91
{
86
92
  if ( stdoutStreamOut.sink.sinkData == 0 )
87
 
      stdoutStreamOut.sink.sinkData = (ulong) stdout;
 
93
      stdoutStreamOut.sink.sinkData = stdout;
88
94
  return &stdoutStreamOut;
89
95
}
 
96
#endif
90
97
 
91
 
void  ReleaseStreamOut( StreamOut* out )
 
98
void  TY_(ReleaseStreamOut)( TidyDocImpl *doc,  StreamOut* out )
92
99
{
93
100
    if ( out && out != &stderrStreamOut && out != &stdoutStreamOut )
94
101
    {
95
102
        if ( out->iotype == FileIO )
96
103
            fclose( (FILE*) out->sink.sinkData );
97
 
        MemFree( out );
 
104
        TidyDocFree( doc, out );
98
105
    }
99
106
}
100
107
 
101
 
 
102
108
/************************
103
109
** Source
104
110
************************/
105
111
 
106
 
static StreamIn* initStreamIn( TidyDocImpl* doc, int encoding )
 
112
static void InitLastPos( StreamIn *in );
 
113
 
 
114
StreamIn* TY_(initStreamIn)( TidyDocImpl* doc, int encoding )
107
115
{
108
 
    StreamIn *in = (StreamIn*) MemAlloc( sizeof(StreamIn) );
 
116
    StreamIn *in = (StreamIn*) TidyDocAlloc( doc, sizeof(StreamIn) );
109
117
 
110
 
    ClearMemory( in, sizeof(StreamIn) );
 
118
    TidyClearMemory( in, sizeof(StreamIn) );
111
119
    in->curline = 1;
112
120
    in->curcol = 1;
113
121
    in->encoding = encoding;
114
122
    in->state = FSM_ASCII;
115
123
    in->doc = doc;
116
124
    in->bufsize = CHARBUF_SIZE;
117
 
    in->charbuf = (tchar*)MemAlloc(sizeof(tchar) * in->bufsize);
 
125
    in->allocator = doc->allocator;
 
126
    in->charbuf = (tchar*)TidyDocAlloc(doc, sizeof(tchar) * in->bufsize);
 
127
    InitLastPos( in );
118
128
#ifdef TIDY_STORE_ORIGINAL_TEXT
119
129
    in->otextbuf = NULL;
120
130
    in->otextlen = 0;
123
133
    return in;
124
134
}
125
135
 
126
 
void freeStreamIn(StreamIn* in)
 
136
void TY_(freeStreamIn)(StreamIn* in)
127
137
{
128
138
#ifdef TIDY_STORE_ORIGINAL_TEXT
129
139
    if (in->otextbuf)
130
 
        MemFree(in->otextbuf);
 
140
        TidyFree(in->allocator, in->otextbuf);
131
141
#endif
132
 
    MemFree(in->charbuf);
133
 
    MemFree(in);
 
142
    TidyFree(in->allocator, in->charbuf);
 
143
    TidyFree(in->allocator, in);
134
144
}
135
145
 
136
 
StreamIn* FileInput( TidyDocImpl* doc, FILE *fp, int encoding )
 
146
StreamIn* TY_(FileInput)( TidyDocImpl* doc, FILE *fp, int encoding )
137
147
{
138
 
    StreamIn *in = initStreamIn( doc, encoding );
139
 
    initFileSource( &in->source, fp );
 
148
    StreamIn *in = TY_(initStreamIn)( doc, encoding );
 
149
    if ( TY_(initFileSource)( doc->allocator, &in->source, fp ) != 0 )
 
150
    {
 
151
        TY_(freeStreamIn)( in );
 
152
        return NULL;
 
153
    }
140
154
    in->iotype = FileIO;
141
155
    return in;
142
156
}
143
157
 
144
 
StreamIn* BufferInput( TidyDocImpl* doc, TidyBuffer* buf, int encoding )
 
158
StreamIn* TY_(BufferInput)( TidyDocImpl* doc, TidyBuffer* buf, int encoding )
145
159
{
146
 
    StreamIn *in = initStreamIn( doc, encoding );
147
 
    initInputBuffer( &in->source, buf );
 
160
    StreamIn *in = TY_(initStreamIn)( doc, encoding );
 
161
    tidyInitInputBuffer( &in->source, buf );
148
162
    in->iotype = BufferIO;
149
163
    return in;
150
164
}
151
165
 
152
 
StreamIn* UserInput( TidyDocImpl* doc, TidyInputSource* source, int encoding )
 
166
StreamIn* TY_(UserInput)( TidyDocImpl* doc, TidyInputSource* source, int encoding )
153
167
{
154
 
    StreamIn *in = initStreamIn( doc, encoding );
 
168
    StreamIn *in = TY_(initStreamIn)( doc, encoding );
155
169
    memcpy( &in->source, source, sizeof(TidyInputSource) );
156
170
    in->iotype = UserIO;
157
171
    return in;
158
172
}
159
173
 
160
 
int ReadBOMEncoding(StreamIn *in)
 
174
int TY_(ReadBOMEncoding)(StreamIn *in)
161
175
{
162
176
    uint c, c1;
163
177
#if SUPPORT_UTF16_ENCODINGS
185
199
    {
186
200
        /* big-endian UTF-16 */
187
201
        if ( in->encoding != UTF16 && in->encoding != UTF16BE )
188
 
            ReportEncodingWarning(in->doc, ENCODING_MISMATCH, UTF16BE);
 
202
            TY_(ReportEncodingWarning)(in->doc, ENCODING_MISMATCH, UTF16BE);
189
203
 
190
204
        return UTF16BE; /* return decoded BOM */
191
205
    }
193
207
    {
194
208
        /* little-endian UTF-16 */
195
209
        if (in->encoding != UTF16 && in->encoding != UTF16LE)
196
 
            ReportEncodingWarning(in->doc, ENCODING_MISMATCH, UTF16LE);
 
210
            TY_(ReportEncodingWarning)(in->doc, ENCODING_MISMATCH, UTF16LE);
197
211
 
198
212
        return UTF16LE; /* return decoded BOM */
199
213
    }
213
227
        {
214
228
            /* UTF-8 */
215
229
            if (in->encoding != UTF8)
216
 
                ReportEncodingWarning(in->doc, ENCODING_MISMATCH, UTF8);
 
230
                TY_(ReportEncodingWarning)(in->doc, ENCODING_MISMATCH, UTF8);
217
231
 
218
232
            return UTF8;
219
233
        }
228
242
}
229
243
 
230
244
#ifdef TIDY_STORE_ORIGINAL_TEXT
231
 
void AddByteToOriginalText(StreamIn *in, tmbchar c)
 
245
void TY_(AddByteToOriginalText)(StreamIn *in, tmbchar c)
232
246
{
233
247
    if (in->otextlen + 1 >= in->otextsize)
234
248
    {
235
249
        size_t size = in->otextsize ? 1 : 2;
236
 
        in->otextbuf = MemRealloc(in->otextbuf, in->otextsize + size);
 
250
        in->otextbuf = TidyRealloc(in->allocator, in->otextbuf, in->otextsize + size);
237
251
        in->otextsize += size;
238
252
    }
239
253
    in->otextbuf[in->otextlen++] = c;
240
254
    in->otextbuf[in->otextlen  ] = 0;
241
255
}
242
256
 
243
 
void AddCharToOriginalText(StreamIn *in, tchar c)
 
257
void TY_(AddCharToOriginalText)(StreamIn *in, tchar c)
244
258
{
245
259
    int i, err, count = 0;
246
260
    tmbchar buf[10] = {0};
247
261
    
248
 
    err = EncodeCharToUTF8Bytes(c, buf, NULL, &count);
 
262
    err = TY_(EncodeCharToUTF8Bytes)(c, buf, NULL, &count);
249
263
 
250
264
    if (err)
251
265
    {
257
271
    }
258
272
    
259
273
    for (i = 0; i < count; ++i)
260
 
        AddByteToOriginalText(in, buf[i]);
 
274
        TY_(AddByteToOriginalText)(in, buf[i]);
261
275
}
262
276
#endif
263
277
 
264
 
 
265
 
uint ReadChar( StreamIn *in )
 
278
static void InitLastPos( StreamIn *in )
 
279
{
 
280
    in->curlastpos = 0;
 
281
    in->firstlastpos = 0;
 
282
}
 
283
 
 
284
static void PopLastPos( StreamIn *in )
 
285
{
 
286
    in->curlastpos = (in->curlastpos+1)%LASTPOS_SIZE;
 
287
    if ( in->curlastpos == in->firstlastpos )
 
288
        in->firstlastpos = (in->firstlastpos+1)%LASTPOS_SIZE;
 
289
}
 
290
 
 
291
static void SaveLastPos( StreamIn *in )
 
292
{
 
293
    PopLastPos( in );
 
294
    in->lastcols[in->curlastpos] = in->curcol;
 
295
}
 
296
 
 
297
static void RestoreLastPos( StreamIn *in )
 
298
{
 
299
    if ( in->firstlastpos == in->curlastpos )
 
300
        in->curcol = 0;
 
301
    else
 
302
    {
 
303
        in->curcol = in->lastcols[in->curlastpos];
 
304
        if ( in->curlastpos == 0 )
 
305
            in->curlastpos = LASTPOS_SIZE;
 
306
        in->curlastpos--;
 
307
    }
 
308
}
 
309
 
 
310
uint TY_(ReadChar)( StreamIn *in )
266
311
{
267
312
    uint c = EndOfStream;
268
313
    uint tabsize = cfg( in->doc, TidyTabSize );
273
318
    if ( in->pushed )
274
319
        return PopChar( in );
275
320
 
276
 
    in->lastcol = in->curcol;
 
321
    SaveLastPos( in );
277
322
 
278
323
    if ( in->tabs > 0 )
279
324
    {
293
338
        {
294
339
#ifdef TIDY_STORE_ORIGINAL_TEXT
295
340
            added = yes;
296
 
            AddCharToOriginalText(in, (tchar)c);
 
341
            TY_(AddCharToOriginalText)(in, (tchar)c);
297
342
#endif
298
343
            in->curcol = 1;
299
344
            in->curline++;
304
349
        {
305
350
#ifdef TIDY_STORE_ORIGINAL_TEXT
306
351
            added = yes;
307
 
            AddCharToOriginalText(in, (tchar)c);
 
352
            TY_(AddCharToOriginalText)(in, (tchar)c);
308
353
#endif
309
 
            in->tabs = tabsize - ((in->curcol - 1) % tabsize) - 1;
 
354
            in->tabs = tabsize > 0 ?
 
355
                tabsize - ((in->curcol - 1) % tabsize) - 1
 
356
                : 0;
310
357
            in->curcol++;
311
358
            c = ' ';
312
359
            break;
317
364
        {
318
365
#ifdef TIDY_STORE_ORIGINAL_TEXT
319
366
            added = yes;
320
 
            AddCharToOriginalText(in, (tchar)c);
 
367
            TY_(AddCharToOriginalText)(in, (tchar)c);
321
368
#endif
322
369
            c = ReadCharFromStream(in);
323
370
            if (c != '\n')
324
371
            {
325
 
                UngetChar( c, in );
 
372
                TY_(UngetChar)( c, in );
326
373
                c = '\n';
327
374
            }
328
375
            else
329
376
            {
330
377
#ifdef TIDY_STORE_ORIGINAL_TEXT
331
 
                AddCharToOriginalText(in, (tchar)c);
 
378
                TY_(AddCharToOriginalText)(in, (tchar)c);
332
379
#endif
333
380
            }
334
381
            in->curcol = 1;
375
422
             in->encoding == UTF16   ||
376
423
             in->encoding == UTF16BE )
377
424
        {
378
 
            if ( !IsValidUTF16FromUCS4(c) )
 
425
            if ( !TY_(IsValidUTF16FromUCS4)(c) )
379
426
            {
380
427
                /* invalid UTF-16 value */
381
 
                ReportEncodingError(in->doc, INVALID_UTF16, c, yes);
 
428
                TY_(ReportEncodingError)(in->doc, INVALID_UTF16, c, yes);
382
429
                c = 0;
383
430
            }
384
 
            else if ( IsLowSurrogate(c) )
 
431
            else if ( TY_(IsLowSurrogate)(c) )
385
432
            {
386
433
                uint n = c;
387
434
                uint m = ReadCharFromStream( in );
389
436
                   return EndOfStream;
390
437
 
391
438
                c = 0;
392
 
                if ( IsHighSurrogate(m) )
 
439
                if ( TY_(IsHighSurrogate)(m) )
393
440
                {
394
 
                    n = CombineSurrogatePair( m, n );
395
 
                    if ( IsValidCombinedChar(n) )
 
441
                    n = TY_(CombineSurrogatePair)( m, n );
 
442
                    if ( TY_(IsValidCombinedChar)(n) )
396
443
                        c = n;
397
444
                }
398
445
                /* not a valid pair */
399
446
                if ( 0 == c )
400
 
                    ReportEncodingError( in->doc, INVALID_UTF16, c, yes );
 
447
                    TY_(ReportEncodingError)( in->doc, INVALID_UTF16, c, yes );
401
448
            }
402
449
        }
403
450
#endif
406
453
        switch ( in->encoding )
407
454
        {
408
455
        case MACROMAN:
409
 
            c = DecodeMacRoman( c );
 
456
            c = TY_(DecodeMacRoman)( c );
410
457
            break;
411
458
        case IBM858:
412
459
            c = DecodeIbm850( c );
424
471
            Bool isVendorChar = ( in->encoding == WIN1252 ||
425
472
                                  in->encoding == MACROMAN );
426
473
            Bool isWinChar    = ( in->encoding == WIN1252 ||
427
 
                                  ReplacementCharEncoding == WIN1252 );
 
474
                                  TY_(ReplacementCharEncoding) == WIN1252 );
428
475
            Bool isMacChar    = ( in->encoding == MACROMAN ||
429
 
                                  ReplacementCharEncoding == MACROMAN );
 
476
                                  TY_(ReplacementCharEncoding) == MACROMAN );
430
477
            
431
478
            /* set error position just before offending character */
432
 
            in->doc->lexer->lines = in->curline;
433
 
            in->doc->lexer->columns = in->curcol;
 
479
            if (in->doc->lexer)
 
480
            {
 
481
                in->doc->lexer->lines = in->curline;
 
482
                in->doc->lexer->columns = in->curcol;
 
483
            }
434
484
                
435
485
            if ( isWinChar )
436
 
                c1 = DecodeWin1252( c );
 
486
                c1 = TY_(DecodeWin1252)( c );
437
487
            else if ( isMacChar )
438
 
                c1 = DecodeMacRoman( c );
 
488
                c1 = TY_(DecodeMacRoman)( c );
439
489
            if ( c1 )
440
490
                replMode = REPLACED_CHAR;
441
491
                
442
492
            if ( c1 == 0 && isVendorChar )
443
 
                ReportEncodingError(in->doc, VENDOR_SPECIFIC_CHARS, c, replMode == DISCARDED_CHAR);
 
493
                TY_(ReportEncodingError)(in->doc, VENDOR_SPECIFIC_CHARS, c, replMode == DISCARDED_CHAR);
444
494
            else if ( ! isVendorChar )
445
 
                ReportEncodingError(in->doc, INVALID_SGML_CHARS, c, replMode == DISCARDED_CHAR);
 
495
                TY_(ReportEncodingError)(in->doc, INVALID_SGML_CHARS, c, replMode == DISCARDED_CHAR);
446
496
                
447
497
            c = c1;
448
498
        }
456
506
 
457
507
#ifdef TIDY_STORE_ORIGINAL_TEXT
458
508
    if (!added)
459
 
        AddCharToOriginalText(in, (tchar)c);
 
509
        TY_(AddCharToOriginalText)(in, (tchar)c);
460
510
#endif
461
511
 
462
512
    return c;
463
513
}
464
514
 
465
 
uint PopChar( StreamIn *in )
 
515
static uint PopChar( StreamIn *in )
466
516
{
467
517
    uint c = EndOfStream;
468
518
    if ( in->pushed )
476
526
        {
477
527
            in->curcol = 1;
478
528
            in->curline++;
 
529
            PopLastPos( in );
479
530
            return c;
480
531
        }
481
532
        in->curcol++;
 
533
        PopLastPos( in );
482
534
    }
483
535
    return c;
484
536
}
485
537
 
486
 
void UngetChar( uint c, StreamIn *in )
 
538
void TY_(UngetChar)( uint c, StreamIn *in )
487
539
{
488
540
    if (c == EndOfStream)
489
541
    {
494
546
    in->pushed = yes;
495
547
 
496
548
    if (in->bufpos + 1 >= in->bufsize)
497
 
        in->charbuf = (tchar*)MemRealloc(in->charbuf, sizeof(tchar) * ++(in->bufsize));
 
549
        in->charbuf = (tchar*)TidyRealloc(in->allocator, in->charbuf, sizeof(tchar) * ++(in->bufsize));
498
550
 
499
551
    in->charbuf[(in->bufpos)++] = c;
500
552
 
501
553
    if (c == '\n')
502
554
        --(in->curline);
503
555
 
504
 
    in->curcol = in->lastcol;
 
556
    RestoreLastPos( in );
505
557
}
506
558
 
507
559
 
510
562
** Sink
511
563
************************/
512
564
 
513
 
static StreamOut* initStreamOut( int encoding, uint nl )
 
565
static StreamOut* initStreamOut( TidyDocImpl* doc, int encoding, uint nl )
514
566
{
515
 
    StreamOut* out = (StreamOut*) MemAlloc( sizeof(StreamOut) );
516
 
    ClearMemory( out, sizeof(StreamOut) );
 
567
    StreamOut* out = (StreamOut*) TidyDocAlloc( doc, sizeof(StreamOut) );
 
568
    TidyClearMemory( out, sizeof(StreamOut) );
517
569
    out->encoding = encoding;
518
570
    out->state = FSM_ASCII;
519
571
    out->nl = nl;
520
572
    return out;
521
573
}
522
574
 
523
 
StreamOut* FileOutput( FILE* fp, int encoding, uint nl )
 
575
StreamOut* TY_(FileOutput)( TidyDocImpl *doc, FILE* fp, int encoding, uint nl )
524
576
{
525
 
    StreamOut* out = initStreamOut( encoding, nl );
526
 
    initFileSink( &out->sink, fp );
 
577
    StreamOut* out = initStreamOut( doc, encoding, nl );
 
578
    TY_(initFileSink)( &out->sink, fp );
527
579
    out->iotype = FileIO;
528
580
    return out;
529
581
}
530
 
StreamOut* BufferOutput( TidyBuffer* buf, int encoding, uint nl )
 
582
StreamOut* TY_(BufferOutput)( TidyDocImpl *doc, TidyBuffer* buf, int encoding, uint nl )
531
583
{
532
 
    StreamOut* out = initStreamOut( encoding, nl );
533
 
    initOutputBuffer( &out->sink, buf );
 
584
    StreamOut* out = initStreamOut( doc, encoding, nl );
 
585
    tidyInitOutputBuffer( &out->sink, buf );
534
586
    out->iotype = BufferIO;
535
587
    return out;
536
588
}
537
 
StreamOut* UserOutput( TidyOutputSink* sink, int encoding, uint nl )
 
589
StreamOut* TY_(UserOutput)( TidyDocImpl *doc, TidyOutputSink* sink, int encoding, uint nl )
538
590
{
539
 
    StreamOut* out = initStreamOut( encoding, nl );
 
591
    StreamOut* out = initStreamOut( doc, encoding, nl );
540
592
    memcpy( &out->sink, sink, sizeof(TidyOutputSink) );
541
593
    out->iotype = UserIO;
542
594
    return out;
543
595
}
544
596
 
545
 
void WriteChar( uint c, StreamOut* out )
 
597
void TY_(WriteChar)( uint c, StreamOut* out )
546
598
{
547
599
    /* Translate outgoing newlines */
548
600
    if ( LF == c )
549
601
    {
550
602
      if ( out->nl == TidyCRLF )
551
 
          WriteChar( CR, out );
 
603
          TY_(WriteChar)( CR, out );
552
604
      else if ( out->nl == TidyCR )
553
605
          c = CR;
554
606
    }
574
626
    {
575
627
        int count = 0;
576
628
        
577
 
        EncodeCharToUTF8Bytes( c, NULL, &out->sink, &count );
 
629
        TY_(EncodeCharToUTF8Bytes)( c, NULL, &out->sink, &count );
578
630
        if (count <= 0)
579
631
        {
580
 
          /* ReportEncodingError(in->lexer, INVALID_UTF8 | REPLACED_CHAR, c); */
 
632
          /* TY_(ReportEncodingError)(in->lexer, INVALID_UTF8 | REPLACED_CHAR, c); */
581
633
            /* replacement char 0xFFFD encoded as UTF-8 */
582
634
            PutByte(0xEF, out); PutByte(0xBF, out); PutByte(0xBF, out);
583
635
        }
633
685
        int i, numChars = 1;
634
686
        uint theChars[2];
635
687
        
636
 
        if ( !IsValidUTF16FromUCS4(c) )
 
688
        if ( !TY_(IsValidUTF16FromUCS4)(c) )
637
689
        {
638
690
            /* invalid UTF-16 value */
639
 
            /* ReportEncodingError(in->lexer, INVALID_UTF16 | DISCARDED_CHAR, c); */
 
691
            /* TY_(ReportEncodingError)(in->lexer, INVALID_UTF16 | DISCARDED_CHAR, c); */
640
692
            c = 0;
641
693
            numChars = 0;
642
694
        }
643
 
        else if ( IsCombinedChar(c) )
 
695
        else if ( TY_(IsCombinedChar)(c) )
644
696
        {
645
697
            /* output both, unless something goes wrong */
646
698
            numChars = 2;
647
 
            if ( !SplitSurrogatePair(c, &theChars[0], &theChars[1]) )
 
699
            if ( !TY_(SplitSurrogatePair)(c, &theChars[0], &theChars[1]) )
648
700
            {
649
 
                /* ReportEncodingError(in->lexer, INVALID_UTF16 | DISCARDED_CHAR, c); */
 
701
                /* TY_(ReportEncodingError)(in->lexer, INVALID_UTF16 | DISCARDED_CHAR, c); */
650
702
                c = 0;
651
703
                numChars = 0;
652
704
            }
703
755
** regardless of specified encoding.  Set at compile time
704
756
** to either Windows or Mac.
705
757
*/
706
 
const int ReplacementCharEncoding = DFLT_REPL_CHARENC;
 
758
const int TY_(ReplacementCharEncoding) = DFLT_REPL_CHARENC;
707
759
 
708
760
 
709
761
/* Mapping for Windows Western character set CP 1252 
718
770
};
719
771
 
720
772
/* Function for conversion from Windows-1252 to Unicode */
721
 
uint DecodeWin1252(uint c)
 
773
uint TY_(DecodeWin1252)(uint c)
722
774
{
723
775
    if (127 < c && c < 160)
724
776
        c = Win2Unicode[c - 128];
782
834
};
783
835
 
784
836
/* Function to convert from MacRoman to Unicode */
785
 
uint DecodeMacRoman(uint c)
 
837
uint TY_(DecodeMacRoman)(uint c)
786
838
{
787
839
    if (127 < c)
788
840
        c = Mac2Unicode[c - 128];
832
884
};
833
885
 
834
886
/* Function for conversion from OS/2-850 to Unicode */
835
 
uint DecodeIbm850(uint c)
 
887
static uint DecodeIbm850(uint c)
836
888
{
837
889
    if (127 < c && c < 256)
838
890
        c = IBM2Unicode[c - 128];
861
913
 
862
914
 
863
915
/* Convert from Latin0 (aka Latin9, ISO-8859-15) to Unicode */
864
 
uint DecodeLatin0(uint c)
 
916
static uint DecodeLatin0(uint c)
865
917
{
866
918
    if (159 < c && c < 191)
867
919
    {
954
1006
    0x003F, 0x003F, 0x003F, 0x003F, 0x003F, 0x003F, 0x003F, 0x003F
955
1007
};
956
1008
 
 
1009
#if 0
957
1010
/* Function to convert from Symbol Font chars to Unicode */
958
1011
uint DecodeSymbolFont(uint c)
959
1012
{
964
1017
 
965
1018
    return Symbol2Unicode[c];
966
1019
}
 
1020
#endif
967
1021
 
968
1022
 
969
1023
/* Facilitates user defined source by providing
980
1034
 
981
1035
  if ( status )
982
1036
  {
983
 
    source->sourceData = (ulong) srcData;
 
1037
    source->sourceData = srcData;
984
1038
    source->getByte    = gbFunc;
985
1039
    source->ungetByte  = ugbFunc;
986
1040
    source->eof        = endFunc;
996
1050
  Bool status = ( sink && snkData && pbFunc );
997
1051
  if ( status )
998
1052
  {
999
 
    sink->sinkData = (ulong) snkData;
 
1053
    sink->sinkData = snkData;
1000
1054
    sink->putByte  = pbFunc;
1001
1055
  }
1002
1056
  return status;
1028
1082
{
1029
1083
    return tidyGetByte( &in->source );
1030
1084
}
1031
 
Bool IsEOF( StreamIn* in )
 
1085
Bool TY_(IsEOF)( StreamIn* in )
1032
1086
{
1033
1087
    return tidyIsEOF( &in->source );
1034
1088
}
1049
1103
    for (i = 0; i < *count; i++)
1050
1104
    {
1051
1105
        /* should never get here; testing for 0xFF, a valid char, is not a good idea */
1052
 
        if ( in && IsEOF(in) )
 
1106
        if ( in && TY_(IsEOF)(in) )
1053
1107
        {
1054
1108
            /* fprintf(stderr,"Attempt to unget EOF in UngetRawBytesToStream\n"); */
1055
1109
            *count = -i;
1097
1151
    uint bytesRead = 0;
1098
1152
#endif
1099
1153
 
1100
 
    if ( IsEOF(in) )
 
1154
    if ( TY_(IsEOF)(in) )
1101
1155
        return EndOfStream;
1102
1156
    
1103
1157
    c = ReadByte( in );
1195
1249
        int err, count = 0;
1196
1250
        
1197
1251
        /* first byte "c" is passed in separately */
1198
 
        err = DecodeUTF8BytesToChar( &n, c, NULL, &in->source, &count );
 
1252
        err = TY_(DecodeUTF8BytesToChar)( &n, c, NULL, &in->source, &count );
1199
1253
        if (!err && (n == (uint)EndOfStream) && (count == 1)) /* EOF */
1200
1254
            return EndOfStream;
1201
1255
        else if (err)
1204
1258
            in->doc->lexer->lines = in->curline;
1205
1259
            in->doc->lexer->columns = in->curcol;
1206
1260
 
1207
 
            ReportEncodingError(in->doc, INVALID_UTF8, n, no);
 
1261
            TY_(ReportEncodingError)(in->doc, INVALID_UTF8, n, no);
1208
1262
            n = 0xFFFD; /* replacement char */
1209
1263
        }
1210
1264
        
1246
1300
#ifdef TIDY_WIN32_MLANG_SUPPORT
1247
1301
    else if (in->encoding > WIN32MLANG)
1248
1302
    {
1249
 
        assert( in->mlang != 0 );
1250
 
        return Win32MLangGetChar((byte)c, in, &bytesRead);
 
1303
        assert( in->mlang != NULL );
 
1304
        return TY_(Win32MLangGetChar)((byte)c, in, &bytesRead);
1251
1305
    }
1252
1306
#endif
1253
1307
 
1258
1312
}
1259
1313
 
1260
1314
/* Output a Byte Order Mark if required */
1261
 
void outBOM( StreamOut *out )
 
1315
void TY_(outBOM)( StreamOut *out )
1262
1316
{
1263
1317
    if ( out->encoding == UTF8
1264
1318
#if SUPPORT_UTF16_ENCODINGS
1269
1323
       )
1270
1324
    {
1271
1325
        /* this will take care of encoding the BOM correctly */
1272
 
        WriteChar( UNICODE_BOM, out );
 
1326
        TY_(WriteChar)( UNICODE_BOM, out );
1273
1327
    }
1274
1328
}
1275
1329
 
1304
1358
  { RAW,      NULL,           "raw"     }
1305
1359
};
1306
1360
 
1307
 
ctmbstr GetEncodingNameFromTidyId(uint id)
 
1361
ctmbstr TY_(GetEncodingNameFromTidyId)(uint id)
1308
1362
{
1309
1363
    uint i;
1310
1364
 
1315
1369
    return NULL;
1316
1370
}
1317
1371
 
1318
 
ctmbstr GetEncodingOptNameFromTidyId(uint id)
 
1372
ctmbstr TY_(GetEncodingOptNameFromTidyId)(uint id)
1319
1373
{
1320
1374
    uint i;
1321
1375
 
1326
1380
    return NULL;
1327
1381
}
1328
1382
 
1329
 
int GetCharEncodingFromOptName( ctmbstr charenc )
 
1383
int TY_(GetCharEncodingFromOptName)( ctmbstr charenc )
1330
1384
{
1331
1385
    uint i;
1332
1386
 
1333
1387
    for (i = 0; i < sizeof(enc2iana)/sizeof(enc2iana[0]); ++i)
1334
 
        if (tmbstrcasecmp(charenc, enc2iana[i].tidyOptName) == 0 )
 
1388
        if (TY_(tmbstrcasecmp)(charenc, enc2iana[i].tidyOptName) == 0 )
1335
1389
            return enc2iana[i].id;
1336
1390
 
1337
1391
    return -1;
1338
1392
}
 
1393
 
 
1394
/*
 
1395
 * local variables:
 
1396
 * mode: c
 
1397
 * indent-tabs-mode: nil
 
1398
 * c-basic-offset: 4
 
1399
 * eval: (c-set-offset 'substatement-open 0)
 
1400
 * end:
 
1401
 */