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 */
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 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 ); }
char * WResHelpIDToStr( const WResHelpID * name ) /***************************************/ /* return the value in a Help ID if it is a string, NULL otherwise */ { char *string; if ( name != NULL && name->IsName) { /* alloc space for the string and a \0 char at the end */ string = WRESALLOC( name->ID.Name.NumChars + 1 ); if (string == NULL) { WRES_ERROR( WRS_MALLOC_FAILED ); } else { /* copy the string */ memcpy( string, name->ID.Name.Name, name->ID.Name.NumChars ); string[ name->ID.Name.NumChars ] = '\0'; } } else { string = WRESALLOC( UINT32_MAXDIGITS + 1 ); if( string == NULL ) { WRES_ERROR( WRS_MALLOC_FAILED ); } else { itoa( name->ID.Num, string, 10 ); } } return( string ); } /* WResHelpIDToStr */
WResHelpID * WResHelpIDFromStr( const char * newstr ) /*******************************************/ /* allocate a Help ID and fill it in */ { WResHelpID *newid; unsigned strsize; strsize = strlen( newstr ); /* check the size of the string: can it fit in one byte? */ if (strsize <= 0xff) { /* allocate the new Help ID */ // if strsize is non-zero then the memory allocated is larger // than required by 1 byte newid = WRESALLOC( sizeof(WResHelpID) + strsize ); if (newid == NULL) { WRES_ERROR( WRS_MALLOC_FAILED ); } else { newid->IsName = TRUE; newid->ID.Name.NumChars = strsize; memcpy( newid->ID.Name.Name, newstr, strsize ); } } else { WRES_ERROR( WRS_BAD_PARAMETER ); newid = NULL; } return( newid ); } /* WResHelpIDFromStr */
extern ResNameOrOrdinal * WResHelpIDToNameOrOrd( WResHelpID * id ) /********************************************************/ { ResNameOrOrdinal * newname; if (id->IsName) { /* the one char in the ResNameOrOrdinal gives room for the '\0' */ newname = WRESALLOC( sizeof(ResNameOrOrdinal) + id->ID.Name.NumChars ); if (newname == NULL) { WRES_ERROR( WRS_MALLOC_FAILED ); } else { memcpy( newname->name, id->ID.Name.Name, id->ID.Name.NumChars ); newname->name[ id->ID.Name.NumChars ] = '\0'; } } else { newname = WRESALLOC( sizeof(ResNameOrOrdinal) ); if (newname == NULL) { WRES_ERROR( WRS_MALLOC_FAILED ); } else { newname->ord.fFlag = 0xff; newname->ord.wOrdinalID = id->ID.Num; } } return( newname ); }
extern ResNameOrOrdinal * ResStrToNameOrOrd( char * string ) /**********************************************************/ { ResNameOrOrdinal * newname; int stringlen; if( string == NULL || *(unsigned char *)string == 0xff ) { /* the first character of a ResNameOrOrdinal can't be 0xff */ /* since this indicated that it is an ordinal, not a name */ WRES_ERROR( WRS_BAD_PARAMETER ); return( NULL ); } stringlen = strlen( string ); newname = WRESALLOC( sizeof(ResNameOrOrdinal) + stringlen ); if (newname != NULL) { /* +1 so we get the '\0' as well */ memcpy( &(newname->name), string, stringlen + 1 ); } else { WRES_ERROR( WRS_MALLOC_FAILED ); } return( newname ); }
bool WResFileInit( WResFileID handle ) /************************************/ /* Writes the initial file header out to the file. Later, when WResWriteDir */ /* is called the real header will be written out */ { WResHeader head; bool error; head.Magic[0] = WRESMAGIC0; head.Magic[1] = WRESMAGIC1; head.DirOffset = 0; head.NumResources = 0; head.NumTypes = 0; head.WResVer = WRESVERSION; /* write the empty record out at the begining of the file */ error = ( WRESSEEK( handle, 0, SEEK_SET ) == -1 ); if( error ) { WRES_ERROR( WRS_SEEK_FAILED ); } else { error = WResWriteHeaderRecord( &head, handle ); if( error ) { WRES_ERROR( WRS_SEEK_FAILED ); } else { /* leave room for the extended header */ error = ( WRESSEEK( handle, sizeof( WResExtHeader ), SEEK_CUR ) == -1 ); if( error ) { WRES_ERROR( WRS_SEEK_FAILED ); } } } return( error ); } /* WResFileInit */
static int readWResDir( WResFileID handle, WResDir currdir, void *fileinfo ) { WResHeader head; WResExtHeader ext_head; int error; off_t seekpos; /* read the header and check that it is valid */ error = WResReadHeaderRecord( &head, handle ); if( !error ) { if( head.Magic[0] != WRESMAGIC0 || head.Magic[1] != WRESMAGIC1 ) { error = TRUE; WRES_ERROR( WRS_BAD_SIG ); } } if( !error ) { if( head.WResVer > WRESVERSION ) { error = TRUE; WRES_ERROR( WRS_BAD_VERSION ); } } if( !error ) { if( head.WResVer >= 1 ) { /* * seek to the extended header and read it */ seekpos = WRESSEEK( handle, sizeof( head ), SEEK_CUR ); error = (seekpos == -1L); if( error ) { WRES_ERROR( WRS_SEEK_FAILED ); } else { error = WResReadExtHeader( &ext_head, handle ); } } else { ext_head.TargetOS = WRES_OS_WIN16; } } /* set up the initial info for the directory and seek to it's start */ if( !error ) { currdir->NumResources = head.NumResources; currdir->NumTypes = head.NumTypes; currdir->TargetOS = ext_head.TargetOS; seekpos = (* WRESSEEK) ( handle, head.DirOffset, SEEK_SET ); if( seekpos == -1L ) { error = TRUE; WRES_ERROR( WRS_SEEK_FAILED ); } } /* read in the list of types (and the resources) */ if( !error ) { error = readTypeList( handle, currdir, head.WResVer, fileinfo ); } return( error ); } /* readWResDir */
DepInfo *WResGetAutoDep( const char *fname ) { WResFileID handle; WResDir dir; bool dup_discarded; WResID *name; WResID *type; WResDirWindow window; WResLangInfo *info; DepInfo *ret; WResFileSSize numread; ret = NULL; handle = ResOpenFileRO( fname ); if( handle != WRES_NIL_HANDLE ) { if( WResIsWResFile( handle ) && (dir = WResInitDir()) != NULL ) { if( !WResReadDir( handle, dir, &dup_discarded ) ) { name = WResIDFromStr( DEP_LIST_NAME ); type = WResIDFromNum( DEP_LIST_TYPE ); if( name != NULL && type != NULL ) { window = WResFindResource( type, name, dir, NULL ); if( WResIsEmptyWindow( window ) ) { WRES_ERROR( WRS_RES_NOT_FOUND ); } else { info = WResGetLangInfo( window ); if( WRESSEEK( handle, info->Offset, SEEK_SET ) == -1 ) { WRES_ERROR( WRS_SEEK_FAILED ); } else { ret = WRESALLOC( info->Length ); if( ret == NULL ) { WRES_ERROR( WRS_MALLOC_FAILED ); } else { numread = WRESREAD( handle, ret, info->Length ); if( numread != (WResFileSSize)info->Length ) { WRES_ERROR( WRESIOERR( handle, numread ) ? WRS_READ_FAILED : WRS_READ_INCOMPLETE ); ret = NULL; } } } } } if( name != NULL ) { WResIDFree( name ); } if( type != NULL ) { WResIDFree( type ); } } WResFreeDir( dir ); } ResCloseFile( handle ); } return( ret ); }
extern int ResReadUint32( uint_32 * newint, WResFileID handle ) /*************************************************************/ { int numread; numread = WRESREAD( handle, newint, sizeof( uint_32 ) ); if( numread == sizeof( uint_32 ) ) { return( FALSE ); } else if( numread == -1 ) { WRES_ERROR( WRS_READ_FAILED ); } else if( numread != sizeof( uint_32 ) ) { WRES_ERROR( WRS_READ_INCOMPLETE ); } return( TRUE ); }
int WResReadFixedWResID( WResID *name, WResFileID handle ) /********************************************************/ /* reads the fixed part of a WResID */ { int numread; numread = WRESREAD( handle, name, sizeof(WResID) ); if( numread == sizeof(WResID) ) { return( FALSE ); } else if( numread == -1 ) { WRES_ERROR( WRS_READ_FAILED ); } else { WRES_ERROR( WRS_READ_INCOMPLETE ); } return( TRUE ); } /* WResReadFixedWResID */
static WResLangNode *newLangNode( uint_16 memflags, uint_32 offset, uint_32 length, WResLangType *type, void *fileinfo ) { WResLangNode *newnode; newnode = WRESALLOC( sizeof( WResLangNode ) ); if( newnode == NULL ) { WRES_ERROR( WRS_MALLOC_FAILED ); } else { newnode->Next = NULL; newnode->Prev = NULL; newnode->data = NULL; newnode->fileInfo = fileinfo; newnode->Info.MemoryFlags = memflags; newnode->Info.Offset = offset; newnode->Info.Length = length; if( type == NULL ) { newnode->Info.lang.lang = DEF_LANG; newnode->Info.lang.sublang = DEF_SUBLANG; } else { newnode->Info.lang = *type; } } return( newnode ); }
bool ResWriteMenuExItemNormal( const MenuItemNormal *curritem, const MenuExItemNormal *exdata, bool use_unicode, WResFileID handle ) /*******************************************************************************************/ { bool error; uint_16 tmp16; uint_32 tmp32; if( curritem->ItemFlags & MENUEX_POPUP ) { WRES_ERROR( WRS_BAD_PARAMETER ); error = true; } else { error = ResWriteUint32( &(exdata->ItemType), handle ); if( !error ) { error = ResWriteUint32( &(exdata->ItemState), handle ); } if( !error ) { tmp32 = curritem->ItemID; error = ResWriteUint32( &tmp32, handle ); } if( !error ) { tmp16 = curritem->ItemFlags; error = ResWriteUint16( &tmp16, handle ); } if( !error ) { error = ResWriteString( curritem->ItemText, use_unicode, handle ); } if( !error ) { error = ResPadDWord( handle ); } } return( error ); }
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 ); }
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 ); }
bool ResWrite( void *buffer, int len, WResFileID handle ) /*******************************************************/ { if( WRESWRITE( handle, buffer, len ) != len ) { WRES_ERROR( WRS_WRITE_FAILED ); return( true ); } return( false ); }
bool ResWriteAccelEntry32( AccelTableEntry32 *currentry, WResFileID handle ) /**************************************************************************/ { if( WRESWRITE( handle, currentry, sizeof( AccelTableEntry32 ) ) != sizeof( AccelTableEntry32 ) ) { WRES_ERROR( WRS_WRITE_FAILED ); return( true ); } return( false ); }
/* * WResWriteLangRecord - write out a language record at the current file * position */ bool WResWriteLangRecord( const WResLangInfo *info, WResFileID handle ) { if( WRESWRITE( handle, info, sizeof( WResLangInfo ) ) != sizeof( WResLangInfo ) ) { WRES_ERROR( WRS_WRITE_FAILED ); return( true ); } else { return( false ); } }
static bool ResOS2WriteAccelEntry( AccelTableEntryOS2 *currentry, WResFileID fid ) /********************************************************************************/ { if( RESWRITE( fid, currentry, sizeof( AccelTableEntryOS2 ) ) != sizeof( AccelTableEntryOS2 ) ) { WRES_ERROR( WRS_WRITE_FAILED ); return( true ); } return( false ); }
static bool ResOS2WriteHelpEntry( HelpTableEntryOS2 *currentry, WResFileID handle ) /**************************************************************************/ { if( RCWRITE( handle, currentry, sizeof( HelpTableEntryOS2 ) ) != sizeof( HelpTableEntryOS2 ) ) { WRES_ERROR( WRS_WRITE_FAILED ); return( true ); } return( false ); }
/* * WResReadFixedResRecord1 - reads the fixed part of a Res info record for * versions 1 and below */ bool WResReadFixedResRecord1( WResResInfo1 *newres, FILE *fp ) /************************************************************/ { size_t numread; if( (numread = WRESREAD( fp, newres, sizeof( WResResInfo1 ) )) != sizeof( WResResInfo1 ) ) return( WRES_ERROR( WRESIOERR( fp, numread ) ? WRS_READ_FAILED : WRS_READ_INCOMPLETE ) ); return( false ); }
bool ResWrite( void *buffer, WResFileSize len, WResFileID fid ) /*************************************************************/ { if( (WResFileSize)WRESWRITE( fid, buffer, len ) != len ) { WRES_ERROR( WRS_WRITE_FAILED ); return( true ); } return( false ); }
bool WResWriteHeaderRecord( const WResHeader *header, WResFileID handle ) /**********************************************************************/ { bool error; error = ( WRESSEEK( handle, 0L, SEEK_SET ) == -1 ); if( error ) { WRES_ERROR( WRS_SEEK_FAILED ); } if( !error ) { if( WRESWRITE( handle, header, sizeof( WResHeader ) ) != sizeof( WResHeader ) ) { error = true; WRES_ERROR( WRS_WRITE_FAILED ); } } return( error ); } /* WResWriteHeaderRecord */
WResID * WResIDFromNum( long newnum ) /***********************************/ /* allocate an ID and fill it in */ { WResID * newid; if( (int_32)newnum < SHRT_MIN || ( newnum > 0 && newnum > USHRT_MAX ) ) { newid = NULL; WRES_ERROR( WRS_BAD_PARAMETER ); } else { newid = WRESALLOC( sizeof( WResID ) ); if( newid == NULL ) { WRES_ERROR( WRS_MALLOC_FAILED ); } else { WResInitIDFromNum( newnum, newid ); } } return( newid ); } /* WResIDFromNum */
bool WResWriteExtHeader( const WResExtHeader *ext_head, WResFileID handle ) /*************************************************************************/ { if( WRESWRITE( handle, ext_head, sizeof( WResExtHeader ) ) != sizeof( WResExtHeader ) ) { WRES_ERROR( WRS_WRITE_FAILED ); return( true ); } else { return( false ); } }
bool ResWriteUint32( uint_32 newint, WResFileID handle ) /******************************************************/ { if( WRESWRITE( handle, &newint, sizeof( uint_32 ) ) != sizeof( uint_32 ) ) { WRES_ERROR( WRS_WRITE_FAILED ); return( true ); } else { return( false ); } }
bool ResWriteFontInfo( FontInfo *info, WResFileID fid ) /*****************************************************/ { if( WRESWRITE( fid, info, sizeof( FontInfo ) ) != sizeof( FontInfo ) ) { WRES_ERROR( WRS_WRITE_FAILED ); return( true ); } else { return( false ); } }
bool ResWriteFontDirEntry( FontDirEntry *entry, WResFileID fid ) /**************************************************************/ { if( WRESWRITE( fid, &(entry->Info), entry->StructSize ) != entry->StructSize ) { WRES_ERROR( WRS_WRITE_FAILED ); return( true ); } else { return( false ); } }
static bool ResOS2WriteMenuHeader( MenuHeaderOS2 *currhead, WResFileID handle ) /*********************************************************************/ { if( RCWRITE( handle, currhead, sizeof( MenuHeaderOS2 ) ) != sizeof( MenuHeaderOS2 ) ) { WRES_ERROR( WRS_WRITE_FAILED ); return( true ); } else { return( false ); } }