/* * 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. */ /* PTITLE.C -------------------------------------------- * @doc * * @module PTITLE.C | * Code to Help-File system global Data like Help-File title, * Copyright-String etc. * * Help Access Library Project. * *-----------------------------------------------------*/ #include #include #include #include #include #include "hlpacces.h" #include "top.h" typedef HELPFILETITLE NEAR * NPHELPFILETITLE; void LOCAL nReadHeader(HIFSFILE ifsfile, NPHELPFILETITLE tit); NPSTR LOCAL nstrdup(LPSTR lpsz) { NPSTR ptr = (NPSTR) LocalAlloc(LMEM_FIXED, lstrlen(lpsz)+1); if (ptr) lstrcpy(ptr, lpsz); return ptr; } /* @func LPHELPFILETITLE | HlpGetHelpTitle | * * Allocates a memory-Object with Informations read from a Help-Files SYSTEM-File * The memory object must be freed with afterwards. * @rdesc A Pointer to a structure or NULL if the file-System * does not contain a SYSTEM-File. * @parm HIFS | ifs | Handle of the File-System, opened wit */ LPHELPFILETITLE WINAPI DLLEXP HlpGetHelpTitle(HIFS ifs) { NPIFSFILE ifsfile; NPHELPFILETITLE npHelpFileTitle = NULL; if (NULL!=(ifsfile = IFSOpenFile(ifs, "|SYSTEM"))) { if (NULL!=(npHelpFileTitle=(NPHELPFILETITLE) LocalAlloc(LPTR, sizeof(HELPFILETITLE)))) { npHelpFileTitle->BgColor = npHelpFileTitle->BgColorNsr = 0xffffff; nReadHeader(ifsfile, npHelpFileTitle); } IFSCloseFile(ifsfile); } return npHelpFileTitle ? (LPHELPFILETITLE) npHelpFileTitle : (NULL); } /* @func void | HlpFreeHelpTitle | * * Frees a memory-Object allocated by the * function * * @parm LPHELPFILETITLE | tit | Pointer to the memory-Object */ void WINAPI DLLEXP HlpFreeHelpTitle(LPHELPFILETITLE tit) { NPHELPFILETITLE npHelpFileTitle = (NPHELPFILETITLE) tit; if (npHelpFileTitle) { if (tit->HelpTitle) LocalFree((HLOCAL) tit->HelpTitle); if (tit->Copyright) LocalFree((HLOCAL) tit->Copyright); if (tit->Citation ) LocalFree((HLOCAL) tit->Citation); while (tit->GroupCount) Hlpfree(tit->GroupNames[--tit->GroupCount]); if (tit->GroupNames) Hlpfree(tit->GroupNames); LocalFree(npHelpFileTitle); } } void LOCAL nReadHeader(HIFSFILE ifsfile, NPHELPFILETITLE tit) { SYSTEMHEADER SystemHeader; SYSTEMREC SystemRec; char buffer[100]; // ---------- Get System-Header data ---------------------------------------- IFSReadFile(ifsfile, &SystemHeader, sizeof(SYSTEMHEADER)); tit->Flags = leword(SystemHeader.Flags); tit->Version = SystemHeader.Version; tit->Revision= SystemHeader.Revision; tit->GenDate = SystemHeader.GenDate; // -------- If Windows 3.0... ---------------------------- if (SystemHeader.Revision == 0x0f) { IFSReadFile(ifsfile, buffer, 32); tit->HelpTitle=nstrdup(buffer); } else { // --- Windows 3.1 ... -------------------------- /* Read in system record and SystemRec data */ while (IFSReadFile(ifsfile, &SystemRec, 4)==4) { SystemRec.RData = (NPSTR) LocalAlloc(LMEM_FIXED, leword(SystemRec.DataSize)); IFSReadFile(ifsfile, SystemRec.RData, leword(SystemRec.DataSize)); switch(leword(SystemRec.RecordType)) { case HPJ_TITLE: if (SystemRec.RData[0]) tit->HelpTitle=nstrdup(SystemRec.RData); break; case HPJ_COPYRIGHT: if (strlen(SystemRec.RData)>2) tit->Copyright=nstrdup(SystemRec.RData); break; case HPJ_CITATION: if (strlen(SystemRec.RData)>2) tit->Citation =nstrdup(SystemRec.RData); break; case HPJ_GROUPDEF: { if (tit->GroupNames) { tit->GroupNames = Hlprealloc(tit->GroupNames, ++tit->GroupCount * sizeof(LPSTR)); } else { tit->GroupNames = Hlpmalloc ( ++tit->GroupCount * sizeof(LPSTR)); tit->GroupNames[tit->GroupCount-1] = Hlpstrdup(SystemRec.RData); } } break; case HPJ_SECWINDOWS: { SECWINDOW *SWin = (SECWINDOW *)SystemRec.RData; if (!strcmp(SWin->Name, "main")) { int Flags = leword(SWin->Flags); if (Flags & WSYSFLAG_RGB) { tit->BgColor = SWin->Rgb[2] | (SWin->Rgb[1] << 8) | (SWin->Rgb[0] << 16); } if (Flags & WSYSFLAG_RGBNSR) { tit->BgColorNsr = SWin->RgbNsr[2] | (SWin->RgbNsr[1] << 8) | (SWin->RgbNsr[0] << 16); } } } break; case HPJ_CONTENTS: tit->ContentsTopicOffset = SystemRec.RData[0] | SystemRec.RData[1]<<8 | SystemRec.RData[2]<<16 | SystemRec.RData[3]<<24; break; } /* switch */ LocalFree((HLOCAL) SystemRec.RData); } // while } }