codetools: copy variables

git-svn-id: trunk@26883 -
This commit is contained in:
mattias 2010-07-28 23:43:40 +00:00
parent 42321c5664
commit 4411050278

View File

@ -78,6 +78,9 @@ function CompareCTCSVariables(Var1, Var2: Pointer): integer;
function ComparePCharWithCTCSVariableName(Name, aVar: Pointer): integer;
function AreCTCSVariablesEqual(const V1, V2: PCTCfgScriptVariable): Boolean;
function AreCTCSVariablesExactEqual(const V1, V2: PCTCfgScriptVariable): Boolean;
function NewCTCSVariable: PCTCfgScriptVariable;
function NewCTCSVariable(CloneName: PChar): PCTCfgScriptVariable;
function CloneCTCSVariable(const V: PCTCfgScriptVariable): PCTCfgScriptVariable;
procedure FreeCTCSVariable(var V: PCTCfgScriptVariable);
procedure ClearCTCSVariable(const V: PCTCfgScriptVariable);
function CTCSNumberEqualsString(const Number: int64; const P: PChar): boolean; inline;
@ -146,6 +149,48 @@ begin
Result:=true;
end;
function NewCTCSVariable: PCTCfgScriptVariable;
begin
New(Result);
FillByte(Result^,SizeOf(Result),0);
end;
function NewCTCSVariable(CloneName: PChar): PCTCfgScriptVariable;
var
l: LongInt;
begin
Result:=NewCTCSVariable();
l:=GetIdentLen(CloneName);
if l>0 then begin
Result^.Name:=GetMem(l+1);
System.Move(CloneName^,Result^.Name^,l);
Result^.Name[l]:=#0;
end;
end;
function CloneCTCSVariable(const V: PCTCfgScriptVariable): PCTCfgScriptVariable;
var
l: LongInt;
begin
Result:=NewCTCSVariable(V^.Name);
Result^.ValueType:=V^.ValueType;
case V^.ValueType of
ctcsvNone: ;
ctcsvString:
begin
l:=V^.StrLen;
Result^.StrLen:=l;
if l>0 then begin
Result^.StrStart:=GetMem(l+1);
System.Move(V^.StrStart^,Result^.StrStart^,l);
Result^.StrStart[l]:=#0;
end;
end;
ctcsvNumber:
Result^.Number:=V^.Number;
end;
end;
procedure FreeCTCSVariable(var V: PCTCfgScriptVariable);
begin
ClearCTCSVariable(V);
@ -285,20 +330,31 @@ procedure TCTCfgScriptVariables.Assign(Source: TCTCfgScriptVariables);
var
Node: TAVLTreeNode;
Item: PCTCfgScriptVariable;
NewItem: PCTCfgScriptVariable;
begin
Clear;
Node:=Source.FItems.FindLowest;
while Node<>nil do begin
Item:=PCTCfgScriptVariable(Node.Data);
if Item=nil then ;
NewItem:=CloneCTCSVariable(Item);
FItems.Add(NewItem);
Node:=Source.FItems.FindSuccessor(Node);
end;
end;
function TCTCfgScriptVariables.GetVariable(const Name: PChar;
CreateIfNotExists: Boolean): PCTCfgScriptVariable;
var
Node: TAVLTreeNode;
begin
Result:=nil;
Node:=FItems.FindKey(Name,@ComparePCharWithCTCSVariableName);
if Node<>nil then
Result:=PCTCfgScriptVariable(Node.Data)
else if CreateIfNotExists then begin
Result:=NewCTCSVariable(Name);
FItems.Add(Result);
end else
Result:=nil;
end;
{ TCTConfigScriptEngine }