-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dict.pas
2363 lines (2223 loc) · 111 KB
/
Dict.pas
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
unit Dict;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, Clipbrd,
ComCtrls, StdCtrls, ExtCtrls, Registry, Math, Data, ImgList, Buttons, MyUtils,
CheckLst, Menus;
type
PLemma = ^TLemma;
PDictEntry = ^TDictEntry;
TLemma = record
Lang: Byte;
Entry: PDictEntry;
end;
TConnotStatus = (csUnused, csUsed, csIncluded, csWarning, csFixedWarning);
TConnot = record
Status: TConnotStatus;
Kind: string;
end;
TConnotArray = array of TConnot;
TDictEntry = record
Word, StressDia: ByteArray;
Ending, MorphBound: Word;
Gloss: string;
Confirmed: Boolean;
Connots: TConnotArray;
OldConnots: Word;
Ancestor: TLemma; {or 1st compound part, or stem of affixed word}
Ancestor2: PDictEntry;
VarCode: Byte;
Irregular: string;
Descendants: array of TLemma;
Mark: Byte;
end;
TDictForm = class(TForm)
ColourList: TImageList; PageControl: TPageControl; DictSheet: TTabSheet; OptionsSheet: TTabSheet;
UploadCheckBox: TCheckBox; Label32: TLabel; HostEdit: TEdit; Label33: TLabel;
UserEdit: TEdit; Label34: TLabel; PasswordEdit: TEdit; Label35: TLabel;
UploadPathEdit: TEdit; BackPanel: TPanel; Bevel3: TBevel; Label10: TLabel;
Label11: TLabel; CopyBtn: TSpeedButton; AncestorLabel: TLabel; CopyEtyBtn: TSpeedButton;
Label13: TLabel; Label14: TLabel; Label16: TLabel; Bevel4: TBevel;
ToMainBtn: TSpeedButton; DelBtn: TSpeedButton; WordPanel: TPanel; WordImage: TPaintBox;
GlossEdit: TEdit; ConfirmedBox: TCheckBox; AncestorPanel: TPanel; AncestorImage: TPaintBox;
DescendantsListBox: TListBox; SaveBtn: TBitBtn; ConnotListBox: TCheckListBox; Label7: TLabel;
IrregularCombo: TComboBox; IrregularLabel: TLabel; WordPopup: TPopupMenu; Deleteword1: TMenuItem;
Copywordtomainwindow1: TMenuItem; DescendantsPopup: TPopupMenu; Gotodescendant1: TMenuItem; ImageList: TImageList;
AncestorPopup: TPopupMenu; Gotoancestor1: TMenuItem; EditBtn: TSpeedButton; Editwordinmainwindow1: TMenuItem;
N1: TMenuItem; Panel1: TPanel; Label1: TLabel; LangTree: TTreeView;
WordListBox: TListBox; FindPanel: TPanel; Label5: TLabel; FindUp: TSpeedButton;
FindDown: TSpeedButton; FindClear: TSpeedButton; FindEdit: TEdit; WordListLabel: TLabel;
LangLabel: TStaticText; Splitter: TSplitter; Bevel1: TBevel; Label6: TLabel;
PathLabel: TLabel; Bevel2: TBevel; ConnotDelBtn: TSpeedButton; FilePanel: TPanel;
FileCombo: TComboBox; Label3: TLabel; ExpandDescBox: TCheckBox; Bevel6: TBevel;
VariantPaintBox: TPaintBox; Label8: TLabel; Copyword1: TMenuItem; CompoundBtn: TSpeedButton;
AffixBtn: TSpeedButton; Compoundword1: TMenuItem; Affixword1: TMenuItem; N2: TMenuItem;
AffixPopup: TPopupMenu; DictVerLabel: TLabel; Switchancestor1: TMenuItem; Noapplicableaffixes1: TMenuItem;
ContaminationBtn: TSpeedButton; Contaminateword1: TMenuItem; N3: TMenuItem; InternalSort: TMenuItem;
DuplicateBtn: TSpeedButton; Duplicateword1: TMenuItem; Image2: TImage; Bevel5: TBevel;
Image4: TImage; Noapplicableaffixes2: TMenuItem; Bevel7: TBevel; CheckDescBtn: TBitBtn;
CheckListBox: TListBox; Label9: TLabel; GlossSort: TMenuItem; FindOpts: TSpeedButton;
FindPopup: TPopupMenu; FindType1: TMenuItem; FindType2: TMenuItem; FindType3: TMenuItem;
FindType8: TMenuItem; FindType0: TMenuItem; N4: TMenuItem; FindNoDescs: TMenuItem;
FindType4: TMenuItem; UploadLabel: TStaticText; CopyEtyOutlineBtn: TSpeedButton; StatusShape: TShape;
Label2: TLabel; Image3: TImage; CheckConnotsBtn: TBitBtn; FindType5: TMenuItem;
Aux: TLabel; FindType7: TMenuItem; Gotoultimateancestor1: TMenuItem; N5: TMenuItem;
CompoundPopup: TPopupMenu; Compound1: TMenuItem; Tatpurusha1: TMenuItem; Bahuvrihi1: TMenuItem;
Appositional1: TMenuItem; Clarifying1: TMenuItem; N6: TMenuItem; N7: TMenuItem;
Caland1: TMenuItem; FindShape: TShape; CopyEngBtn: TSpeedButton; CognatesBtn: TSpeedButton;
CognatesPopup: TPopupMenu; AddCognate1: TMenuItem; N8: TMenuItem; EditCognate1: TMenuItem;
ConnotLabel: TLabel; ToMainBtn2: TSpeedButton; EditBtn2: TSpeedButton; Copywordtomainwindow2: TMenuItem;
Editwordinmainwindow2: TMenuItem; N9: TMenuItem; ShowConsoleBox: TCheckBox; ConnotPopup: TPopupMenu;
Copyconnotations1: TMenuItem; Gotoorigin1: TMenuItem; N10: TMenuItem; Bookmark1: TMenuItem;
N11: TMenuItem; Bookmarks: TMenuItem; Bookmark2: TMenuItem; Bookmark3: TMenuItem;
Bookmark4: TMenuItem; Bookmark5: TMenuItem; Bookmark6: TMenuItem; CopyConnotBtn: TSpeedButton;
TreeSheet: TTabSheet; SemTreePanel: TPanel; Label4: TLabel; SemanticTree: TTreeView;
TreeSplitter: TSplitter; Panel3: TPanel; SemDelBtn: TSpeedButton; SemTreeBtn: TSpeedButton;
Bevel8: TBevel; SemAddEmptyBtn: TSpeedButton; Addtotree1: TMenuItem; N12: TMenuItem;
SemChangeBtn: TSpeedButton; Bevel9: TBevel; SemDownBtn: TSpeedButton; SemUpBtn: TSpeedButton;
SemMoveBtn: TSpeedButton; Label12: TLabel; SemTopmostEdit: TEdit; SemAddMemo: TMemo;
Label15: TLabel; SemTreeLabel: TLabel; SemanticPopup: TPopupMenu; Addchildnodewithoutaword1: TMenuItem;
Deletenode1: TMenuItem; Changenode1: TMenuItem; N13: TMenuItem; Movedown1: TMenuItem;
Moveup1: TMenuItem; Movetodifferentparentnode1: TMenuItem; SemSortBtn: TSpeedButton; Sortchildrenalphabetically1: TMenuItem;
FindType6: TMenuItem;
procedure LangTreeChanging(Sender: TObject; Node: TTreeNode; var AllowChange: Boolean);
procedure LangTreeChange(Sender: TObject; Node: TTreeNode);
procedure AncestorImageDblClick(Sender: TObject);
procedure DescendantsListBoxDblClick(Sender: TObject);
procedure WordListBoxClick(Sender: TObject);
procedure ListBoxDrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState);
procedure ImagePaint(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure DelBtnClick(Sender: TObject);
procedure CopyBtnClick(Sender: TObject);
procedure CopyEtyBtnClick(Sender: TObject);
procedure GlossEditChange(Sender: TObject);
procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure ConfirmedBoxClick(Sender: TObject);
procedure ToMainBtnClick(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure SaveBtnClick(Sender: TObject);
procedure FormResize(Sender: TObject);
procedure FindClearClick(Sender: TObject);
procedure FindEditKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure FindEditChange(Sender: TObject);
procedure ConnotListBoxClickCheck(Sender: TObject);
procedure IrregularComboChange(Sender: TObject);
procedure PopupPopup(Sender: TObject);
procedure SplitterMoved(Sender: TObject);
procedure PageControlChange(Sender: TObject);
procedure ConnotDelBtnClick(Sender: TObject);
procedure ConnotListBoxClick(Sender: TObject);
procedure FileComboDropDown(Sender: TObject);
procedure FileComboExit(Sender: TObject);
procedure FileComboKeyPress(Sender: TObject; var Key: Char);
procedure ExpandDescBoxClick(Sender: TObject);
procedure VariantPaintBoxPaint(Sender: TObject);
procedure AffixBtnClick(Sender: TObject);
procedure CompoundBtnClick(Sender: TObject);
procedure AffixPopupPopup(Sender: TObject);
procedure AncestorImageClick(Sender: TObject);
procedure ContaminationBtnClick(Sender: TObject);
procedure SortClick(Sender: TObject);
procedure DuplicateBtnClick(Sender: TObject);
procedure CheckBtnClick(Sender: TObject);
procedure CheckListBoxDrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState);
procedure CheckListBoxDblClick(Sender: TObject);
procedure FindOptsClick(Sender: TObject);
procedure FindTypeClick(Sender: TObject);
procedure FindNoDescsClick(Sender: TObject);
procedure UploadLabelClick(Sender: TObject);
procedure FormHide(Sender: TObject);
procedure ConnotListBoxDrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState);
procedure Gotoultimateancestor1Click(Sender: TObject);
procedure CompoundClick(Sender: TObject);
procedure CompoundPopupPopup(Sender: TObject);
procedure CopyEngBtnClick(Sender: TObject);
procedure CognatesBtnClick(Sender: TObject);
procedure ConnotListBoxDblClick(Sender: TObject);
procedure FindShapeMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
procedure AddCognate1Click(Sender: TObject);
procedure WordListBoxMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
procedure EditCognate1Click(Sender: TObject);
procedure Copyconnotations1Click(Sender: TObject);
procedure ConnotPopupPopup(Sender: TObject);
procedure BookmarkClick(Sender: TObject);
procedure CopyConnotBtnClick(Sender: TObject);
procedure SemTreeBtnClick(Sender: TObject);
procedure SemDelBtnClick(Sender: TObject);
procedure SemanticTreeChange(Sender: TObject; Node: TTreeNode);
procedure SemAddEmptyBtnClick(Sender: TObject);
procedure SemChangeBtnClick(Sender: TObject);
procedure SemMoveBtnClick(Sender: TObject);
procedure SemDownBtnClick(Sender: TObject);
procedure SemanticTreeCustomDrawItem(Sender: TCustomTreeView; Node: TTreeNode; State: TCustomDrawState; var DefaultDraw: Boolean);
procedure SemTreePanelResize(Sender: TObject);
procedure SemanticPopupPopup(Sender: TObject);
procedure SemUpBtnClick(Sender: TObject);
procedure SemSortBtnClick(Sender: TObject);
private
HDict: THandle; {File handle}
Dicts: array[0..High(LangNs)] of TList;
BackupStr, DictFile: string;
SortInternal: Boolean;
SortLang: Integer;
SortCharsRev: array[0..High(LangNs), 0..43] of Byte;
EditBtnNotes: array[False..True] of Byte;
procedure LoadDict;
procedure CloseDict;
function MakePHP: string;
procedure AffixClick(Sender: TObject);
procedure AffixDrawItem(Sender: TObject; ACanvas: TCanvas; ARect: TRect; Selected: Boolean);
procedure CognatesClick(Sender: TObject);
function PartOfSpeech: string;
procedure GotoEntry(Lang: Integer; Entry: PDictEntry);
function PThisEntry: PDictEntry;
function ThisLang: Integer;
function PrepareWord(Control: TControl; Index: Integer; Right: Boolean; var Lemma: TLemma): Boolean;
procedure SetEditBtn(Btn: TSpeedButton; Entry: PDictEntry; Lang: Byte);
procedure FillMainWord(i, Lang: Integer; Entry: PDictEntry);
procedure UpdateConnot(Index: Integer);
procedure UpdateWordListLabel;
procedure AddWord(AWord, AStressDia: ByteArray; AEnding, AMorphBound: Integer; AGloss: string; AConnots: TConnotArray; AVarCode: Byte; AAnc1, AAnc2: PDictEntry);
procedure AddDescendant(ELang, DLang: Integer; AEntry, ADescendant: PDictEntry; FirstDesc: Boolean);
procedure PropagateConnots(Entry1, Entry2: PDictEntry; AConnots: TStrings);
function WideWordListBox: Boolean;
procedure DictSort(Lang: Integer);
procedure CheckListBoxClear;
function ConnotIsFrom(Index: Integer): TLemma;
procedure PlaceCognatesMenuItem(Index: Integer);
function WordInTree(E: PDictEntry): Integer;
procedure UpdateSemTreeBtn;
procedure DisconnectSemNode(Node: TTreeNode);
public
procedure AppHint(var HintStr: string; var HintInfo: THintInfo);
function SaveDict(WantClose: Boolean): Boolean;
procedure AddWords(Lang1, Lang2: Integer; Word1, Word2, StressDia1, StressDia2: ByteArray; Ending1, Ending2, MorphBound1, MorphBound2: Word;
Gloss: string; Connots: TStrings; VarCode: Byte; var Entry1, Entry2: PDictEntry; const AnotherDesc: Boolean);
function ChangeWords(Entry1, Entry2: PDictEntry; Word1, Word2, StressDia1, StressDia2: ByteArray; Ending1, Ending2, MorphBound1: Word;
Connots: TStrings; VarCode2: Byte): Boolean;
function AskDictSave: Integer;
function ValidFileHandle: Boolean;
function Changed: Boolean;
end;
var
DictForm: TDictForm;
implementation
uses MainForm, Cases, Cognates;
{$R *.DFM}
const
UndefIrreg = 'yes';
csString: array[Low(TConnotStatus)..High(TConnotStatus)] of string = ('unused', 'used', 'included in lemma', 'open warning', 'fixed warning');
EditBtnNoteStrings: array[1..3] of string = ('Word has more than one descendant.', 'Descendant has descendants of its own.', 'Descendant is a derivation in the same language.');
function DictGlossCompare(Item1, Item2: Pointer): Integer;
begin
Result:=AnsiCompareStr(GlossBrackets(PDictEntry(Item1).Gloss, False), GlossBrackets(PDictEntry(Item2).Gloss, False));
end; {DictGlossCompare}
function DictEntryCompare(Item1, Item2: Pointer): Integer;
var i, w1, w2: Integer;
begin
i:=0;
while (PDictEntry(Item1).Word[i]=PDictEntry(Item2).Word[i]) and (i<Length(PDictEntry(Item1).Word)-1) and (i<Length(PDictEntry(Item2).Word)-1) do Inc(i);
with DictForm do if SortInternal then begin
w1:=PDictEntry(Item1).Word[i];
w2:=PDictEntry(Item2).Word[i];
end else begin
w1:=SortCharsRev[SortLang, PDictEntry(Item1).Word[i]];
w2:=SortCharsRev[SortLang, PDictEntry(Item2).Word[i]];
end;
if w1<w2 then Result:=-1 else
if w1>w2 then Result:=1 else
if Length(PDictEntry(Item1).Word)<Length(PDictEntry(Item2).Word) then Result:=-1 else
if Length(PDictEntry(Item1).Word)>Length(PDictEntry(Item2).Word) then Result:=1 else Result:=0;
if Result=0 then begin
i:=0;
while (PDictEntry(Item1).StressDia[i]=PDictEntry(Item2).StressDia[i]) and (i<Length(PDictEntry(Item1).StressDia)-1) and (i<Length(PDictEntry(Item2).StressDia)-1) do Inc(i);
if PDictEntry(Item1).StressDia[i]<PDictEntry(Item2).StressDia[i] then Result:=-1 else
if PDictEntry(Item1).StressDia[i]>PDictEntry(Item2).StressDia[i] then Result:=1 else Result:=0;
end;
if Result=0 then Result:=PDictEntry(Item1).Ending-PDictEntry(Item2).Ending;
if Result=0 then Result:=PDictEntry(Item1).MorphBound-PDictEntry(Item2).MorphBound;
end; {DictEntryCompare}
function LemmaCompare(Item1, Item2: TLemma): Integer;
begin
Result:=Item1.Lang-Item2.Lang;
if Result=0 then begin
DictForm.SortInternal:=False;
DictForm.SortLang:=Item1.Lang;
Result:=DictEntryCompare(Item1.Entry, Item2.Entry);
end;
end; {LemmaCompare}
function Variant(AncLang, Lang: Integer; Entry: PDictEntry; ForCopy: Boolean): string;
var id: Integer;
begin
Result:='';
with Entry^ do if VarCode<$F0 then begin
if AncLang=Lang then begin
if Ancestor2<>nil then id:=4900 else if VarCode<$80 then id:=5000+100*Lang else id:=30-$80-$40*Ord(VarCode>=$C0); {PIE participle}
end else if (AncLang=lOLem) and (Lang in [lVolg, lEHell, lPrWald]) then id:=70 else if AncLang=lPIE then id:=30 else if (AncLang=lOLem) and (Lang=lMLem) then id:=20 else if Lang=lModLem then id:=10 else id:=0;
if id<>0 then Result:=Copy(LoadStr(id+VarCode), 3, MaxInt);
if (id+VarCode=41) and (Lang=lPrLem) then Result:=Copy(Result, 1, 6)+Copy(Result, 8, MaxInt); {sk(é)-present}
end else if VarCode=$F1 then begin
if AncLang=lPIE then id:=IfThen((Lang=lPrLem) and (Entry.Ancestor.Entry.Ending=System.Word(-1)), 6, 1) else if (AncLang=lPrLem) and (Lang=lOLem) then id:=2
else if (AncLang=lOLem) and (Lang=lMLem) then id:=9 else if (AncLang=lBesk) and (Lang=lNLem) then id:=5 else if (AncLang=lPrWald) and (Lang=lEth) then id:=11 else if AncLang=lEHell then id:=3 else
if (AncLang=lKoi) and (Lang in [lLMLem, lNLem, lModLem]) then id:=0 else // see Greek.pas > KoineToLem; too much trouble to implement here
if Lang=lBesk then id:=4 else id:=0;
if id>0 then Result:=CheckBoxCaptions[id];
end;
if (Result='') and (AncLang<$FF) and (Lang in LLoans[AncLang]) then Result:='academic loan';
Result:=Trim(RemoveFrom(IfThen(ForCopy, '[')+'{', Result));
with Entry^ do if Result<>'' then Result:=Result+IfThen(VarCode in [$80..$EF], IfThen(VarCode<>$80+24, ' '+IfThen(VarCode<$C0, 'active', 'mediopassive'))+' participle');
if ForCopy then Result:=StringReplace(StringReplace(Result, '¶', '<span class="etyco">', []), '¶', '</span>', [])
else Result:=StringReplace(Result, '¶', '', [rfReplaceAll]);
end; {Variant}
{----------------------------------------------------------Dictionary---------------------------------------------------------------------}
procedure TDictForm.FormCreate(Sender: TObject);
begin
HDict:=Invalid_Handle_Value;
PageControl.ActivePage:=DictSheet;
with ContaminationBtn do Hint:=Hint+#13#10'often in compact series or for antonyms';
end; {FormCreate}
const MaxFindType = 8;
procedure TDictForm.FormShow(Sender: TObject);
var i, j: Integer;
sl: TStringList;
begin
if ColourList.Count=0 then with TRegIniFile.Create(Reg+'\Dict') do begin
for i:=0 to High(LangNs) do for j:=0 to High(SortChars[0]) do if SortChars[i,j]<255 then SortCharsRev[i,SortChars[i,j]]:=j;
Gotodescendant1.Caption:=Gotodescendant1.Caption+#9#9'Double click';
Gotoancestor1.Caption:=Gotoancestor1.Caption+#9#9'Double click';
Switchancestor1.Caption:=Switchancestor1.Caption+#9#9#9'Click';
Gotoorigin1.Caption:=Gotoorigin1.Caption+#9'Double click';
GlossEdit.Hint:='( ) = quoted remark'#13#10'[ ] = unquoted'#13#10'{ } = hidden'#13#10', = additional (informal) glosses'#13#10'lit., [tr.], [intr.]';
for i:=0 to CompoundPopup.Items.Count-1 do with CompoundPopup.Items[i] do AddMenuItem(self, Caption, Tag, OnClick, Compoundword1);
LangTree.Items.Assign(Neogrammarian.SourceTree.Items);
LangTree.FullExpand;
ColourList.Assign(Neogrammarian.ColourList);
for i:=0 to High(LangNs) do Dicts[i]:=TList.Create;
LangTree.Selected:=LangTree.Items[1];
PathLabel.Caption:=ExtractFilePath(Application.ExeName);
DictFile:=ReadString('', '', 'Dict');
FileCombo.Text:=DictFile;
WindowState:=TWindowState(ReadInteger('', 'WinState', Ord(wsNormal)));
Left:=ReadInteger('', 'WinLeft', 100);
Top:=ReadInteger('', 'WinTop', 100);
Width:=ReadInteger('', 'WinWidth', Width);
Height:=ReadInteger('', 'WinHeight', Height);
Panel1.Width:=ReadInteger('', 'WinSplit', Panel1.Width);
FindEdit.Text:=ReadString('', 'FindString', '');
TMenuItem(FindComponent('FindType'+IntToStr(Min(Max(ReadInteger('', 'FindType', 0), 0), MaxFindType)))).Checked:=True;
FindNoDescs.Checked:=ReadBool('', 'FindNoDescs', False);
FindEditChange(FindEdit);
SemTreePanel.Width:=ReadInteger('', 'WinTreeSplit', SemTreePanel.Width);
UploadCheckBox.Checked:=ReadBool('', 'Upload', False);
HostEdit.Text:=ReadString('', 'UploadHost', '');
UserEdit.Text:=ReadString('', 'UploadUser', '');
PasswordEdit.Text:=DecryptPwd(ReadString('', 'UploadPwd', ''), 34960119);
UploadPathEdit.Text:=ReadString('', 'UploadPath', '');
ShowConsoleBox.Checked:=ReadBool('', 'UploadShow', False);
sl:=TStringList.Create;
ReadSection('Cognates', sl);
sl.Sort;
for i:=0 to sl.Count-1 do AddMenuItem(self, sl[i], 0, CognatesClick, CognatesPopup.Items).Hint:=ReadString('Cognates', sl[i], '');
sl.Free;
LoadDict;
Free;
end;
if PageControl.ActivePage=DictSheet then FocusControl(WordListBox);
WordListBoxClick(nil);
end; {FormShow}
procedure TDictForm.FormHide(Sender: TObject);
begin
if ActiveControl=FileCombo then FileComboExit(Sender);
end; {FormHide}
procedure TDictForm.FormDestroy(Sender: TObject);
var i: Integer;
begin
if ColourList.Count>0 then begin
with TRegIniFile.Create(Reg+'\Dict') do begin
WriteString('', '', DictFile);
WriteInteger('', 'WinState', Ord(WindowState));
WriteInteger('', 'WinLeft', Left);
WriteInteger('', 'WinTop', Top);
WriteInteger('', 'WinWidth', Width);
WriteInteger('', 'WinHeight', Height);
WriteInteger('', 'WinSplit', Panel1.Width);
WriteString('', 'FindString', FindEdit.Text);
for i:=0 to MaxFindType do if TMenuItem(FindComponent('FindType'+IntToStr(i))).Checked then WriteInteger('', 'FindType', i);
WriteBool('', 'FindNoDescs', FindNoDescs.Checked);
WriteInteger('', 'WinTreeSplit', SemTreePanel.Width);
WriteBool('', 'Upload', UploadCheckBox.Checked);
WriteString('', 'UploadHost', HostEdit.Text);
WriteString('', 'UploadUser', UserEdit.Text);
WriteString('', 'UploadPwd', EncryptPwd(PasswordEdit.Text, 34960119));
WriteString('', 'UploadPath', UploadPathEdit.Text);
WriteBool('', 'UploadShow', ShowConsoleBox.Checked);
EraseSection('Cognates');
with CognatesPopup do for i:=3 to Items.Count-1 do WriteString('Cognates', Items[i].Caption, Items[i].Hint);
Free;
end;
CloseDict;
for i:=0 to High(Dicts) do Dicts[i].Free;
end;
end; {FormDestroy}
procedure TDictForm.FormResize(Sender: TObject);
begin
DescendantsListBox.Repaint;
FilePanel.Left:=Min(PathLabel.Left+PathLabel.Width+2, PageControl.Width-FilePanel.Width);
end; {FormResize}
procedure TDictForm.AppHint(var HintStr: string; var HintInfo: THintInfo);
var i, j, m, w: Integer;
c: TConnotStatus;
cs: array[Low(TConnotStatus)..High(TConnotStatus)] of Integer;
lem: TLemma;
n: TTreeNode;
begin
with HintInfo do if HintControl=SaveBtn then begin
if Changed then HintStr:='Save dictionary (Ctrl+S)' else HintStr:='Nothing needs to be saved.';
end else if HintControl=ConnotLabel then begin
for c:=Low(cs) to High(cs) do cs[c]:=0;
m:=0; w:=0;
for i:=0 to Dicts[ThisLang].Count-1 do for j:=0 to Length(PDictEntry(Dicts[ThisLang][i])^.Connots)-1 do begin
c:=PDictEntry(Dicts[ThisLang][i])^.Connots[j].Status;
Inc(cs[c]);
if c in [csUnused, csUsed, csIncluded] then Inc(m) else Inc(w);
end;
HintStr:=IntToStr(m)+' connotation'+IfThen(m<>1, 's')+' in '+LongLangNs[ThisLang]+IfThen(m>0, ':');
if m>0 then for c:=csUnused to csIncluded do HintStr:=HintStr+#13#10+IntToStr(cs[c])+' ('+IntToStr(Round(cs[c]/m*100))+'%) '+csString[c];
HintStr:=HintStr+#13#10#13#10+IntToStr(w)+' warning'+IfThen(w<>1, 's')+IfThen(w>0, ':');
if w>0 then for c:=csWarning to csFixedWarning do HintStr:=HintStr+#13#10+IntToStr(cs[c])+' ('+IntToStr(Round(cs[c]/w*100))+'%) '+csString[c]+IfThen(cs[c]<>1, 's');
end else if (HintControl=ConnotListBox) or (HintControl=WordListBox) or (HintControl=DescendantsListBox) or (HintControl=CheckListBox) then with TListBox(HintControl) do begin
m:=ItemAtPos(CursorPos, True);
CursorRect:=ItemRect(m);
if ((HintControl=WordListBox) and WideWordListBox) or (HintControl=CheckListBox) then
if CursorPos.X<Width div 2 then CursorRect.Right:=Width div 2 else CursorRect.Left:=Width div 2 +1;
if m>-1 then
if HintControl=ConnotListBox then begin
with PThisEntry.Connots[m] do HintStr:=Kind+#13#10' '+IfThen(m>=PThisEntry.OldConnots, 'new in ', 'since ')+LongLangNs[ConnotIsFrom(m).Lang]+#13#10' '+csString[Status];
end else
if PrepareWord(HintControl, m, CursorPos.X>=Width div 2, lem) and ((HintControl<>WordListBox) or not WideWordListBox or (CursorPos.X<Width div 2)) then
HintStr:=Neogrammarian.DrawWord(3, Aux.Canvas, Rect(0, 0, 0, 0), False, False, 0)
else if HintControl=WordListBox then HintStr:=lem.Entry.Gloss;
end else if HintControl=SemanticTree then begin
n:=SemanticTree.GetNodeAt(CursorPos.X, CursorPos.Y);
if n<>nil then begin
CursorRect:=n.DisplayRect(False);
if n.Data<>nil then begin
FillMainWord(3, lModLem, PDictEntry(n.Data));
HintStr:=Neogrammarian.DrawWord(3, Aux.Canvas, Rect(0, 0, 0, 0), False, False, 0)+' '+PDictEntry(n.Data)^.Gloss+'';
end else HintStr:=n.Text;
end;
end;
end; {AppHint}
procedure TDictForm.LoadDict;
var i, j, k, l, n, wi: Integer;
e: PDictEntry;
r: DWord;
b: Byte;
st, ver: string;
lach: array[0..255] of Integer;
function ReadString: string;
var k: Integer;
ach: array[0..255] of Byte;
begin
ReadFile(HDict, k, 4, r, nil);
ReadFile(HDict, ach, k, r, nil);
ach[r]:=0;
Result:=PChar(@ach);
end;
procedure FillConnots(e: PDictEntry);
var k, l: Integer;
begin
for k:=0 to Length(e.Descendants)-1 do with e.Descendants[k] do if (Entry.Ancestor.Entry=e) then begin
for l:=0 to Entry.OldConnots-1 do if Entry.Connots[l].Kind='' then Entry.Connots[l].Kind:=e.Connots[l].Kind;
FillConnots(Entry);
end;
end;
begin
CopyFile(PChar(PathLabel.Caption+DictFile+'.ngr'), PChar(PathLabel.Caption+DictFile+'.bak'), False);
HDict:=CreateFile(PChar(PathLabel.Caption+DictFile+'.ngr'), Generic_Read or Generic_Write, File_Share_Read, nil, Open_Always, File_Attribute_Normal, 0);
if HDict<>Invalid_Handle_Value then begin
st:=ReadString;
ver:=Copy(st, 4, 1);
st:=Copy(st, 5, MaxInt);
for i:=0 to LangTree.Items.Count-1 do if (LangTree.Items[i].Level=1) and (LangNs[Integer(LangTree.Items[i].Data)]=st) then
LangTree.Selected:=LangTree.Items[i];
ReadFile(HDict, wi, 4, r, nil);
ReadFile(HDict, n, 4, r, nil);
if r=0 then n:=0;
ReadFile(HDict, lach, 4*n, r, nil);
for i:=0 to Min(n-1, High(Dicts)) do Dicts[i].Capacity:=lach[i];
for i:=0 to Min(n-1, High(Dicts)) do for j:=0 to lach[i]-1 do begin
New(e);
ReadFile(HDict, l, 4, r, nil);
SetLength(e.Word, l);
SetLength(e.StressDia, l);
for k:=0 to l-1 do
ReadFile(HDict, e.Word[k], 1, r, nil);
for k:=0 to l-1 do
ReadFile(HDict, e.StressDia[k], 1, r, nil);
ReadFile(HDict, e.Ending, 2, r, nil);
if ver>='#' then
ReadFile(HDict, e.MorphBound, 2, r, nil) else e.MorphBound:=Word(-1);
e.Gloss:=ReadString;
ReadFile(HDict, e.Confirmed, 1, r, nil);
ReadFile(HDict, k, 4, r, nil);
SetLength(e.Connots, k);
for k:=0 to Length(e.Connots)-1 do with e.Connots[k] do begin
ReadFile(HDict, Status, 1, r, nil);
if ver='$' then begin
ReadFile(HDict, b, 1, r, nil);
if b=3 then Status:=csIncluded;
end;
Kind:=ReadString;
end;
ReadFile(HDict, e.Ancestor.Lang, 1, r, nil);
if (ver<='"') or (e.Ancestor.Lang<255) then
ReadFile(HDict, e.Ancestor.Entry, 4, r, nil);
if (ver='"') or (ver>='#') and (e.Ancestor.Lang=i) then
ReadFile(HDict, e.Ancestor2, 4, r, nil);
if ver>='!' then
ReadFile(HDict, e.VarCode, 1, r, nil) else e.VarCode:=$FF;
e.Irregular:=ReadString;
ReadFile(HDict, k, 4, r, nil);
SetLength(e.Descendants, k);
for k:=0 to Length(e.Descendants)-1 do with e.Descendants[k] do begin
ReadFile(HDict, Lang, 1, r, nil);
ReadFile(HDict, Entry, 4, r, nil);
end;
if ver>='&' then
ReadFile(HDict, e.Mark, 1, r, nil);
Dicts[i].Add(e)
end;
if ver>='#' then begin
ReadFile(HDict, b, 1, r, nil);
InternalSort.Checked:=Odd(b);
GlossSort.Checked:=b>=2;
ReadFile(HDict, b, 1, r, nil);
ExpandDescBox.Checked:=Odd(b);
end;
if ver>='''' then begin
ReadFile(HDict, l, 4, r, nil);
with SemanticTree do for i:=0 to l-1 do begin
ReadFile(HDict, k, 4, r, nil);
ReadFile(HDict, b, 1, r, nil);
if b=0 then begin
e:=nil;
st:=ReadString;
end else begin
ReadFile(HDict, l, 4, r, nil);
e:=Dicts[lModLem][l];
st:='';
end;
if k=-1 then with Items[0] do begin
Text:=st; Data:=e;
end else Items.AddChildObject(Items[k], st, e);
end;
SemanticTree.Items[0].Expand(False);
end;
if (r<1) and (ver<>'') then TangoMessageBox('Dictionary wasnt loaded completely.', mtWarning, [mbOK], '');
for i:=0 to Min(n-1, High(Dicts)) do for j:=0 to Dicts[i].Count-1 do with PDictEntry(Dicts[i][j])^ do begin
if (Ancestor.Lang<255) and (Integer(Ancestor.Entry)>-1) and (Dicts[Ancestor.Lang].Count>Integer(Ancestor.Entry)) then begin
Ancestor.Entry:=Dicts[Ancestor.Lang][Integer(Ancestor.Entry)];
OldConnots:=Min(Length(Ancestor.Entry.Connots), Length(Connots));
end;
if Ancestor.Lang=i then
if Integer(Ancestor2)=-1 then Ancestor2:=nil else Ancestor2:=Dicts[i][Integer(Ancestor2)];
for k:=0 to Length(Descendants)-1 do if (Descendants[k].Lang<255) then
if (Integer(Descendants[k].Entry)>-1) and (Dicts[Descendants[k].Lang].Count>Integer(Descendants[k].Entry)) then
Descendants[k].Entry:=Dicts[Descendants[k].Lang][Integer(Descendants[k].Entry)] else begin
for l:=k+1 to Length(Descendants)-1 do Descendants[l-1]:=Descendants[l];
SetLength(Descendants, Length(Descendants)-1);
end;
end;
for i:=0 to Min(n-1, High(Dicts)) do for j:=0 to Dicts[i].Count-1 do FillConnots(PDictEntry(Dicts[i][j]));
if ver='' then i:=-1 else i:=Ord(ver[1])-32;
DictVerLabel.Caption:='(a version '+IntToStr(i)+' file)';
Caption:=DictFile+'.ngr - Dictionary';
UploadLabel.Caption:=LowerCase(DictFile)+'.ngr and '+LowerCase(DictFile)+'.php';
BackupStr:=MakePHP;
LangTreeChange(nil, nil);
WordListBox.ItemIndex:=wi;
WordListBoxClick(nil);
end else begin
TangoMessageBox('Error opening dictionary.', mtError, [mbOK], '');
BackupStr:=MakePHP;
PageControl.ActivePage:=OptionsSheet;
PageControlChange(nil);
FileCombo.SetFocus;
end;
end; {LoadDict}
function TDictForm.SaveDict(WantClose: Boolean): Boolean;
var i, j, k, l, p: Integer;
w: DWord;
b: Byte;
lach: array[0..255] of Integer;
fname: string;
t: TDateTime;
sl: TStringList;
procedure WriteString(S: string);
var l: Integer;
ach: array[0..255] of Byte;
begin
l:=Length(S);
WriteFile(HDict, l, 4, w, nil);
StrPCopy(PChar(@ach), S);
WriteFile(HDict, ach, Length(S), w, nil);
end;
begin
Result:=HDict<>Invalid_Handle_Value;
if Result and (not WantClose or Changed) then begin
SetFilePointer(HDict, 0, nil, File_Begin);
SetEndOfFile(HDict);
WriteString('NGR'''+LangNs[ThisLang]);
i:=WordListBox.ItemIndex;
WriteFile(HDict, i, 4, w, nil);
lach[0]:=Length(Dicts);
for i:=0 to lach[0]-1 do lach[i+1]:=Dicts[i].Count;
WriteFile(HDict, lach, 4*(lach[0]+1), w, nil);
for i:=0 to Length(Dicts)-1 do for j:=0 to Dicts[i].Count-1 do with PDictEntry(Dicts[i][j])^ do begin
l:=Length(Word);
WriteFile(HDict, l, 4, w, nil);
for k:=0 to l-1 do
WriteFile(HDict, Word[k], 1, w, nil);
for k:=0 to l-1 do
WriteFile(HDict, StressDia[k], 1, w, nil);
WriteFile(HDict, Ending, 2, w, nil);
WriteFile(HDict, MorphBound, 2, w, nil);
WriteString(Gloss);
WriteFile(HDict, Confirmed, 1, w, nil);
k:=Length(Connots);
WriteFile(HDict, k, 4, w, nil);
for k:=0 to Length(Connots)-1 do with Connots[k] do begin
WriteFile(HDict, Status, 1, w, nil);
WriteString(IfThen(k>=OldConnots, Kind));
end;
WriteFile(HDict, Ancestor.Lang, 1, w, nil);
if Ancestor.Lang<255 then begin
p:=Dicts[Ancestor.Lang].IndexOf(Ancestor.Entry);
WriteFile(HDict, p, 4, w, nil);
end;
if Ancestor.Lang=i then begin
p:=Dicts[i].IndexOf(Ancestor2);
WriteFile(HDict, p, 4, w, nil);
end;
WriteFile(HDict, VarCode, 1, w, nil);
WriteString(Irregular);
k:=Length(Descendants);
WriteFile(HDict, k, 4, w, nil);
for k:=0 to Length(Descendants)-1 do begin
WriteFile(HDict, Descendants[k].Lang, 1, w, nil);
if Descendants[k].Lang<255 then p:=Dicts[Descendants[k].Lang].IndexOf(Descendants[k].Entry) else p:=-1;
WriteFile(HDict, p, 4, w, nil);
end;
WriteFile(HDict, Mark, 1, w, nil);
end;
b:=Ord(InternalSort.Checked)+2*Ord(GlossSort.Checked);
WriteFile(HDict, b, 1, w, nil);
b:=Ord(ExpandDescBox.Checked);
WriteFile(HDict, b, 1, w, nil);
l:=SemanticTree.Items.Count; {Semantic tree}
WriteFile(HDict, l, 4, w, nil);
for i:=0 to SemanticTree.Items.Count-1 do with SemanticTree.Items[i] do begin
if Parent<>nil then l:=Parent.AbsoluteIndex else l:=-1;
WriteFile(HDict, l, 4, w, nil);
b:=Ord(Data<>nil);
WriteFile(HDict, b, 1, w, nil);
if Data<>nil then begin
l:=Dicts[lModLem].IndexOf(Data);
WriteFile(HDict, l, 4, w, nil);
end else WriteString(Text);
end;
Result:=w>=1;
BackupStr:=MakePHP;
if UploadCheckBox.Checked then begin
sl:=TStringList.Create;
SetCurrentDir(PathLabel.Caption);
sl.Add('ftp -s:upload.bat');
sl.Add('goto done');
sl.Add('open "'+HostEdit.Text+'"');
sl.Add(UserEdit.Text);
sl.Add(PasswordEdit.Text);
fname:=StringReplace(UploadPathEdit.Text, '/', '\', [rfReplaceAll]);
fname:=fname+IfThen(Copy(fname, Length(fname), 1)<>'\', '\')+DictFile+'.';
repeat
j:=Pos('\', fname);
if j>0 then begin
sl.Add('cd "'+Copy(fname, 1, j-1)+'"');
fname:=Copy(fname, j+1, 20000);
end;
until j=0;
sl.Add('ascii');
sl.Add('put "'+PathLabel.Caption+fname+'php" "'+LowerCase(fname)+'php"');
sl.Add('bin');
sl.Add('put "'+PathLabel.Caption+fname+'ngr" "'+LowerCase(fname)+'ngr"');
sl.Add('bye');
sl.Add(':done');
sl.Add('del upload.bat');
t:=Now;
repeat i:=FileCreate('upload.bat') until (i>-1) or (Now>t+0.001);
FileClose(i);
try sl.SaveToFile('upload.bat') except end;
sl.Text:=BackupStr;
try sl.SaveToFile(PathLabel.Caption+ExtractFileName(fname)+'php') except end;
sl.Free;
WinExec('upload.bat', Ord(ShowConsoleBox.Checked));
end;
end;
if not Result then
if WantClose then Result:=TangoMessageBox('Error saving dictionary. Close anyway?', mtError, [mbYes, mbNo], '')=idYes
else TangoMessageBox('Error saving dictionary.', mtError, [mbOK], '');
end; {SaveDict}
function TDictForm.MakePHP: string;
const identifiers: array[0..12] of string = ('word', 'gloss', 'confirmed', 'variant', 'ancLang', 'ancNo', 'anc2No', 'descLang', 'descNo', 'connot', 'connStatus', 'irregular', 'mark');
BoolStr: array[False..True] of string = ('False', 'True');
StatusStr: array[csUnused..csFixedWarning] of string = ('Unused', 'Used', 'Included', 'Warning', 'FixedWarning');
var i, j, k, l: Integer;
st: string;
sl: TStringList;
begin
if LangTree.Items.Count>0 then begin
sl:=TStringList.Create;
sl.Add('<?php');
for k:=0 to High(identifiers) do begin
sl.Add('$'+identifiers[k]+' = [');
for i:=0 to Length(Dicts)-1 do begin
sl.Add('[');
for j:=0 to Dicts[i].Count-1 do begin
with PDictEntry(Dicts[i][j])^ do case k of
0: begin
FillMainWord(3, i, PDictEntry(Dicts[i][j]));
st:=QuoteRTFtoUTF8(Neogrammarian.MakeWordHTML(3, -1, -1, 'h2', False), False);
end;
1: st:=QuoteRTFtoUTF8(Gloss, True);
2: st:=BoolStr[Confirmed];
3: st:=QuoteRTFtoUTF8(PercentToRTF(Variant(Ancestor.Lang, i, PDictEntry(Dicts[i][j]), False)), True);
4: if Ancestor.Lang<255 then st:=IntToStr(Ancestor.Lang) else st:='-1';
5: if Ancestor.Lang<255 then st:=IntToStr(Dicts[Ancestor.Lang].IndexOf(Ancestor.Entry)) else st:='-1';
6: if Ancestor.Lang=i then st:=IntToStr(Dicts[i].IndexOf(Ancestor2)) else st:='-1';
7: begin
st:='[';
for l:=0 to Length(Descendants)-1 do st:=st+IntToStr(Descendants[l].Lang)+IfThen(l<Length(Descendants)-1, ',');
st:=st+']';
end;
8: begin
st:='[';
for l:=0 to Length(Descendants)-1 do st:=st+IntToStr(Dicts[Descendants[l].Lang].IndexOf(Descendants[l].Entry))+IfThen(l<Length(Descendants)-1, ',');
st:=st+']';
end;
9: begin
st:='[';
for l:=0 to Length(Connots)-1 do st:=st+QuoteRTFtoUTF8(PercentToRTF(Connots[l].Kind), True)+IfThen(l<Length(Connots)-1, ',');
st:=st+']';
end;
10: begin
st:='[';
for l:=0 to Length(Connots)-1 do st:=st+''''+StatusStr[Connots[l].Status]+''''+IfThen(l<Length(Connots)-1, ',');
st:=st+']';
end;
11: st:=QuoteRTFtoUTF8(Irregular, True);
12: st:=IntToStr(Mark);
end;
sl.Add(st+IfThen(j<Dicts[i].Count-1, ','));
end;
sl.Add(']'+IfThen(i<Length(Dicts)-1, ','));
end;
sl.Add('];');
end;
sl.Add('$tree = [');
for i:=0 to SemanticTree.Items.Count-1 do with SemanticTree.Items[i] do begin
if Data<>nil then st:=IntToStr(Dicts[lModLem].IndexOf(Data)) else st:=QuoteRTFtoUTF8(Text, True);
sl.Add('['+IntToStr(Level)+','+BoolStr[Data<>nil]+','+st+']'+IfThen(i<SemanticTree.Items.Count-1, ','));
end;
sl.Add(']; ?>');
Result:=sl.Text;
sl.Free;
end else Result:='';
end; {MakePHP}
procedure TDictForm.CloseDict;
var i, j: Integer;
begin
if HDict<>Invalid_Handle_Value then CloseHandle(HDict);
for i:=0 to High(Dicts) do with Dicts[i] do begin
for j:=0 to Count-1 do Dispose(PDictEntry(Items[j]));
Count:=0;
end;
with Neogrammarian do if Addallwords.Checked then AddallwordsClick(nil) else begin
DictLinkS:=nil;
DictLinkT:=nil;
end;
LangTreeChange(nil, nil);
end; {CloseDict}
{procedure TDictForm.PropagateConnots(Entry1, Entry2: PDictEntry; AConnots: TStrings); /// propagate to all descendants (see OLem fler-/flor- "blue")
procedure Propagate(E1, E2: PDictEntry); // compounds have no connots
var i, l: Integer; // contaminations inherit only those of 1st part
st: string; // affixed words and duplicates inherit connots
begin
l:=Length(E1.Connots);
SetLength(E2.Connots, l);
E2.OldConnots:=l;
for i:=0 to l-1 do E2.Connots[i]:=E1.Connots[i];
end;
var i: Integer;
begin
for i:=0 to AConnots.Count-1 do if (AConnots.Objects[i]=Pointer(clWindowText)) or (AConnots.Objects[i]=Pointer(clRed)) then begin
st:=Copy(AConnots[i], Pos('|', AConnots[i])+1, MaxInt);
if (Length(st)>0) and (st[1]<>'(') then begin
Inc(l);
SetLength(Entry2.Connots, l);
with Entry2.Connots[l-1] do begin
if AConnots.Objects[i]=Pointer(clWindowText) then Status:=csUnused else Status:=csError;
Kind:=st;
end;
end;
end;
end; {PropagateConnots}
procedure TDictForm.PropagateConnots(Entry1, Entry2: PDictEntry; AConnots: TStrings); /// propagate to all descendants (see OLem fler-/flor- "blue")
var i, l: Integer;
st: string;
begin
l:=Length(Entry1.Connots);
SetLength(Entry2.Connots, l);
Entry2.OldConnots:=l;
for i:=0 to l-1 do Entry2.Connots[i]:=Entry1.Connots[i];
for i:=0 to AConnots.Count-1 do if (AConnots.Objects[i]=Pointer(clWindowText)) or (AConnots.Objects[i]=Pointer(clRed)) then begin
st:=Copy(AConnots[i], Pos('|', AConnots[i])+1, MaxInt);
if (Length(st)>0) and (st[1]<>'(') then begin
Inc(l);
SetLength(Entry2.Connots, l);
with Entry2.Connots[l-1] do begin
if AConnots.Objects[i]=Pointer(clWindowText) then Status:=csUnused else Status:=csWarning;
Kind:=st;
end;
end;
end;
end; {PropagateConnots}
procedure TDictForm.AddWords(Lang1, Lang2: Integer; Word1, Word2, StressDia1, StressDia2: ByteArray; Ending1, Ending2, MorphBound1, MorphBound2: Word;
Gloss: string; Connots: TStrings; VarCode: Byte; var Entry1, Entry2: PDictEntry; const AnotherDesc: Boolean);
procedure Add(ALang: Integer; AWord, AStressDia: ByteArray; AEnding, AMorphBound: Word; Kind: string; var Added: Boolean; var Entry: PDictEntry);
var i, j: Integer;
e: PDictEntry;
begin
if Dicts[ALang].IndexOf(Entry)=-1 then begin
New(e);
SetLength(e.Word, Length(AWord)); // merge with ChangeWords.Change, AddWord?
for i:=0 to Length(AWord)-1 do e.Word[i]:=AWord[i];
SetLength(e.StressDia, Length(AStressDia));
for i:=0 to Length(AStressDia)-1 do e.StressDia[i]:=AStressDia[i];
e.Ending:=AEnding;
e.MorphBound:=AMorphBound;
e.Gloss:=Gloss;
e.Confirmed:=False;
e.Ancestor.Lang:=255;
e.Ancestor2:=nil;
e.VarCode:=$FF;
e.Mark:=0;
j:=-1;
SortLang:=ALang;
for i:=0 to Dicts[ALang].Count-1 do if DictEntryCompare(e, Dicts[ALang][i])=0 then j:=i;
if (j=-1) or Added and (PDictEntry(Dicts[ALang][j]).Ancestor.Lang<255) or
(TangoMessageBoxT(Kind+' word already exists. Add as a homonym?', mtConfirmation, [mbYes, mbNo], ['&Yes, homonym', '&No, same word'], '')=idYes) then begin
Dicts[ALang].Add(e);
DictSort(ALang);
Entry:=e;
Added:=True;
end else begin
Dispose(e);
Entry:=Dicts[ALang][j];
end;
end;
end; {Add}
var i, j: Integer;
a: Boolean;
begin
a:=False;
Add(Lang1, Word1, StressDia1, Ending1, MorphBound1, 'Source', a, Entry1);
Add(Lang2, Word2, StressDia2, Ending2, MorphBound2, 'Target', a, Entry2);
if Connots<>nil then PropagateConnots(Entry1, Entry2, Connots);
Entry2.VarCode:=VarCode;
AddDescendant(Lang1, Lang2, Entry1, Entry2, True);
GotoEntry(Lang1, Entry1);
GlossEditChange(nil);
j:=-1;
for i:=0 to Length(Entry1.Descendants)-1 do if Entry1.Descendants[i].Lang=Lang2 then Inc(j);
if AnotherDesc and (j>0) then TangoMessageBox('Note: Source word has '+IfThen(j=1, 'another descendant', IntToStr(j)+' other descendants')+' in '+LongLangNs[Lang2]+'.',
mtInformation, [mbOK], '');
end; {AddWords}
function TDictForm.ChangeWords(Entry1, Entry2: PDictEntry; Word1, Word2, StressDia1, StressDia2: ByteArray; Ending1, Ending2, MorphBound1: Word; Connots: TStrings; VarCode2: Byte): Boolean;
procedure Change(Entry: PDictEntry; AWord, AStressDia: ByteArray; AEnding, AMorphBound: Word; AVarCode: Byte; TargetWord: Boolean);
var i: Integer;
same: Boolean;
begin
with Entry^ do begin
same:=(Length(Word)=Length(AWord)) and (Ending=AEnding) and (MorphBound=AMorphBound);
if same then for i:=0 to Length(Word)-1 do same:=same and (Word[i]=AWord[i]) and (StressDia[i]=AStressDia[i]);
if not same then begin
SetLength(Word, Length(AWord)); // merge with AddWords.Add, AddWord?
for i:=0 to Length(Word)-1 do Word[i]:=AWord[i];
SetLength(StressDia, Length(AStressDia));
for i:=0 to Length(StressDia)-1 do StressDia[i]:=AStressDia[i];
Ending:=AEnding;
MorphBound:=AMorphBound;
Confirmed:=False;
if TargetWord then VarCode:=AVarCode else if (Ancestor.Lang<255) and (Irregular='') then Irregular:=UndefIrreg;
Result:=True;
end;
end;
end; {Change}
begin
Result:=False;
if (Entry1<>nil) and (Length(Word1)>0) then begin
Change(Entry1, Word1, StressDia1, Ending1, MorphBound1, 0, False);
DictSort(Neogrammarian.Langs[0,0]);
if ThisLang=Neogrammarian.Langs[0,0] then WordListBox.ItemIndex:=Dicts[Neogrammarian.Langs[0,0]].IndexOf(Entry1);
end;
if (Entry2<>nil) and (Length(Word2)>0) then begin
Change(Entry2, Word2, StressDia2, Ending2, Word(-1), VarCode2, True);
if Entry2<>nil then PropagateConnots(Entry1, Entry2, Connots);
DictSort(Neogrammarian.Langs[2,0]);
if ThisLang=Neogrammarian.Langs[2,0] then WordListBox.ItemIndex:=Dicts[Neogrammarian.Langs[2,0]].IndexOf(Entry2);
end;
// sort Entry1.Descendants: see AddDescendant (only if both words exist!)
WordListBox.Invalidate;
WordListBoxClick(nil);
end; {ChangeWords}
{----------------------------------------------------------Controls--------------------------------------------------------------}
procedure TDictForm.PageControlChange(Sender: TObject);
begin
LangLabel.Visible:=PageControl.ActivePage=DictSheet;
UpdateSemTreeBtn;
end; {PageControlChange}
procedure TDictForm.SplitterMoved(Sender: TObject);
begin
WordListBox.Invalidate;
DescendantsListBox.Invalidate;
end; {SplitterMoved}
procedure TDictForm.SaveBtnClick(Sender: TObject);
begin
SaveDict(False);
end; {SaveBtnClick}
procedure TDictForm.UpdateWordListLabel;
var i, u: Integer;
begin
u:=0;
with Dicts[ThisLang] do begin
for i:=0 to Count-1 do if not PDictEntry(Items[i]).Confirmed then Inc(u);
WordListLabel.Caption:=IntToStr(Count)+' le&mma'+Copy('ta', 1, 2*Ord(Count<>1))+' ('+IntToStr(u)+' unconfirmed)';
end;
end; {UpdateWordListLabel}
procedure TDictForm.LangTreeChanging(Sender: TObject; Node: TTreeNode; var AllowChange: Boolean);
begin
with LangTree do AllowChange:=Node.Level>0;
end; {LangTreeChanging}
procedure TDictForm.LangTreeChange(Sender: TObject; Node: TTreeNode);
var i: Integer;
begin
UpdateWordListLabel;
LangLabel.Caption:=LongLangNs[ThisLang];
WordListBox.Items.BeginUpdate;
WordListBox.Items.Clear;
with Dicts[ThisLang] do for i:=0 to Count-1 do WordListBox.Items.Add('');
WordListBox.Items.EndUpdate;
BackPanel.Visible:=Dicts[ThisLang].Count>0;
if BackPanel.Visible then WordListBox.ItemIndex:=0;
CompoundBtn.Down:=False;
ContaminationBtn.Down:=False;
WordListBoxClick(nil);
end; {LangTreeChange}
procedure TDictForm.SetEditBtn(Btn: TSpeedButton; Entry: PDictEntry; Lang: Byte);
begin
Btn.Enabled:=Lang<255;
Btn.Hint:='Edit word in main window ('+IfThen(Btn=EditBtn2, 'Shift+')+'Ctrl+E)';
EditBtnNotes[Btn=EditBtn2]:=0;
with Btn, Entry^ do if Enabled and (Length(Descendants)>0) then if Length(Descendants)>1 then EditBtnNotes[Btn=EditBtn2]:=1
else if Length(Descendants[0].Entry.Descendants)>0 then EditBtnNotes[Btn=EditBtn2]:=2
else if Descendants[0].Lang=Lang then EditBtnNotes[Btn=EditBtn2]:=3;
if EditBtnNotes[Btn=EditBtn2]>0 then Btn.Hint:=Btn.Hint+#13#10'Note: '+EditBtnNoteStrings[EditBtnNotes[Btn=EditBtn2]];
end; {SetEditBtn}
procedure TDictForm.WordListBoxClick(Sender: TObject);
procedure Compound;
var e1, e2: PDictEntry;
wrd, strs: ByteArray;
i, mb: Integer;
begin
e1:=PDictEntry(CompoundBtn.Tag);
e2:=PThisEntry;
if e1<>e2 then with Neogrammarian do begin
FillMainWord(1, ThisLang, e1);
WordLen[1]:=Min(WordLen[1], Ending[1]);
if ThisLang=lPIE then case CompoundPopup.Tag of
2{bahuvrihi}: Grade(gFull, True);
3{appositional}: ; // grade, accent?
9{Caland}: begin Grade(gZeroPlusV, False); Add(1, 7); end;
end else if (ThisLang=lElb) and (CompoundPopup.Tag=2) then ; //
with CasesForm do if (ThisLang=lModLem) and (ShowModal=mrOK) then for i:=WordLen[1]-1 downto 0 do if Words[1,i]=0 then begin
Words[1,i]:=CaseBox.ItemIndex mod 8;
if SecCaseBox.ItemIndex>0 then Insert(1, i+1, SecCaseBox.ItemIndex+23);
if CaseBox.ItemIndex>=8 then Insert(1, i+1, 29-(CaseBox.ItemIndex div 8));
Break;
end;
mb:=WordLen[1];