procedure FormatINI(Filename:
string);
var
sBuffer:
string;
ParseFile: TextFile;
StringList: TStringList;
StringParse:
string;
procedure AppendToLinkedList(nReading: Integer; sBuffer:
string);
begin
New(FPBuffer);
if nReading = 0
then
Begin
New(FToPBuffer);
LineStart := FToPBuffer;
LineStart^.Nr := 0;
end;
FPBuffer^.Nr := nReading;
FPBuffer^.Str := sBuffer;
LineStart^.Max := FPBuffer^.Nr;
FToPBuffer^.Ptr := FPBuffer;
FToPBuffer := FPBuffer;
end;
begin
StringList := TStringList.Create;
Assignfile(ParseFile, Filename);
reset(ParseFile);
try
try
while not eof(ParseFile)
do
begin
ReadLN(ParseFile, sBuffer);
AppendToLinkedList(nReading, sBuffer);
inc(nReading);
end;
except
raise Exception.Create(SysErrorMessage(GetLastError));
end;
finally
nReading := 0;
CloseFile(ParseFile);
end;
FPBuffer := LineStart;
while (FPBuffer.Nr <= LineStart.Max - 1)
do
begin
FPBuffer := FPBuffer.Ptr;
StringParse := LeftTrim(FPBuffer.Str);
if Length(StringParse) <> 0
then
StringList.Add(FPBuffer^.Str);
if FPBuffer.Nr > 0
then
if LeftStr(FPBuffer^.Str, 1) = '
['
then
StringList.Insert(StringList.IndexOf(StringParse), '
');
ZeroMemory(PWideChar(FPBuffer.Str), Length(FPBuffer.Str) * SizeOf(Char));
FPBuffer.Str := '
';
end;
StringList.SaveToFile(Filename);
StringList.Free;
Dispose(FPBuffer);
FPBuffer :=
nil;
LineStart :=
nil;
end;