⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 semsingl.c

📁 开放源码的编译器open watcom 1.6.0版的源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
    loc.start = SemStartResource();
    error = ResWriteIconCurDirHeader( &(dir->Header), CurrResFile.handle );

    for (entry = dir->Head; !error && entry != NULL; entry = entry->Next) {
        error = ResWriteIconDirEntry( &(entry->Entry.Res), CurrResFile.handle );
    }

    if (!error) {
        loc.len = SemEndResource( loc.start );
#ifdef PREPROC_BUG
        SemAddResourceFree( name, WResIDFromNum( (long)(RT_GROUP_ICON) ),
                            flags, loc );
#else
        SemAddResourceFree( name, WResIDFromNum( (long)14 ),
                            flags, loc );
#endif
    } else {
        *err_code = LastWresErr();
    }

    return( error );
} /* writeIconDir */

static void AddIconResource( WResID * name, ResMemFlags flags,
                        ResMemFlags group_flags, char * filename )
/****************************************************************/
{
    int             handle;
    int             error;
    FullIconDir     dir;
    int             err_code;

    handle = RcIoOpenInput( filename, O_RDONLY | O_BINARY );
    if (handle == -1) goto FILE_OPEN_ERROR;

    dir.Head = NULL;
    dir.Tail = NULL;

    error = readIcoFileDir( handle, &dir, &err_code );
    if( error != RS_OK ) goto READ_DIR_ERROR;

    error = copyIcons( &dir, handle, flags, &err_code );
    if( error != RS_OK ) goto COPY_ICONS_ERROR;

    error = writeIconDir( &dir, name, group_flags, &err_code );
    if (error) goto WRITE_DIR_ERROR;

    FreeIconDir( &dir );
    RcClose( handle );

    return;


FILE_OPEN_ERROR:
    RcError( ERR_CANT_OPEN_FILE, filename, strerror( errno ) );
    ErrorHasOccured = TRUE;
    RcMemFree( name );
    return;

READ_DIR_ERROR:
    if( error == RS_INVALID_RESOURCE ) {
        RcError( ERR_NOT_ICON_FILE, filename );
    } else {
        ReportCopyError( error, ERR_READING_ICON, filename, err_code );
    }
    ErrorHasOccured = TRUE;
    RcMemFree( name );
    FreeIconDir( &dir );
    RcClose( handle );
    return;

WRITE_DIR_ERROR:
    RcError( ERR_WRITTING_RES_FILE, CurrResFile.filename,
                strerror( err_code ) );
    ErrorHasOccured = TRUE;
    FreeIconDir( &dir );
    RcClose( handle );
    return;

COPY_ICONS_ERROR:
    ReportCopyError( error, ERR_READING_ICON, filename, err_code );
    ErrorHasOccured = TRUE;
    RcMemFree( name );
    FreeIconDir( &dir );
    RcClose( handle );
    return;
} /* AddIconResource */

static int writeCurDir( FullCurDir *dir, WResID *name, ResMemFlags flags,
                        int *err_code )
/****************************************************************************/
{
    int                 error;
    FullCurDirEntry *   entry;
    ResLocation         loc;

    loc.start = SemStartResource();
    error = ResWriteIconCurDirHeader( &(dir->Header), CurrResFile.handle );

    for (entry = dir->Head; !error && entry != NULL; entry = entry->Next) {
        error = ResWriteCurDirEntry( &(entry->Entry.Res), CurrResFile.handle );
    }

    if (!error) {
        loc.len = SemEndResource( loc.start );
#ifdef PREPROC_BUG
        SemAddResourceFree( name, WResIDFromNum( (long)RT_GROUP_CURSOR ),
                         flags, loc );
#else
        SemAddResourceFree( name, WResIDFromNum( (long)12 ),
                         flags, loc );
#endif
    } else {
        *err_code = LastWresErr();
    }

    return( error );
}

static RcStatus copyOneCursor( const CurFileDirEntry *entry, int handle,
                void *buffer, int buffer_size, BitmapInfoHeader *dibhead,
                int *err_code )
/**************************************************************************/
/* NOTE: this routine fills in dibhead as it copies the data */
{
    RcStatus    error;
    long        seekrc;

    error = RS_OK;
    seekrc = RcSeek( handle, entry->Offset, SEEK_SET );
    if( seekrc == -1 ) {
        error = RS_READ_ERROR;
        *err_code = errno;
    }

    if( error == RS_OK ) {
        error = ReadBitmapInfoHeader( dibhead, handle );
        *err_code = errno;
    }
    if( error == RS_OK ) {
        if( ResWriteBitmapInfoHeader( dibhead, CurrResFile.handle ) ) {
            error = RS_WRITE_ERROR;
            *err_code = LastWresErr();
        }
    }
    if( error == RS_OK ) {
        seekrc = RcTell( handle );
        if( seekrc == -1 ) {
            error = RS_READ_ERROR;
            *err_code = errno;
        } else {
            error = CopyData( seekrc,
                              entry->Length - sizeof(BitmapInfoHeader),
                              handle, buffer, buffer_size, err_code );
        }
    }

    return( error );
}


static RcStatus copyCursors( FullCurDir * dir, int handle,
                             ResMemFlags flags, int *err_code )
/***********************************************************************/
/* This function uses the same size of buffers to copy info as for icons */
{
    RcStatus            error = RS_OK; // should this be RS_PARAM_ERROR ??
    char *              buffer;
    FullCurDirEntry *   entry;
    CurFileDirEntry     fileentry;
    CurHotspot          hotspot;
    BitmapInfoHeader    dibhead;
    ResLocation         loc;

    buffer = RcMemMalloc( BUFFER_SIZE );

    for (entry = dir->Head; entry != NULL; entry = entry->Next) {
        /* copy the cursor */
        loc.start = SemStartResource();

        hotspot.X = entry->Entry.Cur.XHotspot;
        hotspot.Y = entry->Entry.Cur.YHotspot;
        if( ResWriteCurHotspot( &hotspot, CurrResFile.handle ) ) {
            error = RS_WRITE_ERROR;
            *err_code = LastWresErr();
            break;
        }

        /* NOTE: the dibhead structure is filled in as a result of this call */
        error = copyOneCursor( &(entry->Entry.Cur), handle, buffer,
                        BUFFER_SIZE, &(dibhead), err_code );
        if( error != RS_OK ) break;

        loc.len = SemEndResource( loc.start );
        /* add the cursor to the RES file directory */
        SemAddResourceFree( WResIDFromNum( CurrResFile.NextCurOrIcon ),
                WResIDFromNum( (long)RT_CURSOR ), flags, loc );
        /* change the reference in the cursor directory */
        fileentry = entry->Entry.Cur;
        entry->IsCurFileEntry = FALSE;
        entry->Entry.Res.Width = dibhead.Width;
        entry->Entry.Res.Height = dibhead.Height;
        entry->Entry.Res.Planes = dibhead.Planes;
        entry->Entry.Res.BitCount = dibhead.BitCount;
        /* the hotspot data is now part of the components */
        entry->Entry.Res.Length = fileentry.Length + sizeof(CurHotspot);
        entry->Entry.Res.CurID = CurrResFile.NextCurOrIcon;
        CurrResFile.NextCurOrIcon += 1;
    }

    RcMemFree( buffer );

    return( error );
} /* copyCursors */

static RcStatus readCurFileDirEntry( CurFileDirEntry * entry, int handle,
                                        int *err_code )
/*************************************************************************/
{
    int     numread;

    numread = RcRead( handle, entry, sizeof(CurFileDirEntry) );
    if( numread != sizeof(CurFileDirEntry ) ) {
        *err_code = errno;
        if( numread == -1 ) {
            return( RS_READ_ERROR );
        } else {
            return( RS_READ_INCMPLT );
        }
    }
    return( RS_OK );
} /* readCurFileDirEntry */

static RcStatus readCurFileDir( int handle, FullCurDir *dir, int *err_code )
/***************************************************************************/
/* this funtion returns one of the above enum constants */
{
    RcStatus            error;
    int                 currentry;
    FullCurDirEntry *   entry;

    error = readIcoCurFileDirHeader( &(dir->Header), handle, err_code );
    /* type 2 is a cursor file */
    if( error == RS_OK && dir->Header.Type != 2 ) {
        return( RS_INVALID_RESOURCE );
    }

    for (currentry = 0; error == RS_OK && currentry < dir->Header.ResCount;
                            currentry++) {
        entry = RcMemMalloc( sizeof(FullCurDirEntry) );
        entry->Next = NULL;
        entry->Prev = NULL;
        entry->IsCurFileEntry = TRUE;
        error = readCurFileDirEntry( &(entry->Entry.Cur), handle, err_code );
        if (error) {
            RcMemFree( entry );
        } else {
            ResAddLLItemAtEnd( (void **) &(dir->Head), (void **) &(dir->Tail), entry );
        }
    }
    return( error );

} /* readCurFileDir */

static void FreeCurDir( FullCurDir * dir )
/****************************************/
{
    FullCurDirEntry * currentry;
    FullCurDirEntry * oldentry;

    currentry = dir->Head;
    while (currentry != NULL) {
        oldentry = currentry;
        currentry = currentry->Next;

        RcMemFree( oldentry );
    }
} /* FreeCurDir */

static void AddCursorResource( WResID * name, ResMemFlags flags,
                            ResMemFlags group_flags, char * filename )
/********************************************************************/
{
    int             handle;
    int             error;
    FullCurDir      dir;
    int             err_code;

    handle = RcIoOpenInput( filename, O_RDONLY | O_BINARY );
    if (handle == -1) goto FILE_OPEN_ERROR;

    dir.Head = NULL;
    dir.Tail = NULL;

    error = readCurFileDir( handle, &dir, &err_code );
    if( error != RS_OK) goto READ_DIR_ERROR;

    error = copyCursors( &dir, handle, flags, &err_code );
    if( error != RS_OK ) goto COPY_CURSORS_ERROR;

    error = writeCurDir( &dir, name, group_flags, &err_code );
    if (error) goto WRITE_DIR_ERROR;

    FreeCurDir( &dir );
    RcClose( handle );

    return;


FILE_OPEN_ERROR:
    RcError( ERR_CANT_OPEN_FILE, filename, strerror( errno ) );
    ErrorHasOccured = TRUE;
    RcMemFree( name );
    return;

READ_DIR_ERROR:
    if( error == RS_INVALID_RESOURCE ) {
        RcError( ERR_NOT_CURSOR_FILE, filename );
    } else {
        ReportCopyError( error, ERR_READING_CURSOR, filename, err_code );
    }
    ErrorHasOccured = TRUE;
    RcMemFree( name );
    FreeCurDir( &dir );
    RcClose( handle );
    return;

WRITE_DIR_ERROR:
    RcError( ERR_WRITTING_RES_FILE, CurrResFile.filename,
                strerror( err_code )  );
    ErrorHasOccured = TRUE;
    FreeCurDir( &dir );
    RcClose( handle );
    return;

COPY_CURSORS_ERROR:
    ReportCopyError( error, ERR_READING_CURSOR, filename, err_code );
    ErrorHasOccured = TRUE;
    RcMemFree( name );
    FreeCurDir( &dir );
    RcClose( handle );
    return;
} /* AddCursorResource */

static RcStatus readBitmapFileHeader( int handle, BitmapFileHeader *head,
                                        int *err_code )
/**************************************************************************/
{
    int     numread;

    numread = RcRead( handle, head, sizeof(BitmapFileHeader) );
    if( numread != sizeof( BitmapFileHeader ) ) {
        *err_code = errno;
        if( numread == -1 ) {
            return( RS_READ_ERROR );
        } else {
            return( RS_READ_INCMPLT );
        }
    }
    return( RS_OK );
}

#define BITMAP_BUFFER_SIZE  0x1000

static RcStatus copyBitmap( BitmapFileHeader *head, int handle, WResID *name,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -