dglobals.pp 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297
  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 = class(TPasTreeContainer)
  220. protected
  221. DescrDocs: TObjectList; // List of XML documents
  222. DescrDocNames: TStringList; // Names of the XML documents
  223. FRootLinkNode: TLinkNode;
  224. FRootDocNode: TDocNode;
  225. FPackages: TList; // List of TFPPackage objects
  226. CurModule: TPasModule;
  227. CurPackageDocNode: TDocNode;
  228. public
  229. constructor Create;
  230. destructor Destroy; override;
  231. procedure SetPackageName(const APackageName: String);
  232. procedure ReadContentFile(const AFilename, ALinkPrefix: String);
  233. procedure WriteContentFile(const AFilename: String);
  234. function CreateElement(AClass: TPTreeElement; const AName: String;
  235. AParent: TPasElement; AVisibility: TPasMemberVisibility;
  236. const ASourceFilename: String; ASourceLinenumber: Integer): TPasElement;
  237. override;
  238. function FindElement(const AName: String): TPasElement; override;
  239. function FindModule(const AName: String): TPasModule; override;
  240. // Link tree support
  241. procedure AddLink(const APathName, ALinkTo: String);
  242. function FindAbsoluteLink(const AName: String): String;
  243. function ResolveLink(AModule: TPasModule; const ALinkDest: String): String;
  244. // Documentation file support
  245. procedure AddDocFile(const AFilename: String);
  246. // Documentation retrieval
  247. function FindDocNode(AElement: TPasElement): TDocNode;
  248. function FindDocNode(ARefModule: TPasModule; const AName: String): TDocNode;
  249. function FindShortDescr(AElement: TPasElement): TDOMElement;
  250. function FindShortDescr(ARefModule: TPasModule;
  251. const AName: String): TDOMElement;
  252. function GetExampleFilename(const ExElement: TDOMElement): String;
  253. property RootLinkNode: TLinkNode read FRootLinkNode;
  254. property RootDocNode: TDocNode read FRootDocNode;
  255. property Package: TPasPackage read FPackage;
  256. Output: String;
  257. HasContentFile: Boolean;
  258. HidePrivate: Boolean; // Hide private class members in output?
  259. HideProtected: Boolean; // Hide protected class members in output?
  260. WarnNoNode : Boolean; // Warn if no description node found for element.
  261. end;
  262. procedure TranslateDocStrings(const Lang: String);
  263. Function IsLinkNode(Node : TDomNode) : Boolean;
  264. Function IsExampleNode(Example : TDomNode) : Boolean;
  265. // returns true is link is an absolute URI
  266. Function IsLinkAbsolute(ALink: String): boolean;
  267. implementation
  268. uses SysUtils, Gettext, XMLRead;
  269. const
  270. AbsoluteLinkPrefixes : array[0..2] of string = ('/', 'http://', 'ms-its:');
  271. { TObjectList }
  272. destructor TObjectList.Destroy;
  273. var
  274. i: Integer;
  275. begin
  276. for i := 0 to Count - 1 do
  277. TObject(Items[i]).Free;
  278. inherited Destroy;
  279. end;
  280. { TLinkNode }
  281. constructor TLinkNode.Create(const AName, ALink: String);
  282. begin
  283. inherited Create;
  284. FName := AName;
  285. FLink := ALink;
  286. end;
  287. destructor TLinkNode.Destroy;
  288. begin
  289. if Assigned(FirstChild) then
  290. FirstChild.Free;
  291. if Assigned(NextSibling) then
  292. NextSibling.Free;
  293. inherited Destroy;
  294. end;
  295. function TLinkNode.FindChild(const APathName: String): TLinkNode;
  296. var
  297. DotPos: Integer;
  298. ChildName: String;
  299. Child: TLinkNode;
  300. begin
  301. if Length(APathName) = 0 then
  302. Result := Self
  303. else
  304. begin
  305. DotPos := Pos('.', APathName);
  306. if DotPos = 0 then
  307. ChildName := APathName
  308. else
  309. ChildName := Copy(APathName, 1, DotPos - 1);
  310. Child := FirstChild;
  311. while Assigned(Child) do
  312. begin
  313. if CompareText(Child.Name, ChildName) = 0 then
  314. begin
  315. if DotPos = 0 then
  316. Result := Child
  317. else
  318. Result := Child.FindChild(
  319. Copy(APathName, DotPos + 1, Length(APathName)));
  320. exit;
  321. end;
  322. Child := Child.NextSibling;
  323. end;
  324. Result := nil;
  325. end;
  326. end;
  327. function TLinkNode.CreateChildren(const APathName, ALinkTo: String): TLinkNode;
  328. var
  329. DotPos: Integer;
  330. ChildName: String;
  331. Child, LastChild: TLinkNode;
  332. begin
  333. if Length(APathName) = 0 then
  334. Result := Self
  335. else
  336. begin
  337. DotPos := Pos('.', APathName);
  338. if DotPos = 0 then
  339. ChildName := APathName
  340. else
  341. ChildName := Copy(APathName, 1, DotPos - 1);
  342. Child := FirstChild;
  343. LastChild := nil;
  344. while Assigned(Child) do
  345. begin
  346. if CompareText(Child.Name, ChildName) = 0 then
  347. begin
  348. if DotPos = 0 then
  349. Result := Child
  350. else
  351. Result := Child.CreateChildren(
  352. Copy(APathName, DotPos + 1, Length(APathName)), ALinkTo);
  353. exit;
  354. end;
  355. LastChild := Child;
  356. Child := Child.NextSibling;
  357. end;
  358. { No child found, let's create one if we are at the end of the path }
  359. if DotPos > 0 then
  360. // !!!: better throw an exception
  361. WriteLn('Link path does not exist: ', APathName);
  362. Result := TLinkNode.Create(ChildName, ALinkTo);
  363. if Assigned(LastChild) then
  364. LastChild.FNextSibling := Result
  365. else
  366. FFirstChild := Result;
  367. end;
  368. end;
  369. { TDocNode }
  370. constructor TDocNode.Create(const AName: String; ANode: TDOMElement);
  371. begin
  372. inherited Create;
  373. FName := AName;
  374. FNode := ANode;
  375. end;
  376. destructor TDocNode.Destroy;
  377. begin
  378. if Assigned(FirstChild) then
  379. FirstChild.Free;
  380. if Assigned(NextSibling) then
  381. NextSibling.Free;
  382. inherited Destroy;
  383. end;
  384. Function TDocNode.IncRefcount : Integer;
  385. begin
  386. Inc(FRefCount);
  387. Result:=FRefCount;
  388. end;
  389. function TDocNode.FindChild(const APathName: String): TDocNode;
  390. var
  391. DotPos: Integer;
  392. ChildName: String;
  393. Child: TDocNode;
  394. begin
  395. if Length(APathName) = 0 then
  396. Result := Self
  397. else
  398. begin
  399. DotPos := Pos('.', APathName);
  400. if DotPos = 0 then
  401. ChildName := APathName
  402. else
  403. ChildName := Copy(APathName, 1, DotPos - 1);
  404. Child := FirstChild;
  405. while Assigned(Child) do
  406. begin
  407. if CompareText(Child.Name, ChildName) = 0 then
  408. begin
  409. if DotPos = 0 then
  410. Result := Child
  411. else
  412. Result := Child.FindChild(
  413. Copy(APathName, DotPos + 1, Length(APathName)));
  414. exit;
  415. end;
  416. Child := Child.NextSibling;
  417. end;
  418. Result := nil;
  419. end;
  420. end;
  421. function TDocNode.CreateChildren(const APathName: String): TDocNode;
  422. var
  423. DotPos: Integer;
  424. ChildName: String;
  425. Child: TDocNode;
  426. begin
  427. if Length(APathName) = 0 then
  428. Result := Self
  429. else
  430. begin
  431. DotPos := Pos('.', APathName);
  432. if DotPos = 0 then
  433. ChildName := APathName
  434. else
  435. ChildName := Copy(APathName, 1, DotPos - 1);
  436. Child := FirstChild;
  437. while Assigned(Child) do
  438. begin
  439. if CompareText(Child.Name, ChildName) = 0 then
  440. begin
  441. if DotPos = 0 then
  442. Result := Child
  443. else
  444. Result := Child.CreateChildren(
  445. Copy(APathName, DotPos + 1, Length(APathName)));
  446. exit;
  447. end;
  448. Child := Child.NextSibling;
  449. end;
  450. // No child found, let's create one
  451. Result := TDocNode.Create(ChildName, nil);
  452. if Assigned(FirstChild) then
  453. begin
  454. Result.FNextSibling := FirstChild;
  455. FFirstChild := Result;
  456. end else
  457. FFirstChild := Result;
  458. if DotPos > 0 then
  459. Result := Result.CreateChildren(
  460. Copy(APathName, DotPos + 1, Length(APathName)));
  461. end;
  462. end;
  463. { TFPDocEngine }
  464. constructor TFPDocEngine.Create;
  465. begin
  466. inherited Create;
  467. DescrDocs := TObjectList.Create;
  468. DescrDocNames := TStringList.Create;
  469. FRootLinkNode := TLinkNode.Create('', '');
  470. FRootDocNode := TDocNode.Create('', nil);
  471. HidePrivate := True;
  472. FPackages := TList.Create;
  473. end;
  474. destructor TFPDocEngine.Destroy;
  475. var
  476. i: Integer;
  477. begin
  478. for i := 0 to FPackages.Count - 1 do
  479. TPasPackage(FPackages[i]).Release;
  480. FPackages.Free;
  481. FRootDocNode.Free;
  482. FRootLinkNode.Free;
  483. DescrDocNames.Free;
  484. DescrDocs.Free;
  485. inherited Destroy;
  486. end;
  487. procedure TFPDocEngine.SetPackageName(const APackageName: String);
  488. begin
  489. ASSERT(not Assigned(Package));
  490. FPackage := TPasPackage(inherited CreateElement(TPasPackage,
  491. '#' + APackageName, nil, '', 0));
  492. FPackages.Add(FPackage);
  493. CurPackageDocNode := RootDocNode.FindChild('#' + APackageName);
  494. If Assigned(CurPackageDocNode) then
  495. CurPackageDocNode.IncRefCount;
  496. end;
  497. procedure TFPDocEngine.ReadContentFile(const AFilename, ALinkPrefix: String);
  498. var
  499. f: Text;
  500. procedure ReadLinkTree;
  501. var
  502. s: String;
  503. PrevSpaces, ThisSpaces, i, StackIndex: Integer;
  504. CurParent, PrevSibling, NewNode: TLinkNode;
  505. ParentStack, SiblingStack: array[0..7] of TLinkNode;
  506. begin
  507. PrevSpaces := 0;
  508. CurParent := RootLinkNode;
  509. PrevSibling := CurParent.FirstChild;
  510. if assigned(PrevSibling) then
  511. while assigned(PrevSibling.NextSibling) do
  512. PrevSibling := PrevSibling.NextSibling;
  513. StackIndex := 0;
  514. while True do
  515. begin
  516. ReadLn(f, s);
  517. if Length(s) = 0 then
  518. break;
  519. ThisSpaces := 0;
  520. while s[ThisSpaces + 1] = ' ' do
  521. Inc(ThisSpaces);
  522. if ThisSpaces <> PrevSpaces then
  523. begin
  524. if ThisSpaces > PrevSpaces then
  525. begin
  526. { Dive down one level }
  527. ParentStack[StackIndex] := CurParent;
  528. SiblingStack[StackIndex] := PrevSibling;
  529. Inc(StackIndex);
  530. CurParent := PrevSibling;
  531. PrevSibling := nil;
  532. end else
  533. while PrevSpaces > ThisSpaces do
  534. begin
  535. Dec(StackIndex);
  536. CurParent := ParentStack[StackIndex];
  537. PrevSibling := SiblingStack[StackIndex];
  538. Dec(PrevSpaces);
  539. end;
  540. PrevSpaces := ThisSpaces;
  541. end;
  542. i := ThisSpaces + 1;
  543. while s[i] <> ' ' do
  544. Inc(i);
  545. NewNode := TLinkNode.Create(Copy(s, ThisSpaces + 1, i - ThisSpaces - 1),
  546. ALinkPrefix + Copy(s, i + 1, Length(s)));
  547. if Assigned(PrevSibling) then
  548. PrevSibling.FNextSibling := NewNode
  549. else
  550. CurParent.FFirstChild := NewNode;
  551. PrevSibling := NewNode;
  552. end;
  553. end;
  554. procedure ReadClasses;
  555. function CreateClass(const AName: String): TPasClassType;
  556. var
  557. DotPos, DotPos2, i: Integer;
  558. s: String;
  559. HPackage: TPasPackage;
  560. Module: TPasModule;
  561. begin
  562. // Find or create package
  563. DotPos := Pos('.', AName);
  564. s := Copy(AName, 1, DotPos - 1);
  565. HPackage := nil;
  566. for i := 0 to FPackages.Count - 1 do
  567. if CompareText(TPasPackage(FPackages[i]).Name, s) = 0 then
  568. begin
  569. HPackage := TPasPackage(FPackages[i]);
  570. break;
  571. end;
  572. if not Assigned(HPackage) then
  573. begin
  574. HPackage := TPasPackage(inherited CreateElement(TPasPackage, s, nil,
  575. '', 0));
  576. FPackages.Add(HPackage);
  577. end;
  578. // Find or create module
  579. DotPos2 := DotPos;
  580. repeat
  581. Inc(DotPos2);
  582. until AName[DotPos2] = '.';
  583. s := Copy(AName, DotPos + 1, DotPos2 - DotPos - 1);
  584. Module := nil;
  585. for i := 0 to HPackage.Modules.Count - 1 do
  586. if CompareText(TPasModule(HPackage.Modules[i]).Name, s) = 0 then
  587. begin
  588. Module := TPasModule(HPackage.Modules[i]);
  589. break;
  590. end;
  591. if not Assigned(Module) then
  592. begin
  593. Module := TPasModule.Create(s, HPackage);
  594. Module.InterfaceSection := TPasSection.Create('', Module);
  595. HPackage.Modules.Add(Module);
  596. end;
  597. // Create node for class
  598. Result := TPasClassType.Create(Copy(AName, DotPos2 + 1, Length(AName)),
  599. Module.InterfaceSection);
  600. Result.ObjKind := okClass;
  601. Module.InterfaceSection.Declarations.Add(Result);
  602. Module.InterfaceSection.Classes.Add(Result);
  603. end;
  604. var
  605. s, Name: String;
  606. CurClass: TPasClassType;
  607. i: Integer;
  608. Member: TPasElement;
  609. begin
  610. CurClass := nil;
  611. while True do
  612. begin
  613. ReadLn(f, s);
  614. if Length(s) = 0 then
  615. break;
  616. if s[1] = '#' then
  617. begin
  618. // New class
  619. i := Pos(' ', s);
  620. CurClass := CreateClass(Copy(s, 1, i - 1));
  621. end else
  622. begin
  623. i := Pos(' ', s);
  624. if i = 0 then
  625. Name := Copy(s, 3, Length(s))
  626. else
  627. Name := Copy(s, 3, i - 3);
  628. case s[2] of
  629. 'M':
  630. Member := TPasProcedure.Create(Name, CurClass);
  631. 'P':
  632. begin
  633. Member := TPasProperty.Create(Name, CurClass);
  634. if i > 0 then
  635. while i <= Length(s) do
  636. begin
  637. case s[i] of
  638. 'r':
  639. TPasProperty(Member).ReadAccessorName := '<dummy>';
  640. 'w':
  641. TPasProperty(Member).WriteAccessorName := '<dummy>';
  642. 's':
  643. TPasProperty(Member).StoredAccessorName := '<dummy>';
  644. end;
  645. Inc(i);
  646. end;
  647. end;
  648. 'V':
  649. Member := TPasVariable.Create(Name, CurClass);
  650. else
  651. raise Exception.Create('Invalid member type: ' + s[2]);
  652. end;
  653. CurClass.Members.Add(Member);
  654. end;
  655. end;
  656. end;
  657. var
  658. s: String;
  659. begin
  660. if not FileExists(AFileName) then
  661. raise EInOutError.Create('File not found: ' + AFileName);
  662. Assign(f, AFilename);
  663. Reset(f);
  664. while not EOF(f) do
  665. begin
  666. ReadLn(f, s);
  667. if (Length(s) = 0) or (s[1] = '#') then
  668. continue;
  669. if s = ':link tree' then
  670. ReadLinkTree
  671. else if s = ':classes' then
  672. ReadClasses
  673. else
  674. repeat
  675. ReadLn(f, s);
  676. until EOF(f) or (Length(s) = 0);
  677. end;
  678. Close(f);
  679. end;
  680. procedure TFPDocEngine.WriteContentFile(const AFilename: String);
  681. var
  682. ContentFile: Text;
  683. procedure ProcessLinkNode(ALinkNode: TLinkNode; const AIdent: String);
  684. var
  685. ChildNode: TLinkNode;
  686. begin
  687. WriteLn(ContentFile, AIdent, ALinkNode.Name, ' ', ALinkNode.Link);
  688. ChildNode := ALinkNode.FirstChild;
  689. while Assigned(ChildNode) do
  690. begin
  691. ProcessLinkNode(ChildNode, AIdent + ' ');
  692. ChildNode := ChildNode.NextSibling;
  693. end;
  694. end;
  695. var
  696. LinkNode: TLinkNode;
  697. i, j, k: Integer;
  698. Module: TPasModule;
  699. ClassDecl: TPasClassType;
  700. Member: TPasElement;
  701. s: String;
  702. begin
  703. Assign(ContentFile, AFilename);
  704. Rewrite(ContentFile);
  705. try
  706. WriteLn(ContentFile, '# FPDoc Content File');
  707. WriteLn(ContentFile, ':link tree');
  708. LinkNode := RootLinkNode.FirstChild;
  709. while Assigned(LinkNode) do
  710. begin
  711. if LinkNode.Name = Package.Name then
  712. begin
  713. ProcessLinkNode(LinkNode, '');
  714. end;
  715. LinkNode := LinkNode.NextSibling;
  716. end;
  717. if Assigned(Package) then
  718. begin
  719. WriteLn(ContentFile);
  720. WriteLn(ContentFile, ':classes');
  721. for i := 0 to Package.Modules.Count - 1 do
  722. begin
  723. Module := TPasModule(Package.Modules[i]);
  724. for j := 0 to Module.InterfaceSection.Classes.Count - 1 do
  725. begin
  726. ClassDecl := TPasClassType(Module.InterfaceSection.Classes[j]);
  727. Write(ContentFile, ClassDecl.PathName, ' ');
  728. if Assigned(ClassDecl.AncestorType) then
  729. WriteLn(ContentFile, ClassDecl.AncestorType.PathName)
  730. else if ClassDecl.ObjKind = okClass then
  731. WriteLn(ContentFile, '.TObject');
  732. for k := 0 to ClassDecl.Members.Count - 1 do
  733. begin
  734. Member := TPasElement(ClassDecl.Members[k]);
  735. Write(ContentFile, Chr(Ord(Member.Visibility) + Ord('0')));
  736. SetLength(s, 0);
  737. if Member.ClassType = TPasVariable then
  738. Write(ContentFile, 'V')
  739. else if Member.ClassType = TPasProperty then
  740. begin
  741. Write(ContentFile, 'P');
  742. if Length(TPasProperty(Member).ReadAccessorName) > 0 then
  743. s := s + 'r';
  744. if Length(TPasProperty(Member).WriteAccessorName) > 0 then
  745. s := s + 'w';
  746. if Length(TPasProperty(Member).StoredAccessorName) > 0 then
  747. s := s + 's';
  748. end else
  749. Write(ContentFile, 'M'); // Member must be a method
  750. Write(ContentFile, Member.Name);
  751. if Length(s) > 0 then
  752. WriteLn(ContentFile, ' ', s)
  753. else
  754. WriteLn(ContentFile);
  755. end;
  756. end;
  757. end;
  758. end;
  759. finally
  760. Close(ContentFile);
  761. end;
  762. end;
  763. function TFPDocEngine.CreateElement(AClass: TPTreeElement; const AName: String;
  764. AParent: TPasElement; AVisibility: TPasMemberVisibility;
  765. const ASourceFilename: String; ASourceLinenumber: Integer): TPasElement;
  766. begin
  767. Result := AClass.Create(AName, AParent);
  768. Result.Visibility := AVisibility;
  769. if AClass.InheritsFrom(TPasModule) then
  770. CurModule := TPasModule(Result);
  771. Result.SourceFilename := ASourceFilename;
  772. Result.SourceLinenumber := ASourceLinenumber;
  773. end;
  774. function TFPDocEngine.FindElement(const AName: String): TPasElement;
  775. function FindInModule(AModule: TPasModule; const LocalName: String): TPasElement;
  776. var
  777. l: TList;
  778. i: Integer;
  779. begin
  780. If assigned(AModule.InterfaceSection) and
  781. Assigned(AModule.InterfaceSection.Declarations) then
  782. begin
  783. l:=AModule.InterfaceSection.Declarations;
  784. for i := 0 to l.Count - 1 do
  785. begin
  786. Result := TPasElement(l[i]);
  787. if CompareText(Result.Name, LocalName) = 0 then
  788. exit;
  789. end;
  790. end;
  791. Result := nil;
  792. end;
  793. var
  794. i: Integer;
  795. //ModuleName, LocalName: String;
  796. Module: TPasElement;
  797. begin
  798. {!!!: Don't know if we ever will have to use the following:
  799. i := Pos('.', AName);
  800. if i <> 0 then
  801. begin
  802. WriteLn('Dot found in name: ', AName);
  803. Result := nil;
  804. end else
  805. begin}
  806. Result := FindInModule(CurModule, AName);
  807. if not Assigned(Result) then
  808. for i := CurModule.InterfaceSection.UsesList.Count - 1 downto 0 do
  809. begin
  810. Module := TPasElement(CurModule.InterfaceSection.UsesList[i]);
  811. if Module.ClassType = TPasModule then
  812. begin
  813. Result := FindInModule(TPasModule(Module), AName);
  814. if Assigned(Result) then
  815. exit;
  816. end;
  817. end;
  818. {end;}
  819. end;
  820. function TFPDocEngine.FindModule(const AName: String): TPasModule;
  821. function FindInPackage(APackage: TPasPackage): TPasModule;
  822. var
  823. i: Integer;
  824. begin
  825. for i := 0 to APackage.Modules.Count - 1 do
  826. begin
  827. Result := TPasModule(APackage.Modules[i]);
  828. if CompareText(Result.Name, AName) = 0 then
  829. exit;
  830. end;
  831. Result := nil;
  832. end;
  833. var
  834. i: Integer;
  835. begin
  836. Result := FindInPackage(Package);
  837. if not Assigned(Result) then
  838. for i := FPackages.Count - 1 downto 0 do
  839. begin
  840. if TPasPackage(FPackages[i]) = Package then
  841. continue;
  842. Result := FindInPackage(TPasPackage(FPackages[i]));
  843. if Assigned(Result) then
  844. exit;
  845. end;
  846. end;
  847. procedure TFPDocEngine.AddLink(const APathName, ALinkTo: String);
  848. begin
  849. RootLinkNode.CreateChildren(APathName, ALinkTo);
  850. end;
  851. function TFPDocEngine.FindAbsoluteLink(const AName: String): String;
  852. var
  853. LinkNode: TLinkNode;
  854. begin
  855. LinkNode := RootLinkNode.FindChild(AName);
  856. if Assigned(LinkNode) then
  857. Result := LinkNode.Link
  858. else
  859. SetLength(Result, 0);
  860. end;
  861. function TFPDocEngine.ResolveLink(AModule: TPasModule;
  862. const ALinkDest: String): String;
  863. var
  864. i: Integer;
  865. ThisPackage: TLinkNode;
  866. UnitList: TList;
  867. begin
  868. //WriteLn('ResolveLink(', ALinkDest, ')... ');
  869. if Length(ALinkDest) = 0 then
  870. begin
  871. SetLength(Result, 0);
  872. exit;
  873. end;
  874. if (ALinkDest[1] = '#') or (not assigned(AModule)) then
  875. Result := FindAbsoluteLink(ALinkDest)
  876. else
  877. begin
  878. Result := ResolveLink(AModule, AModule.PathName + '.' + ALinkDest);
  879. if Length(Result) > 0 then
  880. exit;
  881. { Try all packages }
  882. SetLength(Result, 0);
  883. ThisPackage := RootLinkNode.FirstChild;
  884. while Assigned(ThisPackage) do
  885. begin
  886. Result := ResolveLink(AModule, ThisPackage.Name + '.' + ALinkDest);
  887. if Length(Result) > 0 then
  888. exit;
  889. ThisPackage := ThisPackage.NextSibling;
  890. end;
  891. if Length(Result) = 0 then
  892. begin
  893. { Okay, then we have to try all imported units of the current module }
  894. UnitList := AModule.InterfaceSection.UsesList;
  895. for i := UnitList.Count - 1 downto 0 do
  896. begin
  897. { Try all packages }
  898. ThisPackage := RootLinkNode.FirstChild;
  899. while Assigned(ThisPackage) do
  900. begin
  901. Result := ResolveLink(AModule, ThisPackage.Name + '.' +
  902. TPasType(UnitList[i]).Name + '.' + ALinkDest);
  903. if Length(Result) > 0 then
  904. exit;
  905. ThisPackage := ThisPackage.NextSibling;
  906. end;
  907. end;
  908. end;
  909. end;
  910. if Length(Result) = 0 then
  911. for i := Length(ALinkDest) downto 1 do
  912. if ALinkDest[i] = '.' then
  913. begin
  914. Result := ResolveLink(AModule, Copy(ALinkDest, 1, i - 1));
  915. exit;
  916. end;
  917. end;
  918. procedure TFPDocEngine.AddDocFile(const AFilename: String);
  919. function ReadNode(OwnerDocNode: TDocNode; Element: TDOMElement): TDocNode;
  920. var
  921. Subnode: TDOMNode;
  922. begin
  923. if OwnerDocNode = RootDocNode then
  924. Result := OwnerDocNode.CreateChildren('#' + Element['name'])
  925. else
  926. Result := OwnerDocNode.CreateChildren(Element['name']);
  927. Result.FNode := Element;
  928. Result.FLink := Element['link'];
  929. Result.FIsSkipped := Element['skip'] = '1';
  930. Subnode := Element.FirstChild;
  931. while Assigned(Subnode) do
  932. begin
  933. if Subnode.NodeType = ELEMENT_NODE then
  934. begin
  935. if Subnode.NodeName = 'short' then
  936. Result.FShortDescr := TDOMElement(Subnode)
  937. else if Subnode.NodeName = 'descr' then
  938. Result.FDescr := TDOMElement(Subnode)
  939. else if Subnode.NodeName = 'errors' then
  940. Result.FErrorsDoc := TDOMElement(Subnode)
  941. else if Subnode.NodeName = 'seealso' then
  942. Result.FSeeAlso := TDOMElement(Subnode)
  943. else if (Subnode.NodeName = 'example') and
  944. not Assigned(Result.FirstExample) then
  945. Result.FFirstExample := TDOMElement(Subnode);
  946. end;
  947. Subnode := Subnode.NextSibling;
  948. end;
  949. end;
  950. Procedure ReadTopics(TopicNode : TDocNode);
  951. Var
  952. SubNode : TDOMNode;
  953. begin
  954. SubNode:=TopicNode.FNode.FirstChilD;
  955. While Assigned(SubNode) do
  956. begin
  957. If (SubNode.NodeType=ELEMENT_NODE) and (SubNode.NodeName='topic') then
  958. With ReadNode(TopicNode,TDomElement(SubNode)) do
  959. // We could allow recursion here, but we won't, because it doesn't work on paper.
  960. FTopicNode:=True;
  961. SubNode:=Subnode.NextSibling;
  962. end;
  963. end;
  964. var
  965. i: Integer;
  966. Node, Subnode, Subsubnode: TDOMNode;
  967. Element: TDOMElement;
  968. Doc: TXMLDocument;
  969. PackageDocNode, TopicNode,ModuleDocNode: TDocNode;
  970. begin
  971. ReadXMLFile(Doc, AFilename);
  972. DescrDocs.Add(Doc);
  973. DescrDocNames.Add(AFilename);
  974. Node := Doc.DocumentElement.FirstChild;
  975. while Assigned(Node) do
  976. begin
  977. if (Node.NodeType = ELEMENT_NODE) and (Node.NodeName = 'package') then
  978. begin
  979. PackageDocNode := ReadNode(RootDocNode, TDOMElement(Node));
  980. PackageDocNode.IncRefCount;
  981. // Scan all 'module' elements within this package element
  982. Subnode := Node.FirstChild;
  983. while Assigned(Subnode) do
  984. begin
  985. if (Subnode.NodeType = ELEMENT_NODE) then
  986. begin
  987. If (Subnode.NodeName = 'module') then
  988. begin
  989. ModuleDocNode := ReadNode(PackageDocNode, TDOMElement(Subnode));
  990. // Scan all 'element' elements within this module element
  991. Subsubnode := Subnode.FirstChild;
  992. while Assigned(Subsubnode) do
  993. begin
  994. if (Subsubnode.NodeType = ELEMENT_NODE) then
  995. begin
  996. if (Subsubnode.NodeName = 'element') then
  997. ReadNode(ModuleDocNode, TDOMElement(Subsubnode))
  998. else if (SubSubNode.NodeName='topic') then
  999. begin
  1000. TopicNode:=ReadNode(ModuleDocNode,TDomElement(SubSubNode));
  1001. TopicNode.FTopicNode:=True;
  1002. ReadTopics(TopicNode);
  1003. end;
  1004. end;
  1005. Subsubnode := Subsubnode.NextSibling;
  1006. end;
  1007. end
  1008. else if (SubNode.NodeName='topic') then
  1009. begin
  1010. TopicNode:=ReadNode(PackageDocNode,TDomElement(SubNode));
  1011. TopicNode.FTopicNode:=True;
  1012. ReadTopics(TopicNode);
  1013. end;
  1014. end;
  1015. Subnode := Subnode.NextSibling;
  1016. end;
  1017. end;
  1018. Node := Node.NextSibling;
  1019. end;
  1020. end;
  1021. function TFPDocEngine.FindDocNode(AElement: TPasElement): TDocNode;
  1022. begin
  1023. Result:=Nil;
  1024. If Assigned(AElement) then
  1025. begin
  1026. if AElement.InheritsFrom(TPasUnresolvedTypeRef) then
  1027. Result := FindDocNode(AElement.GetModule, AElement.Name)
  1028. else
  1029. Result := RootDocNode.FindChild(AElement.PathName);
  1030. if (Result=Nil) and
  1031. WarnNoNode and
  1032. (Length(AElement.PathName)>0) and
  1033. (AElement.PathName[1]='#') then
  1034. Writeln('No documentation node found for identifier : ',AElement.PathName);
  1035. end;
  1036. end;
  1037. function TFPDocEngine.FindDocNode(ARefModule: TPasModule;
  1038. const AName: String): TDocNode;
  1039. var
  1040. CurPackage: TDocNode;
  1041. UnitList: TList;
  1042. i: Integer;
  1043. begin
  1044. if Length(AName) = 0 then
  1045. Result := nil
  1046. else
  1047. begin
  1048. if AName[1] = '#' then
  1049. Result := RootDocNode.FindChild(AName)
  1050. else
  1051. Result := RootDocNode.FindChild(Package.Name + '.' + AName);
  1052. if (not Assigned(Result)) and Assigned(ARefModule) then
  1053. Result := RootDocNode.FindChild(ARefModule.PathName + '.' + AName);
  1054. if (not Assigned(Result)) and (AName[1] <> '#') then
  1055. begin
  1056. CurPackage := RootDocNode.FirstChild;
  1057. while Assigned(CurPackage) do
  1058. begin
  1059. Result := RootDocNode.FindChild(CurPackage.Name + '.' + AName);
  1060. if Assigned(Result) then
  1061. break;
  1062. CurPackage := CurPackage.NextSibling;
  1063. end;
  1064. if not Assigned(Result) then
  1065. begin
  1066. { Okay, then we have to try all imported units of the current module }
  1067. UnitList := CurModule.InterfaceSection.UsesList;
  1068. for i := UnitList.Count - 1 downto 0 do
  1069. begin
  1070. { Try all packages }
  1071. CurPackage := RootDocNode.FirstChild;
  1072. while Assigned(CurPackage) do
  1073. begin
  1074. Result := RootDocNode.FindChild(CurPackage.Name + '.' +
  1075. TPasType(UnitList[i]).Name + '.' + AName);
  1076. if Assigned(Result) then
  1077. break;
  1078. CurPackage := CurPackage.NextSibling;
  1079. end;
  1080. end;
  1081. end;
  1082. end;
  1083. end;
  1084. end;
  1085. function TFPDocEngine.FindShortDescr(AElement: TPasElement): TDOMElement;
  1086. var
  1087. DocNode: TDocNode;
  1088. begin
  1089. DocNode := FindDocNode(AElement);
  1090. if Assigned(DocNode) then
  1091. Result := DocNode.ShortDescr
  1092. else
  1093. Result := nil;
  1094. end;
  1095. function TFPDocEngine.FindShortDescr(ARefModule: TPasModule;
  1096. const AName: String): TDOMElement;
  1097. var
  1098. DocNode: TDocNode;
  1099. begin
  1100. DocNode := FindDocNode(ARefModule, AName);
  1101. if Assigned(DocNode) then
  1102. Result := DocNode.ShortDescr
  1103. else
  1104. Result := nil;
  1105. end;
  1106. function TFPDocEngine.GetExampleFilename(const ExElement: TDOMElement): String;
  1107. var
  1108. i: Integer;
  1109. fn : String;
  1110. begin
  1111. Result:='';
  1112. for i := 0 to DescrDocs.Count - 1 do
  1113. begin
  1114. Fn:=ExElement['file'];
  1115. if (FN<>'') and (TDOMDocument(DescrDocs[i]) = ExElement.OwnerDocument) then
  1116. begin
  1117. Result := ExtractFilePath(DescrDocNames[i]) + FN;
  1118. if (ExtractFileExt(Result)='') then
  1119. Result:=Result+'.pp';
  1120. end;
  1121. end;
  1122. end;
  1123. { Global helpers }
  1124. procedure TranslateDocStrings(const Lang: String);
  1125. Const
  1126. {$ifdef unix}
  1127. DefDir = '/usr/local/share/locale';
  1128. {$else}
  1129. DefDir = 'intl';
  1130. {$endif}
  1131. var
  1132. mo: TMOFile;
  1133. dir : string;
  1134. begin
  1135. dir:=modir;
  1136. If Dir='' then
  1137. Dir:=DefDir;
  1138. Dir:=IncludeTrailingPathDelimiter(Dir);
  1139. {$IFDEF Unix}
  1140. mo := TMOFile.Create(Format(Dir+'%s/LC_MESSAGES/dglobals.mo', [Lang]));
  1141. {$ELSE}
  1142. mo := TMOFile.Create(Format(Dir+'dglobals.%s.mo', [Lang]));
  1143. {$ENDIF}
  1144. try
  1145. TranslateResourceStrings(mo);
  1146. finally
  1147. mo.Free;
  1148. end;
  1149. end;
  1150. Function IsLinkNode(Node : TDomNode) : Boolean;
  1151. begin
  1152. Result:=Assigned(Node) and (Node.NodeType = ELEMENT_NODE) and (Node.NodeName = 'link');
  1153. end;
  1154. Function IsExampleNode(Example : TDomNode) : Boolean;
  1155. begin
  1156. Result:=Assigned(Example) and (Example.NodeType = ELEMENT_NODE) and (Example.NodeName = 'example')
  1157. end;
  1158. function IsLinkAbsolute(ALink: String): boolean;
  1159. var
  1160. i: integer;
  1161. begin
  1162. Result := false;
  1163. for i := low(AbsoluteLinkPrefixes) to high(AbsoluteLinkPrefixes) do
  1164. if CompareText(AbsoluteLinkPrefixes[i], copy(ALink,1,length(AbsoluteLinkPrefixes[i])))=0 then begin
  1165. Result := true;
  1166. break;
  1167. end;
  1168. end;
  1169. initialization
  1170. LEOL:=Length(LineEnding);
  1171. end.