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
|
{
girfiles.pas
Copyright (C) 2011 Andrew Haines andrewd207@aol.com
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
}
unit girFiles;
{$mode objfpc}{$H+}
{$INTERFACES CORBA}
interface
uses
Classes, SysUtils, DOM, girNameSpaces, girParser, CommandLineOptions;
type
{ TgirFile }
TgirFile = class(IgirParser)
private
FNameSpaces: TgirNamespaces;
FOnNeedGirFile: TgirNeedGirFileEvent;
FOwner: TObject;
FCmdOptions: TCommandLineOptions;
procedure ParseNode(ANode: TDomNode);
procedure SetOnNeedGirFile(AValue: TgirNeedGirFileEvent);
procedure SetOwner(const AValue: TObject);
procedure ParseIncludeNode(ANode: TDomNode; AIncludes: TList);
procedure CheckVersionLimits(const ANameSpace: TgirNamespace);
function CheckVersionOptions(const ANamespace: String; var AMajor, AMinor: Integer): Boolean;
public
constructor Create(AOwner: TObject; AOptions: TCommandLineOptions);
destructor Destroy; override;
procedure ParseXMLDocument(AXML: TXMLDocument);
property NameSpaces: TgirNamespaces read FNameSpaces;
property Owner: TObject read FOwner write SetOwner; // TGirConsoleConverter
property OnNeedGirFile: TgirNeedGirFileEvent read FOnNeedGirFile write SetOnNeedGirFile;
end;
implementation
uses girErrors, girTokens;
{ TgirFile }
{ TgirFile }
procedure TgirFile.ParseNode(ANode: TDomNode);
var
Node: TDomNode;
NS: TgirNamespace;
Includes: TList;
begin
if ANode.NodeName <> 'repository' then
girError(geError, 'Not a Valid Document Type!');
Node := Anode.FirstChild;
Ns := nil;
Includes := TList.Create;
while Node <> nil do begin
case GirTokenNameToToken(Node.NodeName) of
gtInclude: ParseIncludeNode(Node, Includes);
gtNameSpace:
begin
NS := TgirNamespace.CreateFromRepositoryNode(NameSpaces, ANode, Includes);
girError(geDebug, 'Adding Namespace '+NS.NameSpace+' to NameSpaces');
FNameSpaces.Add(NS);
girError(geDebug, 'Added Namespace '+NS.NameSpace);
CheckVersionLimits(NS);
NS.ParseNode(Node);
end;
gtPackage, gtCInclude: ;// ignore for now
else
girError(geDebug, 'Unknown Node Type for Reposiotory: '+ node.NodeName);
end;
Node := Node.NextSibling;
end;
{ANode := ANode.FindNode('namespace');
if ANode = nil then
girError(geError, 'namespace node not found')
else
begin
end;}
end;
procedure TgirFile.SetOnNeedGirFile(AValue: TgirNeedGirFileEvent);
begin
FNameSpaces.OnNeedGirFile:=AValue;
if FOnNeedGirFile=AValue then Exit;
FOnNeedGirFile:=AValue;
end;
procedure TgirFile.SetOwner(const AValue: TObject);
begin
if FOwner=AValue then exit;
FOwner:=AValue;
end;
procedure TgirFile.ParseIncludeNode(ANode: TDomNode; AIncludes: TList);
var
NS: TgirNamespace;
NSName, NSVersion: String;
begin
NSName := TDOMElement(ANode).GetAttribute('name');
NSVersion := TDOMElement(ANode).GetAttribute('version');
NS := FNameSpaces.FindNameSpace(NSName, NSVersion);
if NS <> nil then
begin
AIncludes.Add(NS);
end;
end;
procedure TgirFile.CheckVersionLimits(const ANameSpace: TgirNamespace);
function SplitVersion(AVersionStr: String; out AVersion: TGirVersion): Boolean;
begin
try
AVersion := girVersion(AVersionStr);
Result := True;
except
Result := False;
end;
end;
function SplitNameSpaceVersionCheck(AOptionName: String; var AVersion: TGirVersion): Boolean;
var
i: Integer;
begin
if FCmdOptions.HasOption(AOptionName) then
with FCmdOptions.OptionValues(AOptionName) do
begin
for i := 0 to Count-1 do
begin
if Lowercase(ANameSpace.NameSpace)+'-' = Lowercase(Copy(Strings[i], 1, Length(ANameSpace.NameSpace)+1)) then
begin
Result := SplitVersion(Copy(Strings[i], Length(ANameSpace.NameSpace)+2, MaxInt), AVersion);
break;
end;
end;
end;
end;
var
lVersion: TGirVersion;
begin
if SplitNameSpaceVersionCheck('max-version', lVersion) then
ANameSpace.MaxSymbolVersion := lVersion
else
ANameSpace.MaxSymbolVersion := girVersion(MaxInt, MaxInt);
if SplitNameSpaceVersionCheck('keep-deprecated-version', lVersion) then
ANameSpace.DeprecatedVersion := lVersion
else
ANameSpace.DeprecatedVersion := girVersion(MaxInt, MaxInt);
end;
function TgirFile.CheckVersionOptions(const ANamespace: String; var AMajor, AMinor: Integer): Boolean;
begin
Result := False;
end;
constructor TgirFile.Create(AOwner: TObject; AOptions: TCommandLineOptions);
begin
Owner := AOwner;
FCmdOptions := AOptions;
FNameSpaces := TgirNamespaces.Create(Self);
end;
destructor TgirFile.Destroy;
begin
FNameSpaces.Free;
inherited Destroy;
end;
procedure TgirFile.ParseXMLDocument(AXML: TXMLDocument);
begin
Self.ParseNode(AXML.DocumentElement);
end;
end.
|