dglobals.pp 40 KB

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