Browse Source

* helpfiles fixed

peter 26 years ago
parent
commit
8d234de1d1
2 changed files with 83 additions and 44 deletions
  1. 75 40
      ide/text/whelp.pas
  2. 8 4
      ide/text/whtmlhlp.pas

+ 75 - 40
ide/text/whelp.pas

@@ -318,8 +318,11 @@ end;
 function NewIndexEntry(Tag: string; FileID: word; HelpCtx: THelpCtx): PIndexEntry;
 function NewIndexEntry(Tag: string; FileID: word; HelpCtx: THelpCtx): PIndexEntry;
 var P: PIndexEntry;
 var P: PIndexEntry;
 begin
 begin
-  New(P); FillChar(P^,SizeOf(P^), 0);
-  P^.Tag:=NewStr(Tag); P^.FileID:=FileID; P^.HelpCtx:=HelpCtx;
+  New(P);
+  FillChar(P^,SizeOf(P^), 0);
+  P^.Tag:=NewStr(Tag);
+  P^.FileID:=FileID;
+  P^.HelpCtx:=HelpCtx;
   NewIndexEntry:=P;
   NewIndexEntry:=P;
 end;
 end;
 
 
@@ -463,7 +466,14 @@ begin
   New(F, Init(AFileName, stOpenRead, HelpStreamBufSize));
   New(F, Init(AFileName, stOpenRead, HelpStreamBufSize));
   OK:=F<>nil;
   OK:=F<>nil;
   if OK then OK:=(F^.Status=stOK);
   if OK then OK:=(F^.Status=stOK);
-  if OK then begin FS:=F^.GetSize; OK:=ReadHeader; end;
+  if OK then
+    begin
+{$ifdef FPC}
+      F^.TPCompatible:=true;
+{$endif}
+      FS:=F^.GetSize;
+      OK:=ReadHeader;
+    end;
   while OK do
   while OK do
   begin
   begin
     L:=F^.GetPos;
     L:=F^.GetPos;
@@ -560,8 +570,10 @@ begin
   for I:=0 to IndexCount-1 do
   for I:=0 to IndexCount-1 do
   begin
   begin
     LenCode:=PByteArray(@Entries)^[CurPtr];
     LenCode:=PByteArray(@Entries)^[CurPtr];
-    AddLen:=LenCode and $1f; CopyCnt:=LenCode shr 5;
-    S[0]:=chr(AddLen); Move(PByteArray(@Entries)^[CurPtr+1],S[1],AddLen);
+    AddLen:=LenCode and $1f;
+    CopyCnt:=LenCode shr 5;
+    S[0]:=chr(AddLen);
+    Move(PByteArray(@Entries)^[CurPtr+1],S[1],AddLen);
     LastTag:=copy(LastTag,1,CopyCnt)+S;
     LastTag:=copy(LastTag,1,CopyCnt)+S;
     Move(PByteArray(@Entries)^[CurPtr+1+AddLen],HelpCtx,2);
     Move(PByteArray(@Entries)^[CurPtr+1+AddLen],HelpCtx,2);
     IndexEntries^.Insert(NewIndexEntry(LastTag,ID,HelpCtx));
     IndexEntries^.Insert(NewIndexEntry(LastTag,ID,HelpCtx));
@@ -642,7 +654,7 @@ begin
   case N of
   case N of
     $00       : C:=#0;
     $00       : C:=#0;
     $01..$0D  : C:=chr(Compression.CharTable[N]);
     $01..$0D  : C:=chr(Compression.CharTable[N]);
-    ncRawChar : C:=chr(GetNextNibble*16+GetNextNibble);
+    ncRawChar : C:=chr(GetNextNibble+GetNextNibble shl 4);
     ncRepChar : begin
     ncRepChar : begin
                   Cnt:=2+GetNextNibble;
                   Cnt:=2+GetNextNibble;
                   C:=GetNextChar{$ifdef FPC}(){$endif};
                   C:=GetNextChar{$ifdef FPC}(){$endif};
@@ -809,10 +821,12 @@ begin
   TopicSearch:=HelpFiles^.FirstThat(@ScanHelpFile)<>nil;
   TopicSearch:=HelpFiles^.FirstThat(@ScanHelpFile)<>nil;
 end;
 end;
 
 
+
 function THelpFacility.BuildIndexTopic: PTopic;
 function THelpFacility.BuildIndexTopic: PTopic;
-var T: PTopic;
-    Keywords: PIndexEntryCollection;
-    Lines: PUnsortedStringCollection;
+var
+  T        : PTopic;
+  Keywords : PIndexEntryCollection;
+  Lines    : PUnsortedStringCollection;
 
 
   procedure InsertKeywordsOfFile(H: PHelpFile); {$ifndef FPC}far;{$endif}
   procedure InsertKeywordsOfFile(H: PHelpFile); {$ifndef FPC}far;{$endif}
 
 
@@ -821,12 +835,9 @@ var T: PTopic;
       Keywords^.Insert(P);
       Keywords^.Insert(P);
       InsertKeywords:=Keywords^.Count>=MaxCollectionSize;
       InsertKeywords:=Keywords^.Count>=MaxCollectionSize;
     end;
     end;
-  var
-    l1,l2 : longint;
+
   begin
   begin
     H^.LoadIndex;
     H^.LoadIndex;
-    l1:=MaxCollectionSize;
-    l2:=Keywords^.count;
     if Keywords^.Count<MaxCollectionSize then
     if Keywords^.Count<MaxCollectionSize then
       H^.IndexEntries^.FirstThat(@InsertKeywords);
       H^.IndexEntries^.FirstThat(@InsertKeywords);
   end;
   end;
@@ -838,29 +849,44 @@ var T: PTopic;
   end;
   end;
 
 
 procedure RenderTopic;
 procedure RenderTopic;
-var Size,CurPtr,I: word;
+var
+  Size,CurPtr,I: word;
   S: string;
   S: string;
-function CountSize(P: PString): boolean; {$ifndef FPC}far;{$endif} begin Inc(Size, length(P^)+1); CountSize:=Size>65200; end;
+
+  function CountSize(P: PString): boolean; {$ifndef FPC}far;{$endif}
+  begin
+    Inc(Size, length(P^)+1);
+    CountSize:=Size>65200;
+  end;
+
 begin
 begin
-  Size:=0; Lines^.FirstThat(@CountSize);
-  T^.TextSize:=Size; GetMem(T^.Text,T^.TextSize);
+  Size:=0;
+  Lines^.FirstThat(@CountSize);
+  T^.TextSize:=Size;
+  GetMem(T^.Text,T^.TextSize);
   CurPtr:=0;
   CurPtr:=0;
   for I:=0 to Lines^.Count-1 do
   for I:=0 to Lines^.Count-1 do
   begin
   begin
     S:=Lines^.At(I)^;
     S:=Lines^.At(I)^;
-    Size:=length(S)+1; S[Size]:=hscLineBreak;
+    Size:=length(S)+1;
+    S[Size]:=hscLineBreak;
     Move(S[1],PByteArray(T^.Text)^[CurPtr],Size);
     Move(S[1],PByteArray(T^.Text)^[CurPtr],Size);
     Inc(CurPtr,Size);
     Inc(CurPtr,Size);
-    if CurPtr>=T^.TextSize then Break;
+    if CurPtr>=T^.TextSize then
+     Break;
   end;
   end;
 end;
 end;
+
 var Line: string;
 var Line: string;
 procedure FlushLine;
 procedure FlushLine;
 begin
 begin
   if Line<>'' then AddLine(Line); Line:='';
   if Line<>'' then AddLine(Line); Line:='';
 end;
 end;
-var KWCount,NLFlag: Sw_integer;
-    LastFirstChar: char;
+
+var
+  KWCount,NLFlag: Sw_integer;
+  LastFirstChar: char;
+
 procedure NewSection(FirstChar: char);
 procedure NewSection(FirstChar: char);
 begin
 begin
   if FirstChar<=#64 then FirstChar:=#32;
   if FirstChar<=#64 then FirstChar:=#32;
@@ -871,6 +897,7 @@ begin
   LastFirstChar:=FirstChar;
   LastFirstChar:=FirstChar;
   NLFlag:=0;
   NLFlag:=0;
 end;
 end;
+
 procedure AddKeyword(KWS: string);
 procedure AddKeyword(KWS: string);
 begin
 begin
   Inc(KWCount); if KWCount=1 then NLFlag:=0;
   Inc(KWCount); if KWCount=1 then NLFlag:=0;
@@ -885,8 +912,10 @@ begin
           end;
           end;
   Inc(NLFlag);
   Inc(NLFlag);
 end;
 end;
-var KW: PIndexEntry;
-    I: Sw_integer;
+
+var
+  KW : PIndexEntry;
+  I  : Sw_integer;
 begin
 begin
   New(Keywords, Init(5000,1000));
   New(Keywords, Init(5000,1000));
   HelpFiles^.ForEach(@InsertKeywordsOfFile);
   HelpFiles^.ForEach(@InsertKeywordsOfFile);
@@ -896,29 +925,32 @@ begin
     begin
     begin
       AddLine('');
       AddLine('');
       AddLine(' No help files installed.')
       AddLine(' No help files installed.')
-    end else
-  begin
-    AddLine(' Help index');
-    KWCount:=0; Line:='';
-    T^.LinkCount:=Keywords^.Count;
-    T^.LinkSize:=T^.LinkCount*SizeOf(T^.Links^[0]);
-    GetMem(T^.Links,T^.LinkSize);
-
-    for I:=0 to Keywords^.Count-1 do
+    end
+  else
     begin
     begin
-      KW:=Keywords^.At(I);
-      AddKeyword(KW^.Tag^);
-      T^.Links^[I].Context:=KW^.HelpCtx; T^.Links^[I].FileID:=KW^.FileID;
+      AddLine(' Help index');
+      KWCount:=0; Line:='';
+      T^.LinkCount:=Keywords^.Count;
+      T^.LinkSize:=T^.LinkCount*SizeOf(T^.Links^[0]);
+      GetMem(T^.Links,T^.LinkSize);
+      for I:=0 to Keywords^.Count-1 do
+       begin
+         KW:=Keywords^.At(I);
+         AddKeyword(KW^.Tag^);
+         T^.Links^[I].Context:=KW^.HelpCtx;
+         T^.Links^[I].FileID:=KW^.FileID;
+       end;
+      FlushLine;
+      AddLine('');
     end;
     end;
-    FlushLine;
-    AddLine('');
-  end;
   RenderTopic;
   RenderTopic;
   Dispose(Lines, Done);
   Dispose(Lines, Done);
-  Keywords^.DeleteAll; Dispose(Keywords, Done);
+  Keywords^.DeleteAll;
+  Dispose(Keywords, Done);
   BuildIndexTopic:=T;
   BuildIndexTopic:=T;
 end;
 end;
 
 
+
 function THelpFacility.SearchFile(ID: byte): PHelpFile;
 function THelpFacility.SearchFile(ID: byte): PHelpFile;
 function Match(P: PHelpFile): boolean; {$ifndef FPC}far;{$endif}
 function Match(P: PHelpFile): boolean; {$ifndef FPC}far;{$endif}
 begin
 begin
@@ -945,7 +977,10 @@ end;
 END.
 END.
 {
 {
   $Log$
   $Log$
-  Revision 1.6  1999-02-20 15:18:35  peter
+  Revision 1.7  1999-02-22 15:04:31  peter
+    * helpfiles fixed
+
+  Revision 1.6  1999/02/20 15:18:35  peter
     + ctrl-c capture with confirm dialog
     + ctrl-c capture with confirm dialog
     + ascii table in the tools menu
     + ascii table in the tools menu
     + heapviewer
     + heapviewer

+ 8 - 4
ide/text/whtmlhlp.pas

@@ -15,7 +15,7 @@ type
     TTopicLinkCollection = object(TStringCollection)
     TTopicLinkCollection = object(TStringCollection)
       procedure Insert(Item: Pointer); virtual;
       procedure Insert(Item: Pointer); virtual;
       function  At(Index: sw_Integer): PString;
       function  At(Index: sw_Integer): PString;
-      function  AddItem(Item: string): integer;
+      function  AddItem(const Item: string): Sw_integer;
     end;
     end;
 
 
     TParagraphAlign = (paLeft,paCenter,paRight);
     TParagraphAlign = (paLeft,paCenter,paRight);
@@ -178,7 +178,7 @@ begin
   At:=inherited At(Index);
   At:=inherited At(Index);
 end;
 end;
 
 
-function TTopicLinkCollection.AddItem(Item: string): integer;
+function TTopicLinkCollection.AddItem(const Item: string): Sw_integer;
 var Idx: sw_integer;
 var Idx: sw_integer;
 begin
 begin
   if Item='' then Idx:=-1 else
   if Item='' then Idx:=-1 else
@@ -563,14 +563,18 @@ var OK: boolean;
     HTMLFile: PDOSTextFile;
     HTMLFile: PDOSTextFile;
     Name: string;
     Name: string;
     Link: string;
     Link: string;
+    FileNo,LinkNo : word;
     P: sw_integer;
     P: sw_integer;
 begin
 begin
   OK:=T<>nil;
   OK:=T<>nil;
   if OK then
   if OK then
     begin
     begin
-      if T^.HelpCtx=0 then Name:=FileName else
+      if (T^.HelpCtx=0) then
+        Name:=FileName
+      else
         begin
         begin
-          Link:=TopicLinks^.At(T^.HelpCtx-1)^;
+          DecodeHTMLCtx(T^.HelpCtx-1,FileNo,LinkNo);
+          Link:=TopicLinks^.At(LinkNo)^;
           Link:=FormatPath(Link);
           Link:=FormatPath(Link);
           P:=Pos('#',Link); if P>0 then Delete(Link,P,255);
           P:=Pos('#',Link); if P>0 then Delete(Link,P,255);
 {          if CurFileName='' then Name:=Link else
 {          if CurFileName='' then Name:=Link else