dw_ipf.pp 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424
  1. {
  2. $Id$
  3. FPDoc - Free Pascal Documentation Tool
  4. Copyright (C) 2000 - 2003 by
  5. Areca Systems GmbH / Sebastian Guenther, [email protected]
  6. * IPF output generator
  7. See the file COPYING, included in this distribution,
  8. for details about the copyright.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  12. }
  13. unit dw_IPF;
  14. {$MODE objfpc}
  15. {$H+}
  16. interface
  17. uses SysUtils, Classes, dWriter, DOM, dGlobals, PasTree;
  18. const
  19. IPFHighLight : Boolean = False;
  20. IPFExtension : String = '.ipf';
  21. type
  22. TLabelType = (ltConst,ltVar,ltType,ltFunction,ltProcedure,ltClass,
  23. ltChapter,ltSection,ltSubsection,
  24. ltTable,ltFigure);
  25. { TIPFWriter }
  26. TIPFWriter = class(TFPDocWriter)
  27. protected
  28. f: Text;
  29. FLink: String;
  30. PackageName: String;
  31. Module: TPasModule;
  32. ModuleName: String;
  33. FTableCount : Integer;
  34. TableRowStartFlag, TableCaptionWritten: Boolean;
  35. function GetLabel(AElement: TPasElement): String;
  36. procedure Write(const s: String);
  37. procedure WriteF(const s: String; const Args: array of const);
  38. procedure WriteLn(const s: String);
  39. procedure WriteLnF(const s: String; const Args: array of const);
  40. // Tex functions
  41. procedure WriteLabel(El: TPasElement);
  42. procedure WriteLabel(const s: String);
  43. procedure WriteIndex(El: TPasElement);
  44. procedure WriteIndex(const s: String);
  45. procedure StartListing(Frames: Boolean; const name: String);
  46. procedure StartListing(Frames: Boolean);
  47. procedure EndListing;
  48. Function EscapeTex(S : String) : String;
  49. Function StripTex(S : String) : String;
  50. procedure WriteCommentLine;
  51. procedure WriteComment(Comment : String);
  52. procedure StartSection(SectionName : String; SectionLabel : String);
  53. // procedure StartSection(SectionName : String);
  54. procedure StartSubSection(SubSectionName : String; SubSectionLabel : String);
  55. // procedure StartSubSection(SubSectionName : String);
  56. procedure StartChapter(ChapterName : String; ChapterLabel : String);
  57. procedure StartChapter(ChapterName : String);
  58. // Description node conversion
  59. procedure DescrWriteText(const AText: DOMString); override;
  60. procedure DescrBeginBold; override;
  61. procedure DescrEndBold; override;
  62. procedure DescrBeginItalic; override;
  63. procedure DescrEndItalic; override;
  64. procedure DescrBeginEmph; override;
  65. procedure DescrEndEmph; override;
  66. procedure DescrWriteFileEl(const AText: DOMString); override;
  67. procedure DescrWriteKeywordEl(const AText: DOMString); override;
  68. procedure DescrWriteVarEl(const AText: DOMString); override;
  69. procedure DescrBeginLink(const AId: DOMString); override;
  70. procedure DescrEndLink; override;
  71. procedure DescrWriteLinebreak; override;
  72. procedure DescrBeginParagraph; override;
  73. procedure DescrBeginCode(HasBorder: Boolean; const AHighlighterName: String); override;
  74. procedure DescrWriteCodeLine(const ALine: String); override;
  75. procedure DescrEndCode; override;
  76. procedure DescrEndParagraph; override;
  77. procedure DescrBeginOrderedList; override;
  78. procedure DescrEndOrderedList; override;
  79. procedure DescrBeginUnorderedList; override;
  80. procedure DescrEndUnorderedList; override;
  81. procedure DescrBeginDefinitionList; override;
  82. procedure DescrEndDefinitionList; override;
  83. procedure DescrBeginListItem; override;
  84. procedure DescrEndListItem; override;
  85. procedure DescrBeginDefinitionTerm; override;
  86. procedure DescrEndDefinitionTerm; override;
  87. procedure DescrBeginDefinitionEntry; override;
  88. procedure DescrEndDefinitionEntry; override;
  89. procedure DescrBeginSectionTitle; override;
  90. procedure DescrBeginSectionBody; override;
  91. procedure DescrEndSection; override;
  92. procedure DescrBeginRemark; override;
  93. procedure DescrEndRemark; override;
  94. procedure DescrBeginTable(ColCount: Integer; HasBorder: Boolean); override;
  95. procedure DescrEndTable; override;
  96. procedure DescrBeginTableCaption; override;
  97. procedure DescrEndTableCaption; override;
  98. procedure DescrBeginTableHeadRow; override;
  99. procedure DescrEndTableHeadRow; override;
  100. procedure DescrBeginTableRow; override;
  101. procedure DescrEndTableRow; override;
  102. procedure DescrBeginTableCell; override;
  103. procedure DescrEndTableCell; override;
  104. procedure WriteDescr(Element: TPasElement);
  105. procedure WriteDescr(AContext: TPasElement; DescrNode: TDOMElement);
  106. function ConstValue(ConstDecl: TPasConst): String;
  107. procedure ProcessSection(ASection: TPasSection);
  108. // Documentation writing methods.
  109. procedure WriteResourceStrings(ASection: TPasSection);
  110. procedure WriteUnitOverview(ASection: TPasSection);
  111. procedure WriteVarsConstsTypes(ASection: TPasSection);
  112. procedure WriteConsts(ASection: TPasSection);
  113. procedure WriteTypes(ASection: TPasSection);
  114. procedure WriteEnumElements(TypeDecl : TPasEnumType);
  115. procedure WriteVars(ASection: TPasSection);
  116. procedure WriteFunctionsAndProcedures(ASection: TPasSection);
  117. procedure WriteProcedure(ProcDecl: TPasProcedureBase);
  118. procedure WriteClasses(ASection: TPasSection);
  119. procedure WriteClassDecl(ClassDecl: TPasClassType);
  120. procedure WriteClassMethodOverview(ClassDecl: TPasClassType);
  121. procedure WriteClassPropertyOverview(ClassDecl: TPasClassType);
  122. procedure WriteProperty(PropDecl: TPasProperty);
  123. procedure WriteExample(ADocNode: TDocNode);
  124. procedure WriteSeeAlso(ADocNode: TDocNode);
  125. procedure SortElementList(List : TList);
  126. Function ShowMember(M : TPasElement) : boolean;
  127. public
  128. constructor Create(APackage: TPasPackage; AEngine: TFPDocEngine); override;
  129. procedure WriteDoc; override;
  130. end;
  131. implementation
  132. constructor TIPFWriter.Create(APackage: TPasPackage; AEngine: TFPDocEngine);
  133. procedure AddLabel(AElement: TPasElement);
  134. begin
  135. Engine.AddLink(AElement.PathName, GetLabel(AElement));
  136. end;
  137. procedure AddList(AElement: TPasElement; AList: TList);
  138. var
  139. i: Integer;
  140. begin
  141. for i := 0 to AList.Count - 1 do
  142. AddLabel(TPasElement(AList[i]));
  143. end;
  144. procedure ScanModule(AModule: TPasModule);
  145. var
  146. i, j, k: Integer;
  147. s: String;
  148. ClassEl: TPasClassType;
  149. FPEl, AncestorMemberEl: TPasElement;
  150. DocNode: TDocNode;
  151. DidAutolink: Boolean;
  152. begin
  153. AddLabel(AModule);
  154. with AModule do
  155. begin
  156. AddList(AModule, InterfaceSection.ResStrings);
  157. AddList(AModule, InterfaceSection.Consts);
  158. AddList(AModule, InterfaceSection.Types);
  159. if InterfaceSection.Classes.Count > 0 then
  160. begin
  161. for i := 0 to InterfaceSection.Classes.Count - 1 do
  162. begin
  163. ClassEl := TPasClassType(InterfaceSection.Classes[i]);
  164. AddLabel(ClassEl);
  165. for j := 0 to ClassEl.Members.Count - 1 do
  166. begin
  167. FPEl := TPasElement(ClassEl.Members[j]);
  168. if ((FPEl.Visibility = visPrivate) and Engine.HidePrivate) or
  169. ((FPEl.Visibility = visProtected) and Engine.HideProtected) then
  170. continue;
  171. DocNode := Engine.FindDocNode(FPEl);
  172. if not Assigned(DocNode) then
  173. begin
  174. DidAutolink := False;
  175. if Assigned(ClassEl.AncestorType) and
  176. (ClassEl.AncestorType.ClassType = TPasClassType) then
  177. begin
  178. for k := 0 to TPasClassType(ClassEl.AncestorType).Members.Count - 1 do
  179. begin
  180. AncestorMemberEl :=
  181. TPasElement(TPasClassType(ClassEl.AncestorType).Members[k]);
  182. if AncestorMemberEl.Name = FPEl.Name then
  183. begin
  184. DocNode := Engine.FindDocNode(AncestorMemberEl);
  185. if Assigned(DocNode) then
  186. begin
  187. DidAutolink := True;
  188. Engine.AddLink(FPEl.PathName,
  189. Engine.FindAbsoluteLink(AncestorMemberEl.PathName));
  190. break;
  191. end;
  192. end;
  193. end;
  194. end;
  195. if not DidAutolink then
  196. AddLabel(FPEl);
  197. end else
  198. AddLabel(FPEl);
  199. end;
  200. end;
  201. end;
  202. AddList(AModule, InterfaceSection.Functions);
  203. AddList(AModule, InterfaceSection.Variables);
  204. end;
  205. end;
  206. var
  207. i: Integer;
  208. begin
  209. inherited ;
  210. { Allocate labels for all elements for which we are going to create
  211. documentation. This is needed for links to work correctly. }
  212. // Allocate label for the package itself, if a name is given (i.e. <> '#')
  213. if Length(Package.Name) > 1 then
  214. AddLabel(Package);
  215. for i := 0 to Package.Modules.Count - 1 do
  216. ScanModule(TPasModule(Package.Modules[i]));
  217. end;
  218. procedure TIPFWriter.WriteDoc;
  219. var
  220. i : Integer;
  221. begin
  222. PackageName := LowerCase(Copy(Package.Name, 2, 255));
  223. If (Engine.OutPut='') then
  224. Engine.Output:=PackageName+IPFExtension;
  225. Assign(f, Engine.Output);
  226. Rewrite(f);
  227. try
  228. WriteLn('.* This file has been created automatically by FPDoc,');
  229. WriteLn('.* (c) 2000-2003 by Areca Systems GmbH / Sebastian Guenther ([email protected])');
  230. for i := 0 to Package.Modules.Count - 1 do
  231. begin
  232. Module := TPasModule(Package.Modules[i]);
  233. ModuleName := LowerCase(Module.Name);
  234. WriteLn('');
  235. Write(':h1 name=');
  236. WriteLabel(Module);
  237. WriteLnF('.%s', [EscapeTex(Format(SDocUnitTitle, [Module.Name]))]);
  238. ProcessSection(Module.InterfaceSection);
  239. end;
  240. finally
  241. Close(f);
  242. end;
  243. end;
  244. function TIPFWriter.GetLabel(AElement: TPasElement): String;
  245. var
  246. i: Integer;
  247. begin
  248. if AElement.ClassType = TPasUnresolvedTypeRef then
  249. Result := Engine.ResolveLink(Module, AElement.Name)
  250. else
  251. begin
  252. Result := AElement.PathName;
  253. Result := LowerCase(Copy(Result, 2, Length(Result) - 1));
  254. end;
  255. for i := 1 to Length(Result) do
  256. if Result[i] = '.' then
  257. Result[i] := '_';
  258. end;
  259. procedure TIPFWriter.Write(const s: String);
  260. begin
  261. System.Write(f, s);
  262. end;
  263. procedure TIPFWriter.WriteF(const s: String; const Args: array of const);
  264. begin
  265. System.Write(f, Format(s, Args));
  266. end;
  267. procedure TIPFWriter.WriteLn(const s: String);
  268. begin
  269. System.WriteLn(f, s);
  270. end;
  271. procedure TIPFWriter.WriteLnF(const s: String; const Args: array of const);
  272. begin
  273. System.WriteLn(f, Format(s, Args));
  274. end;
  275. Function TIPFWriter.EscapeTex(S : String) : String;
  276. var
  277. i: Integer;
  278. begin
  279. SetLength(Result, 0);
  280. for i := 1 to Length(S) do
  281. case S[i] of
  282. '.': // Escape these characters
  283. Result := Result + '&per.';
  284. ':':
  285. Result := Result + '&colon.';
  286. ',':
  287. Result := Result + '&comma.';
  288. '&':
  289. Result := Result + '&amp.';
  290. (*
  291. ³&amp. ³ampersand ³& ³
  292. ³&and. ³and ³^ ³
  293. ³&apos. ³apostrophe ³' ³
  294. ³&asterisk. ³asterisk ³* ³
  295. ³&atsign. ³at sign ³@ ³
  296. ³&bslash., &bsl. ³back slash ³\ ³
  297. ³&caret. ³caret symbol ³^ ³
  298. ³&cdq. ³close double quote ³" ³
  299. ³&csq. ³close single quote ³' ³
  300. ³&comma. ³comma ³, ³
  301. ³&colon. ³colon ³: ³
  302. ³&dash. ³dash ³- ³
  303. ³&degree., &deg. ³degree ³ø ³
  304. ³&dollar. ³dollar sign ³$ ³
  305. ³&dot. ³dot ³ú ³
  306. ³&darrow. ³down arrow ³ ³
  307. ³&emdash. ³em dash ³- ³
  308. ³&endash. ³en dash ³- ³
  309. ³&eq., &equals., ³equal sign ³= ³
  310. ³&eqsym. ³ ³ ³
  311. ³&xclm., &xclam. ³exclamation point ³! ³
  312. ³&gtsym., &gt. ³greater than ³> ³
  313. ³&house. ³house ³ ³
  314. ³&hyphen. ³hyphen ³- ³
  315. ³&larrow. ³left arrow ³ ³
  316. ³&lahead. ³left arrowhead ³ ³
  317. ³&lbrace., &lbrc. ³left brace ³{ ³
  318. ³&lbracket. &lbrk. ³left bracket ³[ ³
  319. ³&lpar. , &lparen. ³left parenthesis ³( ³
  320. ³&mdash. ³em dash ³- ³
  321. ³&minus. ³minus sign ³- ³
  322. ³&ndash. ³en dash ³- ³
  323. ³&numsign. ³number sign ³# ³
  324. ³&odq. ³open double quote ³" ³
  325. ³&osq. ³open single quote ³` ³
  326. ³&percent. ³percent ³% ³
  327. ³&per. ³period ³. ³
  328. ³&plus. ³plus sign ³+ ³
  329. ³&rbrace., &rbrc. ³right brace ³} ³
  330. ³&rbracket., &rbrk. ³right bracket ³] ³
  331. ³&rpar., &rparen. ³right parenthesis ³) ³
  332. ³&slash., &slr. ³slash ³/ ³
  333. ³&splitvbar. ³split vertical bar ³| ³
  334. ³ ³(piping symbol) ³ ³
  335. ³&sqbul. ³square bullet ³þ ³
  336. ³&tilde. ³tilde ³~ ³
  337. ³&us. ³underscore ³_ ³
  338. *)
  339. else
  340. Result := Result + S[i];
  341. end;
  342. end;
  343. Function TIPFWriter.StripTex(S : String) : String;
  344. var
  345. I,L: Integer;
  346. begin
  347. Result:=S;
  348. // SetLength(Result, 0);
  349. // for i := 1 to Length(S) do
  350. // If not (S[i] in ['&','{','}','#','_','$','%','''','~','^', '\']) then
  351. // Result := Result + S[i];
  352. end;
  353. procedure TIPFWriter.DescrWriteText(const AText: DOMString);
  354. begin
  355. Write(EscapeTex(AText));
  356. end;
  357. procedure TIPFWriter.DescrBeginBold;
  358. begin
  359. Write(':hp2.');
  360. end;
  361. procedure TIPFWriter.DescrEndBold;
  362. begin
  363. WriteLn(':ehp2.');
  364. end;
  365. procedure TIPFWriter.DescrBeginItalic;
  366. begin
  367. Write(':hp1.');
  368. end;
  369. procedure TIPFWriter.DescrEndItalic;
  370. begin
  371. WriteLn(':ehp1.');
  372. end;
  373. procedure TIPFWriter.DescrBeginEmph;
  374. begin
  375. Write(':hp2.');
  376. end;
  377. procedure TIPFWriter.DescrEndEmph;
  378. begin
  379. Write(':ehp2.');
  380. end;
  381. procedure TIPFWriter.DescrWriteFileEl(const AText: DOMString);
  382. begin
  383. Write(':hp2.');
  384. DescrWriteText(AText);
  385. Write(':ehp2.');
  386. end;
  387. procedure TIPFWriter.DescrWriteKeywordEl(const AText: DOMString);
  388. begin
  389. Write(':hp2.');
  390. DescrWriteText(AText);
  391. Write(':ehp2.');
  392. end;
  393. procedure TIPFWriter.DescrWriteVarEl(const AText: DOMString);
  394. begin
  395. Write(':hp2.');
  396. DescrWriteText(AText);
  397. Write(':ehp2.');
  398. end;
  399. procedure TIPFWriter.DescrBeginLink(const AId: DOMString);
  400. var
  401. i: Integer;
  402. begin
  403. FLink := Engine.ResolveLink(Module, AId);
  404. While pos(':',flink)>0 do flink[pos(':',flink)]:='_';
  405. // System.WriteLn('Link "', AId, '" => ', FLink);
  406. WriteF(':link reftype=hd refid=%s.', [flink]);
  407. end;
  408. procedure TIPFWriter.DescrEndLink;
  409. begin
  410. Write(':elink.');
  411. end;
  412. procedure TIPFWriter.DescrWriteLinebreak;
  413. begin
  414. WriteLn('.br');
  415. end;
  416. procedure TIPFWriter.DescrBeginParagraph;
  417. begin
  418. WriteLn(':p.');
  419. // Do nothing
  420. end;
  421. procedure TIPFWriter.DescrEndParagraph;
  422. begin
  423. WriteLn('');
  424. WriteLn('');
  425. end;
  426. procedure TIPFWriter.DescrBeginCode(HasBorder: Boolean;
  427. const AHighlighterName: String);
  428. begin
  429. StartListing(HasBorder);
  430. end;
  431. procedure TIPFWriter.DescrWriteCodeLine(const ALine: String);
  432. begin
  433. WriteLn(EscapeTex(ALine));
  434. end;
  435. procedure TIPFWriter.DescrEndCode;
  436. begin
  437. EndListing
  438. end;
  439. procedure TIPFWriter.DescrBeginOrderedList;
  440. begin
  441. WriteLn(':ol.');
  442. end;
  443. procedure TIPFWriter.DescrEndOrderedList;
  444. begin
  445. WriteLn(':eol.');
  446. end;
  447. procedure TIPFWriter.DescrBeginUnorderedList;
  448. begin
  449. WriteLn(':ul.');
  450. end;
  451. procedure TIPFWriter.DescrEndUnorderedList;
  452. begin
  453. WriteLn(':eul.');
  454. end;
  455. procedure TIPFWriter.DescrBeginDefinitionList;
  456. begin
  457. WriteLn(':dl.');
  458. end;
  459. procedure TIPFWriter.DescrEndDefinitionList;
  460. begin
  461. WriteLn(':edl.');
  462. end;
  463. procedure TIPFWriter.DescrBeginListItem;
  464. begin
  465. Write(':li.');
  466. end;
  467. procedure TIPFWriter.DescrEndListItem;
  468. begin
  469. WriteLn('');
  470. end;
  471. procedure TIPFWriter.DescrBeginDefinitionTerm;
  472. begin
  473. Write(':li.');
  474. end;
  475. procedure TIPFWriter.DescrEndDefinitionTerm;
  476. begin
  477. WriteLn('');
  478. end;
  479. procedure TIPFWriter.DescrBeginDefinitionEntry;
  480. begin
  481. WriteLn('');
  482. // Do nothing
  483. end;
  484. procedure TIPFWriter.DescrEndDefinitionEntry;
  485. begin
  486. WriteLn('');
  487. end;
  488. procedure TIPFWriter.DescrBeginSectionTitle;
  489. begin
  490. Write(':h3.');
  491. end;
  492. procedure TIPFWriter.DescrBeginSectionBody;
  493. begin
  494. WriteLn('');
  495. end;
  496. procedure TIPFWriter.DescrEndSection;
  497. begin
  498. WriteLn('');
  499. // Do noting
  500. end;
  501. procedure TIPFWriter.DescrBeginRemark;
  502. begin
  503. WriteLn(':note.');
  504. end;
  505. procedure TIPFWriter.DescrEndRemark;
  506. begin
  507. WriteLn('');
  508. end;
  509. procedure TIPFWriter.DescrBeginTable(ColCount: Integer; HasBorder: Boolean);
  510. var
  511. i: Integer;
  512. begin
  513. // !!!: How do we set the border?
  514. // for i := 1 to ColCount do
  515. // Write('l');
  516. // write('}{');
  517. TableCaptionWritten:=False;
  518. end;
  519. procedure TIPFWriter.DescrEndTable;
  520. begin
  521. WriteLn(':etable.');
  522. end;
  523. procedure TIPFWriter.DescrBeginTableCaption;
  524. begin
  525. // Do nothing.
  526. end;
  527. procedure TIPFWriter.DescrEndTableCaption;
  528. begin
  529. Write('');
  530. // Inc(FTableCount);
  531. // Write(IntToStr(FTableCount));
  532. // Writeln('}');
  533. TableCaptionWritten := True;
  534. Write(':table cols=''30 50''.');
  535. end;
  536. procedure TIPFWriter.DescrBeginTableHeadRow;
  537. begin
  538. if not TableCaptionWritten then
  539. DescrEndTableCaption;
  540. TableRowStartFlag := True;
  541. WriteLn(':row.:c.');
  542. end;
  543. procedure TIPFWriter.DescrEndTableHeadRow;
  544. begin
  545. WriteLn('');
  546. end;
  547. procedure TIPFWriter.DescrBeginTableRow;
  548. begin
  549. if not TableCaptionWritten then
  550. DescrEndTableCaption;
  551. TableRowStartFlag := True;
  552. WriteLn(':row.:c.');
  553. end;
  554. procedure TIPFWriter.DescrEndTableRow;
  555. begin
  556. end;
  557. procedure TIPFWriter.DescrBeginTableCell;
  558. begin
  559. if TableRowStartFlag then
  560. TableRowStartFlag := False
  561. else
  562. WriteLn(':c.');
  563. end;
  564. procedure TIPFWriter.DescrEndTableCell;
  565. begin
  566. WriteLn('');
  567. // Do nothing
  568. end;
  569. procedure TIPFWriter.WriteDescr(Element: TPasElement);
  570. var
  571. DocNode: TDocNode;
  572. begin
  573. DocNode := Engine.FindDocNode(Element);
  574. if Assigned(DocNode) then
  575. begin
  576. if not IsDescrNodeEmpty(DocNode.Descr) then
  577. WriteDescr(Element, DocNode.Descr)
  578. else if not IsDescrNodeEmpty(DocNode.ShortDescr) then
  579. WriteDescr(Element, DocNode.ShortDescr);
  580. end;
  581. end;
  582. procedure TIPFWriter.WriteDescr(AContext: TPasElement; DescrNode: TDOMElement);
  583. begin
  584. if Assigned(DescrNode) then
  585. ConvertDescr(AContext, DescrNode, False);
  586. end;
  587. function TIPFWriter.ConstValue(ConstDecl: TPasConst): String;
  588. begin
  589. if Assigned(ConstDecl) then
  590. Result := ConstDecl.ClassName
  591. else
  592. Result := '<nil>';
  593. end;
  594. procedure TIPFWriter.WriteUnitOverview(ASection: TPasSection);
  595. var
  596. i: Integer;
  597. UnitRef: TPasType;
  598. DocNode: TDocNode;
  599. begin
  600. if ASection.UsesList.Count > 0 then
  601. begin
  602. WriteLnF(':h2.%s', [SDocUsedUnits]);
  603. WriteLn(':ol.');
  604. for i := 0 to ASection.UsesList.Count - 1 do
  605. begin
  606. UnitRef := TPasType(ASection.UsesList[i]);
  607. WriteLnF(':li.%s', [UnitRef.Name]);
  608. end;
  609. WriteLn(':eol.');
  610. end;
  611. DocNode := Engine.FindDocNode(ASection.Parent);
  612. if Assigned(DocNode) and not IsDescrNodeEmpty(DocNode.Descr) then
  613. begin
  614. WriteLnF(':h2.%s', [EscapeTex(SDocOverview)]);
  615. WriteDescr(ASection.Parent, DocNode.Descr);
  616. Writeln('');
  617. end;
  618. end;
  619. procedure TIPFWriter.WriteResourceStrings(ASection: TPasSection);
  620. var
  621. ResStrDecl: TPasResString;
  622. i: Integer;
  623. begin
  624. if ASection.ResStrings.Count > 0 then
  625. begin
  626. StartSubSection(SDocResStrings,ModuleName+'ResStrings');
  627. for i := 0 to ASection.ResStrings.Count - 1 do
  628. begin
  629. ResStrDecl := TPasResString(ASection.ResStrings[i]);
  630. StartListing(false, '');
  631. Writeln(ResStrDecl.GetDeclaration(True));
  632. EndListing;
  633. WriteLabel(ResStrDecl);
  634. WriteIndex(ResStrDecl);
  635. WriteDescr(ResStrDecl);
  636. Writeln('');
  637. end;
  638. end;
  639. end;
  640. procedure TIPFWriter.WriteConsts(ASection: TPasSection);
  641. var
  642. i: Integer;
  643. ConstDecl: TPasConst;
  644. begin
  645. if ASection.Consts.Count > 0 then
  646. begin
  647. WriteLnF(':h3 name=suse_%sconstants.%s', [EscapeTex(ModuleName), EscapeTex(SDocConstants)]);
  648. for i := 0 to ASection.Consts.Count - 1 do
  649. begin
  650. ConstDecl := TPasConst(ASection.Consts[i]);
  651. StartListing(False);
  652. WriteLn(EscapeTex(ConstDecl.GetDeclaration(True)));
  653. EndListing;
  654. // WriteLabel(ConstDecl);
  655. // WriteIndex(ConstDecl);
  656. WriteDescr(ConstDecl);
  657. end;
  658. end;
  659. end;
  660. procedure TIPFWriter.WriteEnumElements(TypeDecl : TPasEnumType);
  661. Var
  662. EV : TPasEnumValue;
  663. I : Integer;
  664. DocNode : TDocNode;
  665. begin
  666. With TypeDecl do
  667. begin
  668. SortElementList(Values);
  669. DescrBeginTable(2,True);
  670. DescrBeginTableCaption;
  671. Writeln(EscapeTex(Format(SDocValuesForEnum,[TypeDecl.Name])));
  672. DescrEndTableCaption;
  673. DescrBeginTableHeadRow;
  674. DescrBeginTableCell;
  675. Writeln(EscapeTex(SDocValue));
  676. DescrEndTableCell;
  677. DescrBeginTableCell;
  678. Writeln(EscapeTex(SDocExplanation));
  679. DescrEndTableCell;
  680. DescrEndTableHeadRow;
  681. For I:=0 to Values.Count-1 do
  682. begin
  683. EV:=TPasEnumValue(Values[i]);
  684. DescrBeginTableRow;
  685. DescrBeginTableCell;
  686. Writeln(EscapeTex(EV.Name));
  687. DescrEndTableCell;
  688. DescrBeginTableCell;
  689. DocNode := Engine.FindDocNode(EV);
  690. if Assigned(DocNode) and (not IsDescrNodeEmpty(DocNode.ShortDescr)) then
  691. WriteDescr(EV,DocNode.ShortDescr);
  692. DescrEndTableCell;
  693. DescrEndTableRow;
  694. end;
  695. DescrEndTable;
  696. end;
  697. end;
  698. procedure TIPFWriter.WriteTypes(ASection: TPasSection);
  699. var
  700. i: Integer;
  701. TypeDecl: TPasType;
  702. begin
  703. if ASection.Types.Count > 0 then
  704. begin
  705. StartSubSection(SDocTypes,ModuleName+'Types');
  706. for i := 0 to ASection.Types.Count - 1 do
  707. begin
  708. TypeDecl := TPasType(ASection.Types[i]);
  709. WriteLn(':h4 name='+GetLabel(TypeDecl)+'.');
  710. // WriteLn(':hdref refid='+GetLabel(TypeDecl)+'.');
  711. // WriteLabel(TypeDecl);
  712. // WriteIndex(TypeDecl);
  713. StartListing(False);
  714. Writeln(EscapeTex(TypeDecl.GetDeclaration(True)));
  715. EndListing;
  716. If TypeDecl is TPasEnumType then
  717. begin
  718. WriteENumElements(TypeDecl as TPasEnumType);
  719. end;
  720. WriteDescr(TypeDecl);
  721. end;
  722. end;
  723. end;
  724. procedure TIPFWriter.WriteVars(ASection: TPasSection);
  725. var
  726. VarDecl: TPasVariable;
  727. i: Integer;
  728. begin
  729. if ASection.Variables.Count > 0 then
  730. begin
  731. StartSubsection(SDocVariables,ModuleName+'Variables');
  732. for i := 0 to ASection.Variables.Count - 1 do
  733. begin
  734. // WriteIndex(VarDecl);
  735. VarDecl := TPasVariable(ASection.Variables[i]);
  736. WriteLn(':h4 name='+GetLabel(VarDecl)+'.');
  737. StartListing(False);
  738. WriteLn(EscapeTex(VarDecl.GetDeclaration(True)));
  739. EndListing;
  740. WriteDescr(VarDecl);
  741. end;
  742. end;
  743. end;
  744. procedure TIPFWriter.WriteVarsConstsTypes(ASection: TPasSection);
  745. begin
  746. With Asection do
  747. if (Consts.Count > 0) or
  748. (Types.Count > 0) or
  749. (Variables.Count > 0) or
  750. (ResStrings.Count>0) then
  751. begin
  752. StartSection(SDocConstsTypesVars, ModuleName+'ConstsTypesVars');
  753. WriteResourceStrings(ASection);
  754. WriteConsts(ASection);
  755. WriteTypes(ASection);
  756. WriteVars(ASection);
  757. end;
  758. end;
  759. const
  760. SVisibility: array[TPasMemberVisibility] of string =
  761. ('Default', 'Private', 'Protected', 'Public',
  762. 'Published', 'Automated');
  763. procedure TIPFWriter.WriteProcedure(ProcDecl : TPasProcedureBase);
  764. var
  765. DocNode: TDocNode;
  766. OP : TPasOverloadedProc;
  767. i : integer;
  768. begin
  769. With ProcDecl do
  770. begin
  771. if Not (Assigned(Parent) and Parent.InheritsFrom(TPasClassType)) then
  772. begin
  773. StartSubSection(Name, GetLabel(ProcDecl));
  774. // WriteLabel(ProcDecl);
  775. // WriteIndex(ProcDecl);
  776. end
  777. else
  778. begin // Parent assigned and hence method.
  779. StartSubSection(Parent.Name+'&per.'+Name, GetLabel(ProcDecl));
  780. // WriteLabel(ProcDecl);
  781. // WriteIndex(Parent.Name+'.'+Name);
  782. end;
  783. // Writeln('\begin{FPCList}');
  784. DocNode := Engine.FindDocNode(ProcDecl);
  785. if Assigned(DocNode) and Assigned(DocNode.ShortDescr) then
  786. begin
  787. Writeln(':hp2.Synopsis:ehp2.&colon. ');
  788. WriteDescr(ProcDecl, DocNode.ShortDescr);
  789. WriteLn('');
  790. WriteLn('.br');
  791. end;
  792. Writeln(':hp2.Declaration:ehp2.&colon. ');
  793. StartListing(False);
  794. if ClassType = TPasOverloadedProc then
  795. begin
  796. OP:=TPasOverloadedProc(ProcDecl);
  797. for i := 0 to OP.Overloads.Count - 1 do
  798. begin
  799. WriteLn(TPasProcedure(OP.Overloads[i]).GetDeclaration(True));
  800. end;
  801. end
  802. else
  803. WriteLn(GetDeclaration(True));
  804. EndListing;
  805. WriteLn('');
  806. WriteLn('.br');
  807. If Assigned(Parent) then
  808. begin
  809. Writeln(':hp2.Visibility:ehp2.&colon. ');
  810. Writeln(VisibilityNames[Visibility]);
  811. WriteLn('');
  812. WriteLn('.br');
  813. end;
  814. if Assigned(DocNode) and Assigned(DocNode.Descr) then
  815. begin
  816. Writeln(':hp2.Description:ehp2.&colon. ');
  817. WriteDescr(ProcDecl);
  818. WriteLn('');
  819. WriteLn('.br');
  820. end;
  821. if Assigned(DocNode) and Assigned(DocNode.ErrorsDoc) then
  822. begin
  823. Writeln(':hp2.Errors:ehp2.&colon.');
  824. WriteDescr(ProcDecl, DocNode.ErrorsDoc);
  825. WriteLn('');
  826. WriteLn('.br');
  827. end;
  828. WriteSeeAlso(DocNode);
  829. WriteLn('');
  830. WriteLn('.br');
  831. // Writeln('\end{FPCList}');
  832. WriteExample(DocNode);
  833. end;
  834. end;
  835. procedure TIPFWriter.WriteFunctionsAndProcedures(ASection: TPasSection);
  836. var
  837. i: Integer;
  838. begin
  839. if ASection.Functions.Count > 0 then
  840. begin
  841. StartSection(SDocProceduresAndFunctions,ModuleName+'Functions');
  842. for i := 0 to ASection.Functions.Count - 1 do
  843. WriteProcedure(TPasProcedureBase(ASection.Functions[i]));
  844. end;
  845. end;
  846. procedure TIPFWriter.WriteExample(ADocNode: TDocNode);
  847. var
  848. Example: TDOMElement;
  849. begin
  850. if Assigned(ADocNode) then
  851. begin
  852. Example := ADocNode.FirstExample;
  853. while Assigned(Example) do
  854. begin
  855. WritelnF(':xmp.%s:exmp.', [EscapeTex(Engine.GetExampleFileName(Example))]);
  856. if Assigned(Example.NextSibling) then
  857. WriteLn('');
  858. Example := TDomElement(Example.NextSibling);
  859. end;
  860. end;
  861. end;
  862. procedure TIPFWriter.WriteSeeAlso(ADocNode: TDocNode);
  863. var
  864. Node: TDOMNode;
  865. s: String;
  866. begin
  867. if Assigned(ADocNode) and Assigned(ADocNode.SeeAlso) and
  868. Assigned(ADocNode.SeeAlso.FirstChild) then
  869. begin
  870. Writeln(':hp2.SeeAlso:ehp2.');
  871. Node := ADocNode.SeeAlso.FirstChild;
  872. while Assigned(Node) do
  873. begin
  874. if (Node.NodeType = ELEMENT_NODE) and
  875. (Node.NodeName = 'link') then
  876. begin
  877. S:=TDomElement(Node)['id'];
  878. DescrBeginLink(S);
  879. Writeln(S);
  880. DescrEndLink();
  881. if Assigned(Node.NextSibling) Then
  882. Writeln(',');
  883. end;
  884. Node:=Node.NextSibling;
  885. end;
  886. end;
  887. end;
  888. procedure TIPFWriter.WriteClasses(ASection: TPasSection);
  889. var
  890. i: Integer;
  891. begin
  892. if (ASection.Classes.Count > 0) then
  893. begin
  894. for i := 0 to ASection.Classes.Count - 1 do
  895. WriteClassDecl(TPasClassType(ASection.Classes[i]));
  896. end;
  897. end;
  898. procedure TIPFWriter.ProcessSection(ASection: TPasSection);
  899. begin
  900. With ASection do
  901. begin
  902. SortElementList(UsesList);
  903. SortElementList(Declarations);
  904. SortElementList(ResStrings);
  905. SortElementList(Types);
  906. SortElementList(Consts);
  907. SortElementList(Classes);
  908. SortElementList(Functions);
  909. SortElementList(Variables);
  910. end;
  911. WriteUnitOverView(ASection);
  912. WriteVarsConstsTypes(ASection);
  913. WriteFunctionsAndProcedures(ASection);
  914. WriteClasses(ASection);
  915. end;
  916. Function TIPFWriter.ShowMember(M : TPasElement) : boolean;
  917. begin
  918. Result:=not ((M.Visibility=visPrivate) and Engine.HidePrivate);
  919. If Result then
  920. Result:=Not ((M.Visibility=visProtected) and Engine.HideProtected)
  921. end;
  922. procedure TIPFWriter.WriteClassMethodOverview(ClassDecl : TPasClassType);
  923. var
  924. Member: TPasElement;
  925. i, j: Integer;
  926. s: String;
  927. Arg: TPasArgument;
  928. DocNode: TDocNode;
  929. List : TStringList;
  930. begin
  931. List:=TStringList.Create;
  932. Try
  933. List.Sorted:=True;
  934. for i := 0 to ClassDecl.Members.Count - 1 do
  935. begin
  936. Member := TPasElement(ClassDecl.Members[i]);
  937. With Member do
  938. if InheritsFrom(TPasProcedureBase) and ShowMember(Member) then
  939. List.AddObject(Member.Name,Member);
  940. end;
  941. If List.Count>0 then
  942. begin
  943. StartSubSection(SDocMethodOverview, GetLabel(ClassDecl) + ':Methods');
  944. // WriteLabel();
  945. WriteLn(':parml.');
  946. // WriteLnF('%s & %s & %s \\ \hline', [EscapeTex(SDocPage), EscapeTex(SDocMethod), EscapeTex(SDocDescription)]);
  947. For I:=0 to List.Count-1 do
  948. begin
  949. Member:=TPasElement(List.Objects[i]);
  950. DocNode := Engine.FindDocNode(Member);
  951. WriteF(':pt.:link reftype=hd refid=%s.%s:elink.:pd.',[StripTex(GetLabel(Member)), EscapeTex(Member.Name)]);
  952. if Assigned(DocNode) and Assigned(DocNode.ShortDescr) then
  953. WriteDescr(Member, DocNode.ShortDescr);
  954. WriteLn('');
  955. WriteLn('.br');
  956. end;
  957. WriteLn(':eparml.');
  958. // WriteLn('\end{tabularx}');
  959. end;
  960. Finally
  961. List.Free;
  962. end;
  963. end;
  964. procedure TIPFWriter.WriteClassPropertyOverview(ClassDecl : TPasClassType);
  965. var
  966. Member: TPasElement;
  967. i, j: Integer;
  968. s: String;
  969. Arg: TPasArgument;
  970. DocNode: TDocNode;
  971. List : TStringList;
  972. begin
  973. // Write property overview
  974. List:=TStringList.Create;
  975. Try
  976. List.Sorted:=True;
  977. for i := 0 to ClassDecl.Members.Count - 1 do
  978. begin
  979. Member := TPasElement(ClassDecl.Members[i]);
  980. With Member do
  981. if InheritsFrom(TPasProperty) and SHowMember(Member) then
  982. List.AddObject(Member.Name,Member)
  983. end;
  984. If (List.Count>0) then
  985. begin
  986. StartSubSection(SDocPropertyOverview, GetLabel(ClassDecl) + ':Properties');
  987. // WriteLabel(GetLabel(ClassDecl) + ':Properties');
  988. WriteLn(':parml.');
  989. // WriteLn('\begin{tabularx}{\textwidth}{lllX}');
  990. // WriteLnF('%s & %s & %s & %s \\ \hline',
  991. // [EscapeTex(SDocPage), EscapeTex(SDocProperty), EscapeTex(SDocAccess), EscapeTex(SDocDescription)]);
  992. For I:=0 to List.Count-1 do
  993. begin
  994. Member:=TPasElement(List.objects[i]);
  995. WriteF(':pt.:link reftype=hd refid=%s.%s:elink.:pd.',[StripTex(GetLabel(Member)), EscapeTex(Member.Name)]);
  996. setlength(S,0);
  997. if Length(TPasProperty(Member).ReadAccessorName) > 0 then
  998. s := s + 'r';
  999. if Length(TPasProperty(Member).WriteAccessorName) > 0 then
  1000. s := s + 'w';
  1001. if Length(TPasProperty(Member).StoredAccessorName) > 0 then
  1002. s := s + 's';
  1003. // Write(s + ' & ');
  1004. DocNode := Engine.FindDocNode(Member);
  1005. if Assigned(DocNode) and Assigned(DocNode.ShortDescr) then
  1006. WriteDescr(Member, DocNode.ShortDescr);
  1007. WriteLn('');
  1008. WriteLn('.br');
  1009. end;
  1010. WriteLn(':eparml.');
  1011. end;
  1012. Finally
  1013. List.Free;
  1014. end;
  1015. end;
  1016. procedure TIPFWriter.WriteClassDecl(ClassDecl: TPasClassType);
  1017. var
  1018. DocNode: TDocNode;
  1019. Vis: TPasMemberVisibilities;
  1020. Member: TPasElement;
  1021. i: Integer;
  1022. begin
  1023. StartSection(ClassDecl.Name, GetLabel(ClassDecl));
  1024. // WriteLabel(ClassDecl);
  1025. // WriteIndex(ClassDecl);
  1026. DocNode := Engine.FindDocNode(ClassDecl);
  1027. if Assigned(DocNode) and ((not IsDescrNodeEmpty(DocNode.Descr)) or
  1028. (not IsDescrNodeEmpty(DocNode.ShortDescr))) then
  1029. begin
  1030. // StartSubSection(SDocDescription, GetLabel(ClassDecl) + ':Description');
  1031. WriteDescr(ClassDecl);
  1032. end;
  1033. // Write method overview
  1034. WriteClassMethodOverView(ClassDecl);
  1035. // Write Property Overview;
  1036. WriteClassPropertyOverView(ClassDecl);
  1037. // Write method & property descriptions
  1038. // Determine visibilities
  1039. Vis := AllVisibilities;
  1040. if Engine.HidePrivate then
  1041. Exclude(Vis,visPrivate);
  1042. if Engine.HideProtected then
  1043. Exclude(Vis,visProtected);
  1044. for i := 0 to ClassDecl.Members.Count - 1 do
  1045. begin
  1046. Member := TPasElement(ClassDecl.Members[i]);
  1047. if ((Member.InheritsFrom(TPasProcedureBase)) and
  1048. (Member.Visibility in Vis)) then
  1049. WriteProcedure(TPasProcedureBase(Member));
  1050. end;
  1051. // properties.
  1052. for i := 0 to ClassDecl.Members.Count - 1 do
  1053. begin
  1054. Member := TPasElement(ClassDecl.Members[i]);
  1055. if ((Member.InheritsFrom(TPasProperty)) and
  1056. (Member.Visibility in Vis)) then
  1057. WriteProperty(TPasProperty(Member));
  1058. end;
  1059. end;
  1060. procedure TIPFWriter.WriteProperty(PropDecl : TPasProperty);
  1061. var
  1062. DocNode: TDocNode;
  1063. S: String;
  1064. begin
  1065. With PropDecl do
  1066. begin
  1067. StartSubSection(Parent.Name+'&per.'+Name, GetLabel(PropDecl));
  1068. // WriteLabel(PropDecl);
  1069. // WriteIndex(Parent.Name+'.'+Name);
  1070. // Writeln('\begin{FPCList}');
  1071. DocNode := Engine.FindDocNode(PropDecl);
  1072. if Assigned(DocNode) and Assigned(DocNode.ShortDescr) then
  1073. begin
  1074. Writeln(':hp2.Synopsis:ehp2.&colon. ');
  1075. WriteDescr(PropDecl, DocNode.ShortDescr);
  1076. WriteLn('');
  1077. WriteLn('.br');
  1078. end;
  1079. Writeln(':hp2.Declaration:ehp2.&colon. ');
  1080. StartListing(False);
  1081. WriteLn('Property '+GetDeclaration(True));
  1082. EndListing;
  1083. WriteLn('');
  1084. WriteLn('.br');
  1085. If Assigned(Parent) then
  1086. begin
  1087. Writeln(':hp2.Visibility:ehp2.&colon. ');
  1088. Writeln(VisibilityNames[Visibility]);
  1089. WriteLn('');
  1090. WriteLn('.br');
  1091. end;
  1092. Writeln(':hp2.Access:ehp2.&colon.');
  1093. Setlength(S,0);
  1094. If Length(ReadAccessorName) > 0 then
  1095. S:='Read';
  1096. if Length(WriteAccessorName) > 0 then
  1097. begin
  1098. If S<>'' then
  1099. S:=S+',';
  1100. S:=S+'Write';
  1101. end;
  1102. Writeln(S);
  1103. WriteLn('');
  1104. WriteLn('.br');
  1105. if Assigned(DocNode) and Assigned(DocNode.Descr) then
  1106. begin
  1107. Writeln(':hp2.Description:ehp2.&colon.');
  1108. WriteDescr(PropDecl);
  1109. WriteLn('');
  1110. WriteLn('.br');
  1111. end;
  1112. if Assigned(DocNode) and Assigned(DocNode.ErrorsDoc) then
  1113. begin
  1114. Writeln(':hp2.Errors:ehp2.&colon. ');
  1115. WriteDescr(PropDecl, DocNode.ErrorsDoc);
  1116. WriteLn('');
  1117. WriteLn('.br');
  1118. end;
  1119. WriteSeeAlso(DocNode);
  1120. WriteLn('');
  1121. WriteLn('.br');
  1122. // Writeln('\end{FPCList}');
  1123. WriteExample(DocNode);
  1124. end;
  1125. end;
  1126. Function CompareElements(P1,P2 : Pointer) : Integer;
  1127. begin
  1128. Result:=CompareText(TPasElement(P1).Name,TPasElement(P2).Name);
  1129. end;
  1130. procedure TIPFWriter.SortElementList(List : TList);
  1131. begin
  1132. List.Sort(@CompareElements)
  1133. end;
  1134. procedure TIPFWriter.WriteLabel(El: TPasElement);
  1135. begin
  1136. WriteLabel(GetLabel(El));
  1137. end;
  1138. procedure TIPFWriter.WriteLabel(const s: String);
  1139. var
  1140. x: String;
  1141. begin
  1142. X:=s;
  1143. While pos(':',x)>0 do x[pos(':',x)]:='_';
  1144. WriteF('%s', [LowerCase(StripTex(x))]);
  1145. end;
  1146. procedure TIPFWriter.WriteIndex(El : TPasElement);
  1147. begin
  1148. WriteIndex(El.Name);
  1149. end;
  1150. procedure TIPFWriter.WriteIndex(const s : String);
  1151. begin
  1152. // Write('\index{');
  1153. // Write(EscapeTex(s));
  1154. // Writeln('}');
  1155. end;
  1156. procedure TIPFWriter.StartListing(Frames: Boolean; const name: String);
  1157. begin
  1158. Writeln(':xmp.')
  1159. end;
  1160. procedure TIPFWriter.StartListing(Frames : Boolean);
  1161. begin
  1162. StartListing(Frames,'');
  1163. end;
  1164. procedure TIPFWriter.EndListing;
  1165. begin
  1166. Writeln(':exmp.')
  1167. end;
  1168. procedure TIPFWriter.WriteCommentLine;
  1169. const
  1170. CommentLine =
  1171. '.* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%';
  1172. begin
  1173. WriteLn('');
  1174. Writeln(CommentLine);
  1175. end;
  1176. procedure TIPFWriter.WriteComment(Comment : String);
  1177. begin
  1178. // Write('.* ');
  1179. // Writeln(Comment);
  1180. end;
  1181. procedure TIPFWriter.StartSection(SectionName : String; SectionLabel : String);
  1182. begin
  1183. // StartSection(SectionName);
  1184. WriteCommentLine;
  1185. WriteComment(SectionName);
  1186. Write(':h2 name=');
  1187. WriteLabel(SectionLabel);
  1188. WriteLn('.'+EscapeTex(SectionName));
  1189. end;
  1190. //procedure TIPFWriter.StartSection(SectionName : String);
  1191. //begin
  1192. //end;
  1193. procedure TIPFWriter.StartSubSection(SubSectionName : String; SubSectionLabel : String);
  1194. begin
  1195. Writeln('');
  1196. WriteComment(SubsectionName);
  1197. Write(':h3 name=');
  1198. WriteLabel(SubsectionLabel);
  1199. WriteLn('.'+{EscapeTex(}SubSectionName{)});
  1200. end;
  1201. //procedure TIPFWriter.StartSubSection(SubSectionName : String);
  1202. //begin
  1203. //end;
  1204. procedure TIPFWriter.StartChapter(ChapterName : String; ChapterLabel : String);
  1205. begin
  1206. StartChapter(ChapterName);
  1207. WriteLabel(ChapterLabel);
  1208. end;
  1209. procedure TIPFWriter.StartChapter(ChapterName : String);
  1210. begin
  1211. Writeln('');
  1212. WriteCommentLine;
  1213. WriteComment(ChapterName);
  1214. WriteCommentLine;
  1215. Writeln(':h1.'+{EscapeTex(}ChapterName{)});
  1216. end;
  1217. initialization
  1218. // Do not localize.
  1219. RegisterWriter(TIPFWriter,'ipf','IPF output.');
  1220. finalization
  1221. UnRegisterWriter('ipf');
  1222. end.
  1223. {
  1224. $Log$
  1225. Revision 1.2 2005-01-12 21:11:41 michael
  1226. + New structure for writers. Implemented TXT writer
  1227. Revision 1.1 2003/10/08 11:41:54 yuri
  1228. + Initial OS/2 IPF support added
  1229. Revision 1.4 2003/03/18 19:28:44 michael
  1230. + Some changes to output handling, more suitable for tex output
  1231. Revision 1.3 2003/03/18 19:12:29 michael
  1232. + More EscapeTex calls needed
  1233. Revision 1.2 2003/03/18 01:11:51 michael
  1234. + Some fixes to deal with illegal tex characters
  1235. Revision 1.1 2003/03/17 23:03:20 michael
  1236. + Initial import in CVS
  1237. Revision 1.13 2003/03/13 22:02:13 sg
  1238. * New version with many bugfixes and our own parser (now independent of the
  1239. compiler source)
  1240. Revision 1.12 2002/10/20 22:49:31 michael
  1241. + Sorted all overviews. Added table with enumeration values for enumerated types.
  1242. Revision 1.11 2002/05/24 00:13:22 sg
  1243. * much improved new version, including many linking and output fixes
  1244. Revision 1.10 2002/03/12 10:58:36 sg
  1245. * reworked linking engine and internal structure
  1246. Revision 1.9 2002/01/20 11:19:55 michael
  1247. + Added link attribute and property to TFPElement
  1248. Revision 1.8 2002/01/08 13:00:06 michael
  1249. + Added correct array handling and syntax highlighting is now optional
  1250. Revision 1.7 2002/01/08 08:22:40 michael
  1251. + Implemented latex writer
  1252. Revision 1.6 2001/12/17 14:41:42 michael
  1253. + Split out of latex writer
  1254. Revision 1.5 2001/12/17 13:41:18 jonas
  1255. * OsPathSeparator -> PathDelim
  1256. }