Esempio n. 1
0
/*
 * SpecialFgets - get from either file or exe
 */
bool SpecialFgets( char *buff, int max, GENERIC_FILE *gf )
{
    size_t      len;
    vi_rc       rc;

    switch( gf->type ) {
    case GF_FILE:
        if( fgets( buff, max, gf->data.f ) == NULL ) {
            return( true );
        }
        for( len = strlen( buff ); len > 0 && isWSorCtrlZ( buff[len - 1] ); --len ) {
            buff[len - 1] = '\0';
        }
        break;
    case GF_BOUND:
        if( gf->gf.a.currline >= gf->gf.a.maxlines ) {
            return( true );
        }
        gf->gf.a.currline++;
        if( BndMemory == NULL ) {
            read( gf->data.handle, buff, gf->gf.a.length + 1 );
        } else {
            memcpy( buff, gf->data.pos, gf->gf.a.length + 1 );
            gf->data.pos += gf->gf.a.length + 1;
        }
        len = gf->gf.a.length;
        gf->gf.a.length = (unsigned char)buff[len];
        buff[len] = '\0';
        break;
    default:
        if( gf->data.cfile == NULL ) {
            return( true );
        }
        memcpy( buff, gf->gf.b.cline->data, gf->gf.b.cline->len + 1 );
        rc = GimmeNextLinePtr( gf->data.cfile, &(gf->gf.b.cfcb), &(gf->gf.b.cline) );
        if( rc != ERR_NO_ERR ) {
            gf->data.cfile = NULL;
        }
        break;
    }
    return( false );

} /* SpecialFgets */
Esempio n. 2
0
/*
 * displayGenericLines - display all lines in a window
 */
static vi_rc displayGenericLines( file *f, linenum pagetop, int leftcol,
                                linenum hilite, type_style *style, hilst *hilist,
                                char **vals, int valoff )
{
    int         i, j, k, text_lines;
    linenum     cl = pagetop;
    fcb         *cfcb, *tfcb;
    line        *cline;
    hilst       *ptr;
    type_style  *text, *hot_key;
    window_info *info;
    type_style  base;
    char        tmp[MAX_STR];
//    bool        disabled;
    vi_rc       rc;

    /*
     * get pointer to first line on page, and window info
     */
    rc = GimmeLinePtr( pagetop, f, &cfcb, &cline );
    if( rc != ERR_NO_ERR ) {
        return( rc );
    }
    base.foreground = WindowAuxInfo( cWin, WIND_INFO_TEXT_COLOR );
    base.background = WindowAuxInfo( cWin, WIND_INFO_BACKGROUND_COLOR );
    base.font = WindowAuxInfo( cWin, WIND_INFO_TEXT_FONT );
    text_lines = WindowAuxInfo( cWin, WIND_INFO_TEXT_LINES );

    /*
     * mark all fcb's as being not in display
     */
    for( tfcb = f->fcbs.head; tfcb != NULL; tfcb = tfcb->next ) {
        tfcb->on_display = FALSE;
    }
    cfcb->on_display = TRUE;

    /*
     * run through each line in the window
     */
    ptr = hilist;
    if( ptr != NULL ) {
        ptr += pagetop - 1;
    }
    for( j = 1; j <= text_lines; j++ ) {
        if( cline != NULL ) {
            if( isMenu ) {
                if( InvokeMenuHook( CurrentMenuNumber, cl ) == -1 ) {
//                    disabled = TRUE;
                    if( cl == hilite ) {
                        info = &activegreyedmenu_info;
                    } else {
                        info = &greyedmenu_info;
                    }
                } else {
//                    disabled = FALSE;
                    if( cl == hilite ) {
                        info = &activemenu_info;
                    } else {
                        info = &menuw_info;
                    }
                }
                text = &info->text;
                hot_key = &info->hilight;
            } else {
                text = &base;
                if( cl == hilite ) {
                    text = style;
                }
                hot_key = text;
            }

            /*
             * now, display what we can of the line on the window
             */
            if( cline->len == 0 ) {
                DisplayCrossLineInWindow( cWin, j );
                goto evil_goto;
            } else if( cline->len > leftcol ) {
                if( vals != NULL ) {
                    i = cline->len - leftcol;
                    strncpy( tmp, &(cline->data[leftcol]), EditVars.WindMaxWidth + 5 );
                    for( k = i; k < valoff; k++ ) {
                        tmp[k] = ' ';
                    }
                    tmp[k] = 0;
                    strcat( tmp, vals[j + pagetop - 2] );
                    DisplayLineInWindowWithColor( cWin, j, tmp, text, 0 );
                } else {
                    DisplayLineInWindowWithColor( cWin, j, cline->data, text, leftcol );
                }
            } else {
                DisplayLineInWindowWithColor( cWin, j, SingleBlank, text, 0 );
            }
            if( ptr != NULL ) {
                SetCharInWindowWithColor( cWin, j, 1 + ptr->_offs, ptr->_char, hot_key );
            }
evil_goto:  if( ptr != NULL ) {
                ptr += 1;
            }
            rc = GimmeNextLinePtr( f, &cfcb, &cline );
            if( rc != ERR_NO_ERR ) {
                if( rc == ERR_NO_MORE_LINES ) {
                    continue;
                }
                return( rc );
            }
            cl++;
            cfcb->on_display = TRUE;
        } else {
            DisplayLineInWindow( cWin, j, "~" );
        }

    }
    return( ERR_NO_ERR );

} /* displayGenericLines */
Esempio n. 3
0
/*
 * CGimmeNextLinePtr - get pointer to next line in current file
 */
vi_rc CGimmeNextLinePtr( fcb **cfcb, line **cline )
{
    return( GimmeNextLinePtr( CurrentFile, cfcb, cline ) );

} /* CGimmeNextLinePtr */