Exemplo n.º 1
0
Arquivo: libio.c Projeto: JWasm/JWlink
void LibSeek( libfile lio, long where, int whence )
{
    if( lio->access & O_WRONLY ) {
        LibFlush( lio );
    } else {
        if( whence == SEEK_END ) {
            where += filelength( lio->io ) - LibTell( lio );
            whence = SEEK_CUR;
        } else if( whence == SEEK_SET ) {
            where -= LibTell( lio );
            whence = SEEK_CUR;
        }
        if( ( lio->buf_pos >= -where ) && ( lio->buf_pos + where < lio->buf_size ) ) {
            lio->buf_pos += where;
            return;
        }
        where -= lio->buf_size - lio->buf_pos;
    }
    lseek( lio->io, where, whence );
    lio->buf_size = 0;
    lio->buf_pos = 0;
}
Exemplo n.º 2
0
void OMFLibWalk( libfile io, char *name, void (*rtn)( arch_header *arch, libfile io ) )
/*************************************************************************************/
{
    long            pagelen;
    long            offset;
    arch_header     arch;
    char            buff[ MAX_IMPORT_STRING ];
    int             len;
    unsigned_16     rec_len;
    unsigned_8      type;

    if( LibRead( io, &type, 1 ) != 1 )
        return; // nyi - FALSE?
    if( LibRead( io, &rec_len, 2 ) != 2 )
        return;
    offset = GET_LE_16( rec_len );
    pagelen = offset + 3;
    if( Options.page_size == 0 ) {
        Options.page_size = pagelen;
    }
    LibSeek( io, offset, SEEK_CUR );
    NewArchHeader( &arch, name );
    offset = LibTell( io );
    while( LibRead( io, &type, 1 ) == 1 && ( type == CMD_THEADR ) ) {
        LibSeek( io, 2, SEEK_CUR );
        if( LibRead( io, &type, 1 ) != 1 )
            break;
        len = type;
        if( LibRead( io, buff, len ) != len )
            break;
        buff[ len ] = '\0';
        arch.name = buff;
        LibSeek( io, offset, SEEK_SET );
        rtn( &arch, io );
        offset = LibTell( io );
        offset = ( offset + pagelen - 1 ) & ~( pagelen - 1 );
        LibSeek( io, offset, SEEK_SET );
    }
}
Exemplo n.º 3
0
void LibSeek( libfile lio, long where, int whence )
{
    if( lio->write_to ) {
        LibFlush( lio );
    } else {
        if( whence == SEEK_END ) {
            where += lio->endpos - LibTell( lio );
            whence = SEEK_CUR;
        } else if( whence == SEEK_SET ) {
            where -= LibTell( lio );
            whence = SEEK_CUR;
        }
        if( ( lio->buf_pos >= -where ) && ( lio->buf_pos + where < lio->buf_size ) ) {
            lio->buf_pos += where;
            return;
        }
        where -= lio->buf_size - lio->buf_pos;
    }
    fseek( lio->io, where, whence );
    lio->buf_size = 0;
    lio->buf_pos = 0;
}
Exemplo n.º 4
0
void LibWalk( libfile io, char *name, void (*rtn)( arch_header *, libfile io ) )
/******************************************************************************/
{
    ar_header           ar;
    arch_header         arch;
    file_offset         bytes_read;
//    int                 dict_count;
    file_offset         pos;

//    dict_count = 0;
    arch.fnametab = NULL;
    arch.ffnametab = NULL;
    while( (bytes_read = LibRead( io, &ar, AR_HEADER_SIZE )) != 0 ) {
        if( bytes_read != AR_HEADER_SIZE ) {
            BadLibrary( name );
        }
        if( strncmp( ar.header_ident, AR_HEADER_IDENT, AR_HEADER_IDENT_LEN ) ) {
            BadLibrary( name );
        }
        GetARHeaderValues( &ar, &arch );
        pos = LibTell( io );
        if( ar.name[ 0 ] == '/' && ar.name[ 1 ] == ' ' && ar.name[ 2 ] == ' ' ) {
            // Ignore symbol table.
/*
            dict_count++;
            if( dict_count == 2 ) {
                error = readDict( &arch );
            } else {
                error = MoveAheadFrom( &arch );
                updateNewArchive( &arch );
            }
*/
        } else if( ar.name[ 0 ] == '/' && ar.name[ 1 ] == '/' && ar.name[ 2 ] == ' ' ) {
            AllocFNameTab( name, io, &arch );
        } else if( ar.name[ 0 ] == '/' && ar.name[ 1 ] == '/' && ar.name[ 2 ] == '/' ) {
            AllocFFNameTab( name, io, &arch );
        } else {
            arch.name = GetARName( io, &ar, &arch );
            arch.ffname = GetFFName( &arch );
            rtn( &arch, io );
            MemFree( arch.name );
            MemFree( arch.ffname );
        }
        if( arch.size & 1 )
            ++arch.size;
        LibSeek( io, pos + arch.size, SEEK_SET );
    }
    MemFree( arch.fnametab );
    MemFree( arch.ffnametab );
}
Exemplo n.º 5
0
static void ExtractObj( libfile io, char *name, arch_header *arch, char *newname )
{
    file_offset  pos;
    libfile      out;
    char        *obj_name;

    obj_name = MakeObjOutputName( name, newname );
    remove( obj_name );
    out = LibOpen( obj_name, LIBOPEN_WRITE );
    pos = LibTell( io );
    CopyObj( io, out, arch );
    LibSeek( io, pos, SEEK_SET );
    LibClose( out );
    if( Options.ar && Options.verbose ) {
        Message( "x - %s", obj_name );
    }
}
Exemplo n.º 6
0
static void ProcessOneObject( arch_header *arch, libfile io )
{
    lib_cmd  *cmd;
    bool      deleted;

    if( Options.explode ) {
        if( Options.explode_count ) {
            char number[10];
            sprintf( number, "%8.8d", Options.explode_count );
            memcpy( Options.explode_ext, number, 8 );
            Options.explode_count++;
        }
        ExtractObj( io, arch->name, arch, Options.explode_ext );
    }
    deleted = FALSE;
    for( cmd = CmdList; cmd != NULL; cmd = cmd->next ) {
        if( SameName( arch->name, cmd->name ) ) {

            if( !Options.explode ) {
                if( ( cmd->ops & OP_EXTRACT ) && !( cmd->ops & OP_EXTRACTED ) ) {
                    if( cmd->fname != NULL ) {
                        ExtractObj( io, cmd->name, arch, cmd->fname );
                    } else {
                        ExtractObj( io, cmd->name, arch, EXT_OBJ );
                    }
                    cmd->ops |= OP_EXTRACTED;
                }
            }
            if( cmd->ops & OP_DELETE ) {
                deleted = TRUE;
                cmd->ops |= OP_DELETED;
            }
            cmd->ops |= OP_FOUND;
            break;
        }
    }

    if( deleted ) {
        SkipObject( io );
        Options.modified = TRUE;
    } else {
        AddObjectSymbols( arch, io, LibTell( io ) );
    }
}
Exemplo n.º 7
0
obj_file *OpenLibFile( char *name, libfile hdl )
/**********************************************/
{
    return( DoOpenObjFile( name, hdl, LibTell( hdl ) ) );
}
Exemplo n.º 8
0
static void AddOneObject( arch_header *arch, libfile io )
{
    AddObjectSymbols( arch, io, LibTell( io ) );
}