OSDN Git Service

シリア語ブラクラ対策で";"で閉じてなくても削除するようにした
[gikonavigoeson/gikonavi.git] / AbonUnit.pas
1 unit AbonUnit;
2
3 interface
4 uses
5     Windows,Messages, ShellAPI, SysUtils, Classes,StdCtrls,StrUtils;
6
7 type
8   TIndiviAbon = record
9         Res: Integer;
10     option: Integer; // 0:\93§\96¾ 1:\92Ê\8fí\82 \82Ú\81[\82ñ
11   end;
12
13   TAbon = class(TObject)
14   private
15     { Private \90é\8c¾ }
16     Froot : String;
17     Flistpath : String;
18     FNGwordpath : String;
19     Ftokens : array of array of string;
20     FAbonRes : array of TIndiviAbon;
21     FAbonString : String;
22 //    FCutoffNum : Integer; //\82±\82Ì\90\94\88È\8fã\98A\91±\82·\82é\93¯\82\89p\8e\9a\82ðNG\83\8f\81[\83h\82Æ\82·\82é
23     FDeleterlo : Boolean; //&rlo;\82ð\8dí\82é\82© //\92Ç\89Á&lro;\82à\8dí\82é
24     FReplaceul :Boolean ; //<ul>\83^\83O\82ð<br>\83^\83O\82É\92u\8a·\82·\82é\82©
25     FReverse : Boolean ;  //NG\83\8f\81[\83h\82Å\82Ì\82 \82Ú\81`\82ñ\82Ì\8c\8b\89Ê\82ð\94½\93]\82³\82¹\82é\82©
26     FAbonPopupRes : Boolean; //\83\8c\83X\83|\83b\83v\83A\83b\83v\82Ì\8e\9e\82É\82 \82Ú\81[\82ñ\82·\82é\82©
27     FCreateNGwordFile : Boolean; //\8ew\92è\82³\82ê\82½path\82ÉNG\83\8f\81[\83htxt\82ª\96³\82©\82Á\82½\82Æ\82«\82É\8e©\93®\93I\82É\90\90¬\82·\82é\82©
28     FNGwordFileIndex : Integer; //\8c»\8dÝ\93Ç\82Ý\8d\9e\82ñ\82Å\82éNG\83\8f\81[\83h\82ªlist\82Ì\89½\8ds\96Ú\82©
29     FNGwordname : String; //\8c»\8dÝ\93Ç\82Ý\8d\9e\82ñ\82Å\82éNG\83\8f\81[\83h\82Ì\95\\8e¦\96¼
30     FIndividualFileName : String;       //\8cÂ\95Ê\82 \82Ú\81`\82ñ\82Ì\83t\83@\83C\83\8b\96¼
31     FReturnNGwordLineNum : Boolean;     //NG\83\8f\81[\83h\82Ì\8ds\90\94\82ð\95Ô\82·\81B
32     FSetNGResAnchor : Boolean; //NG\82É\8aY\93\96\82µ\82½\82Æ\82«\82É\96{\95\82É\82»\82Ì\83\8c\83X\82Ö\82Ì\83\8c\83X\83A\83\93\83J\81[\82ð\82Â\82¯\82é\82©\82Ç\82¤\82©
33     FDeleteSyria: Boolean;      //\83V\83\8a\83A\8cê\83u\83\89\83N\83\89\91Î\8dô\81i&#1792~&#1871\81j
34     procedure SetTokens(index: integer ; argline:String);
35     function Getlistpath() : String;
36     procedure Setlistpath(const Value : String);
37     function LoadListFile(path :String;listStringList : TStringList) : Boolean;
38     function ReadNGwordslist(line : Integer) : Boolean;
39     function LoadFromSetResNumFile(SetResNumFile : String) : Boolean;
40   public
41     { Public \90é\8c¾ }
42     constructor Create; // \83R\83\93\83X\83g\83\89\83N\83^
43     destructor Destroy; override; // \83f\83X\83g\83\89\83N\83^
44     property Deleterlo: Boolean read FDeleterlo write FDeleterlo  default false;
45     property Replaceul: Boolean read FReplaceul write FReplaceul  default false;
46     property Reverse: Boolean read FReverse write FReverse  default false;
47     property CreateNGwordFile: Boolean read FCreateNGwordFile write FCreateNGwordFile;
48     property AbonString : String read FAbonString write FAbonString;
49     property  AbonPopupRes : Boolean read FAbonPopupRes write FAbonPopupRes default false;
50     property listpath : String read Getlistpath write Setlistpath;
51     property NGwordFileIndex : Integer read FNGwordFileIndex write FNGwordFileIndex default 0;
52     property NGwordname : String read FNGwordname write FNGwordname;
53         property ReturnNGwordLineNum : Boolean read FReturnNGwordLineNum write FReturnNGwordLineNum default false;
54     property SetNGResAnchor : Boolean read FSetNGResAnchor write FSetNGResAnchor default false;
55     property DeleteSyria : Boolean read FDeleteSyria write FDeleteSyria default false;
56     procedure Setroot(root :String);
57     function Getroot() : String;
58
59     function Getfullpath(argpath : String) : String;
60     procedure SetNGwordpath(path :String);
61     function GetNGwordpath() : String;
62     function LoadFromNGwordFile(path :String) : Boolean;
63     function ReLoadFromNGwordFile() : Boolean;
64     procedure LoadFromStringList( bufstl : TStringList );
65     function CheckAbonPopupRes(line : String) :Boolean;
66         function FindNGwords(const line : String; var NGwordsLineNum : Integer; var Invisible : Boolean) : Boolean;//1\83\89\83C\83\93\82¸\82Â\97p\81B
67         function FindNGwordsEx(const line : String; var NGwordsLineNum : Integer; var Invisible : Boolean) : Boolean;//1\83\89\83C\83\93\82¸\82Â\97p\81B
68         //\82 \82Ú\81`\82ñ\8f\88\97\9d(NG\83\8f\81[\83h\82Å\82Ì\83t\83B\83\8b\83^\83\8a\83\93\83O)
69         procedure Execute(var ThreadStrings : TStringList); overload;
70         procedure Execute(var ThreadStrings : TStringList; NGwords : TStringList); overload;
71         procedure Execute(var ThreadStrings : TStringList; NGwords : TStrings); overload;
72         procedure Execute(var ResString : String; ResNumber : Integer); overload;       //\8eå\82Éplugin\82©\82ç\82ÌDat To HTML \97p
73         procedure ExecuteEx(var ThreadStrings : TStringList); overload;
74         procedure ExecuteEx(var ThreadStrings : TStringList; NGwords : TStringList); overload;
75         procedure ExecuteEx(var ThreadStrings : TStringList; NGwords : TStrings); overload;
76         procedure ExecuteEx(var ResString : String; ResNumber : Integer); overload;     //\8eå\82Éplugin\82©\82ç\82ÌDat To HTML \97p
77
78         //\8cÂ\95Ê\82 \82Ú\81`\82ñ\82µ\82å\82è
79         procedure IndividualAbon(var ThreadStrings : TStringList; SetResNumFile : String); overload;
80         procedure IndividualAbon(var ResString : String; SetResNumFile : String; ResNumber : Integer); overload;
81         procedure AddIndividualAbon( ResNum : Integer ; option : Integer);
82         procedure DeleteIndividualAbon( ResNum : Integer);
83         function GetAbonResCount() : Integer;
84         function GetAbonResString(Num : Integer) : String;
85         function CheckIndividualAbonList(ResNum : Integer) : Boolean;
86
87         procedure EditNGwords();  //NGword.txt\82ð\8aJ\82­\81B
88         function ShowAllTokens() : String;  //\83f\83o\83b\83O\97p
89         //--
90         procedure GoHome();//List\82Ì\82P\8ds\96Ú\82ð\93Ç\82Þ
91         function GoForward() : Boolean; //List\82Ì\88ê\82Â\8e\9f\82ÌNG\83\8f\81[\83h\83t\83@\83C\83\8b\82ð\93Ç\82Ý\8d\9e\82Þ
92         function GoBack() : Boolean; //List\82Ì\88ê\82Â\91O\82ÌNG\83\8f\81[\83h\83t\83@\83C\83\8b\82ð\93Ç\82Ý\8d\9e\82Þ
93         //--
94         function TreatSyria(AString: string): string;
95   end;
96 var
97         Abon1 :TAbon;
98 const
99         NGwordListFileName : String = 'NGwords.list';
100
101 implementation
102
103 uses MojuUtils;
104
105 constructor TAbon.Create;
106 begin
107         // \8f\89\8aú\89»
108         FAbonString := '&nbsp;<>&nbsp;<>&nbsp;<>&nbsp;&nbsp;<><>';
109         FCreateNGwordFile := true;
110         SetLength(FAbonRes,1);
111         FAbonRes[0].Res := 0;
112         FAbonRes[0].option := -1;
113
114 end;
115
116 destructor TAbon.Destroy;
117 begin
118         inherited;
119 end;
120 //root\82ÍExe\config\NGwords\83t\83H\83\8b\83_
121 procedure TAbon.Setroot(root :String);
122 var
123         bufStringList : TStringList;
124 begin
125         bufStringList := TStringList.Create;
126         try
127                 if not DirectoryExists(root) then begin
128                         CreateDir(root);
129                 end;
130                 if root[Length(root)] <> '\' then begin
131                         root := root + '\';
132                 end;
133                 Flistpath := root + NGwordListFileName;
134                 LoadListFile(Flistpath, bufStringList);
135         finally
136                 bufStringList.Free;
137         end;
138         Froot := root;
139 end;
140 function TAbon.Getroot() : String;
141 begin
142         Result := Froot;
143 end;
144 //NGwordpath\82ÍNGword.txt\82Ì\83t\83\8b\83p\83X
145 procedure TAbon.SetNGwordpath(path :String);
146 begin
147         FNGwordpath := Getfullpath(path);
148         LoadFromNGwordFile(FNGwordpath);
149 end;
150 function TAbon.GetNGwordpath() : String;
151 begin
152         Result :=  FNGwordpath;
153 end;
154 //\83t\83\8b\83p\83X\82Å\82È\82¯\82ê\82Î\83t\83\8b\83p\83X\82É\82µ\82Ä\95Ô\82·\81B
155 function TAbon.Getfullpath(argpath : String) : String;
156 begin
157         if AnsiPos(':\',argpath) <> 2 then begin  //\83h\83\89\83C\83u\82©\82ç\82Ì\83t\83\8b\83p\83X\82ª\96³\82¯\82ê\82Î
158                 if Getroot() = '' then begin
159                         Result := '';    //root\83p\83X\82ª\90Ý\92è\82³\82ê\82Ä\82È\82¢\82©\8bó\82É\82·\82é
160                 end else begin
161                         if (Froot[Length(Froot)] = '\') and (argpath[1] = '\') then begin  //\90æ\93ª\82Ì\\82ð\8dí\8f\9c
162                                 Delete(argpath,1,1);
163                         end;
164                         Insert( Getroot(), argpath , 1);//root\83p\83X\82ð\91}\93ü
165                         Result := argpath;
166                 end;
167         end else begin
168                 Result := argpath;
169         end;
170
171 end;
172 //NGword\83t\83@\83C\83\8b\82Ì\93Ç\82Ý\8d\9e\82Ý
173 function TAbon.LoadFromNGwordFile(path :String) : boolean;
174 var
175         bufstl : TStringList;
176 begin
177         path := Getfullpath(path);
178         if path = '' then begin
179                 Result := false;
180         end else begin
181                 bufstl := TStringList.Create;
182                 try
183                         try
184                                 bufstl.LoadFromFile(path);
185                                 LoadFromStringList( bufstl );
186                                 Result := true;
187                         except
188                                 if CreateNGwordFile = true then begin
189                                         bufstl.SaveToFile(path);
190                                 end;
191                                 Result := false;
192                         end;
193                 finally
194                         bufstl.Free;
195                 end;
196         end;
197
198 end;
199 //NGword\83\8a\83X\83g\93Ç\82Ý\8d\9e\82Ý
200 procedure TAbon.LoadFromStringList( bufstl : TStringList );
201 var
202         i : integer;
203 begin
204         try
205                 for i := bufstl.Count -1  downto 0 do begin
206                         if bufstl.Strings[i] = '' then begin
207                                 bufstl.Delete(i);
208                         end;
209                 end;
210                 SetLength(Ftokens,bufstl.Count);
211                 for i := 0  to bufstl.Count -1 do begin
212                         SetTokens(i , bufstl.Strings[i]);
213                 end;
214
215         except
216                 Exit;
217         end;
218 end;
219 //NGwordpath\82ª\8aù\82É\90Ý\92è\82³\82ê\82Ä\82¢\82é\82Æ\82«\82Ì\83\8a\83\8d\81[\83h\97p\8aÖ\90\94
220 function TAbon.ReLoadFromNGwordFile() : boolean;
221 begin
222         if GetNGwordpath() ='' then begin
223                 Result := false;
224         end else begin
225                 Result := LoadFromNGwordFile( GetNGwordpath() );
226         end;
227 end;
228 function TAbon.Getlistpath() : String;
229 begin
230         Result := Flistpath;
231 end;
232 procedure TAbon.Setlistpath(const Value : String);
233 begin
234         Flistpath := Getfullpath(Value);
235 end;
236 //\88ê\8ds\82Ì\92\86\82Ì\83g\81[\83N\83\93\82ð\90Ø\82è\95ª\82¯\82Ä\83Z\83b\83g
237 procedure TAbon.SetTokens(index: integer ; argline : String);
238 var
239         ret : Integer;
240         bufstl : TStringList;
241         i : Integer;
242         pos : Integer;
243         buftoken : String;
244 begin
245         pos := 0;
246         bufstl := TStringList.Create;
247         try
248                 if Length(argline) > 0 then begin
249                         pos := AnsiPos(#9,argline);
250                         while pos <> 0 DO begin
251                                 buftoken := Copy(argline,1,pos-1);
252                                 Delete(argline,1,pos);
253                                 if Length(buftoken) > 0 then begin
254                                         bufstl.Append(buftoken);
255                                 end else if ( bufstl.Count = 0 ) then begin
256                                         bufstl.Append('');
257                                 end;
258                                 pos := AnsiPos(#9,argline);
259                         end;
260                         if Length(argline) > 0 then begin
261                                 bufstl.Append(argline);
262                         end;
263                         ret := bufstl.Count;
264                         SetLength(Ftokens[index],ret);
265                         for i := 0 to bufstl.Count - 1  do begin
266                                 Ftokens[index][i] := bufstl.Strings[i];
267                         end;
268                 end;
269         finally
270                 bufstl.Free;
271         end;
272
273 end;
274 //Debug\97p\82¿\82á\82ñ\82ÆNG\83\8f\81[\83h\82ð\8fE\82¦\82Ä\82¢\82é\82©
275 function TAbon.ShowAllTokens() : String;
276 var
277         i : Integer;
278         j : Integer;
279         ret : String;
280 begin
281         for i := 0 to High(Ftokens) do begin
282                 for j := 0 to High(Ftokens[i]) do begin
283                         ret := ret + Ftokens[i][j];
284                 end;
285         end;
286         Result := ret;
287
288
289
290 end;
291 //NG\83\8f\81[\83h\82ª\8aÜ\82Ü\82ê\82Ä\82¢\82½\82çtrue\82ð\95Ô\82µ\81A\82»\82ÌNG\83\8f\81[\83h\82Ì\8ds\90\94\82ðNGwordsLineNum\82É\93ü\82ê\82Ä\95Ô\82·\81B
292 //\82à\82µ\82à\93§\96¾\82 \82Ú\81`\82ñ\82É\82·\82é\82È\82çInbisible\82ðtrue\82É\82µ\82Ä\95Ô\82·
293 function TAbon.FindNGwords(const line : String; var NGwordsLineNum : Integer; var Invisible : Boolean) : Boolean; //1\83\89\83C\83\93\82¸\82Â\97p\81B
294 var
295         lines : Integer;
296         cells : Integer;
297         hit : Boolean;
298         bufline : String;
299         start : Integer;
300 begin
301         hit := false;
302         if AnsiPos(FAbonString,line) <> 1 then begin
303                 for lines := 0 to High(Ftokens) do begin
304                         hit := true;
305                         bufline := line;
306                         if Ftokens[lines][0] <> ''  then begin
307                                 Invisible := false;
308                                 start := 0;
309                         end else begin
310                                 Invisible := true;
311                                 start := 1;
312                         end;
313
314                         for cells := start to High(Ftokens[lines]) do begin
315                                 if AnsiPos(Ftokens[lines][cells],bufline) = 0 then begin
316                                         hit := false;
317                                         break;
318                                 end else begin
319                                         Delete(bufline,AnsiPos(Ftokens[lines][cells],bufline),Length(Ftokens[lines][cells]));
320                                 end;
321                         end;
322                         if hit = true then begin
323                                 NGwordsLineNum := lines + 1;
324                                 break;
325                         end;
326                 end;
327         end;
328         Result := hit;
329 end;
330 //NG\83\8f\81[\83h\82ª\8aÜ\82Ü\82ê\82Ä\82¢\82½\82çtrue\82ð\95Ô\82µ\81A\82»\82ÌNG\83\8f\81[\83h\82Ì\8ds\90\94\82ðNGwordsLineNum\82É\93ü\82ê\82Ä\95Ô\82·\81B
331 //\82à\82µ\82à\93§\96¾\82 \82Ú\81`\82ñ\82É\82·\82é\82È\82çInbisible\82ðtrue\82É\82µ\82Ä\95Ô\82·
332 //\94¼\8ap\91S\8ap\96³\8e\8b
333 function TAbon.FindNGwordsEx(const line : String; var NGwordsLineNum : Integer; var Invisible : Boolean) : Boolean;//1\83\89\83C\83\93\82¸\82Â\97p\81B
334 var
335         lines : Integer;
336         cells : Integer;
337         hit : Boolean;
338         bufline : String;
339         start : Integer;
340 begin
341         hit := false;
342         if AnsiPos(FAbonString,line) <> 1 then begin
343                 for lines := 0 to High(Ftokens) do begin
344                         hit := true;
345                         bufline := line;
346                         if Ftokens[lines][0] <> ''  then begin
347                                 Invisible := false;
348                                 start := 0;
349                         end else begin
350                                 Invisible := true;
351                                 start := 1;
352                         end;
353
354                         for cells := start to High(Ftokens[lines]) do begin
355                                 if AnsiPos(Ftokens[lines][cells],bufline) = 0 then begin
356                                         hit := false;
357                                         break;
358                                 end else begin
359                                         Delete(bufline, AnsiPos(Ftokens[lines][cells],bufline),Length(Ftokens[lines][cells]));
360                                 end;
361                         end;
362                         if hit = true then begin
363                                 NGwordsLineNum := lines + 1;
364                                 break;
365                         end;
366                 end;
367         end;
368         Result := hit;
369 end;
370 //\96\96\94ö\82Ì\83u\81[\83\8b\92l\82Ítrue\82¾\82Æ\81ANG\83\8f\81[\83h\82ð\8aÜ\82Þ\82à\82Ì\82¾\82¯\82ð\95Ô\82·\81B
371 procedure TAbon.Execute(var ThreadStrings : TStringList);
372 var
373         i : Integer;
374         NGwordsLine : Integer;
375         bufline : String;
376         invisi : Boolean;
377 begin
378         for i:=0 to ThreadStrings.Count - 1 do begin
379                 NGwordsLine := 0;
380                 if FindNGwords(ThreadStrings.Strings[i], NGwordsLine ,invisi) <> Reverse  then begin
381                         if invisi = true then begin
382                                 ThreadStrings.Strings[i] := '';
383                         end else begin
384                                 if not ReturnNGwordLineNum and not SetNGResAnchor then begin
385                                         ThreadStrings.Strings[i] := FAbonString;
386                                 end else if not ReturnNGwordLineNum then begin
387                                         ThreadStrings.Strings[i] := Format('&nbsp;<>&nbsp;<>&nbsp;<>&gt;%d<><>',[(i+1)]);
388                                 end else if not SetNGResAnchor then begin
389                                         ThreadStrings.Strings[i] := Format('&nbsp;<>&nbsp;<>&nbsp;<><B> %d \8ds\96Ú\82ÌNG\83\8f\81[\83h\82ª\8aÜ\82Ü\82ê\82Ä\82¢\82Ü\82·\81B</B><><>',[NGwordsLine]);
390                                 end else begin
391                                         ThreadStrings.Strings[i] := Format('&nbsp;<>&nbsp;<>&nbsp;<><B> %d \8ds\96Ú\82ÌNG\83\8f\81[\83h\82ª\8aÜ\82Ü\82ê\82Ä\82¢\82Ü\82·\81B</B>&gt;%d <><>',[NGwordsLine,(i+1)]);
392                                 end;
393                         end;
394                 end else begin
395                         bufline := ThreadStrings.Strings[i];
396                         if Deleterlo = true then begin
397                                 bufline := CustomStringReplace(bufline,'&rlo;','');
398                                 bufline := CustomStringReplace(bufline,'&lro;','');
399                         end;
400                         if Replaceul = true then begin
401                                 bufline := CustomStringReplace( bufline,'<ul>','<br>' );
402                                 bufline := CustomStringReplace( bufline,'</ul>','<br>' );
403                         end;
404                         if DeleteSyria = true then
405                                 bufline := TreatSyria(bufline);
406                         ThreadStrings.Strings[i] := bufline;
407                 end;
408         end;
409 end;
410 procedure TAbon.Execute(var ResString : String; ResNumber : Integer);
411 var
412         NGwordsLine : Integer;
413         bufline : String;
414         invisi : Boolean;
415 begin
416         NGwordsLine := 0;
417         if FindNGwords(ResString, NGwordsLine ,invisi) <> Reverse  then begin
418                 if invisi = true then begin
419                         ResString := '';
420                 end else begin
421                         if not ReturnNGwordLineNum and not SetNGResAnchor then begin
422                                 ResString := FAbonString;
423                         end else if not ReturnNGwordLineNum then begin
424                                 ResString := Format('&nbsp;<>&nbsp;<>&nbsp;<>&gt;%d<><>',[(ResNumber)]);
425                         end else if not SetNGResAnchor then begin
426                                 ResString := Format('&nbsp;<>&nbsp;<>&nbsp;<><B> %d \8ds\96Ú\82ÌNG\83\8f\81[\83h\82ª\8aÜ\82Ü\82ê\82Ä\82¢\82Ü\82·\81B</B><><>',[NGwordsLine]);
427                         end else begin
428                                 ResString := Format('&nbsp;<>&nbsp;<>&nbsp;<><B> %d \8ds\96Ú\82ÌNG\83\8f\81[\83h\82ª\8aÜ\82Ü\82ê\82Ä\82¢\82Ü\82·\81B</B>&gt;%d <><>',[NGwordsLine,(ResNumber)]);
429                         end;
430                 end;
431         end else begin
432                 bufline := ResString;
433                 if Deleterlo = true then begin
434                         bufline := CustomStringReplace( bufline,'&rlo;','' );
435                         bufline := CustomStringReplace( bufline,'&lro;','' );
436                 end;
437                 if Replaceul = true then begin
438                         bufline := CustomStringReplace( bufline,'<ul>','<br>' );
439                         bufline := CustomStringReplace( bufline,'</ul>','<br>' );
440                 end;
441                 if DeleteSyria = true then
442                         bufline := TreatSyria(bufline);
443                 ResString := bufline;
444         end;
445 end;
446
447 procedure TAbon.Execute(var ThreadStrings : TStringList; NGwords : TStringList);
448 var
449         i : Integer;
450 begin
451         SetLength(Ftokens,NGwords.Count);
452         for i := 0  to NGwords.Count -1 do begin
453                 SetTokens(i , NGwords.Strings[i]);
454         end;
455         Execute(ThreadStrings);
456
457 end;
458 procedure TAbon.Execute(var ThreadStrings : TStringList; NGwords : TStrings);
459 var
460         i : Integer;
461         buf : TStringList;
462 begin
463         buf := TStringList.Create;
464         buf.AddStrings(NGwords);
465         SetLength(Ftokens,buf.Count);
466         for i := 0  to buf.Count -1 do begin
467                 SetTokens(i , buf.Strings[i]);
468         end;
469         Execute(ThreadStrings);
470         buf.Free;
471 end;
472
473 //\96\96\94ö\82Ì\83u\81[\83\8b\92l\82Ítrue\82¾\82Æ\81ANG\83\8f\81[\83h\82ð\8aÜ\82Þ\82à\82Ì\82¾\82¯\82ð\95Ô\82·\81B
474 procedure TAbon.ExecuteEx(var ThreadStrings : TStringList);
475 var
476         i : Integer;
477         NGwordsLine : Integer;
478         bufline : String;
479         invisi : Boolean;
480 begin
481         for i:=0 to ThreadStrings.Count - 1 do begin
482                 NGwordsLine := 0;
483                 if FindNGwordsEx(ThreadStrings.Strings[i], NGwordsLine ,invisi) <> Reverse  then begin
484                         if invisi = true then begin
485                                 ThreadStrings.Strings[i] := '';
486                         end else begin
487                                 if not ReturnNGwordLineNum and not SetNGResAnchor then begin
488                                         ThreadStrings.Strings[i] := FAbonString;
489                                 end else if not ReturnNGwordLineNum then begin
490                                         ThreadStrings.Strings[i] := Format('&nbsp;<>&nbsp;<>&nbsp;<>&gt;%d<><>',[(i+1)]);
491                                 end else if not SetNGResAnchor then begin
492                                         ThreadStrings.Strings[i] := Format('&nbsp;<>&nbsp;<>&nbsp;<><B> %d \8ds\96Ú\82ÌNG\83\8f\81[\83h\82ª\8aÜ\82Ü\82ê\82Ä\82¢\82Ü\82·\81B</B><><>',[NGwordsLine]);
493                                 end else begin
494                                         ThreadStrings.Strings[i] := Format('&nbsp;<>&nbsp;<>&nbsp;<><B> %d \8ds\96Ú\82ÌNG\83\8f\81[\83h\82ª\8aÜ\82Ü\82ê\82Ä\82¢\82Ü\82·\81B</B>&gt;%d <><>',[NGwordsLine,(i+1)]);
495                                 end;
496                         end;
497                 end else begin
498                         bufline := ThreadStrings.Strings[i];
499                         if Deleterlo = true then begin
500                                 bufline := CustomStringReplace(bufline,'&rlo;','');
501                                 bufline := CustomStringReplace(bufline,'&lro;','');
502                         end;
503                         if Replaceul = true then begin
504                                 bufline := CustomStringReplace( bufline,'<ul>','<br>' );
505                                 bufline := CustomStringReplace( bufline,'</ul>','<br>' );
506                         end;
507                         if DeleteSyria = true then
508                                 bufline := TreatSyria(bufline);
509                         ThreadStrings.Strings[i] := bufline;
510                 end;
511         end;
512 end;
513 procedure TAbon.ExecuteEx(var ResString : String; ResNumber : Integer);
514 var
515         NGwordsLine : Integer;
516         bufline : String;
517         invisi : Boolean;
518 begin
519         NGwordsLine := 0;
520         if FindNGwordsEx(ResString, NGwordsLine ,invisi) <> Reverse  then begin
521                 if invisi = true then begin
522                         ResString := '';
523                 end else begin
524                         if not ReturnNGwordLineNum and not SetNGResAnchor then begin
525                                 ResString := FAbonString;
526                         end else if not ReturnNGwordLineNum then begin
527                                 ResString := Format('&nbsp;<>&nbsp;<>&nbsp;<>&gt;%d<><>',[(ResNumber)]);
528                         end else if not SetNGResAnchor then begin
529                                 ResString := Format('&nbsp;<>&nbsp;<>&nbsp;<><B> %d \8ds\96Ú\82ÌNG\83\8f\81[\83h\82ª\8aÜ\82Ü\82ê\82Ä\82¢\82Ü\82·\81B</B><><>',[NGwordsLine]);
530                         end else begin
531                                 ResString := Format('&nbsp;<>&nbsp;<>&nbsp;<><B> %d \8ds\96Ú\82ÌNG\83\8f\81[\83h\82ª\8aÜ\82Ü\82ê\82Ä\82¢\82Ü\82·\81B</B>&gt;%d <><>',[NGwordsLine,(ResNumber)]);
532                         end;
533                 end;
534         end else begin
535                 bufline := ResString;
536                 if Deleterlo = true then begin
537                         bufline := CustomStringReplace( bufline,'&rlo;','' );
538                         bufline := CustomStringReplace( bufline,'&lro;','' );
539                 end;
540                 if Replaceul = true then begin
541                         bufline := CustomStringReplace( bufline,'<ul>','<br>' );
542                         bufline := CustomStringReplace( bufline,'</ul>','<br>' );
543                 end;
544                 if DeleteSyria = true then
545                         bufline := TreatSyria(bufline);
546                 ResString := bufline;
547         end;
548 end;
549
550 procedure TAbon.ExecuteEx(var ThreadStrings : TStringList; NGwords : TStringList);
551 var
552         i : Integer;
553 begin
554         SetLength(Ftokens,NGwords.Count);
555         for i := 0  to NGwords.Count -1 do begin
556                 SetTokens(i , NGwords.Strings[i]);
557         end;
558         ExecuteEx(ThreadStrings);
559
560 end;
561 procedure TAbon.ExecuteEx(var ThreadStrings : TStringList; NGwords : TStrings);
562 var
563         i : Integer;
564         buf : TStringList;
565 begin
566         buf := TStringList.Create;
567         buf.AddStrings(NGwords);
568         SetLength(Ftokens,buf.Count);
569         for i := 0  to buf.Count -1 do begin
570                 SetTokens(i , buf.Strings[i]);
571         end;
572         ExecuteEx(ThreadStrings);
573         buf.Free;
574 end;
575
576 //****************************************************************************//
577 //\8c»\8dÝ\83Z\83b\83g\82³\82ê\82Ä\82¢\82éNGword.txt\82ð\8aJ\82­
578 procedure TAbon.EditNGwords();
579 begin
580         ShellExecute(0 ,nil,PChar(FNGwordpath),nil,nil,SW_SHOW);
581 end;
582 //\83|\83b\83v\83A\83b\83v\97p\94»\92è\8aÖ\90\94
583 function TAbon.CheckAbonPopupRes(line : String) :Boolean;
584 var
585         i: Integer;
586         v: boolean;
587 begin
588         if AbonPopupRes = true then begin
589                 Result := FindNGwords(line, i ,v);
590         end else begin
591                 Result := false;
592         end;
593 end;
594 //\95¡\90\94\82ÌNG\83\8f\81[\83h\83e\83L\83X\83g\82ð\93Ç\82Ý\8d\9e\82Þ==============================================
595 //List\83t\83@\83C\83\8b\82ð\93Ç\82Ý\8d\9e\82Þ
596 function TAbon.LoadListFile(path :String; listStringList : TStringList) : Boolean;
597 begin
598     try
599         listStringList.LoadFromFile(path);
600         Result := true;
601     except
602         listStringList.Append('\88ê\94Ê=NGword.txt');
603         listStringList.SaveToFile(path);
604         Result := false;
605     end;
606 end;
607 //List\82Ì\88ê\82Â\8e\9f\82ÌNG\83\8f\81[\83h\83t\83@\83C\83\8b\82ð\93Ç\82Ý\8d\9e\82Þ
608 function TAbon.GoForward() : Boolean;
609 begin
610     FNGwordFileIndex := FNGwordFileIndex + 1;
611     Result := ReadNGwordslist(FNGwordFileIndex);
612 end;
613 //List\82Ì\88ê\82Â\91O\82ÌNG\83\8f\81[\83h\83t\83@\83C\83\8b\82ð\93Ç\82Ý\8d\9e\82Þ
614 function TAbon.GoBack() : Boolean;
615 begin
616     FNGwordFileIndex := FNGwordFileIndex -1;
617     Result := ReadNGwordslist(FNGwordFileIndex);
618 end;
619 //List\82Ì\82P\8ds\96Ú\82ð\93Ç\82Þ
620 procedure TAbon.GoHome();
621 begin
622     FNGwordFileIndex := 0;
623     ReadNGwordslist(FNGwordFileIndex);
624 end;
625 //List\82Ìline\8ds\96Ú\82ð\93Ç\82Þ
626 function TAbon.ReadNGwordslist(line : Integer) : Boolean;
627 var
628     liststl : TStringList;
629     linebuf : String;
630 begin
631     liststl := TStringList.Create;
632     try
633         if LoadListFile(Flistpath,liststl) = true then begin
634             if line < 0 then begin
635                 line := liststl.Count - 1;
636                 FNGwordFileIndex := liststl.Count - 1;
637             end else if line > liststl.Count - 1 then begin
638                 line := 0;
639                 FNGwordFileIndex := 0;
640             end;
641             linebuf := liststl.Strings[line];
642             FNGwordname := Copy(linebuf,1,AnsiPos('=',linebuf)-1);
643             Delete(linebuf,1,AnsiPos('=',linebuf));
644             SetNGwordpath(linebuf);
645             Result := true;
646         end else begin
647             Result := false;
648         end
649     finally
650         liststl.Free;
651     end;
652
653 end;
654 //\95¡\90\94\82ÌNG\83\8f\81[\83h\83e\83L\83X\83g\82ð\93Ç\82Ý\8d\9e\82Þ=====\82±\82±\82Ü\82Å=================================
655 //\8cÂ\95Ê\82 \82Ú\81`\82ñ\8eÀ\8ds\8aÖ\90\94
656 procedure TAbon.IndividualAbon(var ThreadStrings : TStringList; SetResNumFile : String);
657 var
658         i : Integer;
659 begin
660         if FileExists(SetResNumFile) = true then begin
661         if LoadFromSetResNumFile(SetResNumFile) = true then begin
662                 for i := 0 to High(FAbonRes) do begin
663                  if (FAbonRes[i].Res <= ThreadStrings.Count) and (FAbonRes[i].Res > 0) then begin
664                         if FAbonRes[i].option = 0 then begin
665                         ThreadStrings.Strings[FAbonRes[i].Res-1] := '';
666                     end else begin
667                         ThreadStrings.Strings[FAbonRes[i].Res-1] := '\82 \82Ú\81`\82ñ<>\82 \82Ú\81`\82ñ<>\82 \82Ú\81`\82ñ<>\82 \82Ú\81`\82ñ<>';
668                     end;
669                  end;
670
671             end;
672         end;
673     end else begin
674         FIndividualFileName := SetResNumFile;
675         SetLength(FAbonRes,1);
676         FAbonRes[0].Res := 0;
677         FAbonRes[0].option := -1;
678     end;
679 end;
680 procedure TAbon.IndividualAbon(var ResString : String; SetResNumFile : String; ResNumber : Integer);
681 var
682         i : Integer;
683 begin
684         if FileExists(SetResNumFile) = true then begin
685         if LoadFromSetResNumFile(SetResNumFile) = true then begin
686                 for i := 0 to High(FAbonRes) do begin
687                  if FAbonRes[i].Res = ResNumber then begin
688                         if FAbonRes[i].option = 0 then begin
689                         ResString := '';
690                     end else begin
691                         ResString := '\82 \82Ú\81`\82ñ<>\82 \82Ú\81`\82ñ<>\82 \82Ú\81`\82ñ<>\82 \82Ú\81`\82ñ<>';
692                     end;
693                     Exit;
694                  end;
695             end;
696         end;
697     end else begin
698         FIndividualFileName := SetResNumFile;
699         SetLength(FAbonRes,1);
700         FAbonRes[0].Res := 0;
701         FAbonRes[0].option := -1;
702     end;
703 end;
704
705 //\8cÂ\95Ê\82 \82Ú\81`\82ñ\83t\83@\83C\83\8b\93Ç\82Ý\8d\9e\82Ý\8aÖ\90\94
706 function TAbon.LoadFromSetResNumFile(SetResNumFile : String) : Boolean;
707 var
708         bufStringList : TStringList;
709     bufLine : String;
710     i : Integer;
711 begin
712     bufStringList := TStringList.Create;
713     try
714         try
715                 bufStringList.LoadFromFile(SetResNumFile);
716             FIndividualFileName := SetResNumFile;
717             //\8bó\8ds\8dí\8f\9c
718             for i := bufStringList.Count-1 downto 0 do begin
719                         if bufStringList.Strings[i] = '' then begin
720                         bufStringList.Delete(i);
721                     end;
722             end;
723
724             //\83\81\83\82\83\8a\8am\95Û
725                 SetLength(FAbonRes,bufStringList.Count);
726             //\91ã\93ü
727             for i :=0 to bufStringList.Count - 1 do begin
728                         bufLine := Trim(bufStringList.Strings[i]);
729                     FAbonRes[i].Res :=  StrToInt(Copy(bufLine,1,AnsiPos('-',bufLine)-1));
730                 FAbonRes[i].option := StrToInt(Copy(bufLine,AnsiPos('-',bufLine)+1,1));
731             end;
732         except
733                 Result := false;
734             Exit;
735         end;
736     finally
737         bufStringList.Free;
738     end;
739     Result := true;
740 end;
741 //\8cÂ\95Ê\82 \82Ú\81`\82ñ\83t\83@\83C\83\8b\82É\92Ç\89Á
742 procedure TAbon.AddIndividualAbon( ResNum : Integer ; option : Integer);
743 var
744         IndividualFile : TStringList;
745     linebuf : String;
746     i : Integer;
747 begin
748     IndividualFile := TStringList.Create;
749         if FAbonRes[0].Res <> 0 then begin
750         for i := 0 to High(FAbonRes) do begin
751             if FAbonRes[i].Res <> ResNum then begin
752                         linebuf := IntToStr(FAbonRes[i].Res) + '-' + IntToStr(FabonRes[i].option);
753                 IndividualFile.Append(linebuf);
754             end;
755         end;
756     end;
757     linebuf := IntToStr(ResNum) + '-' + IntToStr(option);
758     IndividualFile.Append(linebuf);
759     try
760         IndividualFile.SaveToFile(FIndividualFileName);
761     finally
762         IndividualFile.Free;
763     end;
764 end;
765 //\8cÂ\95Ê\82 \82Ú\81`\82ñ\83t\83@\83C\83\8b\82©\82ç\8dí\8f\9c
766 procedure TAbon.DeleteIndividualAbon( ResNum : Integer);
767 var
768         IndividualFile : TStringList;
769     linebuf : String;
770     i : Integer;
771 begin
772     IndividualFile := TStringList.Create;
773         if FAbonRes[0].Res <> 0 then begin
774         for i := 0 to High(FAbonRes) do begin
775             if FAbonRes[i].Res <> ResNum then begin
776                         linebuf := IntToStr(FAbonRes[i].Res) + '-' + IntToStr(FabonRes[i].option);
777                 IndividualFile.Append(linebuf);
778             end;
779         end;
780     end;
781         if IndividualFile.Count <> 0 then begin
782         try
783                 IndividualFile.SaveToFile(FIndividualFileName);
784         finally
785                 IndividualFile.Free;
786         end;
787     end else begin
788         if FileExists(FIndividualFileName) = true then begin
789                 DeleteFile(FIndividualFileName);
790         end;
791     end;
792 end;
793 //\8cÂ\95Ê\82 \82Ú\81`\82ñ\82Ì\83\8a\83X\83g\82Ì\8cÂ\90\94\82ð\95Ô\82·
794 function TAbon.GetAbonResCount() : Integer;
795 var
796         i : Integer;
797 begin
798     if FAbonRes[0].Res = 0 then begin
799         Result := 0
800     end else begin
801                 i := High(FAbonRes);
802         Result := i+1;
803     end;
804 end;
805 //\8cÂ\95Ê\82 \82Ú\81`\82ñ\82Ì\83\8a\83X\83g\82Ì\82\8e\8ds\96Ú\82Ì\83\8c\83X\82ð\95\8e\9a\97ñ\82Å\95Ô\82·
806 function TAbon.GetAbonResString(Num : Integer) : String;
807 begin
808         if (Num <= High(FAbonRes)) and (Num >= 0) then begin
809         Result := IntToStr(FAbonRes[Num].Res);
810     end else begin
811         Result := '';
812     end;
813 end;
814 //\83|\83b\83v\83A\83b\83v\82Ì\94»\92è\97p
815 function TAbon.CheckIndividualAbonList(ResNum : Integer) : Boolean;
816 var
817         i : Integer;
818 begin
819         if FAbonRes[0].Res <> 0 then begin
820         for i := 0 to High(FAbonRes) do begin
821                 if FAbonRes[i].Res = ResNum then begin
822                 Result := true;
823                 Exit;
824             end;
825         end;
826     end;
827         Result := false;
828
829 end;
830 //\83V\83\8a\83A\8cê\83u\83\89\83N\83\89\91Î\8dô
831 function TAbon.TreatSyria(AString: string): string;
832 var
833         //count: Integer; //(&#1792~&#1871)
834         pos: Integer;
835         tmp: string;
836 begin
837         pos := AnsiPos('&#18', AString);
838         while pos <> 0  do begin
839                 if StrToIntDef(Copy(AString, pos+4, 2), -1) > 0 then begin
840                         if (AString[pos+6] = ';' )  or (AString[pos+6] = ' ') then begin
841                                 tmp := tmp + Copy(AString, 1, pos - 1);
842                                 Delete(AString, 1, pos+6);
843                         end else if StrToIntDef(AString[pos+6], -1) = -1 then begin
844                                 tmp := tmp + Copy(AString, 1, pos - 1);
845                                 Delete(AString, 1, pos+5);
846                         end else begin
847                                 tmp := tmp + Copy(AString, 1, pos + 5);
848                                 Delete(AString, 1, pos+5);
849                         end;
850                 end else begin
851                         tmp := tmp + Copy(AString, 1, pos + 5);
852                         Delete(AString, 1, pos+5);
853                 end;
854                 pos := AnsiPos('&#18', AString);
855         end;
856         if Length(AString) > 0 then
857                 tmp := tmp + AString;
858         AString := tmp;
859         tmp := '';
860
861         pos := AnsiPos('&#179', AString);
862         while pos <> 0 do begin
863                 if StrToIntDef(Copy(AString, pos+5, 1), 0) > 2 then begin
864                         if (AString[pos+6] = ';') or (AString[pos+6] = ' ') then begin
865                                 tmp := tmp + Copy(AString, 1, pos - 1);
866                                 Delete(AString, 1, pos+6);
867                         end else if StrToIntDef(AString[pos+6], -1) = -1 then begin
868                                 tmp := tmp + Copy(AString, 1, pos - 1);
869                                 Delete(AString, 1, pos+5);
870                         end else begin
871                                 tmp := tmp + Copy(AString, 1, pos + 5);
872                                 Delete(AString, 1, pos+5);
873                         end;
874                 end else begin
875                         tmp := tmp + Copy(AString, 1, pos + 5);
876                         Delete(AString, 1, pos+5);
877                 end;
878                 pos := AnsiPos('&#179', AString);
879         end;
880         if Length(AString) > 0 then
881                 tmp := tmp + AString;
882         Result := tmp;
883 end;
884 end.
885