/* * Help Access Library * A Library to access the contents of Windows Help files. * * Copyright (C) 1995-2000 Bernd Herd, http://www.herdsoft.com * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /* GETTTL.C ------------------------------------------- * @doc * @module GETTTL.C | * Gets Topic Title for any valid TopicOffset Value * * Help Access Library Project. * *-----------------------------------------------------*/ #include #include #include #include #include #include "hlpacces.h" BOOL LOCAL nEnumerateTopics(NPIFSFILE ifsfile, DWORD dwTopicOffset, LPSTR lpszBuffer, UINT uBufferSize, LPDWORD lpdwTopicOffsetStart); BOOL LOCAL nEnumeratePage(NPIFSFILE ifsfile, int PageCount, int CurrentLevel, int PageSize, int CurrPage, DWORD dwTopicOffset, LPSTR lpszBuffer, UINT uBufferSize, LPDWORD lpdwTopicOffsetStart); /* @func BOOL | HlpGetTopicTitle | * * Retrieves the Topic Title for a given TopicOffset Value. * The TopicOffset does not neccessarily need to point directly * to the start of the Topic. * * @rdesc * TRUE if the Function was Successfull * FALSE else */ BOOL FAR PASCAL DLLEXP HlpGetTopicTitle( HIFS ifs, // @parm Handle to a opened File-System opened by DWORD dwTopicOffset, // @parm TopicOffset to search for LPSTR lpszBuffer, // @parm Pointer to a Buffer to copy the retrieved Title String or NULL if not needed UINT uBufferSize, // @parm Size of the Bufffer in Bytes LPDWORD lpdwTopicOffsetStart) // @parm Pointer to a DWORD that will contain the TopicOffset value for the begin of the Topic or NULL if this is not needed { BOOL Success=FALSE; NPIFSFILE ifsfile = IFSOpenFile(ifs, "|TTLBTREE"); if (ifsfile) { Success = nEnumerateTopics(ifsfile, dwTopicOffset, lpszBuffer, uBufferSize, lpdwTopicOffsetStart); IFSCloseFile(ifsfile); } return Success; } /* nEnumerateTopic * * Does the buch of Work to do enumeration */ BOOL LOCAL nEnumerateTopics(NPIFSFILE ifsfile, DWORD dwTopicOffset, LPSTR lpszBuffer, UINT uBufferSize, LPDWORD lpdwTopicOffsetStart) { BOOL Success; BTREEHEADER BTreeHdr; DWORD dwSize; UINT PageCount; //--------- Read Title B-Tree header ------------------ IFSReadFile(ifsfile, &BTreeHdr, sizeof(BTreeHdr)); dwSize = IFSSeekFile(ifsfile, 0L, 2); PageCount = (UINT) (dwSize/leword(BTreeHdr.PageSize)); // printf("# PageCount:%u NLevels: %u NSplits: %u PageSize: %u Total Entries:%ld\n\n", PageCount, BTreeHdr.NLevels, BTreeHdr.NSplits, BTreeHdr.PageSize, BTreeHdr.TotalBtreeEntries); Success = nEnumeratePage(ifsfile, PageCount, leword(BTreeHdr.NLevels)-1, leword(BTreeHdr.PageSize), leword(BTreeHdr.RootPage), dwTopicOffset, lpszBuffer, uBufferSize, lpdwTopicOffsetStart); return Success; } #pragma pack(1) typedef struct { LEWORD PageNo; LEDWORD TopicOffset; } PACKED BTREEINDEXENTRY; #pragma pack() BOOL LOCAL nEnumeratePage(NPIFSFILE ifsfile, int PageCount, int CurrentLevel, int PageSize, int CurrPage, DWORD dwTopicOffset, LPSTR lpszBuffer, UINT uBufferSize, LPDWORD lpdwTopicOffsetStart) { BOOL Success = FALSE; DWORD loc = sizeof(BTREEHEADER) + PageSize * (DWORD) CurrPage; NPSTR page = (NPSTR) LocalAlloc(LPTR, PageSize); NPSTR next; BTREENODEHEADER NodeHeader; BTREEINDEXENTRY NEAR *CurrIndexEntry, NEAR *DownIndexEntry; int i; if (page) { //----------- Read Page ---------------------------------------- IFSSeekFile(ifsfile, loc, 0); if (PageSize == IFSReadFile(ifsfile, page, PageSize)) { memcpy(&NodeHeader, page, sizeof(NodeHeader)); //--------- Are we in a Node or in a leaf? ------------------- if (CurrentLevel > 0) { //-- We're in a node, search for next sub-node or leaf -- DownIndexEntry = NULL; for (i=0, CurrIndexEntry = (BTREEINDEXENTRY NEAR *) (page+sizeof(BTREEINDEXHEADER)); iTopicOffset)>dwTopicOffset || i==leword(NodeHeader.NEntries)) DownIndexEntry = CurrIndexEntry; if (DownIndexEntry) Success = nEnumeratePage(ifsfile, PageCount, CurrentLevel-1, PageSize, leword(DownIndexEntry->PageNo), dwTopicOffset, lpszBuffer, uBufferSize, lpdwTopicOffsetStart); } else //--------- Enumerate Page contents -------------------------- for (Success=TRUE, next=page+sizeof(BTREENODEHEADER), i=0; Success &&i