bool ResWriteDialogBoxControl( DialogBoxControl *control, FILE *fp ) /******************************************************************/ { bool error; error = ResWriteDialogSizeInfo( &(control->SizeInfo), fp ); if( !error ) { error = ResWriteUint16( control->ID, fp ); } if( !error ) { error = ResWriteUint32( control->Style, fp ); } /* if the ClassID is one of the predefined ones write it out as a byte */ /* otherwise it is a string */ if( !error ) { if( control->ClassID->Class & 0x80 ) { error = ResWriteUint8( control->ClassID->Class, fp ); } else { error = ResWriteString( control->ClassID->ClassName, false, fp ); } } if( !error ) { error = ResWriteNameOrOrdinal( control->Text, false, fp ); } if( !error ) { error = ResWriteUint8( control->ExtraBytes, fp ); } return( error ); }
bool ResWriteDialogBoxExHeader32( DialogBoxHeader32 *head, DialogBoxExHeader32short *exhead, FILE *fp ) /*****************************************************************************************************/ { bool error; /* Write out the miscellaneous two WORDs 0x0001, 0xFFFF */ error = ResWriteUint16( 0x0001, fp ); if( !error ) { error = ResWriteUint16( 0xFFFF, fp ); } if( !error ) { error = ResWriteUint32( exhead->HelpId, fp ); } if( !error ) { error = ResWriteUint32( head->ExtendedStyle, fp ); } if( !error ) { error = ResWriteUint32( head->Style, fp ); } if( !error ) { error = ResWriteUint16( head->NumOfItems, fp ); } if( !error ) { error = ResWriteDialogSizeInfo( &(head->SizeInfo), fp ); } if( !error ) { error = ResWriteDialogHeaderCommon32( head, fp, true ); } /* If the font was set, write the font information */ if( !error && (head->Style & DS_SETFONT) ) { error = ResWriteUint16( head->PointSize, fp ); if( !error ) { error = ResWriteUint16( exhead->FontWeight, fp ); } if( !error ) { error = ResWriteUint8( exhead->FontItalic, fp ); } if( !error ) { error = ResWriteUint8( exhead->FontCharset, fp ); } if( !error ) { error = ResWriteString( head->FontName, true, fp ); } } if( !error ) { /* padding full record to dword boundary if necessary */ error = ResWritePadDWord( fp ); } return( error ); }
int ResWriteNameOrOrdinal( ResNameOrOrdinal *name, uint_8 use_unicode, int handle ) /*********************************************************************************/ { int error; uint_16 flag; uint_16 tmp16; uint_8 tmp8; if( name == NULL ) { error = ResWriteString( "", use_unicode, handle ); } else { if (name->ord.fFlag == 0xff) { if( use_unicode ) { flag = 0xffff; error = ResWriteUint16( &flag, handle ); } else { tmp8 = name->ord.fFlag; error = ResWriteUint8( &tmp8, handle ); } if (!error) { tmp16 = name->ord.wOrdinalID; ResWriteUint16( &tmp16, handle ); } } else { error = ResWriteString( name->name, use_unicode, handle ); } } return( error ); } /* ResWriteNameOrOrdinal */
bool ResWriteDialogBoxHeader( DialogBoxHeader *head, FILE *fp ) /*************************************************************/ { bool error; error = ResWriteUint32( head->Style, fp ); if( !error ) { error = ResWriteUint8( head->NumOfItems, fp ); } if( !error ) { error = ResWriteDialogSizeInfo( &(head->SizeInfo), fp ); } if( !error ) { error = ResWriteNameOrOrdinal( head->MenuName, false, fp ); } if( !error ) { error = ResWriteNameOrOrdinal( head->ClassName, false, fp ); } if( !error ) { error = ResWriteString( head->Caption, false, fp ); } /* if the font was set output the font name and point size */ if( !error && (head->Style & DS_SETFONT) ) { error = ResWriteUint16( head->PointSize, fp ); if( !error ) { error = ResWriteString( head->FontName, false, fp ); } } return( error ); }
extern int ResOS2WriteStringTableBlock( StringTableBlock *currblock, int handle, uint_32 codepage ) /********************************************************************/ { int stringid; int error; WResIDName *name; uint_16 tmp16; uint_8 tmp8; uint_8 tmpzero = 0; // Write string table codepage tmp16 = codepage; error = ResWriteUint16( &tmp16, handle ); if( error ) return( error ); tmp16 = 1; for( stringid = 0, error = FALSE; stringid < STRTABLE_STRS_PER_BLOCK && !error; stringid++ ) { name = currblock->String[ stringid ]; if( name == NULL ) { // Write an empty string error = ResWriteUint16( &tmp16, handle ); } else { // The string can't be longer than 255 chars tmp8 = (name->NumChars + 1) & 0xFF; error = ResWriteUint8( &tmp8, handle ); if( !error ) error = ResWriteStringLen( name->Name, FALSE, handle, tmp8 - 1 ); // The terminating NULL is not stored in the table, need to add it now if( !error ) error = ResWriteUint8( &tmpzero, handle ); } } return( error ); } /* ResOS2WriteStringTableBlock */
static bool ResOS2WriteStringTableBlock( StringTableBlock *currblock, WResFileID fid, uint_32 codepage ) /******************************************************************************************************/ { int stringid; bool error; WResIDName *name; // Write string table codepage error = ResWriteUint16( codepage, fid ); if( error ) return( error ); error = false; for( stringid = 0; stringid < STRTABLE_STRS_PER_BLOCK && !error; stringid++ ) { name = currblock->String[stringid]; if( name == NULL ) { // Write an empty string error = ResWriteUint16( 1, fid ); } else { size_t len; // The string can't be longer than 255 chars len = name->NumChars + 1; if( len > 255 ) len = 255; error = ResWriteUint8( len, fid ); if( !error ) error = ResWriteStringLen( name->Name, false, fid, len - 1 ); // The terminating NULL is not stored in the table, need to add it now if( !error ) { error = ResWriteUint8( 0, fid ); } } } return( error ); } /* ResOS2WriteStringTableBlock */
int WResWriteWResIDNameUni( const WResIDName *name, uint_8 use_unicode, int handle ) /**********************************************************************************/ { int error; wio_ssize_t numwrote; uint_16 numchars; uint_8 tmp; char *ptr; int freebuf; freebuf = FALSE; error = FALSE; if (name == NULL) { /* a NULL name means write 0 length name */ numchars = 0; } else { numchars = name->NumChars; } if( use_unicode ) { // for short strings use a static buffer in improve performance if( numchars <= CONV_BUF_SIZE / 2 ) { ptr = ConvBuffer; } else { freebuf = TRUE; ptr = WRESALLOC( 2 * numchars ); } numchars = (ConvToUnicode)( numchars, name->Name, ptr ) / 2; error = ResWriteUint16( &numchars, handle ); numchars *= 2; } else { numchars &= 0xFF; /* in 16-bit the string can be no more than 256 characters*/ tmp = numchars; ptr = (char *)name->Name; error = ResWriteUint8( &tmp, handle ); } if( !error && numchars > 0 ) { numwrote = WRESWRITE( handle, ptr, numchars ); if( numwrote != numchars ) { error = TRUE; WRES_ERROR( WRS_WRITE_FAILED ); } } if( freebuf ) { WRESFREE( ptr ); } return( error ); } /* WResWriteWResIDNameUni */
bool WResWriteWResID( const WResID *name, WResFileID handle ) /***********************************************************/ { bool error; error = ResWriteUint8( name->IsName, handle ); if( !error ) { if( name->IsName ) { error = WResWriteWResIDName( &(name->ID.Name), handle ); } else { error = ResWriteUint16( name->ID.Num, handle ); } } return( error ); } /* WResWriteWResID */
bool WResWriteWResIDNameUni( const WResIDName *name, bool use_unicode, WResFileID handle ) /******************************************************************************************/ { bool error; uint_16 numchars; char *ptr; bool freebuf; freebuf = false; error = false; if( name == NULL ) { /* a NULL name means write 0 length name */ numchars = 0; } else { numchars = name->NumChars; } if( use_unicode ) { // for short strings use a static buffer in improve performance if( numchars <= CONV_BUF_SIZE / 2 ) { ptr = ConvBuffer; } else { freebuf = true; ptr = WRESALLOC( 2 * numchars ); } numchars = (ConvToUnicode)( numchars, name->Name, ptr ) / 2; error = ResWriteUint16( numchars, handle ); numchars *= 2; } else { /* in 16-bit resources the string can be no more than 255 characters */ if( numchars > 0xFF ) numchars = 0xFF; ptr = (char *)name->Name; error = ResWriteUint8( numchars, handle ); } if( !error && numchars > 0 ) { if( WRESWRITE( handle, ptr, numchars ) != numchars ) { error = true; WRES_ERROR( WRS_WRITE_FAILED ); } } if( freebuf ) { WRESFREE( ptr ); } return( error ); } /* WResWriteWResIDNameUni */
int WResWriteWResID( const WResID *name, int handle ) /***************************************************/ { int error; uint_16 tmp16; uint_8 tmp8; tmp8 = name->IsName; error = ResWriteUint8( &tmp8, handle ); if( !error ) { if( name->IsName ) { error = WResWriteWResIDName( &(name->ID.Name), handle ); } else { tmp16 = name->ID.Num; error = ResWriteUint16( &tmp16, handle ); } } return( error ); } /* WResWriteWResID */
bool ResWriteMenuExHeader( MenuHeader *currhead, WResFileID handle, uint_8 *headerdata ) /**************************************************************************************/ { bool error; int i; if( WRESWRITE( handle, currhead, sizeof( MenuHeader ) ) != sizeof( MenuHeader ) ) { WRES_ERROR( WRS_WRITE_FAILED ); return( true ); } else { if( headerdata != NULL ) { for( i = 0; i < currhead->HeaderSize; i++ ) { error = ResWriteUint8( headerdata + i, handle ); if( error ) { WRES_ERROR( WRS_WRITE_FAILED ); return( true ); } } } return( false ); } }
bool ResWriteNameOrOrdinal( ResNameOrOrdinal *name, bool use_unicode, WResFileID handle ) /*****************************************************************************************/ { bool error; if( name == NULL ) { error = ResWriteString( "", use_unicode, handle ); } else { if( name->ord.fFlag == 0xff ) { if( use_unicode ) { error = ResWriteUint16( (uint_16)-1, handle ); } else { error = ResWriteUint8( name->ord.fFlag, handle ); } if( !error ) { error = ResWriteUint16( name->ord.wOrdinalID, handle ); } } else { error = ResWriteString( name->name, use_unicode, handle ); } } return( error ); } /* ResWriteNameOrOrdinal */
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; } } }