dglobals.pp 38 KB

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