dglobals.pp 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352
  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. 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;InheritanceStr:String): TPasClassType;
  567. var
  568. DotPos, DotPos2, i,j: 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. s:=Copy(AName, DotPos2 + 1, length(AName)-dotpos2);
  609. // Create node for class
  610. Result := TPasClassType.Create(s, Module.InterfaceSection);
  611. Result.ObjKind := okClass;
  612. Module.InterfaceSection.Declarations.Add(Result);
  613. Module.InterfaceSection.Classes.Add(Result);
  614. // process inheritancestr here.
  615. end;
  616. var
  617. s, Name: String;
  618. CurClass: TPasClassType;
  619. i: Integer;
  620. Member: TPasElement;
  621. begin
  622. CurClass := nil;
  623. while True do
  624. begin
  625. ReadLn(f, s);
  626. if Length(s) = 0 then
  627. break;
  628. if s[1] = '#' then
  629. begin
  630. // New class
  631. i := Pos(' ', s);
  632. CurClass := CreateClass(Copy(s, 1, i - 1), copy(s,i+1,length(s)));
  633. end else
  634. begin
  635. i := Pos(' ', s);
  636. if i = 0 then
  637. Name := Copy(s, 3, Length(s))
  638. else
  639. Name := Copy(s, 3, i - 3);
  640. case s[2] of
  641. 'M':
  642. Member := TPasProcedure.Create(Name, CurClass);
  643. 'P':
  644. begin
  645. Member := TPasProperty.Create(Name, CurClass);
  646. if i > 0 then
  647. while i <= Length(s) do
  648. begin
  649. case s[i] of
  650. 'r':
  651. TPasProperty(Member).ReadAccessorName := '<dummy>';
  652. 'w':
  653. TPasProperty(Member).WriteAccessorName := '<dummy>';
  654. 's':
  655. TPasProperty(Member).StoredAccessorName := '<dummy>';
  656. end;
  657. Inc(i);
  658. end;
  659. end;
  660. 'V':
  661. Member := TPasVariable.Create(Name, CurClass);
  662. else
  663. raise Exception.Create('Invalid member type: ' + s[2]);
  664. end;
  665. CurClass.Members.Add(Member);
  666. end;
  667. end;
  668. end;
  669. var
  670. s: String;
  671. begin
  672. if not FileExists(AFileName) then
  673. raise EInOutError.Create('File not found: ' + AFileName);
  674. Assign(f, AFilename);
  675. Reset(f);
  676. while not EOF(f) do
  677. begin
  678. ReadLn(f, s);
  679. if (Length(s) = 0) or (s[1] = '#') then
  680. continue;
  681. if s = ':link tree' then
  682. ReadLinkTree
  683. else if s = ':classes' then
  684. ReadClasses
  685. else
  686. repeat
  687. ReadLn(f, s);
  688. until EOF(f) or (Length(s) = 0);
  689. end;
  690. Close(f);
  691. end;
  692. procedure TFPDocEngine.WriteContentFile(const AFilename: String);
  693. var
  694. ContentFile: Text;
  695. procedure ProcessLinkNode(ALinkNode: TLinkNode; const AIdent: String);
  696. var
  697. ChildNode: TLinkNode;
  698. begin
  699. WriteLn(ContentFile, AIdent, ALinkNode.Name, ' ', ALinkNode.Link);
  700. ChildNode := ALinkNode.FirstChild;
  701. while Assigned(ChildNode) do
  702. begin
  703. ProcessLinkNode(ChildNode, AIdent + ' ');
  704. ChildNode := ChildNode.NextSibling;
  705. end;
  706. end;
  707. var
  708. LinkNode: TLinkNode;
  709. i, j, k: Integer;
  710. Module: TPasModule;
  711. ClassDecl: TPasClassType;
  712. Member: TPasElement;
  713. s: String;
  714. begin
  715. Assign(ContentFile, AFilename);
  716. Rewrite(ContentFile);
  717. try
  718. WriteLn(ContentFile, '# FPDoc Content File');
  719. WriteLn(ContentFile, ':link tree');
  720. LinkNode := RootLinkNode.FirstChild;
  721. while Assigned(LinkNode) do
  722. begin
  723. if LinkNode.Name = Package.Name then
  724. begin
  725. ProcessLinkNode(LinkNode, '');
  726. end;
  727. LinkNode := LinkNode.NextSibling;
  728. end;
  729. if Assigned(Package) then
  730. begin
  731. WriteLn(ContentFile);
  732. WriteLn(ContentFile, ':classes');
  733. for i := 0 to Package.Modules.Count - 1 do
  734. begin
  735. Module := TPasModule(Package.Modules[i]);
  736. for j := 0 to Module.InterfaceSection.Classes.Count - 1 do
  737. begin
  738. ClassDecl := TPasClassType(Module.InterfaceSection.Classes[j]);
  739. Write(ContentFile, ClassDecl.PathName, ' ');
  740. if Assigned(ClassDecl.AncestorType) then
  741. Write(ContentFile, ClassDecl.AncestorType.PathName)
  742. else if ClassDecl.ObjKind = okClass then
  743. Write(ContentFile, '.TObject');
  744. if ClassDecl.Interfaces.Count>0 then
  745. begin
  746. for k:=0 to ClassDecl.Interfaces.count-1 do
  747. write(contentfile,',',TPasClassType(ClassDecl.Interfaces[k]).PathName);
  748. end;
  749. writeln(contentfile);
  750. for k := 0 to ClassDecl.Members.Count - 1 do
  751. begin
  752. Member := TPasElement(ClassDecl.Members[k]);
  753. Write(ContentFile, Chr(Ord(Member.Visibility) + Ord('0')));
  754. SetLength(s, 0);
  755. if Member.ClassType = TPasVariable then
  756. Write(ContentFile, 'V')
  757. else if Member.ClassType = TPasProperty then
  758. begin
  759. Write(ContentFile, 'P');
  760. if Length(TPasProperty(Member).ReadAccessorName) > 0 then
  761. s := s + 'r';
  762. if Length(TPasProperty(Member).WriteAccessorName) > 0 then
  763. s := s + 'w';
  764. if Length(TPasProperty(Member).StoredAccessorName) > 0 then
  765. s := s + 's';
  766. end else
  767. Write(ContentFile, 'M'); // Member must be a method
  768. Write(ContentFile, Member.Name);
  769. if Length(s) > 0 then
  770. WriteLn(ContentFile, ' ', s)
  771. else
  772. WriteLn(ContentFile);
  773. end;
  774. end;
  775. end;
  776. end;
  777. finally
  778. Close(ContentFile);
  779. end;
  780. end;
  781. function TFPDocEngine.CreateElement(AClass: TPTreeElement; const AName: String;
  782. AParent: TPasElement; AVisibility: TPasMemberVisibility;
  783. const ASourceFilename: String; ASourceLinenumber: Integer): TPasElement;
  784. begin
  785. Result := AClass.Create(AName, AParent);
  786. Result.Visibility := AVisibility;
  787. if AClass.InheritsFrom(TPasModule) then
  788. CurModule := TPasModule(Result);
  789. Result.SourceFilename := ASourceFilename;
  790. Result.SourceLinenumber := ASourceLinenumber;
  791. end;
  792. function TFPDocEngine.FindElement(const AName: String): TPasElement;
  793. function FindInModule(AModule: TPasModule; const LocalName: String): TPasElement;
  794. var
  795. l: TList;
  796. i: Integer;
  797. begin
  798. If assigned(AModule.InterfaceSection) and
  799. Assigned(AModule.InterfaceSection.Declarations) then
  800. begin
  801. l:=AModule.InterfaceSection.Declarations;
  802. for i := 0 to l.Count - 1 do
  803. begin
  804. Result := TPasElement(l[i]);
  805. if CompareText(Result.Name, LocalName) = 0 then
  806. exit;
  807. end;
  808. end;
  809. Result := nil;
  810. end;
  811. var
  812. i: Integer;
  813. //ModuleName, LocalName: String;
  814. Module: TPasElement;
  815. begin
  816. {!!!: Don't know if we ever will have to use the following:
  817. i := Pos('.', AName);
  818. if i <> 0 then
  819. begin
  820. WriteLn('Dot found in name: ', AName);
  821. Result := nil;
  822. end else
  823. begin}
  824. Result := FindInModule(CurModule, AName);
  825. if not Assigned(Result) then
  826. for i := CurModule.InterfaceSection.UsesList.Count - 1 downto 0 do
  827. begin
  828. Module := TPasElement(CurModule.InterfaceSection.UsesList[i]);
  829. if Module.ClassType = TPasModule then
  830. begin
  831. Result := FindInModule(TPasModule(Module), AName);
  832. if Assigned(Result) then
  833. exit;
  834. end;
  835. end;
  836. {end;}
  837. end;
  838. function TFPDocEngine.FindModule(const AName: String): TPasModule;
  839. function FindInPackage(APackage: TPasPackage): TPasModule;
  840. var
  841. i: Integer;
  842. begin
  843. for i := 0 to APackage.Modules.Count - 1 do
  844. begin
  845. Result := TPasModule(APackage.Modules[i]);
  846. if CompareText(Result.Name, AName) = 0 then
  847. exit;
  848. end;
  849. Result := nil;
  850. end;
  851. var
  852. i: Integer;
  853. begin
  854. Result := FindInPackage(Package);
  855. if not Assigned(Result) then
  856. for i := FPackages.Count - 1 downto 0 do
  857. begin
  858. if TPasPackage(FPackages[i]) = Package then
  859. continue;
  860. Result := FindInPackage(TPasPackage(FPackages[i]));
  861. if Assigned(Result) then
  862. exit;
  863. end;
  864. end;
  865. procedure TFPDocEngine.AddLink(const APathName, ALinkTo: String);
  866. begin
  867. RootLinkNode.CreateChildren(APathName, ALinkTo);
  868. end;
  869. function TFPDocEngine.FindAbsoluteLink(const AName: String): String;
  870. var
  871. LinkNode: TLinkNode;
  872. begin
  873. LinkNode := RootLinkNode.FindChild(AName);
  874. if Assigned(LinkNode) then
  875. Result := LinkNode.Link
  876. else
  877. SetLength(Result, 0);
  878. end;
  879. function TFPDocEngine.ResolveLink(AModule: TPasModule;
  880. const ALinkDest: String): String;
  881. var
  882. i: Integer;
  883. ThisPackage: TLinkNode;
  884. UnitList: TList;
  885. begin
  886. //WriteLn('ResolveLink(', ALinkDest, ')... ');
  887. if Length(ALinkDest) = 0 then
  888. begin
  889. SetLength(Result, 0);
  890. exit;
  891. end;
  892. if (ALinkDest[1] = '#') or (not assigned(AModule)) then
  893. Result := FindAbsoluteLink(ALinkDest)
  894. else
  895. begin
  896. Result := ResolveLink(AModule, amodule.packagename + '.' + ALinkDest);
  897. if Length(Result) > 0 then
  898. exit;
  899. Result := ResolveLink(AModule, AModule.PathName + '.' + ALinkDest);
  900. if Length(Result) > 0 then
  901. exit;
  902. { Try all packages }
  903. SetLength(Result, 0);
  904. ThisPackage := RootLinkNode.FirstChild;
  905. while Assigned(ThisPackage) do
  906. begin
  907. Result := ResolveLink(AModule, ThisPackage.Name + '.' + ALinkDest);
  908. if Length(Result) > 0 then
  909. exit;
  910. ThisPackage := ThisPackage.NextSibling;
  911. end;
  912. if Length(Result) = 0 then
  913. begin
  914. { Okay, then we have to try all imported units of the current module }
  915. UnitList := AModule.InterfaceSection.UsesList;
  916. for i := UnitList.Count - 1 downto 0 do
  917. begin
  918. { Try all packages }
  919. ThisPackage := RootLinkNode.FirstChild;
  920. while Assigned(ThisPackage) do
  921. begin
  922. Result := ResolveLink(AModule, ThisPackage.Name + '.' +
  923. TPasType(UnitList[i]).Name + '.' + ALinkDest);
  924. if Length(Result) > 0 then
  925. exit;
  926. ThisPackage := ThisPackage.NextSibling;
  927. end;
  928. end;
  929. end;
  930. end;
  931. if Length(Result) = 0 then
  932. for i := Length(ALinkDest) downto 1 do
  933. if ALinkDest[i] = '.' then
  934. begin
  935. Result := ResolveLink(AModule, Copy(ALinkDest, 1, i - 1));
  936. exit;
  937. end;
  938. end;
  939. procedure TFPDocEngine.AddDocFile(const AFilename: String);
  940. function ReadNode(OwnerDocNode: TDocNode; Element: TDOMElement): TDocNode;
  941. var
  942. Subnode: TDOMNode;
  943. begin
  944. if OwnerDocNode = RootDocNode then
  945. Result := OwnerDocNode.CreateChildren('#' + Element['name'])
  946. else
  947. Result := OwnerDocNode.CreateChildren(Element['name']);
  948. Result.FNode := Element;
  949. Result.FLink := Element['link'];
  950. Result.FIsSkipped := Element['skip'] = '1';
  951. Subnode := Element.FirstChild;
  952. while Assigned(Subnode) do
  953. begin
  954. if Subnode.NodeType = ELEMENT_NODE then
  955. begin
  956. if Subnode.NodeName = 'short' then
  957. Result.FShortDescr := TDOMElement(Subnode)
  958. else if Subnode.NodeName = 'descr' then
  959. Result.FDescr := TDOMElement(Subnode)
  960. else if Subnode.NodeName = 'version' then
  961. begin
  962. Result.FVersion := TDOMElement(Subnode)
  963. end
  964. else if Subnode.NodeName = 'errors' then
  965. Result.FErrorsDoc := TDOMElement(Subnode)
  966. else if Subnode.NodeName = 'seealso' then
  967. Result.FSeeAlso := TDOMElement(Subnode)
  968. else if (Subnode.NodeName = 'example') and
  969. not Assigned(Result.FirstExample) then
  970. Result.FFirstExample := TDOMElement(Subnode);
  971. end;
  972. Subnode := Subnode.NextSibling;
  973. end;
  974. end;
  975. Procedure ReadTopics(TopicNode : TDocNode);
  976. Var
  977. SubNode : TDOMNode;
  978. begin
  979. SubNode:=TopicNode.FNode.FirstChilD;
  980. While Assigned(SubNode) do
  981. begin
  982. If (SubNode.NodeType=ELEMENT_NODE) and (SubNode.NodeName='topic') then
  983. With ReadNode(TopicNode,TDomElement(SubNode)) do
  984. // We could allow recursion here, but we won't, because it doesn't work on paper.
  985. FTopicNode:=True;
  986. SubNode:=Subnode.NextSibling;
  987. end;
  988. end;
  989. var
  990. i: Integer;
  991. Node, Subnode, Subsubnode: TDOMNode;
  992. Element: TDOMElement;
  993. Doc: TXMLDocument;
  994. PackageDocNode, TopicNode,ModuleDocNode: TDocNode;
  995. begin
  996. ReadXMLFile(Doc, AFilename);
  997. DescrDocs.Add(Doc);
  998. DescrDocNames.Add(AFilename);
  999. Node := Doc.DocumentElement.FirstChild;
  1000. while Assigned(Node) do
  1001. begin
  1002. if (Node.NodeType = ELEMENT_NODE) and (Node.NodeName = 'package') then
  1003. begin
  1004. PackageDocNode := ReadNode(RootDocNode, TDOMElement(Node));
  1005. PackageDocNode.IncRefCount;
  1006. // Scan all 'module' elements within this package element
  1007. Subnode := Node.FirstChild;
  1008. while Assigned(Subnode) do
  1009. begin
  1010. if (Subnode.NodeType = ELEMENT_NODE) then
  1011. begin
  1012. If (Subnode.NodeName = 'module') then
  1013. begin
  1014. ModuleDocNode := ReadNode(PackageDocNode, TDOMElement(Subnode));
  1015. // Scan all 'element' elements within this module element
  1016. Subsubnode := Subnode.FirstChild;
  1017. while Assigned(Subsubnode) do
  1018. begin
  1019. if (Subsubnode.NodeType = ELEMENT_NODE) then
  1020. begin
  1021. if (Subsubnode.NodeName = 'element') then
  1022. ReadNode(ModuleDocNode, TDOMElement(Subsubnode))
  1023. else if (SubSubNode.NodeName='topic') then
  1024. begin
  1025. TopicNode:=ReadNode(ModuleDocNode,TDomElement(SubSubNode));
  1026. TopicNode.FTopicNode:=True;
  1027. ReadTopics(TopicNode);
  1028. end;
  1029. end;
  1030. Subsubnode := Subsubnode.NextSibling;
  1031. end;
  1032. end
  1033. else if (SubNode.NodeName='topic') then
  1034. begin
  1035. TopicNode:=ReadNode(PackageDocNode,TDomElement(SubNode));
  1036. TopicNode.FTopicNode:=True;
  1037. ReadTopics(TopicNode);
  1038. end;
  1039. end;
  1040. Subnode := Subnode.NextSibling;
  1041. end;
  1042. end;
  1043. Node := Node.NextSibling;
  1044. end;
  1045. end;
  1046. function TFPDocEngine.FindDocNode(AElement: TPasElement): TDocNode;
  1047. begin
  1048. Result:=Nil;
  1049. If Assigned(AElement) then
  1050. begin
  1051. if AElement.InheritsFrom(TPasUnresolvedTypeRef) then
  1052. Result := FindDocNode(AElement.GetModule, AElement.Name)
  1053. else
  1054. Result := RootDocNode.FindChild(AElement.PathName);
  1055. if (Result=Nil) and
  1056. WarnNoNode and
  1057. (Length(AElement.PathName)>0) and
  1058. (AElement.PathName[1]='#') then
  1059. Writeln('No documentation node found for identifier : ',AElement.PathName);
  1060. end;
  1061. end;
  1062. function TFPDocEngine.FindDocNode(ARefModule: TPasModule;
  1063. const AName: String): TDocNode;
  1064. var
  1065. CurPackage: TDocNode;
  1066. UnitList: TList;
  1067. i: Integer;
  1068. begin
  1069. if Length(AName) = 0 then
  1070. Result := nil
  1071. else
  1072. begin
  1073. if AName[1] = '#' then
  1074. Result := RootDocNode.FindChild(AName)
  1075. else
  1076. Result := RootDocNode.FindChild(Package.Name + '.' + AName);
  1077. if (not Assigned(Result)) and Assigned(ARefModule) then
  1078. Result := RootDocNode.FindChild(ARefModule.PathName + '.' + AName);
  1079. if (not Assigned(Result)) and (AName[1] <> '#') then
  1080. begin
  1081. CurPackage := RootDocNode.FirstChild;
  1082. while Assigned(CurPackage) do
  1083. begin
  1084. Result := RootDocNode.FindChild(CurPackage.Name + '.' + AName);
  1085. if Assigned(Result) then
  1086. break;
  1087. CurPackage := CurPackage.NextSibling;
  1088. end;
  1089. if not Assigned(Result) then
  1090. begin
  1091. { Okay, then we have to try all imported units of the current module }
  1092. UnitList := CurModule.InterfaceSection.UsesList;
  1093. for i := UnitList.Count - 1 downto 0 do
  1094. begin
  1095. { Try all packages }
  1096. CurPackage := RootDocNode.FirstChild;
  1097. while Assigned(CurPackage) do
  1098. begin
  1099. Result := RootDocNode.FindChild(CurPackage.Name + '.' +
  1100. TPasType(UnitList[i]).Name + '.' + AName);
  1101. if Assigned(Result) then
  1102. break;
  1103. CurPackage := CurPackage.NextSibling;
  1104. end;
  1105. end;
  1106. end;
  1107. end;
  1108. end;
  1109. end;
  1110. function TFPDocEngine.FindShortDescr(AElement: TPasElement): TDOMElement;
  1111. var
  1112. DocNode,N: TDocNode;
  1113. begin
  1114. DocNode := FindDocNode(AElement);
  1115. if Assigned(DocNode) then
  1116. begin
  1117. N:=FindLinkedNode(DocNode);
  1118. If (N<>Nil) then
  1119. DocNode:=N;
  1120. Result := DocNode.ShortDescr;
  1121. end
  1122. else
  1123. Result := nil;
  1124. end;
  1125. function TFPDocEngine.FindLinkedNode(ANode : TDocNode) : TDocNode;
  1126. Var
  1127. S: String;
  1128. begin
  1129. If (ANode.Link='') then
  1130. Result:=Nil
  1131. else
  1132. Result:=FindDocNode(CurModule,ANode.Link);
  1133. end;
  1134. function TFPDocEngine.FindShortDescr(ARefModule: TPasModule;
  1135. const AName: String): TDOMElement;
  1136. var
  1137. N,DocNode: TDocNode;
  1138. begin
  1139. DocNode := FindDocNode(ARefModule, AName);
  1140. if Assigned(DocNode) then
  1141. begin
  1142. N:=FindLinkedNode(DocNode);
  1143. If (N<>Nil) then
  1144. DocNode:=N;
  1145. Result := DocNode.ShortDescr;
  1146. end
  1147. else
  1148. Result := nil;
  1149. end;
  1150. function TFPDocEngine.GetExampleFilename(const ExElement: TDOMElement): String;
  1151. var
  1152. i: Integer;
  1153. fn : String;
  1154. begin
  1155. Result:='';
  1156. for i := 0 to DescrDocs.Count - 1 do
  1157. begin
  1158. Fn:=ExElement['file'];
  1159. if (FN<>'') and (TDOMDocument(DescrDocs[i]) = ExElement.OwnerDocument) then
  1160. begin
  1161. Result := ExtractFilePath(DescrDocNames[i]) + FN;
  1162. if (ExtractFileExt(Result)='') then
  1163. Result:=Result+'.pp';
  1164. end;
  1165. end;
  1166. end;
  1167. { Global helpers }
  1168. procedure TranslateDocStrings(const Lang: String);
  1169. Const
  1170. {$ifdef unix}
  1171. DefDir = '/usr/local/share/locale';
  1172. {$else}
  1173. DefDir = 'intl';
  1174. {$endif}
  1175. var
  1176. mo: TMOFile;
  1177. dir : string;
  1178. begin
  1179. dir:=modir;
  1180. If Dir='' then
  1181. Dir:=DefDir;
  1182. Dir:=IncludeTrailingPathDelimiter(Dir);
  1183. {$IFDEF Unix}
  1184. mo := TMOFile.Create(Format(Dir+'%s/LC_MESSAGES/dglobals.mo', [Lang]));
  1185. {$ELSE}
  1186. mo := TMOFile.Create(Format(Dir+'dglobals.%s.mo', [Lang]));
  1187. {$ENDIF}
  1188. try
  1189. TranslateResourceStrings(mo);
  1190. finally
  1191. mo.Free;
  1192. end;
  1193. end;
  1194. Function IsLinkNode(Node : TDomNode) : Boolean;
  1195. begin
  1196. Result:=Assigned(Node) and (Node.NodeType = ELEMENT_NODE) and (Node.NodeName = 'link');
  1197. end;
  1198. Function IsExampleNode(Example : TDomNode) : Boolean;
  1199. begin
  1200. Result:=Assigned(Example) and (Example.NodeType = ELEMENT_NODE) and (Example.NodeName = 'example')
  1201. end;
  1202. function IsLinkAbsolute(ALink: String): boolean;
  1203. var
  1204. i: integer;
  1205. begin
  1206. Result := false;
  1207. for i := low(AbsoluteLinkPrefixes) to high(AbsoluteLinkPrefixes) do
  1208. if CompareText(AbsoluteLinkPrefixes[i], copy(ALink,1,length(AbsoluteLinkPrefixes[i])))=0 then begin
  1209. Result := true;
  1210. break;
  1211. end;
  1212. end;
  1213. initialization
  1214. LEOL:=Length(LineEnding);
  1215. end.