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
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
|
/*************************************************************************
*
* $RCSfile: localize.cxx,v $
*
* $Revision: 1.38 $
*
* last change: $Author: obo $ $Date: 2005-04-27 09:35:15 $
*
* 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): _______________________________________
*
*
************************************************************************/
#include "srciter.hxx"
#include "export.hxx"
#include <bootstrp/appdef.hxx>
#include <bootstrp/command.hxx>
#include <stdio.h>
#include "tools/errcode.hxx"
#include "tools/fsys.hxx"
// #define EHAM02_TEST
//
// SourceTreeLocalizer
//
const char *ExeTable[][5] = {
{ "src", "transex3", " -UTF8 -e", "negative", "noiso" },
{ "hrc", "transex3", " -UTF8 -e", "positive", "noiso" },
//{ "src", "transex3", "-UTF8 -e", "negative", "noiso" },
//{ "hrc", "transex3", "-UTF8 -e", "positive", "noiso" },
//{ "lng", "lngex", "-UTF8 -e", "negative", "noiso" },
{ "ulf", "ulfex", " -e", "negative", "noiso" },
{ "xrb", "xmlex", "-UTF8 -e", "negative", "iso" },
{ "xxl", "xmlex", "-UTF8 -e", "negative", "iso" },
{ "xgf", "xmlex", "-UTF8 -e -t:xgf", "negative", "iso" },
{ "xcd", "cfgex", "-UTF8 -e", "negative", "iso" },
{ "xcu", "cfgex", "-UTF8 -e", "negative", "iso" },
{ "xcs", "cfgex", "-UTF8 -e -f", "negative", "iso" },
{ "xrm", "xrmex", "-UTF8 -e", "negative", "iso" },
{ "xhp", "helpex", " -e", "negative", "noiso" },
{ "NULL", "NULL", "NULL", "NULL", "NULL" }
};
const char *NegativeList[] = {
"officecfg/data/org.openoffice.Office.Labels.xcd",
"officecfg/data/org/openoffice/Office/Labels.xcd",
"officecfg/data/org/openoffice/Office/SFX.xcd",
// "officecfg/registry/data/org/openoffice/Office/Labels.xcu",
// "officecfg/registry/data/org/openoffice/Office/SFX.xcu",
"hidother.src",
"NULL"
};
const char *PositiveList[] = {
"svx/inc/globlmn_tmpl.hrc",
"sw/source/ui/inc/swmn_tmpl.hrc",
"sw/source/ui/inc/swacc_tmpl.hrc",
"sw/source/ui/inc/toolbox_tmpl.hrc",
"offmgr/inc/offmenu_tmpl.hrc",
"offmgr/source/offapp/intro/intro_tmpl.hrc",
"dbaccess/source/ui/inc/toolbox_tmpl.hrc",
"svx/source/intro/intro_tmpl.hrc",
"dbaccess/source/ui/dlg/AutoControls_tmpl.hrc",
"svx/source/unodialogs/textconversiondlgs/chinese_direction_tmpl.hrc",
"chart2/source/controller/dialogs/res_DataLabel_tmplhrc",
"chart2/source/controller/dialogs/res_LegendPosition_tmpl.hrc",
"chart2/source/controller/dialogs/res_Statistic_tmpl.hrc",
"chart2/source/controller/menu/MenuItems_tmpl.hrc",
"NULL"
};
const char PRJ_DIR_NAME[] = "prj";
const char DLIST_NAME[] = "d.lst";
#define LOCALIZE_NONE 0x0000
#define LOCALIZE_EXTRACT 0x0001
#define LOCALIZE_MERGE 0x0002
class SourceTreeLocalizer : public SourceTreeIterator
{
private:
SvFileStream aSDF;
USHORT nMode;
ByteString sLanguageRestriction;
ByteString sIsoCode99;
ByteString sOutputFile;
int nFileCnt;
const ByteString GetProjectName( BOOL bAbs = FALSE );
const ByteString GetProjectRootRel();
bool bQuiet2;
BOOL CheckNegativeList( const ByteString &rFileName );
BOOL CheckPositiveList( const ByteString &rFileName );
void WorkOnFile(
const ByteString &rFileName,
const ByteString &rExecutable,
const ByteString &rParameter,
const ByteString &rIso
);
void WorkOnFileType(
const ByteString &rDirectory,
const ByteString &rExtension,
const ByteString &rExecutable,
const ByteString &rParameter,
const ByteString &rCollectMode,
const ByteString &rIso
);
void WorkOnDirectory( const ByteString &rDirectory );
BOOL ExecuteMerge();
BOOL MergeSingleFile(
const ByteString &rPrj,
const ByteString &rFile,
const ByteString &rSDFFile
);
public:
SourceTreeLocalizer( const ByteString &rRoot, const ByteString &rVersion , bool bLocal , bool bQuiet2_in );
~SourceTreeLocalizer();
ByteString getSourceLanguages( ByteString sLanguageRestriction , ByteString sCommand , ByteString rParameter );
void SetLanguageRestriction( const ByteString& rRestrictions )
{ sLanguageRestriction = rRestrictions; }
void SetIsoCode99( const ByteString& rIsoCode )
{ sIsoCode99 = rIsoCode; }
int getFileCnt();
BOOL Extract( const ByteString &rDestinationFile );
BOOL Merge( const ByteString &rSourceFile , const ByteString &rOutput );
int GetFileCnt();
virtual void OnExecuteDirectory( const ByteString &rDirectory );
};
/*****************************************************************************/
SourceTreeLocalizer::SourceTreeLocalizer(
const ByteString &rRoot, const ByteString &rVersion, bool bLocal , bool bQuiet2_in )
/*****************************************************************************/
: SourceTreeIterator( rRoot, rVersion , bLocal ),
nMode( LOCALIZE_NONE ),
bQuiet2( bQuiet2_in ),
nFileCnt( 0 )
{
}
/*****************************************************************************/
SourceTreeLocalizer::~SourceTreeLocalizer()
/*****************************************************************************/
{
}
/*****************************************************************************/
const ByteString SourceTreeLocalizer::GetProjectName( BOOL bAbs )
/*****************************************************************************/
{
BOOL bFound = FALSE;
DirEntry aCur;
aCur.ToAbs();
for ( ; ! bFound && aCur.Level() > 1; aCur.CutName() )
{
DirEntry aTest = aCur + DirEntry(PRJ_DIR_NAME) + DirEntry(DLIST_NAME);
if ( aTest.Exists() )
{
// HACK !!!!!!!!!!!!!!!!!!!!!!!!!!!!!
if (( ByteString( aCur.GetName(), RTL_TEXTENCODING_ASCII_US ).Equals("webinstall") ) ||
( ByteString( aCur.GetName(), RTL_TEXTENCODING_ASCII_US ).Equals("portal") ) ||
( ByteString( aCur.GetName(), RTL_TEXTENCODING_ASCII_US ).Equals("xulclient") ) ||
( ByteString( aCur.GetName(), RTL_TEXTENCODING_ASCII_US ).Search( "wdk_" ) == 0 ))
return "";
// end HACK !!!!!!!!!!!!!!!!!!!!!!!!!
if ( bAbs )
return ByteString( aCur.GetFull(), RTL_TEXTENCODING_ASCII_US );
else
return ByteString( aCur.GetName(), RTL_TEXTENCODING_ASCII_US );
}
}
return "";
}
/*****************************************************************************/
int SourceTreeLocalizer::GetFileCnt(){
/*****************************************************************************/
return nFileCnt;
}
/*****************************************************************************/
const ByteString SourceTreeLocalizer::GetProjectRootRel()
/*****************************************************************************/
{
ByteString sProjectRoot( GetProjectName( TRUE ));
DirEntry aCur;
aCur.ToAbs();
ByteString sCur( aCur.GetFull(), RTL_TEXTENCODING_ASCII_US );
if( sCur.SearchAndReplace( sProjectRoot, "" ) == STRING_NOTFOUND )
return "";
ByteString sDelimiter(
DirEntry::GetAccessDelimiter(), RTL_TEXTENCODING_ASCII_US );
sCur.SearchAndReplaceAll( sDelimiter, "/" );
sCur.EraseLeadingChars( '/' );
ULONG nCount = sCur.GetTokenCount( '/' );
ByteString sProjectRootRel;
for ( ULONG i = 0; i < nCount; i++ ) {
if ( sProjectRootRel.Len())
sProjectRootRel += sDelimiter;
sProjectRootRel += "..";
}
if ( sProjectRootRel.Len())
return sProjectRootRel;
return ".";
}
/*****************************************************************************/
void SourceTreeLocalizer::WorkOnFile(
const ByteString &rFileName, const ByteString &rExecutable,
const ByteString &rParameter, const ByteString &rIso )
/*****************************************************************************/
{
String sFull( rFileName, RTL_TEXTENCODING_ASCII_US );
DirEntry aEntry( sFull );
ByteString sFileName( aEntry.GetName(), RTL_TEXTENCODING_ASCII_US );
// set current working directory
DirEntry aPath( aEntry.GetPath());
DirEntry aOldCWD;
aPath.SetCWD();
ByteString sPrj( GetProjectName());
//printf ("prj = %s , exe = %s\n", sPrj.GetBuffer() , rExecutable.GetBuffer() );
if ( sPrj.Len()
// && !( rExecutable.EqualsIgnoreCaseAscii( "helpex" ) && !sPrj.EqualsIgnoreCaseAscii( "help2" ) ) // You don't see that!
) {
ByteString sRoot( GetProjectRootRel());
// get temp file
DirEntry aTemp( Export::GetTempFile());
ByteString sTempFile( aTemp.GetFull(), RTL_TEXTENCODING_ASCII_US );
ByteString sExecutable( rExecutable );
#ifdef WNT
sExecutable += ".exe";
String sPath( GetEnv( "PATH" ), RTL_TEXTENCODING_ASCII_US );
#else
String sPath( GetEnv( "LD_LIBRARY_PATH" ), RTL_TEXTENCODING_ASCII_US );
#endif
DirEntry aExecutable( String( sExecutable, RTL_TEXTENCODING_ASCII_US ));
aExecutable.Find( sPath );
ByteString sCommand( aExecutable.GetFull(), RTL_TEXTENCODING_ASCII_US );
sCommand += " ";
sCommand += rParameter;
sCommand += " -p ";
sCommand += sPrj;
sCommand += " -r ";
sCommand += sRoot;
sCommand += " -i ";
sCommand += sFileName;
sCommand += " -o ";
sCommand += sTempFile;
if ( sLanguageRestriction.Len()) {
sCommand += " -l ";
sCommand += getSourceLanguages( sLanguageRestriction , sCommand , rParameter );
//sCommand += sLanguageRestriction;
}
if ( rIso.Equals("iso") && sIsoCode99.Len()) {
sCommand += " -ISO99 ";
sCommand += sIsoCode99;
}
if( bQuiet2 ){
sCommand +=" -QQ ";
}
//printf("DBG: %s\n",sCommand.GetBuffer());
system( sCommand.GetBuffer());
nFileCnt++;
printf(".");
fflush( stdout );
SvFileStream aSDFIn( aTemp.GetFull(), STREAM_READ );
ByteString sLine;
while ( aSDFIn.IsOpen() && !aSDFIn.IsEof()) {
aSDFIn.ReadLine( sLine );
if ( sLine.Len()) {
#ifdef EHAM02_TEST
if ( sLine.GetToken( 9, '\t' ) == "99" ) {
ByteString sTmp;
for ( USHORT i = 0; i < sLine.GetTokenCount( '\t' ); i++ ) {
if ( i == 10 )
sTmp += "X_";
sTmp += sLine.GetToken( i, '\t' );
sTmp += "\t";
}
sTmp.EraseTrailingChars( '\t' );
sLine = sTmp;
}
#endif
aSDF.WriteLine( sLine );
}
}
aSDFIn.Close();
aTemp.Kill();
}
// reset current working directory
aOldCWD.SetCWD();
}
ByteString SourceTreeLocalizer::getSourceLanguages( ByteString sLanguageRestriction , ByteString sCommand , ByteString sParameter )
{
// Source languages in helpcontent2 and macromigration en-US only!
if( sCommand.Search("helpex") != STRING_NOTFOUND ) {
sLanguageRestriction.Assign( ByteString("en-US") );
}
else if( sCommand.Search("xmlex") != STRING_NOTFOUND ){
sLanguageRestriction.Assign( ByteString("en-US") );
}
return sLanguageRestriction;
}
/*****************************************************************************/
BOOL SourceTreeLocalizer::CheckNegativeList( const ByteString &rFileName )
/*****************************************************************************/
{
ULONG nIndex = 0;
BOOL bReturn = TRUE;
ByteString sDelimiter(
DirEntry::GetAccessDelimiter(), RTL_TEXTENCODING_ASCII_US );
ByteString sFileName( rFileName );
sFileName.ToLowerAscii();
ByteString sNegative( NegativeList[ nIndex ] );
while( !sNegative.Equals( "NULL" ) && bReturn ) {
sNegative.SearchAndReplaceAll( "\\", sDelimiter );
sNegative.SearchAndReplaceAll( "/", sDelimiter );
sNegative.ToLowerAscii();
if( sFileName.Search( sNegative ) == sFileName.Len() - sNegative.Len())
bReturn = FALSE;
nIndex++;
sNegative = NegativeList[ nIndex ];
}
return bReturn;
}
/*****************************************************************************/
BOOL SourceTreeLocalizer::CheckPositiveList( const ByteString &rFileName )
/*****************************************************************************/
{
ULONG nIndex = 0;
BOOL bReturn = FALSE;
ByteString sDelimiter(
DirEntry::GetAccessDelimiter(), RTL_TEXTENCODING_ASCII_US );
ByteString sFileName( rFileName );
sFileName.ToLowerAscii();
ByteString sNegative( PositiveList[ nIndex ] );
while( !sNegative.Equals( "NULL" ) && !bReturn ) {
sNegative.SearchAndReplaceAll( "\\", sDelimiter );
sNegative.SearchAndReplaceAll( "/", sDelimiter );
sNegative.ToLowerAscii();
if( sFileName.Search( sNegative ) == sFileName.Len() - sNegative.Len())
bReturn = TRUE;
nIndex++;
sNegative = PositiveList[ nIndex ];
}
return bReturn;
}
/*****************************************************************************/
void SourceTreeLocalizer::WorkOnFileType(
const ByteString &rDirectory, const ByteString &rExtension,
const ByteString &rExecutable, const ByteString &rParameter,
const ByteString &rCollectMode, const ByteString &rIso
)
/*****************************************************************************/
{
String sWild( rDirectory, RTL_TEXTENCODING_ASCII_US );
sWild += DirEntry::GetAccessDelimiter();
sWild += String::CreateFromAscii( "*." );
sWild += String( rExtension, RTL_TEXTENCODING_ASCII_US );
DirEntry aEntry( sWild );
Dir aDir( sWild, FSYS_KIND_FILE );
for ( USHORT i = 0; i < aDir.Count(); i++ ) {
DirEntry aFile( aDir[ i ] );
ByteString sFile( aFile.GetFull(), RTL_TEXTENCODING_ASCII_US );
BOOL bAllowed = TRUE;
if ( rCollectMode.Equals( "negative" ))
bAllowed = CheckNegativeList( sFile );
else if ( rCollectMode.Equals( "positive" ))
bAllowed = CheckPositiveList( sFile );
if ( bAllowed )
WorkOnFile( sFile, rExecutable, rParameter, rIso );
}
}
/*****************************************************************************/
void SourceTreeLocalizer::WorkOnDirectory( const ByteString &rDirectory )
/*****************************************************************************/
{
//printf("Working on Directory %s\n",rDirectory.GetBuffer());
ULONG nIndex = 0;
ByteString sExtension( ExeTable[ nIndex ][ 0 ] );
ByteString sExecutable( ExeTable[ nIndex ][ 1 ] );
ByteString sParameter( ExeTable[ nIndex ][ 2 ] );
ByteString sCollectMode( ExeTable[ nIndex ][ 3 ] );
ByteString sIso( ExeTable[ nIndex ][ 4 ] );
while( !sExtension.Equals( "NULL" )) {
WorkOnFileType(
rDirectory,
sExtension,
sExecutable,
sParameter,
sCollectMode,
sIso
);
nIndex++;
sExtension = ExeTable[ nIndex ][ 0 ];
sExecutable = ExeTable[ nIndex ][ 1 ];
sParameter = ExeTable[ nIndex ][ 2 ];
sCollectMode = ExeTable[ nIndex ][ 3 ];
sIso = ExeTable[ nIndex ][ 4 ];
}
}
/*****************************************************************************/
void SourceTreeLocalizer::OnExecuteDirectory( const ByteString &rDirectory )
/*****************************************************************************/
{
if ( nMode == LOCALIZE_NONE ){
if( !bQuiet2 ) fprintf( stdout, "%s\n", rDirectory.GetBuffer());
}
else
WorkOnDirectory( rDirectory );
}
/*****************************************************************************/
BOOL SourceTreeLocalizer::Extract( const ByteString &rDestinationFile )
/*****************************************************************************/
{
nMode = LOCALIZE_EXTRACT;
aSDF.Open( String( rDestinationFile, RTL_TEXTENCODING_ASCII_US ),
STREAM_STD_WRITE | STREAM_TRUNC );
aSDF.SetLineDelimiter( LINEEND_CRLF );
BOOL bReturn = aSDF.IsOpen();
if ( bReturn ) {
bReturn = StartExecute();
aSDF.Close();
}
else{
printf("ERROR: Can't create file %s\n", rDestinationFile.GetBuffer() );
}
nMode = LOCALIZE_NONE;
return bReturn;
}
/*****************************************************************************/
BOOL SourceTreeLocalizer::MergeSingleFile(
const ByteString &rPrj,
const ByteString &rFile,
const ByteString &rSDFFile
)
/*****************************************************************************/
{
//printf("MergeSingleFile(%s,%s,%s)",rPrj.GetBuffer(),rFile.GetBuffer(),rSDFFile.GetBuffer());
if ( !rFile.Len())
return TRUE;
ByteString sRoot( GetEnv( "SRC_ROOT" ));
DirEntry aEntry( String( sRoot, RTL_TEXTENCODING_ASCII_US ));
aEntry += DirEntry( String( rPrj, RTL_TEXTENCODING_ASCII_US ));
ByteString sDelimiter(
DirEntry::GetAccessDelimiter(), RTL_TEXTENCODING_ASCII_US );
ByteString sCur( rFile );
sCur.SearchAndReplaceAll( "\\", sDelimiter );
sCur.SearchAndReplaceAll( "/", sDelimiter );
aEntry += DirEntry( String( sCur, RTL_TEXTENCODING_ASCII_US ));
ByteString sFile( aEntry.GetFull(), RTL_TEXTENCODING_ASCII_US );
ByteString sBCur( aEntry.GetFull(), RTL_TEXTENCODING_ASCII_US );
if( !bQuiet2 ) fprintf( stdout, "##### %s #####\n", sBCur.GetBuffer());
ULONG nIndex = 0;
ByteString sExtension( aEntry.GetExtension(), RTL_TEXTENCODING_ASCII_US );
ByteString sCandidate( ExeTable[ nIndex ][ 0 ] );
while( !sCandidate.Equals ("NULL") && !sCandidate.Equals(sExtension) )
sCandidate = ExeTable[ ++nIndex ][ 0 ];
ByteString sIso( ExeTable[ nIndex ][ 4 ] );
if ( !sCandidate.Equals( "NULL" ) ) {
if( !aEntry.Exists()) {
DirEntryKind theDir=FSYS_KIND_FILE;
Dir myDir( aEntry.GetPath(), theDir);
DirEntry current;
BOOL found=FALSE;
for(int x=0; x < myDir.Count() && !found;){
current=myDir[x++];
StringCompare result=current.GetName().CompareIgnoreCaseToAscii( aEntry.GetName() );
if( result==COMPARE_EQUAL ){
fprintf(stderr,"WARNING: %s not found\n", ByteString(aEntry.GetFull(),RTL_TEXTENCODING_ASCII_US).GetBuffer() );
fprintf(stderr,"but use %s instead \n" , ByteString(current.GetFull(), RTL_TEXTENCODING_ASCII_US).GetBuffer() );
aEntry=current;
found=TRUE;
}
}
if(!found) return TRUE;
}
DirEntry aOut( Export::GetTempFile() );
ByteString sOutput;
if( sOutputFile.Len() == 0 )
sOutput = ByteString ( aOut.GetFull(), RTL_TEXTENCODING_ASCII_US );
else
sOutput = sOutputFile;
ByteString sCommand( ExeTable[ nIndex ][ 1 ] );
sCommand += " -i ";
sCommand += ByteString( aEntry.GetName(), RTL_TEXTENCODING_ASCII_US );
sCommand += " -m ";
sCommand += rSDFFile;
sCommand += " -o ";
sCommand += sOutput;
sCommand += " ";
sCommand += ByteString( ExeTable[ nIndex ][ 2 ] );
if ( sIso.Equals( "iso" ) && sIsoCode99.Len()) {
sCommand += " -ISO99 ";
sCommand += sIsoCode99;
}
if ( sLanguageRestriction.Len()) {
sCommand += " -l ";
sCommand += sLanguageRestriction;
}
if( bQuiet2 ){
sCommand +=" -QQ ";
}
DirEntry aPath( aEntry.GetPath());
DirEntry aOldCWD;
aPath.SetCWD();
system( sCommand.GetBuffer());
nFileCnt++;
printf(".");
//if( bQuiet2 ){ printf("."); }
SvFileStream aInStream( aOut.GetFull(), STREAM_READ );
if ( !aInStream.IsOpen()) {
fprintf( stderr,
"ERROR: Unable to open file %s for reading!\n",
sOutput.GetBuffer());
}
else {
FileStat::SetReadOnlyFlag( aEntry, FALSE );
String myStr2(aEntry.GetFull());
String aTemp22 = String::CreateFromAscii("_tmp");
myStr2.Append(aTemp22);
ByteString test(myStr2,RTL_TEXTENCODING_ASCII_US);
SvFileStream aOutStream( myStr2, STREAM_STD_WRITE | STREAM_TRUNC );
if ( !aOutStream.IsOpen()) {
ByteString test2(myStr2,RTL_TEXTENCODING_ASCII_US);
fprintf( stderr,"ERROR: Unable to open file %s for modification!\n", test2.GetBuffer());
aInStream.Close();
}
else {
ByteString sLine;
aOutStream.SetLineDelimiter( LINEEND_LF );
aInStream.ReadLine( sLine );
while ( !aInStream.IsEof()) {
aOutStream.WriteLine( sLine );
aInStream.ReadLine( sLine );
}
aInStream.Close();
aOutStream.Close();
DirEntry myTempFile(ByteString(myStr2,RTL_TEXTENCODING_ASCII_US)); // xxx_tmp ->
DirEntry myFile(ByteString(aEntry.GetFull(),RTL_TEXTENCODING_ASCII_US));// xxx
DirEntry oldFile(ByteString(aEntry.GetFull(),RTL_TEXTENCODING_ASCII_US));
if(oldFile.Kill()==ERRCODE_NONE){
if(myTempFile.MoveTo(myFile)!=ERRCODE_NONE){
fprintf( stderr, "ERROR: Can't rename file %s\n",ByteString(myStr2,RTL_TEXTENCODING_ASCII_US).GetBuffer());
}
}
else{
fprintf( stderr, "ERROR: Can't remove file %s\n",ByteString(aEntry.GetFull(),RTL_TEXTENCODING_ASCII_US).GetBuffer());
}
} // else
aOldCWD.SetCWD();
aOut.Kill();
} // else
}
return TRUE;
}
/*****************************************************************************/
BOOL SourceTreeLocalizer::ExecuteMerge( )
/*****************************************************************************/
{
DirEntry aEntry( Export::GetTempFile());
BOOL bReturn = TRUE;
bool bMerged = false;
ByteString sFileName;
ByteString sCurFile;
ByteString sLine;
ByteString sFileKey;
SvFileStream aFile;
ByteString sOutputFileName = sOutputFile;
ByteString sInpath(".");
sInpath += GetEnv("INPATH");
ByteString sBlank("");
sOutputFileName.SearchAndReplaceAll( sInpath , sBlank );
String sDel = DirEntry::GetAccessDelimiter();
if( bLocal ){
int nPos = sOutputFileName.SearchBackward( sDel.GetChar(0) );
if( nPos >= 0 )
sOutputFileName = sOutputFileName.Copy( nPos+1 , sOutputFileName.Len()-nPos-1 );
}
ByteStringBoolHashMap aFileHM;
// Read all possible files
while ( !aSDF.IsEof()) {
aSDF.ReadLine( sLine );
sFileName = sLine.GetToken( 0, '\t' );
sFileName += "#";
sFileName += sLine.GetToken( 1, '\t' );
aFileHM[sFileName]=true;
}
// RECODE THIS !!!!!!!!!!!!!!!!!!!!!
for( ByteStringBoolHashMap::iterator iter = aFileHM.begin(); iter != aFileHM.end(); ++iter ){
sFileKey = iter->first;
aSDF.Seek( 0 );
aFile.Open( aEntry.GetFull(), STREAM_STD_WRITE |STREAM_TRUNC );
while ( !aSDF.IsEof()) {
aSDF.ReadLine( sLine );
sFileName = sLine.GetToken( 0, '\t' );
sFileName += "#";
sFileName += sLine.GetToken( 1, '\t' );
if( sFileName.Len() && ( sFileName.CompareTo(sFileKey) == COMPARE_EQUAL ) ){
if ( aFile.IsOpen() && sLine.Len())
aFile.WriteLine( sLine );
}
}
if ( aFile.IsOpen())
aFile.Close();
ByteString sPrj( sFileKey.GetToken( 0, '#' ));
ByteString sFile( sFileKey.GetToken( 1, '#' ));
ByteString sSDFFile( aFile.GetFileName(), RTL_TEXTENCODING_ASCII_US );
if( bLocal ){
int nPos = sFile.SearchBackward( '\\' );
ByteString sTmp = sFile.Copy( nPos+1 , sFile.Len()-nPos-1 );
//printf("'%s'='%s'\n",sTmp.GetBuffer(), sOutputFileName.GetBuffer());
if( sTmp.CompareTo(sOutputFileName) == COMPARE_EQUAL ){
//int nPos = sFile.SearchBackward( '\\' );
//ByteString sCurFile = sFileKey.Copy( nPos+1 , sFile.Len()-nPos-1 );
//printf("MergeSingleFile('%s','%s','%s')\n",sPrj.GetBuffer(),sFileKey.GetBuffer(),sSDFFile.GetBuffer());
//if( sCurFile.EqualsIgnoreCaseAscii(sOutputFileName) ){
bMerged = true;
//printf("Found\n");
if ( !MergeSingleFile( sPrj, sFile, sSDFFile ))
bReturn = FALSE;
//}
}/*else{
bMerged = true;
printf("d\n");
printf("MergeSingleFile('%s','%s','%s')\n",sPrj.GetBuffer(),sFile.GetBuffer(),sSDFFile.GetBuffer());
if ( !MergeSingleFile( sPrj, sFile, sSDFFile ))
bReturn = FALSE;
}*/
}
}
//}
aEntry.Kill();
// If Outputfile not included in the SDF file copy it without merge
if( bLocal && !bMerged ){
DirEntry aSourceFile( sOutputFileName.GetBuffer() );
FSysError aErr = aSourceFile.CopyTo( DirEntry ( sOutputFile.GetBuffer() ) , FSYS_ACTION_COPYFILE );
if( aErr != FSYS_ERR_OK ){
printf("ERROR: Can't copy file '%s' to '%s' %d\n",sOutputFileName.GetBuffer(),sOutputFile.GetBuffer(),aErr);
}
}
return bReturn;
//printf("DBG: sFilename = %s , sOldFileName = %s ", sFileName.GetBuffer() , sOldFileName.GetBuffer() );
/*if ( sFileName.Len() && ( !sOldFileName.Equals(sFileName) ) ){
if ( aFile.IsOpen()) {
aFile.Close();
ByteString sPrj( sOldFileName.GetToken( 0, '#' ));
ByteString sFile( sOldFileName.GetToken( 1, '#' ));
ByteString sSDFFile( aFile.GetFileName(), RTL_TEXTENCODING_ASCII_US );
if( bLocal ){
int nPos = sFile.SearchBackward( '\\' );
sCurFile = sFile.Copy( nPos+1 , sFile.Len()-nPos-1 );
//printf("'%s'\n'%s'",sCurFile.GetBuffer(),sOutputFileName.GetBuffer());
if( sCurFile.EqualsIgnoreCaseAscii(sOutputFileName) ){
bMerged = true;
printf("a\n");
if ( !MergeSingleFile( sPrj, sFile, sSDFFile ))
bReturn = FALSE;
}
}else {
bMerged = true;
printf("b\n");
if ( !MergeSingleFile( sPrj, sFile, sSDFFile ))
bReturn = FALSE;
}
}
aFile.Open( aEntry.GetFull(),
STREAM_STD_WRITE |STREAM_TRUNC );
}
if ( aFile.IsOpen() && sLine.Len())
aFile.WriteLine( sLine );
}
if ( aFile.IsOpen()) {
aFile.Close();
ByteString sPrj( sLine.GetToken( 0, '\t' ));
ByteString sFile( sLine.GetToken( 1, '\t' ));
ByteString sSDFFile( aFile.GetFileName(), RTL_TEXTENCODING_ASCII_US );
if( bLocal ){
int nPos = sFile.SearchBackward( '\\' );
sCurFile = sFile.Copy( nPos+1 , sFile.Len()-nPos-1 );
//printf("'%s'\n'%s'",sCurFile.GetBuffer(),sOutputFileName.GetBuffer());
if( sCurFile.EqualsIgnoreCaseAscii(sOutputFileName) ){
bMerged = true;
printf("c\n");
if ( !MergeSingleFile( sPrj, sFile, sSDFFile ))
bReturn = FALSE;
}
}else{
bMerged = true;
printf("d\n");
if ( !MergeSingleFile( sPrj, sFile, sSDFFile ))
bReturn = FALSE;
}
}
*/
/* aEntry.Kill();
if( bLocal && !bMerged ){
//printf("File not merged sOutFile: '%s' , sCurFile = '%s' , sOutFilename: '%s' \n", sOutputFile.GetBuffer() ,
// sCurFile.GetBuffer() , sOutputFileName.GetBuffer() );
DirEntry aSourceFile( sOutputFileName.GetBuffer() );
FSysError aErr = aSourceFile.CopyTo( DirEntry ( sOutputFile.GetBuffer() ) , FSYS_ACTION_COPYFILE );
//printf("Error = %d\n",aErr);
if( aErr != FSYS_ERR_OK ){
printf("ERROR: Can't copy file '%s' to '%s' %d\n",sOutputFileName.GetBuffer(),sOutputFile.GetBuffer(),aErr);
}
}
return bReturn; */
}
/*****************************************************************************/
BOOL SourceTreeLocalizer::Merge( const ByteString &rSourceFile , const ByteString &rOutput )
/*****************************************************************************/
{
sOutputFile = rOutput;
nMode = LOCALIZE_MERGE;
aSDF.Open( String( rSourceFile, RTL_TEXTENCODING_ASCII_US ),
STREAM_STD_READ );
BOOL bReturn = aSDF.IsOpen();
if ( bReturn ) {
bReturn = ExecuteMerge();
aSDF.Close();
}
nMode = LOCALIZE_NONE;
return bReturn;
}
#define STATE_NONE 0x0000
#define STATE_EXPORT 0x0001
#define STATE_MERGE 0x0002
#define STATE_ISOCODE 0x0003
#define STATE_LANGUAGES 0x0004
#define STATE_FILENAME 0x0005
#define STATE_OUTPUT 0x0006
/*****************************************************************************/
void Help()
/*****************************************************************************/
{
fprintf( stdout,
"localize (c)2001 by Sun Microsystems\n"
"====================================\n" );
fprintf( stdout,
"As part of the L10N framework, localize extracts and merges translations\n"
"out of and into the whole source tree.\n\n"
"Syntax: localize -e|-m -l l1[=f1][,l2[=f2]][...] -f FileName [-QQ]\n"
"Parameter:\n"
"\t-e: Extract mode\n"
"\t-m: Merge mode\n"
"\tFileName: Output file when extract mode, input file when merge mode\n"
"\tl1...ln: supported languages (\"all\" for all languages).\n"
"\tf1...fn: fallback languages for supported languages\n"
"\tQQ: quiet output)"
);
fprintf( stdout,
"Valid language codes for l1...ln and f1...fn are:\n" );
// Ivo
/* for ( USHORT i = 0; i < LANGUAGES; i++ ) {
ByteString sId;
if ( Export::LangId[ i ] < 10 ) {
sId = "0";
}
sId += ByteString::CreateFromInt32( Export::LangId[ i ] );
ByteString sLanguage( Export::LangName[ i ] );
fprintf( stdout,
"\t%s => %s\n",
sId.GetBuffer(),
sLanguage.GetBuffer()
);
} */
fprintf( stdout,
"\nExample 1:\n"
"==========\n"
"localize -e -l en-US,de -f MyFile\n\n"
"All strings will be extracted for language de and language en-US.\n"
);
fprintf( stdout,
"\nExample 2:\n"
"==========\n"
"localize -m -l es -f MyFile\n\n"
"All strings in MyFile will be merged into language es in the\n"
"source code.\n"
);
}
/*****************************************************************************/
int Error()
/*****************************************************************************/
{
Help();
return 1;
}
/*****************************************************************************/
BOOL CheckLanguages( ByteString &rLanguages )
/*****************************************************************************/
{
BOOL bReturn = TRUE;
ByteString sTmp( rLanguages );
/* Using gcc-2.95.3 and STLport-4.5 .Equals() must
* be used.. using == causes a compile error */
/* if ( sTmp.ToUpperAscii().Equals("ALL") ) {
rLanguages = "cz,nl";
fprintf( stdout, "\nExpanded -l all to %s\n", rLanguages.GetBuffer());
}*/
/*for ( USHORT i = 0; i < rLanguages.GetTokenCount( ',' ); i++ ) {
ByteString sCur = rLanguages.GetToken( i, ',' );
ByteString sLang = sCur.GetToken( 0, '=' );
USHORT nLang = ( USHORT ) sLang.ToInt32();
ByteString sFallback = sCur.GetToken( 1, '=' );
USHORT nFallback = ( USHORT ) sFallback.ToInt32();
if ( Export::GetLangIndex( nLang ) == 0xFFFF ) {
fprintf( stderr, "ERROR: Unknown language %s\n",
sLang.GetBuffer());
bReturn = FALSE;
}
else if ( sFallback.Len() && ( Export::GetLangIndex( nFallback )==0xFFFF )){
fprintf( stderr, "ERROR: Unknown fallback languges %s\n",
sFallback.GetBuffer());
bReturn = FALSE;
}
}
if ( bReturn ) {
if ( !rLanguages.Len()) {
rLanguages = "01,99=01";
}
}
return bReturn;*/
return true;
}
/*****************************************************************************/
#if defined( UNX ) || defined( MAC )
int main( int argc, char *argv[] )
#else
int _cdecl main( int argc, char *argv[] )
#endif
/*****************************************************************************/
{
String sTempBase( String::CreateFromAscii( "loc" ));
DirEntry::SetTempNameBase( sTempBase );
USHORT nState = STATE_NONE;
BOOL bExport = FALSE;
BOOL bMerge = FALSE;
bool bQuiet = false;
bool bQuiet2 = false;
ByteString sIsoCode;
ByteString sLanguages;
ByteString sFileName;
ByteString sOutput;
for( int i = 1; i < argc; i++ ) {
if ( ByteString( argv[ i ]).ToUpperAscii().Equals( "-E" )) {
nState = STATE_EXPORT;
if ( bMerge )
return Error();
bExport = TRUE;
}
else if ( ByteString( argv[ i ]).ToUpperAscii().Equals( "-M" )) {
nState = STATE_MERGE;
if ( bExport )
return Error();
bMerge = TRUE;
}
else if( ByteString( argv[ i ]).ToUpperAscii().Equals( "-Q" )) {
bQuiet = true;
}
else if ( ByteString( argv[ i ]).ToUpperAscii().Equals( "-I" ) )
nState = STATE_ISOCODE;
else if ( ByteString( argv[ i ]).ToUpperAscii().Equals( "-L" ) )
nState = STATE_LANGUAGES;
else if ( ByteString( argv[ i ]).ToUpperAscii().Equals( "-F" ) )
nState = STATE_FILENAME;
else if ( ByteString( argv[ i ]).ToUpperAscii().Equals( "-QQ" ))
bQuiet2 = true;
else if ( ByteString( argv[ i ]).ToUpperAscii().Equals( "-O" ) )
nState = STATE_OUTPUT;
else {
switch ( nState ) {
case STATE_NONE:
return Error();
break;
case STATE_ISOCODE:
if ( sIsoCode.Len())
return Error();
sIsoCode = ByteString( argv[ i ] );
nState = STATE_NONE;
break;
case STATE_OUTPUT:
if ( sOutput.Len())
return Error();
sOutput = ByteString( argv[ i ] );
nState = STATE_NONE;
break;
case STATE_LANGUAGES:
if ( sLanguages.Len())
return Error();
sLanguages = ByteString( argv[ i ] );
nState = STATE_NONE;
break;
case STATE_FILENAME:
if ( sFileName.Len())
return Error();
sFileName = ByteString( argv[ i ] );
nState = STATE_NONE;
break;
default:
return Error();
break;
}
}
}
if ( !bMerge && !bExport ) {
Help();
return 1;
}
ByteString sRoot( GetEnv( "SRC_ROOT" ));
DirEntry aRoot( String( sRoot, RTL_TEXTENCODING_ASCII_US ));
sRoot = ByteString( aRoot.GetFull(), RTL_TEXTENCODING_ASCII_US );
ByteString sVersion( GetEnv( "WORK_STAMP" ));
if ( !sRoot.Len() || !sVersion.Len()) {
fprintf( stderr, "ERROR: No environment set!\n" );
return 1;
}
if ( !CheckLanguages( sLanguages ))
return 2;
/* Ivo
if ( !sIsoCode.Len() && ( sLanguages.Search( "99" ) != STRING_NOTFOUND )) {
fprintf( stderr, "ERROR: No ISO code given\n" );
return 3;
}
*/
if ( !sFileName.Len()) {
fprintf( stderr, "ERROR: No filename given\n" );
return 3;
}
ByteString sMode( "merge" );
if ( bExport )
sMode = "extract";
ByteString sICode( sIsoCode );
if ( !sICode.Len())
sICode = "not given, support for language 99 disabled";
if(!bQuiet && !bQuiet2 ){
fprintf( stdout,
"\n"
"============================================================\n"
"Current settings:\n"
"============================================================\n"
"Mode: %s\n"
"Workspace: %s\n"
"Source tree: %s\n"
"Languages: %s\n"
"ISO code (99): %s\n"
"Filename: %s\n"
"Outputfile %s\n"
"============================================================\n"
"\n"
,
sMode.GetBuffer(),
sVersion.GetBuffer(),
sRoot.GetBuffer(),
sLanguages.GetBuffer(),
sICode.GetBuffer(),
sFileName.GetBuffer(),
sOutput.GetBuffer()
);
}
SourceTreeLocalizer aIter( sRoot, sVersion , (sOutput.Len() > 0) , bQuiet2 );
aIter.SetLanguageRestriction( sLanguages );
aIter.SetIsoCode99( sIsoCode );
if ( bExport ){
if( bQuiet2 ){ printf("");fflush( stdout );}
aIter.Extract( sFileName );
if( bQuiet2 ){ printf("\n %d files found!\n",aIter.GetFileCnt());}
}
else {
DirEntry aEntry( String( sFileName, RTL_TEXTENCODING_ASCII_US ));
if ( !aEntry.Exists())
return FALSE;
aIter.Merge( sFileName , sOutput );
}
return 0;
}
|