dglobals.pp 39 KB

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