コード例 #1
0
static void SetDict( file_list *lib, unsigned dict_page )
/*******************************************************/
/* set lib->buffer to the dict_page th page in lib 's dictionary */
{
    unsigned        pages;
    unsigned        num_buckets;
    unsigned        residue;
    unsigned        bucket;
    long   off;
    long   dictoff;
    omf_dict_entry  *dict;

    dict = &lib->u.dict->o;
    if( dict->cache == NULL ) {
        pages = dict->pages;
        num_buckets = pages / PAGES_IN_CACHE;
        residue = pages - num_buckets * PAGES_IN_CACHE;
        dict->cache = AllocDict( num_buckets, residue );
        if( dict->cache != NULL ) {
            QSeek( lib->file->handle, dict->start, lib->file->name );
            for( bucket = 0; bucket < num_buckets; ++bucket ) {
                QRead( lib->file->handle, dict->cache[ bucket ], DIC_REC_SIZE * PAGES_IN_CACHE, lib->file->name );
            }
            QRead( lib->file->handle, dict->cache[bucket], DIC_REC_SIZE * residue, lib->file->name );
            lib->file->currpos = dict->start + DIC_REC_SIZE * ( residue + PAGES_IN_CACHE * num_buckets );
        }
    }
    if( dict->cache == NULL ) {
        off = dict_page * DIC_REC_SIZE;
        dictoff = dict->start + off;
        dict->buffer = (unsigned_8 *)TokBuff;
        QSeek( lib->file->handle, dictoff, lib->file->name );
        QRead( lib->file->handle, dict->buffer, DIC_REC_SIZE, lib->file->name );
        lib->file->currpos = dictoff + DIC_REC_SIZE;
    } else {
        bucket = dict_page / PAGES_IN_CACHE;
        residue = dict_page - bucket * PAGES_IN_CACHE;
        dict->buffer = (unsigned_8 *)dict->cache[bucket] + residue * DIC_REC_SIZE;
    }
}
コード例 #2
0
ファイル: mixcache.c プロジェクト: Ukusbobra/open-watcom-v2
void *CacheRead( file_list *list, unsigned long pos, unsigned len )
/**************************************************************************/
/* read len bytes out of the cache. */
{
    unsigned        bufnum;
    unsigned        startnum;
    unsigned        offset;
    unsigned        amtread;
    char            *result;
    char            **cache;
    unsigned long   newpos;
    infilelist      *file;

    if( list->file->flags & INSTAT_FULL_CACHE ) {
        if( pos + len > list->file->len )
            return( NULL );
        return( (char *)list->file->cache + pos );
    }
    Multipage = FALSE;
    file = list->file;
    offset = pos % CACHE_PAGE_SIZE;
    amtread = CACHE_PAGE_SIZE - offset;
    startnum = pos / CACHE_PAGE_SIZE;
    bufnum = startnum;
    cache = file->cache;
    for( ;; ) {
        if( cache[ bufnum ] == NULL ) {   // make sure page is in.
            _ChkAlloc( cache[ bufnum ], CACHE_PAGE_SIZE );
            newpos = (unsigned long)bufnum * CACHE_PAGE_SIZE;
            if( file->currpos != newpos ) {
                QSeek( file->handle, newpos, file->name );
            }
            file->currpos = newpos + CACHE_PAGE_SIZE;
            QRead( file->handle, cache[ bufnum ], CACHE_PAGE_SIZE, file->name );
        }
        if( amtread >= len )
            break;
        amtread += CACHE_PAGE_SIZE;     // it spans pages.
        bufnum++;
        Multipage = TRUE;
    }
    if( !Multipage ) {
        result = cache[ startnum ] + offset;
    } else {
        if( len > TokSize ) {
            TokSize = ROUND_UP( len, SECTOR_SIZE );
            _LnkReAlloc( TokBuff, TokBuff, TokSize );
        }
        amtread = CACHE_PAGE_SIZE - offset;
        memcpy( TokBuff, cache[ startnum ] + offset, amtread );
        len -= amtread;
        result = TokBuff + amtread;
        for( ;; ) {
            startnum++;
            if( len <= CACHE_PAGE_SIZE ) {
                memcpy( result, cache[ startnum ], len );
                break;
            } else {
                memcpy( result, cache[ startnum ], CACHE_PAGE_SIZE );
                len -= CACHE_PAGE_SIZE;
                result += CACHE_PAGE_SIZE;
            }
        }
        result = TokBuff;
    }
    return( result );
}
コード例 #3
0
ファイル: spillio.c プロジェクト: Azarien/open-watcom-v2
void SpillWrite( virt_mem_size base, size_t off, const void *mem, size_t size )
/*****************************************************************************/
{
    QSeek( TempFile, base + (unsigned long)off - 1, TFileName );
    QWrite( TempFile, mem, size, TFileName );
}
コード例 #4
0
ファイル: spillio.c プロジェクト: Azarien/open-watcom-v2
void SpillRead( virt_mem_size base, size_t off, void *mem, size_t size )
/**********************************************************************/
{
    QSeek( TempFile, base + (unsigned long)off - 1, TFileName );
    QRead( TempFile, mem, size, TFileName );
}
コード例 #5
0
ファイル: spillio.c プロジェクト: Azarien/open-watcom-v2
void SpillNull( virt_mem_size base, size_t off, size_t size )
/***********************************************************/
{
    QSeek( TempFile, base + (unsigned long)off - 1, TFileName );
    WriteNulls( TempFile, size, TFileName );
}