/* * 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. */ /* IFSENUM.C ------------------------------------------- * * @doc * @module IFSENUM.C | * Code to enumerate all files contained in a internal * file System to a callback-Procedure. * * Help File Access Project. * *-----------------------------------------------------*/ #include #include #pragma hdrstop #include #include #include #include "hlpacces.h" // --------- Local function prototypes ----------------- void LOCAL nIFSEnumerate(HIFS ifs, IFSENUMPROC fnCallback, UINT NLevel, UINT CurrPage, LPARAM lParam); /* @func void | IFSEnumerateFiles | * * Enumerates the files contained in the File System. * * Has about the same meaning as a DIR-Command or a set of findfirst/findnext... * * @comm Files starting with a 0x7c-Character are usually automatically added by the * Compiler, while other files are usually added by the [Baggage] * @comm The enumeration is sorted by the Filename, upper case characters first */ void WINAPI DLLEXP IFSEnumerateFiles( HIFS ifs, // @parm Handle of the file system opened with a call to IFSENUMPROC fnCallback, /* @parm application-supplied callback-function that will be called for every filename retrieved from the File System */ LPARAM lParam) /* @parm Application-Defined parameter that will be transfered to the callback */ { nIFSEnumerate(ifs, fnCallback, leword(ifs->WHIFSHeader.NLevels), leword(ifs->WHIFSHeader.RootPage), lParam); } /* nFindInternalFile * * Internal routine does a binary Search for the given * Filename in the IFS * * Returns position of FIle in physical if it's found and * 0 if not. */ #define HlpGotoWHIFSPage(ifs, DestPage) \ _llseek(ifs->hf, FirstPageLoc+(DestPage * \ leword(ifs->WHIFSHeader.PageSize)), SEEK_SET) void LOCAL nIFSEnumerate(HIFS ifs, IFSENUMPROC fnCallback, UINT NLevel, UINT CurrPage, LPARAM lParam) { NPSTR buf = (NPSTR) LocalAlloc(LPTR, leword(ifs->WHIFSHeader.PageSize)), // Buffer for one Page nxt; BTREENODEHEADER NEAR *CurrNode = (BTREENODEHEADER NEAR *)buf; /* Current Node in B-Tree */ DWORD FirstPageLoc= ledword(ifs->HelpHeader.DirectoryFileOffset) + sizeof(ifs->WHIFSHeader) + sizeof(FILEHEADER); int i; if (buf) { //-------- Read in a Page ---------------------------------- HlpGotoWHIFSPage(ifs, CurrPage); _lread(ifs->hf, buf, leword(ifs->WHIFSHeader.PageSize)); //-------- In node or leaf ? ------------------------------- if (NLevel>1) { //-- We're in a node, search for next sub-node or leaf -- for (i=0, nxt = buf+sizeof(BTREEINDEXHEADER); iNEntries)+1; ++i, nxt+=lstrlen(nxt+2)+1+sizeof(WORD)) { CurrPage=nxt[0]+(nxt[1]<<8); //------- We're currently in a node, so recurse down... ---- nIFSEnumerate(ifs, fnCallback, NLevel-1, CurrPage, lParam); } } else { //-- We're in the right leaf now, scan for Data --------- for (i=0, nxt = buf+sizeof(BTREENODEHEADER); iNEntries); ++i ,nxt+=lstrlen(nxt)+1+sizeof(LONG)) fnCallback(nxt, ledword(((LEDWORD NEAR *) (nxt+lstrlen(nxt)+1))[0]), lParam); } } LocalFree((HLOCAL) buf); }