dglobals.pp 40 KB

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