void ResFreeMenuItem( MenuItem * olditem ) /****************************************/ { if( olditem->IsPopup ) { if( olditem->Item.Popup.ItemText != NULL ) { WRESFREE( olditem->Item.Popup.ItemText ); } } else { if( olditem->Item.Normal.ItemText != NULL ) { WRESFREE( olditem->Item.Normal.ItemText ); } } WRESFREE( olditem ); }
extern int ResWriteStringLen( char *string, uint_8 use_unicode, int handle, uint_16 len ) /***************************************************************************************/ { wio_ssize_t numwrote; char *buf; int ret; if( use_unicode ) { if( len * 2 > CONV_BUF_SIZE ) { buf = WRESALLOC( 2 * len ); } else { buf = ConvBuffer; } len = (ConvToUnicode)( len, string, buf ); } else { buf = string; } numwrote = WRESWRITE( handle, buf, len ); if( numwrote != len ) { WRES_ERROR( WRS_WRITE_FAILED ); ret = TRUE; } else { ret = FALSE; } if( buf != ConvBuffer && buf != string ) { WRESFREE( buf ); } return( ret ); }
static int readLangInfoList( WResFileID handle, WResResNode *res, void *fileinfo ) { unsigned i; WResLangNode *langnode; int error; int numread; error = FALSE; for( i=0; i < res->Info.NumResources; i++ ) { langnode = WRESALLOC( sizeof(WResLangNode) ); if( langnode == NULL ) { error = TRUE; WRES_ERROR( WRS_MALLOC_FAILED ); } if( error ) break; numread = (* WRESREAD) ( handle, &(langnode->Info), sizeof( WResLangInfo ) ); if( numread != sizeof( WResLangInfo ) ) { error = TRUE; WRES_ERROR( numread == -1 ? WRS_READ_FAILED:WRS_READ_INCOMPLETE ); WRESFREE( langnode ); break; } langnode->data = NULL; langnode->fileInfo = fileinfo; ResAddLLItemAtEnd( (void **)&(res->Head), (void **)&(res->Tail), langnode ); } return( error ); }
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 */
static bool ResWriteDialogHeaderCommon32( DialogBoxHeader32 *head, FILE *fp, bool add_quotes ) /********************************************************************************************/ { bool error; size_t len; char *newname; if( add_quotes ) { if( head->MenuName != NULL && head->MenuName->name[0] != '\0' ) { len = strlen( head->MenuName->name ); newname = WRESALLOC( len + 3 ); newname[0] = '"'; strcpy( newname + 1, head->MenuName->name ); newname[len + 1] = '"'; newname[len + 2] = '\0'; head->MenuName = ResStrToNameOrOrd( newname ); WRESFREE( newname ); } } error = ResWriteNameOrOrdinal( head->MenuName, true, fp ); if( !error ) { error = ResWriteNameOrOrdinal( head->ClassName, true, fp ); } if( !error ) { error = ResWriteString( head->Caption, true, fp ); } return( error ); }
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 */
bool ResWriteStringLen( const char *string, bool use_unicode, WResFileID handle, uint_16 len ) /********************************************************************************************/ { char *buf = NULL; bool ret; if( use_unicode ) { if( len * 2 > CONV_BUF_SIZE ) { buf = WRESALLOC( 2 * len ); } else { buf = ConvBuffer; } len = (ConvToUnicode)( len, string, buf ); string = buf; } if( WRESWRITE( handle, string, len ) != len ) { WRES_ERROR( WRS_WRITE_FAILED ); ret = true; } else { ret = false; } if( use_unicode ) { if( buf != ConvBuffer ) { WRESFREE( buf ); } } return( ret ); }
void WResHelpIDFree( WResHelpID * oldid ) /*******************************/ /* release the space occupied by a Help ID */ { if( oldid != NULL ) { WRESFREE( oldid ); } } /* WResHelpIDFree */
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 ); }
ResNameOrOrdinal *ResRead32NameOrOrdinal( WResFileID handle ) /***********************************************************/ { uint_16 flags; uint_16 ord; ResNameOrOrdinal * newptr; int error; int stringlen; char * restofstr; restofstr = NULL; ord = 0; stringlen = 0; error = ResReadUint16( &flags, handle ); /* read the rest of the Name or Ordinal */ if( !error ) { if( flags == 0xffff ) { error = ResReadUint16( &ord, handle ); } else { if( flags != 0x0000 ) { restofstr = ResRead32String( 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 ) { if( flags == 0xffff ) { newptr->ord.fFlag = 0xff; newptr->ord.wOrdinalID = ord; } else { newptr->name[0] = (char)(flags & 0x00ff); if( flags != 0x0000 ) { memcpy( &(newptr->name[1]), restofstr, stringlen ); WRESFREE( restofstr ); } } } return( newptr ); }
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 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 */
MResResourceHeader *MResReadResourceHeader( WResFileID handle ) /*************************************************************/ { MResResourceHeader *newhead; int error; uint_16 tmp16; uint_32 tmp32; newhead = WRESALLOC( sizeof(MResResourceHeader) ); if( newhead == NULL ) { error = TRUE; WRES_ERROR( WRS_MALLOC_FAILED ); } else { error = FALSE; } if (!error) { newhead->Type = ResReadNameOrOrdinal( handle ); error = (newhead->Type == NULL); } if (!error) { newhead->Name = ResReadNameOrOrdinal( handle ); error = (newhead->Name == NULL); } if (!error) { error = ResReadUint16( &tmp16, handle); newhead->MemoryFlags = tmp16; } if (!error) { error = ResReadUint32( &tmp32, handle ); newhead->Size = tmp32; } if (error && newhead != NULL) { WRESFREE( newhead ); newhead = NULL; } return( newhead ); } /* MResReadResourceHeader */
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 */
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 */
char *ResRead32String( WResFileID handle, int *strlen ) /*****************************************************/ { VarString * newstring; bool error; uint_16 nextchar; char * retstring; newstring = VarStringStart(); error = ResReadUint16( &nextchar, handle ); while( !error && nextchar != 0x0000 ) { VarStringAddChar( newstring, (uint_8)(nextchar & 0x00ff) ); error = ResReadUint16( &nextchar, handle ); } retstring = VarStringEnd( newstring, strlen ); if( error && retstring != NULL ) { WRESFREE(retstring); retstring = NULL; } return( retstring ); } /* ResRead32String */
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 */
void WResFreeAutoDep( DepInfo *ptr ) { WRESFREE( ptr ); }
extern M32ResResourceHeader *M32ResReadResourceHeader( WResFileID handle ) /************************************************************************/ { M32ResResourceHeader *newhead; int error = FALSE; uint_16 tmp16; uint_32 tmp32; newhead = WRESALLOC( sizeof( M32ResResourceHeader ) ); if( newhead == NULL ) { error = TRUE; WRES_ERROR( WRS_MALLOC_FAILED ); } newhead->head16 = WRESALLOC( sizeof( MResResourceHeader ) ); if( newhead->head16 == NULL ) { error = TRUE; WRES_ERROR( WRS_MALLOC_FAILED ); } if( !error ) { error = ResPadDWord( handle ); } if( !error ) { error = ResReadUint32( &tmp32, handle ); newhead->head16->Size = tmp32; } if( !error ) { error = ResReadUint32( &(newhead->HeaderSize), handle ); } if( !error ) { newhead->head16->Type = ResRead32NameOrOrdinal( handle ); error = (newhead->head16->Type == NULL ); } if( !error ) { newhead->head16->Name = ResRead32NameOrOrdinal( handle ); error = (newhead->head16->Name == NULL ); } if( !error ) { error = ResPadDWord( handle ); } if( !error ) { error = ResReadUint32( &tmp32, handle ); newhead->head16->DataVersion = tmp32; } if( !error ) { error = ResReadUint16( &tmp16, handle ); newhead->head16->MemoryFlags = tmp16; } if( !error ) { error = ResReadUint16( &tmp16, handle ); newhead->head16->LanguageId = tmp16; } if( !error ) { error = ResReadUint32( &tmp32, handle ); newhead->head16->Version = tmp32; } if( !error ) { error = ResReadUint32( &tmp32, handle ); newhead->head16->Characteristics = tmp32; } if( error && newhead != NULL ) { WRESFREE( newhead->head16 ); WRESFREE( newhead ); newhead = NULL; } return( newhead ); }
static int readMResDir( WResFileID handle, WResDir currdir, int *dup_discarded, char iswin32, void *fileinfo ) /******************************************************************************/ { MResResourceHeader *head = NULL; M32ResResourceHeader *head32 = NULL; WResDirWindow dup; int error; off_t seek_rc; WResID *name; WResID *type; error = FALSE; if( iswin32 ) { /* Read NULL header */ head32 = M32ResReadResourceHeader( handle ); if( head32 != NULL ) { MResFreeResourceHeader( head32->head16 ); WRESFREE( head32 ); } else { error = TRUE; } if( !error ) { head32 = M32ResReadResourceHeader( handle ); if( head32 != NULL ) { head = head32->head16; } else { error = TRUE; } } } else { head = MResReadResourceHeader( handle ); if( head == NULL ) error = TRUE; } if( dup_discarded != NULL ) { *dup_discarded = FALSE; } if( iswin32 ) { currdir->TargetOS = WRES_OS_WIN32; } else { currdir->TargetOS = WRES_OS_WIN16; } /* assume that a NULL head is the EOF which is the only way of detecting */ /* the end of a MS .RES file */ while( head != NULL && !( iswin32 && head32 == NULL ) && !error ) { name = WResIDFromNameOrOrd( head->Name ); type = WResIDFromNameOrOrd( head->Type ); error = (name == NULL || type == NULL); /* MResReadResourceHeader leaves the file at the start of the resource*/ if( !error ) { if( !type->IsName && type->ID.Num == RT_NAMETABLE ) { error = FALSE; } else { error = WResAddResource2( type, name, head->MemoryFlags, WRESTELL( handle ), head->Size, currdir, NULL, &dup, fileinfo ); if( error && !WResIsEmptyWindow( dup ) ) { error = FALSE; if( dup_discarded != NULL ) { *dup_discarded = TRUE; } } } } if( !error ) { seek_rc = WRESSEEK( handle, head->Size, SEEK_CUR ); if( seek_rc == -1L ) { error = TRUE; WRES_ERROR( WRS_SEEK_FAILED ); } } if( name != NULL ) { WRESFREE( name ); name = NULL; } if( type != NULL ) { WRESFREE( type ); type = NULL; } MResFreeResourceHeader( head ); if( iswin32 ) { WRESFREE( head32 ); } if( !error ) { if( iswin32 ) { head32 = M32ResReadResourceHeader( handle ); if( head32 != NULL ) { head = head32->head16; } } else { head = MResReadResourceHeader( handle ); } } } return( error ); } /* readMResDir */