static int ChangeTmpToOutFile( const char * tmpfile, const char * outfile ) /**************************************************************************/ { int fileerror; /* error while deleting or renaming */ /* remove the old copy of the output file */ fileerror = remove( outfile ); if( fileerror ) { if( errno == ENOENT ) { /* ignore the error if it says that the file doesn't exist */ errno = 0; } else { RcError( ERR_RENAMEING_TMP_FILE, tmpfile, outfile, strerror( errno ) ); remove( tmpfile ); UnregisterTmpFile( tmpfile ); return( TRUE ); } } /* rename the temp file to the output file */ fileerror = rename( tmpfile, outfile ); if( fileerror ) { RcError( ERR_RENAMEING_TMP_FILE, tmpfile, outfile, strerror( errno ) ); remove( tmpfile ); UnregisterTmpFile( tmpfile ); return( TRUE ); } return( FALSE ); } /* ChangeTmpToOutFile */
static void Pass1ResFileShutdown( void ) /**************************************/ { bool error; error = false; if( CurrResFile.fp != NULL ) { if( CmdLineParms.TargetOS == RC_TARGET_OS_OS2 ) { WriteOS2Tables(); } else { WriteWINTables(); } if( !ErrorHasOccured ) { if( CurrResFile.IsWatcomRes ) { error = WResWriteDir( CurrResFile.fp, CurrResFile.dir ); if( error ) { RcError( ERR_WRITTING_RES_FILE, CurrResFile.filename, LastWresErrStr() ); } } if( !error ) { ChangeTmpToOutFile( CurrResFile.fp, CmdLineParms.OutResFileName ); } } if( CurrResFile.dir != NULL ) { WResFreeDir( CurrResFile.dir ); CurrResFile.dir = NULL; } if( ResCloseFile( CurrResFile.fp ) ) { RcError( ERR_CLOSING_TMP, CurrResFile.filename, LastWresErrStr() ); } CurrResFile.fp = NULL; } } /* Pass1ResFileShutdown */
static bool CreatePreprocFile( void ) { int hdl; bool error; int ch; char ch1; int len; error = FALSE; hdl = RcOpen( CmdLineParms.OutResFileName, O_WRONLY | O_TEXT | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH ); if( hdl == -1 ) { RcError( ERR_CANT_OPEN_FILE, CmdLineParms.OutResFileName, strerror( errno ) ); error = TRUE; } else { ch = RcIoGetChar(); while( ch != RC_EOF ) { ch1 = (char) ch; len = RcWrite( hdl, &ch1, 1 ); if( len != 1 ) { RcError( ERR_WRITTING_FILE, CmdLineParms.OutResFileName, strerror( errno ) ); error = TRUE; } ch = RcIoGetChar(); } } if( hdl != -1 ) RcClose( hdl ); return( error ); }
static bool readObjectAndPageTable( ExeFileInfo *exe ) /****************************************************/ { RcStatus ret; size_t table_size; table_size = exe->u.LXInfo.OS2Head.num_objects * sizeof( object_record ); exe->u.LXInfo.Objects = RESALLOC( table_size ); ret = SeekRead( exe->fid, exe->WinHeadOffset + exe->u.LXInfo.OS2Head.objtab_off, exe->u.LXInfo.Objects, table_size ); if( ret == RS_OK ) { table_size = exe->u.LXInfo.OS2Head.num_pages * sizeof( lx_map_entry ); exe->u.LXInfo.Pages = RESALLOC( table_size ); ret = SeekRead( exe->fid, exe->WinHeadOffset + exe->u.LXInfo.OS2Head.objmap_off, exe->u.LXInfo.Pages, table_size ); } switch( ret ) { case RS_OK: break; case RS_READ_ERROR: RcError( ERR_READING_EXE, exe->name, strerror( errno ) ); break; case RS_READ_INCMPLT: RcError( ERR_UNEXPECTED_EOF, exe->name ); break; default: RcError( ERR_INTERNAL, INTERR_UNKNOWN_RCSTATUS ); break; } CheckDebugOffset( exe ); return( ret != RS_OK ); }
static int readObjectTable( ExeFileInfo * exe ) /*********************************************/ { RcStatus error; exe->u.PEInfo.Objects = RcMemMalloc( exe->u.PEInfo.WinHead->num_objects * sizeof(pe_object) ); error = SeekRead( exe->Handle, exe->WinHeadOffset + sizeof(pe_header), exe->u.PEInfo.Objects, exe->u.PEInfo.WinHead->num_objects * sizeof(pe_object) ); switch( error ) { case RS_OK: break; case RS_READ_ERROR: RcError( ERR_READING_EXE, exe->name, strerror( errno ) ); break; case RS_READ_INCMPLT: RcError( ERR_UNEXPECTED_EOF, exe->name ); break; default: RcError( ERR_INTERNAL, INTERR_UNKNOWN_RCSTATUS ); break; } CheckDebugOffset( exe ); return( error != RS_OK ); }
static RcStatus readObjectTable( ExeFileInfo *exe ) /*************************************************/ { RcStatus ret; unsigned objects_size; long file_offset; exe_pe_header *pehdr; pehdr = exe->u.PEInfo.WinHead; if( IS_PE64( *pehdr ) ) { objects_size = PE64( *pehdr ).num_objects * sizeof( pe_object ); file_offset = exe->WinHeadOffset + sizeof( pe_header64 ); } else { objects_size = PE32( *pehdr ).num_objects * sizeof( pe_object ); file_offset = exe->WinHeadOffset + sizeof( pe_header ); } exe->u.PEInfo.Objects = RESALLOC( objects_size ); ret = SeekRead( exe->fid, file_offset, exe->u.PEInfo.Objects, objects_size ); switch( ret ) { case RS_OK: break; case RS_READ_ERROR: RcError( ERR_READING_EXE, exe->name, strerror( errno ) ); break; case RS_READ_INCMPLT: RcError( ERR_UNEXPECTED_EOF, exe->name ); break; default: RcError( ERR_INTERNAL, INTERR_UNKNOWN_RCSTATUS ); break; } CheckDebugOffset( exe ); return( ret ); }
ResLocation SemCopyRawFile( const char *filename ) /************************************************/ { WResFileID fid; RcStatus ret; char *buffer; char full_filename[_MAX_PATH]; ResLocation loc; int err_code; WResFileOffset pos; buffer = RESALLOC( BUFFER_SIZE ); if( RcFindResource( filename, full_filename ) == -1 ) { RcError( ERR_CANT_FIND_FILE, filename ); goto HANDLE_ERROR; } if( AddDependency( full_filename ) ) goto HANDLE_ERROR; fid = RcIoOpenInput( full_filename, false ); if( fid == WRES_NIL_HANDLE ) { RcError( ERR_CANT_OPEN_FILE, filename, strerror( errno ) ); goto HANDLE_ERROR; } loc.start = SemStartResource(); pos = RESTELL( fid ); if( pos == -1 ) { RcError( ERR_READING_DATA, full_filename, strerror( errno ) ); RESCLOSE( fid ); goto HANDLE_ERROR; } else { ret = SemCopyDataUntilEOF( pos, fid, buffer, BUFFER_SIZE, &err_code ); if( ret != RS_OK ) { ReportCopyError( ret, ERR_READING_DATA, full_filename, err_code ); RESCLOSE( fid ); goto HANDLE_ERROR; } } loc.len = SemEndResource( loc.start ); RESCLOSE( fid ); RESFREE( buffer ); return( loc ); HANDLE_ERROR: ErrorHasOccured = true; loc.start = 0; loc.len = 0; RESFREE( buffer ); return( loc ); }
static bool copyResourcesFromRes( const char *full_filename ) /***********************************************************/ { WResFileID fid; WResDir dir; bool dup_discarded; WResDirWindow wind; char *buffer; bool error; buffer = NULL; dir = WResInitDir(); fid = RcIoOpenInput( full_filename, false ); if( fid == WRES_NIL_HANDLE ) { RcError( ERR_CANT_OPEN_FILE, full_filename, strerror( errno ) ); goto HANDLE_ERROR; } error = WResReadDir( fid, dir, &dup_discarded ); if( error ) { switch( LastWresStatus() ) { case WRS_BAD_SIG: RcError( ERR_INVALID_RES, full_filename ); break; case WRS_BAD_VERSION: RcError( ERR_BAD_RES_VER, full_filename ); break; default: RcError( ERR_READING_RES, full_filename, LastWresErrStr() ); break; } goto HANDLE_ERROR; } if( WResGetTargetOS( dir ) != WResGetTargetOS( CurrResFile.dir ) ) { RcError( ERR_RES_OS_MISMATCH, full_filename ); goto HANDLE_ERROR; } buffer = RESALLOC( BUFFER_SIZE ); wind = WResFirstResource( dir ); while( !WResIsEmptyWindow( wind ) ) { copyAResource( fid, &wind, buffer, full_filename ); wind = WResNextResource( wind, dir ); } RESFREE( buffer ); WResFreeDir( dir ); RESCLOSE( fid ); return( false ); HANDLE_ERROR: ErrorHasOccured = true; WResFreeDir( dir ); if( fid != WRES_NIL_HANDLE ) RESCLOSE( fid ); return( true ); }
static void AddBitmapResource( WResID * name, ResMemFlags flags, const char * filename ) /**************************************************************/ { BitmapFileHeader head; WResFileID handle; RcStatus ret; int err_code; handle = RcIoOpenInput( filename, O_RDONLY | O_BINARY ); if( handle == NIL_HANDLE) goto FILE_OPEN_ERROR; ret = readBitmapFileHeader( handle, &head, &err_code ); if( ret != RS_OK ) goto READ_HEADER_ERROR; if( head.Type != BITMAP_MAGIC ) goto NOT_BITMAP_ERROR; ret = copyBitmap( &head, handle, name, flags, &err_code ); if( ret != RS_OK ) goto COPY_BITMAP_ERROR; RCCLOSE( handle ); return; FILE_OPEN_ERROR: RcError( ERR_CANT_OPEN_FILE, filename, strerror( errno ) ); ErrorHasOccured = true; RCFREE( name ); return; READ_HEADER_ERROR: ReportCopyError( ret, ERR_READING_BITMAP, filename, err_code ); ErrorHasOccured = true; RCFREE( name ); RCCLOSE( handle ); return; NOT_BITMAP_ERROR: RcError( ERR_NOT_BITMAP_FILE, filename ); ErrorHasOccured = true; RCFREE( name ); RCCLOSE( handle ); return; COPY_BITMAP_ERROR: ReportCopyError( ret, ERR_READING_BITMAP, filename, err_code ); ErrorHasOccured = true; RCCLOSE( handle ); return; }
static bool Pass1InitRes( void ) /******************************/ { WResID null_id; ResMemFlags null_memflags; ResLocation null_loc; memset( &CurrResFile, 0, sizeof( CurrResFile ) ); /* open the temporary file */ CurrResFile.filename = "Temporary file 0 (res)"; CurrResFile.fp = ResOpenFileTmp( NULL ); if( CurrResFile.fp == NULL ) { RcError( ERR_OPENING_TMP, CurrResFile.filename, LastWresErrStr() ); return( true ); } /* initialize the directory */ CurrResFile.dir = WResInitDir(); if( CurrResFile.dir == NULL ) { RcError( ERR_OUT_OF_MEMORY ); ResCloseFile( CurrResFile.fp ); CurrResFile.fp = NULL; return( true ); } if( CmdLineParms.TargetOS == RC_TARGET_OS_WIN16 ) { WResSetTargetOS( CurrResFile.dir, WRES_OS_WIN16 ); } else if( CmdLineParms.TargetOS == RC_TARGET_OS_WIN32 ) { WResSetTargetOS( CurrResFile.dir, WRES_OS_WIN32 ); } else { WResSetTargetOS( CurrResFile.dir, WRES_OS_OS2 ); } if( CmdLineParms.MSResFormat ) { CurrResFile.IsWatcomRes = false; /* write null header here if it is win32 */ if( CmdLineParms.TargetOS == RC_TARGET_OS_WIN32 ) { null_loc.start = SemStartResource(); null_loc.len = SemEndResource( null_loc.start ); null_id.IsName = false; null_id.ID.Num = 0; null_memflags = 0; SemAddResource( &null_id, &null_id, null_memflags, null_loc ); } } else { CurrResFile.IsWatcomRes = true; WResFileInit( CurrResFile.fp ); } CurrResFile.NextCurOrIcon = 1; return( false ); } /* Pass1InitRes */
static void SemCheckMenuItemPopup( FullMenuItem *item, uint_16 tokentype ) /************************************************************************/ { if( tokentype == Y_MENU ) { if( item->item.popup.item.type == MT_MENUEX ) { RcError( ERR_MENUEX_POPUP_OPTIONS ); } } else if( tokentype == Y_MENU_EX ) { item->item.popup.item.menuData.ItemFlags = MENUEX_POPUP; if( item->item.popup.item.type == MT_MENU ) { RcError( ERR_MENU_POPUP_OPTIONS ); } } }
extern bool RcPass2IoInit( void ) /******************************/ { bool noerror; bool tmpexe_exists; memset( &Pass2Info, 0, sizeof( RcPass2Info ) ); Pass2Info.IoBuffer = RESALLOC( IO_BUFFER_SIZE ); noerror = openExeFileInfoRO( CmdLineParms.InExeFileName, &(Pass2Info.OldFile) ); if( noerror ) { Pass2Info.TmpFile.name = "Temporary file 2 (exe)"; Pass2Info.TmpFile.fp = ResOpenFileTmp( NULL ); if( Pass2Info.TmpFile.fp == NULL ) { RcError( ERR_OPENING_TMP, Pass2Info.TmpFile.name, strerror( errno ) ); noerror = false; } } tmpexe_exists = noerror; if( noerror ) { Pass2Info.TmpFile.Type = Pass2Info.OldFile.Type; Pass2Info.TmpFile.WinHeadOffset = Pass2Info.OldFile.WinHeadOffset; if( Pass2Info.OldFile.Type == EXE_TYPE_PE ) { Pass2Info.TmpFile.u.PEInfo.WinHead = &Pass2Info.TmpFile.u.PEInfo.WinHeadData; *Pass2Info.TmpFile.u.PEInfo.WinHead = *Pass2Info.OldFile.u.PEInfo.WinHead; } if( ( Pass2Info.OldFile.Type == EXE_TYPE_NE_WIN || Pass2Info.OldFile.Type == EXE_TYPE_NE_OS2 ) && CmdLineParms.ExtraResFiles != NULL ) { RcError( ERR_FR_NOT_VALID_FOR_WIN ); noerror = false; } else { noerror = OpenResFileInfo( Pass2Info.OldFile.Type ); } } if( !noerror ) { RESFREE( Pass2Info.IoBuffer ); Pass2Info.IoBuffer = NULL; ClosePass2FilesAndFreeMem(); if( tmpexe_exists ) { ResCloseFile( Pass2Info.TmpFile.fp ); Pass2Info.TmpFile.fp = NULL; } } return( noerror ); } /* RcPass2IoInit */
extern int RcIoPushInputFile( char * filename ) /*********************************************/ { int error; if( InStack.Current == InStack.Stack + MAX_INCLUDE_DEPTH - 1 ) { RcError( ERR_RCINCLUDE_TOO_DEEP, MAX_INCLUDE_DEPTH ); return( TRUE ); } SetPhysFileOffset( &(InStack) ); InStack.Current++; /* set up the logical file info */ RcIoSetLogicalFileInfo( 1, filename ); /* set up the physical file info */ error = OpenNewPhysicalFile( &(InStack.Current->Physical), filename ); if( error ) { InStack.Current--; } else { error = ReadBuffer( &(InStack) ); } return( error ); } /* RcIoPushInputFile */
extern void SemOS2WriteHelpTable( WResID * name, ResMemFlags flags, FullHelpTableOS2 * helptable ) /******************************************************************/ { ResLocation loc; int error; int err_code; if( !ErrorHasOccured ) { loc.start = SemStartResource(); error = SemOS2WriteHelpTableEntries( helptable, CurrResFile.handle ); if(error) { err_code = LastWresErr(); goto OutputWriteError; } loc.len = SemEndResource( loc.start ); SemAddResourceFree( name, WResIDFromNum( OS2_RT_HELPTABLE ), flags, loc ); } else { RcMemFree( name ); } SemOS2FreeHelpTable( helptable ); return; OutputWriteError: RcError( ERR_WRITTING_RES_FILE, CurrResFile.filename, strerror( err_code ) ); ErrorHasOccured = TRUE; SemOS2FreeHelpTable( helptable ); return; }
/* Please note that this function is vital to the resource editors. Thusly * any changes made to Pass2 should cause the notification of the * resource editor dude. */ static int Pass2( void ) /**********************/ { int noerror; noerror = RcPass2IoInit(); if( noerror ) { switch( Pass2Info.OldFile.Type ) { case EXE_TYPE_NE_WIN: noerror = MergeResExeNE(); break; case EXE_TYPE_NE_OS2: noerror = MergeResExeOS2NE(); break; case EXE_TYPE_PE: noerror = MergeResExePE(); break; case EXE_TYPE_LX: noerror = MergeResExeLX(); break; default: //EXE_TYPE_UNKNOWN RcError( ERR_INTERNAL, INTERR_UNKNOWN_RCSTATUS ); noerror = FALSE; break; } RcPass2IoShutdown( noerror ); } return( noerror ); } /* Pass2 */
void SemOS2WriteAccelTable( WResID *name, ResMemFlags flags, uint_32 codepage, FullAccelTableOS2 *acctable ) /****************************************************************************/ { ResLocation loc; bool error; int err_code; if( !ErrorHasOccured ) { loc.start = SemStartResource(); error = writeAccelTableEntries( acctable, CurrResFile.fid, codepage ); if( error ) { err_code = LastWresErr(); goto OutputWriteError; } loc.len = SemEndResource( loc.start ); SemAddResourceFree( name, WResIDFromNum( OS2_RT_ACCELTABLE ), flags, loc ); } else { RESFREE( name ); } SemOS2FreeAccelTable( acctable ); return; OutputWriteError: RcError( ERR_WRITTING_RES_FILE, CurrResFile.filename, strerror( err_code ) ); ErrorHasOccured = true; SemOS2FreeAccelTable( acctable ); return; }
FullAccelEntry SemWINMakeAccItem( AccelEvent event, unsigned long idval, FullAccelFlags flags ) /***********************************************************************/ { FullAccelEntry entry; entry.Win32 = false; entry.startoftable = 0; if( event.strevent || flags.typegiven ) { CheckAccelFlags( &flags.flags, idval ); if( CmdLineParms.TargetOS == RC_TARGET_OS_WIN16 ) { entry.u.entry.Ascii = event.event; entry.u.entry.Flags = flags.flags; entry.u.entry.Id = idval; } else { entry.Win32 = true; entry.u.entry32.Ascii = event.event; entry.u.entry32.Flags = flags.flags; entry.u.entry32.Id = idval; entry.u.entry32.Unknown = 0; } } else { RcError( ERR_ACCEL_NO_TYPE, idval ); ErrorHasOccured = true; entry.u.entry.Ascii = 0; entry.u.entry.Flags = 0; entry.u.entry.Id = 0; } return( entry ); }
void SemOS2WriteMenu( WResID *name, ResMemFlags flags, FullMenuOS2 *menu, YYTOKENTYPE tokentype, uint_32 codepage ) /***********************************************************************/ { ResLocation loc; int error; int err_code; tokentype = tokentype; if( !ErrorHasOccured ) { loc.start = SemStartResource(); error = SemOS2WriteSubMenu( menu, &err_code, codepage ); if( error ) { err_code = LastWresErr(); goto OutputWriteError; } loc.len = SemEndResource( loc.start ); SemAddResourceFree( name, WResIDFromNum( OS2_RT_MENU ), flags, loc ); } else { RCFREE( name ); } SemOS2FreeSubMenu( menu ); return; OutputWriteError: RcError( ERR_WRITTING_RES_FILE, CurrResFile.filename, strerror( err_code ) ); ErrorHasOccured = TRUE; SemOS2FreeSubMenu( menu ); return; }
extern void SemOS2AddDlgincResource( WResID *name, char *filename ) /*****************************************************************/ { ResLocation loc; int error, err_code; loc.start = SemStartResource(); error = ResWriteString( filename, FALSE, CurrResFile.handle ); if( error ) { err_code = LastWresErr(); goto OutputWriteError; } loc.len = SemEndResource( loc.start ); SemAddResourceFree( name, WResIDFromNum( OS2_RT_DLGINCLUDE ), MEMFLAG_DISCARDABLE | MEMFLAG_MOVEABLE | MEMFLAG_PURE, loc ); RcMemFree( filename ); return; OutputWriteError: RcError( ERR_WRITTING_RES_FILE, CurrResFile.filename, strerror( err_code ) ); ErrorHasOccured = TRUE; RcMemFree( filename ); return; }
void SemOS2AddStrToStringTable( FullStringTable *currtable, uint_16 stringid, char *string ) /***************************************************************/ { FullStringTableBlock *currblock; uint_16 blocknum; uint_16 stringnum; blocknum = stringid >> 4; stringnum = stringid & 0x000f; currblock = findStringTableBlock( currtable, blocknum ); if( currblock != NULL ) { if( currblock->Block.String[stringnum] != NULL ) { /* duplicate stringid */ RcError( ERR_DUPLICATE_STRING_CONST, stringid ); ErrorHasOccured = true; } } else { currblock = newStringTableBlock(); currblock->BlockNum = blocknum; ResAddLLItemAtEnd( (void **)&(currtable->Head), (void **)&(currtable->Tail), currblock ); } currblock->Block.String[stringnum] = WResIDNameFromStr( string ); } /* SemOS2AddStrToStringTable */
static void SemCheckMenuItemNormal( FullMenuItem *item, uint_16 tokentype ) /*************************************************************************/ { if( tokentype == Y_MENU ) { if( item->item.normal.type == MT_MENUEX ) { RcError( ERR_MENUEX_NORMAL_OPTIONS ); } else if( item->item.normal.type == MT_MENUEX_NO_ID ) { RcError( ERR_MISSING_MENUITEM_ID ); } } else if ( tokentype == Y_MENU_EX ) { if( item->item.normal.type == MT_MENU ) { RcError( ERR_MENU_NORMAL_OPTIONS ); } } }
void SemOS2WriteHelpSubTable( WResID * name, int numWords, ResMemFlags flags, FullHelpSubTableOS2 * helptable ) /********************************************************************/ { ResLocation loc; bool error; int err_code; if( !ErrorHasOccured ) { loc.start = SemStartResource(); if( helptable != NULL ) { helptable->numWords = numWords; } error = SemOS2WriteHelpSubTableEntries( helptable, CurrResFile.handle ); if( error ) { err_code = LastWresErr(); goto OutputWriteError; } loc.len = SemEndResource( loc.start ); SemAddResourceFree( name, WResIDFromNum( OS2_RT_HELPSUBTABLE ), flags, loc ); } else { RCFREE( name ); } SemOS2FreeHelpSubTable( helptable ); return; OutputWriteError: RcError( ERR_WRITTING_RES_FILE, CurrResFile.filename, strerror( err_code ) ); ErrorHasOccured = true; SemOS2FreeHelpSubTable( helptable ); return; }
void SemWriteRawDataItem( RawDataItem item ) /******************************************/ { uint_16 num16; uint_32 num32; bool error; if( item.IsString ) { int len = item.StrLen; if( item.WriteNull ) { ++len; } if( ResWriteStringLen( item.Item.String, item.LongItem, CurrResFile.handle, len ) ) { RcError( ERR_WRITTING_RES_FILE, CurrResFile.filename, LastWresErrStr() ); ErrorHasOccured = true; } if( item.TmpStr ) { RCFREE( item.Item.String ); } } else { if( !item.LongItem ) { if( (int_32)item.Item.Num < 0 ) { if( (int_32)item.Item.Num < SHRT_MIN ) { RcWarning( ERR_RAW_DATA_TOO_SMALL, item.Item.Num, SHRT_MIN ); } } else { if( item.Item.Num > USHRT_MAX ) { RcWarning( ERR_RAW_DATA_TOO_BIG, item.Item.Num, USHRT_MAX ); } } } if( !ErrorHasOccured ) { if( !item.LongItem ) { num16 = item.Item.Num; error = ResWriteUint16( &(num16), CurrResFile.handle ); } else { num32 = item.Item.Num; error = ResWriteUint32( &(num32), CurrResFile.handle ); } if( error ) { RcError( ERR_WRITTING_RES_FILE, CurrResFile.filename, LastWresErrStr() ); ErrorHasOccured = true; } } } }
void SemAddResource2( WResID * name, WResID * type, ResMemFlags flags, ResLocation loc, char *filename ) /******************************************************************/ { int error; int duplicate; char * namestr; WResLangType *lang; if( resourceHasLang ) { lang = &resourceLang; resourceHasLang = FALSE; } else { lang = &curLang; } // Windows 95 is currently unable to load an exe that contains a resource // with numeric type or numeric identifier greater than 0x7FFF // so we warn the user if( CmdLineParms.TargetOS == RC_TARGET_OS_WIN32 ) { if( !type->IsName && type->ID.Num > 0x7FFF ) { namestr = WResIDToStr( name ); RcWarning( ERR_TYPE_GT_7FFF, namestr ); RcMemFree( namestr ); } if( !name->IsName && name->ID.Num > 0x7FFF ) { namestr = WResIDToStr( name ); RcWarning( ERR_NAME_GT_7FFF, namestr ); RcMemFree( namestr ); } } error = WResAddResource( type, name, flags, loc.start, loc.len, CurrResFile.dir, lang, &duplicate ); if (duplicate) { if( filename == NULL ) { ReportDupResource( name, type, NULL, NULL, TRUE ); } else { ReportDupResource( name, type, filename, CmdLineParms.InFileName, TRUE ); } /* The resource has already been written but we can't add it to */ /* directory. This will make the .RES file larger but will otherwise */ /* not affect it since there will be no references to the resource in */ /* the directory. */ } else if (error) { RcError( ERR_OUT_OF_MEMORY ); ErrorHasOccured = TRUE; } if (!CurrResFile.IsWatcomRes) { if (!duplicate) { copyMSFormatRes( name, type, flags, loc, lang ); } /* erase the temporary file */ remove( MSFormatTmpFile ); UnregisterTmpFile( MSFormatTmpFile ); MSFormatTmpFile[0] = '\0'; } }
void ReportCopyError( RcStatus status, int read_msg, const char *filename, int err_code ) { switch( status ) { case RS_READ_ERROR: RcError( read_msg, filename, strerror( err_code ) ); break; case RS_READ_INCMPLT: RcError( ERR_UNEXPECTED_EOF, filename ); break; case RS_WRITE_ERROR: RcError( ERR_WRITTING_RES_FILE, CurrResFile.filename, strerror( err_code ) ); break; default: RcError( ERR_INTERNAL, INTERR_UNKNOWN_RCSTATUS ); break; } }
static bool OpenPhysicalFile( PhysFileInfo *phys ) /************************************************/ { if( !phys->IsOpen ) { phys->fp = RcIoOpenInput( phys->Filename, true ); if( phys->fp == NULL ) { RcError( ERR_CANT_OPEN_FILE, phys->Filename, strerror( errno ) ); return( true ); } phys->IsOpen = true; if( fseek( phys->fp, phys->Offset, SEEK_SET ) == -1 ) { RcError( ERR_READING_FILE, phys->Filename, strerror( errno ) ); return( true ); } } return( false ); } /* OpenPhysicalFile */
static int OpenPhysicalFile( PhysFileInfo * phys ) /************************************************/ { if( !phys->IsOpen ) { phys->Handle = RcIoOpenInput( phys->Filename, O_RDONLY | O_TEXT ); if( phys->Handle == NIL_HANDLE ) { RcError( ERR_CANT_OPEN_FILE, phys->Filename, strerror( errno ) ); return( TRUE ); } phys->IsOpen = TRUE; if( RcSeek( phys->Handle, phys->Offset, SEEK_SET ) == -1 ) { RcError( ERR_READING_FILE, phys->Filename, strerror( errno ) ); return( TRUE ); } } return( FALSE ); } /* OpenPhysicalFile */
/* The OS/2 dialog templates present us with a problem because the template items contain a number of offsets that are not known until the template is processed; this means we cannot just start spitting the data into a file. Instead we build an in-memory image of the resource (the size must be < 64K) and then dump the entire resource into the file - which certainly shouldn't hurt performance either. */ extern void SemOS2WriteDialogTemplate( WResID *name, ResMemFlags flags, uint_32 codepage, FullDiagCtrlListOS2 *ctrls ) /*********************************************************************/ { ResLocation loc; int err_code; int error; int size; DialogHeaderOS2 *head = NULL; char *tmpl; char *ptr; size = sizeof( DialogHeaderOS2 ) + SemOS2CalcControlSize( ctrls ); if( size > 65536 ) { // TODO: Error, template is too big } tmpl = RcMemMalloc( size ); head = (DialogHeaderOS2 *)tmpl; InitOS2DialogBoxHeader( head, codepage ); head->Size = size; ptr = tmpl + sizeof( DialogHeaderOS2 ); // Create the DLGTITEM array in memory ptr = SemOS2BuildTemplateArray( ptr, ctrls ); // Dump all other data into memory and update the offsets SemOS2DumpTemplateData( tmpl, ptr, ctrls ); // Write the resource to file loc.start = SemStartResource(); error = ResOS2WriteDlgTemplate( tmpl, size, CurrResFile.handle ); if( error ) { err_code = LastWresErr(); goto OutputWriteError; } RcMemFree( tmpl ); loc.len = SemEndResource( loc.start ); SemAddResourceFree( name, WResIDFromNum( OS2_RT_DIALOG ), flags, loc ); SemOS2FreeDiagCtrlList( ctrls ); return; OutputWriteError: RcError( ERR_WRITTING_RES_FILE, CurrResFile.filename, strerror( err_code ) ); ErrorHasOccured = TRUE; SemOS2FreeDiagCtrlList( ctrls ); return; } /* SemOS2WriteDialogTemplate */
void SemWriteMenu( WResID *name, ResMemFlags flags, FullMenu *menu, uint_16 tokentype ) /********************************************************************/ { MenuHeader head; ResLocation loc; int error = 0; int err_code; uint_8 headerdata[ RES_HEADER_SIZE ]; if(!ErrorHasOccured) { if( tokentype == Y_MENU ) { head.Version = 0; /* currently these fields are both 0 */ head.HeaderSize = 0; loc.start = SemStartResource(); error = ResWriteMenuHeader( &head, CurrResFile.handle ); } else if( tokentype == Y_MENU_EX ) { head.Version = RES_HEADER_VERSION; head.HeaderSize = RES_HEADER_SIZE; memset( headerdata, 0, head.HeaderSize ); ResPadDWord( CurrResFile.handle ); loc.start = SemStartResource(); error = ResWriteMenuExHeader( &head, CurrResFile.handle, headerdata ); } else { loc.start = 0; // Is this valid? } if(error) { err_code = LastWresErr(); goto OutputWriteError; } error = SemWriteSubMenu( menu, &err_code, tokentype ); if( !error && CmdLineParms.MSResFormat && CmdLineParms.TargetOS == RC_TARGET_OS_WIN32 ) { error = ResPadDWord( CurrResFile.handle ); } if(error) goto OutputWriteError; loc.len = SemEndResource( loc.start ); SemAddResourceFree( name, WResIDFromNum( RT_MENU ), flags, loc ); } else { RcMemFree( name ); } SemFreeSubMenu( menu ); return; OutputWriteError: RcError( ERR_WRITTING_RES_FILE, CurrResFile.filename, strerror( err_code ) ); ErrorHasOccured = TRUE; SemFreeSubMenu( menu ); return; }
static bool myCopyExeData( ExeFileInfo *inexe, ExeFileInfo *outexe, uint_32 length ) { switch( CopyExeData( inexe->Handle, outexe->Handle, length ) ) { case RS_OK: case RS_PARAM_ERROR: return( false ); case RS_READ_ERROR: RcError( ERR_READING_EXE, inexe->name, strerror( errno ) ); break; case RS_READ_INCMPLT: RcError( ERR_UNEXPECTED_EOF, inexe->name ); break; case RS_WRITE_ERROR: RcError( ERR_WRITTING_FILE, outexe->name, strerror( errno ) ); break; default: RcError( ERR_INTERNAL, INTERR_UNKNOWN_RCSTATUS ); break; } return( true ); }