diff options
| author | marco <marco@3ad0048d-3df7-0310-abae-a5850022a9f2> | 2009-12-29 23:33:34 +0000 |
|---|---|---|
| committer | marco <marco@3ad0048d-3df7-0310-abae-a5850022a9f2> | 2009-12-29 23:33:34 +0000 |
| commit | 4979c5bf4424c8a9e57098a31b7c9ea66bacb234 (patch) | |
| tree | 32050f08c98aaf2b2605050fcc13ed1d24646b79 /packages/chm | |
| parent | 80784968833c227101a6908dab492029534e034c (diff) | |
| download | fpc-4979c5bf4424c8a9e57098a31b7c9ea66bacb234.tar.gz | |
* Am now able to generate helpfiles with contextids from xml via chmfilewriter. XML format needs some rethinking though.
git-svn-id: http://svn.freepascal.org/svn/fpc/trunk@14499 3ad0048d-3df7-0310-abae-a5850022a9f2
Diffstat (limited to 'packages/chm')
| -rw-r--r-- | packages/chm/src/chmfilewriter.pas | 55 | ||||
| -rw-r--r-- | packages/chm/src/chmwriter.pas | 15 |
2 files changed, 50 insertions, 20 deletions
diff --git a/packages/chm/src/chmfilewriter.pas b/packages/chm/src/chmfilewriter.pas index 5da45aed63..bf6c860807 100644 --- a/packages/chm/src/chmfilewriter.pas +++ b/packages/chm/src/chmfilewriter.pas @@ -59,6 +59,7 @@ type procedure SaveToFile(AFileName: String); procedure WriteChm(AOutStream: TStream); function ProjectDir: String; + procedure AddFileWithContext(contextid:integer;filename:ansistring;contextname:ansistring=''); // though stored in the project file, it is only there for the program that uses the unit // since we actually write to a stream property OutputFileName: String read FOutputFileName write FOutputFileName; @@ -77,17 +78,16 @@ type property OnProgress: TChmProgressCB read FOnProgress write FOnProgress; end; -implementation - -uses XmlCfg, chmsitemap; - -Type TChmContextNode = Class URLName : AnsiString; ContextNumber : Integer; ContextName : AnsiString; End; +implementation + +uses XmlCfg, chmsitemap; + { TChmProject } function TChmProject.GetData(const DataName: String; out PathInChm: String; out @@ -129,7 +129,7 @@ begin IndexSitemap := TChmSiteMap.Create(stIndex); indexSitemap.LoadFromStream(IndexStream); Writer.AppendBinaryIndexFromSiteMap(IndexSitemap,False); - IndexSitemap.Free; + IndexSitemap.Free; end; IndexStream.Free; end; @@ -162,12 +162,13 @@ begin FFiles.Free; inherited Destroy; end; + procedure TChmProject.LoadFromFile(AFileName: String); var Cfg: TXMLConfig; FileCount: Integer; I : Integer; - nd : TChmContextNode; + nd : TChmContextNode; begin Cfg := TXMLConfig.Create(nil); Cfg.Filename := AFileName; @@ -175,12 +176,12 @@ begin Files.Clear; FileCount := Cfg.GetValue('Files/Count/Value', 0); - for I := 0 to FileCount-1 do + for I := 0 to FileCount-1 do begin - nd:=TChmContextNode.Create; + nd:=TChmContextNode.Create; nd.urlname:=Cfg.GetValue('Files/FileName'+IntToStr(I)+'/Value',''); nd.contextnumber:=Cfg.GetValue('Files/FileName'+IntToStr(I)+'/ContextNumber',0); - nd.contextname:=Cfg.GetValue('Files/FileName'+IntToStr(I)+'/ContextName',''); + nd.contextname:=Cfg.GetValue('Files/FileName'+IntToStr(I)+'/ContextName',''); Files.AddObject(nd.urlname,nd); end; IndexFileName := Cfg.GetValue('Files/IndexFile/Value',''); @@ -197,6 +198,33 @@ begin Cfg.Free; end; +procedure TChmProject.AddFileWithContext(contextid:integer;filename:ansistring;contextname:ansistring=''); +var x : integer; + nd : TChmContextNode; +begin + x:=files.indexof(filename); + if x=-1 then + begin + nd:=TChmContextNode.Create; + nd.urlname:=filename; + nd.contextnumber:=contextid; + nd.contextname:=contextname; + Files.AddObject(nd.urlname,nd); + end + else + begin + nd:=TChmContextNode(files.objects[x]); + if not assigned(nd) then + begin + nd:=TChmContextNode.Create; + nd.urlname:=filename; + files.objects[x]:=nd; + end; + nd.contextnumber:=contextid; + nd.contextname:=contextname; + end; +end; + procedure TChmProject.SaveToFile(AFileName: String); var Cfg: TXMLConfig; @@ -208,7 +236,7 @@ begin Cfg.Filename := FileName; Cfg.Clear; Cfg.SetValue('Files/Count/Value', Files.Count); - for I := 0 to Files.Count-1 do + for I := 0 to Files.Count-1 do begin nd:=TChmContextNode(files.objects[i]); Cfg.SetValue('Files/FileName'+IntToStr(I)+'/Value', Files.Strings[I]); @@ -216,7 +244,7 @@ begin begin Cfg.SetValue('Files/FileName'+IntToStr(I)+'/ContextNumber', nd.contextnumber); Cfg.SetValue('Files/FileName'+IntToStr(I)+'/ContextName', nd.contextname); - end; + end; end; Cfg.SetValue('Files/IndexFile/Value', IndexFileName); Cfg.SetValue('Files/TOCFile/Value', TableOfContentsFileName); @@ -268,7 +296,8 @@ begin for i:=0 to files.count-1 do begin nd:=TChmContextNode(files.objects[i]); - Writer.AddContext(nd.ContextNumber,files[i]); + if assigned(nd) and (nd.contextnumber<>0) then + Writer.AddContext(nd.ContextNumber,files[i]); end; // and write! diff --git a/packages/chm/src/chmwriter.pas b/packages/chm/src/chmwriter.pas index 6a3afe8c17..4a770123f1 100644 --- a/packages/chm/src/chmwriter.pas +++ b/packages/chm/src/chmwriter.pas @@ -204,7 +204,7 @@ const procedure logentry(s:string); begin Writeln(s); - flush(stdout); + flush(stdout); end; {$endif} {$I chmobjinstconst.inc} @@ -1883,17 +1883,17 @@ Var i : Integer; EntryBytes : Integer; Hdr : TBTreeHeader; TreeDepth : Integer; - + {$ifdef binindex} procedure printloopvars(i:integer); -begin +begin Writeln('location :' ,i, ' blocknr :', blocknr,' level:',TreeDepth); Writeln('blockn length: ',length(blockn),' indexblocknr: ',indexblocknr,' blockind ',blockind); Writeln('blocknplus1 length: ',length(blocknplus1),' blocknplusindex:',blocknplusindex,' entries:',blocknplusentries); flush(stdout); end; -{$endif} +{$endif} begin IndexStream:=TMemoryStream.Create; indexstream.size:=sizeof(TBTreeHeader); @@ -1955,7 +1955,7 @@ begin {$endif} FinalizeIndexBlockN(@blockn[indexblocknr][0],blockind,blockentries); // also increasing indexblocknr inc(IndexBlockNr); - end; + end; {$ifdef binindex} writeln('binindex: listingblocks : '+inttostr(listingblocks),' indexblocks: ',indexblocknr,' entries:',blockentries); {$endif} @@ -2058,11 +2058,11 @@ procedure stadd(fn:string;stream:TStream); begin Stream.Position:=0; - if CHW then + if CHW then fn:=uppercase(fn); {$ifdef binindex} logentry('before append '+fn); - {$endif} + {$endif} AddStreamToArchive(fn,'/$WWKeywordLinks/',stream,True); end; @@ -2090,6 +2090,7 @@ var Offset: DWord; begin if FContextStream = nil then begin + FContextStream:=TMemoryStream.Create; // #IVB starts with a dword which is the size of the stream - sizeof(dword) FContextStream.WriteDWord(0); // we will update this when we write the file to the final stream |
