Пример #1
0
static void freeFileList( FileList *list )
{
    unsigned            i;

    for( i = 0; i < list->used; i++ ) {
        HelpMemFree( list->items[i]->fpath );
        HelpMemFree( list->items[i]->fname );
        HelpMemFree( list->items[i] );
    }
    HelpMemFree( list );
}
Пример #2
0
static void freeSearchList( void )
{
    unsigned    i;

    if( srch_List != NULL ) {
        i = 0;
        for( ;; i++ ) {
            HelpMemFree( srch_List[i].info );
            if( srch_List[i].type == SRCHTYPE_EOL ) break;
        }
        HelpMemFree( srch_List );
        srch_List = NULL;
    }
}
Пример #3
0
void FiniHelpSearch( HelpHdl hdl )
{
    if( hdl != NULL ) {
        if( hdl->itemindex != NULL ) {
            HelpMemFree( hdl->itemindex );
        }
        if( hdl->def_topic != NULL ) {
            HelpMemFree( hdl->def_topic );
        }
        if( hdl->desc_str != NULL ) {
            HelpMemFree( hdl->desc_str );
        }
        HelpMemFree( hdl );
    }
}
Пример #4
0
void check_buffer( a_helpnode *h, char *buffer )
{
    ScanLine( buffer, checkBufCB, h );
    HelpMemFree( nameBuf );
    nameBuf = NULL;
    nameBufLen = 0;
}
Пример #5
0
void Free_Stack( void )
{
    while( helpStack->next != NULL ) {
        prevtopic();
    }
    HelpMemFree( helpStack );
}
Пример #6
0
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 );
}
Пример #7
0
static void freeHyperlinkInfo( TextInfoBlock *cur )
{
    TextInfoBlock       *tmp;

    while( cur != NULL ) {
        tmp = cur;
        cur = cur->next;
        HelpMemFree( tmp );
    }
}
Пример #8
0
static void replacetopic( char *word )
{
    if( helpStack->next == NULL ) {
        HelpMemFree( helpStack );
        helpStack = NULL;
    } else {
        prevtopic();
    }
    nexttopic( word );
}
Пример #9
0
void helpfini( void )
{
    int         count;

    for( count=0; count < MAX_HELP_FILES - 1; ++count ) {
        if( HelpFiles[count].name == NULL ) break;
        HelpMemFree( HelpFiles[count].name );
        HelpFiles[count].name = NULL;
    }
    freeSearchList();
}
Пример #10
0
static void prevtopic( void )
{
    a_hstackent         *h;

    if( helpStack->next != NULL ) {
        h = helpStack;
        helpStack = helpStack->next;
        HelpMemFree( h );
    }
    free_fields( &helpTab );
}
Пример #11
0
void main( int argc, char *argv[] )
{
    HelpFp              fp;
    HelpHdl             hdl;
    char                name[_MAX_PATH];
    char                *cur;
    HelpSrchInfo        cursor;
    unsigned            i;

    if( argc != 2 ) {
        printf( "USAGE:\n" );
        printf( "exename <help file>\n" );
        return;
    }
    fp = HelpOpen( argv[1], HELP_OPEN_RDONLY | HELP_OPEN_BINARY );
    if( fp == -1 ) {
        printf( "Unable to open %s\n", argv[1] );
        return;
    }
    TRMemOpen();
    hdl = InitHelpSearch( fp );
    for( ;; ) {
        gets( name );
        if( !strcmp( name, "bob" ) ) break;
        cur = HelpFindFirst( hdl, name, &cursor );
        for( i=0; i < 5; i++ ) {
            if( cur == NULL ) break;
            printf( "     %s\n", cur );
            HelpMemFree( cur );
            cur = HelpFindNext( &cursor );
        }
        if( cur != NULL ) {
            HelpMemFree( cur );
        }
    }
    FiniHelpSearch( hdl );
    HelpClose( fp );
    TRMemClose();
}
Пример #12
0
static void del_field( a_field *table, a_field **field, bool changecurr )
{
    a_field             *next;
    int                 count;

    count = field_count( table, *field );
    if( *field == tabFilter.curr ) {
        tabFilter.curr = NULL;
    }
    if( changecurr && count < helpStack->cur ) {
        helpStack->cur -= 1;
    }
    next = (*field)->next;
    HelpMemFree( *field );
    *field = next;
    tabFilter.first = helpTab;
}
Пример #13
0
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 );
        }
    }
}
Пример #14
0
/*
 * 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 );
}
Пример #15
0
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 );
}
Пример #16
0
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 );
}
Пример #17
0
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 );
}
Пример #18
0
int main( int argc, char **argv )
{
    char        **nargv;
    char        **sargv;
    FILE        *fin;
    int         fout;
    char        *helpstr[2];
    bool        f_swtch;

    f_swtch = FALSE;
    helpstr[0] = NULL;
    helpstr[1] = NULL;
    for( argc=1, sargv=nargv=argv+1; *sargv; ++sargv ) {
        if( ! _IsCmdSwitch( *sargv ) ) {
            *nargv++ = *sargv;
            argc++;
        } else {
            switch( (*sargv)[1] ) {
            case 'n':
                GenIndex = FALSE;
                if( f_swtch ) {
                    PrintError( "More than one format switch found in command line\n" );
                    Usage();
                }
                f_swtch = TRUE;
                break;
            case 'v':
                Verbose = TRUE;
            break;
            case 'c':
                if( (*sargv)[2] != '\0' ) {
                    MaxCol = atoi( &(*sargv)[2] );
                } else {
                    if( *++sargv == NULL )
                        Usage();
                    MaxCol = atoi( *sargv );
                }
                break;
            case 'r':
                if( (*sargv)[2] != '\0' ) {
                    MaxRow = atoi( &(*sargv)[2] );
                } else {
                    if( *++sargv == NULL )
                        Usage();
                    MaxRow = atoi( *sargv );
                }
                break;
            case 'h':
                if( (*sargv)[2] != '\0' ) {
                    Height = atoi( &(*sargv)[2] );
                } else {
                    if( *++sargv == NULL )
                        Usage();
                    Height = atoi( *sargv );
                }
                break;
            case 'w':
                if( (*sargv)[2] != '\0' ) {
                    Width = atoi( &(*sargv)[2] );
                } else {
                    if( *++sargv == NULL )
                        Usage();
                    Width = atoi( *sargv );
                }
                break;
            case 'f':
                if( f_swtch ) {
                    PrintError( "More than one format switch found in command line\n" );
                    Usage();
                }
                f_swtch = TRUE;
                if( (*sargv)[2] == '0' ) {
                    GenIndex = FALSE;
                } else if( (*sargv)[2] == '1' ) {
                    GenStrings = FALSE;
                } else if( (*sargv)[2] == '2' ) {
                    GenStrings = TRUE;
                } else {
                    Usage();
                }
                break;
            default:
                Usage();
            break;
            }
        }
    }

    if( argc > 1  &&  strcmp( argv[1], "?" ) == 0 ) {
        Usage();
    }

    if( argc != 3 ) {
        Usage();
    }

    InitError( argv[1] );
    fin = fopen( argv[1], "rt" );
    if( fin == NULL ) {
        PrintError( "Unable to open '%s' for input\n", argv[1] );
        return( -1 );
    }

    fout = open( argv[2], O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, PMODE_RW );
    if( fout == -1 ) {
        PrintError( "Unable to open '%s' for output\n", argv[2] );
        return( -1 );
    }

    pass1( fin, helpstr );
    pass2( fin, fout, helpstr );

    fclose( fin );
    close( fout );
    if( GenIndex ) {
        fout = open( argv[2], O_WRONLY | O_BINARY );
        WriteIndex( fout, helpstr, GenStrings );
        close( fout );
    }
    FiniError();
    HelpMemFree( helpstr[0] );
    HelpMemFree( helpstr[1] );
    return( 0 );
}
Пример #19
0
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 );
}
Пример #20
0
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 );
}
Пример #21
0
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 );
}