dglobals.pp 39 KB

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