OSDN Git Service

(none)
[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 constructor TAbon.Create;
104 begin
105     // \8f\89\8aú\89»
106     FAbonString := '&nbsp;<>&nbsp;<>&nbsp;<>&nbsp;&nbsp;<><>';
107     FCreateNGwordFile := true;
108     SetLength(FAbonRes,1);
109     FAbonRes[0].Res := 0;
110     FAbonRes[0].option := -1;
111
112 end;
113
114 destructor TAbon.Destroy;
115 begin
116     inherited;
117 end;
118 //root\82ÍExe\config\NGwords\83t\83H\83\8b\83_
119 procedure TAbon.Setroot(root :String);
120 var
121     bufStringList : TStringList;
122 begin
123     bufStringList := TStringList.Create;
124     try
125         if not DirectoryExists(root) then begin
126             CreateDir(root);
127         end;
128         if root[Length(root)] <> '\' then begin
129             root := root + '\';
130         end;
131         Flistpath := root + NGwordListFileName;
132         LoadListFile(Flistpath, bufStringList);
133     finally
134         bufStringList.Free;
135     end;
136     Froot := root;
137 end;
138 function TAbon.Getroot() : String;
139 begin
140     Result := Froot;
141 end;
142 //NGwordpath\82ÍNGword.txt\82Ì\83t\83\8b\83p\83X
143 procedure TAbon.SetNGwordpath(path :String);
144 begin
145     FNGwordpath := Getfullpath(path);
146     LoadFromNGwordFile(FNGwordpath);
147 end;
148 function TAbon.GetNGwordpath() : String;
149 begin
150     Result :=  FNGwordpath;
151 end;
152 //\83t\83\8b\83p\83X\82Å\82È\82¯\82ê\82Î\83t\83\8b\83p\83X\82É\82µ\82Ä\95Ô\82·\81B
153 function TAbon.Getfullpath(argpath : String) : String;
154 begin
155     if AnsiPos(':\',argpath) <> 2 then begin  //\83h\83\89\83C\83u\82©\82ç\82Ì\83t\83\8b\83p\83X\82ª\96³\82¯\82ê\82Î
156         if Getroot() = '' then begin
157             Result := '';    //root\83p\83X\82ª\90Ý\92è\82³\82ê\82Ä\82È\82¢\82©\8bó\82É\82·\82é
158         end else begin
159             if (Froot[Length(Froot)] = '\') and (argpath[1] = '\') then begin  //\90æ\93ª\82Ì\\82ð\8dí\8f\9c
160                 Delete(argpath,1,1);
161             end;
162             Insert( Getroot(), argpath , 1);//root\83p\83X\82ð\91}\93ü
163             Result := argpath;
164         end;
165     end else begin
166         Result := argpath;
167     end;
168
169 end;
170 //NGword\83t\83@\83C\83\8b\82Ì\93Ç\82Ý\8d\9e\82Ý
171 function TAbon.LoadFromNGwordFile(path :String) : boolean;
172 var
173     bufstl : TStringList;
174 begin
175     path := Getfullpath(path);
176     if path = '' then begin
177         Result := false;
178     end else begin
179         bufstl := TStringList.Create;
180         try
181             try
182                 bufstl.LoadFromFile(path);
183                 LoadFromStringList( bufstl );
184                 Result := true;
185             except
186                 if CreateNGwordFile = true then begin
187                     bufstl.SaveToFile(path);
188                 end;
189                 Result := false;
190             end;
191         finally
192             bufstl.Free;
193         end;
194     end;
195
196 end;
197 //NGword\83\8a\83X\83g\93Ç\82Ý\8d\9e\82Ý
198 procedure TAbon.LoadFromStringList( bufstl : TStringList );
199 var
200     i : integer;
201 begin
202     try
203         for i := bufstl.Count -1  downto 0 do begin
204             if bufstl.Strings[i] = '' then begin
205                 bufstl.Delete(i);
206             end;
207         end;
208         SetLength(Ftokens,bufstl.Count);
209         for i := 0  to bufstl.Count -1 do begin
210             SetTokens(i , bufstl.Strings[i]);
211         end;
212
213     except
214         Exit;
215     end;
216 end;
217 //NGwordpath\82ª\8aù\82É\90Ý\92è\82³\82ê\82Ä\82¢\82é\82Æ\82«\82Ì\83\8a\83\8d\81[\83h\97p\8aÖ\90\94
218 function TAbon.ReLoadFromNGwordFile() : boolean;
219 begin
220     if GetNGwordpath() ='' then begin
221         Result := false;
222     end else begin
223         Result := LoadFromNGwordFile( GetNGwordpath() );
224     end;
225 end;
226 function TAbon.Getlistpath() : String;
227 begin
228     Result := Flistpath;
229 end;
230 procedure TAbon.Setlistpath(const Value : String);
231 begin
232     Flistpath := Getfullpath(Value);
233 end;
234 //\88ê\8ds\82Ì\92\86\82Ì\83g\81[\83N\83\93\82ð\90Ø\82è\95ª\82¯\82Ä\83Z\83b\83g
235 procedure TAbon.SetTokens(index: integer ; argline : String);
236 var
237     ret : Integer;
238     bufstl : TStringList;
239     i : Integer;
240     pos : Integer;
241     buftoken : String;
242 begin
243     pos := 0;
244     bufstl := TStringList.Create;
245     try
246         if Length(argline) > 0 then begin
247                 pos := AnsiPos(#9,argline);
248             while pos <> 0 DO begin
249                 buftoken := Copy(argline,1,pos-1);
250                 Delete(argline,1,pos);
251                 if Length(buftoken) > 0 then begin
252                                 bufstl.Append(buftoken);
253                 end else if ( bufstl.Count = 0 ) then begin
254                     bufstl.Append('');
255                 end;
256                     pos := AnsiPos(#9,argline);
257             end;
258                 if Length(argline) > 0 then begin
259                         bufstl.Append(argline);
260             end;
261                 ret := bufstl.Count;
262                 SetLength(Ftokens[index],ret);
263                 for i := 0 to bufstl.Count - 1  do begin
264                         Ftokens[index][i] := bufstl.Strings[i];
265                 end;
266         end;
267     finally
268         bufstl.Free;
269     end;
270
271 end;
272 //Debug\97p\82¿\82á\82ñ\82ÆNG\83\8f\81[\83h\82ð\8fE\82¦\82Ä\82¢\82é\82©
273 function TAbon.ShowAllTokens() : String;
274 var
275     i : Integer;
276     j : Integer;
277     ret : String;
278 begin
279     for i := 0 to High(Ftokens) do begin
280         for j := 0 to High(Ftokens[i]) do begin
281             ret := ret + Ftokens[i][j];
282         end;
283     end;
284     Result := ret;
285
286
287
288 end;
289
290 //****************************************************************************//
291 //NG\83\8f\81[\83h\82ª\8aÜ\82Ü\82ê\82Ä\82½\82çtrue\82ð\95Ô\82·\81B
292 function TAbon.FindNGwords(line : String) : Boolean;
293 var
294     lines : Integer;
295     cells : Integer;
296     hit : Boolean;
297     bufline : String;
298 begin
299     hit := false;
300     if AnsiPos(FAbonString,line) <> 1 then begin
301         for lines := 0 to High(Ftokens) do begin
302                 hit := true;
303             bufline := line;
304             for cells := 0 to High(Ftokens[lines]) do begin
305                 if AnsiPos(Ftokens[lines][cells],bufline) = 0 then begin
306                         hit := false;
307                     break;
308                 end else begin
309                         Delete(bufline,AnsiPos(Ftokens[lines][cells],bufline),Length(Ftokens[lines][cells]));
310                 end;
311             end;
312             if hit = true then begin
313                 break;
314             end;
315         end;
316     end;
317     Result := hit;
318 end;
319 //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·
320 function TAbon.FindNGwords(line : String; var NGwordsLineNum : Integer) : Boolean;
321 var
322     lines : Integer;
323     cells : Integer;
324     hit : Boolean;
325     bufline : String;
326 begin
327     hit := false;
328     if AnsiPos(FAbonString,line) <> 1 then begin
329         for lines := 0 to High(Ftokens) do begin
330                 hit := true;
331             bufline := line;
332             for cells := 0 to High(Ftokens[lines]) do begin
333                 if AnsiPos(Ftokens[lines][cells],bufline) = 0 then begin
334                         hit := false;
335                     break;
336                 end else begin
337                         Delete(bufline,AnsiPos(Ftokens[lines][cells],bufline),Length(Ftokens[lines][cells]));
338                 end;
339             end;
340             if hit = true then begin
341                 NGwordsLineNum := lines + 1;
342                 break;
343             end;
344         end;
345     end;
346     Result := hit;
347 end;
348 //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
349 //\82à\82µ\82à\93§\96¾\82 \82Ú\81`\82ñ\82É\82·\82é\82È\82çInbisible\82ðtrue\82É\82µ\82Ä\95Ô\82·
350 function TAbon.FindNGwords(line : String; var NGwordsLineNum : Integer; var Invisible : Boolean) : Boolean; //1\83\89\83C\83\93\82¸\82Â\97p\81B
351 var
352     lines : Integer;
353     cells : Integer;
354     hit : Boolean;
355     bufline : String;
356     start : Integer;
357 begin
358     hit := false;
359     if AnsiPos(FAbonString,line) <> 1 then begin
360         for lines := 0 to High(Ftokens) do begin
361                 hit := true;
362             bufline := line;
363             if Ftokens[lines][0] <> ''  then begin
364                 Invisible := false;
365                 start := 0;
366             end else begin
367                 Invisible := true;
368                 start := 1;
369             end;
370
371             for cells := start to High(Ftokens[lines]) do begin
372                 if AnsiPos(Ftokens[lines][cells],bufline) = 0 then begin
373                     hit := false;
374                     break;
375                 end else begin
376                     Delete(bufline,AnsiPos(Ftokens[lines][cells],bufline),Length(Ftokens[lines][cells]));
377                 end;
378             end;
379             if hit = true then begin
380                 NGwordsLineNum := lines + 1;
381                 break;
382             end;
383         end;
384     end;
385     Result := hit;
386 end;
387
388 //CutOff\92l\88È\8fã\8cÂ\82Ì\93¯\82\89p\90\94\82ª\95À\82ñ\82Å\82¢\82½\82çtrue
389 function TAbon.Cutoff(line : String) : Boolean;
390 var
391     i : Integer;
392     sheed : AnsiChar;
393     buf : String;
394     ret : Bool;
395 begin
396     ret := false;
397     if FCutoffNum <> 0 then begin
398         for i := 65 to 90 do begin
399             sheed := Chr(i);
400             buf := DupeString(sheed, FCutoffNum);
401             if AnsiContainsText(line, buf) = true then begin
402                 ret := true;
403                 break;
404             end;
405         end;
406     end;
407     Result := ret;
408 end;
409 //\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
410 procedure TAbon.Execute(var ThreadStrings : TStringList);
411 var
412     i : Integer;
413     NGwordsLine : Integer;
414     bufline : String;
415     invisi : Boolean;
416 begin
417     for i:=0 to ThreadStrings.Count - 1 do begin
418         NGwordsLine := 0;
419         if FindNGwords(ThreadStrings.Strings[i], NGwordsLine ,invisi) <> Reverse  then begin
420             if invisi = true then begin
421                 ThreadStrings.Strings[i] := '';
422             end else begin
423                 if not ReturnNGwordLineNum and not SetNGResAnchor then begin
424                     ThreadStrings.Strings[i] := FAbonString;
425                 end else if not ReturnNGwordLineNum then begin
426                     ThreadStrings.Strings[i] := Format('&nbsp;<>&nbsp;<>&nbsp;<>&gt;%d<><>',[(i+1)]);
427                 end else if not SetNGResAnchor then begin
428                     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]);
429                 end else 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>&gt;%d <><>',[NGwordsLine,(i+1)]);
431                 end;
432             end;
433         end else begin
434             bufline := ThreadStrings.Strings[i];
435             if Deleterlo = true then begin
436                 bufline := AnsiReplaceText( bufline,'&rlo;','' );
437                 bufline := AnsiReplaceText( bufline,'&lro;','' );
438             end;
439             if Replaceul = true then begin
440                 bufline := AnsiReplaceText( bufline,'<ul>','<br>' );
441                 bufline := AnsiReplaceText( bufline,'</ul>','<br>' );
442             end;
443             ThreadStrings.Strings[i] := bufline;
444         end;
445     end;
446 end;
447 procedure TAbon.Execute(var ResString : String; ResNumber : Integer);
448 var
449     i : Integer;
450     NGwordsLine : Integer;
451     bufline : String;
452     invisi : Boolean;
453 begin
454     NGwordsLine := 0;
455     if FindNGwords(ResString, NGwordsLine ,invisi) <> Reverse  then begin
456         if invisi = true then begin
457             ResString := '';
458         end else begin
459             if not ReturnNGwordLineNum and not SetNGResAnchor then begin
460                 ResString := FAbonString;
461             end else if not ReturnNGwordLineNum then begin
462                 ResString := Format('&nbsp;<>&nbsp;<>&nbsp;<>&gt;%d<><>',[(ResNumber)]);
463             end else if not SetNGResAnchor then begin
464                 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]);
465             end else 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>&gt;%d <><>',[NGwordsLine,(ResNumber)]);
467             end;
468         end;
469     end else begin
470         bufline := ResString;
471         if Deleterlo = true then begin
472             bufline := AnsiReplaceText( bufline,'&rlo;','' );
473             bufline := AnsiReplaceText( bufline,'&lro;','' );
474         end;
475         if Replaceul = true then begin
476             bufline := AnsiReplaceText( bufline,'<ul>','<br>' );
477             bufline := AnsiReplaceText( bufline,'</ul>','<br>' );
478         end;
479         ResString := bufline;
480     end;
481 end;
482
483 procedure TAbon.Execute(var ThreadStrings : TStringList; NGwords : TStringList);
484 var
485     i : Integer;
486 begin
487     SetLength(Ftokens,NGwords.Count);
488     for i := 0  to NGwords.Count -1 do begin
489         SetTokens(i , NGwords.Strings[i]);
490     end;
491     Execute(ThreadStrings);
492
493 end;
494 procedure TAbon.Execute(var ThreadStrings : TStringList; NGwords : TStrings);
495 var
496     i : Integer;
497     buf : TStringList;
498 begin
499     buf := TStringList.Create;
500     buf.AddStrings(NGwords);
501     SetLength(Ftokens,buf.Count);
502     for i := 0  to buf.Count -1 do begin
503         SetTokens(i , buf.Strings[i]);
504     end;
505     Execute(ThreadStrings);
506     buf.Free;
507 end;
508
509
510 //****************************************************************************//
511 //DAT\82ð\92¼\82É\82¢\82\82é\93z\82ç===========================================================
512 //NG\83\8f\81[\83h\82ð\8aÜ\82Þ\83\8c\83X\82Ì\90æ\93ª\82É\82 \82Ú\81[\82ñ\82ð\91}\93ü
513 function TAbon.ExecuteFile(datfilepath : String; NGwordpath : String) : Boolean; //DAT\83t\83@\83C\83\8b\82ð\92¼\82É\82¢\82\82é
514 var
515     datstl : TStringList;
516     ret : Boolean;
517     i : Integer;
518 begin
519     datstl := TStringList.Create;
520     ret := true;
521     try
522         try
523             datstl.LoadFromFile(datfilepath);
524             for i := 0 to datstl.Count -1 do begin
525                 if FindNGwords(datstl.Strings[i]) = true  then begin
526                     datstl.Strings[i] := FAbonString + datstl.Strings[i]
527                 end;
528             end;
529
530             datstl.SaveToFile(datfilepath);
531         except
532             ret := false;
533         end;
534     finally
535         datstl.Free;
536     end;
537     Result := ret;
538
539 end;
540 //\8ew\92è\82³\82ê\82½\83\8c\83X\94Ô\82Ì\90æ\93ª\82É\82 \82Ú\81[\82ñ\91}\93ü
541 function TAbon.ExecuteFile(datfilepath : String; resnum : Integer) : Boolean; //DAT\83t\83@\83C\83\8b\82ð\92¼\82É\82¢\82\82é
542 var
543     datstl : TStringList;
544     ret : Boolean;
545 begin
546     ret := true;
547     datstl := TStringList.Create;
548     try
549         try
550             datstl.LoadFromFile(datfilepath);
551             if (resnum > 0) and (resnum <= datstl.Count) then begin
552                 if AnsiPos(FAbonString, datstl.Strings[resnum-1]) <> 1 then begin
553                     datstl.Strings[resnum-1] := FAbonString + datstl.Strings[resnum-1];
554                 end;
555             end;
556             datstl.SaveToFile(datfilepath);
557         except
558             ret := false;
559         end;
560     finally
561         datstl.Free;
562     end;
563     Result := ret;
564 end;
565 //firstres\82©\82çcount\8cÂ\82Ì\83\8c\83X\82Ì\90æ\93ª\82É\82 \82Ú\81[\82ñ\91}\93ü
566 function TAbon.ExecuteFile(datfilepath : String; firstres : Integer; count : Integer) : Boolean; //DAT\83t\83@\83C\83\8b\82ð\92¼\82É\82¢\82\82é
567 var
568     datstl : TStringList;
569     i : Integer;
570     endnum : Integer; //\8fI\82í\82è\82Ì\83\8c\83X\94Ô
571     ret : Boolean;
572 begin
573     ret := true;
574     datstl := TStringList.Create;
575     try
576         try
577             datstl.LoadFromFile(datfilepath);
578             if (firstres > 0) and (firstres <= datstl.Count) then begin
579                 if firstres + count -1 > datstl.Count then begin
580                     endnum := datstl.Count;
581                 end else if count <= 0 then begin
582                     endnum := firstres + 1;
583                 end else begin
584                     endnum := firstres + count -1;
585                 end;
586
587                 for i := firstres to endnum do begin
588                     if AnsiPos(FAbonString, datstl.Strings[i-1]) <> 1 then begin
589                         datstl.Strings[i-1] := FAbonString + datstl.Strings[i-1];
590                     end;
591                 end;
592             end;
593             datstl.SaveToFile(datfilepath);
594         except
595             ret := false;
596         end;
597     finally
598         datstl.Free;
599     end;
600     Result := ret;
601 end;
602 //DAT\82ð\92¼\82É\82¢\82\82é\93z\82ç==========\82±\82±\82Ü\82Å=========================================
603
604 //\8c³\82É\96ß\82·\93z\82ç==================================================================
605 function TAbon.ReverseExecuteFile(datfilepath : String) : Boolean; //DAT\83t\83@\83C\83\8b\82ð\92¼\82É\82¢\82\82é
606 var
607     datstl : TStringList;
608     i : Integer;
609     buf : String;
610     ret : Boolean;
611 begin
612     ret := true;
613     datstl := TStringList.Create;
614     try
615         try
616             datstl.LoadFromFile(datfilepath);
617             for i:=0 to datstl.Count -1  do begin
618                 if AnsiPos(FAbonString, datstl.Strings[i]) = 1 then begin
619                     buf := datstl.Strings[i];
620                     Delete(buf,1,Length(FAbonString));
621                     datstl.Strings[i] := buf;
622                 end;
623             end;
624             datstl.SaveToFile(datfilepath);
625         except
626             ret := false;
627         end;
628     finally
629         datstl.Free;
630     end;
631     Result := ret;
632
633 end;
634 function TAbon.ReverseExecuteFile(datfilepath : String; resnum : Integer) : Boolean; //DAT\83t\83@\83C\83\8b\82ð\92¼\82É\82¢\82\82é
635 var
636     datstl : TStringList;
637     buf : String;
638     ret : Boolean;
639 begin
640     ret := true;
641     datstl := TStringList.Create;
642     try
643         try
644             datstl.LoadFromFile(datfilepath);
645             if (resnum > 0) and (resnum <= datstl.Count) then begin
646                 if AnsiPos(FAbonString, datstl.Strings[resnum-1]) = 1 then begin
647                     buf := datstl.Strings[resnum-1];
648                     Delete(buf,1,Length(FAbonString));
649                     datstl.Strings[resnum-1] := buf;
650                 end;
651             end;
652             datstl.SaveToFile(datfilepath);
653         except
654             ret := false;
655         end;
656     finally
657         datstl.Free;
658     end;
659     Result := ret;
660
661 end;
662 function TAbon.ReverseExecuteFile(datfilepath : String; firstres : Integer; count : Integer) : Boolean;//DAT\83t\83@\83C\83\8b\82ð\92¼\82É\82¢\82\82é
663 var
664     datstl : TStringList;
665     i : Integer;
666     endnum : Integer; //\8fI\82í\82è\82Ì\83\8c\83X\94Ô
667     buf : String;
668     ret : Boolean;
669 begin
670     ret := true;
671     datstl := TStringList.Create;
672     try
673         try
674             datstl.LoadFromFile(datfilepath);
675             if (firstres > 0) and (firstres <= datstl.Count) then begin
676                 if firstres + count -1 > datstl.Count then begin
677                     endnum := datstl.Count;
678                 end else if count <= 0 then begin
679                     endnum := firstres + 1;
680                 end else begin
681                     endnum := firstres + count -1;
682                 end;
683                 for i := firstres to endnum do begin
684                     if AnsiPos(FAbonString, datstl.Strings[i-1]) = 1 then begin
685                         buf := datstl.Strings[i-1];
686                         Delete(buf,1,Length(FAbonString));
687                         datstl.Strings[i-1] := buf;
688                     end;
689                 end;
690             end;
691             datstl.SaveToFile(datfilepath);
692         except
693             ret := false;
694         end;
695     finally
696         datstl.Free;
697     end;
698     Result := ret;
699 end;
700 //\8c³\82É\96ß\82·\93z\82ç=================\82±\82±\82Ü\82Å=========================================
701 //\8c»\8dÝ\83Z\83b\83g\82³\82ê\82Ä\82¢\82éNGword.txt\82ð\8aJ\82­
702 procedure TAbon.EditNGwords();
703 begin
704     ShellExecute(0 ,nil,PChar(FNGwordpath),nil,nil,SW_SHOW);
705 end;
706 //\83|\83b\83v\83A\83b\83v\97p\94»\92è\8aÖ\90\94
707 function TAbon.CheckAbonPopupRes(line : String) :Boolean;
708 begin
709     if AbonPopupRes = true then begin
710         Result := FindNGwords(line);
711     end else begin
712         Result := false;
713     end;
714 end;
715 //\95¡\90\94\82ÌNG\83\8f\81[\83h\83e\83L\83X\83g\82ð\93Ç\82Ý\8d\9e\82Þ==============================================
716 //List\83t\83@\83C\83\8b\82ð\93Ç\82Ý\8d\9e\82Þ
717 function TAbon.LoadListFile(path :String; listStringList : TStringList) : Boolean;
718 begin
719     try
720         listStringList.LoadFromFile(path);
721         Result := true;
722     except
723         listStringList.Append('\88ê\94Ê=NGword.txt');
724         listStringList.SaveToFile(path);
725         Result := false;
726     end;
727 end;
728 //List\82Ì\88ê\82Â\8e\9f\82ÌNG\83\8f\81[\83h\83t\83@\83C\83\8b\82ð\93Ç\82Ý\8d\9e\82Þ
729 function TAbon.GoForward() : Boolean;
730 begin
731     FNGwordFileIndex := FNGwordFileIndex + 1;
732     Result := ReadNGwordslist(FNGwordFileIndex);
733 end;
734 //List\82Ì\88ê\82Â\91O\82ÌNG\83\8f\81[\83h\83t\83@\83C\83\8b\82ð\93Ç\82Ý\8d\9e\82Þ
735 function TAbon.GoBack() : Boolean;
736 begin
737     FNGwordFileIndex := FNGwordFileIndex -1;
738     Result := ReadNGwordslist(FNGwordFileIndex);
739 end;
740 //List\82Ì\82P\8ds\96Ú\82ð\93Ç\82Þ
741 procedure TAbon.GoHome();
742 begin
743     FNGwordFileIndex := 0;
744     ReadNGwordslist(FNGwordFileIndex);
745 end;
746 //List\82Ìline\8ds\96Ú\82ð\93Ç\82Þ
747 function TAbon.ReadNGwordslist(line : Integer) : Boolean;
748 var
749     liststl : TStringList;
750     linebuf : String;
751 begin
752     liststl := TStringList.Create;
753     try
754         if LoadListFile(Flistpath,liststl) = true then begin
755             if line < 0 then begin
756                 line := liststl.Count - 1;
757                 FNGwordFileIndex := liststl.Count - 1;
758             end else if line > liststl.Count - 1 then begin
759                 line := 0;
760                 FNGwordFileIndex := 0;
761             end;
762             linebuf := liststl.Strings[line];
763             FNGwordname := Copy(linebuf,1,AnsiPos('=',linebuf)-1);
764             Delete(linebuf,1,AnsiPos('=',linebuf));
765             SetNGwordpath(linebuf);
766             Result := true;
767         end else begin
768             Result := false;
769         end
770     finally
771         liststl.Free;
772     end;
773
774 end;
775 //\95¡\90\94\82ÌNG\83\8f\81[\83h\83e\83L\83X\83g\82ð\93Ç\82Ý\8d\9e\82Þ=====\82±\82±\82Ü\82Å=================================
776 //\8cÂ\95Ê\82 \82Ú\81`\82ñ\8eÀ\8ds\8aÖ\90\94
777 procedure TAbon.IndividualAbon(var ThreadStrings : TStringList; SetResNumFile : String);
778 var
779         i : Integer;
780 begin
781         if FileExists(SetResNumFile) = true then begin
782         if LoadFromSetResNumFile(SetResNumFile) = true then begin
783                 for i := 0 to High(FAbonRes) do begin
784                  if (FAbonRes[i].Res <= ThreadStrings.Count) and (FAbonRes[i].Res > 0) then begin
785                         if FAbonRes[i].option = 0 then begin
786                         ThreadStrings.Strings[FAbonRes[i].Res-1] := '';
787                     end else begin
788                         ThreadStrings.Strings[FAbonRes[i].Res-1] := '\82 \82Ú\81`\82ñ<>\82 \82Ú\81`\82ñ<>\82 \82Ú\81`\82ñ<>\82 \82Ú\81`\82ñ<>';
789                     end;
790                  end;
791
792             end;
793         end;
794     end else begin
795         FIndividualFileName := SetResNumFile;
796         SetLength(FAbonRes,1);
797         FAbonRes[0].Res := 0;
798         FAbonRes[0].option := -1;
799     end;
800 end;
801 procedure TAbon.IndividualAbon(var ResString : String; SetResNumFile : String; ResNumber : Integer);
802 var
803         i : Integer;
804 begin
805         if FileExists(SetResNumFile) = true then begin
806         if LoadFromSetResNumFile(SetResNumFile) = true then begin
807                 for i := 0 to High(FAbonRes) do begin
808                  if FAbonRes[i].Res = ResNumber then begin
809                         if FAbonRes[i].option = 0 then begin
810                         ResString := '';
811                     end else begin
812                         ResString := '\82 \82Ú\81`\82ñ<>\82 \82Ú\81`\82ñ<>\82 \82Ú\81`\82ñ<>\82 \82Ú\81`\82ñ<>';
813                     end;
814                     Exit;
815                  end;
816             end;
817         end;
818     end else begin
819         FIndividualFileName := SetResNumFile;
820         SetLength(FAbonRes,1);
821         FAbonRes[0].Res := 0;
822         FAbonRes[0].option := -1;
823     end;
824 end;
825
826 //\8cÂ\95Ê\82 \82Ú\81`\82ñ\83t\83@\83C\83\8b\93Ç\82Ý\8d\9e\82Ý\8aÖ\90\94
827 function TAbon.LoadFromSetResNumFile(SetResNumFile : String) : Boolean;
828 var
829         bufStringList : TStringList;
830     bufLine : String;
831     i : Integer;
832 begin
833     bufStringList := TStringList.Create;
834     try
835         try
836                 bufStringList.LoadFromFile(SetResNumFile);
837             FIndividualFileName := SetResNumFile;
838             //\8bó\8ds\8dí\8f\9c
839             for i := bufStringList.Count-1 downto 0 do begin
840                         if bufStringList.Strings[i] = '' then begin
841                         bufStringList.Delete(i);
842                     end;
843             end;
844
845             //\83\81\83\82\83\8a\8am\95Û
846                 SetLength(FAbonRes,bufStringList.Count);
847             //\91ã\93ü
848             for i :=0 to bufStringList.Count - 1 do begin
849                         bufLine := Trim(bufStringList.Strings[i]);
850                     FAbonRes[i].Res :=  StrToInt(Copy(bufLine,1,AnsiPos('-',bufLine)-1));
851                 FAbonRes[i].option := StrToInt(Copy(bufLine,AnsiPos('-',bufLine)+1,1));
852             end;
853         except
854                 Result := false;
855             Exit;
856         end;
857     finally
858         bufStringList.Free;
859     end;
860     Result := true;
861 end;
862 //\8cÂ\95Ê\82 \82Ú\81`\82ñ\83t\83@\83C\83\8b\82É\92Ç\89Á
863 procedure TAbon.AddIndividualAbon( ResNum : Integer ; option : Integer);
864 var
865         IndividualFile : TStringList;
866     linebuf : String;
867     i : Integer;
868 begin
869     IndividualFile := TStringList.Create;
870         if FAbonRes[0].Res <> 0 then begin
871         for i := 0 to High(FAbonRes) do begin
872             if FAbonRes[i].Res <> ResNum then begin
873                         linebuf := IntToStr(FAbonRes[i].Res) + '-' + IntToStr(FabonRes[i].option);
874                 IndividualFile.Append(linebuf);
875             end;
876         end;
877     end;
878     linebuf := IntToStr(ResNum) + '-' + IntToStr(option);
879     IndividualFile.Append(linebuf);
880     try
881         IndividualFile.SaveToFile(FIndividualFileName);
882     finally
883         IndividualFile.Free;
884     end;
885 end;
886 //\8cÂ\95Ê\82 \82Ú\81`\82ñ\83t\83@\83C\83\8b\82©\82ç\8dí\8f\9c
887 procedure TAbon.DeleteIndividualAbon( ResNum : Integer);
888 var
889         IndividualFile : TStringList;
890     linebuf : String;
891     i : Integer;
892 begin
893     IndividualFile := TStringList.Create;
894         if FAbonRes[0].Res <> 0 then begin
895         for i := 0 to High(FAbonRes) do begin
896             if FAbonRes[i].Res <> ResNum then begin
897                         linebuf := IntToStr(FAbonRes[i].Res) + '-' + IntToStr(FabonRes[i].option);
898                 IndividualFile.Append(linebuf);
899             end;
900         end;
901     end;
902         if IndividualFile.Count <> 0 then begin
903         try
904                 IndividualFile.SaveToFile(FIndividualFileName);
905         finally
906                 IndividualFile.Free;
907         end;
908     end else begin
909         if FileExists(FIndividualFileName) = true then begin
910                 DeleteFile(FIndividualFileName);
911         end;
912     end;
913 end;
914 //\8cÂ\95Ê\82 \82Ú\81`\82ñ\82Ì\83\8a\83X\83g\82Ì\8cÂ\90\94\82ð\95Ô\82·
915 function TAbon.GetAbonResCount() : Integer;
916 var
917         i : Integer;
918 begin
919     if FAbonRes[0].Res = 0 then begin
920         Result := 0
921     end else begin
922                 i := High(FAbonRes);
923         Result := i+1;
924     end;
925 end;
926 //\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·
927 function TAbon.GetAbonResString(Num : Integer) : String;
928 begin
929         if (Num <= High(FAbonRes)) and (Num >= 0) then begin
930         Result := IntToStr(FAbonRes[Num].Res);
931     end else begin
932         Result := '';
933     end;
934 end;
935 //\83|\83b\83v\83A\83b\83v\82Ì\94»\92è\97p
936 function TAbon.CheckIndividualAbonList(ResNum : Integer) : Boolean;
937 var
938         i : Integer;
939 begin
940         if FAbonRes[0].Res <> 0 then begin
941         for i := 0 to High(FAbonRes) do begin
942                 if FAbonRes[i].Res = ResNum then begin
943                 Result := true;
944                 Exit;
945             end;
946         end;
947     end;
948     Result := false;
949     
950 end;
951 end.
952