dglobals.pp 38 KB

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