source: trunk/Forms/UFormCheck.pas

Last change on this file was 209, checked in by chronos, 3 years ago
  • Fixed: Correctly detect data application directories for Linux installation.
  • Modified: Use registry key and root from application info component.
File size: 24.7 KB
Line 
1unit UFormCheck;
2
3{$mode delphi}
4
5interface
6
7uses
8 Classes, SysUtils, LazFileUtils, Forms, Controls, Graphics, Dialogs, StdCtrls,
9 ExtCtrls, ComCtrls, Menus, ActnList, UAcronym, URegistry, Registry, UCommon,
10 fgl;
11
12type
13 TReportType = (rtNone, rtNote, rtWarning, rtError);
14
15 TReportItem = class
16 Message: string;
17 Position: TPoint;
18 Kind: TReportType;
19 end;
20
21 { TReportItems }
22
23 TReportItems = class(TFPGObjectList<TReportItem>)
24 function AddNew(Message: string; Position: TPoint;
25 Kind: TReportType = rtNone): TReportItem;
26 procedure SaveToCsv(FileName: string);
27 end;
28
29 { TFormCheck }
30
31 TFormCheck = class(TForm)
32 AGoToLocation: TAction;
33 ASaveToCsv: TAction;
34 ActionList1: TActionList;
35 ButtonLoadFromFile: TButton;
36 ButtonAcronymsContent: TButton;
37 ButtonAcronymsSummary: TButton;
38 ButtonCheck: TButton;
39 CheckBoxCaseSensitive: TCheckBox;
40 EditSummaryStart: TEdit;
41 EditSummaryEnd: TEdit;
42 GroupBox1: TGroupBox;
43 GroupBox2: TGroupBox;
44 Label1: TLabel;
45 Label2: TLabel;
46 LabelAcronymCountContent: TLabel;
47 LabelAcronymCountSummary: TLabel;
48 ListViewReport: TListView;
49 MemoDocument: TMemo;
50 MenuItem1: TMenuItem;
51 MenuItemGoTo: TMenuItem;
52 OpenDialog1: TOpenDialog;
53 PageControl1: TPageControl;
54 Panel1: TPanel;
55 Panel2: TPanel;
56 PopupMenuReport: TPopupMenu;
57 SaveDialog1: TSaveDialog;
58 Splitter1: TSplitter;
59 TabSheetSource: TTabSheet;
60 TabSheetReport: TTabSheet;
61 procedure AGoToLocationExecute(Sender: TObject);
62 procedure ASaveToCsvExecute(Sender: TObject);
63 procedure ButtonAcronymsSummaryClick(Sender: TObject);
64 procedure ButtonAcronymsContentClick(Sender: TObject);
65 procedure ButtonCheckClick(Sender: TObject);
66 procedure ButtonLoadFromFileClick(Sender: TObject);
67 procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
68 procedure FormCreate(Sender: TObject);
69 procedure FormDestroy(Sender: TObject);
70 procedure FormShow(Sender: TObject);
71 procedure ListViewReportData(Sender: TObject; Item: TListItem);
72 procedure MenuItemGoToClick(Sender: TObject);
73 private
74 AcronymDbSummary: TAcronymDb;
75 AcronymDbContent: TAcronymDb;
76 LastDocumentFileName: string;
77 function SearchLine(Lines: TStrings; Text: string; Start: Integer = 0): Integer;
78 function SearchLineReverse(Lines: TStrings; Text: string; Start: Integer = -1): Integer;
79 procedure FindInSummary;
80 procedure FindInContent;
81 function AllowedSideChar(Before, After: Char): Boolean;
82 function ParseMeaning(Acronym, Text: string; StartIndex: Integer;
83 out Meaning: string; DashSeparator: Boolean = False): Boolean;
84 function IsUppercaseAlpha(Text: string): Boolean;
85 function IsLowercaseAlpha(Text: string): Boolean;
86 function IsAlpha(Text: string): Boolean;
87 function IsAcronym(Text: string): Boolean;
88 function IsDigit(Text: Char): Boolean;
89 procedure ReportDifferencies;
90 function WordContainsLetters(Text, Letters: string): Boolean;
91 function StringEqual(Text1, Text2: string): Boolean;
92 procedure ReloadReport;
93 public
94 ReportItems: TReportItems;
95 procedure UpdateInterface;
96 procedure LoadConfig;
97 procedure SaveConfig;
98 end;
99
100var
101 FormCheck: TFormCheck;
102
103const
104 ReportTypeString: array[TReportType] of string = ('', 'Note', 'Warning', 'Error');
105
106
107implementation
108
109{$R *.lfm}
110
111uses
112 UFormAcronyms, UCore;
113
114resourcestring
115 SAcronymCountContent = 'Content acronym count:';
116 SAcronymCountSummary = 'Summary acronym count:';
117 SDuplicateAcronymContent = 'Duplicate acronym %s with "%s" in document body.';
118 SDuplicateAcronymSummary = 'Duplicate acronym %s with "%s" in acronym summary.';
119 SMissingAcronymContent = 'Document body acronym %s with meaning "%s" missing from acronym summary.';
120 SMissingAcronymSummary = 'Summary acronym %s with meaning "%s" missing from document body.';
121 SAcronymContentMultipleMeanings = 'Content acronym %s has multiple meanings: %s.';
122 SAcronymSummaryMultipleMeanings = 'Summary acronym %s has multiple meanings: %s.';
123 SAcronymWithDifferentMeaning = 'Acronym %s has different meaning for content "%s" and for summary "%s".';
124 SAcronymWithDifferentMeaningCount = 'Acronym %s has different meaning count for content (%d) and for summary (%d).';
125 SPluralAcronym = 'Acronym %s is defined as plural in document body.';
126 SPluralAcronymUsed = 'Acronym %s is used as plural in document body.';
127 SSummaryAcronyms = 'Summary acronyms';
128 SContentAcronyms = 'Content acronyms';
129 SAcronymUsedBeforeDefined = 'Acronym %s used before it was defined.';
130 SCSVFilter = 'CSV file (.csv)|*.csv|Any file|*.*';
131
132const
133 MinAcronymLength = 2;
134
135{ TReportItems }
136
137function TReportItems.AddNew(Message: string; Position: TPoint;
138 Kind: TReportType = rtNone): TReportItem;
139begin
140 Result := TReportItem.Create;
141 Result.Message := Message;
142 Result.Position := Position;
143 Result.Kind := Kind;
144 Add(Result);
145end;
146
147procedure TReportItems.SaveToCsv(FileName: string);
148var
149 I: Integer;
150 F: TStringList;
151 Line: TStringList;
152begin
153 F := TStringList.Create;
154 Line := TStringList.Create;
155 Line.StrictDelimiter := True;
156 try
157 Line.Clear;
158 for I := 0 to Count - 1 do
159 with TReportItem(Items[I]) do begin
160 Line.Clear;
161 if Position <> Point(0, 0) then
162 Line.Add(IntToStr(Position.X) + ', ' + IntToStr(Position.Y))
163 else Line.Add('');
164 Line.Add(ReportTypeString[Kind]);
165 Line.Add(Message);
166 F.Add(Line.CommaText);
167 end;
168 F.SaveToFile(FileName);
169 finally
170 F.Free;
171 Line.Free;
172 end;
173end;
174
175{ TFormCheck }
176
177procedure TFormCheck.ButtonCheckClick(Sender: TObject);
178begin
179 ReportItems.Clear;
180 UpdateInterface;
181 FindInSummary;
182 FindInContent;
183 ReportDifferencies;
184 UpdateInterface;
185 ReloadReport;
186 TabSheetReport.Show;
187end;
188
189procedure TFormCheck.ButtonLoadFromFileClick(Sender: TObject);
190begin
191 OpenDialog1.InitialDir := ExtractFileDir(LastDocumentFileName);
192 OpenDialog1.FileName := ExtractFileName(LastDocumentFileName);
193 if OpenDialog1.Execute then begin
194 LastDocumentFileName := OpenDialog1.FileName;
195 MemoDocument.Lines.LoadFromFile(OpenDialog1.FileName);
196 TabSheetSource.Show;
197 end;
198end;
199
200procedure TFormCheck.FormClose(Sender: TObject; var CloseAction: TCloseAction);
201begin
202 Core.PersistentForm1.Save(Self);
203end;
204
205procedure TFormCheck.FormCreate(Sender: TObject);
206begin
207 AcronymDbSummary := TAcronymDb.Create;
208 AcronymDbContent := TAcronymDb.Create;
209 Core.Translator.TranslateComponentRecursive(Self);
210 Core.ThemeManager.UseTheme(Self);
211 ReportItems := TReportItems.Create;
212end;
213
214procedure TFormCheck.FormDestroy(Sender: TObject);
215begin
216 ReportItems.Free;
217 AcronymDbSummary.Free;
218 AcronymDbContent.Free;
219end;
220
221procedure TFormCheck.FormShow(Sender: TObject);
222begin
223 PageControl1.TabIndex := 0;
224 Core.PersistentForm1.Load(Self);
225 if FileExists(LastDocumentFileName) then
226 MemoDocument.Lines.LoadFromFile(LastDocumentFileName);
227 UpdateInterface;
228end;
229
230procedure TFormCheck.ListViewReportData(Sender: TObject; Item: TListItem);
231begin
232 if Item.Index < ReportItems.Count then
233 with ReportItems[Item.Index] do begin
234 if Position <> Point(0, 0) then
235 Item.Caption := IntToStr(Position.X) + ', ' + IntToStr(Position.Y)
236 else Item.Caption := '';
237 Item.Data := ReportItems[Item.Index];
238 Item.SubItems.Add(ReportTypeString[Kind]);
239 Item.SubItems.Add(Message);
240 end;
241end;
242
243procedure TFormCheck.MenuItemGoToClick(Sender: TObject);
244begin
245
246end;
247
248procedure TFormCheck.ButtonAcronymsContentClick(Sender: TObject);
249var
250 FormAcronyms: TFormAcronyms;
251begin
252 FormAcronyms := TFormAcronyms.Create(Self);
253 try
254 FormAcronyms.Acronyms := AcronymDbContent.Acronyms;
255 FormAcronyms.Caption := SContentAcronyms;
256 FormAcronyms.ShowModal;
257 finally
258 FreeAndNil(FormAcronyms);
259 end;
260end;
261
262procedure TFormCheck.ButtonAcronymsSummaryClick(Sender: TObject);
263var
264 FormAcronyms: TFormAcronyms;
265begin
266 FormAcronyms := TFormAcronyms.Create(Self);
267 try
268 FormAcronyms.Acronyms := AcronymDbSummary.Acronyms;
269 FormAcronyms.Caption := SSummaryAcronyms;
270 FormAcronyms.ShowModal;
271 finally
272 FreeAndNil(FormAcronyms);
273 end;
274end;
275
276procedure TFormCheck.ASaveToCsvExecute(Sender: TObject);
277begin
278 SaveDialog1.InitialDir := ExtractFileDir(LastDocumentFileName);
279 SaveDialog1.DefaultExt := '.csv';
280 SaveDialog1.FileName := ExtractFileNameWithoutExt(ExtractFileName(LastDocumentFileName)) + SaveDialog1.DefaultExt;
281 SaveDialog1.Filter := SCSVFilter;
282 if SaveDialog1.Execute then begin
283 ReportItems.SaveToCsv(SaveDialog1.FileName);
284 end;
285end;
286
287procedure TFormCheck.AGoToLocationExecute(Sender: TObject);
288begin
289 if Assigned(ListViewReport.Selected) then
290 with TReportItem(ListViewReport.Selected.Data) do
291 if Position <> Point(0, 0) then begin
292 MemoDocument.CaretPos := Position;
293 TabSheetSource.Show;
294 end;
295end;
296
297function TFormCheck.SearchLine(Lines: TStrings; Text: string; Start: Integer = 0): Integer;
298begin
299 Result := Start;
300 while (Result < Lines.Count) and (Pos(Text, Lines[Result]) = 0) do Inc(Result);
301 if Result >= Lines.Count then Result := -1;
302end;
303
304function TFormCheck.SearchLineReverse(Lines: TStrings; Text: string;
305 Start: Integer = -1): Integer;
306begin
307 if Start = -1 then Result := Lines.Count - 1
308 else Result := Start;
309 while (Result >= 0) and (Pos(Text, Lines[Result]) = 0) do Dec(Result);
310end;
311
312procedure TFormCheck.FindInSummary;
313var
314 AcronymSectionStart: Integer;
315 AcronymSectionEnd: Integer;
316 I: Integer;
317 Line: string;
318 Acronym: string;
319 Meaning: string;
320 Index: Integer;
321begin
322 AcronymDbSummary.Acronyms.Clear;
323
324 AcronymSectionStart := SearchLineReverse(MemoDocument.Lines, EditSummaryStart.Text);
325 if AcronymSectionStart <> -1 then begin
326 AcronymSectionEnd := SearchLine(MemoDocument.Lines, EditSummaryEnd.Text, AcronymSectionStart + 1);
327 if AcronymSectionEnd <> -1 then begin
328 Acronym := '';
329 for I := AcronymSectionStart + 1 to AcronymSectionEnd - 1 do begin
330 Line := Trim(MemoDocument.Lines[I]);
331 Line := StringReplace(Line, #9, ' ', [rfReplaceAll]);
332 if Line <> '' then begin
333 if (Acronym <> '') and IsUppercaseAlpha(Acronym) then begin
334 Meaning := Line;
335 end else begin
336 Index := Pos(' ', Line);
337 if Index > 0 then begin
338 Acronym := Copy(Line, 1, Index - 1);
339 Meaning := Trim(Copy(Line, Index + 1, Length(Line)));
340 end else begin
341 if Acronym = '' then Acronym := Line
342 else Meaning := Line;
343 end;
344 end;
345 if (Acronym <> '') and IsUppercaseAlpha(Acronym) and (Meaning <> '') then begin
346 if Assigned(AcronymDbSummary.SearchAcronym(Acronym, Meaning)) then
347 ReportItems.AddNew(Format(SDuplicateAcronymSummary, [Acronym, Meaning]), Point(0, I), rtWarning)
348 else AcronymDbSummary.AddAcronym(Acronym, Meaning);
349 Acronym := '';
350 Meaning := '';
351 end;
352 end;
353 end;
354 end;
355 end;
356end;
357
358procedure TFormCheck.FindInContent;
359var
360 Text: string;
361 Index: Integer;
362 State: (stNone, stAcronymUsage, stAcronymDefinition);
363 Acronym: string;
364 AcronymCharBefore: Char;
365 AcronymCharAfter: Char;
366 Lines: TStringList;
367 HasUpperCase: Boolean;
368 HasLowerCase: Boolean;
369 I: Integer;
370 J: Integer;
371 Line: string;
372 Meaning: string;
373 Meaning1: string;
374 Meaning2: string;
375 HasMeaning1: Boolean;
376 HasMeaning2: Boolean;
377 Plural: Boolean;
378 StartIndex: Integer;
379 Acro: TAcronym;
380begin
381 AcronymDbContent.Acronyms.Clear;
382
383 // Make lowercase lines where all alpha characters are in uppercase
384 // These are usually first level chapter titles or first page text
385 Lines := TStringList.Create;
386 Lines.Assign(MemoDocument.Lines);
387 for I := 0 to Lines.Count - 1 do begin
388 HasLowerCase := False;
389 HasUpperCase := False;
390 Line := Lines[I];
391 for J := 1 to Length(Line) do begin
392 if IsUppercaseAlpha(Line[J]) then HasUpperCase := True;
393 if IsLowercaseAlpha(Line[J]) then HasLowerCase := True;
394 end;
395 if HasUpperCase and not HasLowerCase then
396 Lines[I] := LowerCase(Lines[I]);
397 end;
398
399 // Find acronyms usage in text
400 Text := Lines.Text;
401 Text := StringReplace(Text, #9, ' ', [rfReplaceAll]);
402 Text := StringReplace(Text, LineEnding, ' ', [rfReplaceAll]);
403 Index := 1;
404 AcronymCharBefore := ' ';
405 AcronymCharAfter := ' ';
406 State := stNone;
407 StartIndex := 0;
408 Acronym := '';
409 repeat
410 if State = stAcronymUsage then begin
411 if not IsUppercaseAlpha(Text[Index]) then begin
412 if Text[Index] = 's' then begin
413 Acronym := Acronym + Text[Index];
414 Inc(Index);
415 end;
416 if (Index) < Length(Text) then AcronymCharAfter := Text[Index]
417 else AcronymCharAfter := ' ';
418 State := stNone;
419
420 // Allow plural acronyms with ending 's' character
421 if (Length(Acronym) >= 1) and (Acronym[Length(Acronym)] = 's') then begin
422 Acronym := Copy(Acronym, 1, Length(Acronym) - 1);
423 Plural := True;
424 end else Plural := False;
425
426 // Acronyms should not contain numbers
427 if (Length(Acronym) >= MinAcronymLength) and
428 AllowedSideChar(AcronymCharBefore, AcronymCharAfter) then begin
429 // If plural acronym then try to remove ending 's' character from the meaning
430 if Plural then ReportItems.AddNew(Format(SPluralAcronymUsed, [Acronym]), Point(0, 0), rtNote);
431
432 Acro := AcronymDbContent.Acronyms.SearchByName(Acronym);
433 if not Assigned(Acro) then begin
434 ReportItems.AddNew(Format(SAcronymUsedBeforeDefined, [Acronym]), Point(0, 0), rtNote);
435 AcronymDbContent.AddAcronym(Acronym, '');
436 end;
437 end;
438 end else Acronym := Acronym + Text[Index];
439 end else
440 if State = stAcronymDefinition then begin
441 if Text[Index] = ')' then begin
442 // Allow plural acronyms with ending 's' character
443 if (Length(Acronym) >= 1) and (Acronym[Length(Acronym)] = 's') then begin
444 Acronym := Copy(Acronym, 1, Length(Acronym) - 1);
445 Plural := True;
446 end else Plural := False;
447 if IsAcronym(Acronym) then begin
448 HasMeaning1 := ParseMeaning(Acronym, Text, StartIndex - 1, Meaning1);
449 if HasMeaning1 then Meaning := Meaning1;
450 HasMeaning2 := ParseMeaning(Acronym, Text, StartIndex - 1, Meaning2, True);
451 if HasMeaning2 then Meaning := Meaning2;
452 if HasMeaning1 and HasMeaning2 then begin
453 if Length(Meaning1) > Length(Meaning2) then Meaning := Meaning1
454 else Meaning := Meaning2;
455 end;
456 if HasMeaning1 or HasMeaning2 then begin
457 // If plural acronym then try to remove ending 's' character from the meaning
458 if Plural then ReportItems.AddNew(Format(SPluralAcronym, [Acronym]), Point(0, 0), rtNote);
459 if Plural and (Length(Meaning) >= 1) and (Meaning[Length(Meaning)] = 's') then begin
460 Meaning := Copy(Meaning, 1, Length(Meaning) - 1);
461 end;
462 if Assigned(AcronymDbContent.SearchAcronym(Acronym, Meaning)) then
463 ReportItems.AddNew(Format(SDuplicateAcronymContent, [Acronym, Meaning]), Point(0, 0), rtWarning)
464 else AcronymDbContent.AddAcronym(Acronym, Meaning);
465 end;
466 end else
467 // No acronym inside parenthesis, continue with parsing inside
468 Index := StartIndex + 1;
469 State := stNone;
470 end else begin
471 Acronym := Acronym + Text[Index];
472 end;
473 end else begin
474 if Text[Index] = '(' then begin
475 State := stAcronymDefinition;
476 Acronym := '';
477 StartIndex := Index;
478 end else
479 if IsUppercaseAlpha(Text[Index]) then begin
480 State := stAcronymUsage;
481 Acronym := Text[Index];
482 if (Index - 1) >= 1 then AcronymCharBefore := Text[Index - 1]
483 else AcronymCharBefore := ' ';
484 end;
485 end;
486 Inc(Index);
487 until Index > Length(Text);
488 Lines.Free;
489end;
490
491function TFormCheck.AllowedSideChar(Before, After: Char): Boolean;
492begin
493 Result := ((Before = ' ') or (Before = #10) or (Before = #13) or (Before = ',') or
494 (Before = ';') or (Before = '(') or (Before = ')'))
495 and ((After = ' ') or (After = #10) or (After = #13) or (After = ',') or
496 (After = '.') or (After = ';') or (After = '(') or (After = ')'));
497end;
498
499function TFormCheck.ParseMeaning(Acronym, Text: string; StartIndex: Integer;
500 out Meaning: string; DashSeparator: Boolean): Boolean;
501var
502 StartIndex2: Integer;
503 StartIndex3: Integer;
504 StartIndex4: Integer;
505 LetterIndex: Integer;
506 OneWord: string;
507 WordLetterIndex: Integer;
508 WordCount: Integer;
509 WordCountWrong: Integer;
510begin
511 Result := True;
512 Meaning := '';
513 StartIndex2 := StartIndex;
514 LetterIndex := Length(Acronym);
515 WordCount := 0;
516 WordCountWrong := 0;
517 while Length(Acronym) > 0 do begin
518 StartIndex3 := PosFromIndexReverse(' ', Text, StartIndex2);
519 if DashSeparator then begin
520 StartIndex4 := PosFromIndexReverse('-', Text, StartIndex2);
521 if StartIndex4 > StartIndex3 then StartIndex3 := StartIndex4;
522 end;
523
524 if StartIndex3 = 0 then Break;
525 OneWord := Copy(Text, StartIndex3 + 1, StartIndex2 - StartIndex3);
526 if OneWord = '$' then begin
527 // Avoid parsing Bash variables
528 Result := False;
529 Exit;
530 end;
531 if Trim(OneWord) = '' then begin
532 StartIndex2 := StartIndex3 - 1;
533 Continue;
534 end;
535 // Is first letter capital?
536 if (Length(OneWord) > 0) and IsAlpha(OneWord[1]) then begin
537 WordLetterIndex := PosFromIndexReverse(LowerCase(OneWord[1]), LowerCase(Copy(Acronym, 1, LetterIndex)), LetterIndex);
538 if WordLetterIndex > 0 then begin
539 // First letter was found in acronym
540 if WordLetterIndex <= LetterIndex then begin
541 if not WordContainsLetters(LowerCase(OneWord), LowerCase(Copy(Acronym, WordLetterIndex, LetterIndex - WordLetterIndex + 1))) then begin
542 Result := False;
543 Exit;
544 end;
545 LetterIndex := WordLetterIndex - 1;
546 end else begin
547 Dec(LetterIndex);
548 end;
549 WordCountWrong := 0;
550 end else begin
551 Inc(WordCountWrong);
552 if WordCountWrong > 1 then begin
553 Result := False;
554 Exit;
555 end;
556 end;
557 end else begin
558 Inc(WordCountWrong);
559 if WordCountWrong > 1 then begin
560 Result := False;
561 Exit;
562 end;
563 end;
564 StartIndex2 := StartIndex3 - 1;
565 if LetterIndex < 1 then Break;
566 Inc(WordCount);
567 if WordCount > 2 * Length(Acronym) then begin
568 // False acronym in braces with too much words
569 Result := False;
570 Exit;
571 end;
572 end;
573 Meaning := Trim(Copy(Text, StartIndex2 + 1, StartIndex - StartIndex2));
574end;
575
576function TFormCheck.IsUppercaseAlpha(Text: string): Boolean;
577var
578 I: Integer;
579begin
580 I := 1;
581 Result := True;
582 while (I <= Length(Text)) do begin
583 if not (Text[I] in ['A'..'Z']) then begin
584 Result := False;
585 Break;
586 end;
587 Inc(I);
588 end;
589end;
590
591function TFormCheck.IsLowercaseAlpha(Text: string): Boolean;
592var
593 I: Integer;
594begin
595 I := 1;
596 Result := True;
597 while (I <= Length(Text)) do begin
598 if not (Text[I] in ['a'..'z']) then begin
599 Result := False;
600 Break;
601 end;
602 Inc(I);
603 end;
604end;
605
606function TFormCheck.IsAlpha(Text: string): Boolean;
607var
608 I: Integer;
609begin
610 I := 1;
611 Result := True;
612 while (I <= Length(Text)) do begin
613 if not (Text[I] in ['A'..'Z']) and not (Text[I] in ['a'..'z']) then begin
614 Result := False;
615 Break;
616 end;
617 Inc(I);
618 end;
619end;
620
621function TFormCheck.IsAcronym(Text: string): Boolean;
622const
623 MinAcronymLength = 2;
624begin
625 Result := (Length(Text) >= MinAcronymLength) and IsUppercaseAlpha(Text);
626end;
627
628function TFormCheck.IsDigit(Text: Char): Boolean;
629begin
630 Result := Text in ['0'..'9'];
631end;
632
633procedure TFormCheck.ReportDifferencies;
634var
635 I: Integer;
636 J: Integer;
637 Acronym: TAcronym;
638 Acronym2: TAcronym;
639 Meaning: TAcronymMeaning;
640 Meaning2: TAcronymMeaning;
641begin
642 // In content but not in summary
643 for I := 0 to AcronymDbContent.Acronyms.Count - 1 do begin
644 Acronym := TAcronym(AcronymDbContent.Acronyms[I]);
645 if Acronym.Meanings.Count > 1 then
646 ReportItems.AddNew(Format(SAcronymContentMultipleMeanings, [Acronym.Name,
647 Acronym.Meanings.GetNames]), Point(0, 0), rtWarning);
648 Acronym2 := AcronymDbSummary.Acronyms.SearchByName(Acronym.Name);
649 if not Assigned(Acronym2) then
650 for J := 0 to Acronym.Meanings.Count - 1 do begin
651 Meaning := TAcronymMeaning(Acronym.Meanings[J]);
652 if not Assigned(AcronymDbSummary.SearchAcronym(Acronym.Name, Meaning.Name, [sfCaseInsensitive])) then
653 ReportItems.AddNew(Format(SMissingAcronymContent, [Acronym.Name, Meaning.Name]), Point(0, 0), rtWarning);
654 end;
655 end;
656
657 // In summary but not in content
658 for I := 0 to AcronymDbSummary.Acronyms.Count - 1 do begin
659 Acronym := TAcronym(AcronymDbSummary.Acronyms[I]);
660 if Acronym.Meanings.Count > 1 then
661 ReportItems.AddNew(Format(SAcronymSummaryMultipleMeanings, [Acronym.Name, Acronym.Meanings.GetNames]), Point(0, 0), rtWarning);
662 Acronym2 := AcronymDbContent.Acronyms.SearchByName(Acronym.Name);
663 if not Assigned(Acronym2) then
664 for J := 0 to Acronym.Meanings.Count - 1 do begin
665 Meaning := TAcronymMeaning(Acronym.Meanings[J]);
666 if not Assigned(AcronymDbContent.SearchAcronym(Acronym.Name, Meaning.Name, [sfCaseInsensitive])) then
667 ReportItems.AddNew(Format(SMissingAcronymSummary, [Acronym.Name, Meaning.Name]), Point(0, 0), rtWarning);
668 end;
669 end;
670
671 // With different meaning
672 for I := 0 to AcronymDbSummary.Acronyms.Count - 1 do begin
673 Acronym := TAcronym(AcronymDbSummary.Acronyms[I]);
674 Acronym2 := AcronymDbContent.Acronyms.SearchByName(Acronym.Name);
675 if Assigned(Acronym2) then begin
676 if (Acronym.Meanings.Count = 1) and (Acronym2.Meanings.Count = 1) then begin
677 Meaning := TAcronymMeaning(Acronym.Meanings[0]);
678 Meaning2 := TAcronymMeaning(Acronym2.Meanings[0]);
679 if not StringEqual(Meaning.Name, Meaning2.Name) then
680 ReportItems.AddNew(Format(SAcronymWithDifferentMeaning, [Acronym.Name, Meaning2.Name, Meaning.Name]), Point(0, 0), rtWarning);
681 end else
682 ReportItems.AddNew(Format(SAcronymWithDifferentMeaningCount, [Acronym.Name, Acronym2.Meanings.Count, Acronym.Meanings.Count]), Point(0, 0), rtWarning);
683 end;
684 end;
685end;
686
687function TFormCheck.WordContainsLetters(Text, Letters: string): Boolean;
688var
689 I: Integer;
690 LetterIndex: Integer;
691begin
692 Result := True;
693 for I := 1 to Length(Letters) do begin
694 LetterIndex := Pos(Letters[I], Text);
695 if LetterIndex > 0 then begin
696 Text := Copy(Text, LetterIndex + 1, Length(Text));
697 end else begin
698 Result := False;
699 Break;
700 end;
701 end;
702end;
703
704function TFormCheck.StringEqual(Text1, Text2: string): Boolean;
705begin
706 if CheckBoxCaseSensitive.Checked then Result := Text1 = Text2
707 else Result := LowerCase(Text1) = LowerCase(Text2);
708end;
709
710procedure TFormCheck.ReloadReport;
711begin
712 ListViewReport.Items.Count := ReportItems.Count;
713 ListViewReport.Refresh;
714end;
715
716procedure TFormCheck.UpdateInterface;
717begin
718 LabelAcronymCountContent.Caption := SAcronymCountContent + ' ' + IntToStr(AcronymDbContent.GetMeaningsCount);
719 LabelAcronymCountSummary.Caption := SAcronymCountSummary + ' ' + IntToStr(AcronymDbSummary.GetMeaningsCount);
720end;
721
722procedure TFormCheck.LoadConfig;
723begin
724 with TRegistryEx.Create do
725 try
726 RootKey := RegistryRootHKEY[Core.ApplicationInfo1.RegistryRoot];
727 OpenKey(Core.ApplicationInfo1.RegistryKey, True);
728 EditSummaryStart.Text := ReadStringWithDefault('SummaryStart', 'ACRONYMS AND ABBREVIATIONS');
729 EditSummaryEnd.Text := ReadStringWithDefault('SummaryEnd', 'Appendix');
730 LastDocumentFileName := ReadStringWithDefault('LastDocumentFileName', '');
731 CheckBoxCaseSensitive.Checked := ReadBoolWithDefault('CaseSensitiveComparison', False);
732 finally
733 Free;
734 end;
735end;
736
737procedure TFormCheck.SaveConfig;
738begin
739 with TRegistryEx.Create do
740 try
741 RootKey := RegistryRootHKEY[Core.ApplicationInfo1.RegistryRoot];
742 OpenKey(Core.ApplicationInfo1.RegistryKey, True);
743 WriteString('SummaryStart', EditSummaryStart.Text);
744 WriteString('SummaryEnd', EditSummaryEnd.Text);
745 WriteString('LastDocumentFileName', LastDocumentFileName);
746 WriteBool('CaseSensitiveComparison', CheckBoxCaseSensitive.Checked);
747 finally
748 Free;
749 end;
750end;
751
752end.
753
Note: See TracBrowser for help on using the repository browser.