12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796 |
- {$mode objfpc}
- {$H+}
- unit dw_man;
- interface
- uses
- Classes, SysUtils, DGlobals, dWriter, pastree, dom;
- Const
- DefaultManSection = 3;
- MaxListLevel = 4;
- // Suffixes for overview man pages.
- SManConsts = 'consts';
- SManVars = 'variables';
- SManTypes = 'types';
- SManResStr = 'resstr';
- // Standard man sections.
- SManDocName = 'NAME';
- SManDocSynopsis = 'SYNOPSIS';
- SManDocDescription = 'DESCRIPTION';
- SManDocErrors = 'ERRORS';
- SManDocSeeAlso = 'SEE ALSO';
- // FPDoc man sections.
- SManDocPackageUnits = 'PACKAGE UNITS';
- SManDocUsedUnits = 'USED UNITS';
- SManDocResourceStrings = 'RESOURCE STRINGS';
- SManDocVariables = 'VARIABLES';
- SManDocTypes = 'TYPES';
- SManDocConstants = 'CONSTANTS';
- SManDocFunctions = 'PROCEDURES AND FUNCTIONS';
- SManDocClasses = 'CLASSES';
- SManDocExamples = 'EXAMPLES';
- SManDocVisibility = 'VISIBILITY';
- SManDocArguments = 'ARGUMENTS';
- SManDocResult = 'RETURN VALUE';
- SManDocAccess = 'ACCESSIBILITY';
- SManDocMethods = 'METHODS';
- SManDocProperties = 'PROPERTIES';
- // Used to start listing
- SManDocListing = 'Listing:';
- Type
- { TManWriter }
- TManWriter = Class(TFPDocWriter)
- SkipUnitPrefix,
- FSkipTrim : Boolean;
- OutputDir,
- ModuleName,
- ManSection,
- PackageDescr,
- PackageName: String;
- FAtLineStart,
- FCheckEOL : Boolean;
- FStream : TStream;
- Module: TPasModule;
- FListLevel : Integer;
- FLists : Array [0..MaxListLevel] of integer;
- Protected
- // Writing support.
- procedure Write(const s: String);
- procedure WriteF(const s: String; const Args: array of const);
- procedure WriteLn(const s: String);
- procedure WriteLnF(const s: String; const Args: array of const);
- Procedure NewLine;
- Function PushWriteContext(S : TStream) : TStream;
- Procedure PopWriteContext(S : TSTream);
- Function EscapeText(const s : String) : String;
- // Formatting
- procedure WriteTP;
- procedure WriteB(Const Msg : String);
- procedure WriteBI(Const Msg : String);
- procedure NewListLevel(Initial : Integer);
- procedure DecListLevel;
- procedure StartListing(Frames: Boolean);
- // Sectioning routines
- Procedure StartManPage(AElement : TPasElement; ADocNode : TDocNode);
- Procedure StartManPage(FN : String);
- Procedure EndManPage;
- procedure StartSection(Const SectionName : String);
- procedure StartSubSection(Const SubSectionName : String);
- procedure PageTitle(Const ATitle,ASection,ASource,Amanual : String);
- // Referencing
- Function ElementToManPage(APasElement : TPasElement) : String;
- procedure WriteManRef(Const ManPage : String; Comma : Boolean);
- procedure WriteManRef(APasElement : TPasElement; Comma : Boolean);
- procedure WriteModuleSeealso(Comma : Boolean);
- procedure SortElementList(List : TList);
- Function GetDescrString(AContext: TPasElement; DescrNode: TDOMElement) : String;
- function ConstValue(ConstDecl: TPasConst): String; virtual;
- procedure WriteCommentLine;
- procedure WriteComment(Comment : String);
- Procedure WriteExampleFile(FN : String); virtual;
- Class Function FileNameExtension : String;virtual;
- procedure WriteExample(ADocNode: TDocNode);
- procedure WriteSeeAlso(ADocNode: TDocNode; Comma : Boolean);
- Public
- Constructor Create(APackage: TPasPackage; AEngine: TFPDocEngine); override;
- procedure WriteDoc; override;
- // Documentation writing methods.
- // Package
- Procedure WritePackagePage;
- // Topics
- Procedure ProcessTopics(DocNode : TDocNode; Subs : Boolean);
- Procedure WriteTopicRefs(DocNode : TDocNode);
- Procedure WriteTopicPage(Parent,Node : TDocNode);
- // Module
- procedure ProcessModule(AModule: TPasModule);
- procedure WriteUnitPage(AModule: TPasModule);
- procedure WriteUnitUsesOverview(ASection: TPasSection);
- procedure WriteUnitFunctionsAndProceduresOverview(ASection: TPasSection);
- procedure WriteUnitClassesOverview(ASection: TPasSection);
- procedure WriteUnitResourceStrings(ASection: TPasSection);
- procedure WriteUnitConsts(ASection: TPasSection);
- procedure WriteUnitTypes(ASection: TPasSection);
- procedure WriteUnitVars(ASection: TPasSection);
- procedure WriteUnitClasses(ASection: TPasSection);
- procedure WriteUnitFunctionsAndProcedures(ASection: TPasSection);
- // Smaller elements
- procedure WriteEnumElements(TypeDecl : TPasEnumType);
- procedure WriteClassPage(ClassDecl: TPasClassType);
- procedure WriteClassMethodOverview(ClassDecl: TPasClassType);
- procedure WriteClassPropertyOverview(ClassDecl: TPasClassType);
- procedure WriteProcedurePage(ProcDecl: TPasProcedureBase);
- procedure AppendProcedureArgsSection(Element: TPasProcedureType);
- procedure AppendFunctionResultSection(Element: TPasFunctionType);
- procedure WritePropertyPage(PropDecl: TPasProperty);
- // Overriden from fpdocwriter;
- procedure DescrWriteText(const AText: DOMString); override;
- procedure DescrBeginBold; override;
- procedure DescrEndBold; override;
- procedure DescrBeginItalic; override;
- procedure DescrEndItalic; override;
- procedure DescrBeginEmph; override;
- procedure DescrEndEmph; override;
- procedure DescrWriteFileEl(const AText: DOMString); override;
- procedure DescrWriteKeywordEl(const AText: DOMString); override;
- procedure DescrWriteVarEl(const AText: DOMString); override;
- procedure DescrBeginLink(const AId: DOMString); override;
- procedure DescrEndLink; override;
- procedure DescrWriteLinebreak; override;
- procedure DescrBeginParagraph; override;
- procedure DescrBeginCode(HasBorder: Boolean; const AHighlighterName: String); override;
- procedure DescrWriteCodeLine(const ALine: String); override;
- procedure DescrEndCode; override;
- procedure DescrEndParagraph; override;
- procedure DescrBeginOrderedList; override;
- procedure DescrEndOrderedList; override;
- procedure DescrBeginUnorderedList; override;
- procedure DescrEndUnorderedList; override;
- procedure DescrBeginDefinitionList; override;
- procedure DescrEndDefinitionList; override;
- procedure DescrBeginListItem; override;
- procedure DescrEndListItem; override;
- procedure DescrBeginDefinitionTerm; override;
- procedure DescrEndDefinitionTerm; override;
- procedure DescrBeginDefinitionEntry; override;
- procedure DescrEndDefinitionEntry; override;
- procedure DescrBeginSectionTitle; override;
- procedure DescrBeginSectionBody; override;
- procedure DescrEndSection; override;
- procedure DescrBeginRemark; override;
- procedure DescrEndRemark; override;
- procedure DescrBeginTable(ColCount: Integer; HasBorder: Boolean); override;
- procedure DescrEndTable; override;
- procedure DescrBeginTableCaption; override;
- procedure DescrEndTableCaption; override;
- procedure DescrBeginTableHeadRow; override;
- procedure DescrEndTableHeadRow; override;
- procedure DescrBeginTableRow; override;
- procedure DescrEndTableRow; override;
- procedure DescrBeginTableCell; override;
- procedure DescrEndTableCell; override;
- Function InterPretOption(Const Cmd,Arg : String) : boolean; override;
- Class procedure Usage(List: TStrings); override;
- end;
- implementation
- { TManWriter }
- constructor TManWriter.Create(APackage: TPasPackage; AEngine: TFPDocEngine);
- procedure AddLabel(AElement: TPasElement);
- begin
- Engine.AddLink(AElement.PathName, ElementToManPage(AElement));
- end;
- procedure AddList(AElement: TPasElement; AList: TList);
- var
- i: Integer;
- begin
- for i := 0 to AList.Count - 1 do
- AddLabel(TPasElement(AList[i]));
- end;
- procedure AddTopicPages(AElement: TPasElement);
- var
- PreviousTopic,
- TopicElement : TTopicElement;
- DocNode,
- TopicNode : TDocNode;
- begin
- DocNode:=Engine.FindDocNode(AElement);
- If not Assigned(DocNode) then
- exit;
- TopicNode:=DocNode.FirstChild;
- PreviousTopic:=Nil;
- While Assigned(TopicNode) do
- begin
- If TopicNode.TopicNode then
- begin
- TopicElement:=TTopicElement.Create(TopicNode.Name,AElement);
- Topics.Add(TopicElement);
- TopicElement.TopicNode:=TopicNode;
- TopicElement.Previous:=PreviousTopic;
- If Assigned(PreviousTopic) then
- PreviousTopic.Next:=TopicElement;
- PreviousTopic:=TopicElement;
- if AElement is TTopicElement then
- TTopicElement(AElement).SubTopics.Add(TopicElement);
- Engine.AddLink(TopicElement.PathName, ElementToManPage(TopicElement));
- if AElement is TTopicElement then
- TTopicElement(AElement).SubTopics.Add(TopicElement)
- else // Only one level of recursion.
- AddTopicPages(TopicElement);
- end;
- TopicNode:=TopicNode.NextSibling;
- end;
- end;
- procedure ScanModule(AModule: TPasModule);
- var
- i, j, k: Integer;
- ClassEl: TPasClassType;
- FPEl, AncestorMemberEl: TPasElement;
- DocNode: TDocNode;
- DidAutolink: Boolean;
- begin
- AddLabel(AModule);
- AddTopicPages(AModule);
- with AModule do
- begin
- AddList(AModule, InterfaceSection.ResStrings);
- AddList(AModule, InterfaceSection.Consts);
- AddList(AModule, InterfaceSection.Types);
- if InterfaceSection.Classes.Count > 0 then
- begin
- for i := 0 to InterfaceSection.Classes.Count - 1 do
- begin
- ClassEl := TPasClassType(InterfaceSection.Classes[i]);
- AddLabel(ClassEl);
- for j := 0 to ClassEl.Members.Count - 1 do
- begin
- FPEl := TPasElement(ClassEl.Members[j]);
- if ((FPEl.Visibility = visPrivate) and Engine.HidePrivate) or
- ((FPEl.Visibility = visProtected) and Engine.HideProtected) then
- continue;
- DocNode := Engine.FindDocNode(FPEl);
- if not Assigned(DocNode) then
- begin
- DidAutolink := False;
- if Assigned(ClassEl.AncestorType) and
- (ClassEl.AncestorType.ClassType = TPasClassType) then
- begin
- for k := 0 to TPasClassType(ClassEl.AncestorType).Members.Count - 1 do
- begin
- AncestorMemberEl :=
- TPasElement(TPasClassType(ClassEl.AncestorType).Members[k]);
- if AncestorMemberEl.Name = FPEl.Name then
- begin
- DocNode := Engine.FindDocNode(AncestorMemberEl);
- if Assigned(DocNode) then
- begin
- DidAutolink := True;
- Engine.AddLink(FPEl.PathName,
- Engine.FindAbsoluteLink(AncestorMemberEl.PathName));
- break;
- end;
- end;
- end;
- end;
- if not DidAutolink then
- AddLabel(FPEl);
- end else
- AddLabel(FPEl);
- end;
- end;
- end;
- AddList(AModule, InterfaceSection.Functions);
- AddList(AModule, InterfaceSection.Variables);
- end;
- end;
- var
- i: Integer;
- begin
- inherited;
- if Length(Package.Name) > 1 then
- AddTopicPages(Package);
- for i := 0 to Package.Modules.Count - 1 do
- ScanModule(TPasModule(Package.Modules[i]));
- end;
- { ---------------------------------------------------------------------
- Writing support
- ---------------------------------------------------------------------}
- Function TManWriter.PushWriteContext(S : TStream) : TStream;
- begin
- Result:=FStream;
- FStream:=S;
- end;
- Procedure TManWriter.PopWriteContext(S : TSTream);
- begin
- FStream:=S;
- end;
- function TManWriter.EscapeText(const s: String): String;
- begin
- Result:=S;
- end;
- procedure TManWriter.Write(const s: String);
- Var
- W : String;
- L : Integer;
- begin
- W:=S;
- If FAtLineStart and not FSKipTrim then
- W:=TrimLeft(W);
- L:=Length(W);
- If (L>0) then
- FStream.Write(PChar(W)^,L);
- FAtLineStart:=false;
- If FCheckEOL then
- begin
- If (L>=LEOL) then
- FAtLineStart:=(Copy(W,L-LEOL+1,LEOL)=LineEnding);
- end;
- end;
- Procedure TManWriter.NewLine;
- begin
- if Not FAtLineStart then
- Writeln('');
- end;
- procedure TManWriter.WriteF(const s: String; const Args: array of const);
- begin
- Write(Format(S,Args));
- end;
- procedure TManWriter.WriteLn(const s: String);
- begin
- FCheckEOL:=False;
- Try
- Write(S);
- Write(LineEnding);
- FAtLineStart:=True;
- finally
- FCheckEOL:=True;
- end;
- end;
- procedure TManWriter.WriteLnF(const s: String; const Args: array of const);
- begin
- Write(Format(S,Args));
- Write(LineEnding);
- end;
- procedure TManWriter.DescrWriteText(const AText: DOMString);
- begin
- self.Write(EscapeText(AText));
- end;
- procedure TManWriter.DescrBeginBold;
- begin
- NewLine;
- Write('.B ');
- end;
- procedure TManWriter.DescrEndBold;
- begin
- NewLine;
- end;
- procedure TManWriter.DescrBeginItalic;
- begin
- NewLine;
- Write('.I ');
- end;
- procedure TManWriter.DescrEndItalic;
- begin
- NewLine;
- end;
- procedure TManWriter.DescrBeginEmph;
- begin
- NewLine;
- Write('.I ');
- end;
- procedure TManWriter.DescrEndEmph;
- begin
- NewLine;
- end;
- procedure TManWriter.DescrWriteFileEl(const AText: DOMString);
- Var
- S : AnsiString;
- begin
- NewLine;
- S:=AText;
- Writeln('.I '+S);
- end;
- procedure TManWriter.DescrWriteKeywordEl(const AText: DOMString);
- Var
- S : AnsiString;
- begin
- NewLine;
- S:=AText;
- Writeln('.B '+S);
- end;
- procedure TManWriter.DescrWriteVarEl(const AText: DOMString);
- Var
- S : AnsiString;
- begin
- NewLine;
- S:=AText;
- Writeln('.B '+S);
- end;
- procedure TManWriter.DescrBeginLink(const AId: DOMString);
- begin
- // Do nothing
- end;
- procedure TManWriter.DescrEndLink;
- begin
- // Do nothing
- end;
- procedure TManWriter.DescrWriteLinebreak;
- begin
- NewLine;
- Writeln('.br');
- end;
- procedure TManWriter.DescrBeginParagraph;
- begin
- NewLine;
- Writeln('.PP');
- end;
- procedure TManWriter.DescrBeginCode(HasBorder: Boolean;
- const AHighlighterName: String);
- begin
- NewLine;
- Writeln('');
- end;
- procedure TManWriter.DescrWriteCodeLine(const ALine: String);
- begin
- FSkipTrim:=True;
- Try
- Writeln(ALine);
- Finally
- FSkipTrim:=False;
- end;
- DescrWriteLinebreak;
- end;
- procedure TManWriter.DescrEndCode;
- begin
- NewLine;
- Writeln('');
- end;
- procedure TManWriter.DescrEndParagraph;
- begin
- NewLine;
- Writeln('');
- end;
- procedure TManWriter.NewListLevel(Initial : Integer);
- begin
- Inc(FListLevel);
- If (FListLevel<MaxListLevel) then
- FLists[FListLevel]:=0;
- NewLine;
- Writeln('.RS');
- end;
- procedure TManWriter.DecListLevel;
- begin
- NewLine;
- Writeln('.RE');
- If (FListLevel>0) then
- Dec(FListLevel)
- end;
- procedure TManWriter.DescrBeginOrderedList;
- begin
- NewListLevel(0);
- end;
- procedure TManWriter.DescrEndOrderedList;
- begin
- DecListLevel;
- end;
- procedure TManWriter.DescrBeginUnorderedList;
- begin
- NewListLevel(-1);
- end;
- procedure TManWriter.DescrEndUnorderedList;
- begin
- DecListlevel;
- end;
- procedure TManWriter.DescrBeginDefinitionList;
- begin
- NewListLevel(-2);
- end;
- procedure TManWriter.DescrEndDefinitionList;
- begin
- DecListLevel
- end;
- procedure TManWriter.DescrBeginListItem;
- begin
- WriteTP
- end;
- procedure TManWriter.DescrEndListItem;
- begin
- NewLine;
- end;
- procedure TManWriter.DescrBeginDefinitionTerm;
- begin
- WriteTP;
- Write('.B ');
- end;
- procedure TManWriter.DescrEndDefinitionTerm;
- begin
- NewLine;
- end;
- procedure TManWriter.DescrBeginDefinitionEntry;
- begin
- NewLine;
- end;
- procedure TManWriter.DescrEndDefinitionEntry;
- begin
- NewLine;
- end;
- procedure TManWriter.DescrBeginSectionTitle;
- begin
- Write('.SH ');
- end;
- procedure TManWriter.DescrBeginSectionBody;
- begin
- NewLine;
- end;
- procedure TManWriter.DescrEndSection;
- begin
- NewLine;
- end;
- procedure TManWriter.DescrBeginRemark;
- begin
- WriteTP;
- WriteB(SDocRemark);
- end;
- procedure TManWriter.DescrEndRemark;
- begin
- NewLine;
- end;
- procedure TManWriter.DescrBeginTable(ColCount: Integer; HasBorder: Boolean);
- begin
- NewLine;
- end;
- procedure TManWriter.DescrEndTable;
- begin
- NewLine;
- end;
- procedure TManWriter.DescrBeginTableCaption;
- begin
- NewLine;
- end;
- procedure TManWriter.DescrEndTableCaption;
- begin
- NewLine;
- end;
- procedure TManWriter.DescrBeginTableHeadRow;
- begin
- DescrBeginParagraph;
- end;
- procedure TManWriter.DescrEndTableHeadRow;
- begin
- DescrEndParagraph;
- end;
- procedure TManWriter.DescrBeginTableRow;
- begin
- DescrBeginParagraph;
- end;
- procedure TManWriter.DescrEndTableRow;
- begin
- DescrEndParagraph;
- end;
- procedure TManWriter.DescrBeginTableCell;
- begin
- // Do nothing
- end;
- procedure TManWriter.DescrEndTableCell;
- begin
- Writeln(#9);
- end;
- function TManWriter.InterPretOption(const Cmd, Arg: String): boolean;
- begin
- Result:=True;
- if (Cmd='--man-section') then
- ManSection:=Arg
- else if (Cmd='--man-description') then
- PackageDescr:=Arg
- else if (Cmd='--nounitprefix') then
- SkipUnitPrefix:=True
- else
- Result:=inherited InterPretOption(Cmd, Arg);
- end;
- Function TManWriter.GetDescrString(AContext: TPasElement; DescrNode: TDOMElement) : String;
- Var
- S : TStringStream;
- F : TStream;
- begin
- Result:='';
- if Assigned(DescrNode) then
- begin
- S:=TStringStream.Create('');
- Try
- F:=PushWriteContext(S);
- Try
- ConvertDescr(AContext, DescrNode, False);
- Result:=S.DataString;
- FInally
- PopWriteContext(F);
- end;
- finally
- S.FRee;
- end;
- end;
- end;
- { ---------------------------------------------------------------------
- Formatting routines
- ---------------------------------------------------------------------}
- procedure TManWriter.WriteTP;
- begin
- NewLine;
- Writeln('.TP');
- end;
- procedure TManWriter.WriteB(Const Msg : String);
- begin
- NewLine;
- Writeln('.B '+MSG);
- end;
- procedure TManWriter.WriteBI(Const Msg : String);
- begin
- NewLine;
- Writeln('.BI '+MSG);
- end;
- { ---------------------------------------------------------------------
- Sectioning routines
- ---------------------------------------------------------------------}
- procedure TManWriter.StartListing(Frames: Boolean);
- begin
- Writeln('');
- WriteB(SManDocListing);
- end;
- procedure TManWriter.StartManPage(AElement: TPasElement; ADocNode: TDocNode);
- begin
- StartManPage(ElementToManPage(AElement))
- end;
- procedure TManWriter.StartManPage(FN: String);
- begin
- FN:=LowerCase(FN+'.'+mansection);
- FStream:=TFileStream.Create(OutputDir+FN,fmCreate);
- end;
- procedure TManWriter.EndManPage;
- begin
- FreeAndNil(FStream);
- end;
- procedure TManWriter.StartSection(Const SectionName: String);
- begin
- NewLine;
- Writeln('');
- Writeln('.SH '+SectionName);
- end;
- procedure TManWriter.StartSubSection(Const SubSectionName: String);
- begin
- NewLine;
- Writeln('.SS '+SubSectionName);
- end;
- procedure TManWriter.PageTitle(Const ATitle,ASection,ASource,Amanual : String);
- Var
- D : String;
- begin
- D:=FormatDateTime('mmmm yyyy',Date);
- WritelnF('.TH "%s" "%s" "%s" "%s" "%s"',[ATitle,ASection,D,ASource,AManual]);
- end;
- procedure TManWriter.WriteManRef(Const ManPage : String; Comma : Boolean);
- begin
- If Comma then
- Writeln(Lowercase(Format('%s (%s),',[ManPage,ManSection])))
- else
- Writeln(Lowercase(Format('%s (%s)',[ManPage,ManSection])));
- end;
- Function TManWriter.ElementToManPage(APasElement : TPasElement) : String;
- Var
- E : TPasElement;
- begin
- E:=APasElement; // Make code more readable
- If (E is TPasPackage) or (E is TPasModule) then
- begin
- Result:=APasElement.Name;
- If (Length(Result)>0) and (Result[1]='#') then
- Delete(Result,1,1);
- end
- else if E is TTopicElement then
- begin
- // Todo : Check for package
- Result:=ModuleName+E.name;
- end
- else
- begin
- If Not SkipUnitprefix then
- Result:=ModuleName+'.';
- If (E.Parent<>Nil) and (not (E.Parent is TPasSection)) then
- begin
- If (E.Parent.Name<>'') then
- Result:=Result+E.Parent.Name;
- If (E is TPasProperty) or (E is TPasProcedure) or (E is TPasClassType) then
- Result:=Result+E.Name;
- end
- else
- begin
- If (E is TPasConst) then
- Result:=Result+SManConsts
- else If E is TPasVariable then
- Result:=Result+SManVars
- else If E is TPasClassType then
- Result:=Result+E.Name
- else If E is TPasType then
- Result:=Result+SManTypes
- else If E is TPasResString then
- Result:=Result+SManResStr
- else
- Result:=Result+E.Name;
- end;
- end;
- Result:=LowerCase(Result);
- end;
- procedure TManWriter.WriteManRef(APasElement : TPasElement; Comma : Boolean);
- begin
- WriteManRef(ElementToManPage(APasElement),Comma);
- end;
- procedure TManWriter.WriteModuleSeealso(Comma : Boolean);
- Var
- HC,HT,HV,HR : Boolean;
- begin
- HC:=Module.InterfaceSection.Consts.Count>0;
- HR:=Module.InterfaceSection.ResStrings.Count>0;
- HV:=Module.InterfaceSection.Variables.Count>0;
- HT:=Module.InterfaceSection.Types.Count>0;
- WriteManRef(ModuleName,HC or HR or HV or HT or comma);
- if HC then
- WriteManRef(ModuleName+'.'+SManConsts,HR or HV or HT or comma);
- if HR then
- WriteManRef(ModuleName+'.'+SManResStr, HV or HT or comma);
- if HV then
- WriteManRef(ModuleName+'.'+SManVars, HT or comma);
- if HT then
- WriteManRef(ModuleName+'.'+SManTypes,comma);
- end;
- procedure TManWriter.WriteSeeAlso(ADocNode: TDocNode; Comma: Boolean);
- var
- Node: TDOMNode;
- s: String;
- begin
- if Not (Assigned(ADocNode) and Assigned(ADocNode.SeeAlso)) then
- Exit;
- Node := ADocNode.SeeAlso.FirstChild;
- while Assigned(Node) do
- begin
- if IsLinkNode(Node) then
- begin
- S:=TDomElement(Node)['id'];
- WriteManRef(S,(Node.NextSibling<>Nil) or Comma);
- end;
- Node:=Node.NextSibling;
- end;
- end;
- function TManWriter.ConstValue(ConstDecl: TPasConst): String;
- begin
- if Assigned(ConstDecl) then
- Result := ConstDecl.ClassName
- else
- Result := '<nil>';
- end;
- procedure TManWriter.WriteExample(ADocNode: TDocNode);
- var
- Example: TDOMElement;
- S : string;
- begin
- S:='';
- if Assigned(ADocNode) then
- begin
- Example := ADocNode.FirstExample;
- If Assigned(Example) then
- begin
- StartSection(SManDocExamples);
- while Assigned(Example) do
- begin
- s:=Engine.GetExampleFileName(Example);
- if (s<>'') then
- WriteExampleFile(S);
- DescrEndParaGraph;
- Repeat
- Example := TDomElement(Example.NextSibling);
- until (Example=Nil) or ((Example.NodeType=ELEMENT_NODE) and (Example.NodeName='example'));
- end;
- end;
- end;
- end;
- procedure TManWriter.WriteExampleFile(FN : String);
- Var
- L : TStringList;
- I : Integer;
- begin
- WriteBI(SDocExample+' \- '+ExtractFileName(FN));
- Writeln('');
- DescrWriteLineBreak;
- If (FN<>'') and FileExists(FN) then
- begin
- L:=TStringList.Create;
- Try
- L.LoadFromFile(FN);
- For I:=0 to L.Count-1 do
- DescrWriteCodeLine(L[i]);
- finally
- L.Free;
- end;
- end;
- end;
- { ---------------------------------------------------------------------
- Actual man page writing
- ---------------------------------------------------------------------}
- procedure TManWriter.WriteDoc;
- var
- i : Integer;
- L : TstringList;
- DocNode : TDocNode;
- begin
- PackageName := LowerCase(Copy(Package.Name, 2, 255));
- If (Engine.Output<>'') then
- OutputDir:=Engine.Output
- else
- OutputDir:=PackageName+'.man';
- If not ForceDirectories(OutputDir) then
- FPDocError(SErrCouldNotCreateOutputDir,[OutputDir]);
- OutputDir:=IncludeTrailingPathDelimiter(OutputDir);
- If (ManSection='') then
- ManSection:=IntToStr(DefaultManSection);
- WritePackagePage;
- L:=TStringList.Create;
- Try
- // Sort modules.
- For I:=0 to Package.Modules.Count-1 do
- L.AddObject(TPasModule(Package.Modules[i]).Name,TPasModule(Package.Modules[i]));
- L.Sorted:=True;
- for i:=0 to L.Count - 1 do
- ProcessModule(TPasModule(L.Objects[i]));
- Finally
- L.Free;
- end;
- end;
- { ---------------------------------------------------------------------
- Package man page
- ---------------------------------------------------------------------}
- Procedure TManWriter.WritePackagePage;
- var
- D,DocNode: TDocNode;
- M : TPasModule;
- I : Integer;
- L : TStringList;
- begin
- DocNode:=Engine.FindDocNode(Package);
- If (PackageDescr='') then
- PackageDescr:=GetDescrString(Package,DocNode.ShortDescr);
- StartManPage(Package,DocNode);
- Try
- PageTitle(PackageName,ManSection,PackageName,PackageDescr);
- StartSection(SManDocName);
- Writeln(PackageName+' \- '+PackageDescr);
- if Assigned(DocNode) and not IsDescrNodeEmpty(DocNode.Descr) then
- begin
- StartSection(SDocDescription);
- WriteDescr(Package, DocNode.Descr);
- end;
- StartSection(SManDocPackageUnits);
- L:=TStringList.Create;
- Try
- For I:=0 to Package.Modules.Count-1 do
- L.AddObject(TPasModule(Package.Modules[i]).Name,TPasModule(Package.Modules[i]));
- L.Sorted:=True;
- for i:=0 to L.Count - 1 do
- begin
- WriteTP;
- WriteB(L[i]);
- M:=TPasModule(L.Objects[i]);
- D:=Engine.FindDocNode(M);
- WriteLn(GetDescrString(M,D.ShortDescr))
- end;
- StartSection(SDocSeeAlso);
- WriteSeeAlso(DocNode,True);
- WriteTopicRefs(DocNode);
- for i:=0 to L.Count - 1 do
- WriteManRef(TPasModule(L.Objects[i]),I<L.Count-1);
- Finally
- L.Free;
- end;
- Finally
- EndManPage;
- end;
- ProcessTopics(DocNode,True);
- end;
- { ---------------------------------------------------------------------
- Topic support
- ---------------------------------------------------------------------}
- Procedure TManWriter.WriteTopicRefs(DocNode : TDocNode);
- Var
- Node : TDocNode;
- begin
- If Not Assigned(DocNode) then
- Exit;
- Node:=DocNode.FirstChild;
- While Assigned(Node) do
- begin
- If Node.TopicNode then
- WriteManRef(DocNode.Name,Node.NextSibling<>Nil);
- Node:=Node.NextSibling;
- end;
- end;
- Procedure TManWriter.ProcessTopics(DocNode : TDocNode; Subs : Boolean);
- Var
- Node,SubNode : TDocNode;
- begin
- If Not Assigned(DocNode) then
- Exit;
- Node:=DocNode.FirstChild;
- While Assigned(Node) do
- begin
- If Node.TopicNode then
- begin
- WriteTopicPage(DocNode,Node);
- If Subs then
- begin
- SubNode:=DocNode.FirstChild;
- While Assigned(SubNode) do
- If SubNode.TopicNode then
- WriteTopicPage(Node,SubNode);
- end;
- end;
- Node:=Node.NextSibling;
- end;
- end;
- Procedure TManWriter.WriteTopicPage(Parent,Node : TDocNode);
- Var
- Element : TTopicElement;
- begin
- Element:=FindTopicElement(Node);
- If Not Assigned(Element) then
- Exit;
- StartManPage(Element,Node) ;
- Try
- PageTitle(Node.Name,ManSection,PackageName,PackageDescr);
- StartSection(SManDocName);
- Writeln(Node.Name+' \- '+GetDescrString(Element,Node.ShortDescr));
- StartSection(SManDocDescription);
- If Assigned(Node.Descr) then
- WriteDescr(Element,Node.Descr);
- StartSection(SManDocSeeAlso);
- WriteSeeAlso(Node,True);
- WriteTopicRefs(Parent);
- WriteTopicRefs(Node);
- Finally
- EndManPage;
- end;
- end;
- { ---------------------------------------------------------------------
- Module man pages
- ---------------------------------------------------------------------}
- procedure TManWriter.ProcessModule(AModule : TPasModule);
- begin
- With AModule do
- begin
- Module:=AModule;
- ModuleName:=Name;
- With InterfaceSection do
- begin
- SortElementList(Declarations);
- SortElementList(Types);
- SortElementList(Consts);
- SortElementList(Classes);
- SortElementList(Functions);
- SortElementList(Variables);
- SortElementList(ResStrings);
- end;
- WriteUnitPage(AModule);
- WriteUnitResourceStrings(InterfaceSection);
- WriteUnitConsts(InterfaceSection);
- WriteUnitTypes(InterfaceSection);
- WriteUnitVars(InterfaceSection);
- WriteUnitClasses(InterfaceSection);
- WriteUnitFunctionsAndProcedures(InterfaceSection);
- end;
- end;
- procedure TManWriter.WriteUnitPage(AModule : TPasModule);
- Var
- DocNode : TDocNode;
- begin
- DocNode:=Engine.FindDocNode(AModule);
- StartManPage(AModule,DocNode);
- Try
- PageTitle(AModule.Name,ManSection,PackageName,PackageDescr);
- StartSection(SManDocName);
- Writeln(DocNode.Name+' \- '+GetDescrString(AModule,DocNode.ShortDescr));
- if Assigned(DocNode) and not IsDescrNodeEmpty(DocNode.Descr) then
- begin
- StartSection(SManDocDescription);
- WriteDescr(AModule.Parent, DocNode.Descr);
- end;
- WriteUnitUsesOverview(AModule.InterfaceSection);
- WriteUnitClassesOverView(AModule.InterfaceSection);
- WriteUnitFunctionsAndProceduresOverView(AModule.InterfaceSection);
- StartSection(SManDocSeealso);
- WriteModuleSeeAlso(False);
- finally
- EndManPage;
- end;
- end;
- procedure TManWriter.WriteUnitUsesOverview(ASection: TPasSection);
- var
- i: Integer;
- UnitRef: TPasType;
- DocNode: TDocNode;
- begin
- if ASection.UsesList.Count > 0 then
- begin
- StartSection(SManDocUsedUnits);
- for i := 0 to ASection.UsesList.Count - 1 do
- begin
- UnitRef := TPasType(ASection.UsesList[i]);
- WriteTP;
- WriteB(UnitRef.Name);
- DocNode := Engine.FindDocNode(UnitRef);
- If Assigned(DocNode) then
- WriteDescr(UnitRef,DocNode.ShortDescr)
- end;
- end;
- end;
- { ---------------------------------------------------------------------
- Classes man pages
- ---------------------------------------------------------------------}
- procedure TManWriter.WriteUnitClassesOverview(ASection: TPasSection);
- var
- i : Integer;
- DocNode : TDocNode;
- ClassDecl : TPasClassType;
- begin
- // Overview page
- if ASection.Classes.Count > 0 then
- begin
- StartSection(SManDocClasses);
- for i := 0 to ASection.Classes.Count - 1 do
- begin
- ClassDecl:=TPasClassType(ASection.Classes[i]);
- WriteTP;
- WriteB(ClassDecl.Name);
- DocNode:=Engine.FindDocNode(ClassDecl);
- If Assigned(DocNode) then
- WriteDescr(ClassDecl,DocNode.ShortDescr);
- end;
- end;
- end;
- procedure TManWriter.WriteUnitClasses(ASection: TPasSection);
- var
- i: Integer;
- begin
- if (ASection.Classes.Count > 0) then
- begin
- for i := 0 to ASection.Classes.Count - 1 do
- WriteClassPage(TPasClassType(ASection.Classes[i]));
- end;
- end;
- procedure TManWriter.WriteClassPage(ClassDecl: TPasClassType);
- var
- DocNode: TDocNode;
- begin
- DocNode:=Engine.FindDocNode(ClassDecl);
- StartManPage(ClassDecl,DocNode);
- Try
- PageTitle(ClassDecl.Name,ManSection,PackageName,PackageDescr);
- StartSection(SManDocName);
- Write(ClassDecl.Name);
- DocNode := Engine.FindDocNode(ClassDecl);
- If Assigned(DocNode) then
- begin
- if not IsDescrNodeEmpty(DocNode.ShortDescr) then
- begin
- write(' \- ');
- WriteDescr(ClassDecl,DocNode.ShortDescr);
- end;
- if Not (IsDescrNodeEmpty(DocNode.Descr)
- and IsDescrNodeEmpty(DocNode.ShortDescr)) then
- begin
- StartSection(SDocDescription);
- WriteDescr(ClassDecl);
- end;
- end;
- // Write method overview
- WriteClassMethodOverView(ClassDecl);
- // Write Property Overview;
- WriteClassPropertyOverView(ClassDecl);
- Finally
- EndManPage;
- end
- end;
- procedure TManWriter.WriteClassPropertyOverview(ClassDecl : TPasClassType);
- var
- Member: TPasElement;
- i: Integer;
- A: String;
- DocNode: TDocNode;
- List : TStringList;
- begin
- // Write property overview
- List:=TStringList.Create;
- Try
- for i := 0 to ClassDecl.Members.Count - 1 do
- begin
- Member := TPasElement(ClassDecl.Members[i]);
- With Member do
- if InheritsFrom(TPasProperty) and SHowMember(Member) then
- List.AddObject(Member.Name,Member)
- end;
- List.Sorted:=True;
- If (List.Count>0) then
- begin
- StartSection(SDocPropertyOverview);
- For I:=0 to List.Count-1 do
- begin
- Member:=TPasElement(List.objects[i]);
- WriteTP;
- A:='';
- if Length(TPasProperty(Member).ReadAccessorName) > 0 then
- a := a + 'r';
- if Length(TPasProperty(Member).WriteAccessorName) > 0 then
- a := a + 'w';
- if Length(TPasProperty(Member).StoredAccessorName) > 0 then
- a := a + 's';
- WriteBI(Member.Name+' '+A);
- DocNode := Engine.FindDocNode(Member);
- If Assigned(DocNode) then
- WriteDescr(Member, DocNode.ShortDescr)
- end;
- end;
- Finally
- List.Free;
- end;
- end;
- { ---------------------------------------------------------------------
- Resource strings man page
- ---------------------------------------------------------------------}
- procedure TManWriter.WriteUnitResourceStrings(ASection: TPasSection);
- var
- ResStrDecl: TPasResString;
- i: Integer;
- begin
- if ASection.ResStrings.Count > 0 then
- begin
- StartManpage(ModuleName+'.'+SManResStr);
- Try
- PageTitle(Modulename,ManSection,PackageName,PackageDescr);
- StartSection(SManDocName);
- Writeln(ModuleName+' \- '+SDocResStrings);
- StartSection(SManDocResourceStrings);
- Writeln('');
- for i := 0 to ASection.ResStrings.Count - 1 do
- begin
- ResStrDecl := TPasResString(ASection.ResStrings[i]);
- StartSubSection(ResStrDecl.Name);
- DescrWriteCodeLine(EscapeText(ResStrDecl.GetDeclaration(False)));
- end;
- StartSection(SDocSeeAlso);
- WriteModuleSeealso(False);
- Finally
- EndManPage;
- end;
- end;
- end;
- { ---------------------------------------------------------------------
- Constants man page
- ---------------------------------------------------------------------}
- procedure TManWriter.WriteUnitConsts(ASection: TPasSection);
- var
- i: Integer;
- ConstDecl: TPasConst;
- DocNode: TDocNode;
- begin
- if ASection.Consts.Count > 0 then
- begin
- StartManpage(ModuleName+'.'+SManConsts);
- Try
- PageTitle(Modulename,ManSection,PackageName,PackageDescr);
- StartSection(SManDocName);
- Writeln(ModuleName+' \- '+SDocConstants);
- StartSection(SManDocConstants);
- for i := 0 to ASection.Consts.Count - 1 do
- begin
- ConstDecl := TPasConst(ASection.Consts[i]);
- StartSubSection(ConstDecl.Name);
- DescrWriteCodeLine(EscapeText(ConstDecl.GetDeclaration(True)));
- DocNode:=Engine.FindDocNode(ConstDecl);
- WriteDescr(ConstDecl,DocNode);
- end;
- StartSection(SDocSeeAlso);
- WriteModuleSeealso(False);
- Finally
- EndManPage;
- end;
- end;
- end;
- { ---------------------------------------------------------------------
- Types man page
- ---------------------------------------------------------------------}
- procedure TManWriter.WriteUnitTypes(ASection: TPasSection);
- var
- i: Integer;
- TypeDecl: TPasType;
- DocNode : TDocNode;
- begin
- if ASection.Types.Count > 0 then
- begin
- StartManpage(ModuleName+'.'+SManTypes);
- Try
- PageTitle(Modulename,ManSection,PackageName,PackageDescr);
- StartSection(SManDocName);
- Writeln(ModuleName+' \- '+SDocTypes);
- StartSection(SManDocTypes);
- for i := 0 to ASection.Types.Count - 1 do
- begin
- TypeDecl := TPasType(ASection.Types[i]);
- StartSubsection(TypeDecl.Name);
- DescrWriteCodeLine(EscapeText(TypeDecl.GetDeclaration(True)));
- DocNode:=Engine.FindDocNode(TypeDecl);
- If TypeDecl is TPasEnumType then
- WriteEnumElements(TypeDecl as TPasEnumType);
- WriteDescr(TypeDecl,DocNode);
- end;
- StartSection(SDocSeeAlso);
- WriteModuleSeeAlso(False);
- Finally
- EndManPage;
- end;
- end;
- end;
- procedure TManWriter.WriteEnumElements(TypeDecl : TPasEnumType);
- Var
- EV : TPasEnumValue;
- I : Integer;
- DocNode : TDocNode;
- begin
- With TypeDecl do
- begin
- SortElementList(Values);
- Writeln(EscapeText(Format(SDocValuesForEnum,[TypeDecl.Name])));
- Try
- For I:=0 to Values.Count-1 do
- begin
- EV:=TPasEnumValue(Values[i]);
- WriteTP;
- WriteB(EscapeText(EV.Name));
- DocNode := Engine.FindDocNode(EV);
- if Assigned(DocNode) and (not IsDescrNodeEmpty(DocNode.ShortDescr)) then
- WriteDescr(EV,DocNode.ShortDescr);
- end;
- Finally
- NewLine;
- end;
- end;
- end;
- { ---------------------------------------------------------------------
- Variables man page
- ---------------------------------------------------------------------}
- procedure TManWriter.WriteUnitVars(ASection: TPasSection);
- var
- VarDecl: TPasVariable;
- i: Integer;
- DocNode : TDocNode;
- begin
- if ASection.Variables.Count > 0 then
- begin
- StartManpage(ModuleName+'.'+SManVars);
- Try
- PageTitle(Modulename,ManSection,PackageName,PackageDescr);
- StartSection(SManDocName);
- Writeln(ModuleName+' \- '+SDocVariables);
- StartSection(SManDocVariables);
- for i := 0 to ASection.Variables.Count - 1 do
- begin
- VarDecl := TPasVariable(ASection.Variables[i]);
- StartSubSection(VarDecl.Name);
- DescrWriteCodeLine(EscapeText(VarDecl.GetDeclaration(True)));
- DocNode:=Engine.FindDocNode(VarDecl);
- WriteDescr(VarDecl,DocNode);
- end;
- StartSection(SDocSeeAlso);
- WriteModuleSeeAlso(False);
- Finally
- EndManPage;
- end;
- end;
- end;
- { ---------------------------------------------------------------------
- Procedure/Function/Method man page
- ---------------------------------------------------------------------}
- procedure TManWriter.WriteUnitFunctionsAndProceduresOverview(ASection: TPasSection);
- var
- i : Integer;
- DocNode : TDocNode;
- PDecl : TPasProcedureBase;
- begin
- // Overview page
- if ASection.Functions.Count > 0 then
- begin
- StartSection(SManDocFunctions);
- for i := 0 to ASection.Functions.Count - 1 do
- begin
- PDecl:=TPasProcedureBase(ASection.Functions[i]);
- WriteTP;
- WriteB(PDecl.Name);
- DocNode:=Engine.FindDocNode(PDecl);
- If Assigned(DocNode) then
- WriteDescr(PDecl,DocNode.ShortDescr);
- end;
- end;
- end;
- procedure TManWriter.WriteUnitFunctionsAndProcedures(ASection: TPasSection);
- var
- i : Integer;
- begin
- // Pages for all identifiers.
- for i := 0 to ASection.Functions.Count - 1 do
- WriteProcedurePage(TPasProcedure(ASection.Functions[i]));
- end;
- procedure TManWriter.WriteProcedurePage(ProcDecl : TPasProcedureBase);
- var
- DocNode: TDocNode;
- OP : TPasOverloadedProc;
- i : integer;
- D,N : String;
- begin
- DocNode := Engine.FindDocNode(ProcDecl);
- StartManpage(ProcDecl,DocNode);
- Try
- PageTitle(ProcDecl.name,ManSection,PackageName,PackageDescr);
- if Assigned(DocNode) then
- D:=GetDescrString(ProcDecl,DocNode.ShortDescr);
- // Name
- StartSection(SManDocName);
- Writeln(N+' \- '+D);
- // Declaration
- StartSection(SManDocSynopsis);
- if ProcDecl is TPasOverloadedProc then
- begin
- OP:=TPasOverloadedProc(ProcDecl);
- for i := 0 to OP.Overloads.Count - 1 do
- begin
- DescrWriteCodeLine(TPasProcedure(OP.Overloads[i]).GetDeclaration(True));
- end;
- end
- else
- DescrWriteCodeLine(ProcDecl.GetDeclaration(True));
- // Visibility
- If Assigned(ProcDecl.Parent) then
- begin
- StartSection(SManDocVisibility);
- Writeln(VisibilityNames[ProcDecl.Visibility])
- end;
- // Arguments, if present.
- If ProcDecl is TPasProcedure then
- AppendProcedureArgsSection(TPasProcedure(ProcDecl).ProcType);
- // Description
- if Assigned(DocNode) then
- begin
- if Assigned(DocNode.Descr) then
- begin
- StartSection(SManDocDescription);
- WriteDescr(ProcDecl,DocNode.Descr);
- end;
- // Errors
- if Assigned(DocNode) and Assigned(DocNode.ErrorsDoc) then
- begin
- StartSection(SManDocErrors);
- WriteDescr(ProcDecl, DocNode.ErrorsDoc);
- end;
- end;
- // Arguments, if present.
- If ProcDecl is TPasFunction then
- AppendProcedureArgsSection(TPasFunction(ProcDecl).ProcType);
- WriteExample(DocNode);
- StartSection(SManDocSeeAlso);
- WriteModuleSeeAlso(True);
- WriteSeeAlso(DocNode,False);
- Finally
- EndManPage;
- end;
- end;
- procedure TManWriter.AppendProcedureArgsSection(Element: TPasProcedureType);
- var
- IsFirst: Boolean;
- DocNode: TDocNode;
- i: Integer;
- Arg: TPasArgument;
- begin
- If Not Assigned(Element) then
- exit;
- IsFirst := True;
- for i := 0 to Element.Args.Count - 1 do
- begin
- Arg := TPasArgument(Element.Args[i]);
- DocNode:=Engine.FindDocNode(Arg);
- if Assigned(DocNode) and (Not IsDescrNodeEmpty(DocNode.ShortDescr)) then
- begin
- if IsFirst then
- begin
- IsFirst:=False;
- StartSection(SManDocArguments);
- end;
- WriteTP;
- WriteB(Arg.Name);
- WriteDescr(Arg,DocNode.ShortDescr);
- end;
- end;
- end;
- procedure TManWriter.AppendFunctionResultSection(Element: TPasFunctionType);
- Var
- ResultEl: TPasResultElement;
- DocNode: TDocNode;
- begin
- If Not Assigned(Element) then
- exit;
- ResultEl := TPasFunctionType(Element).ResultEl;
- DocNode := Engine.FindDocNode(ResultEl);
- If Assigned(DocNode) then
- begin
- if IsDescrNodeEmpty(DocNode.Descr) or not IsDescrNodeEmpty(DocNode.ShortDescr) then
- begin
- StartSection(SManDocResult);
- WriteDescr(ResultEl,DocNode);
- end;
- end;
- end;
- { ---------------------------------------------------------------------
- Property man page
- ---------------------------------------------------------------------}
- procedure TManWriter.WritePropertyPage(PropDecl : TPasProperty);
- var
- DocNode: TDocNode;
- N,D: String;
- begin
- DocNode := Engine.FindDocNode(PropDecl);
- StartManpage(PropDecl,DocNode);
- Try
- PageTitle(PropDecl.Name,ManSection,PackageName,PackageDescr);
- if Assigned(DocNode) then
- D:=GetDescrString(PropDecl,DocNode.ShortDescr);
- // Name
- StartSection(SManDocName);
- Writeln(N+' \- '+D);
- // Declaration
- StartSection(SManDocSynopsis);
- WriteLn(PropDecl.GetDeclaration(True));
- // Visibility
- If Assigned(PropDecl.Parent) then
- begin
- StartSection(SManDocVisibility);
- Writeln(VisibilityNames[PropDecl.Visibility])
- end;
- StartSection(SManDocAccess);
- D:='';
- If Length(PropDecl.ReadAccessorName) > 0 then
- D:='Read';
- if Length(PropDecl.WriteAccessorName) > 0 then
- begin
- If D<>'' then
- D:=D+',';
- D:=D+'Write';
- end;
- Writeln(D);
- if Assigned(DocNode) then
- begin
- // Description
- if Assigned(DocNode.Descr) then
- begin
- StartSection(SManDocDescription);
- WriteDescr(PropDecl,DocNode.Descr);
- end;
- // Errors
- if Assigned(DocNode) and Assigned(DocNode.ErrorsDoc) then
- begin
- StartSection(SManDocErrors);
- WriteDescr(PropDecl, DocNode.ErrorsDoc);
- end;
- WriteExample(DocNode);
- WriteSeeAlso(DocNode,False);
- end;
- Finally
- EndManPage;
- end;
- end;
- Function CompareElements(P1,P2 : Pointer) : Integer;
- begin
- Result:=CompareText(TPasElement(P1).Name,TPasElement(P2).Name);
- end;
- procedure TManWriter.SortElementList(List : TList);
- begin
- List.Sort(@CompareElements);
- end;
- procedure TManWriter.WriteCommentLine;
- begin
- WriteComment('-------------------------------------------------------');
- end;
- procedure TManWriter.WriteComment(Comment : String);
- begin
- Writeln('." '+Comment);
- end;
- class function TManWriter.FileNameExtension: String;
- begin
- Result:=IntToStr(DefaultManSection);
- end;
- procedure TManWriter.WriteClassMethodOverview(ClassDecl: TPasClassType);
- var
- Member : TPasElement;
- i : Integer;
- DocNode : TDocNode;
- List : TStringList;
- begin
- List:=TStringList.Create;
- Try
- GetMethodList(ClassDecl,List);
- If List.Count>0 then
- begin
- StartSection(SManDocMethods);
- For I:=0 to List.Count-1 do
- begin
- Member:=TPasElement(List.Objects[i]);
- WriteTP;
- WriteB(EscapeText(Member.Name));
- DocNode := Engine.FindDocNode(Member);
- If Assigned(DocNode) then
- WriteDescr(Member, DocNode.ShortDescr)
- end;
- end;
- Finally
- List.Free;
- end;
- end;
- Class procedure TManWriter.Usage(List: TStrings);
- begin
- List.add('--nounitprefix');
- List.Add(SManUsageNoUnitPrefix);
- List.add('--man-section=ASection');
- List.Add(SManUsageManSection);
- List.Add('--man-description=descr');
- List.Add(SManUsagePackageDescription);
- end;
- initialization
- // Do not localize.
- RegisterWriter(TMANWriter,'man',SManUsageWriterDescr);
- finalization
- UnRegisterWriter('man');
- end.
|