int Help(char *name, void (*print)(char *buffer)) { char buffer[MBUFFER]; char start[MBUFFER]; int count; int found; if(print!=0) { count=0; found=0; if(HelpFile==0) { HelpOpen("nart.help"); } if(HelpFile!=0) { SformatOutput(start,MBUFFER-1,"<tag=%s>",name); buffer[MBUFFER-1]=0; HelpRewind(); // // look for start of documentation section, <tag=name> // while(HelpRead(buffer,MBUFFER-1)>=0) { if(Smatch(buffer,start)) { found=1; break; } } // // print all lines up to the next <tag=anything> // if(found) { ErrorPrint(ParseHelpDescriptionStart); while(HelpRead(buffer,MBUFFER-1)>=0) { if(strncmp(buffer,"<tag=",5)==0) { break; } ErrorPrint(ParseHelp,buffer); count++; } ErrorPrint(ParseHelpDescriptionEnd); return count; } } } 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 ); }
int HelpIndex(void (*print)(char *buffer)) { char buffer[MBUFFER]; int count; char *end; if(print!=0) { count=0; if(HelpFile==0) { HelpOpen("nart.help"); } if(HelpFile!=0) { HelpRewind(); // // look for start of documentation section, <tag=name> // while(HelpRead(buffer,MBUFFER-1)>=0) { if(strncmp(buffer,"<tag=",5)==0) { end=strchr(buffer,'>'); if(end!=0) { *end=0; } ErrorPrint(ParseHelp,&buffer[5]); count++; } } } } return count; }
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 ); }