From 651593139149af522ece3a4f0e8cce164e93a9bd Mon Sep 17 00:00:00 2001 From: mysticbbs Date: Sat, 11 Aug 2012 12:50:26 -0400 Subject: [PATCH] Initial import --- mdl/m_inireader.pas | 94 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 mdl/m_inireader.pas diff --git a/mdl/m_inireader.pas b/mdl/m_inireader.pas new file mode 100644 index 0000000..329d8c9 --- /dev/null +++ b/mdl/m_inireader.pas @@ -0,0 +1,94 @@ +Unit m_IniReader; + +{$I M_OPS.PAS} + +Interface + +Type + TIniReader = Class + FileName : String; + IniFile : Text; + Buffer : Array[1..1024*4] of Char; + Opened : Boolean; + + Constructor Create (FN: String); + Destructor Destroy; Override; + Function ReadString (Category, Value, DefValue: String) : String; + Function ReadInteger (Category, Value: String; DefValue: LongInt) : LongInt; + End; + +Implementation + +Uses + m_Strings; + +Constructor TIniReader.Create (FN: String); +Begin + FileName := FN; + FileMode := 66; + + Assign (IniFile, FileName); + SetTextBuf (IniFile, Buffer); + Reset (IniFile); + + Opened := IoResult = 0; +End; + +Destructor TIniReader.Destroy; +Begin + If Opened Then Close(IniFile); +End; + +Function TIniReader.ReadString (Category, Value, DefValue: String) : String; +Var + RawStr : String; + NewStr : String; + GotCat : Boolean = False; +Begin + Result := DefValue; + + If Not Opened Then Exit; + + Category := strUpper(Category); + Value := strUpper(Value); + + Reset (IniFile); + + While Not GotCat And Not Eof(IniFile) Do Begin + ReadLn (IniFile, RawStr); + + RawStr := strStripB(RawStr, ' '); + NewStr := strUpper(strStripLOW(RawStr)); + + If (RawStr = '') or (RawStr[1] = ';') Then Continue; + + GotCat := Pos('[' + Category + ']', NewStr) > 0; + End; + + If Not GotCat Then Exit; + + While Not Eof(IniFile) Do Begin + ReadLn (IniFile, RawStr); + + RawStr := strStripB(RawStr, ' '); + NewStr := strUpper(strStripLOW(RawStr)); + + If (RawStr = '') or (RawStr[1] = ';') Then Continue; + + If RawStr[1] = '[' Then Exit; + + If (Pos(Value, NewStr) = 1) and (Pos('=', NewStr) > 0) Then Begin + Result := strStripB(Copy(RawStr, Pos('=', RawStr) + 1, 255), ' '); + Exit; + End; + End; +End; + +Function TIniReader.ReadInteger (Category, Value: String; DefValue: LongInt) : LongInt; +Var + Str : String; +Begin + Result := strS2I(ReadString(Category, Value, strI2S(DefValue))); +End; + +End.