1{ 2 *************************************************************************** 3 * * 4 * This source is free software; you can redistribute it and/or modify * 5 * it under the terms of the GNU General Public License as published by * 6 * the Free Software Foundation; either version 2 of the License, or * 7 * (at your option) any later version. * 8 * * 9 * This code is distributed in the hope that it will be useful, but * 10 * WITHOUT ANY WARRANTY; without even the implied warranty of * 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 12 * General Public License for more details. * 13 * * 14 * A copy of the GNU General Public License is available on the World * 15 * Wide Web at <http://www.gnu.org/copyleft/gpl.html>. You can also * 16 * obtain it by writing to the Free Software Foundation, * 17 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 18 * * 19 *************************************************************************** 20 21 Author: Mattias Gaertner 22 23 Abstract: 24 Demonstrating, how to read, update and use the unitdictionary. 25} 26program unitdicttest; 27 28{$mode objfpc}{$H+} 29 30uses 31 SysUtils, Laz_AVL_Tree, 32 // LazUtils 33 LazFileUtils, AvgLvlTree, 34 // CodeTools 35 CodeToolManager, FileProcs, 36 DefineTemplates, unitdictionary, CodeToolsStructs; 37 38const 39 ConfigFilename = 'codetools.config'; 40 DictionaryFilename = 'dictionary.txt'; 41var 42 Filename: string; 43 Dictionary: TUnitDictionary; 44 UnitSet: TFPCUnitSetCache; 45 CfgCache: TPCTargetConfigCache; 46 AVLNode: TAVLTreeNode; 47 Item: PStringToStringItem; 48 Directory: String; 49 D2: TUnitDictionary; 50begin 51 CodeToolBoss.SimpleInit(ConfigFilename); 52 53 Dictionary:=TUnitDictionary.Create; 54 try 55 UnitSet:=CodeToolBoss.GetUnitSetForDirectory(''); 56 CfgCache:=UnitSet.GetConfigCache(true); 57 AVLNode:=CfgCache.Units.Tree.FindLowest; 58 Directory:=AppendPathDelim(UnitSet.FPCSourceDirectory)+'packages'; 59 while AVLNode<>nil do begin 60 Item:=PStringToStringItem(AVLNode.Data); 61 FileName:=UnitSet.GetUnitSrcFile(Item^.Name,false); 62 //writeln('UnitName=',Item^.Name,' Source=',Filename); 63 if FilenameIsPascalUnit(Filename) 64 and FileIsInPath(Filename,Directory) then begin 65 //writeln('Filename: ',Filename); 66 // parse the unit 67 try 68 Dictionary.ParseUnit(Filename); 69 except 70 on E: Exception do begin 71 writeln(Filename,' Error: ',E.Message); 72 end; 73 end; 74 end; 75 AVLNode:=CfgCache.Units.Tree.FindSuccessor(AVLNode); 76 end; 77 78 Dictionary.ConsistencyCheck; 79 Dictionary.SaveToFile(DictionaryFilename); 80 81 D2:=TUnitDictionary.Create; 82 D2.LoadFromFile(DictionaryFilename,false); 83 D2.ConsistencyCheck; 84 85 if not D2.Equals(Dictionary) then 86 raise Exception.Create('SaveToFile/LoadFromFile difference'); 87 88 D2.Free; 89 finally 90 Dictionary.Free; 91 end; 92end. 93 94