////////////////////////////////////////////////////////////////////////////////
// CM2MMRB.pas
// -----------
// This unit contains functions to manage version numbers in CoolMon 2.
//
// Last Edit: June, 20th 2006
// Certified: NA
//
// This unit is coded in : Delphi 7
//
// Unit is copyright (c) 2003 - 2006, The CoolMon Project
////////////////////////////////////////////////////////////////////////////////
unit CM2MMRB;

interface

Uses SysUtils, Filter;

Type
 TMMRB = record // Version notation system - [M]ajor [M]inor [R]elease [B]uilt
  Major: byte;
  Minor: byte;
  Release: byte;
  Built: byte;
 End;

 Function WordToMMRB(W: word): TMMRB;
 Function MMRBToWord(MMRB: TMMRB): Word;
 Function MMRBToStr(MMRB: TMMRB; Periods: boolean = true): String;
 Function WordToStr(W: Word): String;
 Function StrWithPeriodToMMRB(S: String): TMMRB;

implementation

Function WordToStr(W: Word): String;
Var
 M: TMMRB;
Begin
 M := WordToMMRB(W);
 Result := IntToStr(M.Major) + '.' + IntToStr(M.Minor) + '.' +
            IntToStr(M.Release) + '.' + IntToStr(M.Built);
End;

Function WordToMMRB(W: word): TMMRB;
Var
 S: String;
 I: Integer;
Begin
 S := IntToStr(W);
 For I := Length(S) to 3 do begin
  S := '0' + S;
 End;
 Result.Built := StrToInt(Copy(S, Length(S), 1));
 S := Copy(S, 1, Length(S) -1);
 Result.Release := StrToInt(Copy(S, Length(S), 1));
 S := Copy(S, 1, Length(S) -1);
 Result.Minor := StrToInt(Copy(S, Length(S), 1));
 S := Copy(S, 1, Length(S) -1);
 Result.Major := StrToInt(S);
End;

Function MMRBToWord(MMRB: TMMRB): Word;
Begin
 Result := MMRB.Major * 1000 +
           MMRB.Minor * 100 +
           MMRB.Release * 10 +
           MMRB.Built;
End;

Function StrWithPeriodToMMRB(S: String): TMMRB;
Begin
 Result.Major := 0;
 Result.Minor := 0;
 Result.Release := 0;
 Result.Built := 0;
 If CountFilt(S, '.') <> 4 then exit;
 Result.Major := StrToInt(GetFilt(S, 1, '.'));
 Result.Minor := StrToInt(GetFilt(S, 2, '.'));
 Result.Release := StrToInt(GetFilt(S, 3, '.'));
 Result.Built := StrToInt(GetFilt(S, 4, '.'));
End;

Function MMRBToStr(MMRB: TMMRB; Periods: boolean = true): String;
Begin
 Result := IntToStr(MMRB.Major);
 If Periods then Result := Result + '.';
 Result := Result + IntToStr(MMRB.Minor);
 If Periods then Result := Result + '.';
 Result := Result + IntToStr(MMRB.Release);
 If Periods then Result := Result + '.';
 Result := Result + IntToStr(MMRB.Built);
End;

end.
