-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCommunityLinks.pas
163 lines (150 loc) · 4.22 KB
/
CommunityLinks.pas
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
unit CommunityLinks;
interface
procedure LoadCommunityLinks;
implementation
uses FormMain, SysUtils, Dialogs, Menus;
// *****************************************************
// ********* Community Menu Loading Procedures *********
// *****************************************************
procedure LoadCommunityLinks;
var
CatCounter, Counter, position: word; // String element and its char position
line, pos: word; // File line and position
token: char; // current char
F: Text; // file
OnText, OnUrl, OnName, OnCategory: boolean;
CatName: string;
Item: TMenuItem;
begin
// Check for file
if not fileexists(extractfiledir(ParamStr(0)) + '/commlist.ini') then
begin
ShowMessage('Error! Commlist.ini doesn''t exist. Initialization aborted!');
FrmMain.Close;
Exit;
end;
// Open File
AssignFile(F, extractfiledir(ParamStr(0)) + '/commlist.ini');
Reset(F);
// Reset engine
CatCounter := 2;
counter := 0;
position := 0;
line := 1;
pos := 1;
OnText := False;
OnUrl := False;
OnName := False;
OnCategory := False;
// Start reading
while not EOF(F) do
begin
// Read next char
Read(F, token);
// If it's receiving text, then...
if OnText then
begin
case (token) of
']':
begin
Inc(pos);
Inc(line);
OnCategory := False;
OnText := False;
Item := TMenuItem.Create(FrmMain);
Item.Caption := CatName;
Item.Tag := CatCounter;
Item.Visible := True;
FrmMain.Comm1.Add(Item);
Inc(CatCounter);
ReadLn(F);
end;
'$':
begin
Inc(pos);
Inc(line);
OnUrl := False;
OnText := False;
Readln(F);
end;
'>':
begin
Inc(pos);
Inc(line);
OnName := False;
OnText := False;
Item := TMenuItem.Create(FrmMain);
Item.Caption := FrmMain.SiteList[counter].SiteName;
Item.Tag := Counter;
Item.OnClick := FrmMain.LoadSite;
Item.Visible := True;
FrmMain.Comm1.Items[CatCounter].Add(Item);
Inc(counter);
Readln(F);
end;
else
begin
if OnCategory then
begin
SetLength(CatName, position);
CatName[position] := token;
end
else if OnUrl then
begin
SetLength(FrmMain.SiteList[counter].SiteUrl, position);
FrmMain.SiteList[counter].SiteUrl[position] := token;
end
else if OnName then
begin
SetLength(FrmMain.SiteList[counter].SiteName, position);
FrmMain.SiteList[counter].SiteName[position] := token;
end;
Inc(position);
end;
end;
end
else // searching instructions
begin
case (token) of
' ':
begin
Inc(pos);
end;
'[':
begin
Inc(pos);
position := 1;
OnCategory := True;
OnText := True;
CatName := '';
end;
'$':
begin
Inc(pos);
position := 1;
OnUrl := True;
OnText := True;
SetLength(FrmMain.SiteList, Counter + 1);
end;
'<':
begin
Inc(pos);
position := 1;
OnName := True;
OnText := True;
end;
'#':
begin
Readln(F);
Inc(line);
pos := 1;
end;
else
ShowMessage('Community Links Error: Parse error at Line ' +
IntToStr(line) + ', Position ' + IntToStr(pos));
end;
end;
end;
CloseFile(F);
end;
end.