-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathformFormat.pas
More file actions
263 lines (226 loc) · 6.84 KB
/
formFormat.pas
File metadata and controls
263 lines (226 loc) · 6.84 KB
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
unit formFormat;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, JvExStdCtrls, JvRichEdit, ToolWin, ComCtrls,
unCommon,
JvExComCtrls, JvToolBar, ExtCtrls, JvExExtCtrls, JvSplitter, jvStrings,
JvDialogs;
type
TfrmFormat = class(TForm)
JvToolBar1: TJvToolBar;
richOrg: TJvRichEdit;
JvSplitter1: TJvSplitter;
richModded: TJvRichEdit;
ToolButton1: TToolButton;
ToolButton2: TToolButton;
ToolButton3: TToolButton;
Edit1: TEdit;
JvSaveDialog1: TJvSaveDialog;
ToolButton4: TToolButton;
ToolButton5: TToolButton;
JvOpenDialog1: TJvOpenDialog;
procedure richOrgVerticalScroll(Sender: TObject);
procedure ToolButton1Click(Sender: TObject);
procedure ToolButton2Click(Sender: TObject);
procedure ToolButton4Click(Sender: TObject);
private
{ Private declarations }
function removeDbls(s:string):string;
function removeLast(s:string):string;
function removeMisc(s:string):string;
function formatValue(s:String; startTabbed:boolean=false):string;
public
{ Public declarations }
procedure populateFile(fileName:String);
function format(bList:TStringList):TStringList; Overload;
function format(bList:TStrings):TStrings; Overload;
end;
var
frmFormat: TfrmFormat;
implementation
uses unMain;
{$R *.dfm}
function TfrmFormat.format(bList: TStringList): TStringList;
Var
i{, iAnime} : integer;
aList : TStringList;
sCrnt, previousLine : string;
FirstAnimeFound, scriptFound : Boolean;
begin
aList := TStringList.Create;
aList.AddStrings(bList);
i := 0;
//for i := 0 to aList.Count -1 do Begin
while i < aList.Count do Begin
try
sCrnt := aList.Strings[i];
if isNewAnimBlock(sCrnt) = true then
FirstAnimeFound := true;
//iAnime := PosStr('anim',LowerCase(sCrnt));
{if iAnime > 0 then
newAnime := true;}
//Detect scripts
if (PosStr('@script',sCrnt) > 0) then
scriptFound := true;
if (PosStr('@end_script',sCrnt) > 0) then
scriptFound := False;
if (FirstAnimeFound = false) or
(scriptFound = true) or
(PosStr('#',sCrnt) > 0) then Begin
aList.Strings[i] := sCrnt;
end else Begin
sCrnt := removeDbls(sCrnt);
sCrnt := removeLast(sCrnt);
sCrnt := removeMisc(sCrnt);
if isNewAnimBlock(sCrnt) = false then
sCrnt := formatValue(sCrnt, true)
else Begin
try
if i > 0 then
previousLine := aList.Strings[i-1]
else
previousLine := '';
if isLineEmpty(previousLine) = false then Begin
aList.Insert(i,'');
inc(i);
end;
except
end;
sCrnt := formatValue(sCrnt);
end;
aList.Strings[i] := sCrnt;
end;
inc(i);
except
end;
end;
Result := aList;
end;
{function TfrmFormat.format(bList: TStringList): TStringList;
begin
end;}
function TfrmFormat.format(bList: TStrings): TStrings;
Var
i{, iAnime} : integer;
aList : TStringList;
sCrnt, previousLine : string;
FirstAnimeFound, scriptFound : Boolean;
begin
aList := TStringList.Create;
aList.AddStrings(bList);
i := 0;
//for i := 0 to aList.Count -1 do Begin
while i < aList.Count do Begin
sCrnt := aList.Strings[i];
if isNewAnimBlock(sCrnt) = true then
FirstAnimeFound := true;
//iAnime := PosStr('anim',LowerCase(sCrnt));
{if iAnime > 0 then
newAnime := true;}
//Detect scripts
if (PosStr('@script',sCrnt) > 0) then
scriptFound := true;
if (PosStr('@end_script',sCrnt) > 0) then
scriptFound := False;
if (FirstAnimeFound = false) or
(scriptFound = true) or
(PosStr('#',sCrnt) > 0) then Begin
aList.Strings[i] := sCrnt;
end else Begin
sCrnt := removeDbls(sCrnt);
sCrnt := removeLast(sCrnt);
sCrnt := removeMisc(sCrnt);
if isNewAnimBlock(sCrnt) = false then
sCrnt := formatValue(sCrnt, true)
else Begin
try
previousLine := aList.Strings[i-1];
if isLineEmpty(previousLine) = false then Begin
aList.Insert(i,'');
inc(i);
end;
except
end;
sCrnt := formatValue(sCrnt);
end;
aList.Strings[i] := sCrnt;
end;
inc(i);
end;
Result := aList;
end;
function TfrmFormat.formatValue(s: String; startTabbed:boolean): string;
Var
s1, s2 : string;
begin
s1 := s;
Form1.StringDeleteFirstChar(s1,' ');
Form1.StringDeleteFirstChar(s1,#09);
Form1.StringDelete2End(s1,' ');
Form1.StringDelete2End(s1,#09);
s2 := s;
Form1.StringDeleteUp2(s2,s1,length(s1)-1);
Form1.StringDeleteFirstChar(s2,' ');
Form1.StringDeleteFirstChar(s2,#09);
Form1.StringDeleteLastChar(s2,' ');
Form1.StringDeleteLastChar(s2,#09);
if startTabbed = true then
s := #09 + s1 + #09 + s2
else
s := s1 + #09 + s2;
{Form1.StringDeleteFirstChar(s,' ');
Form1.StringDeleteFirstChar(s,#09);
s := #09 + s;}
Result := s;
end;
procedure TfrmFormat.populateFile(fileName:String);
begin
richOrg.Lines.LoadFromFile(fileName);
richModded.Lines := format(richOrg.Lines);
JvSaveDialog1.InitialDir := ExtractFilePath(fileName);
JvOpenDialog1.InitialDir := ExtractFilePath(fileName);
Edit1.Text := fileName;
end;
function TfrmFormat.removeDbls(s: string): string;
begin
form1.StringReplace(s,' ',#09);
form1.StringReplace(s,' ',#09);
form1.StringReplace(s,' ',#09);
form1.StringReplace(s,' ',#09);
form1.StringReplace(s,' ',' ');
form1.StringReplace(s,#09#09,#09);
Result := s;
end;
function TfrmFormat.removeLast(s: string): string;
begin
Form1.StringDeleteLastChar(s,' ');
Form1.StringDeleteLastChar(s,#09);
Result := s;
end;
function TfrmFormat.removeMisc(s: string): string;
begin
Form1.StringReplace(s,#09+' ',#09);
Result := s;
end;
procedure TfrmFormat.richOrgVerticalScroll(Sender: TObject);
begin
richModded.ScrollBars := richOrg.ScrollBars;
end;
procedure TfrmFormat.ToolButton1Click(Sender: TObject);
begin
richModded.Lines.SaveToFile(Edit1.Text);
ShowMessage('Succesfully Saved: ' + ExtractFileName(Edit1.Text));
end;
procedure TfrmFormat.ToolButton2Click(Sender: TObject);
begin
if JvSaveDialog1.Execute then
richModded.Lines.SaveToFile(JvSaveDialog1.FileName);
end;
procedure TfrmFormat.ToolButton4Click(Sender: TObject);
begin
if JvOpenDialog1.Execute then Begin
populateFile(JvOpenDialog1.FileName);
end;
end;
end.