/* * CheckHelpBlock - see if a topic is in the 2nd half of a block */ static int CheckHelpBlock( HelpFp help_file, char *topic, char *buffer, long int start ) { int retn; char *ftopic; char *end; unsigned len; HelpSeek( help_file, start, HELP_SEEK_SET ); retn = 0; do { if( helpGetString( buffer, BUF_LEN, help_file ) == NULL ) { retn = -1; break; } } while( memcmp( buffer, "::::", 4 ) != 0 ); if( retn == 0 ) { ftopic = scanTopic( buffer, &end ); len = end - ftopic; retn = strnicmp( topic, ftopic, len ); if( !retn && topic[len] != '\0' ) { retn = 1; } } return( retn ); }
static void seek_line( int line ) { int i; if( line > lastHelpLine ) { HelpSeek( helpFileHdl, topPos + helpPos[lastHelpLine], HELP_SEEK_SET ); for( i = lastHelpLine; ; ++i ) { save_line( i, HelpTell( helpFileHdl ) ); if( i == line ) break; if( !mygetline() || strnicmp( helpInBuf, "::::", 4 ) == 0 ) { maxLine = i; break; } } } else if( line >= 0 ) { HelpSeek( helpFileHdl, topPos + helpPos[line], HELP_SEEK_SET ); } }
/* * OpenTopicInFile - open a help file and look for a topic */ static int OpenTopicInFile( help_file *fileinfo, char *topic, char *buffer ) { long int start_offset; /* - starting offset in HELP file */ long int size_left; /* - size left to search */ int next_posn; /* - contains indicator for next pos'n */ unsigned long topic_pos; if( fileinfo->f == -1 ) return( 0 ); if( fileinfo->searchhdl != NULL ) { /* search by new method */ topic_pos = HelpFindTopicOffset( fileinfo->searchhdl, topic ); if( topic_pos == (unsigned long)-1 ) { return( 0 ); } else { HelpSeek( fileinfo->f, topic_pos, HELP_SEEK_SET ); if( helpGetString( buffer, BUF_LEN, fileinfo->f ) == NULL ) { return( 0 ); } else { return( 1 ); } } } else { start_offset = 0L; } size_left = HelpFileLen( fileinfo->f ); do { size_left = size_left / 2; if( size_left <= 8 ) { if( CheckHelpBlock( fileinfo->f, topic, buffer, start_offset ) != 0 ) { return( 0 ); } else { return( 1 ); } } next_posn = CheckHelpBlock( fileinfo->f, topic, buffer, start_offset + size_left ); if( next_posn > 0 ) { start_offset += size_left; } } while( next_posn != 0 ); return( 1 ); }
/* * helpGetString */ static char *helpGetString( char *buf, size_t size, HelpFp fp ) { long int pos; int bytesread; int cnt; pos = HelpTell( fp ); bytesread = HelpRead( fp, buf, size - 1 ); if( bytesread == 0 || bytesread == -1 ) return( NULL ); for( cnt = 0; cnt < bytesread; ++cnt ) { if( buf[cnt] == '\n' ) { cnt++; break; } } HelpSeek( fp, pos + cnt, HELP_SEEK_SET ); buf[cnt] = '\0'; return( buf ); }
static void loadPage( HelpHdl hdl, unsigned long pagenum ) { unsigned long offset; unsigned tmp; if( curFile == hdl->fp && pageHeader->page_num == pagenum ) return; if( hdl->header.ver_maj == 1 ) { tmp = sizeof( HelpHeader ) - sizeof( uint_16 ); // no str_size } else { tmp = sizeof( HelpHeader ); } offset = tmp + hdl->header.str_size + pagenum * PAGE_SIZE + hdl->header.datapagecnt * sizeof( uint_16 ); HelpSeek( hdl->fp, offset, HELP_SEEK_SET ); HelpRead( hdl->fp, curPage, PAGE_SIZE ); curFile = hdl->fp; pageHeader = (HelpPageHeader *)curPage; pageIndex = curPage + sizeof( HelpPageHeader ); if( pageHeader->type == PAGE_DATA ) { stringBlock = curPage + sizeof( HelpPageHeader ) + pageHeader->num_entries * sizeof( PageIndexEntry ); } }
HelpHdl InitHelpSearch( HelpFp fp ) { HelpHdl hdl; unsigned len; char *topic; char *description; uint_16 str_cnt; uint_16 *str_len; char *ptr; char *buffer; HelpSeek( fp, 0, HELP_SEEK_SET ); hdl = HelpMemAlloc( sizeof( struct HelpHdl ) ); hdl->fp = fp; HelpRead( fp, &( hdl->header ), sizeof( HelpHeader ) ); if( hdl->header.sig[0] != HELP_SIG_1 || hdl->header.sig[1] != HELP_SIG_2 || hdl->header.ver_min != HELP_MIN_VER ) { HelpMemFree( hdl ); hdl = NULL; } else if( hdl->header.ver_maj != HELP_MAJ_VER ) { if( hdl->header.ver_maj != 1 ) { HelpMemFree( hdl ); hdl = NULL; } else { HelpSeek( fp, -sizeof( uint_16 ), SEEK_CUR ); // no str_size in header topic = HelpMemAlloc( strlen( DEFAULTTOPIC ) + 1 ); strcpy( topic, DEFAULTTOPIC ); hdl->def_topic = topic; hdl->desc_str = NULL; hdl->header.str_size = 0; // no str_size in old header format len = hdl->header.datapagecnt * sizeof( uint_16 ); hdl->itemindex = HelpMemAlloc( len ); HelpRead( fp, hdl->itemindex, len ); } } else { buffer = HelpMemAlloc( hdl->header.str_size ); HelpRead( fp, buffer, hdl->header.str_size ); ptr = buffer; str_len = (uint_16 *)ptr; str_cnt = *str_len; str_len++; if( *str_len != 0 ) { topic = HelpMemAlloc( *str_len ); ptr += (str_cnt + 1) * sizeof( uint_16 ); strcpy( topic, ptr); // assume topic is first string } else { topic = HelpMemAlloc( strlen( DEFAULTTOPIC ) + 1 ); strcpy( topic, DEFAULTTOPIC ); } ptr = buffer; ptr += ( str_cnt + 1 ) * ( sizeof( uint_16 ) ); ptr += ( *str_len ) * ( sizeof( char ) ); str_len++; if( *str_len != 0 ) { description = HelpMemAlloc( *str_len ); strcpy( description, ptr ); } else { description = NULL; } HelpMemFree( buffer ); hdl->def_topic = topic; hdl->desc_str = description; len = ( hdl->header.datapagecnt ) * ( sizeof( uint_16 ) ); hdl->itemindex = HelpMemAlloc( len ); HelpRead( fp, hdl->itemindex, len ); } return( hdl ); }