summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGraeme Geldenhuys <graeme@mastermaths.co.za>2009-09-29 16:39:52 +0200
committerGraeme Geldenhuys <graeme@mastermaths.co.za>2009-09-29 16:39:52 +0200
commit3cc37f3a09f6d30d7e9565f2a358e85003f41476 (patch)
treef6a7e4d16a0b2a613e6e6340be338d01e4c2e122
parent6c9bd169bdcab488387518eb071532f1e62c564a (diff)
downloadfpGUI-3cc37f3a09f6d30d7e9565f2a358e85003f41476.tar.xz
Ported the huge HelpFile unit to FPC.
I disabled Bitmap support for new via the nvNullObject unit. All methods are faked at the moment, until I can do the real implementation of image support. Signed-off-by: Graeme Geldenhuys <graeme@mastermaths.co.za>
-rw-r--r--src/HelpFile.pas122
-rw-r--r--src/newview_fpgui.lpi25
-rw-r--r--src/newview_fpgui.lpr2
3 files changed, 71 insertions, 78 deletions
diff --git a/src/HelpFile.pas b/src/HelpFile.pas
index 727fa948..c4608e1f 100644
--- a/src/HelpFile.pas
+++ b/src/HelpFile.pas
@@ -1,5 +1,7 @@
Unit HelpFile;
+{$mode objfpc}{$H+}
+
// NewView - a new OS/2 Help Viewer
// Copyright 2001 Aaron Lawrence (aaronl at consultant dot com)
// This software is released under the Gnu Public License - see readme.txt
@@ -9,10 +11,12 @@ Interface
// Encapsulates the basic reading of a help file's structure.
uses
- classes, BseDos, os2def, SysUtils, Graphics,
- DataTypes,
- HelpFileHeader, HelpTopic, HelpBitmap, ACLUtility,
- TextSearchQuery, SearchTable, CompareWordUnit;
+ Classes, SysUtils, DataTypes,
+ HelpFileHeader, HelpTopic,
+// HelpBitmap,
+ TextSearchQuery, SearchTable, CompareWordUnit,
+ // this unit is used to fake image support untill fpGUI has this implemented.
+ nvNullObjects;
Type
@@ -32,7 +36,7 @@ type
_Title: string;
_Header: THelpFileHeader;
- _Topics: TList; // of TTopics
+ _Topics: TList; // of TTopic
_Dictionary: TList; // pointers to strings.
@@ -42,7 +46,7 @@ type
_SearchTable: TSearchTable;
procedure InitMembers;
- procedure ReadFile( Filename: string );
+ procedure ReadFile(const AFilename: string );
procedure ReadHeader;
procedure ReadContents;
@@ -59,6 +63,7 @@ type
function GetDictionaryWord( Index: longint ): string;
public
+ HighlightWords: Int32ArrayPointer;
constructor Create( const FileName: string;
UpdateProgress: TProgressCallback );
@@ -79,24 +84,21 @@ type
function IndexOfTopic( Topic: TTopic ): longint;
property SearchTable: TSearchTable read _SearchTable;
-
- HighlightWords: Int32ArrayPointer;
end;
// Returns helpfile that the given topic is within
Function TopicFile( Topic: TTopic ): THelpFile;
+
Implementation
uses
- Dialogs, Forms,
- BseErr,
- ACLFileUtility, ACLStringUtility, ACLFileIOUtility, ACLProfile,
- ACLPCharUtility, ACLDialogs,
- HelpWindow;
+ //ACLFileUtility, ACLStringUtility, ACLFileIOUtility, ACLProfile,
+ //ACLPCharUtility, ACLDialogs,
+ HelpWindow, nvUtilities;
// Load "missing" bitmap
-{$R Images}
+//{.$R Images}
Function TopicFile( Topic: TTopic ): THelpFile;
Begin
@@ -114,62 +116,47 @@ begin
_Index:= TStringList.Create;
end;
-procedure THelpFile.ReadFile( Filename: string );
+procedure THelpFile.ReadFile(const AFilename: string );
var
- OpenAction: ULong;
- rc: APIRET;
- szName: Cstring;
- F: HFILE;
- FileInfo: FILESTATUS3;
+ AFile: File of char;
begin
- _FileName:= Filename;
- if not FileExists( Filename ) then
- raise EHelpFileException.Create( 'File not found' );
-
- szName:= FileName;
- rc:= DosOpen( szName,
- F,
- OpenAction,
- 0, // file size - irrelevant, not creating,
- 0, // attrs - ''
- OPEN_ACTION_OPEN_IF_EXISTS,
- OPEN_SHARE_DENYNONE + OPEN_ACCESS_READONLY,
- nil ); // no eas
- if rc<> 0 then
- begin
- case rc of
- ERROR_FILE_NOT_FOUND: // crap, this doesn't actually occur!
- raise EHelpFileException.Create( 'File not found' );
-
- ERROR_ACCESS_DENIED:
- raise EHelpFileException.Create( 'Access denied' );
-
- ERROR_SHARING_VIOLATION:
- raise EHelpFileException.Create( 'File in use by another program' );
-
- else
- raise EHelpFileException.Create( 'File open error' );
+ _FileName:= AFilename;
+ if not FileExists( AFilename ) then
+ raise EHelpFileException.CreateFmt('File <%s> not found', [AFilename]);
+
+ AssignFile(AFile, Filename);
+ try
+ FileMode := fmOpenRead; // read-only
+ {$i-}
+ Reset(AFile);
+ {$i+}
+ if IOResult <> 0 then
+ begin
+ case IOResult of
+ 2: raise EHelpFileException.Create( 'File not found' );
+ 5: raise EHelpFileException.Create( 'Access denied' );
+ else
+ raise EHelpFileException.CreateFmt( 'File open error. IO Error is <%d>', [IOResult] );
+ end;
end;
- end;
- DosQueryFileInfo( F,
- FIL_STANDARD,
- FileInfo,
- sizeof( FileInfo ) );
- _DataLen:= FileInfo.cbFile; // file size
- GetMem( _Data, _DataLen );
- MyRead( F, _Data, _DataLen );
- DosClose( F );
+ _DataLen := FileSize(AFile); // in bytes
+ _Data := nil;
+ GetMem( _Data, _DataLen ); // allocate enough memory
+ BlockRead(AFile, _Data^, _DataLen);
+ finally
+ CloseFile(AFile);
+ end;
end;
procedure THelpFile.ReadHeader;
begin
- MemCopy( _Data, Addr( _Header ), sizeof( _Header ) );
+ MemCopy(_Data, _Header, sizeof(_Header));
if _Header.ID <> $5348 then
raise EHelpFileException.Create( 'File doesn''t appear to be an OS/2 Help document (header ID not correct)' );
- _Title:= StrPas( _Header.Title );
+ _Title := _Header.Title;
end;
constructor THelpFile.Create( const FileName: string;
@@ -293,30 +280,32 @@ type
procedure THelpFile.ReadIndex;
var
- IndexIndex: longint; // I can't resist :-)
+ IndexIndex: longint;
pEntryHeader: ^TIndexEntryHeader;
EntryText: string;
IndexTitleLen: longint;
p: pointer;
begin
- p:= _Data + _Header.indexstart;
+ p := _Data + _Header.indexstart;
for IndexIndex:= 0 to longint( _Header.nindex ) - 1 do
begin
- pEntryHeader:= p;
+ pEntryHeader := p;
IndexTitleLen:= pEntryHeader^.TextLength;
inc( p, sizeof( TIndexEntryHeader ) );
- GetMemString( p, EntryText, IndexTitleLen );
+ { TODO -oGraeme : Double check this later }
+ EntryText := PChar(p);
+// GetMemString( p, EntryText, IndexTitleLen );
+
if ( pEntryHeader^.flags and 2 ) > 0 then
EntryText:= '- ' + EntryText;
if pEntryHeader^.TOCIndex < _Topics.Count then
- _Index.AddObject( EntryText, _Topics[ pEntryHeader^.TOCIndex ] )
+ _Index.AddObject( EntryText, TTopic(_Topics[ pEntryHeader^.TOCIndex ]) )
else
// raise EHelpFileException.Create( 'Error reading help file index - out of range topic reference' );
; // pass! something special
- inc( p, IndexTitleLen
- + pEntryHeader^.NumberOfRoots ); // skip 'roots' for index search
+ inc( p, IndexTitleLen + pEntryHeader^.NumberOfRoots ); // skip 'roots' for index search
end;
end;
@@ -362,13 +351,12 @@ begin
Images.Add( Bitmap, nil );
Bitmap.Destroy;
-
end;
end;
function THelpFile.GetTopic( Index: longint ): TTopic;
begin
- Result:= _Topics[ Index ];
+ Result:= TTopic(_Topics[ Index ]);
end;
function THelpFile.GetTopicCount: longint;
diff --git a/src/newview_fpgui.lpi b/src/newview_fpgui.lpi
index ae36a414..05278266 100644
--- a/src/newview_fpgui.lpi
+++ b/src/newview_fpgui.lpi
@@ -32,7 +32,7 @@
<PackageName Value="fpgui_toolkit"/>
</Item1>
</RequiredPackages>
- <Units Count="12">
+ <Units Count="13">
<Unit0>
<Filename Value="newview_fpgui.lpr"/>
<IsPartOfProject Value="True"/>
@@ -69,30 +69,35 @@
<UnitName Value="HelpTopic"/>
</Unit6>
<Unit7>
- <Filename Value="CompareWordUnit.pas"/>
+ <Filename Value="HelpFile.pas"/>
<IsPartOfProject Value="True"/>
- <UnitName Value="CompareWordUnit"/>
+ <UnitName Value="HelpFile"/>
</Unit7>
<Unit8>
- <Filename Value="SearchTable.pas"/>
+ <Filename Value="CompareWordUnit.pas"/>
<IsPartOfProject Value="True"/>
- <UnitName Value="SearchTable"/>
+ <UnitName Value="CompareWordUnit"/>
</Unit8>
<Unit9>
- <Filename Value="TextSearchQuery.pas"/>
+ <Filename Value="SearchTable.pas"/>
<IsPartOfProject Value="True"/>
- <UnitName Value="TextSearchQuery"/>
+ <UnitName Value="SearchTable"/>
</Unit9>
<Unit10>
- <Filename Value="nvUtilities.pas"/>
+ <Filename Value="TextSearchQuery.pas"/>
<IsPartOfProject Value="True"/>
- <UnitName Value="nvUtilities"/>
+ <UnitName Value="TextSearchQuery"/>
</Unit10>
<Unit11>
+ <Filename Value="nvUtilities.pas"/>
+ <IsPartOfProject Value="True"/>
+ <UnitName Value="nvUtilities"/>
+ </Unit11>
+ <Unit12>
<Filename Value="nvNullObjects.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="nvNullObjects"/>
- </Unit11>
+ </Unit12>
</Units>
</ProjectOptions>
<CompilerOptions>
diff --git a/src/newview_fpgui.lpr b/src/newview_fpgui.lpr
index a1d891ea..08827df8 100644
--- a/src/newview_fpgui.lpr
+++ b/src/newview_fpgui.lpr
@@ -8,7 +8,7 @@ uses
{$ENDIF}{$ENDIF}
Classes, fpg_main, frm_main, DataTypes, HelpFileHeader, HelpWindow, IPFEscapeCodes,
HelpTopic, CompareWordUnit, SearchTable, TextSearchQuery, nvUtilities,
- nvNullObjects;
+ nvNullObjects, HelpFile;
procedure MainProc;