int helpinit( /* INITIALIZATION FOR THE HELP PROCESS */ char **helpfilenames, /* - list of help file names */ HelpSrchPathItem *srchlist ) /* - list of places to look for help files */ { unsigned i; int cnt; if( srchlist != NULL ) { cnt = 0; while( srchlist[cnt].type != SRCHTYPE_EOL ) cnt++; cnt++; srch_List = HelpMemAlloc( cnt * sizeof( HelpSrchPathItem ) ); for( i = 0; i < cnt ; ++i ) { srch_List[i].type = srchlist[i].type; if( srchlist[i].info != NULL ) { srch_List[i].info = HelpMemAlloc( strlen( srchlist[i].info ) + 1 ); strcpy( srch_List[i].info, srchlist[i].info ); } else { srch_List[i].info = NULL; } } } else { freeSearchList(); } cnt = do_init( helpfilenames, srchlist ); return( cnt ); }
static void scanDirectory( char *buf, FileList *list ) { DIR *dirhdl; struct dirent *dirent; char fname[_MAX_FNAME]; unsigned len; dirhdl = opendir( buf ); if ( dirhdl == NULL ) return; dirent = readdir( dirhdl ); while( dirent != NULL ) { len = strlen( dirent->d_name ); if ( len < 5 || stricmp ( &dirent->d_name[len - 4], DEF_EXT ) != 0 ) { dirent = readdir( dirhdl ); continue; } list->items[ list->used ] = HelpMemAlloc( sizeof( FileInfo ) ); len = strlen( buf ) + 1; list->items[ list->used ]->fpath = HelpMemAlloc( len ); strcpy( list->items[ list->used ]->fpath, buf ); _splitpath( dirent->d_name, NULL, NULL, fname, NULL ); len = strlen( fname ) + 1; list->items[ list->used ]->fname = HelpMemAlloc( len ); strcpy( list->items[ list->used ]->fname, fname ); list->used ++; if( list->used == list->allocated ) { list->allocated += MAX_HELPFILES; list = HelpMemRealloc( list, sizeof( FileList ) + list->allocated * sizeof( FileInfo* ) ); } dirent = readdir( dirhdl ); } closedir( dirhdl ); }
int do_init( /* INITIALIZATION FOR THE HELP PROCESS */ char **helpfilenames, /* - list of help file names */ HelpSrchPathItem *srchlist ) /* - list of places to look for help files */ { int count; char **fname; char fullpath[_MAX_PATH]; count = 0; while( HelpFiles[count].name != NULL && count < MAX_HELP_FILES - 1 ) { HelpMemFree( HelpFiles[count].name ); HelpFiles[count].name = NULL; count += 1; } fname = helpfilenames; count = 0; while( *fname != NULL && count < MAX_HELP_FILES-1 ) { if( search_for_file( fullpath, *fname, srchlist ) ) { HelpFiles[count].name = HelpMemAlloc( strlen( fullpath ) + 1 ); strcpy( HelpFiles[count].name, fullpath ); HelpFiles[count].f = 0; count += 1; } ++fname; } HelpFiles[count].name = NULL; HelpFiles[count].f = 0; return( count ); }
static void nexttopic( char *word ) { a_hstackent *h; unsigned len; if( word == NULL ) { len = 0; } else { len = strlen( word ); } h = HelpMemAlloc( sizeof( a_hstackent ) + len ); if( helpStack != NULL ) { helpStack->cur = field_count( helpTab, helpCur ); helpStack->line = currLine; } h->next = helpStack; h->type = HSTCK_NAME; h->cur = 0; h->line = 0; strcpy( h->helpfname, curFile ); if( word != NULL ) { strcpy( h->word, word ); } h->word[len] = '\0'; helpStack = h; free_fields( &helpTab ); }
/* * fixHelpTopic - escape any special characters in topics that comes from * the outside world */ static char *fixHelpTopic( char *topic ) { char *ptr; char *retptr; unsigned cnt; char *ret; ptr = topic; cnt = 0; while( *ptr != '\0' ) { if( *ptr == '<' || *ptr == '>' || *ptr == '"' || *ptr == '{' || *ptr == '}' ) { cnt++; } cnt ++; ptr ++; } ret = HelpMemAlloc( cnt + 1 ); retptr = ret; ptr = topic; while( *ptr != '\0' ) { if( *ptr == '<' || *ptr == '>' || *ptr == '"' || *ptr == '{' || *ptr == '}' ) { *retptr = HELP_ESCAPE; retptr ++; *retptr = *ptr; } else { *retptr = *ptr; } retptr++; ptr++; } *retptr = '\0'; return( ret ); }
static FileList *initFileList( void ) { FileList *ret; ret = HelpMemAlloc( sizeof( FileList ) + MAX_HELPFILES * sizeof( FileInfo* ) ); ret->allocated = MAX_HELPFILES; ret->used = 0; return( ret ); }
static void checkBufCB( TokenType type, Info *info, void *_node ) { a_helpnode *node = _node; if( type == TK_PLAIN_LINK || type == TK_GOOFY_LINK ) { if( nameBufLen <= info->u.link.topic_len ) { HelpMemFree( nameBuf ); nameBuf = HelpMemAlloc( info->u.link.topic_len + 1 ); nameBufLen = info->u.link.topic_len + 1; } memcpy( nameBuf, info->u.link.topic, info->u.link.topic_len ); nameBuf[ info->u.link.topic_len ] = '\0'; if( info->u.link.hfname_len == 0 ) { lookup_name( node, nameBuf ); } } }
/* * dispHelp */ static int dispHelp( char *str, VTAB *tab ) { EVENT ev; bool done; int lastline; int start; SAREA use; SAREA line; char helpname[81]; ignoreMouseRelease = true; helpSet( str, helpname, sizeof( helpname ) ); if( uivopen( &helpScreen ) == NULL ) return( HELP_NO_VOPEN ); use.height = helpScreen.area.height - 3; use.width = helpScreen.area.width; use.col = 0; line.height = 1; line.width = helpScreen.area.width; line.col = 0; topPos = HelpTell( helpFileHdl ); mygetline(); handleHeader( &start, &line ); use.row = start; use.height -= start; handleFooter( &start, &use, &line ); setupScrollBar( &use ); if( helpLines > 0 ) { maxPos = helpLines + 1; helpPos = HelpMemAlloc( maxPos * sizeof( *helpPos ) ); } else { maxPos = 0; helpPos = NULL; } maxLine = 0; lastHelpLine = 0; save_line( 0, topPos ); currLine = helpStack->line; seek_line( currLine ); lastline = currLine + use.height; done = false; ev = EV_NO_EVENT; while( !done ) { currentColour = C_PLAIN; currentAttr = AT( ATTR_NORMAL ); if( lastline != currLine ) { lastline = scrollHelp( &use, lastline, ( ev != EV_NO_EVENT ) ); } ev = hlpwait( tab ); switch( ev ) { case E_UP: case EV_CURSOR_UP: case EV_TOP: if( currLine > 0 ) { --currLine; } break; case E_DOWN: case EV_CURSOR_DOWN: case EV_BOTTOM: ++currLine; if( maxLine != 0 && currLine+use.height > maxLine ) { --currLine; } break; case EV_SCROLL_VERTICAL: currLine = vGadget.pos; break; case EV_PAGE_UP: currLine -= use.height; if( currLine < 0 ) { currLine = 0; } break; case EV_PAGE_DOWN: currLine += use.height; if( maxLine != 0 && currLine >= maxLine ) { currLine -= use.height; } break; default: done = true; break; } } clearline(); uivclose( &helpScreen ); if( helpPos != NULL ) { HelpMemFree( helpPos ); helpPos = NULL; } return( HELP_OK ); }
static int do_showhelp( char **helptopic, char *filename, EVENT (*rtn)( EVENT ), bool first ) { int err; char *ptr; unsigned len; char *htopic; eventMapFn = rtn; helpTab = NULL; helpCur = helpTab; strcpy( curFile, filename ); helpInBuf = HelpMemAlloc( BUF_LEN ); if( helpInBuf == NULL ) { HelpMemFree( helpStack ); return( HELP_NO_MEM ); } helpOutBuf = HelpMemAlloc( BUF_LEN ); if( helpOutBuf == NULL ) { HelpMemFree( helpStack ); return( HELP_NO_MEM ); } // don't fix hyperlink topics if( *helptopic != NULL && first ) { htopic = fixHelpTopic( *helptopic ); } else if( *helptopic == NULL ) { len = 1; htopic = HelpMemAlloc( len ); htopic[0] = '\0'; } else { len = strlen( *helptopic ); htopic = HelpMemAlloc( len + 1 ); strcpy( htopic, *helptopic ); } nexttopic( htopic ); for( ;; ) { err = findhelp( &tabFilter ); if( err != HELP_OK ) break; if( curEvent == EV_ESCAPE ) break; if( curEvent == EV_KILL_UI ) { break; } } SearchDlgFini(); help_close(); // This is Not Nice - we're freeing memory that // someone else allocated! Just don't do it. if( err != HELP_NO_SUBJECT ) { if( *helptopic != NULL ) { HelpMemFree( *helptopic ); *helptopic = NULL; } *filename = '\0'; } HelpMemFree( helpInBuf ); HelpMemFree( helpOutBuf ); HelpMemFree( htopic ); if( helpTab != NULL && helpCur->key2_len != 0 ) { // cross file link len = helpCur->key1_len; *helptopic = ptr = HelpMemAlloc( len + 1 ); strncpy( ptr, helpCur->keyword, len ); ptr[len] = '\0'; ptr = helpCur->keyword + len; len = helpCur->key2_len; strncpy( filename, ptr, len ); filename[len] = '\0'; if( helpCur != tabFilter.curr ) { // backwards through cross file link prevtopic(); } } else { Free_Stack(); } free_fields( &helpTab ); return( err ); }
static void doFillFileList( char *cur, FileList *list ) { char done; char *path; unsigned len; char buf[ _MAX_PATH ]; done = 0; len = strlen( cur ) + 1; path = HelpMemAlloc( len + 2 ); strcpy( path, cur ); cur = path; for( ;; ) { #ifdef __UNIX__ while( *cur != ':' ) { #else while( *cur != ';' ) { #endif if( *cur == '\0' ) { done = 1; break; } cur++; } *cur = '\0'; strcpy( buf, path ); len = strlen( buf ); #ifdef __UNIX__ if( buf[len] == '/' ) buf[len] = '\0'; #else if( buf[len] == '/' || buf[len] == '\\' ) buf[len] = '\0'; #endif scanDirectory( buf, list ); if( done ) break; path = cur + 1; cur = path; } } static void fillFileList( HelpSrchPathItem *srch, FileList *list ) { unsigned i; char *cur; unsigned done; done = 0; for( i = 0 ;; i++ ) { switch( srch[i].type ) { #ifndef __NETWARE_386__ case SRCHTYPE_ENV: cur = getenv( srch[i].info ); break; #endif case SRCHTYPE_PATH: cur = srch[i].info; break; case SRCHTYPE_EOL: done = 1; break; } if( done ) break; if( cur != NULL ) { doFillFileList( cur, list ); } } }
static unsigned scanHyperLink( char *line, TokenType *type, HyperLinkInfo *info ) { unsigned char endchar; char *cur; char *topic; char *hfname; int cnt; TextInfoBlock *block; bool chktopic; bool chkhfname; block = &(info->block1); block->next = NULL; cur = line; cnt = 0; chktopic = false; chkhfname = false; if( *(unsigned char *)cur == GOOFY_HYPERLINK ) { *type = TK_GOOFY_LINK; endchar = GOOFY_HYPERLINK; } else { *type = TK_PLAIN_LINK; endchar = '>'; } hfname = NULL; ++cur; topic = cur; for( ;; ) { switch( *(unsigned char *)cur ) { case HELP_ESCAPE: if( cnt == TEXT_BLOCK_SIZE ) { cnt = 0; block->next = HelpMemAlloc( sizeof( TextInfoBlock ) ); block = block->next; block->next = NULL; } block->info[cnt].str = cur; block->info[cnt].type = TT_ESC_SEQ; block->info[cnt].len = 2; cur += 2; cnt ++; break; case '{': case '>': case '}': case '<': if( cur[0] == cur[1] ) { cur[0] = HELP_ESCAPE; continue; // let the HELP_ESCAPE case handle this } /* fall through */ case GOOFY_HYPERLINK: if( *(unsigned char *)cur == endchar ) { info->topic = topic; block->cnt = cnt; if( chkhfname ) { info->hfname = hfname; info->hfname_len = cur - hfname; info->topic_len = hfname - topic - 1; } else { info->hfname = NULL; info->hfname_len = 0; info->topic_len = cur - topic; } return( cur - line + 1 ); } break; case HYPER_TOPIC: cur++; if( !chktopic ) { topic = cur; chktopic = true; } else { hfname = cur; chkhfname = true; } while( (*(unsigned char *)cur != endchar) && (*(unsigned char *)cur != HYPER_TOPIC) ) { if( *cur == HELP_ESCAPE ) cur++; cur++; } break; default: if( cnt == TEXT_BLOCK_SIZE ) { cnt = 0; block->next = HelpMemAlloc( sizeof( TextInfoBlock ) ); block = block->next; block->next = NULL; } block->info[cnt].str = cur; block->info[cnt].type = TT_PLAIN; block->info[cnt].len = strcspn( cur, (char *)specialHyperChars ); cur += block->info[cnt].len; cnt ++; break; } } }
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 ); }
char *HelpSearch( HelpHdl hdl ) { EVENT event; char done; char *ret; static EVENT events[] = { EV_NO_EVENT, EV_ENTER, EV_ESCAPE, EV_MOUSE_PRESS, EV_LIST_BOX_DCLICK, EV_NO_EVENT }; searchHdl = hdl; listData = hdl->header.topiccnt; curHelpDialog = uibegdialog( "Search", helpSearchDialog, 12, 60, 0, 0 ); if( editCtl.buffer == NULL ) { fillListBox( "" ); } else { fillListBox( editCtl.buffer ); } uipushlist( NULL ); /* modal barrier */ uipushlist( events ); done = 0; while( !done ) { event = uidialog( curHelpDialog ); switch( event ) { case EV_MOUSE_PRESS: if( curHelpDialog->curr != NULL ) { if( curHelpDialog->curr->ptr == &listBox ) { copyLBLinetoEditCtl( listBox.box->row ); } } break; case EV_KILL_UI: uiforceevadd( EV_KILL_UI ); /* fall through */ case EV_ESCAPE: ret = NULL; done = 1; break; case EV_ENTER: case EV_LIST_BOX_DCLICK: ret = HelpMemAlloc( MAX_EDIT_LINE_LEN ); GetLBItemLiteral( &listData, listBox.box->row, ret, MAX_EDIT_LINE_LEN ); if( ret[0] == '\0' ) { HelpMemFree( ret ); ret = NULL; } done = 1; break; } } uipoplist(); uipoplist(); uienddialog( curHelpDialog ); return( ret ); }
int showhelp( const char *topic, EVENT (*rtn)( EVENT ), HelpLangType lang ) { bool first; int err; char filename[_MAX_PATH]; const char *hfiles[] = { NULL, NULL }; char ext[_MAX_EXT]; char *buffer; char *helptopic; if( HelpFiles[0].name == NULL ) { return( HELP_NO_FILE ); } switch( lang ) { case HELPLANG_FRENCH: hotSpots[0].str = "F4=Sujet pr�c�dent"; hotSpots[1].str = "Sortir"; break; case HELPLANG_ENGLISH: break; } helpStack = NULL; currentColour = C_PLAIN; currentAttr = AT( ATTR_NORMAL ); /* initialize the tab filter */ tabFilter.tab = (unsigned (*)(void *,void *))help_in_tab; tabFilter.next = (a_tab_field *(*)(void *,void *))help_next_field; tabFilter.parm = helpTab; tabFilter.mousepos = (void *(*)(void *,ORD *, ORD *))uivmousepos; tabFilter.mouseparm = &helpScreen; tabFilter.first = helpTab; tabFilter.wrap = false; tabFilter.enter = false; _splitpath( HelpFiles[0].name, NULL, NULL, filename, ext ); strcat( filename, ext ); hfiles[0] = filename; if( topic != NULL ) { size_t len = strlen( topic ) + 1; helptopic = HelpMemAlloc( len ); memcpy( helptopic, topic, len ); } else { helptopic = NULL; } err = HELP_OK; first = true; while( helptopic != NULL || first ) { if( first || help_reinit( hfiles ) ) { err = do_showhelp( &helptopic, filename, rtn, first ); if( err == HELP_NO_SUBJECT ) { break; } } else { // cannot open help file for hyperlink buffer = HelpMemAlloc( 28 + strlen( filename ) ); sprintf( buffer, "Unable to open helpfile \"%s\".", filename ); ShowMsgBox( "Error", buffer ); HelpMemFree( buffer ); HelpMemFree( helptopic ); helptopic = HelpMemAlloc( strlen( helpStack->word ) + 1 ); strcpy( helptopic, helpStack->word ); strcpy( filename, helpStack->helpfname ); prevtopic(); } first = false; } if( helptopic != NULL ) HelpMemFree( helptopic ); return( err ); }
static EVENT hlpwait( VTAB *tab ) { bool done; static EVENT bumpev = EV_NO_EVENT; char *next_name; unsigned len1; unsigned len2; helpCur = field_find( helpTab, helpStack->cur ); if( helpTab != NULL && helpCur == NULL ) { helpCur = helpTab; } tab->other = helpCur; tab->curr = helpCur; if( helpCur != NULL ) { tab->home = helpCur->area.col; } uipushlist( helpEventList ); if( bumpev != EV_NO_EVENT ) { uitabfilter( bumpev, tab ); helpCur = tab->curr; bumpev = EV_NO_EVENT; } done = false; while( !done ) { if( helpTab != NULL ) { uivattribute( &helpScreen, helpCur->area, AT( ATTR_CURR_EDIT ) ); } do { uipushlist( keyShift ); curEvent = uivget( &helpScreen ); if( curEvent == EV_MOUSE_PRESS ) { ignoreMouseRelease = false; } uipoplist(); curEvent = uigadgetfilter( curEvent, &vGadget ); curEvent = uitabfilter( curEvent, tab ); } while( curEvent == EV_NO_EVENT ); if( eventMapFn != NULL ) { curEvent = (*eventMapFn)( curEvent ); } curEvent = uihotspotfilter( &helpScreen, hotSpotFields, curEvent ); if( helpTab != NULL ) { uivattribute( &helpScreen, helpCur->area, AT( ATTR_EDIT ) ); } switch( curEvent ) { case EV_HELP: nexttopic( helpWord ); done = true; break; case EV_BOTTOM: case E_UP: case EV_PAGE_UP: case EV_PAGE_DOWN: case EV_CURSOR_UP: case EV_CURSOR_DOWN: case EV_TOP: case E_DOWN: case EV_SCROLL_VERTICAL: if( curEvent == EV_BOTTOM ) { bumpev = EV_CURSOR_DOWN; } else if( curEvent == EV_TOP ) { bumpev = EV_CURSOR_UP; } helpStack->cur = field_count( helpTab, helpCur ); done = true; break; case '-': case EV_MOUSE_RELEASE_R: case EV_ALT_B: case 'b': case 'B': case EV_F8: case EV_F4: prevtopic(); if( strcmp( helpStack->helpfname, curFile ) ) { len1 = strlen( helpStack->word ); len2 = strlen( helpStack->helpfname ); helpCur = HelpMemAlloc( sizeof( a_field ) + len1 + len2 ); memcpy( helpCur->keyword, helpStack->word, len1 ); memcpy( helpCur->keyword + len1, helpStack->helpfname, len2 ); helpCur->keyword[len1 + len2] = '\0'; helpCur->key1_len = len1; helpCur->key2_len = len2; helpCur->next = NULL; // prevtopic(); helpTab = helpCur; } done = true; break; case EV_ALT_S: case 'S': case 's': if( helpSearchHdl != NULL ) { uipoplist(); next_name = HelpSearch( helpSearchHdl ); if( next_name != NULL ) { nexttopic( next_name ); HelpMemFree( next_name ); done = true; } uipushlist( helpEventList ); } break; case EV_FIELD_CHANGE: helpCur = tab->curr; break; case EV_MOUSE_RELEASE: if( tab->other == NULL ) break; if( ignoreMouseRelease ) { /* this mouse release is for a mouse press that occured * before this help topic was opened */ ignoreMouseRelease = false; break; } tab->other = tab->curr; /* fall through */ case EV_ENTER: /*same as page-down if there are other topics*/ case EV_F7: case '+': // DEN 90/04/12 - next line necessary for mouse release kludge helpCur = tab->curr; if( helpTab != NULL ) { if( helpCur->key2_len == 0 ) { nexttopic( helpCur->keyword ); } done = true; } break; case EV_KILL_UI: uiforceevadd( EV_KILL_UI ); /* fall through */ case EV_ESCAPE: done = true; break; } } uipoplist(); return( curEvent ); }
static void scanCallBack( TokenType type, Info *info, void *_myinfo ) { TextInfoBlock *block; bool goofy; unsigned cnt; a_field *ht; ScanInfo *myinfo = _myinfo; goofy = true; switch( type ) { case TK_TEXT: switch( info->u.text.type ) { case TT_LEFT_ARROW: myinfo->buf[0] = REAL_LEFT_ARROW; myinfo->buf++; myinfo->pos++; break; case TT_RIGHT_ARROW: myinfo->buf[0] = REAL_RIGHT_ARROW; myinfo->buf++; myinfo->pos++; break; case TT_END_OF_LINE: myinfo->buf[0] = '\0'; myinfo->buf++; myinfo->pos++; break; case TT_CTRL_SEQ: memcpy( myinfo->buf, info->u.text.str, info->u.text.len ); myinfo->buf += info->u.text.len; break; case TT_ESC_SEQ: memcpy( myinfo->buf, info->u.text.str, info->u.text.len ); myinfo->buf += info->u.text.len; myinfo->pos += 1; break; default: memcpy( myinfo->buf, info->u.text.str, info->u.text.len ); myinfo->buf += info->u.text.len; myinfo->pos += info->u.text.len; break; } break; case TK_PLAIN_LINK: myinfo->buf[0] = '<'; myinfo->buf ++; myinfo->pos ++; goofy = false; /* fall through */ case TK_GOOFY_LINK: block = &( info->u.link.block1 ); cnt = 0; ht = HelpMemAlloc( sizeof( a_field ) + info->u.link.topic_len + info->u.link.hfname_len ); ht->area.width = 0; ht->area.row = myinfo->line; ht->area.height = 1; ht->area.col = myinfo->pos; memcpy( ht->keyword, info->u.link.topic, info->u.link.topic_len ); if( info->u.link.hfname_len != 0 ) { memcpy( ht->keyword + info->u.link.topic_len, info->u.link.hfname, info->u.link.hfname_len ); ht->keyword[info->u.link.topic_len + info->u.link.hfname_len] = '\0'; } else { ht->keyword[info->u.link.topic_len] = '\0'; } ht->key1_len = info->u.link.topic_len; ht->key2_len = info->u.link.hfname_len; while( block != NULL ) { while( cnt < block->cnt ) { info = (Info *)&( block->info[cnt] ); switch( info->u.text.type ) { case TT_ESC_SEQ: memcpy( myinfo->buf, info->u.text.str, info->u.text.len ); myinfo->buf += info->u.text.len; myinfo->pos ++; ht->area.width ++; break; case TT_PLAIN: memcpy( myinfo->buf, info->u.text.str, info->u.text.len ); myinfo->buf += info->u.text.len; myinfo->pos += info->u.text.len; ht->area.width += info->u.text.len; break; } cnt++; } block = block->next; cnt = 0; } if( ht->area.col + ht->area.width > helpScreen.area.width ) { ht->area.width = helpScreen.area.width - ht->area.col; } add_field( ht, myinfo->changecurr ); if( !goofy ) { myinfo->buf[0] = '>'; myinfo->buf ++; myinfo->pos ++; } break; } }
static bool pass1( FILE *fin, char **helpstr ) { char buffer[ BUFFER_SIZE ]; int buflen; long fpos; a_helpnode *h; a_helpnode **hn; char *ptr; int cmp; char *namebuff; unsigned namebuff_len; int count; int len; unsigned topic_len; unsigned desc_len; namebuff = NULL; namebuff_len = 0; topic_len = strlen( DEFTOPIC ); desc_len = strlen( DESCRIPTION ); printf( "Pass One:\n" ); fpos = 0; while( !feof( fin ) ) { fpos = ftell( fin ); fgetstring( buffer, BUFFER_SIZE, fin ); if( memcmp( buffer, DEFTOPIC, topic_len ) == 0 ) { if( helpstr[0] != NULL ) { PrintError( "more than one DEFTOPIC found\n" ); } else { if( !GenStrings || !GenIndex ) { PrintError( "DEFTOPIC string ignored with this format.\n" ); } if( GenStrings ) { ptr = find_str( &buffer[topic_len] ); helpstr[0] = HelpMemAlloc( strlen( ptr ) + 1 ); strcpy( helpstr[0], ptr); } } } else if( memcmp( buffer, DESCRIPTION, desc_len ) == 0 ) { if( helpstr[1] != NULL ) { PrintError( "more than one DESCRIPTION found\n" ); } else { if( !GenStrings || !GenIndex ) { PrintError( "DESCRIPTION string ignored with this format.\n" ); } if( GenStrings ) { ptr = find_str( &buffer[desc_len] ); helpstr[1] = HelpMemAlloc( strlen( ptr ) + 1 ); strcpy( helpstr[1], ptr ); } } } else if( memcmp( buffer, "::::", 4 ) == 0 ) break; } while( !feof( fin ) ) { h = (a_helpnode *)HelpMemAlloc( sizeof( a_helpnode ) ); h->fpos = fpos; buflen = strlen( buffer ); if( buffer[ buflen-1 ] == '\n' ) { buffer[ buflen-1 ] = '\0'; } h->maxrow = 0; h->maxcol = 0; h->row = -1; h->col = -1; h->lines = -1; ptr = &buffer[4]; if( *ptr == '"' ) { ptr ++; while( *ptr != '\0' && *ptr != '"' ) { if( *ptr == HELP_ESCAPE ) ptr++; ptr++; } len = ptr - &buffer[5]; if( namebuff_len <= len ) { HelpMemFree( namebuff ); namebuff = HelpMemAlloc( len + 1 ); namebuff_len = len + 1; } memcpy( namebuff, &buffer[5], len ); namebuff[len] = '\0'; if( *ptr == '"' ) ++ptr; } else { for( ; *ptr != '\0' && !isspace(*ptr); ++ptr ) ; while( *ptr != '\0' && !isspace(*ptr) ) { if( *ptr == HELP_ESCAPE ) ptr++; ptr++; } len = ptr - &buffer[4]; if( namebuff_len <= len ) { HelpMemFree( namebuff ); namebuff = HelpMemAlloc( len + 1 ); namebuff_len = len + 1; } memcpy( namebuff, &buffer[4], len ); namebuff[len] = '\0'; } while( isspace( *ptr ) ) ++ptr; if( *ptr != '\0' ) { count = sscanf( ptr, "%d %d %d %d %d", &h->maxrow, &h->maxcol, &h->row, &h->col, &h->lines ); if( count != 2 && count != 4 && count != 5 ) { PrintError( "invalid help topic line '%s'\n", buffer ); } } h->name = strdup( namebuff ); if( Verbose ) { printf( " %s\n", h->name ); } for( hn=&HelpNodes; *hn != NULL; hn=&(*hn)->next ) { cmp = stricmp( h->name, (*hn)->name ); if( cmp == 0 ) { PrintError( "Duplicate Help Topic '%s'\n", h->name ); } if( cmp <= 0 ) { h->next = *hn; *hn = h; break; } } if( *hn == NULL ) { h->next = NULL; *hn = h; } if( h->row == -1 ) { h->row = 0; h->col = 0; } h->maxcol = 0; h->maxrow = 0; h->lines = 0; while( !feof( fin ) ) { fpos = ftell( fin ); fgetstring( buffer, BUFFER_SIZE, fin ); if( memcmp( buffer, "::::", 4 ) == 0 ) break; if( strnicmp( buffer, ":eh", 3 ) == 0 || strnicmp( buffer, ":et", 3 ) == 0 ) { h->lines = 0; } else if( strnicmp( buffer, ":h", 2 ) == 0 || strnicmp( buffer, ":t", 2 ) == 0 ) { } else { buflen = line_len( buffer ); if( buflen - 1 > h->maxcol ){ h->maxcol = buflen - 1; } h->lines += 1; h->maxrow += 1; } } } HelpMemFree( namebuff ); return( TRUE ); }