Exemplo n.º 1
0
WResIDName *WResReadWResIDName( FILE *fp )
/****************************************/
{
    WResIDName      newname;
    WResIDName      *newptr;
    size_t          numread;

    /* read the size of the name in */
    if( ResReadUint8( &(newname.NumChars), fp ) )
        return( NULL );

    /* alloc the space for the new record */
    /* -1 because one of the chars in the name is declared in the struct */
    newptr = WRESALLOC( sizeof( WResIDName ) + newname.NumChars - 1 );
    if( newptr == NULL ) {
        WRES_ERROR( WRS_MALLOC_FAILED );
    } else {
        /* read in the characters */
        newptr->NumChars = newname.NumChars;
        if( (numread = WRESREAD( fp, newptr->Name, newptr->NumChars )) != newptr->NumChars ) {
            WRES_ERROR( WRESIOERR( fp, numread ) ? WRS_READ_FAILED : WRS_READ_INCOMPLETE );
            WRESFREE( newptr );
            newptr = NULL;
        }
    }

    return( newptr );
} /* WResReadWResIDName */
Exemplo n.º 2
0
WResIDName *WResReadWResIDName( WResFileID fid )
/**********************************************/
{
    WResIDName      newname;
    WResIDName      *newptr;
    WResFileSSize   numread;
    bool            error;

    /* read the size of the name in */
    error = ResReadUint8( &(newname.NumChars), fid );

    /* alloc the space for the new record */
    if( error ) {
        return( NULL );
    } else {
        /* -1 because one of the chars in the name is declared in the struct */
        newptr = WRESALLOC( sizeof( WResIDName ) + newname.NumChars - 1 );
    }

    /* read in the characters */
    if( newptr == NULL ) {
        WRES_ERROR( WRS_MALLOC_FAILED );
    } else {
        newptr->NumChars = newname.NumChars;
        numread = WRESREAD( fid, newptr->Name, newptr->NumChars );
        if( numread != newptr->NumChars ) {
            WRES_ERROR( WRESIOERR( fid, numread ) ? WRS_READ_FAILED : WRS_READ_INCOMPLETE );
            WRESFREE( newptr );
            newptr = NULL;
        }
    }

    return( newptr );
} /* WResReadWResIDName */
Exemplo n.º 3
0
/*
 * WResReadFixedResRecord1 - reads the fixed part of a Res info record for
 *                           versions 1 and below
 */
bool WResReadFixedResRecord1( WResResInfo1 *newres, FILE *fp )
/************************************************************/
{
    size_t      numread;

    if( (numread = WRESREAD( fp, newres, sizeof( WResResInfo1 ) )) != sizeof( WResResInfo1 ) )
        return( WRES_ERROR( WRESIOERR( fp, numread ) ? WRS_READ_FAILED : WRS_READ_INCOMPLETE ) );
    return( false );
}
Exemplo n.º 4
0
DepInfo *WResGetAutoDep( const char *fname )
{
    WResFileID      handle;
    WResDir         dir;
    bool            dup_discarded;
    WResID          *name;
    WResID          *type;
    WResDirWindow   window;
    WResLangInfo    *info;
    DepInfo         *ret;
    WResFileSSize   numread;

    ret = NULL;
    handle = ResOpenFileRO( fname );
    if( handle != WRES_NIL_HANDLE ) {
        if( WResIsWResFile( handle ) && (dir = WResInitDir()) != NULL ) {
            if( !WResReadDir( handle, dir, &dup_discarded ) ) {
                name = WResIDFromStr( DEP_LIST_NAME );
                type = WResIDFromNum( DEP_LIST_TYPE );
                if( name != NULL && type != NULL ) {
                    window = WResFindResource( type, name, dir, NULL );
                    if( WResIsEmptyWindow( window ) ) {
                        WRES_ERROR( WRS_RES_NOT_FOUND );
                    } else {
                        info = WResGetLangInfo( window );
                        if( WRESSEEK( handle, info->Offset, SEEK_SET ) == -1 ) {
                            WRES_ERROR( WRS_SEEK_FAILED );
                        } else {
                            ret = WRESALLOC( info->Length );
                            if( ret == NULL ) {
                                WRES_ERROR( WRS_MALLOC_FAILED );
                            } else {
                                numread = WRESREAD( handle, ret, info->Length );
                                if( numread != (WResFileSSize)info->Length ) {
                                    WRES_ERROR( WRESIOERR( handle, numread ) ? WRS_READ_FAILED : WRS_READ_INCOMPLETE );
                                    ret = NULL;
                                }
                            }
                        }
                    }
                }
                if( name != NULL ) {
                    WResIDFree( name );
                }
                if( type != NULL ) {
                    WResIDFree( type );
                }
            }
            WResFreeDir( dir );
        }
        ResCloseFile( handle );
    }
    return( ret );
}
Exemplo n.º 5
0
bool ResReadMenuHeader( MenuHeader *currhead, WResFileID handle )
/***************************************************************/
{
    WResFileSSize   numread;

    numread = WRESREAD( handle, currhead, sizeof( MenuHeader ) );
    if( numread != sizeof( MenuHeader ) ) {
        WRES_ERROR( WRESIOERR( handle, numread ) ? WRS_READ_FAILED:WRS_READ_INCOMPLETE );
        return( true );
    } else {
        return( false );
    }
}
Exemplo n.º 6
0
bool ResReadUint32( uint_32 *newint, WResFileID handle )
/******************************************************/
{
    WResFileSSize   numread;

    numread = WRESREAD( handle, newint, sizeof( uint_32 ) );
    if( numread == sizeof( uint_32 ) ) {
        return( false );
    } else {
        WRES_ERROR( WRESIOERR( handle, numread ) ? WRS_READ_FAILED : WRS_READ_INCOMPLETE );
    }
    return( true );
}
Exemplo n.º 7
0
/*
 * WResReadFixedResRecord2 - reads the fixed part of a Res info record for version 2
 */
bool WResReadFixedResRecord2( WResResInfo *newres, FILE *fp )
/***********************************************************/
{
    size_t          numread;
    WResResInfo2    info;

    if( (numread = WRESREAD( fp, &info, sizeof( WResResInfo2 ) )) != sizeof( WResResInfo2 ) )
        return( WRES_ERROR( WRESIOERR( fp, numread ) ? WRS_READ_FAILED : WRS_READ_INCOMPLETE ) );
    newres->NumResources = info.NumResources;
    newres->ResName.IsName = info.ResName.IsName;
    if( newres->ResName.IsName ) {
        newres->ResName.ID.Name.Name[0] = info.ResName.ID.Name.Name[0];
        newres->ResName.ID.Name.NumChars = info.ResName.ID.Name.NumChars;
    } else {
        newres->ResName.ID.Num = info.ResName.ID.Num;
    }
    return( false );
}
Exemplo n.º 8
0
bool WResReadExtraWResID( WResID *name, WResFileID handle )
/*********************************************************/
/* reads the extra bytes into the end of the structure */
/* assumes that the fixed portion has just been read in and is in name and */
/* that name is big enough to hold the extra bytes */
{
    WResFileSSize   numread;
    uint_16         extrabytes;

    if( name->IsName ) {
        extrabytes = name->ID.Name.NumChars - 1;
        if( extrabytes > 0 ) {
            numread = WRESREAD( handle, &(name->ID.Name.Name[1]), extrabytes );
            if( numread != extrabytes ) {
                WRES_ERROR( WRESIOERR( handle, numread ) ? WRS_READ_FAILED : WRS_READ_INCOMPLETE );
                return( true );
            }
        }
    }
    return( false );
}
Exemplo n.º 9
0
WResID *WResReadWResID( WResFileID handle )
/*****************************************/
{
    WResID          newid;
    WResID          *newidptr;
    WResFileSSize   numread;
    int             extrabytes;     /* chars to be read beyond the fixed size */
    bool            error;

    /* read in the fixed part of the record */
    error = WResReadFixedWResID( &newid, handle );
    if( error ) {
        return( NULL );
    }

    if( newid.IsName ) {
        extrabytes = newid.ID.Name.NumChars - 1;
    } else {
        extrabytes = 0;
    }

    newidptr = WRESALLOC( sizeof( WResID ) + extrabytes );
    if( newidptr == NULL ) {
        WRES_ERROR( WRS_MALLOC_FAILED );
    } else {
        memcpy( newidptr, &newid, sizeof( WResID ) );
        if( extrabytes != 0 ) {
            numread = WRESREAD( handle, newidptr->ID.Name.Name + 1, extrabytes );
            if( numread != extrabytes ) {
                WRES_ERROR( WRESIOERR( handle, numread ) ? WRS_READ_FAILED : WRS_READ_INCOMPLETE );
                WRESFREE( newidptr );
                newidptr = NULL;
            }
        }
    }

    return( newidptr );
} /* WResReadWResID */
Exemplo n.º 10
0
WResResInfo *WResReadResRecord( WResFileID handle )
/*************************************************/
/* reads in the fields of a res info record from the current position in */
/* the file identified by fp */
{
    WResResInfo     newres;
    WResResInfo     *newptr;
    WResFileSSize   numread;
    int             numcharsleft;
    bool            error;

    error = WResReadFixedResRecord( &newres, handle );
    if( error ) {
        return( NULL );
    }

    if( newres.ResName.IsName ) {
        numcharsleft = newres.ResName.ID.Name.NumChars - 1;
    } else {
        numcharsleft = 0;
    }
    newptr = WRESALLOC( sizeof( WResResInfo ) + numcharsleft );
    if( newptr == NULL ) {
        WRES_ERROR( WRS_MALLOC_FAILED );
    } else {
        memcpy( newptr, &newres, sizeof( WResResInfo ) );
        if( numcharsleft != 0 ) {
            numread = WRESREAD( handle, newptr->ResName.ID.Name.Name + 1, numcharsleft );
            if( numread != numcharsleft ) {
                WRES_ERROR( WRESIOERR( handle, numread ) ? WRS_READ_FAILED : WRS_READ_INCOMPLETE );
                WRESFREE( newptr );
                newptr = NULL;
            }
        }
    }

    return( newptr );
} /* WResReadResRecord */