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     procedure SetTokens(index: integer ; argline:String);
34     function Getlistpath() : String;
35     procedure Setlistpath(const Value : String);
36     function LoadListFile(path :String;listStringList : TStringList) : Boolean;
37     function ReadNGwordslist(line : Integer) : Boolean;
38     function LoadFromSetResNumFile(SetResNumFile : String) : Boolean;
39   public
40     { Public \90é\8c¾ }
41     constructor Create; // \83R\83\93\83X\83g\83\89\83N\83^
42     destructor Destroy; override; // \83f\83X\83g\83\89\83N\83^
43     property Deleterlo: Boolean read FDeleterlo write FDeleterlo  default false;
44     property Replaceul: Boolean read FReplaceul write FReplaceul  default false;
45     property Reverse: Boolean read FReverse write FReverse  default false;
46     property CreateNGwordFile: Boolean read FCreateNGwordFile write FCreateNGwordFile;
47     property AbonString : String read FAbonString write FAbonString;
48     property  AbonPopupRes : Boolean read FAbonPopupRes write FAbonPopupRes default false;
49     property listpath : String read Getlistpath write Setlistpath;
50     property NGwordFileIndex : Integer read FNGwordFileIndex write FNGwordFileIndex default 0;
51     property NGwordname : String read FNGwordname write FNGwordname;
52         property ReturnNGwordLineNum : Boolean read FReturnNGwordLineNum write FReturnNGwordLineNum default false;
53     property SetNGResAnchor : Boolean read FSetNGResAnchor write FSetNGResAnchor default false;
54     procedure Setroot(root :String);
55     function Getroot() : String;
56
57     function Getfullpath(argpath : String) : String;
58     procedure SetNGwordpath(path :String);
59     function GetNGwordpath() : String;
60     function LoadFromNGwordFile(path :String) : Boolean;
61     function ReLoadFromNGwordFile() : Boolean;
62     procedure LoadFromStringList( bufstl : TStringList );
63     function CheckAbonPopupRes(line : String) :Boolean;
64     function FindNGwords(line : String) : Boolean; overload;//1\83\89\83C\83\93\82¸\82Â\97p\81B
65     function FindNGwords(line : String; var NGwordsLineNum : Integer) : Boolean; overload;//1\83\89\83C\83\93\82¸\82Â\97p\81B
66     function FindNGwords(line : String; var NGwordsLineNum : Integer; var Invisible : Boolean) : Boolean; overload;//1\83\89\83C\83\93\82¸\82Â\97p\81B
67     function Cutoff(line : String) : Boolean; //CutOff\92l\88È\8fã\8cÂ\82Ì\93¯\82\89p\90\94\82ª\95À\82ñ\82Å\82¢\82½\82çtrue
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     //\8cÂ\95Ê\82 \82Ú\81`\82ñ\82µ\82å\82è
74     procedure IndividualAbon(var ThreadStrings : TStringList; SetResNumFile : String); overload;
75         procedure IndividualAbon(var ResString : String; SetResNumFile : String; ResNumber : Integer); overload;
76     procedure AddIndividualAbon( ResNum : Integer ; option : Integer);
77     procedure DeleteIndividualAbon( ResNum : Integer);
78     function GetAbonResCount() : Integer;
79     function GetAbonResString(Num : Integer) : String;
80     function CheckIndividualAbonList(ResNum : Integer) : Boolean;
81     //--
82     function ExecuteFile(datfilepath : String; NGwordpath : String) : Boolean; overload;//DAT\83t\83@\83C\83\8b\82ð\92¼\82É\82¢\82\82é
83     function ExecuteFile(datfilepath : String; resnum : Integer) : Boolean; overload; //DAT\83t\83@\83C\83\8b\82ð\92¼\82É\82¢\82\82é
84     function ExecuteFile(datfilepath : String; firstres : Integer; count : Integer) : Boolean; overload; //DAT\83t\83@\83C\83\8b\82ð\92¼\82É\82¢\82\82é
85     function ReverseExecuteFile(datfilepath : String) : Boolean; overload; //DAT\83t\83@\83C\83\8b\82ð\92¼\82É\82¢\82\82é
86     function ReverseExecuteFile(datfilepath : String; resnum : Integer) : Boolean; overload; //DAT\83t\83@\83C\83\8b\82ð\92¼\82É\82¢\82\82é
87     function ReverseExecuteFile(datfilepath : String; firstres : Integer; count : Integer) : Boolean; overload; //DAT\83t\83@\83C\83\8b\82ð\92¼\82É\82¢\82\82é
88     //--
89     procedure EditNGwords();  //NGword.txt\82ð\8aJ\82­\81B
90     function ShowAllTokens() : String;  //\83f\83o\83b\83O\97p
91     //--
92     procedure GoHome();//List\82Ì\82P\8ds\96Ú\82ð\93Ç\82Þ
93     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Þ
94     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Þ
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
292 //****************************************************************************//
293 //NG\83\8f\81[\83h\82ª\8aÜ\82Ü\82ê\82Ä\82½\82çtrue\82ð\95Ô\82·\81B
294 function TAbon.FindNGwords(line : String) : Boolean;
295 var
296     lines : Integer;
297     cells : Integer;
298     hit : Boolean;
299     bufline : String;
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             for cells := 0 to High(Ftokens[lines]) do begin
307                 if AnsiPos(Ftokens[lines][cells],bufline) = 0 then begin
308                         hit := false;
309                     break;
310                 end else begin
311                         Delete(bufline,AnsiPos(Ftokens[lines][cells],bufline),Length(Ftokens[lines][cells]));
312                 end;
313             end;
314             if hit = true then begin
315                 break;
316             end;
317         end;
318     end;
319     Result := hit;
320 end;
321 //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·
322 function TAbon.FindNGwords(line : String; var NGwordsLineNum : Integer) : Boolean;
323 var
324     lines : Integer;
325     cells : Integer;
326     hit : Boolean;
327     bufline : String;
328 begin
329     hit := false;
330     if AnsiPos(FAbonString,line) <> 1 then begin
331         for lines := 0 to High(Ftokens) do begin
332                 hit := true;
333             bufline := line;
334             for cells := 0 to High(Ftokens[lines]) do begin
335                 if AnsiPos(Ftokens[lines][cells],bufline) = 0 then begin
336                         hit := false;
337                     break;
338                 end else begin
339                         Delete(bufline,AnsiPos(Ftokens[lines][cells],bufline),Length(Ftokens[lines][cells]));
340                 end;
341             end;
342             if hit = true then begin
343                 NGwordsLineNum := lines + 1;
344                 break;
345             end;
346         end;
347     end;
348     Result := hit;
349 end;
350 //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
351 //\82à\82µ\82à\93§\96¾\82 \82Ú\81`\82ñ\82É\82·\82é\82È\82çInbisible\82ðtrue\82É\82µ\82Ä\95Ô\82·
352 function TAbon.FindNGwords(line : String; var NGwordsLineNum : Integer; var Invisible : Boolean) : Boolean; //1\83\89\83C\83\93\82¸\82Â\97p\81B
353 var
354     lines : Integer;
355     cells : Integer;
356     hit : Boolean;
357     bufline : String;
358     start : Integer;
359 begin
360     hit := false;
361     if AnsiPos(FAbonString,line) <> 1 then begin
362         for lines := 0 to High(Ftokens) do begin
363                 hit := true;
364             bufline := line;
365             if Ftokens[lines][0] <> ''  then begin
366                 Invisible := false;
367                 start := 0;
368             end else begin
369                 Invisible := true;
370                 start := 1;
371             end;
372
373             for cells := start to High(Ftokens[lines]) do begin
374                 if AnsiPos(Ftokens[lines][cells],bufline) = 0 then begin
375                     hit := false;
376                     break;
377                 end else begin
378                     Delete(bufline,AnsiPos(Ftokens[lines][cells],bufline),Length(Ftokens[lines][cells]));
379                 end;
380             end;
381             if hit = true then begin
382                 NGwordsLineNum := lines + 1;
383                 break;
384             end;
385         end;
386     end;
387     Result := hit;
388 end;
389
390 //CutOff\92l\88È\8fã\8cÂ\82Ì\93¯\82\89p\90\94\82ª\95À\82ñ\82Å\82¢\82½\82çtrue
391 function TAbon.Cutoff(line : String) : Boolean;
392 var
393     i : Integer;
394     sheed : AnsiChar;
395     buf : String;
396     ret : Bool;
397 begin
398     ret := false;
399     if FCutoffNum <> 0 then begin
400         for i := 65 to 90 do begin
401             sheed := Chr(i);
402             buf := DupeString(sheed, FCutoffNum);
403             if AnsiContainsText(line, buf) = true then begin
404                 ret := true;
405                 break;
406             end;
407         end;
408     end;
409     Result := ret;
410 end;
411 //\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
412 procedure TAbon.Execute(var ThreadStrings : TStringList);
413 var
414     i : Integer;
415     NGwordsLine : Integer;
416     bufline : String;
417     invisi : Boolean;
418 begin
419     for i:=0 to ThreadStrings.Count - 1 do begin
420         NGwordsLine := 0;
421         if FindNGwords(ThreadStrings.Strings[i], NGwordsLine ,invisi) <> Reverse  then begin
422             if invisi = true then begin
423                 ThreadStrings.Strings[i] := '';
424             end else begin
425                 if not ReturnNGwordLineNum and not SetNGResAnchor then begin
426                     ThreadStrings.Strings[i] := FAbonString;
427                 end else if not ReturnNGwordLineNum then begin
428                     ThreadStrings.Strings[i] := Format('&nbsp;<>&nbsp;<>&nbsp;<>&gt;%d<><>',[(i+1)]);
429                 end else if not SetNGResAnchor then begin
430                     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]);
431                 end else begin
432                     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)]);
433                 end;
434             end;
435         end else begin
436             bufline := ThreadStrings.Strings[i];
437             if Deleterlo = true then begin
438                 bufline := CustomStringReplace(bufline,'&rlo;','');
439                 bufline := CustomStringReplace(bufline,'&lro;','');
440             end;
441             if Replaceul = true then begin
442                 bufline := CustomStringReplace( bufline,'<ul>','<br>' );
443                 bufline := CustomStringReplace( bufline,'</ul>','<br>' );
444             end;
445             ThreadStrings.Strings[i] := bufline;
446         end;
447     end;
448 end;
449 procedure TAbon.Execute(var ResString : String; ResNumber : Integer);
450 var
451     i : Integer;
452     NGwordsLine : Integer;
453     bufline : String;
454     invisi : Boolean;
455 begin
456     NGwordsLine := 0;
457     if FindNGwords(ResString, NGwordsLine ,invisi) <> Reverse  then begin
458         if invisi = true then begin
459             ResString := '';
460         end else begin
461             if not ReturnNGwordLineNum and not SetNGResAnchor then begin
462                 ResString := FAbonString;
463             end else if not ReturnNGwordLineNum then begin
464                 ResString := Format('&nbsp;<>&nbsp;<>&nbsp;<>&gt;%d<><>',[(ResNumber)]);
465             end else if not SetNGResAnchor then begin
466                 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]);
467             end else begin
468                 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)]);
469             end;
470         end;
471     end else begin
472         bufline := ResString;
473         if Deleterlo = true then begin
474             bufline := CustomStringReplace( bufline,'&rlo;','' );
475             bufline := CustomStringReplace( bufline,'&lro;','' );
476         end;
477         if Replaceul = true then begin
478             bufline := CustomStringReplace( bufline,'<ul>','<br>' );
479             bufline := CustomStringReplace( bufline,'</ul>','<br>' );
480         end;
481         ResString := bufline;
482     end;
483 end;
484
485 procedure TAbon.Execute(var ThreadStrings : TStringList; NGwords : TStringList);
486 var
487     i : Integer;
488 begin
489     SetLength(Ftokens,NGwords.Count);
490     for i := 0  to NGwords.Count -1 do begin
491         SetTokens(i , NGwords.Strings[i]);
492     end;
493     Execute(ThreadStrings);
494
495 end;
496 procedure TAbon.Execute(var ThreadStrings : TStringList; NGwords : TStrings);
497 var
498     i : Integer;
499     buf : TStringList;
500 begin
501     buf := TStringList.Create;
502     buf.AddStrings(NGwords);
503     SetLength(Ftokens,buf.Count);
504     for i := 0  to buf.Count -1 do begin
505         SetTokens(i , buf.Strings[i]);
506     end;
507     Execute(ThreadStrings);
508     buf.Free;
509 end;
510
511
512 //****************************************************************************//
513 //DAT\82ð\92¼\82É\82¢\82\82é\93z\82ç===========================================================
514 //NG\83\8f\81[\83h\82ð\8aÜ\82Þ\83\8c\83X\82Ì\90æ\93ª\82É\82 \82Ú\81[\82ñ\82ð\91}\93ü
515 function TAbon.ExecuteFile(datfilepath : String; NGwordpath : String) : Boolean; //DAT\83t\83@\83C\83\8b\82ð\92¼\82É\82¢\82\82é
516 var
517     datstl : TStringList;
518     ret : Boolean;
519     i : Integer;
520 begin
521     datstl := TStringList.Create;
522     ret := true;
523     try
524         try
525             datstl.LoadFromFile(datfilepath);
526             for i := 0 to datstl.Count -1 do begin
527                 if FindNGwords(datstl.Strings[i]) = true  then begin
528                     datstl.Strings[i] := FAbonString + datstl.Strings[i]
529                 end;
530             end;
531
532             datstl.SaveToFile(datfilepath);
533         except
534             ret := false;
535         end;
536     finally
537         datstl.Free;
538     end;
539     Result := ret;
540
541 end;
542 //\8ew\92è\82³\82ê\82½\83\8c\83X\94Ô\82Ì\90æ\93ª\82É\82 \82Ú\81[\82ñ\91}\93ü
543 function TAbon.ExecuteFile(datfilepath : String; resnum : Integer) : Boolean; //DAT\83t\83@\83C\83\8b\82ð\92¼\82É\82¢\82\82é
544 var
545     datstl : TStringList;
546     ret : Boolean;
547 begin
548     ret := true;
549     datstl := TStringList.Create;
550     try
551         try
552             datstl.LoadFromFile(datfilepath);
553             if (resnum > 0) and (resnum <= datstl.Count) then begin
554                 if AnsiPos(FAbonString, datstl.Strings[resnum-1]) <> 1 then begin
555                     datstl.Strings[resnum-1] := FAbonString + datstl.Strings[resnum-1];
556                 end;
557             end;
558             datstl.SaveToFile(datfilepath);
559         except
560             ret := false;
561         end;
562     finally
563         datstl.Free;
564     end;
565     Result := ret;
566 end;
567 //firstres\82©\82çcount\8cÂ\82Ì\83\8c\83X\82Ì\90æ\93ª\82É\82 \82Ú\81[\82ñ\91}\93ü
568 function TAbon.ExecuteFile(datfilepath : String; firstres : Integer; count : Integer) : Boolean; //DAT\83t\83@\83C\83\8b\82ð\92¼\82É\82¢\82\82é
569 var
570     datstl : TStringList;
571     i : Integer;
572     endnum : Integer; //\8fI\82í\82è\82Ì\83\8c\83X\94Ô
573     ret : Boolean;
574 begin
575     ret := true;
576     datstl := TStringList.Create;
577     try
578         try
579             datstl.LoadFromFile(datfilepath);
580             if (firstres > 0) and (firstres <= datstl.Count) then begin
581                 if firstres + count -1 > datstl.Count then begin
582                     endnum := datstl.Count;
583                 end else if count <= 0 then begin
584                     endnum := firstres + 1;
585                 end else begin
586                     endnum := firstres + count -1;
587                 end;
588
589                 for i := firstres to endnum do begin
590                     if AnsiPos(FAbonString, datstl.Strings[i-1]) <> 1 then begin
591                         datstl.Strings[i-1] := FAbonString + datstl.Strings[i-1];
592                     end;
593                 end;
594             end;
595             datstl.SaveToFile(datfilepath);
596         except
597             ret := false;
598         end;
599     finally
600         datstl.Free;
601     end;
602     Result := ret;
603 end;
604 //DAT\82ð\92¼\82É\82¢\82\82é\93z\82ç==========\82±\82±\82Ü\82Å=========================================
605
606 //\8c³\82É\96ß\82·\93z\82ç==================================================================
607 function TAbon.ReverseExecuteFile(datfilepath : String) : Boolean; //DAT\83t\83@\83C\83\8b\82ð\92¼\82É\82¢\82\82é
608 var
609     datstl : TStringList;
610     i : Integer;
611     buf : String;
612     ret : Boolean;
613 begin
614     ret := true;
615     datstl := TStringList.Create;
616     try
617         try
618             datstl.LoadFromFile(datfilepath);
619             for i:=0 to datstl.Count -1  do begin
620                 if AnsiPos(FAbonString, datstl.Strings[i]) = 1 then begin
621                     buf := datstl.Strings[i];
622                     Delete(buf,1,Length(FAbonString));
623                     datstl.Strings[i] := buf;
624                 end;
625             end;
626             datstl.SaveToFile(datfilepath);
627         except
628             ret := false;
629         end;
630     finally
631         datstl.Free;
632     end;
633     Result := ret;
634
635 end;
636 function TAbon.ReverseExecuteFile(datfilepath : String; resnum : Integer) : Boolean; //DAT\83t\83@\83C\83\8b\82ð\92¼\82É\82¢\82\82é
637 var
638     datstl : TStringList;
639     buf : String;
640     ret : Boolean;
641 begin
642     ret := true;
643     datstl := TStringList.Create;
644     try
645         try
646             datstl.LoadFromFile(datfilepath);
647             if (resnum > 0) and (resnum <= datstl.Count) then begin
648                 if AnsiPos(FAbonString, datstl.Strings[resnum-1]) = 1 then begin
649                     buf := datstl.Strings[resnum-1];
650                     Delete(buf,1,Length(FAbonString));
651                     datstl.Strings[resnum-1] := buf;
652                 end;
653             end;
654             datstl.SaveToFile(datfilepath);
655         except
656             ret := false;
657         end;
658     finally
659         datstl.Free;
660     end;
661     Result := ret;
662
663 end;
664 function TAbon.ReverseExecuteFile(datfilepath : String; firstres : Integer; count : Integer) : Boolean;//DAT\83t\83@\83C\83\8b\82ð\92¼\82É\82¢\82\82é
665 var
666     datstl : TStringList;
667     i : Integer;
668     endnum : Integer; //\8fI\82í\82è\82Ì\83\8c\83X\94Ô
669     buf : String;
670     ret : Boolean;
671 begin
672     ret := true;
673     datstl := TStringList.Create;
674     try
675         try
676             datstl.LoadFromFile(datfilepath);
677             if (firstres > 0) and (firstres <= datstl.Count) then begin
678                 if firstres + count -1 > datstl.Count then begin
679                     endnum := datstl.Count;
680                 end else if count <= 0 then begin
681                     endnum := firstres + 1;
682                 end else begin
683                     endnum := firstres + count -1;
684                 end;
685                 for i := firstres to endnum do begin
686                     if AnsiPos(FAbonString, datstl.Strings[i-1]) = 1 then begin
687                         buf := datstl.Strings[i-1];
688                         Delete(buf,1,Length(FAbonString));
689                         datstl.Strings[i-1] := buf;
690                     end;
691                 end;
692             end;
693             datstl.SaveToFile(datfilepath);
694         except
695             ret := false;
696         end;
697     finally
698         datstl.Free;
699     end;
700     Result := ret;
701 end;
702 //\8c³\82É\96ß\82·\93z\82ç=================\82±\82±\82Ü\82Å=========================================
703 //\8c»\8dÝ\83Z\83b\83g\82³\82ê\82Ä\82¢\82éNGword.txt\82ð\8aJ\82­
704 procedure TAbon.EditNGwords();
705 begin
706     ShellExecute(0 ,nil,PChar(FNGwordpath),nil,nil,SW_SHOW);
707 end;
708 //\83|\83b\83v\83A\83b\83v\97p\94»\92è\8aÖ\90\94
709 function TAbon.CheckAbonPopupRes(line : String) :Boolean;
710 begin
711     if AbonPopupRes = true then begin
712         Result := FindNGwords(line);
713     end else begin
714         Result := false;
715     end;
716 end;
717 //\95¡\90\94\82ÌNG\83\8f\81[\83h\83e\83L\83X\83g\82ð\93Ç\82Ý\8d\9e\82Þ==============================================
718 //List\83t\83@\83C\83\8b\82ð\93Ç\82Ý\8d\9e\82Þ
719 function TAbon.LoadListFile(path :String; listStringList : TStringList) : Boolean;
720 begin
721     try
722         listStringList.LoadFromFile(path);
723         Result := true;
724     except
725         listStringList.Append('\88ê\94Ê=NGword.txt');
726         listStringList.SaveToFile(path);
727         Result := false;
728     end;
729 end;
730 //List\82Ì\88ê\82Â\8e\9f\82ÌNG\83\8f\81[\83h\83t\83@\83C\83\8b\82ð\93Ç\82Ý\8d\9e\82Þ
731 function TAbon.GoForward() : Boolean;
732 begin
733     FNGwordFileIndex := FNGwordFileIndex + 1;
734     Result := ReadNGwordslist(FNGwordFileIndex);
735 end;
736 //List\82Ì\88ê\82Â\91O\82ÌNG\83\8f\81[\83h\83t\83@\83C\83\8b\82ð\93Ç\82Ý\8d\9e\82Þ
737 function TAbon.GoBack() : Boolean;
738 begin
739     FNGwordFileIndex := FNGwordFileIndex -1;
740     Result := ReadNGwordslist(FNGwordFileIndex);
741 end;
742 //List\82Ì\82P\8ds\96Ú\82ð\93Ç\82Þ
743 procedure TAbon.GoHome();
744 begin
745     FNGwordFileIndex := 0;
746     ReadNGwordslist(FNGwordFileIndex);
747 end;
748 //List\82Ìline\8ds\96Ú\82ð\93Ç\82Þ
749 function TAbon.ReadNGwordslist(line : Integer) : Boolean;
750 var
751     liststl : TStringList;
752     linebuf : String;
753 begin
754     liststl := TStringList.Create;
755     try
756         if LoadListFile(Flistpath,liststl) = true then begin
757             if line < 0 then begin
758                 line := liststl.Count - 1;
759                 FNGwordFileIndex := liststl.Count - 1;
760             end else if line > liststl.Count - 1 then begin
761                 line := 0;
762                 FNGwordFileIndex := 0;
763             end;
764             linebuf := liststl.Strings[line];
765             FNGwordname := Copy(linebuf,1,AnsiPos('=',linebuf)-1);
766             Delete(linebuf,1,AnsiPos('=',linebuf));
767             SetNGwordpath(linebuf);
768             Result := true;
769         end else begin
770             Result := false;
771         end
772     finally
773         liststl.Free;
774     end;
775
776 end;
777 //\95¡\90\94\82ÌNG\83\8f\81[\83h\83e\83L\83X\83g\82ð\93Ç\82Ý\8d\9e\82Þ=====\82±\82±\82Ü\82Å=================================
778 //\8cÂ\95Ê\82 \82Ú\81`\82ñ\8eÀ\8ds\8aÖ\90\94
779 procedure TAbon.IndividualAbon(var ThreadStrings : TStringList; SetResNumFile : String);
780 var
781         i : Integer;
782 begin
783         if FileExists(SetResNumFile) = true then begin
784         if LoadFromSetResNumFile(SetResNumFile) = true then begin
785                 for i := 0 to High(FAbonRes) do begin
786                  if (FAbonRes[i].Res <= ThreadStrings.Count) and (FAbonRes[i].Res > 0) then begin
787                         if FAbonRes[i].option = 0 then begin
788                         ThreadStrings.Strings[FAbonRes[i].Res-1] := '';
789                     end else begin
790                         ThreadStrings.Strings[FAbonRes[i].Res-1] := '\82 \82Ú\81`\82ñ<>\82 \82Ú\81`\82ñ<>\82 \82Ú\81`\82ñ<>\82 \82Ú\81`\82ñ<>';
791                     end;
792                  end;
793
794             end;
795         end;
796     end else begin
797         FIndividualFileName := SetResNumFile;
798         SetLength(FAbonRes,1);
799         FAbonRes[0].Res := 0;
800         FAbonRes[0].option := -1;
801     end;
802 end;
803 procedure TAbon.IndividualAbon(var ResString : String; SetResNumFile : String; ResNumber : Integer);
804 var
805         i : Integer;
806 begin
807         if FileExists(SetResNumFile) = true then begin
808         if LoadFromSetResNumFile(SetResNumFile) = true then begin
809                 for i := 0 to High(FAbonRes) do begin
810                  if FAbonRes[i].Res = ResNumber then begin
811                         if FAbonRes[i].option = 0 then begin
812                         ResString := '';
813                     end else begin
814                         ResString := '\82 \82Ú\81`\82ñ<>\82 \82Ú\81`\82ñ<>\82 \82Ú\81`\82ñ<>\82 \82Ú\81`\82ñ<>';
815                     end;
816                     Exit;
817                  end;
818             end;
819         end;
820     end else begin
821         FIndividualFileName := SetResNumFile;
822         SetLength(FAbonRes,1);
823         FAbonRes[0].Res := 0;
824         FAbonRes[0].option := -1;
825     end;
826 end;
827
828 //\8cÂ\95Ê\82 \82Ú\81`\82ñ\83t\83@\83C\83\8b\93Ç\82Ý\8d\9e\82Ý\8aÖ\90\94
829 function TAbon.LoadFromSetResNumFile(SetResNumFile : String) : Boolean;
830 var
831         bufStringList : TStringList;
832     bufLine : String;
833     i : Integer;
834 begin
835     bufStringList := TStringList.Create;
836     try
837         try
838                 bufStringList.LoadFromFile(SetResNumFile);
839             FIndividualFileName := SetResNumFile;
840             //\8bó\8ds\8dí\8f\9c
841             for i := bufStringList.Count-1 downto 0 do begin
842                         if bufStringList.Strings[i] = '' then begin
843                         bufStringList.Delete(i);
844                     end;
845             end;
846
847             //\83\81\83\82\83\8a\8am\95Û
848                 SetLength(FAbonRes,bufStringList.Count);
849             //\91ã\93ü
850             for i :=0 to bufStringList.Count - 1 do begin
851                         bufLine := Trim(bufStringList.Strings[i]);
852                     FAbonRes[i].Res :=  StrToInt(Copy(bufLine,1,AnsiPos('-',bufLine)-1));
853                 FAbonRes[i].option := StrToInt(Copy(bufLine,AnsiPos('-',bufLine)+1,1));
854             end;
855         except
856                 Result := false;
857             Exit;
858         end;
859     finally
860         bufStringList.Free;
861     end;
862     Result := true;
863 end;
864 //\8cÂ\95Ê\82 \82Ú\81`\82ñ\83t\83@\83C\83\8b\82É\92Ç\89Á
865 procedure TAbon.AddIndividualAbon( ResNum : Integer ; option : Integer);
866 var
867         IndividualFile : TStringList;
868     linebuf : String;
869     i : Integer;
870 begin
871     IndividualFile := TStringList.Create;
872         if FAbonRes[0].Res <> 0 then begin
873         for i := 0 to High(FAbonRes) do begin
874             if FAbonRes[i].Res <> ResNum then begin
875                         linebuf := IntToStr(FAbonRes[i].Res) + '-' + IntToStr(FabonRes[i].option);
876                 IndividualFile.Append(linebuf);
877             end;
878         end;
879     end;
880     linebuf := IntToStr(ResNum) + '-' + IntToStr(option);
881     IndividualFile.Append(linebuf);
882     try
883         IndividualFile.SaveToFile(FIndividualFileName);
884     finally
885         IndividualFile.Free;
886     end;
887 end;
888 //\8cÂ\95Ê\82 \82Ú\81`\82ñ\83t\83@\83C\83\8b\82©\82ç\8dí\8f\9c
889 procedure TAbon.DeleteIndividualAbon( ResNum : Integer);
890 var
891         IndividualFile : TStringList;
892     linebuf : String;
893     i : Integer;
894 begin
895     IndividualFile := TStringList.Create;
896         if FAbonRes[0].Res <> 0 then begin
897         for i := 0 to High(FAbonRes) do begin
898             if FAbonRes[i].Res <> ResNum then begin
899                         linebuf := IntToStr(FAbonRes[i].Res) + '-' + IntToStr(FabonRes[i].option);
900                 IndividualFile.Append(linebuf);
901             end;
902         end;
903     end;
904         if IndividualFile.Count <> 0 then begin
905         try
906                 IndividualFile.SaveToFile(FIndividualFileName);
907         finally
908                 IndividualFile.Free;
909         end;
910     end else begin
911         if FileExists(FIndividualFileName) = true then begin
912                 DeleteFile(FIndividualFileName);
913         end;
914     end;
915 end;
916 //\8cÂ\95Ê\82 \82Ú\81`\82ñ\82Ì\83\8a\83X\83g\82Ì\8cÂ\90\94\82ð\95Ô\82·
917 function TAbon.GetAbonResCount() : Integer;
918 var
919         i : Integer;
920 begin
921     if FAbonRes[0].Res = 0 then begin
922         Result := 0
923     end else begin
924                 i := High(FAbonRes);
925         Result := i+1;
926     end;
927 end;
928 //\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·
929 function TAbon.GetAbonResString(Num : Integer) : String;
930 begin
931         if (Num <= High(FAbonRes)) and (Num >= 0) then begin
932         Result := IntToStr(FAbonRes[Num].Res);
933     end else begin
934         Result := '';
935     end;
936 end;
937 //\83|\83b\83v\83A\83b\83v\82Ì\94»\92è\97p
938 function TAbon.CheckIndividualAbonList(ResNum : Integer) : Boolean;
939 var
940         i : Integer;
941 begin
942         if FAbonRes[0].Res <> 0 then begin
943         for i := 0 to High(FAbonRes) do begin
944                 if FAbonRes[i].Res = ResNum then begin
945                 Result := true;
946                 Exit;
947             end;
948         end;
949     end;
950     Result := false;
951     
952 end;
953 end.
954