forked from tracefoundation/UTFC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Converter_20100625.c
executable file
·15568 lines (13053 loc) · 395 KB
/
Converter_20100625.c
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
/**
* Universal Tibetan Font Converter Version 2.0
*
* Copyright 2003-2008 Trace Foundation
*
* Licensed under GNU General Public License 3.0.
* Author: Tashi Tsering
* Research Assistant: Nyima Droma
* Supported by: Trace Foundation
*
* @license GPL-3.0+ <http://spdx.org/licenses/GPL-3.0+>
*/
//----------------------------------------------------
//----------include-----------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
//#include <process.h> //For Windows, not for Unix
#include <malloc.h>
#include <string.h>
//#include <wchar.h> //Only for Unix //20090325
//-------------OS--------------------------------------
//#define Windows //This is for Windows system!!!!!
//#define Mac //This is for Macintosh system!!!!!
#define Unix //This is for Unix or Linux system!!!!!
//#define OS390 //This is for OS/390 system!!!!!
//--------------Language Edition-----------------------
//#define CHINESE //This is for Chinese Edition
#define ENGLISH //This is for English Edition
//--------------Other Defines--------------------------
#define Yes 1
#define No 0
#define Latin 100
#define Tibetan 101
#define Chinese 102
#define Sanskrit 103
//------------------------------------------------------
#define Unicode 0 //ID--0
#define TMW 1 //ID--1
#define TM 2 //ID--2
#define Fz 3 //ID--3
#define Hg 4 //ID--4
#define ACIP 5 //ID--5
#define Wylie 6 //ID--6
#define LTibetan 7 //ID--7
#define OldSambhota 8 //ID--8
#define NewSambhota 9 //ID--9
#define THDLWylie 10 //ID--10
#define LCWylie 11 //ID--11
#define TCRCBodYig 12 //ID--12
#define Bzd 13 //ID--13 //2007
#define Ty 14 //ID--14
#define NS 15 //ID--15
#define Jamyang 16 //ID--16 //20080924
//--------------------------------------------
#define TXT 0
#define RTF 1
#define UnicodeTXT 2
#define WebPage 3
#define UnicodeToOthers 0
#define OthersToUnicode 1
#define EncodingToEncoding 2
#define OthersToOthers 3
//-----------------------------------------------------
char m_UTFCdirectory[1000]; //The directory of UTFC.exe
//Unicode to others Mapping Table File Names
char *Uni2othersMTFNames[] =
{
"Uni2Uni.tbl",
"Uni2TMW.tbl",
"Uni2TM.tbl",
"Uni2Fz.tbl",
"Uni2Hg.tbl",
"Uni2ACIP.tbl",
"Uni2Wylie.tbl",
"Uni2LTibetan.tbl",
"Uni2OldSambhota.tbl",
"Uni2NewSambhota.tbl",
"Uni2THDLWylie.tbl",
"Uni2LCWylie.tbl",
"Uni2TCRCBodYig.tbl",
"Uni2Bzd.tbl", //2007
"Uni2Ty.tbl",
"Uni2NS.tbl",
"Uni2Jamyang.tbl"//20080924
};
//Others to Unicode Mapping Table File Names
char *Others2UniMTFNames[] =
{
"Uni2Uni.tbl",
"TMW2Uni.tbl",
"TM2Uni.tbl",
"Fz2Uni.tbl",
"Hg2Uni.tbl",
"ACIP2Uni.tbl",
"Wylie2Uni.tbl",
"LTibetan2Uni.tbl",
"OldSambhota2Uni.tbl",
"NewSambhota2Uni.tbl",
"THDLWylie2Uni.tbl",
"LCWylie2Uni.tbl",
"TCRCBodYig2Uni.tbl",
"Bzd2Uni.tbl", //2007
"Ty2Uni.tbl",
"NS2Uni.tbl",
"Jamyang2Uni.tbl"//20080924
};
//Tibetan Syllable Table File Names for different transliteration scheme
char *TibetanSyllableTableFileNames[] =
{
"Uni2Uni.tbl",
"TMW2Uni.tbl",
"TM2Uni.tbl",
"Fz2Uni.tbl",
"Hg2Uni.tbl",
"ACIPTibetanSyllable.tbl",
"WylieTibetanSyllable.tbl",
"LTibetan2Uni.tbl",
"OldSambhota2Uni.tbl",
"NewSambhota2Uni.tbl",
"THDLWylieTibetanSyllable.tbl",
"LCWylieTibetanSyllable.tbl",
"TCRCBodYig2Uni.tbl",
"Bzd2Uni.tbl", //2007
"Ty2Uni.tbl",
"NS2Uni.tbl",
"Jamyang2Uni.tbl"//20080924
};
char *VowelsForTSLtableNames[] =
{
"VowelsForUni.tbl",//No use
"VowelsForTMW.tbl",
"VowelsForTM.tbl",
"VowelsForFz.tbl",//No use
"VowelsForHg.tbl",//No use
"VowelsForACIP.tbl",//No use
"VowelsForWylie.tbl",//No use
"VowelsForLTibetan.tbl",
"VowelsForOldSambhota.tbl",
"VowelsForNewSambhota.tbl",
"VowelsForTHDLWylie.tbl", //No use
"VowelsForLCWylie.tbl", //No use
"VowelsForTCRCBodYig.tbl",
"VowelsForBzd.tbl", //2007
"VowelsForTy.tbl",
"VowelsForNS.tbl",
"VowelsForJamyang.tbl"//20080924
};
//--------------------------------------
//Those that can be adjusted
//
#define DeffFontSize 16
#define MAXSTACKHEIGHT 100
#define SZBuffer 1000 //Source Text Buffer Size
#define FontBufferSize 300 //Using for hunting fonttbl
#define BaseNumber 33 //For setting up rtf head when writing a new rtf file
//---------------------------------------------------------------------------
//Default Unicode tibetan font name in the system
#ifdef Windows
char TibetanUnicodeFontName[]="Microsoft Himalaya";
#endif
#ifdef Mac
char TibetanUnicodeFontName[]="kalaso";//TO BE DETERMINED 20080924
#endif
#ifdef Unix
char TibetanUnicodeFontName[]="Microsoft Himalaya"; //UnixTibetanFont";//TO BE DETERMINED
#endif
#define TEMP_FILE "TMP/tempFile" //mk parameterized tempFile location
//------------------------------
#define PUSHED 0
#define STACKFULL 1
#define NOTHINGONSTACK 2
#define POPED 3
#define ControlSymbol 4
#define ControlWord 5
#define SpecialControlWord 6
#define TextBufferEmpty 7
#define TranslationDone 8
#define NoFontFileID 9
#define NotRtfFile 10
#define ThisIsRtfFile 11
#define NoDeff 12
#define FonttblProcessed 13
#define EndOfBuffer 14
#define NoCertainTibetanFont 15
#define NoFonttbl 16
#define Exception 17
#define ConversionDone 18
#define NoSourceFile 19
#define NoTargetFile 20
#define WrongSourceEncoding 21
#define WrongTargetEncoding 22
#define Initialized 23
#define WrongSourceFileFormat 24
#define WrongTargetFileFormat 25
#define UnknowConversionDirection 26
#define SameEncoding 27
#define EndOfFile 28
#define GotTheDeff 29
#define NoTableFile 30
#define WrongBytesAppeared 31
#define EmptyFile 32
#define NoMemory 33
#define ReachFontTbl 34
#define MappingTableLoaded 35
#define MemoryFreed 36
#define WrongSourceEncodingOrFileFormat 37
#define WrongTargetEncodingOrFileFormat 38
#define MSoffice 39
#define BodyTagFound 40
#define FontTagFound 41
#define OtherTagFound 42
#define NoVowelTableFile 43
#define VowelTableLoaded 44
#define NoUnicodeToAWTableFile 45
#define UnicodeToAWTableLoaded 46
#define Translated 47
#define AWToUnicodeTableLoaded 48
#define NeedFileName 49
#define ClosingTagFound 50
#define NonLatinCharacterCodeValue 51
#define NoTibetanSyllableTableFile 52
#define LinkTagFound 53
#define StyleTagFound 54
#define ClosingStyleTagFound 55
#define CommentTagFound 56
#define FontStyleTagFound 57
#define SimpleTag 58
#define TagWithAttributes 59
#define NoStyleSheetFile 60
#define NoAWToUnicodeTableFile 61
#define CP936TableUnavailable 62 //GB2312
#define CP936TableBuilt 63 //GB2312
#define UnicodeBigEndian 64 //200802
#define UTF8 65 //200802
#define DOCTYPETagFound 66 //20080229
#ifdef CHINESE
//For output debug information
char *DebugInfo[] = {
"PUSHED",
"STACKFULL",
"NOTHINGONSTACK",
"POPED",
"ControlSymbol",
"ControlWord",
"SpecialControlWord",
"TextBufferEmpty",
"翻译结束。",
"No Font File ID",
"源文件不是RTF文件。",
"ThisIsRtfFile",
"No Deff",
"Fonttbl Processed",
"End Of Buffer",
"No Certain Tibetan Font",
"No Fonttbl",
"Exception Happened!",
" 转换结束!",
"没有源文件!",
"没有目标文件!",
"源文件编码或字体名称不正确!",
"目标文件编码或字体名称不正确!",
"Initialized",
"源文件格式不正确!",
"目标文件格式不正确!",
"Unknow Conversion Direction!",
"相同编码或字体!",
"文件结束!",
"Got The Deff",
"影射表文件不存在!",
"Wrong Bytes Appeared",
"源文件是空的!",
"没有足够的内存空间!",
"Font table presents!",
"Mapping Table Loaded!",
"Memory Is Freed!",
"源文件编码或格式不正确!", //"Wrong Source Encoding Or Source File Format!",
"目标文件编码或格式不正确!", //"Wrong Target Encoding Or Target File Format!",
"微软Office就可以做这个转换,请用它转换!",
"Body tag found!",
"Font tag found!",
"Other tag found!",
"缺影射表文件VowelsForTSL.tbl!",
"VowelsForTSL table loaded!",
"缺Unicode 到AW影射表文件!",
"Unicode to AW table loaded!",
"Unicode 到AW转换结束!",
"AW to Unicode table loaded!",
"请指定文件名!",
"Closing tag found!",
"Non Latin Character Code Value!",
"No Tibetan Syllable TableFile!",
"Link tag found!",
"Style tag found!",
"Closing Style Tag Found!",
"Comment Tag Found!",
"Style Tag That Has Font is Found!",
"A simple tag!",
"Tag With Attributes Found!",
"没有Stylesheet文件!",
"缺AW到Unicode影射表文件!",
"CP936toUnicodeTable.TXT 不存在!请检查!",//GB2312
"CP936toUnicode Table and Unicode to CP936 Table are already being built!",//GB2312
"您的源文件的格式是 Unicode Big Endian, 无法进行转换。请将其格式用其它软件如MS Notepad转存为Unicode, 然后再来转换!", //200802
"您的源文件的格式是 UTF8, 无法进行转换。请将其格式用其它软件如MS Notepad转存为Unicode, 然后再来转换!", //200802
"A DOCTYPE Tag Found."
};
#endif
#ifdef ENGLISH
//For output debug information
char *DebugInfo[] = {
"PUSHED",
"STACKFULL",
"NOTHINGONSTACK",
"POPED",
"ControlSymbol",
"ControlWord",
"SpecialControlWord",
"TextBufferEmpty",
"Translation Done",
"No Font File ID",
"Source File Is Not Rtf File!",
"ThisIsRtfFile",
"No Deff",
"Fonttbl Processed",
"End Of Buffer",
"No Certain Tibetan Font",
"No Fonttbl",
"Exception Happened!",
" Conversion Is Done!",
"No Source File!",
"No Target File!",
"Wrong Source Encoding Name!",
"Wrong Target Encoding Name!",
"Initialized",
"WrongSourceFileFormat",
"Wrong Target File Format Name!",
"Unknow Conversion Direction!",
"They Are The Same Encoding!",
"End Of File!",
"Got The Deff",
"There Is No Table File!",
"Wrong Bytes Appeared",
"Source File Is a Empty File!",
"There is no enough memory!",
"Font table presents!",
"Mapping Table Loaded!",
"Memory Is Freed!",
"Wrong Source File! It's not in the specified format!", //"Wrong Source Encoding Or Source File Format!",
"Wrong Target File Format!", //"Wrong Target Encoding Or Target File Format!",
"MS Office Can Do This! Please use it to do this!",
"Body tag found!",
"Font tag found!",
"Other tag found!",
"There is no VowelsForTSL table file",
"VowelsForTSL table loaded!",
"There is no Unicode to AW table!",
"Unicode to AW table loaded!",
"Unicode to AW Translation done!",
"AW to Unicode table loaded!",
"Need file name!",
"Closing tag found!",
"Non Latin Character Code Value!",
"No Tibetan Syllable TableFile!",
"Link tag found!",
"Style tag found!",
"Closing Style Tag Found!",
"Comment Tag Found!",
"Style Tag That Has Font is Found!",
"A simple tag!",
"Tag With Attributes Found!",
"There Is No Style Sheet File!",
"There is no AW to Unicode table!",
"Table file CP936toUnicodeTable.TXT is unavailable!",//GB2312
"CP936toUnicode Table and Unicode to CP936 Table are already being built!",//GB2312
"Source file format is Unicode Big Endian, please contert it into Unicode by other software such as Microsoft Notepad, and then come back and do the conversion here again!", //200802
"Source file format is UTF8, please contert it into Unicode by other software such as Microsoft Notepad, and then come back and do the conversion here again!", //200802
"A DOCTYPE Tag Found." //20080229
};
#endif
//-----------------------------------------------------------------------
//Pointers to TMW font names
char *TibetanFontNames[] = {
//Unicode font
"Microsoft Himalaya",
"CTRC-Uchen", //20090325
"CTRC-Betsu", //20090325
"CTRC-Drutsa", //20090325
"CTRC-Tsumachu", //20090325
"藏研乌坚体", //20090325
"藏研簇玛丘体", //20090325
"藏研柏簇体", //20090325
"藏研珠擦体", //20090325
"藏研乌金体", //20090325
//TMW font
"TibetanMachineWeb",
"TibetanMachineWeb1",
"TibetanMachineWeb2",
"TibetanMachineWeb3",
"TibetanMachineWeb4",
"TibetanMachineWeb5",
"TibetanMachineWeb6",
"TibetanMachineWeb7",
"TibetanMachineWeb8",
"TibetanMachineWeb9",
//TM font
"TibetanMachine",
"TibetanMachineSkt1",
"TibetanMachineSkt2",
"TibetanMachineSkt3",
"TibetanMachineSkt4",
//Fz
//Hg
//ACIP
"Arial",
"Times New Roman",
//Wylie
"Arial",
"Times New Roman",
//LTibetan
"LTibetan",
"LMantra",
//OldSambhota
"Sama",
"Samb",
"Samc",
"Esama",
"Esamb",
"Esamc",
//NewSambhota
"Dedris-a",
"Dedris-a1",
"Dedris-a2",
"Dedris-a3",
"Dedris-b",
"Dedris-b1",
"Dedris-b2",
"Dedris-b3",
"Dedris-c",
"Dedris-c1",
"Dedris-c2",
"Dedris-c3",
"Dedris-d",
"Dedris-d1",
"Dedris-d2",
"Dedris-d3",
"Dedris-e",
"Dedris-e1",
"Dedris-e2",
"Dedris-e3",
"Dedris-f",
"Dedris-f1",
"Dedris-f2",
"Dedris-f3",
"Dedris-g",
"Dedris-g1",
"Dedris-g2",
"Dedris-g3",
"Dedris-syma",
"Dedris-vowa",
"Ededris-a",
"Ededris-a1",
"Ededris-a2",
"Ededris-a3",
"Ededris-b",
"Ededris-b1",
"Ededris-b2",
"Ededris-b3",
"Ededris-c",
"Ededris-c1",
"Ededris-c2",
"Ededris-c3",
"Ededris-d",
"Ededris-d1",
"Ededris-d2",
"Ededris-d3",
"Ededris-e",
"Ededris-e1",
"Ededris-e2",
"Ededris-e3",
"Ededris-f",
"Ededris-f1",
"Ededris-f2",
"Ededris-f3",
"Ededris-g",
"Ededris-g1",
"Ededris-g2",
"Ededris-g3",
"Ededris-syma",
"Ededris-vowa",
//THDLWylie
"Arial",
"Times New Roman",
//LCWylie
"Arial",
"Times New Roman",
//TCRCBodYig
"TCRC Bod-Yig",
"TCRC Youtso",
"TCRC Youtsoweb",
//Bzd
"BZDBT", //2007
"BZDHT",
"BZDMT",
//Ty
"TIBETBT",
"TIBETHT",
"CHINATIBET",//20090325
//NS
"藏文吾坚琼体",
//Jamyang 20080924
"DBu-can",
"Tibetisch dBu-can",
"Tibetisch dBu-can Overstrike"
};//TO BE EXTENDED
char *AllTibetanFontNames[] = {
//Unicode font
"Microsoft Himalaya", //2007
"CTRC-Uchen", //20090325
"CTRC-Betsu", //20090325
"CTRC-Drutsa", //20090325
"CTRC-Tsumachu", //20090325
"藏研乌坚体", //20090325
"藏研簇玛丘体", //20090325
"藏研柏簇体", //20090325
"藏研珠擦体", //20090325
"藏研乌金体", //20090325
//TMW font
"TibetanMachineWeb",
"TibetanMachineWeb1",
"TibetanMachineWeb2",
"TibetanMachineWeb3",
"TibetanMachineWeb4",
"TibetanMachineWeb5",
"TibetanMachineWeb6",
"TibetanMachineWeb7",
"TibetanMachineWeb8",
"TibetanMachineWeb9",
//TM font
"TibetanMachine",
"TibetanMachineSkt1",
"TibetanMachineSkt2",
"TibetanMachineSkt3",
"TibetanMachineSkt4",
//Fz
//Hg
//Chinese
//"宋体", //20080229 //20090325
//LTibetan
"LTibetan",
"LMantra",
//OldSambhota
"Sama",
"Samb",
"Samc",
"Esama",
"Esamb",
"Esamc",
//NewSambhota
"Dedris-a",
"Dedris-a1",
"Dedris-a2",
"Dedris-a3",
"Dedris-b",
"Dedris-b1",
"Dedris-b2",
"Dedris-b3",
"Dedris-c",
"Dedris-c1",
"Dedris-c2",
"Dedris-c3",
"Dedris-d",
"Dedris-d1",
"Dedris-d2",
"Dedris-d3",
"Dedris-e",
"Dedris-e1",
"Dedris-e2",
"Dedris-e3",
"Dedris-f",
"Dedris-f1",
"Dedris-f2",
"Dedris-f3",
"Dedris-g",
"Dedris-g1",
"Dedris-g2",
"Dedris-g3",
"Dedris-syma",
"Dedris-vowa",
"Ededris-a",
"Ededris-a1",
"Ededris-a2",
"Ededris-a3",
"Ededris-b",
"Ededris-b1",
"Ededris-b2",
"Ededris-b3",
"Ededris-c",
"Ededris-c1",
"Ededris-c2",
"Ededris-c3",
"Ededris-d",
"Ededris-d1",
"Ededris-d2",
"Ededris-d3",
"Ededris-e",
"Ededris-e1",
"Ededris-e2",
"Ededris-e3",
"Ededris-f",
"Ededris-f1",
"Ededris-f2",
"Ededris-f3",
"Ededris-g",
"Ededris-g1",
"Ededris-g2",
"Ededris-g3",
"Ededris-syma",
"Ededris-vowa",
"TCRC Bod-Yig",
"TCRC Youtso",
"TCRC Youtsoweb"
//Bzd
"BZDBT", //2007
"BZDHT",
"BZDMT",
//Ty
"TIBETBT",
"TIBETHT",
"CHINATIBET",//20090325
//NS
"藏文吾坚琼体",
//Jamyang 20080924
"DBu-can",
"Tibetisch dBu-can",
"Tibetisch dBu-can Overstrike"
};//TO BE EXTENDED
int TotalTibetanFontNumber = 106; // = 95 - 8 + 1; //# of all Tibetan fonts over all encodings //2007 20080924 //20090325
//TO BE DETERMINED
//--------------------------------------------------------------------------
//Tibetan encodings. Index is the ID of the encoding
char *EncodingNames[] = {
"Unicode", //ID--0
"TMW", //ID--1
"TM", //ID--2
"Fz", //ID--3
"Hg", //ID--4
"ACIP", //ID--5
"Wylie", //ID--6
"LTibetan", //ID--7
"OldSambhota", //ID--8
"NewSambhota", //ID--9
"THDLWylie", //ID--10
"LCWylie", //ID--11
"TCRCBodYig", //ID--12
"Bzd", //ID--13 //2007
"Ty", //ID--14
"NS", //ID--15
"Jamyang" //ID--16 //20080924
};
int Encodings = 17; //How many Encodings are there!!!!! //2007 20080924
int BaseIndex[]={0, 10, 20, 0, 0, 25, 27, 29, 31, 37, 97, 99, 101, 104, 107, 110, 111};//Actual index of each encoding in the array "TibetanFontNames" //2007 20080924 //20090325
int EncodingFontNumber[] = {10, 10, 5, 0, 0, 2, 2, 2, 6, 60, 2, 2, 3, 3, 3, 1, 3}; //Number of Tibetan font in a certain font encoding //2007 20080924 //20090325
int TargetFileBaseFontNumberRTF2RTF; //20090427
//
//---------------------------------------------------------------------
//Files
FILE *sourceFile;
FILE *targetFile;
FILE *fTable; //For mapping tables
FILE *fTibetanSyllableTable; //For Tibetan Syllable
char *styleSheetFileName;
FILE *stylesheetFile;
//---------------------------------------------------------------------
int SourceEncoding = -1;//To be initiallized as -1
int TargetEncoding = -1;
int ConversionDirection = -1; //Conversion direction
//0---Unicode to others
//1---Others to Unicode
//2---between same encodings, doesn't make sense
//3---Others to others
int SourceFileFormat; //0---TXT
//1---RTF
//2---UnicodeTXT
//3---webpage
int TargetFileFormat; //0---TXT
//1---RTF
//2---UnicodeTXT
//3---webpage
int SourceFileType = -1; //0---TXT //200802
//1---RTF
//2---UnicodeTXT
//3---webpage
int TargetFileType = -1; //0---TXT //200802
//1---RTF
//2---UnicodeTXT
//3---webpage
//---------------------------------------------------------------------
char ChineseFontName[]="宋体"; //20080229
char RtfFontSize[] = "\\fs16";
//---------------------------------------------------------------------
//Global variables for parsing fonttbl
#define fTrue 1
#define fFalse 0
int holdTibetanBuffer = No;//For making Unicode sequence continuous when convert from Unicode to others.
int FonttblPast = No;
long lParam;
int param;
int fParam = fFalse; //Does the control word have a parameter?
char szKeyword[30]; //Buffer for the keyword
char szParameter[20]; //Buffer for the parameter
typedef struct // font info structure to be on stack
{
int fontSize;
int fontID;
int isTibetan;
} FONTINFO;
FONTINFO myStack[MAXSTACKHEIGHT];
int stackIndex = 0;
FONTINFO currentFontInfo;
FONTINFO deffFontInfo;
//----------------------------------------------------
//The buffer holding characters from RTF files!
typedef struct
{
int ch;
int fontID;
} CharWithFontInfo;//Character with its font info
CharWithFontInfo TibetanBuffer[SZBuffer + 1];
int nTibetan = 0; //Number of Tibetan Characters In Source Text Buffer;
int nChinese = 0;
int nLatin = 0;
int nTibetanInAW = 0;
int nFormatBuffer = 0;
int nGBCode = 0;
int LastCh;
int LatinBuffer[SZBuffer + 1];
int ChineseBuffer[SZBuffer + 1];
int TibetanInAWBuffer[SZBuffer + 1];
int FormatBuffer[SZBuffer + 1];
char GBCode[20];
int header = No;//Don't process control words in header
//--------------------------------------------------------------------------
#define MaxEncodingFontNumber 200 //The max number in all. TO BE ADJUSTED from time to time
//Source and target font info, set up when parsing fonttbl, used during
//parsing rtf file
int sourceFontIDs[MaxEncodingFontNumber+1] = {-1}; //set up when parsing fonttbl, used when parsing text
//int sourceFontNumber;
int TibetanFontIDs[MaxEncodingFontNumber+1] = {-1}; //201004
int nTibetanFontIDs = 0; //201004
int targetFontIDs[MaxEncodingFontNumber+1]; //set up when parsing fonttbl, used when translating
//int targetFontBaseIndex;
//int targetFontNumber;
int Western[101];//Western font IDs, special for ACIP and Wylie
int nWestern = 0;
int ChineseFontID[10];//Chinese font IDs, special for ACIP and Wylie
//---------------------------------------------------------------------------
//Omapping table
char *pTable; //The mapping table entry. ----global
int *pVowel; //The vowel table entry. ----global
int *pAW2Unicode; //The vowel table entry. ----global
char *pUnicodeToAW; //The Unicode to AW table entry. ----global
char *pTibetanSyllable; //Tibetan syllable table entry. ----global
char **pTSLookupTable; //For quick look up Tibetan syllable in the table pTibetanSyllable.
int TCRCvowelChart[300][6];//Combination chart for TCRC to pick up right vowels
int TCRCconstantChart[50][50][3];//Combination chart for TCRC to pick up right low level constant
//--------------------------DATA STRUCTURES-----------------------------------
//Data structures for lookup tables for converting from Unicode to
//others
typedef struct
{
int FileNumber;
char theChar;
}LEVEL;
typedef struct
{
char FzHg[3];
int FileNumber; //Correspounding file number
char theChar;
LEVEL level[5];
}NODEDATA; //Data that stored at B-tree node
typedef struct node
{
NODEDATA data;
struct node *NextNode[126]; //[126]; //Only concern Unicode rank: 0f40--0fbd
} BTREE; //The tree that stores mapping tables
BTREE *TableHead; //The root of the mapping table tree.
//The entry point of the table
BTREE *currentNode; //current working node
BTREE *AllocatedNodes[6000];//For freeing those allocated memory;
int nAllocatedNodes = 0;//Only for delocating purpose
NODEDATA otherCells[208]; //This is for hodling Unicode points that are not
// considered in the BTREE. u<0f40 && u>0fbd
//-----------------For web page----------------------------------------
char TagName[50];
char FontSize[30];
char FontName[100];
char RestFontInfo[200];
typedef struct // font info structure to be on stack
{
char tagName[50];
char fontSize[30];
char fontName[50];
int isTibetan;
} WebFONTINFO;
WebFONTINFO currentWebFontInfo;
WebFONTINFO deffWebFontInfo;
WebFONTINFO myWebFontInfoStack[MAXSTACKHEIGHT];
typedef struct // font info structure to be on stack
{
int ch;
char fontSize[30];
char fontName[50];
} WebTEXTWITHFONTNAME;
WebTEXTWITHFONTNAME TibetanBufferForWebPage[SZBuffer];
//-----------------------for HTML 3.20 over------------------------------
#define MAXATTRIBUTENUMBER 10
char AttributeName[MAXATTRIBUTENUMBER][50];
char AttributeContent[MAXATTRIBUTENUMBER][200];
int nAttributes = 0; //number of attributes in a tag;
//Current Tibetan Font Tag Attribute Names
char CurrentTibetanFontTagName[50];
char CurrentTibetanFontTagAttributeName[MAXATTRIBUTENUMBER][50];
char CurrentTibetanFontTagAttributeContent[MAXATTRIBUTENUMBER][200];
int nCurrentTibetanFontTagAttributes = 0;
int nStyleTags = 0;
char StyleTags[50][50];
int nClassNames = 0;
char ClassNames[50][50];
char ClassName[50];
char FontNameInStyles[50][50][30];//FontNameInStyles[TagName][ClassName][].
int WayToChangeFontAttribute = 0; //Remeber the way the tag changes the font attribute of text
//1---by <font ...>;
//2---by class or inline style --->Write back inline style
char lastClosingTag[50];//For buffering format
//--------------------------------------//GB2312---------------------------------------------
//Conversion table from CP936 or GB2312 to Unicode
unsigned short GB2Unicode[0xffff]; //CP936 to Unicode table
unsigned short Unicode2GB[0xffff]; //Unicode to CP936 table
int CP936GBTablesBuilt = No; //
//--------------------------End of Header-----------------------------------------------------
//////////////////////////////////////////////////////
// //
// All Routines //
// //
//////////////////////////////////////////////////////
//----------------------------Function declaration--------------------------------------------
int TranslateAndWriteBack(void);
int WriteBackFormat(void);
int axtoi(char *hexStg) {
int n = 0; // position in string
int m = 0; // position in digit[] to shift
int count; // loop index
int intValue = 0; // integer value of hex string
int digit[5]; // hold values to convert
while (n < 4) {
if (hexStg[n]=='\0')
break;
if (hexStg[n] > 0x29 && hexStg[n] < 0x40 ) //if 0 to 9
digit[n] = hexStg[n] & 0x0f; //convert to int
else if (hexStg[n] >='a' && hexStg[n] <= 'f') //if a to f
digit[n] = (hexStg[n] & 0x0f) + 9; //convert to int
else if (hexStg[n] >='A' && hexStg[n] <= 'F') //if A to F
digit[n] = (hexStg[n] & 0x0f) + 9; //convert to int