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
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
|
/*************************************************************************
*
* $RCSfile: tagtest.cxx,v $
*
* $Revision: 1.9 $
*
* last change: $Author: rt $ $Date: 2004-12-10 17:17:17 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
*
* - GNU Lesser General Public License Version 2.1
* - Sun Industry Standards Source License Version 1.1
*
* Sun Microsystems Inc., October, 2000
*
* GNU Lesser General Public License Version 2.1
* =============================================
* Copyright 2000 by Sun Microsystems, Inc.
* 901 San Antonio Road, Palo Alto, CA 94303, USA
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
*
* Sun Industry Standards Source License Version 1.1
* =================================================
* The contents of this file are subject to the Sun Industry Standards
* Source License Version 1.1 (the "License"); You may not use this file
* except in compliance with the License. You may obtain a copy of the
* License at http://www.openoffice.org/license.html.
*
* Software provided under this License is provided on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
* See the License for the specific provisions governing your rights and
* obligations concerning the Software.
*
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
*
* Copyright: 2000 by Sun Microsystems, Inc.
*
* All Rights Reserved.
*
* Contributor(s): _______________________________________
*
*
************************************************************************/
#ifndef _STRING_HXX
#include <tools/string.hxx>
#endif
#include "tagtest.hxx"
#if OSL_DEBUG_LEVEL > 1
#include <stdio.h>
#endif
#define HAS_FLAG( nFlags, nFlag ) ( ( nFlags & nFlag ) != 0 )
#define SET_FLAG( nFlags, nFlag ) ( nFlags |= nFlag )
#define RESET_FLAG( nFlags, nFlag ) ( nFlags &= ~nFlag ) // ~ = Bitweises NOT
//ByteString SimpleParser::aLastUnknownToken;
struct Tag
{
char* aName;
TokenId nTag;
};
static Tag __READONLY_DATA aKnownTags[] =
{
// { "<#GROUP_FORMAT>", TAG_GROUP_FORMAT },
{ "<#BOLD>", TAG_BOLDON },
{ "<#/BOLD>", TAG_BOLDOFF },
{ "<#ITALIC>", TAG_ITALICON },
{ "<#/ITALIC>", TAG_ITALICOFF },
{ "<#UNDER>", TAG_UNDERLINEON },
{ "<#/UNDER>", TAG_UNDERLINEOFF },
// { "<#GROUP_NOTALLOWED>", TAG_GROUP_NOTALLOWED },
{ "<#HELPID>", TAG_HELPID },
{ "<#MODIFY>", TAG_MODIFY },
{ "<#REFNR>", TAG_REFNR },
// { "<#GROUP_STRUCTURE>", TAG_GROUP_STRUCTURE },
{ "<#NAME>", TAG_NAME },
{ "<#HREF>", TAG_HREF },
{ "<#AVIS>", TAG_AVIS },
{ "<#AHID>", TAG_AHID },
{ "<#AEND>", TAG_AEND },
{ "<#TITEL>", TAG_TITEL },
{ "<#KEY>", TAG_KEY },
{ "<#INDEX>", TAG_INDEX },
{ "<#REFSTART>", TAG_REFSTART },
{ "<#GRAPHIC>", TAG_GRAPHIC },
{ "<#NEXTVERSION>", TAG_NEXTVERSION },
// { "<#GROUP_SYSSWITCH>", TAG_GROUP_SYSSWITCH },
{ "<#WIN>", TAG_WIN },
{ "<#UNIX>", TAG_UNIX },
{ "<#MAC>", TAG_MAC },
{ "<#OS2>", TAG_OS2 },
// { "<#GROUP_PROGSWITCH>", TAG_GROUP_PROGSWITCH },
{ "<#WRITER>", TAG_WRITER },
{ "<#CALC>", TAG_CALC },
{ "<#DRAW>", TAG_DRAW },
{ "<#IMPRESS>", TAG_IMPRESS },
{ "<#SCHEDULE>", TAG_SCHEDULE },
{ "<#IMAGE>", TAG_IMAGE },
{ "<#MATH>", TAG_MATH },
{ "<#CHART>", TAG_CHART },
{ "<#OFFICE>", TAG_OFFICE },
// { "<#TAG_GROUP_META>", TAG_GROUP_META },
{ "$[officefullname]", TAG_OFFICEFULLNAME },
{ "$[officename]", TAG_OFFICENAME },
{ "$[officepath]", TAG_OFFICEPATH },
{ "$[officeversion]", TAG_OFFICEVERSION },
{ "$[portalname]", TAG_PORTALNAME },
{ "$[portalfullname]", TAG_PORTALFULLNAME },
{ "$[portalpath]", TAG_PORTALPATH },
{ "$[portalversion]", TAG_PORTALVERSION },
{ "$[portalshortname]", TAG_PORTALSHORTNAME },
// { "<#TAG_GROUP_SINGLE>", TAG_GROUP_SINGLE },
{ "<#REFINSERT>", TAG_REFINSERT },
// { "<#GROUP_MULTI>", TAG_GROUP_MULTI },
{ "<#END>", TAG_END },
{ "<#ELSE>", TAG_ELSE },
{ "<#VERSIONEND>", TAG_VERSIONEND },
{ "<#ENDGRAPHIC>", TAG_ENDGRAPHIC },
{ "<Common Tag>", TAG_COMMONSTART },
{ "</Common Tag>", TAG_COMMONEND },
{ "", TAG_UNKNOWN_TAG },
};
SimpleParser::SimpleParser()
: nPos( 0 )
, aNextTag( TAG_NOMORETAGS )
{
}
void SimpleParser::Parse( ByteString PaSource )
{
aSource = PaSource;
nPos = 0;
aLastToken = "";
aNextTag = TokenInfo( TAG_NOMORETAGS );
aTokenList.Clear();
};
TokenInfo SimpleParser::GetNextToken( ParserMessageList &rErrorList )
{
TokenInfo aResult;
if ( aNextTag.nId != TAG_NOMORETAGS )
{
aResult = aNextTag;
aNextTag = TokenInfo( TAG_NOMORETAGS );
}
else
{
aLastToken = GetNextTokenString( rErrorList );
if ( aLastToken == "" )
return TokenInfo( TAG_NOMORETAGS );
USHORT i = 0;
while ( aKnownTags[i].nTag != TAG_UNKNOWN_TAG &&
aLastToken != aKnownTags[i].aName )
i++;
aResult = TokenInfo( aKnownTags[i].nTag );
// do we have a \< ... \> style tag?
if ( aResult.nId == TAG_UNKNOWN_TAG && aLastToken.Copy(0,2).Equals( "\\<" ) )
{
// check for paired \" \"
bool bEven = true;
USHORT nPos = 0;
USHORT nQuotedQuotesPos = aLastToken.Search( "\\\"" );
USHORT nQuotedBackPos = aLastToken.Search( "\\\\" ); // this is only to kick out quoted backslashes
while ( nQuotedQuotesPos != STRING_NOTFOUND )
{
if ( nQuotedBackPos <= nQuotedQuotesPos )
nPos = nQuotedBackPos+2;
else
{
nPos = nQuotedQuotesPos+2;
bEven = !bEven;
}
nQuotedQuotesPos = aLastToken.Search( "\\\"", nPos );
nQuotedBackPos = aLastToken.Search( "\\\\", nPos ); // this is only to kick out quoted backslashes
}
if ( !bEven )
{
ByteString sTmp( "Missing quotes ( \\\" ) in Tag: " );
sTmp += aLastToken;
rErrorList.Insert( new ParserMessage( 24, sTmp ) );
}
// check if we have an end-tag or a start-tag
if ( aLastToken.GetChar(2) == '/' )
aResult = TokenInfo( TAG_COMMONEND, aLastToken );
else
{
aResult = TokenInfo( TAG_COMMONSTART, aLastToken );
if ( aLastToken.GetChar( aLastToken.Len() -3 ) == '/' )
aNextTag = TokenInfo( TAG_COMMONEND, aLastToken );
}
}
}
if ( aResult.nId == TAG_UNKNOWN_TAG )
aResult = TokenInfo( TAG_UNKNOWN_TAG, aLastToken );
aTokenList.Insert( aResult, LIST_APPEND );
return aResult;
}
ByteString SimpleParser::GetTokenText()
{
return aLastToken;
}
ByteString SimpleParser::GetNextTokenString( ParserMessageList &rErrorList )
{
USHORT nStyle1StartPos = aSource.Search( "<#", nPos );
USHORT nStyle2StartPos = aSource.Search( "$[", nPos );
USHORT nStyle3StartPos = aSource.Search( "\\<", nPos );
USHORT nStyle4StartPos = aSource.Search( "\\\\", nPos ); // this is only to kick out quoted backslashes
// check if the tag starts with a letter to avoid things like <> <= ... >
while ( STRING_NOTFOUND != nStyle3StartPos && !( aSource.Copy( nStyle3StartPos+2, 1 ).IsAlphaAscii() || aSource.GetChar( nStyle3StartPos+2 ) == '/' ) )
nStyle3StartPos = aSource.Search( "\\<", nStyle3StartPos+1 );
if ( STRING_NOTFOUND == nStyle1StartPos && STRING_NOTFOUND == nStyle2StartPos && STRING_NOTFOUND == nStyle3StartPos )
return ""; // no more tokens
if ( nStyle4StartPos < nStyle1StartPos && nStyle4StartPos < nStyle2StartPos && nStyle4StartPos <= nStyle3StartPos ) // <= to make sure \\ is always handled first
{ // Skip quoted Backslash
nPos = nStyle4StartPos +2;
return GetNextTokenString( rErrorList );
}
if ( nStyle1StartPos < nStyle2StartPos && nStyle1StartPos <= nStyle3StartPos ) // <= to make sure our spechial tags are recognized before all others
{ // test for <# ... > style tokens
USHORT nEndPos = aSource.Search( ">", nStyle1StartPos );
if ( nEndPos == STRING_NOTFOUND )
{ // Token is incomplete. Skip start and search for better ones
nPos = nStyle1StartPos +2;
return GetNextTokenString( rErrorList );
}
nPos = nEndPos;
return aSource.Copy( nStyle1StartPos, nEndPos-nStyle1StartPos +1 ).ToUpperAscii();
}
else if ( nStyle2StartPos < nStyle1StartPos && nStyle2StartPos < nStyle3StartPos )
{ // test for $[ ... ] style tokens
USHORT nEndPos = aSource.Search( "]", nStyle2StartPos);
if ( nEndPos == STRING_NOTFOUND )
{ // Token is incomplete. Skip start and search for better ones
nPos = nStyle2StartPos +2;
return GetNextTokenString( rErrorList );
}
nPos = nEndPos;
return aSource.Copy( nStyle2StartPos, nEndPos-nStyle2StartPos +1 );
}
else
{ // test for \< ... \> style tokens
USHORT nEndPos = aSource.Search( "\\>", nStyle3StartPos);
USHORT nQuotedBackPos = aSource.Search( "\\\\", nStyle3StartPos ); // this is only to kick out quoted backslashes
while ( nQuotedBackPos <= nEndPos && nQuotedBackPos != STRING_NOTFOUND )
{
nEndPos = aSource.Search( "\\>", nQuotedBackPos +2);
nQuotedBackPos = aSource.Search( "\\\\", nQuotedBackPos +2 ); // this is only to kick out quoted backslashes
}
if ( nEndPos == STRING_NOTFOUND )
{ // Token is incomplete. Skip start and search for better ones
nPos = nStyle3StartPos +2;
ByteString sTmp( "Tag Start '\\<' without Tag End '\\>': " );
sTmp += aSource.Copy( nStyle3StartPos-10, 20 );
rErrorList.Insert( new ParserMessage( 24, sTmp ) );
return GetNextTokenString( rErrorList );
}
// check for paired quoted " --> \"sometext\"
nPos = nEndPos;
return aSource.Copy( nStyle3StartPos, nEndPos-nStyle3StartPos +2 );
}
}
ByteString SimpleParser::GetLexem( TokenInfo const &aToken )
{
if ( aToken.aName.Len() )
return aToken.aName;
else
{
USHORT i = 0;
while ( aKnownTags[i].nTag != TAG_UNKNOWN_TAG &&
aKnownTags[i].nTag != aToken.nId )
i++;
return ByteString( aKnownTags[i].aName );
}
}
TokenParser::TokenParser()
{}
void TokenParser::Parse( const ByteString &aCode )
{
while ( aErrorList.Count() )
{
delete aErrorList.GetCurObject();
aErrorList.Remove();
}
//Scanner initialisieren
aParser.Parse( aCode );
//erstes Symbol holen
aTag = aParser.GetNextToken( aErrorList );
nPfCaseOptions = 0;
nAppCaseOptions = 0;
bPfCaseActive = FALSE;
bAppCaseActive = FALSE;
nActiveRefTypes = 0;
//Ausfhren der Start-Produktion
Paragraph();
//Es wurde nicht die ganze Kette abgearbeitet, bisher ist aber
//kein Fehler aufgetreten
//=> es wurde ein einleitendes Tag vergessen
if ( aTag.nId != TAG_NOMORETAGS )
{
switch ( aTag.nId )
{
case TAG_END:
{
ParseError( 3, "Extra Tag <#END>. Switch or <#HREF> expected." );
}
break;
case TAG_BOLDOFF:
{
ParseError( 4, "<#BOLD> expected before <#/BOLD>." );
}
break;
case TAG_ITALICOFF:
{
ParseError( 5, "<#ITALIC> expected before <#/ITALIC>." );
}
break;
case TAG_UNDERLINEOFF:
{
ParseError( 17, "<#UNDER> expected before <#/UNDER>." );
}
break;
/* case TAG_MISSPARENTHESIS:
{
ParseError( 14, "missing closing parenthesis '>'" );
}
break;*/
case TAG_AEND:
{
ParseError( 5, "Extra Tag <#AEND>. <#AVIS> or <#AHID> expected." );
}
break;
case TAG_ELSE:
{
ParseError( 16, "Application-tag or platform-tag expected before <#ELSE>." );
}
break;
case TAG_UNKNOWN_TAG:
{
ByteString sTmp( "unknown Tag: " );
sTmp += aParser.GetLexem( aTag );
ParseError( 6, sTmp );
}
break;
default:
{
ByteString sTmp( "unexpected Tag: " );
sTmp += aParser.GetLexem( aTag );
ParseError( 6, sTmp );
}
}
}
}
void TokenParser::Paragraph()
{
switch ( aTag.nId )
{
case TAG_GRAPHIC:
case TAG_NEXTVERSION:
{
TagRef();
Paragraph();
}
break;
case TAG_AVIS:
case TAG_AHID:
{
TagRef();
Paragraph();
}
break;
case TAG_HELPID:
{
SimpleTag();
Paragraph();
}
break;
case TAG_OFFICEFULLNAME:
case TAG_OFFICENAME:
case TAG_OFFICEPATH:
case TAG_OFFICEVERSION:
case TAG_PORTALNAME:
case TAG_PORTALFULLNAME:
case TAG_PORTALPATH:
case TAG_PORTALVERSION:
case TAG_PORTALSHORTNAME:
{
SimpleTag();
Paragraph();
}
break;
case TAG_REFINSERT:
{
SimpleTag();
Paragraph();
}
break;
case TAG_BOLDON:
case TAG_ITALICON:
case TAG_UNDERLINEON:
case TAG_COMMONSTART:
{
TagPair();
Paragraph();
}
break;
case TAG_HREF:
case TAG_NAME:
case TAG_KEY:
case TAG_INDEX:
case TAG_TITEL:
case TAG_REFSTART:
{
TagRef();
Paragraph();
}
break;
case TAG_OS2:
case TAG_WIN:
case TAG_UNIX:
case TAG_MAC: //...
{
if ( ! bPfCaseActive )
{
//PfCases drfen nicht verschachtelt sein:
bPfCaseActive = TRUE;
PfCase();
//So jetzt kann wieder ein PfCase kommen:
bPfCaseActive = FALSE;
Paragraph();
}
}
break;
case TAG_WRITER:
case TAG_CALC:
case TAG_DRAW:
case TAG_IMPRESS:
case TAG_SCHEDULE:
case TAG_IMAGE:
case TAG_MATH:
case TAG_CHART:
case TAG_OFFICE:
{
if ( !bAppCaseActive )
{
//AppCases drfen nicht verschachtelt sein:
bAppCaseActive = TRUE;
AppCase();
//jetzt knnen wieder AppCases kommen:
bAppCaseActive = FALSE;
Paragraph();
}
}
break;
//Case TAG_BOLDOFF, TAG_ITALICOFF, TAG_BUNDERLINE, TAG_END
//nichts tun wg. epsilon-Prod.
}
}
void TokenParser::PfCase()
{
//Produktion:
//PfCase -> PfCaseBegin Paragraph (PfCase | PfCaseEnd)
PfCaseBegin();
//Jetzt ist eine PfCase-Produktion aktiv:
Paragraph();
switch ( aTag.nId )
{
case TAG_ELSE:
case TAG_END:
{
CaseEnd();
}
break;
case TAG_OS2:
case TAG_WIN:
case TAG_UNIX:
case TAG_MAC: //First (PfBegin)
{
PfCase();
}
break;
default:
ParseError( 8, "<#ELSE> or <#END> or platform-tag expected." );
}
//Die gemerkten Tags wieder lschen fr nchstes PfCase:
nPfCaseOptions = 0;
}
void TokenParser::PfCaseBegin()
{
switch ( aTag.nId )
{
case TAG_OS2:
case TAG_WIN:
case TAG_UNIX:
case TAG_MAC:
{
//Token darf noch nicht vorgekommen sein im
//aktuellen Plattform-Case:
if ( !HAS_FLAG( nPfCaseOptions, TAG_NOGROUP( aTag.nId ) ) )
{
SET_FLAG( nPfCaseOptions, TAG_NOGROUP( aTag.nId ) );
match( aTag, aTag );
}
else {
ByteString sTmp( aParser.GetLexem( aTag ));
sTmp += " defined twice in the same platform-case.";
ParseError( 9, sTmp );
}
}
}
}
void TokenParser::AppCase()
{
//Produktion:
//AppCase -> AppCaseBegin Paragraph (AppCase | AppCaseEnd)
AppCaseBegin();
Paragraph();
switch ( aTag.nId )
{
case TAG_ELSE:
case TAG_END:
{
CaseEnd();
}
break;
case TAG_WRITER:
case TAG_DRAW:
case TAG_CALC:
case TAG_IMAGE:
case TAG_MATH:
case TAG_CHART:
case TAG_OFFICE:
case TAG_IMPRESS:
case TAG_SCHEDULE: //First (AppBegin)
{
AppCase();
}
break;
default:
ParseError( 1, "<#ELSE> or <#END> or application-case-tag expected." );
}
//Die gemerkten Tags wieder lschen fr nchstes AppCase:
nAppCaseOptions = 0;
}
void TokenParser::AppCaseBegin()
{
switch ( aTag.nId )
{
case TAG_WRITER:
case TAG_DRAW:
case TAG_CALC:
case TAG_IMAGE:
case TAG_MATH:
case TAG_CHART:
case TAG_OFFICE:
case TAG_IMPRESS:
case TAG_SCHEDULE:
{
//Token darf noch nicht vorgekommen sein im
//aktuellen Plattform-Case:
if ( !HAS_FLAG( nAppCaseOptions, TAG_NOGROUP( aTag.nId ) ) )
{
SET_FLAG( nAppCaseOptions, TAG_NOGROUP( aTag.nId ) );
match( aTag, aTag );
}
else {
ByteString sTmp( aParser.GetLexem( aTag ));
sTmp += " defined twice in the same application-case.";
ParseError( 13, sTmp );
}
}
}
}
void TokenParser::CaseEnd()
{
//Produktion:
//CaseEnd -> <#ELSE> Paragraph <#END> | <#END>
switch ( aTag.nId )
{
case TAG_ELSE:
{
match( aTag, TAG_ELSE );
Paragraph();
match( aTag, TAG_END );
}
break;
case TAG_END:
{
match( aTag, TAG_END );
}
break;
default:
ParseError( 2, "<#ELSE> or <#END> expected." );
}
}
void TokenParser::SimpleTag()
{
switch ( aTag.nId )
{
case TAG_HELPID:
{
match( aTag, TAG_HELPID );
}
break;
case TAG_OFFICEFULLNAME:
case TAG_OFFICENAME:
case TAG_OFFICEPATH:
case TAG_OFFICEVERSION:
case TAG_PORTALNAME:
case TAG_PORTALFULLNAME:
case TAG_PORTALPATH:
case TAG_PORTALVERSION:
case TAG_PORTALSHORTNAME:
case TAG_REFINSERT:
{
match( aTag, aTag );
}
break;
default:
ParseError( 15, "[<#SimpleTag>] expected." );
}
}
void TokenParser::TagPair()
{
switch ( aTag.nId )
{
case TAG_BOLDON:
{
match( aTag, TAG_BOLDON );
Paragraph();
match( aTag, TAG_BOLDOFF );
}
break;
case TAG_ITALICON:
{
match( aTag, TAG_ITALICON );
Paragraph();
match( aTag, TAG_ITALICOFF );
}
break;
case TAG_UNDERLINEON:
{
match( aTag, TAG_UNDERLINEON );
Paragraph();
match( aTag, TAG_UNDERLINEOFF );
}
break;
case TAG_COMMONSTART:
{
//remember tag so we can give the original tag in case of an error
TokenInfo aEndTag( TAG_COMMONEND, ByteString( "Close tag for " ).Append(aTag.aName) );
match( aTag, TAG_COMMONSTART );
Paragraph();
match( aTag, aEndTag );
}
break;
default:
ParseError( 10, "<#BOLD>, <#ITALIC>, <#UNDER> expected." );
}
}
void TokenParser::TagRef()
{
switch ( aTag.nId )
{
case TAG_GRAPHIC:
case TAG_NEXTVERSION:
{
if ( !HAS_FLAG( nActiveRefTypes, TAG_NOGROUP( aTag.nId ) ) )
{
TokenId aThisToken = aTag.nId;
SET_FLAG( nActiveRefTypes, TAG_NOGROUP( aThisToken ) );
match( aTag, aTag );
Paragraph();
if ( aThisToken == TAG_GRAPHIC )
match( aTag, TAG_ENDGRAPHIC );
else
match( aTag, TAG_VERSIONEND );
// don't reset since alowed only once per paragraph
// RESET_FLAG( nActiveRefTypes, TAG_NOGROUP( aThisToken ) );
}
else
{
ParseError( 11, "Tags <#GRAPHIC>,<#NEXTVERSION> allowed only once per paragraph." );
}
}
break;
case TAG_AVIS:
case TAG_AHID:
{
if ( !HAS_FLAG( nActiveRefTypes, TAG_NOGROUP( aTag.nId ) ) )
{
TokenId aThisToken = aTag.nId;
SET_FLAG( nActiveRefTypes, TAG_NOGROUP( aThisToken ) );
match( aTag, aTag );
Paragraph();
match( aTag, TAG_AEND );
RESET_FLAG( nActiveRefTypes, TAG_NOGROUP( aThisToken ) );
}
else
{
ParseError( 11, "Nested <#AHID>,<#AVIS> not allowed." );
}
}
break;
case TAG_HREF:
case TAG_NAME:
{
}
// NOBREAK
case TAG_KEY:
case TAG_INDEX:
case TAG_TITEL:
case TAG_REFSTART:
{
if ( !HAS_FLAG( nActiveRefTypes, TAG_NOGROUP( aTag.nId ) ) )
{
TokenId aThisToken = aTag.nId;
match( aTag, aTag );
if ( aThisToken != TAG_NAME )
{ // TAG_NAME has no TAG_END
SET_FLAG( nActiveRefTypes, TAG_NOGROUP( aThisToken ) );
Paragraph();
match( aTag, TAG_END );
RESET_FLAG( nActiveRefTypes, TAG_NOGROUP( aThisToken ) );
}
}
else
{
ParseError( 11, "Nested <#HREF>,<#NAME> or <#KEY> not allowed." );
}
}
break;
default:
ParseError( 12, "<#HREF>,<#NAME> or <#KEY> expected." );
}
}
BOOL TokenParser::match( const TokenInfo &aCurrentToken, const TokenId &aExpectedToken )
{
return match( aCurrentToken, TokenInfo( aExpectedToken ) );
}
BOOL TokenParser::match( const TokenInfo &aCurrentToken, const TokenInfo &aExpectedToken )
{
if ( aCurrentToken.nId == aExpectedToken.nId )
{
aTag = aParser.GetNextToken( aErrorList );
return TRUE;
}
else
{
ByteString sTmp( "Expected Symbol: " );
sTmp += aParser.GetLexem( aExpectedToken );
sTmp += ".";
ParseError( 7, sTmp );
return FALSE;
}
}
void TokenParser::ParseError( USHORT nErrNr, const ByteString &aErrMsg )
{
USHORT nTokenLength = aParser.GetTokenText().Len() + 2;
aErrorList.Insert( new ParserMessage( nErrNr, aErrMsg, aParser.GetScanningPosition()-nTokenLength, nTokenLength), LIST_APPEND );
// Das Fehlerhafte Tag berspringen
aTag = aParser.GetNextToken( aErrorList );
}
void LingTest::CheckMandatoryTag( TokenList aReference, TokenList aTestee, ParserMessageList &rErrorList, TokenInfo aToken )
{
while ( (aReference.GetPos( aToken ) != LIST_ENTRY_NOTFOUND) && (aTestee.GetPos( aToken ) != LIST_ENTRY_NOTFOUND) )
{
aReference.Remove( aToken );
aTestee.Remove( aToken );
}
if ( aReference.GetPos( aToken ) != LIST_ENTRY_NOTFOUND )
{
ByteString sTmp( "Missing Tag in Translation: " );
sTmp += SimpleParser::GetLexem( aToken );
rErrorList.Insert( new ParserMessage( 18, sTmp ) );
aReference.Remove( aToken );
}
if ( aTestee.GetPos( aToken ) != LIST_ENTRY_NOTFOUND )
{
ByteString sTmp( "Extra Tag in Translation: " );
sTmp += SimpleParser::GetLexem( aToken );
rErrorList.Insert( new ParserMessage( 19, sTmp ));
aTestee.Remove( aToken );
}
}
ByteString GetTagName( ByteString const &aTag )
{
ByteString aRet( aTag.Copy(2) ); // cut off \<
aRet.EraseLeadingChars( ' ' );
USHORT nPos;
if ( ( nPos = aRet.Search(' ') ) != STRING_NOTFOUND )
return aRet.Copy( 0, nPos );
aRet.Erase( aRet.Len() -2 );
if ( aRet.GetChar( aRet.Len()-1 ) == '/' )
aRet.Erase( aRet.Len() -1 );
else if ( aRet.GetChar( 0 ) == '/' )
aRet.Erase( 0, 1 );
return aRet;
}
BOOL LingTest::IsTagMandatory( TokenInfo const &aToken, TokenId &aMetaTokens )
{
TokenId aTokenId = aToken.nId;
TokenId aTokenGroup = TAG_GROUP( aTokenId );
if ( TAG_GROUP_PROGSWITCH == aTokenGroup
|| TAG_REFINSERT == aTokenId
|| TAG_REFSTART == aTokenId
|| TAG_NAME == aTokenId
|| TAG_HREF == aTokenId
|| TAG_AVIS == aTokenId
|| TAG_AHID == aTokenId
|| TAG_GRAPHIC == aTokenId
|| TAG_NEXTVERSION == aTokenId
|| ( TAG_GROUP_META == aTokenGroup && (aMetaTokens & aTokenId) == aTokenId ) )
{
if ( TAG_GROUP_META == aTokenGroup )
aMetaTokens |= aTokenId;
return TRUE;
}
else if ( TAG_COMMONSTART == aTokenId
|| TAG_COMMONEND == aTokenId )
{
ByteString aTagName = GetTagName( aToken.aName );
return !(aTagName.EqualsIgnoreCaseAscii( "comment" )
|| aTagName.EqualsIgnoreCaseAscii( "bookmark_value" )
|| aTagName.EqualsIgnoreCaseAscii( "emph" )
|| aTagName.EqualsIgnoreCaseAscii( "item" )
|| aTagName.EqualsIgnoreCaseAscii( "br" ) );
}
return FALSE;
}
void LingTest::CheckTags( TokenList aReference, TokenList aTestee, ParserMessageList &rErrorList )
{
ULONG i=0,j=0;
// Clean old Warnings
while ( aCompareWarningList.Count() )
{
delete aCompareWarningList.GetCurObject();
aCompareWarningList.Remove();
}
/* in xml tags, do not require the following tags
comment
bookmark_value
emph
item
br
*/
// filter uninteresting Tags
TokenId aMetaTokens = 0;
i=0;
while ( i < aReference.Count() )
{
if ( IsTagMandatory( aReference.GetObject( i ), aMetaTokens ) )
{
i++;
}
else
aReference.Remove( i );
}
aMetaTokens = 0;
i=0;
while ( i < aTestee.Count() )
{
if ( IsTagMandatory( aTestee.GetObject( i ), aMetaTokens ) )
{
i++;
}
else
aTestee.Remove( i );
}
// remove all found tags
i = 0;
while ( i < aReference.Count() )
{
BOOL bTagFound = FALSE;
j = 0;
while ( j < aTestee.Count() && !bTagFound )
{
if ( aReference.GetObject( i ).nId == aTestee.GetObject( j ).nId )
bTagFound = TRUE;
else
j++;
}
if ( bTagFound )
{
aReference.Remove( i );
aTestee.Remove( j );
}
else
i++;
}
// list remaining tags as errors
ParserMessage *pNewWarning = NULL;
i = 0;
while ( i < aReference.Count() )
{
ByteString sTmp( "Missing Tag in Translation: " );
sTmp += SimpleParser::GetLexem( aReference.GetObject( i ));
pNewWarning = new ParserMessage( 20, sTmp );
aCompareWarningList.Insert( pNewWarning, LIST_APPEND );
i++;
}
i = 0;
while ( i < aTestee.Count() )
{
ByteString sTmp( "Extra Tag in Translation: " );
sTmp += SimpleParser::GetLexem( aTestee.GetObject( i ));
pNewWarning = new ParserMessage( 21, sTmp );
aCompareWarningList.Insert( pNewWarning, LIST_APPEND );
i++;
}
// This message is obselete now
// pNewWarning = new ParserMessage( 22, "Tags Differ. Too many differences to be specified" );
}
BOOL LingTest::ReferenceOK( const ByteString &aReference )
{
aReferenceParser.Parse( aReference );
return !aReferenceParser.HasErrors();
}
BOOL LingTest::TesteeOK( const ByteString &aTestee, BOOL bHasSourceLine )
{
aTesteeParser.Parse( aTestee );
if ( bHasSourceLine )
CheckTags( aReferenceParser.GetTokenList(), aTesteeParser.GetTokenList(), aTesteeParser.GetErrors() );
return !aTesteeParser.HasErrors() && !HasCompareWarnings();
}
|