static bool ScanOptionsArg( const char * arg ) { bool contok; int predeftype; contok = true; switch (*arg) { case '\0': puts( "Error: no option specifed after option character" ); contok = false; break; case 'n': arg++; if (*arg != '=') { puts( "Missing = after option n" ); contok = false; } else { arg++; if (isdigit( *arg )) { CmdLineParms.Name = WResIDFromNum( atoi( arg ) ); } else { CmdLineParms.Name = WResIDFromStr( arg ); } } break; case 't': arg++; if (*arg != '=') { puts( "Missing = after option t" ); contok = false; } else { arg++; if (isdigit( *arg )) { CmdLineParms.Type = WResIDFromNum( atoi( arg ) ); } else { predeftype = CheckPredefType( arg ); if (predeftype == 0) { CmdLineParms.Type = WResIDFromStr( arg ); } else { CmdLineParms.Type = WResIDFromNum( predeftype ); } } } break; default: /* option that could have others with it */ contok = ScanMultiOptArg( arg ) && contok; break; } return( contok ); }
WResID *WGetWResIDFromEdit( HWND edit, bool *mod ) { WResID *rp; uint_16 ordID; char *cp; char *ep; rp = NULL; cp = WGetStrFromEdit( edit, mod ); /* find out if the edit field has changed */ if( mod == NULL || *mod ) { if( cp == NULL ) { return( NULL ); } ordID = (uint_16)strtoul( cp, &ep, 0 ); if( *ep == '\0' ) { rp = WResIDFromNum( ordID ); } else { rp = WResIDFromStr( cp ); } } if( cp != NULL ) { WRMemFree( cp ); } return( rp ); }
void WHandleMemFlags( WStringEditInfo *einfo ) { char *rtext; char *ntext; WResID *rname; ntext = AllocRCString( W_STRINGNAMES ); if( einfo != NULL && einfo->current_block != NULL && ntext != NULL ) { WSetStatusByID( einfo->wsb, W_CHANGESTRINGMEMFLAGS, -1 ); // alloc space for ntext and two 16-bit ints rtext = (char *)WRMemAlloc( strlen( ntext ) + 20 ); if( rtext != NULL ) { sprintf( rtext, ntext, einfo->current_block->blocknum & 0xfff0, (einfo->current_block->blocknum & 0xfff0) + 16 - 1 ); } rname = WResIDFromStr( rtext ); if( rname != NULL ) { einfo->info->modified |= WChangeMemFlags( einfo->win, &einfo->current_block->MemFlags, rname, WGetEditInstance(), WStrHelpRoutine ); WRMemFree( rname ); } FreeRCString( ntext ); WSetStatusReadyText( einfo->wsb ); } }
int WRLoadBitmapFile( WRInfo *info ) { int ok; int file_handle; long int file_length; char fn[_MAX_FNAME]; WResID *type; WResID *name; WResLangType def_lang; file_handle = -1; def_lang.sublang = DEF_LANG; def_lang.lang = DEF_SUBLANG; ok = ( info != NULL ); if( ok ) { ok = ( ( file_handle = ResOpenFileRO( info->file_name ) ) != -1 ); } if( ok ) { file_length = filelength( file_handle ); ok = ( ( file_length != 0 ) && ( file_length != -1 ) ); } if( ok ) { type = WResIDFromNum( (long)RT_BITMAP ); ok = ( type != NULL ); } if( ok ) { _splitpath( info->file_name, NULL, NULL, fn, NULL ); name = WResIDFromStr( fn ); ok = ( name != NULL ); } if( ok ) { ok = ( ( info->dir = WResInitDir() ) != NULL ); } if( ok ) { ok = !WResAddResource( type, name, 0, sizeof(BITMAPFILEHEADER), file_length - sizeof(BITMAPFILEHEADER), info->dir, &def_lang, NULL ); } if( file_handle != -1 ) { ResCloseFile( file_handle ); } if( name ) { WRMemFree( name ); } if( type ) { WRMemFree( type ); } return( ok ); }
static WResID * ConvertNameOrOrdToID( ResNameOrOrdinal * name ) /*************************************************************/ { if (name->ord.fFlag == 0xff) { return( WResIDFromNum( name->ord.wOrdinalID ) ); } else { return( WResIDFromStr( name->name ) ); } }
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 ); }
WResID *WRGetUniCodeWResID( WResFileID file_handle, uint_32 rva ) { uint_32 old_pos; uint_32 offset; uint_16 len; bool ok; char *unistr; WResID *id; int i; offset = WR_MAP_RES_RVA( rva ); unistr = NULL; /* seek to the location of the Unicode string */ ok = ((old_pos = ResSeek( file_handle, offset, SEEK_SET )) != -1); /* read the Unicode string */ if( ok ) { ResReadUint16( &len, file_handle ); len *= 2; unistr = (char *)MemAlloc( len + 2 ); ok = (unistr != NULL); } if( ok ) { unistr[len] = 0; unistr[len + 1] = 0; ok = (read( file_handle, unistr, len ) == len); } if( ok ) { for( i = 0; i < len + 2; i += 2 ) { unistr[i / 2] = unistr[i]; } ok = ((id = WResIDFromStr( unistr )) != NULL); } #if 0 if( old_pos != -1 ) { ok = (ResSeek( file_handle, old_pos, SEEK_SET ) != -1 && ok); } #endif if( unistr != NULL ) { MemFree( unistr ); } if( ok ) { return( id ); } else { return( NULL ); } }
void SemOS2WriteFontDir( void ) /*****************************/ { FullFontDirEntry * currentry; ResLocation loc; bool error; if( CurrResFile.FontDir == NULL ) { return; } loc.start = SemStartResource(); error = ResWriteUint16( &(CurrResFile.FontDir->NumOfFonts), CurrResFile.handle ); if( error) goto OUTPUT_WRITE_ERROR; for( currentry = CurrResFile.FontDir->Head; currentry != NULL; currentry = currentry->Next ) { error = ResWriteFontDirEntry( &(currentry->Entry), CurrResFile.handle ); if( error ) { goto OUTPUT_WRITE_ERROR; } } loc.len = SemEndResource( loc.start ); SemAddResourceFree( WResIDFromStr( FONT_DIR_NAME ), WResIDFromNum( (long)RT_FONTDIR ), FONT_DIR_FLAGS, loc ); FreeFontDir( CurrResFile.FontDir ); CurrResFile.FontDir = NULL; return; OUTPUT_WRITE_ERROR: RcError( ERR_WRITTING_RES_FILE, CurrResFile.filename, LastWresErrStr() ); ErrorHasOccured = true; FreeFontDir( CurrResFile.FontDir ); CurrResFile.FontDir = NULL; return; }
WResID *WRECreateAccTitle( void ) { char *text; char *title; WResID *name; WRENumAccTitles++; name = NULL; text = AllocRCString( WRE_DEFACCELNAME ); if( text != NULL ) { title = (char *)WRMemAlloc( strlen( text ) + 20 + 1 ); if( title != NULL ) { title[0] = '\0'; sprintf( title, text, WRENumAccTitles ); name = WResIDFromStr( title ); WRMemFree( title ); } FreeRCString( text ); } return( name ); }
void WdeChangeDialogInfo( WdeInfoStruct *is ) { WdeInfoStruct c_is; char *str; char *cp; bool quoted_str; bool str_is_ordinal; uint_16 ord; bool found; WdeHashValue value; c_is = *is; str = NULL; cp = WdeGetStrFromEdit( WdeInfoWindow, IDB_INFO_CAPTION, NULL ); if( cp != NULL ) { str = WRConvertStringTo( cp, "\t\n", "tn" ); WRMemFree( cp ); } c_is.d.caption = str; str = WdeGetStrFromCombo( WdeInfoWindow, IDB_INFO_IDSTR ); if( str == NULL ) { WRMemFree( c_is.d.caption ); c_is.d.caption = NULL; return; } WRStripSymbol( str ); quoted_str = FALSE; if( _mbclen( (unsigned char *)str ) == 1 && str[0] == '"' ) { unsigned char *s; str[0] = ' '; cp = NULL; for( s = (unsigned char *)str; *s != '\0'; s = _mbsinc( s ) ) { if( _mbclen( s ) == 1 && *s == '"' ) { cp = (char *)s; } } if( cp != NULL ) { *cp = '\0'; } WRStripSymbol( str ); quoted_str = TRUE; } if( str[0] == '\0' ) { WRMemFree( str ); WRMemFree( c_is.d.caption ); c_is.d.caption = NULL; return; } ord = (uint_16)strtoul( str, &cp, 0 ); str_is_ordinal = (*cp == '\0'); c_is.symbol = NULL; if( quoted_str ) { c_is.d.name = WResIDFromStr( str ); WRMemFree( str ); } else if( str_is_ordinal ) { c_is.d.name = WResIDFromNum( ord ); WRMemFree( str ); } else { if( !WdeIsValidSymbol( str ) ) { WRMemFree( str ); WRMemFree( c_is.d.caption ); c_is.d.caption = NULL; return; } strupr( str ); c_is.symbol = str; c_is.d.name = NULL; } Forward( is->obj, MODIFY_INFO, &c_is, NULL ); if( c_is.symbol ) { WdeAddUniqueStringToCombo( WdeInfoWindow, IDB_INFO_IDSTR, c_is.symbol ); value = WdeLookupName( c_is.res_info->hash_table, c_is.symbol, &found ); if( found ) { WdeSetEditWithSINT32( (int_32)value, 10, WdeInfoWindow, IDB_INFO_IDNUM ); } } else if( str_is_ordinal ) { WdeSetEditWithSINT32( (int_32)ord, 10, WdeInfoWindow, IDB_INFO_IDNUM ); } else { WdeSetEditWithStr( "", WdeInfoWindow, IDB_INFO_IDNUM ); } *is = c_is; }
int WRLoadCursorFile( WRInfo *info ) { BYTE *data; uint_32 data_size; CURSORHEADER *ch; uint_32 chsize; RESCURSORHEADER *rch; uint_32 rchsize; WResFileID file; WResID *tname; WResID *rname; WResLangType lang; char fn[_MAX_FNAME]; int dup; int i; int ok; data = NULL; rch = NULL; dup = FALSE; file = -1; lang.lang = DEF_LANG; lang.sublang = DEF_SUBLANG; tname = NULL; rname = NULL; ok = ( info && info->file_name ); if( ok ) { ok = ( ( file = ResOpenFileRO( info->file_name ) ) != -1 ); } if( ok ) { ok = WRReadEntireFile( file, &data, &data_size ); } if( ok ) { ch = (CURSORHEADER *) data; chsize = sizeof(CURSORHEADER); chsize += sizeof(CURSORDIRENTRY)*(ch->cdCount-1); ok = WRCreateCursorResHeader( &rch, &rchsize, data, data_size ); } if( ok ) { ok = ( ( info->dir = WResInitDir() ) != NULL ); } if( ok ) { tname = WResIDFromNum( (uint_16)RT_GROUP_CURSOR ); ok = ( tname != NULL ); } if( ok ) { _splitpath( info->file_name, NULL, NULL, fn, NULL ); rname = WResIDFromStr( fn ); ok = ( rname != NULL ); } if ( ok ) { ok = !WResAddResource( tname, rname, DEF_MEMFLAGS, 0, rchsize, info->dir, &lang, &dup ); } if( ok ) { ok = WRFindAndSetData( info->dir, tname, rname, &lang, rch ); } if( ok ) { for( i=0; ok && i<ch->cdCount ; i++ ) { ok = WRGetAndAddCursorImage( data, info->dir, &ch->cdEntries[i], i+1 ); } } if( !ok ) { if( info->dir ) { WRFreeWResDirData( info->dir ); WResFreeDir( info->dir ); info->dir = NULL; } } if( tname != NULL ) { WRMemFree( tname ); } if( rname != NULL ) { WRMemFree( rname ); } if( file != -1 ) { ResCloseFile( file ); } return( ok ); }
bool WSaveObjectAs( bool get_name, WAccelEditInfo *einfo ) { char resfile[_MAX_PATH]; char *fname; WRFileType ftype; WRFileType rtype; WGetFileStruct gf; WRSaveIntoData idata; WRSaveIntoData idata2; bool got_name; bool ok; fname = NULL; got_name = FALSE; ok = (einfo != NULL); if( ok ) { memset( &idata2, 0, sizeof( idata2 ) ); if( einfo->info->symbol_file != NULL ) { idata2.next = NULL; idata2.type = WResIDFromNum( RESOURCE2INT( RT_RCDATA ) ); idata2.name = WResIDFromStr( "DLGINCLUDE" ); idata2.data = einfo->info->symbol_file; idata2.lang = einfo->info->lang; idata2.size = (uint_32)( strlen( einfo->info->symbol_file ) + 1 ); idata2.MemFlags = MEMFLAG_DISCARDABLE; } } if( ok ) { idata.next = NULL; if( einfo->info->symbol_file != NULL ) { idata.next = &idata2; } idata.type = WResIDFromNum( RESOURCE2INT( RT_ACCELERATOR ) ); ok = (idata.type != NULL); } if( ok ) { if( einfo->file_name == NULL || get_name ) { gf.file_name = NULL; gf.title = AllocRCString( W_SAVERESAS ); gf.filter = AllocRCString( W_SAVERESFILTER ); WMassageFilter( gf.filter ); fname = WGetSaveFileName( einfo->win, &gf ); if( gf.title != NULL ) { FreeRCString( gf.title ); } if( gf.filter != NULL ) { FreeRCString( gf.filter ); } if( fname != NULL ) { got_name = TRUE; } } else { fname = einfo->file_name; } ok = (fname != NULL); } if( ok ) { if( got_name ) { ftype = WSelectFileType( einfo->win, fname, einfo->info->is32bit, TRUE, WGetEditInstance(), WAccHelpRoutine ); } else { ftype = einfo->file_type; } ok = (ftype != WR_DONT_KNOW); } if( ok ) { if( ftype == WR_WIN_RC_ACCEL ) { ok = WSaveObjectToRC( einfo, fname, FALSE, FALSE ); if( ok ) { WGetInternalRESName( fname, resfile ); if( einfo->info->is32bit ) { rtype = WR_WINNTW_RES; } else { rtype = WR_WIN16W_RES; } } } else { strcpy( resfile, fname ); rtype = ftype; } } if( ok ) { idata.name = einfo->info->res_name; idata.data = einfo->info->data; idata.lang = einfo->info->lang; idata.size = (uint_32)einfo->info->data_size; idata.MemFlags = einfo->info->MemFlags; ok = WRSaveObjectAs( resfile, rtype, &idata ); } if( ok ) { if( got_name ) { if( einfo->file_name != NULL ) { WRMemFree( einfo->file_name ); } einfo->file_name = fname; einfo->file_type = ftype; WSetEditTitle( einfo ); } } else { if( fname != NULL && got_name ) { WRMemFree( fname ); } } if( idata.type != NULL ) { WRMemFree( idata.type ); } if( idata2.type != NULL ) { WRMemFree( idata2.type ); } if( idata2.name != NULL ) { WRMemFree( idata2.name ); } return( ok ); }
int WRLoadIconFile( WRInfo *info ) { BYTE *data; uint_32 data_size; ICONHEADER *pih; uint_32 pihsize; RESICONHEADER *rih; uint_32 rihsize; WResFileID file; WResID *tname; WResID *rname; WResLangType lang; char fn[_MAX_FNAME]; int dup; int i; int ok; data = NULL; rih = NULL; dup = FALSE; file = -1; lang.lang = DEF_LANG; lang.sublang = DEF_SUBLANG; tname = NULL; rname = NULL; ok = (info != NULL && info->file_name != NULL); if( ok ) { ok = ((file = ResOpenFileRO( info->file_name )) != -1); } if( ok ) { ok = WRReadEntireFile( file, &data, &data_size ); } if( ok ) { pih = (ICONHEADER *)data; pihsize = sizeof( ICONHEADER ); pihsize += sizeof( ICONDIRENTRY ) * (pih->idCount - 1); ok = WRCreateIconResHeader( &rih, &rihsize, data, data_size ); } if( ok ) { ok = ((info->dir = WResInitDir()) != NULL); } if( ok ) { tname = WResIDFromNum( (uint_16)RT_GROUP_ICON ); ok = (tname != NULL); } if( ok ) { _splitpath( info->file_name, NULL, NULL, fn, NULL ); rname = WResIDFromStr( fn ); ok = (rname != NULL); } if ( ok ) { ok = !WResAddResource( tname, rname, DEF_MEMFLAGS, 0, rihsize, info->dir, &lang, &dup ); } if( ok ) { ok = WRFindAndSetData( info->dir, tname, rname, &lang, rih ); } if( ok ) { for( i = 0; ok && i < pih->idCount; i++ ) { ok = WRGetAndAddIconImage( data, info->dir, &pih->idEntries[i], i + 1 ); } } if( !ok ) { if( info->dir != NULL ) { WRFreeWResDirData( info->dir ); WResFreeDir( info->dir ); info->dir = NULL; } } if( data != NULL ) { WRMemFree( data ); } if( tname != NULL ) { WRMemFree( tname ); } if( rname != NULL ) { WRMemFree( rname ); } if( file != -1 ) { ResCloseFile( file ); } return( ok ); }