Exemplo n.º 1
0
extern void StartNewFile( char *fname )
/*************************************/
{
    cmdfilelist *   newfile;
    unsigned long   size;

    newfile = MemAlloc( sizeof( cmdfilelist ) );
    newfile->name = fname;
    newfile->file = NIL_HANDLE;
    newfile->next = CmdFile;
    CmdFile = newfile;
    CmdFile->buffer = NULL;
    newfile->file = QOpenR( newfile->name );
    size = QFileSize( newfile->file );
    if( size < 65510 ) {       // if can alloc a chunk big enough
        CmdFile->buffer = MemAlloc( size + 1 );
        if( CmdFile->buffer != NULL ) {
            size = QRead( newfile->file, CmdFile->buffer, size, newfile->name );
            *(CmdFile->buffer + size) = '\0';
            CmdFile->where = MIDST;
            CmdFile->how = BUFFERED;
            CmdFile->current = CmdFile->buffer;
        }
    }
    if( CmdFile->buffer == NULL ) {  // if couldn't buffer for some reason.
        CmdFile->where = ENDOFLINE;
        CmdFile->how = NONBUFFERED;
        CmdFile->buffer = MemAlloc( MAX_LINE + 1 );// have to have at least this
        CmdFile->current = CmdFile->buffer;        // much RAM or death ensues.
    }
}
Exemplo n.º 2
0
bool CacheOpen( file_list *list )
/**************************************/
{
    infilelist  *file;
    unsigned    numblocks;
    char        **cache;

    if( list == NULL )
        return( TRUE );
    file = list->file;
    if( file->flags & INSTAT_IOERR )
        return( FALSE );
    if( DoObjOpen( file ) ) {
        file->flags |= INSTAT_IN_USE;
    } else {
        file->flags |= INSTAT_IOERR;
        return( FALSE );
    }
    if( file->len == 0 ) {
        file->len = QFileSize( file->handle );
        if( file->len == 0 ) {
            LnkMsg( ERR+MSG_BAD_OBJECT, "s", file->name );
            file->flags |= INSTAT_IOERR;
            return( FALSE );
        }
    }
    if( !(file->flags & INSTAT_SET_CACHE) ) {
        if( LinkFlags & CACHE_FLAG ) {
            file->flags |= INSTAT_FULL_CACHE;
        } else if( LinkFlags & NOCACHE_FLAG ) {
            file->flags |= INSTAT_PAGE_CACHE;
        } else {
            if( file->flags & INSTAT_LIBRARY ) {
                file->flags |= INSTAT_PAGE_CACHE;
            } else {
                file->flags |= INSTAT_FULL_CACHE;
            }
        }
    }
    if( file->cache == NULL ) {
        if( file->flags & INSTAT_FULL_CACHE ) {
            _ChkAlloc( file->cache, file->len );
            if( file->currpos != 0 ) {
                QLSeek( file->handle, 0, SEEK_SET, file->name );
            }
            QRead( file->handle, file->cache, file->len, file->name );
            file->currpos = file->len;
        } else {
            numblocks = NumCacheBlocks( file->len );
            _Pass1Alloc( file->cache, numblocks * sizeof( char * ) );
            cache = file->cache;
            while( numblocks > 0 ) {
                *cache = NULL;
                cache++;
                numblocks--;
            }
        }
    }
    return( TRUE );
}
Exemplo n.º 3
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;
    }
}
Exemplo n.º 4
0
static void WriteQNXResource( void )
/**********************************/
{
    unsigned long   len;
    lmf_record      rec;
    f_handle        file;
    lmf_resource    resource;
    void *          buf;

    if( FmtData.resource != NULL ) {
        rec.reserved = 0;
        rec.spare = 0;
        rec.rec_type = LMF_RESOURCE_REC;
        memset( &resource, 0, sizeof( lmf_resource ) );
        if( FmtData.res_name_only ) {
            file = QObjOpen( FmtData.resource );
            if( file == NIL_FHANDLE ) {
                PrintIOError( WRN+MSG_CANT_OPEN_NO_REASON, "s",
                                        FmtData.resource );
                return;
            }
            len = QFileSize( file );
            if( len + sizeof(lmf_resource) > QNX_MAX_REC_SIZE ) {
                LnkMsg( WRN+MSG_RESOURCE_TOO_BIG, "s", FmtData.resource );
                return;
            }
            _ChkAlloc( buf, len );
            rec.data_nbytes = len + sizeof( lmf_resource );
            WriteLoad( &rec, sizeof( lmf_record ) );
            WriteLoad( &resource, sizeof( lmf_resource ) );
            QRead( file, buf, len, FmtData.resource );
            WriteLoad( buf, len );
            _LnkFree( buf );
            QClose( file, FmtData.resource );
        } else {
            len = strlen( FmtData.resource );
            FmtData.resource[len] = '\n';
            len++;
            rec.data_nbytes = len + sizeof( lmf_resource );
            WriteLoad( &rec, sizeof( lmf_record ) );
            WriteLoad( &resource, sizeof( lmf_resource ) );
            WriteLoad( FmtData.resource, len );
        }
    }
}
Exemplo n.º 5
0
bool QReadStr( f_handle file, char *dest, unsigned size, char *name )
/**************************************************************************/
/* quick read string (for reading directive file) */
{
    bool            eof;
    char            ch;

    eof = FALSE;
    while( --size > 0 ) {
        if( QRead( file, &ch, 1, name ) == 0 ) {
            eof = TRUE;
            break;
        } else if( ch != '\r' ) {
            *dest++ = ch;
        }
        if( ch == '\n' ) break;
    }
    *dest = '\0';
    return( eof );
}
Exemplo n.º 6
0
bool QReadStr( f_handle file, char *dest, size_t size, const char *name )
/***********************************************************************/
/* quick read string (for reading directive file) */
{
    bool            eof;
    char            ch;

    eof = false;
    while( --size > 0 ) {
        if( QRead( file, &ch, 1, name ) == 0 ) {
            eof = true;
            break;
        } else if( ch != '\r' ) {
            *dest++ = ch;
        }
        if( ch == '\n' ) {
            break;
        }
    }
    *dest = '\0';
    return( eof );
}
Exemplo n.º 7
0
int CopyFile( const char * file1, const char * file2 )
/****************************************************/
{
    size_t                  len;
    auto struct stat        statblk;
    auto struct utimbuf     utimebuf;

    remove( file2 );
    OutFile = NOFILE;
    InFile = QOpen( file1, O_RDONLY | O_BINARY, 0 );
    OutFile = QOpen( file2, O_WRONLY | O_TRUNC | O_CREAT | O_BINARY, 0 );
    while( (len = QRead( InFile, InputBuffer, MAX_OBJECT_REC_SIZE )) != 0 ) {
        QWrite( OutFile, InputBuffer, len );
    }
    CloseFiles();
    if( stat( file1, &statblk ) == 0 ) {
        utimebuf.actime = statblk.st_atime;
        utimebuf.modtime = statblk.st_mtime;
        utime( file2, &utimebuf );
    }
    return( OK );
}
Exemplo n.º 8
0
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 );
}
Exemplo n.º 9
0
static wio_ssize_t res_read( WResFileID handle, void *buffer, wio_size_t len )
/****************************************************************************/
{
    return( QRead( handle, buffer, len, NULL ) );
}
Exemplo n.º 10
0
static ssize_t ResRead( int handle, void *buffer, size_t len )
/************************************************************/
{
    return( QRead( handle, buffer, len, NULL ) );
}
Exemplo n.º 11
0
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 );
}