This repository has been archived by the owner on May 16, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
/
index.dpr
182 lines (162 loc) · 4.42 KB
/
index.dpr
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
uses
Common, Classes, SysUtils, Windows;
type
TWord = class(TObject)
Count : longword;
Date : TDateTime;
Word : string;
end; {case}
const
hicolor = '#B00000';
locolor = '#800000';
WordList : TList = NIL;
indexstr : string = '';
totalentries : integer = 0;
totalwords : integer = 0;
dayz : integer = 0;
var
noquery : boolean;
hasdate : boolean;
indexChar : string;
procedure buildindexstr;
var
a:char;
procedure addindex(showstr, querystr:string; hede:boolean);
begin
indexstr := indexstr + '<a href="/cgi-bin/index.exe'+querystr+'">';
if hede then indexstr := indexstr + '<font color="'+hicolor+'"><b>'+showstr+'</b></font></a> '
else indexstr := indexstr + showstr+'</a> ';
end;
begin
indexstr := '';
addindex('0-9','?i=*',indexchar='*');
for a := 'a' to 'z' do begin
addindex(a,'?i='+a,indexchar=a);
end;
addindex('tümü','?i=all',indexChar='all');
addindex('taze','',queryString='');
end;
function FindWord(w:string):TWord;
var
n:integer;
begin
for n := 0 to WordList.Count-1 do begin
Result := WordList[n];
if Result.Word = w then exit;
end;
Result := NIL;
end;
function wordcompare(p1,p2:pointer):integer;
begin
Result := CompareStr(TWord(p1).Word,TWord(p2).Word);
end;
var
I:TextFile;
authstr,numstr,desc,word,templine,searchstr,s:string;
date,fd,td:TDateTime;
T:TWord;
n:integer;
ok:boolean;
begin
WordList := TList.Create;
noquery := queryString='';
buildindexstr;
indexchar := getValue('i');
searchstr := getValue('search');
authstr := getValue('author');
s := getValue('date');
hasdate := s <> '';
fd := 0;
if hasdate then try
fd := StrToDate(s);
except
hasdate := false;
end;
td := 0;
s := getValue('todate');
if s <> '' then try
td := StrToDate(s);
except
td := Now;
end;
if FileExists(dictFile) then begin
AssignFile(I,dictFile);
Reset(I);
s := '';
while not Eof(I) do begin
if s <> '' then if s[1]='~' then begin
ok := true;
templine := s;
if indexChar='*' then ok := not (s[2] in ['a'..'z'])
else if indexChar <> '' then if indexChar <> 'all' then ok := s[2] = indexChar[1];
if ok then begin
word := copy(s,2,length(s));
Readln(I,s);
if authstr <> '' then if pos(authstr,s) = 0 then continue;
Readln(I,s);
s := Getparse(Trim(s),' ',1);
try
date := StrToDate(s);
except
date := Trunc(Now);
end;
desc := '';
while not Eof(I) do begin
Readln(I,s);
if s <> '' then
if s[1] = '~' then break else desc := desc + Trim(s);
end;
if noquery then if date <> Trunc(Now) then continue else
else if hasdate then if (date >= fd) and (date <= td) then continue;
if searchstr <> '' then
if pos(searchstr,desc) = 0 then
if pos(searchstr,templine) = 0 then continue;
T := FindWord(word);
if T <> NIL then begin
inc(T.Count);
if date > T.Date then T.Date := date;
end else begin
T := TWord.Create;
T.Word := word;
T.Count := 1;
T.Date := date;
WordList.Add(T);
inc(totalwords);
end;
inc(totalentries);
continue;
end;
end; {if}
Readln(I,s);
end; {while}
CloseFile(I);
end else FileCreate(dictFile);
WordList.Sort(wordcompare);
AssignFile(I,indexTemplateFile);
Reset(I);
repeat
Readln(I,s);
writeln(Replace(s,'%index',indexstr));
until s = '';
Readln(I,templine);
Flush(output);
if WordList.Count = 0 then writeln('Hic kayIt yok') else for n:=0 to WordList.Count-1 do begin
T := WordList[n];
word := T.Word;
if T.Count=1 then numstr := ''
else numstr := '('+IntToStr(T.Count)+')';
if Trunc(T.Date) = Trunc(Now) then s := Replace(templine,'%linkcolor',hicolor)
else s := Replace(templine,'%linkcolor',locolor);
s := Replace(s,'%word',word);
s := Replace(s,'%num',numstr);
s := Replace(s,'%search',Translate(word,' ','+'));
writeln(s);
end;
repeat
Readln(I,s);
s := Replace(s,'%totalwords',IntToStr(totalwords));
s := Replace(s,'%totalentries',IntToStr(totalentries));
writeln(s);
until Eof(I);
CloseFile(I);
end.