1{ Utility to update every alllclintfunits.pas unit of every LCL widget set.
2}
3program update_allunits;
4
5{$mode objfpc}{$H+}
6
7uses
8  // Note: do not use any LCL unit!
9  Classes, SysUtils;
10
11procedure FindUnits(SrcDir: string; Units: TStrings);
12var
13  FileInfo: TSearchRec;
14  Ext: String;
15  CurUnitName: String;
16begin
17  if FindFirst(SrcDir+'*.*',faAnyFile,FileInfo)=0 then begin
18    repeat
19      // check if special file
20      if (FileInfo.Name='.') or (FileInfo.Name='..') or (FileInfo.Name='') then
21        continue;
22      if (FileInfo.Attr and faDirectory)=0 then begin
23        Ext:=LowerCase(ExtractFileExt(FileInfo.Name));
24        if (Ext='.pp') or (Ext='.pas') or (Ext='.p') then
25        begin
26          CurUnitName:=copy(FileInfo.Name,1,length(FileInfo.Name)-length(Ext));
27          if CompareText(CurUnitName,'AllLCLIntfUnits')=0 then continue;
28          Units.Add(CurUnitName);
29        end;
30      end;
31    until FindNext(FileInfo)<>0;
32  end;
33  FindClose(FileInfo);
34end;
35
36procedure Run(WidgetSet, UnitPaths: string);
37var
38  Units: TStringList;
39  Paths: TStringList;
40  BaseDir, Path: String;
41  i: Integer;
42  Source: TStringList;
43  Filename: String;
44  s: string;
45begin
46  Units:=TStringList.Create;
47  Paths:=TStringList.Create;
48  Source:=TStringList.Create;
49  try
50    BaseDir:='interfaces/'+WidgetSet+'/';
51    FindUnits(BaseDir,Units);
52    Paths.Delimiter:=';';
53    Paths.StrictDelimiter:=true;
54    Paths.DelimitedText:=UnitPaths;
55    for i:=0 to Paths.Count-1 do begin
56      Path:=Trim(Paths[i]);
57      if Path='' then continue;
58      FindUnits(BaseDir+Path,Units);
59    end;
60    Source.Add('{ This unit was automatically created by update_allunits }');
61    Source.Add('unit AllLCLIntfUnits;');
62    Source.Add('interface');
63    Source.Add('uses');
64    for i:=0 to Units.Count-1 do begin
65      s:='  '+Units[i]+'{%H-}';
66      if i=Units.Count-1 then
67        s:=s+';'
68      else
69        s:=s+',';
70      Source.Add(s);
71    end;
72    Source.Add('implementation');
73    Source.Add('end.');
74    Filename:=BaseDir+'alllclintfunits.pas';
75    writeln('writing ',Filename,' ...');
76    Source.SaveToFile(Filename);
77  finally
78    Source.Free;
79    Paths.Free;
80    Units.Free;
81  end;
82end;
83
84begin
85  Run('gtk','');
86  Run('gtk2','');
87  Run('qt','');
88  Run('win32','');
89  Run('nogui','');
90  Run('cocoa','');
91  Run('carbon','objc;pascocoa/appkit;pascocoa/foundation');
92  // fpgui needs manual additions for corelib/x11 and corelib/gdi
93  Run('fpgui','gui;corelib');
94end.
95
96