Esempio n. 1
0
int WRReadResourceNames( WResDir dir, WResFileID file_handle, uint_32 name_offset )
{
    uint_8      name_len;
    char        *name;
    int         end_of_names;

    end_of_names = FALSE;

    ResReadUint8( &name_len, file_handle );

    while( !end_of_names ) {
        if( name_len == 0 ) {
            ResReadUint8( &name_len, file_handle );
            if( name_len == 0 ) {
                end_of_names = TRUE;
            } else {
                name_offset++;
            }
        } else {
            name = (char *)WRMemAlloc( name_len + 1 );
            if( read( file_handle, name, name_len ) != name_len ) {
                return( FALSE );
            }
            name[name_len] = 0;
            WRSetResName( dir, name_offset, name );
            WRMemFree( name );
            name_offset = name_offset + name_len + 1;
            ResReadUint8( &name_len, file_handle );
        }
    }

    return( TRUE );
}
Esempio n. 2
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 */
Esempio n. 3
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 */
Esempio n. 4
0
ResNameOrOrdinal *ResReadNameOrOrdinal( WResFileID handle )
/*********************************************************/
{
    ResNameOrOrdinal    newname;
    ResNameOrOrdinal *  newptr;
    int                 error;
    int                 stringlen;
    char *              restofstr;
    uint_8              tmp8;
    uint_16             tmp16;

    restofstr = NULL;
    error = ResReadUint8( &tmp8, handle );
    newname.ord.fFlag = tmp8;
    newname.ord.wOrdinalID = 0;
    stringlen = 0;

    /* read the rest of the Name or Ordinal */
    if (!error) {
        if (newname.ord.fFlag == 0xff) {
            error = ResReadUint16( &tmp16, handle );
            newname.ord.wOrdinalID = tmp16;
        } else {
            if (newname.name[0] != '\0') {
                restofstr = ResReadString( handle, &stringlen );
                stringlen += 1; /* for the '\0' */
                error = (restofstr == NULL);
            }
        }
    }

    /* allocate space for the new Name or Ordinal */
    if (error) {
        newptr = NULL;
    } else {
        newptr = WRESALLOC( sizeof(ResNameOrOrdinal) + stringlen );
        error = (newptr == NULL);
        if( error ) WRES_ERROR( WRS_MALLOC_FAILED );
    }

    /* copy the new new Name or Ordinal into the correct place */
    if (!error) {
        newptr->ord.fFlag = newname.ord.fFlag;
        if (newname.ord.fFlag == 0xff) {
            newptr->ord.wOrdinalID = newname.ord.wOrdinalID;
        } else {
            if (newptr->name[0] != '\0') {
                memcpy( &(newptr->name[1]), restofstr, stringlen );
                WRESFREE( restofstr );
            }
        }
    }

    return( newptr );
}
Esempio n. 5
0
char *ResReadString( WResFileID handle, int *strlen )
/***************************************************/
{
    VarString *         newstring;
    bool                error;
    uint_8              nextchar;
    char *              retstring;

    newstring = VarStringStart();
    error = ResReadUint8( &nextchar, handle );
    while( !error && nextchar != '\0' ) {
        VarStringAddChar( newstring, nextchar );
        error = ResReadUint8( &nextchar, handle );
    }

    retstring = VarStringEnd( newstring, strlen );

    if( error && retstring != NULL ) {
        WRESFREE(retstring);
        retstring = NULL;
    }

    return( retstring );
} /* ResReadString */
Esempio n. 6
0
static void copyMSFormatRes( WResID * name, WResID * type, ResMemFlags flags,
                ResLocation loc, WResLangType *lang )
/***************************************************************************/
{
    MResResourceHeader  ms_head;
    long                cur_byte_num;
    uint_8              cur_byte;
    long                seek_rc;
    int                 error;
    int                 tmp_handle;

    /* fill in and output a MS format resource header */
    ms_head.Type = WResIDToNameOrOrd( type );
    ms_head.Name = WResIDToNameOrOrd( name );
    ms_head.MemoryFlags = flags;
    ms_head.Size = loc.len;
    ms_head.LanguageId = MAKELANGID( lang->lang, lang->sublang );
    ms_head.Version = 0L; /* Currently Unsupported */
    ms_head.DataVersion = 0L;
    ms_head.Characteristics = 0L; /* Currently Unsupported */

    /* OS/2 resource header happens to be identical to Win16 */
    if( CmdLineParms.TargetOS == RC_TARGET_OS_WIN16 ||
        CmdLineParms.TargetOS == RC_TARGET_OS_OS2 ) {
        error = MResWriteResourceHeader( &ms_head, CurrResFile.handle, FALSE );
    } else {
        error = MResWriteResourceHeader( &ms_head, CurrResFile.handle, TRUE );
    }
    if (error) {
        RcError( ERR_WRITTING_RES_FILE, CurrResFile.filename,
                 LastWresErrStr() );
        RcMemFree( ms_head.Type );
        RcMemFree( ms_head.Name );
        ErrorHasOccured = TRUE;
    } else {
        RcMemFree( ms_head.Type );
        RcMemFree( ms_head.Name );
        tmp_handle = ResOpenFileRO( MSFormatTmpFile );
        if (tmp_handle == -1) {
            RcError( ERR_OPENING_TMP, MSFormatTmpFile, LastWresErrStr() );
            ErrorHasOccured = TRUE;
            return;
        }

        /* copy the data from the temperary file to the RES file */
        seek_rc = ResSeek( tmp_handle, loc.start, SEEK_SET );
        if (seek_rc == -1) {
            RcError( ERR_READING_TMP, MSFormatTmpFile, LastWresErrStr() );
            ResCloseFile( tmp_handle );
            ErrorHasOccured = TRUE;
            return;
        }

        /* this is very inefficient but hopefully the buffering in layer0.c */
        /* will make it tolerable */
        for (cur_byte_num = 0; cur_byte_num < loc.len; cur_byte_num++) {
            error = ResReadUint8( &cur_byte, tmp_handle );
            if( error ) {
                RcError( ERR_READING_TMP, MSFormatTmpFile, LastWresErrStr() );
                ResCloseFile( tmp_handle );
                ErrorHasOccured = TRUE;
                return;
            } else {
                error = ResWriteUint8( &cur_byte, CurrResFile.handle );
                if( error ) {
                    RcError( ERR_WRITTING_RES_FILE,
                             CurrResFile.filename, LastWresErrStr() );
                    ResCloseFile( tmp_handle );
                    ErrorHasOccured = TRUE;
                    return;
                }
            }
        }
        if( ResCloseFile( tmp_handle ) == -1 ) {
            RcError( ERR_WRITTING_RES_FILE, MSFormatTmpFile,
                     LastWresErrStr() );
            ErrorHasOccured = TRUE;
        }
    }
}