Browse Source

+ added lastsynonym and InNameAnchor fields to TCustomHTMLLinkScanner
these allow to eliminate double index entries pointing to the same
html file location (which had two different names).

pierre 23 years ago
parent
commit
63ec8ab5bf
2 changed files with 96 additions and 10 deletions
  1. 8 3
      ide/whtmlhlp.pas
  2. 88 7
      ide/whtmlscn.pas

+ 8 - 3
ide/whtmlhlp.pas

@@ -1192,11 +1192,11 @@ begin
     begin
     begin
       LS^.SetBaseDir(DirOf(IndexFileName));
       LS^.SetBaseDir(DirOf(IndexFileName));
       for I:=0 to LS^.GetDocumentCount-1 do
       for I:=0 to LS^.GetDocumentCount-1 do
-       for J:=0 to LS^.GetDocumentAliasCount(I)-1 do
         begin
         begin
           TLI:=TopicLinks^.AddItem(LS^.GetDocumentURL(I));
           TLI:=TopicLinks^.AddItem(LS^.GetDocumentURL(I));
           TLI:=EncodeHTMLCtx(ID,TLI+1);
           TLI:=EncodeHTMLCtx(ID,TLI+1);
-          IndexEntries^.Insert(NewIndexEntry(FormatAlias(LS^.GetDocumentAlias(I,J)),ID,TLI));
+          for J:=0 to LS^.GetDocumentAliasCount(I)-1 do
+            IndexEntries^.Insert(NewIndexEntry(FormatAlias(LS^.GetDocumentAlias(I,J)),ID,TLI));
         end;
         end;
       Dispose(LS, Done);
       Dispose(LS, Done);
     end;
     end;
@@ -1233,7 +1233,12 @@ end;
 END.
 END.
 {
 {
   $Log$
   $Log$
-  Revision 1.4  2002-04-11 07:04:23  pierre
+  Revision 1.5  2002-04-23 09:55:22  pierre
+    + added lastsynonym and InNameAnchor fields to TCustomHTMLLinkScanner
+      these allow to eliminate double index entries pointing to the same
+      html file location (which had two different names).
+
+  Revision 1.4  2002/04/11 07:04:23  pierre
    + handle tables
    + handle tables
 
 
   Revision 1.3  2002/03/20 17:16:11  pierre
   Revision 1.3  2002/03/20 17:16:11  pierre

+ 88 - 7
ide/whtmlscn.pas

@@ -22,10 +22,11 @@ uses Objects,
 
 
 const
 const
      HTMLIndexMagicNo = ord('H')+ord('H') shl 8+ord('I') shl 16+ord('X') shl 24;
      HTMLIndexMagicNo = ord('H')+ord('H') shl 8+ord('I') shl 16+ord('X') shl 24;
-     HTMLIndexVersion = 1;
+     HTMLIndexVersion = 2;
 
 
 type
 type
      PHTMLLinkScanner = ^THTMLLinkScanner;
      PHTMLLinkScanner = ^THTMLLinkScanner;
+     PHTMLLinkScanDocument = ^THTMLLinkScanDocument;
 
 
      TCustomHTMLLinkScanner = object(THTMLParser)
      TCustomHTMLLinkScanner = object(THTMLParser)
        function    DocAddTextChar(C: char): boolean; virtual;
        function    DocAddTextChar(C: char): boolean; virtual;
@@ -39,13 +40,14 @@ type
        CurLinkText: string;
        CurLinkText: string;
        CurURL: string;
        CurURL: string;
        CurDoc: string;
        CurDoc: string;
-       InAnchor: boolean;
+       InAnchor,InNameAnchor: boolean;
+       LastSynonym: PHTMLLinkScanDocument;
      end;
      end;
 
 
-     PHTMLLinkScanDocument = ^THTMLLinkScanDocument;
      THTMLLinkScanDocument = object(TObject)
      THTMLLinkScanDocument = object(TObject)
        constructor Init(const ADocName: string);
        constructor Init(const ADocName: string);
        function    GetName: string;
        function    GetName: string;
+       function    GetUniqueName: string;
        function    GetAliasCount: sw_integer;
        function    GetAliasCount: sw_integer;
        function    GetAlias(Index: sw_integer): string;
        function    GetAlias(Index: sw_integer): string;
        procedure   AddAlias(const Alias: string);
        procedure   AddAlias(const Alias: string);
@@ -54,6 +56,7 @@ type
        destructor  Done; virtual;
        destructor  Done; virtual;
      private
      private
        DocName: PString;
        DocName: PString;
+       Synonym: PHTMLLinkScanDocument;
        Aliases: PStringCollection;
        Aliases: PStringCollection;
      end;
      end;
 
 
@@ -63,6 +66,7 @@ type
        function    Compare(Key1, Key2: Pointer): sw_Integer; virtual;
        function    Compare(Key1, Key2: Pointer): sw_Integer; virtual;
        function    At(Index: sw_Integer): PHTMLLinkScanDocument;
        function    At(Index: sw_Integer): PHTMLLinkScanDocument;
        function    SearchDocument(const DocName: string): PHTMLLinkScanDocument;
        function    SearchDocument(const DocName: string): PHTMLLinkScanDocument;
+       procedure   MoveAliasesToSynonym;
      private
      private
        Scanner: PHTMLLinkScanner;
        Scanner: PHTMLLinkScanner;
      end;
      end;
@@ -72,6 +76,7 @@ type
        procedure   SetBaseDir(const ABaseDir: string);
        procedure   SetBaseDir(const ABaseDir: string);
        function    GetDocumentCount: sw_integer;
        function    GetDocumentCount: sw_integer;
        function    GetDocumentURL(DocIndex: sw_integer): string;
        function    GetDocumentURL(DocIndex: sw_integer): string;
+       function    GetUniqueDocumentURL(DocIndex: sw_integer): string;
        function    GetDocumentAliasCount(DocIndex: sw_integer): sw_integer;
        function    GetDocumentAliasCount(DocIndex: sw_integer): sw_integer;
        function    GetDocumentAlias(DocIndex, AliasIndex: sw_integer): string;
        function    GetDocumentAlias(DocIndex, AliasIndex: sw_integer): string;
        constructor LoadDocuments(var S: TStream);
        constructor LoadDocuments(var S: TStream);
@@ -142,6 +147,9 @@ const
      Store:   @THTMLLinkScanDocument.Store
      Store:   @THTMLLinkScanDocument.Store
   );
   );
 
 
+const
+  CurrentHTMLIndexVersion : sw_integer = HTMLIndexVersion;
+
 function TCustomHTMLLinkScanner.DocAddTextChar(C: char): boolean;
 function TCustomHTMLLinkScanner.DocAddTextChar(C: char): boolean;
 var Added: boolean;
 var Added: boolean;
 begin
 begin
@@ -151,6 +159,8 @@ begin
     CurLinkText:=CurLinkText+C;
     CurLinkText:=CurLinkText+C;
     Added:=true;
     Added:=true;
   end;
   end;
+  if ord(c)>32 then
+    LastSynonym:=nil;
   DocAddTextChar:=Added;
   DocAddTextChar:=Added;
 end;
 end;
 
 
@@ -161,7 +171,11 @@ begin
       CurLinkText:='';
       CurLinkText:='';
       if DocGetTagParam('HREF',CurURL)=false then
       if DocGetTagParam('HREF',CurURL)=false then
       if DocGetTagParam('NAME',CurURL) then
       if DocGetTagParam('NAME',CurURL) then
-        CurURL:=CurDoc+'#'+CurURL
+        begin
+          InNameAnchor:=true;
+          If Pos('#',CurURL)=0 then
+            CurURL:=CurDoc+'#'+CurURL;
+        end
       else
       else
         CurURL:='';
         CurURL:='';
       CurURL:=Trim(CurURL);
       CurURL:=Trim(CurURL);
@@ -170,8 +184,9 @@ begin
   else
   else
     begin
     begin
       CurLinkText:=Trim(CurLinkText);
       CurLinkText:=Trim(CurLinkText);
-      if CheckURL(CurURL) and CheckText(CurLinkText) then
+      if CheckURL(CurURL) and CheckText(CurLinkText) or InNameAnchor then
         AddLink(CurLinkText,CurURL);
         AddLink(CurLinkText,CurURL);
+      InNameAnchor:=false;
     end;
     end;
   InAnchor:=Entered;
   InAnchor:=Entered;
 end;
 end;
@@ -204,6 +219,7 @@ begin
   inherited Init;
   inherited Init;
   SetStr(DocName,ADocName);
   SetStr(DocName,ADocName);
   New(Aliases, Init(10,10));
   New(Aliases, Init(10,10));
+  Synonym:=nil;
 end;
 end;
 
 
 function THTMLLinkScanDocument.GetName: string;
 function THTMLLinkScanDocument.GetName: string;
@@ -211,6 +227,17 @@ begin
   GetName:=GetStr(DocName);
   GetName:=GetStr(DocName);
 end;
 end;
 
 
+function THTMLLinkScanDocument.GetUniqueName: string;
+var
+  PD: PHTMLLinkScanDocument;
+begin
+  PD:=@Self;
+  while assigned(PD^.synonym) do
+    PD:=PD^.Synonym;
+  GetUniqueName:=GetStr(PD^.DocName);
+end;
+
+
 function THTMLLinkScanDocument.GetAliasCount: sw_integer;
 function THTMLLinkScanDocument.GetAliasCount: sw_integer;
 begin
 begin
   GetAliasCount:=Aliases^.Count;
   GetAliasCount:=Aliases^.Count;
@@ -284,6 +311,28 @@ begin
   SearchDocument:=P;
   SearchDocument:=P;
 end;
 end;
 
 
+procedure THTMLLinkScanDocumentCollection.MoveAliasesToSynonym;
+  procedure MoveAliases(P: PHTMLLinkScanDocument);
+  var
+    PD: PHTMLLinkScanDocument;
+    i: sw_integer;
+  begin
+    if not assigned(P^.synonym) then
+      exit;
+    PD:=P;
+    while assigned(PD^.synonym) do
+      PD:=PD^.Synonym;
+
+    For i:=P^.GetAliasCount-1 downto 0 do
+      begin
+        PD^.AddAlias(P^.GetAlias(i));
+        P^.Aliases^.AtFree(i);
+      end;
+  end;
+begin
+  ForEach(@MoveAliases);
+end;
+
 constructor THTMLLinkScanner.Init(const ABaseDir: string);
 constructor THTMLLinkScanner.Init(const ABaseDir: string);
 begin
 begin
   inherited Init;
   inherited Init;
@@ -322,6 +371,11 @@ begin
   GetDocumentURL:=ExpandChildURL(Documents^.At(DocIndex)^.GetName);
   GetDocumentURL:=ExpandChildURL(Documents^.At(DocIndex)^.GetName);
 end;
 end;
 
 
+function THTMLLinkScanner.GetUniqueDocumentURL(DocIndex: sw_integer): string;
+begin
+  GetUniqueDocumentURL:=ExpandChildURL(Documents^.At(DocIndex)^.GetUniqueName);
+end;
+
 function THTMLLinkScanner.GetDocumentAliasCount(DocIndex: sw_integer): sw_integer;
 function THTMLLinkScanner.GetDocumentAliasCount(DocIndex: sw_integer): sw_integer;
 begin
 begin
   GetDocumentAliasCount:=Documents^.At(DocIndex)^.GetAliasCount;
   GetDocumentAliasCount:=Documents^.At(DocIndex)^.GetAliasCount;
@@ -334,6 +388,10 @@ end;
 
 
 procedure THTMLLinkScanner.AddLink(const LinkText, LinkURL: string);
 procedure THTMLLinkScanner.AddLink(const LinkText, LinkURL: string);
 var D: PHTMLLinkScanDocument;
 var D: PHTMLLinkScanDocument;
+    DoInsert: boolean;
+    int: sw_integer;
+    Text: string;
+    error: word;
 begin
 begin
   D:=Documents^.SearchDocument(LinkURL);
   D:=Documents^.SearchDocument(LinkURL);
   if D=nil then
   if D=nil then
@@ -341,7 +399,20 @@ begin
     New(D, Init(NormalizeChildURL(LinkURL)));
     New(D, Init(NormalizeChildURL(LinkURL)));
     Documents^.Insert(D);
     Documents^.Insert(D);
   end;
   end;
-  D^.AddAlias(LinkText);
+  If assigned(LastSynonym) then
+    LastSynonym^.Synonym:=D;
+  DoInsert:=true;
+  If (length(LinkText)=0) or (Pos(',',LinkText)=1) then
+    DoInsert:=false;
+  Val(LinkText,int,error);
+  If (Error>1) and (LinkText[Error]=' ') then
+    Text:=Trim(Copy(LinkText,error+1,length(LinkText)))
+  else
+    Text:=LinkText;
+  IF DoInsert then
+    D^.AddAlias(Text);
+  If InNameAnchor then
+    LastSynonym:=D;
 end;
 end;
 
 
 constructor THTMLLinkScanner.LoadDocuments(var S: TStream);
 constructor THTMLLinkScanner.LoadDocuments(var S: TStream);
@@ -355,6 +426,7 @@ begin
   if (S.Status=stOK) and (L=HTMLIndexMagicNo) then
   if (S.Status=stOK) and (L=HTMLIndexMagicNo) then
   begin
   begin
     S.Read(L,sizeof(L));
     S.Read(L,sizeof(L));
+    CurrentHTMLIndexVersion:=L;
     OK:=(S.Status=stOK);
     OK:=(S.Status=stOK);
   end;
   end;
   if not OK then
   if not OK then
@@ -367,6 +439,8 @@ begin
   New(Documents, Load(S));
   New(Documents, Load(S));
   if not Assigned(Documents) then
   if not Assigned(Documents) then
     Fail;
     Fail;
+  Documents^.MoveAliasesToSynonym;
+  CurrentHTMLIndexVersion:=HTMLIndexVersion;
 end;
 end;
 
 
 procedure THTMLLinkScanner.StoreDocuments(var S: TStream);
 procedure THTMLLinkScanner.StoreDocuments(var S: TStream);
@@ -375,8 +449,10 @@ begin
   L:=HTMLIndexMagicNo;
   L:=HTMLIndexMagicNo;
   S.Write(L,sizeof(L));
   S.Write(L,sizeof(L));
   L:=HTMLIndexVersion;
   L:=HTMLIndexVersion;
+  CurrentHTMLIndexVersion:=L;
   S.Write(L,sizeof(L));
   S.Write(L,sizeof(L));
   S.WriteStr(BaseDir);
   S.WriteStr(BaseDir);
+  Documents^.MoveAliasesToSynonym;
   Documents^.Store(S);
   Documents^.Store(S);
 end;
 end;
 
 
@@ -537,7 +613,12 @@ end;
 END.
 END.
 {
 {
   $Log$
   $Log$
-  Revision 1.2  2002-04-11 07:06:31  pierre
+  Revision 1.3  2002-04-23 09:55:22  pierre
+    + added lastsynonym and InNameAnchor fields to TCustomHTMLLinkScanner
+      these allow to eliminate double index entries pointing to the same
+      html file location (which had two different names).
+
+  Revision 1.2  2002/04/11 07:06:31  pierre
    + recreate the full target of an anchor that only has a NAME field
    + recreate the full target of an anchor that only has a NAME field
 
 
   Revision 1.1  2001/08/04 11:30:26  peter
   Revision 1.1  2001/08/04 11:30:26  peter