dglobals.pp 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344
  1. {
  2. FPDoc - Free Pascal Documentation Tool
  3. Copyright (C) 2000 - 2002 by
  4. Areca Systems GmbH / Sebastian Guenther, [email protected]
  5. * Global declarations
  6. * Link list management
  7. * Document node tree
  8. * Main engine
  9. See the file COPYING, included in this distribution,
  10. for details about the copyright.
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. }
  15. {$MODE objfpc}
  16. {$H+}
  17. unit dGlobals;
  18. interface
  19. uses Classes, DOM, PasTree, PParser;
  20. Var
  21. LEOL : Integer;
  22. modir : string;
  23. resourcestring
  24. // Output strings
  25. SDocPackageTitle = 'Reference for package ''%s''';
  26. SDocPrograms = 'Programs';
  27. SDocUnits = 'Units';
  28. SDocUnitTitle = 'Reference for unit ''%s''';
  29. SDocInterfaceSection = 'Interface section';
  30. SDocImplementationSection = 'Implementation section';
  31. SDocUsedUnits = 'Used units';
  32. SDocUsedUnitsByUnitXY = 'Used units by unit ''%s''';
  33. SDocConstsTypesVars = 'Constants, types and variables';
  34. SDocResStrings = 'Resource strings';
  35. SDocTypes = 'Types';
  36. SDocConstants = 'Constants';
  37. SDocClasses = 'Classes';
  38. SDocProceduresAndFunctions = 'Procedures and functions';
  39. SDocVariables = 'Variables';
  40. SDocIdentifierIndex = 'Index';
  41. SDocModuleIndex = 'Index of all identifiers in unit ''%s''';
  42. SDocPackageIndex = 'Index of all identifiers in package ''%s''';
  43. SDocUnitOverview = 'Overview of unit ''%s''';
  44. SDocOverview = 'Overview';
  45. SDocSearch = 'Search';
  46. SDocDeclaration = 'Declaration';
  47. SDocDescription = 'Description';
  48. SDocErrors = 'Errors';
  49. SDocVersion = 'Version info';
  50. SDocSeeAlso = 'See also';
  51. SDocExample = 'Example';
  52. SDocArguments = 'Arguments';
  53. SDocFunctionResult = 'Function result';
  54. SDocRemark = 'Remark: ';
  55. SDocMethodOverview = 'Method overview';
  56. SDocPropertyOverview = 'Property overview';
  57. SDocPage = 'Page';
  58. SDocMethod = 'Method';
  59. SDocProperty = 'Property';
  60. SDocAccess = 'Access';
  61. SDocInheritance = 'Inheritance';
  62. SDocProperties = 'Properties';
  63. SDocMethods = 'Methods';
  64. SDocEvents = 'Events';
  65. SDocByName = 'by Name';
  66. SDocValue = 'Value';
  67. SDocExplanation = 'Explanation';
  68. SDocProcedure = 'Procedure';
  69. SDocValuesForEnum = 'Enumeration values for type %s';
  70. SDocSourcePosition = 'Source position: %s line %d';
  71. SDocSynopsis = 'Synopsis';
  72. SDocVisibility = 'Visibility';
  73. SDocOpaque = 'Opaque type';
  74. SDocDateGenerated = 'Documentation generated on: %s';
  75. // Topics
  76. SDocRelatedTopics = 'Related topics';
  77. SDocUp = 'Up';
  78. SDocNext = 'Next';
  79. SDocPrevious = 'Previous';
  80. // Various backend constants
  81. SDocChapter = 'Chapter';
  82. SDocSection = 'Section';
  83. SDocSubSection = 'Subsection';
  84. SDocTable = 'Table';
  85. SDocListing = 'Listing';
  86. // Man page usage
  87. SManUsageManSection = 'Use ASection as the man page section';
  88. SManUsageNoUnitPrefix = 'Do not prefix man pages with unit name.';
  89. SManUsageWriterDescr = 'UNIX man page output.';
  90. SManUsagePackageDescription = 'Use descr as the description of man pages';
  91. // HTML usage
  92. SHTMLUsageFooter = 'Append xhtml from file as footer to html page';
  93. SHTMLUsageFooterDate = 'Append footer with date. fmt is Optional format for FormatDateTime';
  94. SHTMLUsageCharset = 'Set the HTML character set';
  95. SHTMLHtmlSearch = 'Add search page with given name to the menu bar';
  96. SHTMLIndexColcount = 'Use N columns in the identifier index pages';
  97. SHTMLImageUrl = 'Prefix image URLs with url';
  98. // CHM usage
  99. SCHMUsageTOC = 'Use [File] as the table of contents. Usually a .hhc file.';
  100. SCHMUsageIndex = 'Use [File] as the index. Usually a .hhk file.';
  101. SCHMUsageDefPage = 'Set the "Home" page relative to where it lives in the chm. i.e. "/index.html"';
  102. SCHMUsageOtrFiles= 'A txt file containing a list of files to be added relative to the working directory.';
  103. SCHMUsageCSSFile = 'Filename of a .css file to be included in the chm.';
  104. SCHMUsageAutoTOC = 'Automatically generate a Table of Contents. Ignores --toc-file';
  105. SCHMUsageAutoIDX = 'Automatically generate an Index. Ignores --index-file';
  106. SCHMUsageMakeSearch = 'Automatically generate a Search Index from filenames that match *.htm*';
  107. STitle = 'FPDoc - Free Pascal Documentation Tool';
  108. SVersion = 'Version %s [%s]';
  109. SCopyright = '(c) 2000 - 2003 Areca Systems GmbH / Sebastian Guenther, [email protected]';
  110. SCmdLineHelp = 'Usage: %s [options]';
  111. SUsageOption010 = '--content Create content file for package cross-references';
  112. SUsageOption020 = '--cputarget=value Set the target CPU for the scanner.';
  113. SUsageOption030 = '--descr=name use name as description file. ';
  114. SUsageOption040 = ' This option is allowed more than once';
  115. SUsageOption050 = '--format=fmt Select output format.';
  116. SUsageOption060 = '--help Show this help.';
  117. SUsageOption070 = '--hide-protected Do not show protected methods in overview';
  118. SUsageOption080 = '--import=file Import content file for package cross-references';
  119. SUsageOption090 = '--input=cmd use cmd as input for the parser.';
  120. SUsageOption100 = ' At least one input option is required.';
  121. SUsageOption110 = '--lang=lng Select output language.';
  122. SUsageOption120 = '--ostarget=value Set the target OS for the scanner.';
  123. SUsageOption130 = '--output=name use name as the output name.';
  124. SUsageOption140 = ' Each backend interpretes this as needed.';
  125. SUsageOption150 = '--package=name Set the package name for which to create output';
  126. SUsageOption160 = '--show-private Show private methods.';
  127. SUsageOption170 = '--warn-no-node Warn if no documentation node was found.';
  128. SUsageOption180 = '--mo-dir=dir Set directory where language files reside to dir';
  129. SUsageOption190 = '--parse-impl (Experimental) try to parse implementation too';
  130. SUsageFormats = 'The following output formats are supported by this fpdoc:';
  131. SUsageBackendHelp = 'Specify an output format, combined with --help to get more help for this backend.';
  132. SUsageFormatSpecific = 'Output format "%s" supports the following options:';
  133. SCmdLineInvalidOption = 'Ignoring unknown option "%s"';
  134. SCmdLineInvalidFormat = 'Invalid format "%s" specified';
  135. SCmdLineOutputOptionMissing = 'Need an output filename, please specify one with --output=<filename>';
  136. SWritingPages = 'Writing %d pages...';
  137. SNeedPackageName = 'No package name specified. Please specify one using the --package option.';
  138. SDone = 'Done.';
  139. SErrCouldNotCreateOutputDir = 'Could not create output directory "%s"';
  140. SErrCouldNotCreateFile = 'Could not create file "%s": %s';
  141. SSeeURL = '(See %s)'; // For lineair text writers.
  142. Const
  143. SVisibility: array[TPasMemberVisibility] of string =
  144. ('Default', 'Private', 'Protected', 'Public',
  145. 'Published', 'Automated','Strict Private','Strict Protected');
  146. type
  147. // Assumes a list of TObject instances and frees them on destruction
  148. TObjectList = class(TList)
  149. public
  150. destructor Destroy; override;
  151. end;
  152. { Link entry tree
  153. TFPDocEngine stores the root of the entry tree in its property
  154. "RootLinkNode". The root has one child node for each package, for which
  155. documentation links are available. The children of a package node
  156. are module nodes; and the children of a module node are the top-level
  157. declarations of this module; the next level in the tree stores e.g. record
  158. members, and so on...
  159. }
  160. TLinkNode = class
  161. private
  162. FFirstChild, FNextSibling: TLinkNode;
  163. FName: String;
  164. FLink: String;
  165. public
  166. constructor Create(const AName, ALink: String);
  167. destructor Destroy; override;
  168. function FindChild(const APathName: String): TLinkNode;
  169. function CreateChildren(const APathName, ALinkTo: String): TLinkNode;
  170. // Properties for tree structure
  171. property FirstChild: TLinkNode read FFirstChild;
  172. property NextSibling: TLinkNode read FNextSibling;
  173. // Link properties
  174. property Name: String read FName;
  175. property Link: String read FLink;
  176. end;
  177. { Documentation entry tree
  178. TFPDocEngine stores the root of the entry tree in its property
  179. "RootDocNode". The root has one child node for each package, for which
  180. documentation is being provided by the user. The children of a package node
  181. are module nodes; and the children of a module node are the top-level
  182. declarations of this module; the next level in the tree stores e.g. record
  183. members, and so on...
  184. }
  185. { TDocNode }
  186. TDocNode = class
  187. private
  188. FFirstChild, FNextSibling: TDocNode;
  189. FName: String;
  190. FNode: TDOMElement;
  191. FIsSkipped: Boolean;
  192. FShortDescr: TDOMElement;
  193. FDescr: TDOMElement;
  194. FErrorsDoc: TDOMElement;
  195. FSeeAlso: TDOMElement;
  196. FFirstExample: TDOMElement;
  197. FLink: String;
  198. FTopicNode : Boolean;
  199. FRefCount : Integer;
  200. FVersion: TDomElement;
  201. public
  202. constructor Create(const AName: String; ANode: TDOMElement);
  203. destructor Destroy; override;
  204. Function IncRefcount : Integer;
  205. function FindChild(const APathName: String): TDocNode;
  206. function CreateChildren(const APathName: String): TDocNode;
  207. // Properties for tree structure
  208. property FirstChild: TDocNode read FFirstChild;
  209. property NextSibling: TDocNode read FNextSibling;
  210. // Basic properties
  211. property Name: String read FName;
  212. property Node: TDOMElement read FNode;
  213. // Data fetched from the XML document
  214. property IsSkipped: Boolean read FIsSkipped;
  215. property ShortDescr: TDOMElement read FShortDescr;
  216. property Descr: TDOMElement read FDescr;
  217. property ErrorsDoc: TDOMElement read FErrorsDoc;
  218. Property Version : TDomElement Read FVersion;
  219. property SeeAlso: TDOMElement read FSeeAlso;
  220. property FirstExample: TDOMElement read FFirstExample;
  221. property Link: String read FLink;
  222. Property TopicNode : Boolean Read FTopicNode;
  223. Property RefCount : Integer Read FRefCount;
  224. end;
  225. // The main FPDoc engine
  226. { TFPDocEngine }
  227. TFPDocEngine = class(TPasTreeContainer)
  228. private
  229. protected
  230. DescrDocs: TObjectList; // List of XML documents
  231. DescrDocNames: TStringList; // Names of the XML documents
  232. FRootLinkNode: TLinkNode;
  233. FRootDocNode: TDocNode;
  234. FPackages: TList; // List of TFPPackage objects
  235. CurModule: TPasModule;
  236. CurPackageDocNode: TDocNode;
  237. public
  238. Output: String;
  239. HasContentFile: Boolean;
  240. HidePrivate: Boolean; // Hide private class members in output?
  241. HideProtected: Boolean; // Hide protected class members in output?
  242. WarnNoNode : Boolean; // Warn if no description node found for element.
  243. constructor Create;
  244. destructor Destroy; override;
  245. procedure SetPackageName(const APackageName: String);
  246. procedure ReadContentFile(const AFilename, ALinkPrefix: String);
  247. procedure WriteContentFile(const AFilename: String);
  248. function CreateElement(AClass: TPTreeElement; const AName: String;
  249. AParent: TPasElement; AVisibility: TPasMemberVisibility;
  250. const ASourceFilename: String; ASourceLinenumber: Integer): TPasElement;
  251. override;
  252. function FindElement(const AName: String): TPasElement; override;
  253. function FindModule(const AName: String): TPasModule; override;
  254. // Link tree support
  255. procedure AddLink(const APathName, ALinkTo: String);
  256. function FindAbsoluteLink(const AName: String): String;
  257. function ResolveLink(AModule: TPasModule; const ALinkDest: String): String;
  258. function FindLinkedNode(ANode: TDocNode): TDocNode;
  259. // Documentation file support
  260. procedure AddDocFile(const AFilename: String);
  261. // Documentation retrieval
  262. function FindDocNode(AElement: TPasElement): TDocNode;
  263. function FindDocNode(ARefModule: TPasModule; const AName: String): TDocNode;
  264. function FindShortDescr(AElement: TPasElement): TDOMElement;
  265. function FindShortDescr(ARefModule: TPasModule;
  266. const AName: String): TDOMElement;
  267. function GetExampleFilename(const ExElement: TDOMElement): String;
  268. property RootLinkNode: TLinkNode read FRootLinkNode;
  269. property RootDocNode: TDocNode read FRootDocNode;
  270. property Package: TPasPackage read FPackage;
  271. end;
  272. procedure TranslateDocStrings(const Lang: String);
  273. Function IsLinkNode(Node : TDomNode) : Boolean;
  274. Function IsExampleNode(Example : TDomNode) : Boolean;
  275. // returns true is link is an absolute URI
  276. Function IsLinkAbsolute(ALink: String): boolean;
  277. implementation
  278. uses SysUtils, Gettext, XMLRead;
  279. const
  280. AbsoluteLinkPrefixes : array[0..2] of string = ('/', 'http://', 'ms-its:');
  281. { TObjectList }
  282. destructor TObjectList.Destroy;
  283. var
  284. i: Integer;
  285. begin
  286. for i := 0 to Count - 1 do
  287. TObject(Items[i]).Free;
  288. inherited Destroy;
  289. end;
  290. { TLinkNode }
  291. constructor TLinkNode.Create(const AName, ALink: String);
  292. begin
  293. inherited Create;
  294. FName := AName;
  295. FLink := ALink;
  296. end;
  297. destructor TLinkNode.Destroy;
  298. begin
  299. if Assigned(FirstChild) then
  300. FirstChild.Free;
  301. if Assigned(NextSibling) then
  302. NextSibling.Free;
  303. inherited Destroy;
  304. end;
  305. function TLinkNode.FindChild(const APathName: String): TLinkNode;
  306. var
  307. DotPos: Integer;
  308. ChildName: String;
  309. Child: TLinkNode;
  310. begin
  311. if Length(APathName) = 0 then
  312. Result := Self
  313. else
  314. begin
  315. DotPos := Pos('.', APathName);
  316. if DotPos = 0 then
  317. ChildName := APathName
  318. else
  319. ChildName := Copy(APathName, 1, DotPos - 1);
  320. Child := FirstChild;
  321. while Assigned(Child) do
  322. begin
  323. if CompareText(Child.Name, ChildName) = 0 then
  324. begin
  325. if DotPos = 0 then
  326. Result := Child
  327. else
  328. Result := Child.FindChild(
  329. Copy(APathName, DotPos + 1, Length(APathName)));
  330. exit;
  331. end;
  332. Child := Child.NextSibling;
  333. end;
  334. Result := nil;
  335. end;
  336. end;
  337. function TLinkNode.CreateChildren(const APathName, ALinkTo: String): TLinkNode;
  338. var
  339. DotPos: Integer;
  340. ChildName: String;
  341. Child, LastChild: TLinkNode;
  342. begin
  343. if Length(APathName) = 0 then
  344. Result := Self
  345. else
  346. begin
  347. DotPos := Pos('.', APathName);
  348. if DotPos = 0 then
  349. ChildName := APathName
  350. else
  351. ChildName := Copy(APathName, 1, DotPos - 1);
  352. Child := FirstChild;
  353. LastChild := nil;
  354. while Assigned(Child) do
  355. begin
  356. if CompareText(Child.Name, ChildName) = 0 then
  357. begin
  358. if DotPos = 0 then
  359. Result := Child
  360. else
  361. Result := Child.CreateChildren(
  362. Copy(APathName, DotPos + 1, Length(APathName)), ALinkTo);
  363. exit;
  364. end;
  365. LastChild := Child;
  366. Child := Child.NextSibling;
  367. end;
  368. { No child found, let's create one if we are at the end of the path }
  369. if DotPos > 0 then
  370. // !!!: better throw an exception
  371. WriteLn('Link path does not exist: ', APathName);
  372. Result := TLinkNode.Create(ChildName, ALinkTo);
  373. if Assigned(LastChild) then
  374. LastChild.FNextSibling := Result
  375. else
  376. FFirstChild := Result;
  377. end;
  378. end;
  379. { TDocNode }
  380. constructor TDocNode.Create(const AName: String; ANode: TDOMElement);
  381. begin
  382. inherited Create;
  383. FName := AName;
  384. FNode := ANode;
  385. end;
  386. destructor TDocNode.Destroy;
  387. begin
  388. if Assigned(FirstChild) then
  389. FirstChild.Free;
  390. if Assigned(NextSibling) then
  391. NextSibling.Free;
  392. inherited Destroy;
  393. end;
  394. Function TDocNode.IncRefcount : Integer;
  395. begin
  396. Inc(FRefCount);
  397. Result:=FRefCount;
  398. end;
  399. function TDocNode.FindChild(const APathName: String): TDocNode;
  400. var
  401. DotPos: Integer;
  402. ChildName: String;
  403. Child: TDocNode;
  404. begin
  405. if Length(APathName) = 0 then
  406. Result := Self
  407. else
  408. begin
  409. DotPos := Pos('.', APathName);
  410. if DotPos = 0 then
  411. ChildName := APathName
  412. else
  413. ChildName := Copy(APathName, 1, DotPos - 1);
  414. Child := FirstChild;
  415. while Assigned(Child) do
  416. begin
  417. if CompareText(Child.Name, ChildName) = 0 then
  418. begin
  419. if DotPos = 0 then
  420. Result := Child
  421. else
  422. Result := Child.FindChild(
  423. Copy(APathName, DotPos + 1, Length(APathName)));
  424. exit;
  425. end;
  426. Child := Child.NextSibling;
  427. end;
  428. Result := nil;
  429. end;
  430. end;
  431. function TDocNode.CreateChildren(const APathName: String): TDocNode;
  432. var
  433. DotPos: Integer;
  434. ChildName: String;
  435. Child: TDocNode;
  436. begin
  437. if Length(APathName) = 0 then
  438. Result := Self
  439. else
  440. begin
  441. DotPos := Pos('.', APathName);
  442. if DotPos = 0 then
  443. ChildName := APathName
  444. else
  445. ChildName := Copy(APathName, 1, DotPos - 1);
  446. Child := FirstChild;
  447. while Assigned(Child) do
  448. begin
  449. if CompareText(Child.Name, ChildName) = 0 then
  450. begin
  451. if DotPos = 0 then
  452. Result := Child
  453. else
  454. Result := Child.CreateChildren(
  455. Copy(APathName, DotPos + 1, Length(APathName)));
  456. exit;
  457. end;
  458. Child := Child.NextSibling;
  459. end;
  460. // No child found, let's create one
  461. Result := TDocNode.Create(ChildName, nil);
  462. if Assigned(FirstChild) then
  463. begin
  464. Result.FNextSibling := FirstChild;
  465. FFirstChild := Result;
  466. end else
  467. FFirstChild := Result;
  468. if DotPos > 0 then
  469. Result := Result.CreateChildren(
  470. Copy(APathName, DotPos + 1, Length(APathName)));
  471. end;
  472. end;
  473. { TFPDocEngine }
  474. constructor TFPDocEngine.Create;
  475. begin
  476. inherited Create;
  477. DescrDocs := TObjectList.Create;
  478. DescrDocNames := TStringList.Create;
  479. FRootLinkNode := TLinkNode.Create('', '');
  480. FRootDocNode := TDocNode.Create('', nil);
  481. HidePrivate := True;
  482. InterfaceOnly:=True;
  483. FPackages := TList.Create;
  484. end;
  485. destructor TFPDocEngine.Destroy;
  486. var
  487. i: Integer;
  488. begin
  489. for i := 0 to FPackages.Count - 1 do
  490. TPasPackage(FPackages[i]).Release;
  491. FPackages.Free;
  492. FRootDocNode.Free;
  493. FRootLinkNode.Free;
  494. DescrDocNames.Free;
  495. DescrDocs.Free;
  496. inherited Destroy;
  497. end;
  498. procedure TFPDocEngine.SetPackageName(const APackageName: String);
  499. begin
  500. ASSERT(not Assigned(Package));
  501. FPackage := TPasPackage(inherited CreateElement(TPasPackage,
  502. '#' + APackageName, nil, '', 0));
  503. FPackages.Add(FPackage);
  504. CurPackageDocNode := RootDocNode.FindChild('#' + APackageName);
  505. If Assigned(CurPackageDocNode) then
  506. CurPackageDocNode.IncRefCount;
  507. end;
  508. procedure TFPDocEngine.ReadContentFile(const AFilename, ALinkPrefix: String);
  509. var
  510. f: Text;
  511. procedure ReadLinkTree;
  512. var
  513. s: String;
  514. PrevSpaces, ThisSpaces, i, StackIndex: Integer;
  515. CurParent, PrevSibling, NewNode: TLinkNode;
  516. ParentStack, SiblingStack: array[0..7] of TLinkNode;
  517. begin
  518. PrevSpaces := 0;
  519. CurParent := RootLinkNode;
  520. PrevSibling := CurParent.FirstChild;
  521. if assigned(PrevSibling) then
  522. while assigned(PrevSibling.NextSibling) do
  523. PrevSibling := PrevSibling.NextSibling;
  524. StackIndex := 0;
  525. while True do
  526. begin
  527. ReadLn(f, s);
  528. if Length(s) = 0 then
  529. break;
  530. ThisSpaces := 0;
  531. while s[ThisSpaces + 1] = ' ' do
  532. Inc(ThisSpaces);
  533. if ThisSpaces <> PrevSpaces then
  534. begin
  535. if ThisSpaces > PrevSpaces then
  536. begin
  537. { Dive down one level }
  538. ParentStack[StackIndex] := CurParent;
  539. SiblingStack[StackIndex] := PrevSibling;
  540. Inc(StackIndex);
  541. CurParent := PrevSibling;
  542. PrevSibling := nil;
  543. end else
  544. while PrevSpaces > ThisSpaces do
  545. begin
  546. Dec(StackIndex);
  547. CurParent := ParentStack[StackIndex];
  548. PrevSibling := SiblingStack[StackIndex];
  549. Dec(PrevSpaces);
  550. end;
  551. PrevSpaces := ThisSpaces;
  552. end;
  553. i := ThisSpaces + 1;
  554. while s[i] <> ' ' do
  555. Inc(i);
  556. NewNode := TLinkNode.Create(Copy(s, ThisSpaces + 1, i - ThisSpaces - 1),
  557. ALinkPrefix + Copy(s, i + 1, Length(s)));
  558. if Assigned(PrevSibling) then
  559. PrevSibling.FNextSibling := NewNode
  560. else
  561. CurParent.FFirstChild := NewNode;
  562. PrevSibling := NewNode;
  563. end;
  564. end;
  565. procedure ReadClasses;
  566. function CreateClass(const AName: String): TPasClassType;
  567. var
  568. DotPos, DotPos2, i: Integer;
  569. s: String;
  570. HPackage: TPasPackage;
  571. Module: TPasModule;
  572. begin
  573. // Find or create package
  574. DotPos := Pos('.', AName);
  575. s := Copy(AName, 1, DotPos - 1);
  576. HPackage := nil;
  577. for i := 0 to FPackages.Count - 1 do
  578. if CompareText(TPasPackage(FPackages[i]).Name, s) = 0 then
  579. begin
  580. HPackage := TPasPackage(FPackages[i]);
  581. break;
  582. end;
  583. if not Assigned(HPackage) then
  584. begin
  585. HPackage := TPasPackage(inherited CreateElement(TPasPackage, s, nil,
  586. '', 0));
  587. FPackages.Add(HPackage);
  588. end;
  589. // Find or create module
  590. DotPos2 := DotPos;
  591. repeat
  592. Inc(DotPos2);
  593. until AName[DotPos2] = '.';
  594. s := Copy(AName, DotPos + 1, DotPos2 - DotPos - 1);
  595. Module := nil;
  596. for i := 0 to HPackage.Modules.Count - 1 do
  597. if CompareText(TPasModule(HPackage.Modules[i]).Name, s) = 0 then
  598. begin
  599. Module := TPasModule(HPackage.Modules[i]);
  600. break;
  601. end;
  602. if not Assigned(Module) then
  603. begin
  604. Module := TPasModule.Create(s, HPackage);
  605. Module.InterfaceSection := TInterfaceSection.Create('', Module);
  606. HPackage.Modules.Add(Module);
  607. end;
  608. // Create node for class
  609. Result := TPasClassType.Create(Copy(AName, DotPos2 + 1, Length(AName)),
  610. Module.InterfaceSection);
  611. Result.ObjKind := okClass;
  612. Module.InterfaceSection.Declarations.Add(Result);
  613. Module.InterfaceSection.Classes.Add(Result);
  614. end;
  615. var
  616. s, Name: String;
  617. CurClass: TPasClassType;
  618. i: Integer;
  619. Member: TPasElement;
  620. begin
  621. CurClass := nil;
  622. while True do
  623. begin
  624. ReadLn(f, s);
  625. if Length(s) = 0 then
  626. break;
  627. if s[1] = '#' then
  628. begin
  629. // New class
  630. i := Pos(' ', s);
  631. CurClass := CreateClass(Copy(s, 1, i - 1));
  632. end else
  633. begin
  634. i := Pos(' ', s);
  635. if i = 0 then
  636. Name := Copy(s, 3, Length(s))
  637. else
  638. Name := Copy(s, 3, i - 3);
  639. case s[2] of
  640. 'M':
  641. Member := TPasProcedure.Create(Name, CurClass);
  642. 'P':
  643. begin
  644. Member := TPasProperty.Create(Name, CurClass);
  645. if i > 0 then
  646. while i <= Length(s) do
  647. begin
  648. case s[i] of
  649. 'r':
  650. TPasProperty(Member).ReadAccessorName := '<dummy>';
  651. 'w':
  652. TPasProperty(Member).WriteAccessorName := '<dummy>';
  653. 's':
  654. TPasProperty(Member).StoredAccessorName := '<dummy>';
  655. end;
  656. Inc(i);
  657. end;
  658. end;
  659. 'V':
  660. Member := TPasVariable.Create(Name, CurClass);
  661. else
  662. raise Exception.Create('Invalid member type: ' + s[2]);
  663. end;
  664. CurClass.Members.Add(Member);
  665. end;
  666. end;
  667. end;
  668. var
  669. s: String;
  670. begin
  671. if not FileExists(AFileName) then
  672. raise EInOutError.Create('File not found: ' + AFileName);
  673. Assign(f, AFilename);
  674. Reset(f);
  675. while not EOF(f) do
  676. begin
  677. ReadLn(f, s);
  678. if (Length(s) = 0) or (s[1] = '#') then
  679. continue;
  680. if s = ':link tree' then
  681. ReadLinkTree
  682. else if s = ':classes' then
  683. ReadClasses
  684. else
  685. repeat
  686. ReadLn(f, s);
  687. until EOF(f) or (Length(s) = 0);
  688. end;
  689. Close(f);
  690. end;
  691. procedure TFPDocEngine.WriteContentFile(const AFilename: String);
  692. var
  693. ContentFile: Text;
  694. procedure ProcessLinkNode(ALinkNode: TLinkNode; const AIdent: String);
  695. var
  696. ChildNode: TLinkNode;
  697. begin
  698. WriteLn(ContentFile, AIdent, ALinkNode.Name, ' ', ALinkNode.Link);
  699. ChildNode := ALinkNode.FirstChild;
  700. while Assigned(ChildNode) do
  701. begin
  702. ProcessLinkNode(ChildNode, AIdent + ' ');
  703. ChildNode := ChildNode.NextSibling;
  704. end;
  705. end;
  706. var
  707. LinkNode: TLinkNode;
  708. i, j, k: Integer;
  709. Module: TPasModule;
  710. ClassDecl: TPasClassType;
  711. Member: TPasElement;
  712. s: String;
  713. begin
  714. Assign(ContentFile, AFilename);
  715. Rewrite(ContentFile);
  716. try
  717. WriteLn(ContentFile, '# FPDoc Content File');
  718. WriteLn(ContentFile, ':link tree');
  719. LinkNode := RootLinkNode.FirstChild;
  720. while Assigned(LinkNode) do
  721. begin
  722. if LinkNode.Name = Package.Name then
  723. begin
  724. ProcessLinkNode(LinkNode, '');
  725. end;
  726. LinkNode := LinkNode.NextSibling;
  727. end;
  728. if Assigned(Package) then
  729. begin
  730. WriteLn(ContentFile);
  731. WriteLn(ContentFile, ':classes');
  732. for i := 0 to Package.Modules.Count - 1 do
  733. begin
  734. Module := TPasModule(Package.Modules[i]);
  735. for j := 0 to Module.InterfaceSection.Classes.Count - 1 do
  736. begin
  737. ClassDecl := TPasClassType(Module.InterfaceSection.Classes[j]);
  738. Write(ContentFile, ClassDecl.PathName, ' ');
  739. if Assigned(ClassDecl.AncestorType) then
  740. WriteLn(ContentFile, ClassDecl.AncestorType.PathName)
  741. else if ClassDecl.ObjKind = okClass then
  742. WriteLn(ContentFile, '.TObject');
  743. for k := 0 to ClassDecl.Members.Count - 1 do
  744. begin
  745. Member := TPasElement(ClassDecl.Members[k]);
  746. Write(ContentFile, Chr(Ord(Member.Visibility) + Ord('0')));
  747. SetLength(s, 0);
  748. if Member.ClassType = TPasVariable then
  749. Write(ContentFile, 'V')
  750. else if Member.ClassType = TPasProperty then
  751. begin
  752. Write(ContentFile, 'P');
  753. if Length(TPasProperty(Member).ReadAccessorName) > 0 then
  754. s := s + 'r';
  755. if Length(TPasProperty(Member).WriteAccessorName) > 0 then
  756. s := s + 'w';
  757. if Length(TPasProperty(Member).StoredAccessorName) > 0 then
  758. s := s + 's';
  759. end else
  760. Write(ContentFile, 'M'); // Member must be a method
  761. Write(ContentFile, Member.Name);
  762. if Length(s) > 0 then
  763. WriteLn(ContentFile, ' ', s)
  764. else
  765. WriteLn(ContentFile);
  766. end;
  767. end;
  768. end;
  769. end;
  770. finally
  771. Close(ContentFile);
  772. end;
  773. end;
  774. function TFPDocEngine.CreateElement(AClass: TPTreeElement; const AName: String;
  775. AParent: TPasElement; AVisibility: TPasMemberVisibility;
  776. const ASourceFilename: String; ASourceLinenumber: Integer): TPasElement;
  777. begin
  778. Result := AClass.Create(AName, AParent);
  779. Result.Visibility := AVisibility;
  780. if AClass.InheritsFrom(TPasModule) then
  781. CurModule := TPasModule(Result);
  782. Result.SourceFilename := ASourceFilename;
  783. Result.SourceLinenumber := ASourceLinenumber;
  784. end;
  785. function TFPDocEngine.FindElement(const AName: String): TPasElement;
  786. function FindInModule(AModule: TPasModule; const LocalName: String): TPasElement;
  787. var
  788. l: TList;
  789. i: Integer;
  790. begin
  791. If assigned(AModule.InterfaceSection) and
  792. Assigned(AModule.InterfaceSection.Declarations) then
  793. begin
  794. l:=AModule.InterfaceSection.Declarations;
  795. for i := 0 to l.Count - 1 do
  796. begin
  797. Result := TPasElement(l[i]);
  798. if CompareText(Result.Name, LocalName) = 0 then
  799. exit;
  800. end;
  801. end;
  802. Result := nil;
  803. end;
  804. var
  805. i: Integer;
  806. //ModuleName, LocalName: String;
  807. Module: TPasElement;
  808. begin
  809. {!!!: Don't know if we ever will have to use the following:
  810. i := Pos('.', AName);
  811. if i <> 0 then
  812. begin
  813. WriteLn('Dot found in name: ', AName);
  814. Result := nil;
  815. end else
  816. begin}
  817. Result := FindInModule(CurModule, AName);
  818. if not Assigned(Result) then
  819. for i := CurModule.InterfaceSection.UsesList.Count - 1 downto 0 do
  820. begin
  821. Module := TPasElement(CurModule.InterfaceSection.UsesList[i]);
  822. if Module.ClassType = TPasModule then
  823. begin
  824. Result := FindInModule(TPasModule(Module), AName);
  825. if Assigned(Result) then
  826. exit;
  827. end;
  828. end;
  829. {end;}
  830. end;
  831. function TFPDocEngine.FindModule(const AName: String): TPasModule;
  832. function FindInPackage(APackage: TPasPackage): TPasModule;
  833. var
  834. i: Integer;
  835. begin
  836. for i := 0 to APackage.Modules.Count - 1 do
  837. begin
  838. Result := TPasModule(APackage.Modules[i]);
  839. if CompareText(Result.Name, AName) = 0 then
  840. exit;
  841. end;
  842. Result := nil;
  843. end;
  844. var
  845. i: Integer;
  846. begin
  847. Result := FindInPackage(Package);
  848. if not Assigned(Result) then
  849. for i := FPackages.Count - 1 downto 0 do
  850. begin
  851. if TPasPackage(FPackages[i]) = Package then
  852. continue;
  853. Result := FindInPackage(TPasPackage(FPackages[i]));
  854. if Assigned(Result) then
  855. exit;
  856. end;
  857. end;
  858. procedure TFPDocEngine.AddLink(const APathName, ALinkTo: String);
  859. begin
  860. RootLinkNode.CreateChildren(APathName, ALinkTo);
  861. end;
  862. function TFPDocEngine.FindAbsoluteLink(const AName: String): String;
  863. var
  864. LinkNode: TLinkNode;
  865. begin
  866. LinkNode := RootLinkNode.FindChild(AName);
  867. if Assigned(LinkNode) then
  868. Result := LinkNode.Link
  869. else
  870. SetLength(Result, 0);
  871. end;
  872. function TFPDocEngine.ResolveLink(AModule: TPasModule;
  873. const ALinkDest: String): String;
  874. var
  875. i: Integer;
  876. ThisPackage: TLinkNode;
  877. UnitList: TList;
  878. begin
  879. //WriteLn('ResolveLink(', ALinkDest, ')... ');
  880. if Length(ALinkDest) = 0 then
  881. begin
  882. SetLength(Result, 0);
  883. exit;
  884. end;
  885. if (ALinkDest[1] = '#') or (not assigned(AModule)) then
  886. Result := FindAbsoluteLink(ALinkDest)
  887. else
  888. begin
  889. Result := ResolveLink(AModule, amodule.packagename + '.' + ALinkDest);
  890. if Length(Result) > 0 then
  891. exit;
  892. Result := ResolveLink(AModule, AModule.PathName + '.' + ALinkDest);
  893. if Length(Result) > 0 then
  894. exit;
  895. { Try all packages }
  896. SetLength(Result, 0);
  897. ThisPackage := RootLinkNode.FirstChild;
  898. while Assigned(ThisPackage) do
  899. begin
  900. Result := ResolveLink(AModule, ThisPackage.Name + '.' + ALinkDest);
  901. if Length(Result) > 0 then
  902. exit;
  903. ThisPackage := ThisPackage.NextSibling;
  904. end;
  905. if Length(Result) = 0 then
  906. begin
  907. { Okay, then we have to try all imported units of the current module }
  908. UnitList := AModule.InterfaceSection.UsesList;
  909. for i := UnitList.Count - 1 downto 0 do
  910. begin
  911. { Try all packages }
  912. ThisPackage := RootLinkNode.FirstChild;
  913. while Assigned(ThisPackage) do
  914. begin
  915. Result := ResolveLink(AModule, ThisPackage.Name + '.' +
  916. TPasType(UnitList[i]).Name + '.' + ALinkDest);
  917. if Length(Result) > 0 then
  918. exit;
  919. ThisPackage := ThisPackage.NextSibling;
  920. end;
  921. end;
  922. end;
  923. end;
  924. if Length(Result) = 0 then
  925. for i := Length(ALinkDest) downto 1 do
  926. if ALinkDest[i] = '.' then
  927. begin
  928. Result := ResolveLink(AModule, Copy(ALinkDest, 1, i - 1));
  929. exit;
  930. end;
  931. end;
  932. procedure TFPDocEngine.AddDocFile(const AFilename: String);
  933. function ReadNode(OwnerDocNode: TDocNode; Element: TDOMElement): TDocNode;
  934. var
  935. Subnode: TDOMNode;
  936. begin
  937. if OwnerDocNode = RootDocNode then
  938. Result := OwnerDocNode.CreateChildren('#' + Element['name'])
  939. else
  940. Result := OwnerDocNode.CreateChildren(Element['name']);
  941. Result.FNode := Element;
  942. Result.FLink := Element['link'];
  943. Result.FIsSkipped := Element['skip'] = '1';
  944. Subnode := Element.FirstChild;
  945. while Assigned(Subnode) do
  946. begin
  947. if Subnode.NodeType = ELEMENT_NODE then
  948. begin
  949. if Subnode.NodeName = 'short' then
  950. Result.FShortDescr := TDOMElement(Subnode)
  951. else if Subnode.NodeName = 'descr' then
  952. Result.FDescr := TDOMElement(Subnode)
  953. else if Subnode.NodeName = 'version' then
  954. begin
  955. Result.FVersion := TDOMElement(Subnode)
  956. end
  957. else if Subnode.NodeName = 'errors' then
  958. Result.FErrorsDoc := TDOMElement(Subnode)
  959. else if Subnode.NodeName = 'seealso' then
  960. Result.FSeeAlso := TDOMElement(Subnode)
  961. else if (Subnode.NodeName = 'example') and
  962. not Assigned(Result.FirstExample) then
  963. Result.FFirstExample := TDOMElement(Subnode);
  964. end;
  965. Subnode := Subnode.NextSibling;
  966. end;
  967. end;
  968. Procedure ReadTopics(TopicNode : TDocNode);
  969. Var
  970. SubNode : TDOMNode;
  971. begin
  972. SubNode:=TopicNode.FNode.FirstChilD;
  973. While Assigned(SubNode) do
  974. begin
  975. If (SubNode.NodeType=ELEMENT_NODE) and (SubNode.NodeName='topic') then
  976. With ReadNode(TopicNode,TDomElement(SubNode)) do
  977. // We could allow recursion here, but we won't, because it doesn't work on paper.
  978. FTopicNode:=True;
  979. SubNode:=Subnode.NextSibling;
  980. end;
  981. end;
  982. var
  983. i: Integer;
  984. Node, Subnode, Subsubnode: TDOMNode;
  985. Element: TDOMElement;
  986. Doc: TXMLDocument;
  987. PackageDocNode, TopicNode,ModuleDocNode: TDocNode;
  988. begin
  989. ReadXMLFile(Doc, AFilename);
  990. DescrDocs.Add(Doc);
  991. DescrDocNames.Add(AFilename);
  992. Node := Doc.DocumentElement.FirstChild;
  993. while Assigned(Node) do
  994. begin
  995. if (Node.NodeType = ELEMENT_NODE) and (Node.NodeName = 'package') then
  996. begin
  997. PackageDocNode := ReadNode(RootDocNode, TDOMElement(Node));
  998. PackageDocNode.IncRefCount;
  999. // Scan all 'module' elements within this package element
  1000. Subnode := Node.FirstChild;
  1001. while Assigned(Subnode) do
  1002. begin
  1003. if (Subnode.NodeType = ELEMENT_NODE) then
  1004. begin
  1005. If (Subnode.NodeName = 'module') then
  1006. begin
  1007. ModuleDocNode := ReadNode(PackageDocNode, TDOMElement(Subnode));
  1008. // Scan all 'element' elements within this module element
  1009. Subsubnode := Subnode.FirstChild;
  1010. while Assigned(Subsubnode) do
  1011. begin
  1012. if (Subsubnode.NodeType = ELEMENT_NODE) then
  1013. begin
  1014. if (Subsubnode.NodeName = 'element') then
  1015. ReadNode(ModuleDocNode, TDOMElement(Subsubnode))
  1016. else if (SubSubNode.NodeName='topic') then
  1017. begin
  1018. TopicNode:=ReadNode(ModuleDocNode,TDomElement(SubSubNode));
  1019. TopicNode.FTopicNode:=True;
  1020. ReadTopics(TopicNode);
  1021. end;
  1022. end;
  1023. Subsubnode := Subsubnode.NextSibling;
  1024. end;
  1025. end
  1026. else if (SubNode.NodeName='topic') then
  1027. begin
  1028. TopicNode:=ReadNode(PackageDocNode,TDomElement(SubNode));
  1029. TopicNode.FTopicNode:=True;
  1030. ReadTopics(TopicNode);
  1031. end;
  1032. end;
  1033. Subnode := Subnode.NextSibling;
  1034. end;
  1035. end;
  1036. Node := Node.NextSibling;
  1037. end;
  1038. end;
  1039. function TFPDocEngine.FindDocNode(AElement: TPasElement): TDocNode;
  1040. begin
  1041. Result:=Nil;
  1042. If Assigned(AElement) then
  1043. begin
  1044. if AElement.InheritsFrom(TPasUnresolvedTypeRef) then
  1045. Result := FindDocNode(AElement.GetModule, AElement.Name)
  1046. else
  1047. Result := RootDocNode.FindChild(AElement.PathName);
  1048. if (Result=Nil) and
  1049. WarnNoNode and
  1050. (Length(AElement.PathName)>0) and
  1051. (AElement.PathName[1]='#') then
  1052. Writeln('No documentation node found for identifier : ',AElement.PathName);
  1053. end;
  1054. end;
  1055. function TFPDocEngine.FindDocNode(ARefModule: TPasModule;
  1056. const AName: String): TDocNode;
  1057. var
  1058. CurPackage: TDocNode;
  1059. UnitList: TList;
  1060. i: Integer;
  1061. begin
  1062. if Length(AName) = 0 then
  1063. Result := nil
  1064. else
  1065. begin
  1066. if AName[1] = '#' then
  1067. Result := RootDocNode.FindChild(AName)
  1068. else
  1069. Result := RootDocNode.FindChild(Package.Name + '.' + AName);
  1070. if (not Assigned(Result)) and Assigned(ARefModule) then
  1071. Result := RootDocNode.FindChild(ARefModule.PathName + '.' + AName);
  1072. if (not Assigned(Result)) and (AName[1] <> '#') then
  1073. begin
  1074. CurPackage := RootDocNode.FirstChild;
  1075. while Assigned(CurPackage) do
  1076. begin
  1077. Result := RootDocNode.FindChild(CurPackage.Name + '.' + AName);
  1078. if Assigned(Result) then
  1079. break;
  1080. CurPackage := CurPackage.NextSibling;
  1081. end;
  1082. if not Assigned(Result) then
  1083. begin
  1084. { Okay, then we have to try all imported units of the current module }
  1085. UnitList := CurModule.InterfaceSection.UsesList;
  1086. for i := UnitList.Count - 1 downto 0 do
  1087. begin
  1088. { Try all packages }
  1089. CurPackage := RootDocNode.FirstChild;
  1090. while Assigned(CurPackage) do
  1091. begin
  1092. Result := RootDocNode.FindChild(CurPackage.Name + '.' +
  1093. TPasType(UnitList[i]).Name + '.' + AName);
  1094. if Assigned(Result) then
  1095. break;
  1096. CurPackage := CurPackage.NextSibling;
  1097. end;
  1098. end;
  1099. end;
  1100. end;
  1101. end;
  1102. end;
  1103. function TFPDocEngine.FindShortDescr(AElement: TPasElement): TDOMElement;
  1104. var
  1105. DocNode,N: TDocNode;
  1106. begin
  1107. DocNode := FindDocNode(AElement);
  1108. if Assigned(DocNode) then
  1109. begin
  1110. N:=FindLinkedNode(DocNode);
  1111. If (N<>Nil) then
  1112. DocNode:=N;
  1113. Result := DocNode.ShortDescr;
  1114. end
  1115. else
  1116. Result := nil;
  1117. end;
  1118. function TFPDocEngine.FindLinkedNode(ANode : TDocNode) : TDocNode;
  1119. Var
  1120. S: String;
  1121. begin
  1122. If (ANode.Link='') then
  1123. Result:=Nil
  1124. else
  1125. Result:=FindDocNode(CurModule,ANode.Link);
  1126. end;
  1127. function TFPDocEngine.FindShortDescr(ARefModule: TPasModule;
  1128. const AName: String): TDOMElement;
  1129. var
  1130. N,DocNode: TDocNode;
  1131. begin
  1132. DocNode := FindDocNode(ARefModule, AName);
  1133. if Assigned(DocNode) then
  1134. begin
  1135. N:=FindLinkedNode(DocNode);
  1136. If (N<>Nil) then
  1137. DocNode:=N;
  1138. Result := DocNode.ShortDescr;
  1139. end
  1140. else
  1141. Result := nil;
  1142. end;
  1143. function TFPDocEngine.GetExampleFilename(const ExElement: TDOMElement): String;
  1144. var
  1145. i: Integer;
  1146. fn : String;
  1147. begin
  1148. Result:='';
  1149. for i := 0 to DescrDocs.Count - 1 do
  1150. begin
  1151. Fn:=ExElement['file'];
  1152. if (FN<>'') and (TDOMDocument(DescrDocs[i]) = ExElement.OwnerDocument) then
  1153. begin
  1154. Result := ExtractFilePath(DescrDocNames[i]) + FN;
  1155. if (ExtractFileExt(Result)='') then
  1156. Result:=Result+'.pp';
  1157. end;
  1158. end;
  1159. end;
  1160. { Global helpers }
  1161. procedure TranslateDocStrings(const Lang: String);
  1162. Const
  1163. {$ifdef unix}
  1164. DefDir = '/usr/local/share/locale';
  1165. {$else}
  1166. DefDir = 'intl';
  1167. {$endif}
  1168. var
  1169. mo: TMOFile;
  1170. dir : string;
  1171. begin
  1172. dir:=modir;
  1173. If Dir='' then
  1174. Dir:=DefDir;
  1175. Dir:=IncludeTrailingPathDelimiter(Dir);
  1176. {$IFDEF Unix}
  1177. mo := TMOFile.Create(Format(Dir+'%s/LC_MESSAGES/dglobals.mo', [Lang]));
  1178. {$ELSE}
  1179. mo := TMOFile.Create(Format(Dir+'dglobals.%s.mo', [Lang]));
  1180. {$ENDIF}
  1181. try
  1182. TranslateResourceStrings(mo);
  1183. finally
  1184. mo.Free;
  1185. end;
  1186. end;
  1187. Function IsLinkNode(Node : TDomNode) : Boolean;
  1188. begin
  1189. Result:=Assigned(Node) and (Node.NodeType = ELEMENT_NODE) and (Node.NodeName = 'link');
  1190. end;
  1191. Function IsExampleNode(Example : TDomNode) : Boolean;
  1192. begin
  1193. Result:=Assigned(Example) and (Example.NodeType = ELEMENT_NODE) and (Example.NodeName = 'example')
  1194. end;
  1195. function IsLinkAbsolute(ALink: String): boolean;
  1196. var
  1197. i: integer;
  1198. begin
  1199. Result := false;
  1200. for i := low(AbsoluteLinkPrefixes) to high(AbsoluteLinkPrefixes) do
  1201. if CompareText(AbsoluteLinkPrefixes[i], copy(ALink,1,length(AbsoluteLinkPrefixes[i])))=0 then begin
  1202. Result := true;
  1203. break;
  1204. end;
  1205. end;
  1206. initialization
  1207. LEOL:=Length(LineEnding);
  1208. end.