]> git.pld-linux.org Git - packages/fpc.git/blob - fpc-r34749.patch
- fixes from fedora, rel 2
[packages/fpc.git] / fpc-r34749.patch
1 Index: fpcsrc/utils/fpdoc/dglobals.pp
2 ===================================================================
3 --- fpcsrc/utils/fpdoc/dglobals.pp      (revision 34748)
4 +++ fpcsrc/utils/fpdoc/dglobals.pp      (revision 34749)
5 @@ -161,6 +161,7 @@
6    SUsageOption120  = '                  At least one input option is required.';
7    SUsageOption130  = '--input-dir=Dir   Add All *.pp and *.pas files in Dir to list of input files';
8    SUsageOption140  = '--lang=lng        Select output language.';
9 +  SUsageOption145  = '--macro=name=value Define a macro to preprocess the project file with.';
10    SUsageOption150  = '--ostarget=value  Set the target OS for the scanner.';
11    SUsageOption160  = '--output=name     use name as the output name.';
12    SUsageOption170  = '                  Each backend interprets this as needed.';
13 @@ -183,6 +184,7 @@
14    SUsageFormats        = 'The following output formats are supported by this fpdoc:';
15    SUsageBackendHelp    = 'Specify an output format, combined with --help to get more help for this backend.';
16    SUsageFormatSpecific = 'Output format "%s" supports the following options:';
17 +  SCmdLineErrInvalidMacro     = 'Macro needs to be in the form name=value';
18  
19    SCmdLineInvalidOption       = 'Ignoring unknown option "%s"';
20    SCmdLineInvalidFormat       = 'Invalid format "%s" specified';
21 Index: fpcsrc/utils/fpdoc/mkfpdoc.pp
22 ===================================================================
23 --- fpcsrc/utils/fpdoc/mkfpdoc.pp       (revision 34748)
24 +++ fpcsrc/utils/fpdoc/mkfpdoc.pp       (revision 34749)
25 @@ -26,6 +26,7 @@
26      FOnLog: TPasParserLogHandler;
27      FPParserLogEvents: TPParserLogEvents;
28      FProject : TFPDocProject;
29 +    FProjectMacros: TStrings;
30      FScannerLogEvents: TPScannerLogEvents;
31      FVerbose: Boolean;
32      function GetOptions: TEngineOptions;
33 @@ -32,6 +33,7 @@
34      function GetPackages: TFPDocPackages;
35      procedure SetBaseDescrDir(AValue: String);
36      procedure SetBaseInputDir(AValue: String);
37 +    procedure SetProjectMacros(AValue: TStrings);
38    Protected
39      Function FixInputFile(Const AFileName : String) : String;
40      Function FixDescrFile(Const AFileName : String) : String;
41 @@ -58,6 +60,8 @@
42      // When set, they will be prepended to non-absolute filenames.
43      Property BaseInputDir : String Read FBaseInputDir Write SetBaseInputDir;
44      Property BaseDescrDir : String Read FBaseDescrDir Write SetBaseDescrDir;
45 +    // Macros used when loading the project file
46 +    Property ProjectMacros : TStrings Read FProjectMacros Write SetProjectMacros;
47    end;
48  
49  implementation
50 @@ -81,13 +85,13 @@
51      end;
52  end;
53  
54 -Procedure TFPDocCreator.DoLog(Const Msg: String);
55 +procedure TFPDocCreator.DoLog(const Msg: String);
56  begin
57    If Assigned(OnLog) then
58      OnLog(Self,Msg);
59  end;
60  
61 -procedure TFPDocCreator.DoLog(Const Fmt: String; Args: Array of Const);
62 +procedure TFPDocCreator.DoLog(const Fmt: String; Args: array of const);
63  begin
64    DoLog(Format(Fmt,Args));
65  end;
66 @@ -132,7 +136,7 @@
67    Result:=FProject.Packages;
68  end;
69  
70 -Function TFPDocCreator.FixInputFile(Const AFileName: String): String;
71 +function TFPDocCreator.FixInputFile(const AFileName: String): String;
72  begin
73    Result:=AFileName;
74    If Result='' then exit;
75 @@ -140,7 +144,7 @@
76      Result:=BaseInputDir+Result;
77  end;
78  
79 -Function TFPDocCreator.FixDescrFile(Const AFileName: String): String;
80 +function TFPDocCreator.FixDescrFile(const AFileName: String): String;
81  begin
82    Result:=AFileName;
83    If Result='' then exit;
84 @@ -164,13 +168,19 @@
85      FBaseInputDir:=IncludeTrailingPathDelimiter(FBaseInputDir);
86  end;
87  
88 -Procedure TFPDocCreator.DoBeforeEmitNote(Sender: TObject; Note: TDomElement;
89 -  Var EmitNote: Boolean);
90 +procedure TFPDocCreator.SetProjectMacros(AValue: TStrings);
91  begin
92 +  if FProjectMacros=AValue then Exit;
93 +  FProjectMacros.Assign(AValue);
94 +end;
95 +
96 +procedure TFPDocCreator.DoBeforeEmitNote(Sender: TObject; Note: TDomElement;
97 +  var EmitNote: Boolean);
98 +begin
99    EmitNote:=True;
100  end;
101  
102 -Constructor TFPDocCreator.Create(AOwner: TComponent);
103 +constructor TFPDocCreator.Create(AOwner: TComponent);
104  begin
105    inherited Create(AOwner);
106    FProject:=TFPDocProject.Create(Self);
107 @@ -178,12 +188,14 @@
108    FProject.Options.CPUTarget:=DefCPUTarget;
109    FProject.Options.OSTarget:=DefOSTarget;
110    FProcessedUnits:=TStringList.Create;
111 +  FProjectMacros:=TStringList.Create;
112  end;
113  
114 -Destructor TFPDocCreator.Destroy;
115 +destructor TFPDocCreator.Destroy;
116  begin
117    FreeAndNil(FProcessedUnits);
118    FreeAndNil(FProject);
119 +  FreeAndNil(FProjectMacros);
120    inherited Destroy;
121  end;
122  
123 @@ -221,7 +233,7 @@
124      Engine.WriteContentFile(APackage.ContentFile);
125  end;
126  
127 -Procedure TFPDocCreator.CreateDocumentation(APackage: TFPDocPackage;
128 +procedure TFPDocCreator.CreateDocumentation(APackage: TFPDocPackage;
129    ParseOnly: Boolean);
130  
131  var
132 @@ -282,7 +294,7 @@
133    end;
134  end;
135  
136 -Procedure TFPDocCreator.CreateProjectFile(Const AFileName: string);
137 +procedure TFPDocCreator.CreateProjectFile(const AFileName: string);
138  begin
139    With TXMLFPDocOptions.Create(Self) do
140    try
141 @@ -292,11 +304,14 @@
142    end;
143  end;
144  
145 -Procedure TFPDocCreator.LoadProjectFile(Const AFileName: string);
146 +procedure TFPDocCreator.LoadProjectFile(const AFileName: string);
147  begin
148    With TXMLFPDocOptions.Create(self) do
149      try
150 -      LoadOptionsFromFile(FProject,AFileName);
151 +      if (ProjectMacros.Count>0) then
152 +        LoadOptionsFromFile(FProject,AFileName,ProjectMacros)
153 +      else
154 +        LoadOptionsFromFile(FProject,AFileName,Nil);
155      finally
156        Free;
157      end;
158 Index: fpcsrc/utils/fpdoc/fpdoc.pp
159 ===================================================================
160 --- fpcsrc/utils/fpdoc/fpdoc.pp (revision 34748)
161 +++ fpcsrc/utils/fpdoc/fpdoc.pp (revision 34749)
162 @@ -90,6 +90,7 @@
163    Writeln(SUsageOption120);
164    Writeln(SUsageOption130);
165    Writeln(SUsageOption140);
166 +  Writeln(SUsageOption145);
167    Writeln(SUsageOption150);
168    Writeln(SUsageOption160);
169    Writeln(SUsageOption170);
170 @@ -181,11 +182,12 @@
171  Const
172    SOptProject = '--project=';
173    SOptPackage = '--package=';
174 -  
175 +  SOptMacro = '--macro=';
176 +
177    Function ProjectOpt(Const s : string) : boolean;
178  
179    begin
180 -    Result:=(Copy(s,1,3)='-p=') or (Copy(s,1,Length(SOptProject))=SOptProject);
181 +    Result:=(Copy(s,1,3)='-p=') or (Copy(s,1,Length(SOptProject))=SOptProject) or (Copy(s,1,Length(SOptMacro))=SOptMacro);
182    end;
183  
184    Function PackageOpt(Const s : string) : boolean;
185 @@ -286,7 +288,7 @@
186  
187  var
188    i: Integer;
189 -  Cmd, Arg: String;
190 +  ProjectFileName,Cmd, Arg: String;
191  
192  begin
193    if (s = '-h') or (s = '--help') then
194 @@ -325,6 +327,12 @@
195        AddDirToFileList(SelectedPackage.Descriptions, Arg, '*.xml')
196      else if (Cmd = '--base-descr-dir') then
197        FCreator.BaseDescrDir:=Arg
198 +    else if (Cmd = '--macro') then
199 +      begin
200 +      If Pos('=',Arg)=0 then
201 +        WriteLn(StdErr, Format(SCmdLineErrInvalidMacro, [Arg]));
202 +      FCreator.ProjectMacros.Add(Arg);
203 +      end
204      else if (Cmd = '-f') or (Cmd = '--format') then
205        begin
206        Arg:=UpperCase(Arg);
207 @@ -384,23 +392,28 @@
208  Procedure TFPDocApplication.DoRun;
209  
210  begin
211 -{$IFDEF Unix}
212 -  gettext.TranslateResourceStrings('/usr/local/share/locale/%s/LC_MESSAGES/fpdoc.mo');
213 -{$ELSE}
214 -  gettext.TranslateResourceStrings('intl/fpdoc.%s.mo');
215 -{$ENDIF}
216 -  WriteLn(STitle);
217 -  WriteLn(Format(SVersion, [DefFPCVersion, DefFPCDate]));
218 -  WriteLn(SCopyright1);
219 -  WriteLn(SCopyright2);
220 -  WriteLn;
221 -  ParseCommandLine;
222 -  if (FWriteProjectFile<>'') then
223 -    FCreator.CreateProjectFile(FWriteProjectFile)
224 -  else
225 -    FCreator.CreateDocumentation(FPackage,FDryRun);
226 -  WriteLn(SDone);
227 -  Terminate;
228 +  try
229 +  {$IFDEF Unix}
230 +    gettext.TranslateResourceStrings('/usr/local/share/locale/%s/LC_MESSAGES/fpdoc.mo');
231 +  {$ELSE}
232 +    gettext.TranslateResourceStrings('intl/fpdoc.%s.mo');
233 +  {$ENDIF}
234 +    WriteLn(STitle);
235 +    WriteLn(Format(SVersion, [DefFPCVersion, DefFPCDate]));
236 +    WriteLn(SCopyright1);
237 +    WriteLn(SCopyright2);
238 +    WriteLn;
239 +    ParseCommandLine;
240 +    if (FWriteProjectFile<>'') then
241 +      FCreator.CreateProjectFile(FWriteProjectFile)
242 +    else
243 +      FCreator.CreateDocumentation(FPackage,FDryRun);
244 +    WriteLn(SDone);
245 +    Terminate;
246 +  except
247 +    ExitCode:=1;
248 +    Raise;
249 +  end;
250  end;
251  
252  constructor TFPDocApplication.Create(AOwner: TComponent);
253 Index: fpcsrc/utils/fpdoc/fpdocxmlopts.pas
254 ===================================================================
255 --- fpcsrc/utils/fpdoc/fpdocxmlopts.pas (revision 34748)
256 +++ fpcsrc/utils/fpdoc/fpdocxmlopts.pas (revision 34749)
257 @@ -13,6 +13,7 @@
258    TXMLFPDocOptions = Class(TComponent)
259    private
260    Protected
261 +    Function PreProcessFile(const AFileName: String; Macros: TStrings): TStream; virtual;
262      Procedure Error(Const Msg : String);
263      Procedure Error(Const Fmt : String; Args : Array of Const);
264      Procedure LoadPackage(APackage : TFPDocPackage; E : TDOMElement); virtual;
265 @@ -24,7 +25,7 @@
266      procedure SaveInputFile(const AInputFile: String; XML: TXMLDocument; AParent: TDOMElement);virtual;
267      Procedure SavePackage(APackage : TFPDocPackage; XML : TXMLDocument; AParent : TDOMElement); virtual;
268    Public
269 -    Procedure LoadOptionsFromFile(AProject : TFPDocProject; Const AFileName : String);
270 +    Procedure LoadOptionsFromFile(AProject : TFPDocProject; Const AFileName : String; Macros : TStrings = Nil);
271      Procedure LoadFromXML(AProject : TFPDocProject; XML : TXMLDocument); virtual;
272      Procedure SaveOptionsToFile(AProject : TFPDocProject; Const AFileName : String);
273      procedure SaveToXML(AProject : TFPDocProject; ADoc: TXMLDocument); virtual;
274 @@ -65,7 +66,7 @@
275  end;
276  
277  
278 -procedure TXMLFPDocOptions.Error(Const Msg: String);
279 +procedure TXMLFPDocOptions.Error(const Msg: String);
280  begin
281    Raise EXMLFPDoc.Create(Msg);
282  end;
283 @@ -248,7 +249,8 @@
284      end;
285  end;
286  
287 -Procedure TXMLFPDocOptions.SaveEngineOptions(Options : TEngineOptions; XML : TXMLDocument; AParent : TDOMElement);
288 +procedure TXMLFPDocOptions.SaveEngineOptions(Options: TEngineOptions;
289 +  XML: TXMLDocument; AParent: TDOMElement);
290  
291    procedure AddStr(const n, v: string);
292    var
293 @@ -288,7 +290,8 @@
294  end;
295  
296  
297 -Procedure TXMLFPDocOptions.SaveInputFile(Const AInputFile : String; XML : TXMLDocument; AParent: TDOMElement);
298 +procedure TXMLFPDocOptions.SaveInputFile(const AInputFile: String;
299 +  XML: TXMLDocument; AParent: TDOMElement);
300  
301  Var
302    F,O : String;
303 @@ -299,7 +302,8 @@
304    AParent['options']:=O;
305  end;
306  
307 -Procedure TXMLFPDocOptions.SaveDescription(Const ADescription : String; XML : TXMLDocument; AParent: TDOMElement);
308 +procedure TXMLFPDocOptions.SaveDescription(const ADescription: String;
309 +  XML: TXMLDocument; AParent: TDOMElement);
310  
311  begin
312    AParent['file']:=ADescription;
313 @@ -317,7 +321,8 @@
314    AParent['prefix']:=Copy(AImportFile,i+1,Length(AImportFile));
315  end;
316  
317 -Procedure TXMLFPDocOptions.SavePackage(APackage: TFPDocPackage; XML : TXMLDocument; AParent: TDOMElement);
318 +procedure TXMLFPDocOptions.SavePackage(APackage: TFPDocPackage;
319 +  XML: TXMLDocument; AParent: TDOMElement);
320  
321  
322  var
323 @@ -358,17 +363,55 @@
324  end;
325  
326  
327 +Function TXMLFPDocOptions.PreprocessFile(const AFileName: String; Macros : TStrings) : TStream;
328  
329 -procedure TXMLFPDocOptions.LoadOptionsFromFile(AProject: TFPDocProject; const AFileName: String);
330 +Var
331 +  F : TFileStream;
332 +  P : TTemplateParser;
333 +  I : Integer;
334 +  N,V : String;
335  
336 +begin
337 +  Result:=Nil;
338 +  P:=Nil;
339 +  F:=TFileStream.Create(AFileName,fmOpenRead or fmShareDenyWrite);
340 +  try
341 +    P:=TTemplateParser.Create;
342 +    P.AllowTagParams:=False;
343 +    P.StartDelimiter:='{{';
344 +    P.EndDelimiter:='}}';
345 +    For I:=0 to Macros.Count-1 do
346 +      begin
347 +      Macros.GetNameValue(I,N,V);
348 +      P.Values[N]:=V;
349 +      end;
350 +    Result:=TMemoryStream.Create;
351 +    P.ParseStream(F,Result);
352 +    Result.Position:=0;
353 +  finally
354 +    FreeAndNil(F);
355 +    FreeAndNil(P);
356 +  end;
357 +end;
358 +
359 +procedure TXMLFPDocOptions.LoadOptionsFromFile(AProject: TFPDocProject;
360 +  const AFileName: String; Macros: TStrings = Nil);
361 +
362  Var
363    XML : TXMLDocument;
364 +  S : TStream;
365  
366  begin
367 -  ReadXMLFile(XML,AFileName);
368 +  XML:=Nil;
369 +  if Macros=Nil then
370 +    S:=TFileStream.Create(AFileName,fmOpenRead or fmShareDenyWrite)
371 +  else
372 +    S:=PreProcessFile(AFileName,Macros);
373    try
374 +    ReadXMLFile(XML,S);
375      LoadFromXML(AProject,XML);
376    finally
377 +    FreeAndNil(S);
378      FreeAndNil(XML);
379    end;
380  end;
381 @@ -393,7 +436,8 @@
382      LoadEngineOptions(AProject.Options,N as TDOMElement);
383  end;
384  
385 -Procedure TXMLFPDocOptions.SaveOptionsToFile(AProject: TFPDocProject; const AFileName: String);
386 +procedure TXMLFPDocOptions.SaveOptionsToFile(AProject: TFPDocProject;
387 +  const AFileName: String);
388  
389  Var
390    XML : TXMLDocument;
This page took 0.051966 seconds and 3 git commands to generate.