예제 #1
0
char *WRERectToStr( RECT *r )
{
    char temp[41];

    sprintf( temp, "%d, %d, %d, %d", r->left, r->top, r->right, r->bottom );

    return( WREStrDup( temp ) );
}
예제 #2
0
Bool WREOpenResource( char *fn )
{
    char                *name;
    WREResInfo          *res_info;
    WREGetFileStruct    gf;
    Bool                ok, got_name;

    res_info = NULL;
    name = NULL;
    got_name = FALSE;

    if( fn != NULL ) {
        if( WRFileExists( fn ) ) {
            ok = ((name = WREStrDup( fn )) != NULL);
        } else {
            ok = FALSE;
        }
    } else {
        gf.file_name = NULL;
        gf.title = WREResOpenTitle;
        gf.filter = WREResFilter;
        gf.save_ext = TRUE;
        ok = ((name = WREGetOpenFileName( &gf )) != NULL);
    }

    if( ok ) {
        got_name = TRUE;
        ok = ((res_info = WRELoadResource( name )) != NULL);
    }

    if( ok ) {
        WREFindAndLoadSymbols( res_info );
        ok = WRECreateResourceWindow( res_info );
    }

    if( ok ) {
        ListAddElt( &WREResList, (void *)res_info );
    } else {
        if( res_info != NULL ) {
            WREFreeResInfo( res_info );
            res_info = NULL;
        }
        if( got_name ) {
            WREDisplayErrorMsg( WRE_RESOURCESNOTLOADED );
        }
    }

    if( name != NULL ) {
        WREMemFree( name );
    }

    return( ok );
}
예제 #3
0
static bool WREGetStrOpt( char *entry, char **opt )
{
    char        str[_MAX_PATH];
    bool        ret;

    ret = GetPrivateProfileString( WRESectionName, entry, "",
                                   str, _MAX_PATH - 1, WREProfileName );

    if( ret ) {
        ret = ((*opt = WREStrDup( str )) != NULL);
    }

    return( ret );
}
예제 #4
0
WREAccelSession *WREStartAccelSession( WRECurrentResInfo *curr )
{
    WREAccelSession *session;

    if( curr == NULL ) {
        return( NULL );
    }

    session = WREAllocAccelSession();
    if( session == NULL ) {
        return( NULL );
    }

    session->info = WAccAllocAccelInfo();
    if( session->info == NULL ) {
        return( NULL );
    }

    session->info->parent = WREGetMainWindowHandle();
    session->info->inst = WREGetAppInstance();
    session->info->file_name = WREStrDup( WREGetQueryName( curr->info ) );
    session->info->res_name = WRECopyWResID( &curr->res->Info.ResName );
    session->info->lang = curr->lang->Info.lang;
    session->info->MemFlags = curr->lang->Info.MemoryFlags;
    session->info->data_size = curr->lang->Info.Length;
    session->info->data = curr->lang->data;
    session->info->is32bit = curr->info->is32bit;

    session->info->stand_alone = WRENoInterface;
    session->info->symbol_table = curr->info->symbol_table;
    session->info->symbol_file = curr->info->symbol_file;

    session->tnode = curr->type;
    session->rnode = curr->res;
    session->lnode = curr->lang;
    session->rinfo = curr->info;

    session->hndl = WAccelStartEdit( session->info );

    if( session->hndl ) {
        WREInsertObject( &WREAccSessions, session );
    } else {
        WAccFreeAccelInfo( session->info );
        WRMemFree( session );
        session = NULL;
    }

    return( session );
}
예제 #5
0
WREResInfo *WRECreateNewResource( char *filename )
{
    WREResInfo  *res_info;
    Bool        ok;

    ok = ((res_info = WREAllocResInfo()) != NULL);

    if( ok ) {
        res_info->info = WRAllocWRInfo();
        ok = (res_info->info != NULL);
    }

    if( ok ) {
        res_info->symbol_table = WRInitHashTable();
        ok = (res_info->symbol_table != NULL);
    }

    if( ok && filename != NULL ) {
        res_info->info->save_name = WREStrDup( filename );
        ok = (res_info->info->save_name != NULL);
    }

    if( ok ) {
#ifdef __NT__
        res_info->is32bit = TRUE;
#else
        res_info->is32bit = FALSE;
#endif
        if( res_info->is32bit ) {
            res_info->info->internal_type = WR_WINNTW_RES;
        } else {
            res_info->info->internal_type = WR_WIN16W_RES;
        }
        WREFindAndLoadSymbols( res_info );
        ok = WRECreateResourceWindow( res_info );
    }

    if( res_info != NULL ) {
        if( ok ) {
            ListAddElt( &WREResList, (void *)res_info );
        } else {
            WREFreeResInfo( res_info );
            res_info = NULL;
        }
    }

    return( res_info );
}
예제 #6
0
char *WRECreateSymName( char *fname )
{
    char        fn_path[_MAX_PATH];
    char        fn_drive[_MAX_DRIVE];
    char        fn_dir[_MAX_DIR];
    char        fn_name[_MAX_FNAME];

    if( fname == NULL ) {
        return( NULL );
    }

    _splitpath( fname, fn_drive, fn_dir, fn_name, NULL );
    _makepath( fn_path, fn_drive, fn_dir, fn_name, "h" );

    return( WREStrDup( fn_path ) );
}
예제 #7
0
void WREOptsShutdown( void )
{
    if( WRECurrentState.last_filter != NULL ) {
        WRMemFree( WRECurrentState.last_filter );
    }
    if( WRECurrentState.last_dir != NULL ) {
        WRMemFree( WRECurrentState.last_dir );
    }

    WRECurrentState.last_dir = WREStrDup( WREGetInitialDir() );
    WRECurrentState.last_filter = WREGetFileFilter();

    WREWriteOpts( &WRECurrentState );

    if( WRECurrentState.last_dir != NULL ) {
        WRMemFree( WRECurrentState.last_dir );
    }
}
예제 #8
0
static char *WRELoadSymbols( WRHashTable **table, char *file_name, bool prompt )
{
    char                *name;
    int                 c;
    unsigned            flags;
    char                *inc_path;
    WREGetFileStruct    gf;
    unsigned            pp_count;
    unsigned            busy_count;
    char                busy_str[2];
    bool                ret;
    bool                ok;

    name = NULL;

    ok = (table != NULL);

    if( ok ) {
        WRESetStatusText( NULL, "", FALSE );
        WRESetStatusByID( WRE_LOADINGSYMBOLS, -1 );
    }

    if( ok ) {
        if( file_name == NULL || prompt ) {
            gf.file_name = file_name;
            gf.title = WRESymLoadTitle;
            gf.filter = WRESymSaveFilter;
            gf.save_ext = FALSE;
            name = WREGetOpenFileName( &gf );
        } else {
            name = WREStrDup( file_name );
        }
        ok = (name != NULL);
    }

    WRESetWaitCursor( TRUE );

    if( ok ) {
        flags = PPFLAG_IGNORE_INCLUDE | PPFLAG_EMIT_LINE;
        inc_path = NULL;
        ret = setjmp( SymEnv );
        if( ret ) {
            PP_Fini();
            WREDisplayErrorMsg( WRE_SYMOUTOFMEM );
            ok = false;
        }
    }

    if( ok ) {
        ok = !PP_Init( name, flags, inc_path );
        if( !ok ) {
            WREDisplayErrorMsg( WRE_NOLOADHEADERFILE );
        }
    }

    if( ok ) {
        pp_count = 0;
        busy_count = 0;
        busy_str[1] = '\0';
        do {
            pp_count++;
            c = PP_Char();
            if( pp_count == MAX_PP_CHARS ) {
                busy_count++;
                busy_str[0] = WREBusyChars[busy_count % 4];
                WRESetStatusText( NULL, busy_str, TRUE );
                pp_count = 0;
            }
        } while( c != EOF );
        if( *table == NULL ) {
            *table = WRInitHashTable();
        }
        WREAddSymbols( *table );
        WRMakeHashTableClean( *table );
        PP_Fini();
        WRESetStatusText( NULL, " ", TRUE );
    }

    if( !ok ) {
        if( name != NULL ) {
            WRMemFree( name );
            name = NULL;
        }
    }

    WRESetWaitCursor( FALSE );

    WRESetStatusReadyText();

    return( name );
}
예제 #9
0
char *WREGetFileName( WREGetFileStruct *gf, DWORD flags, WREGetFileAction action )
{
    OPENFILENAME  wreofn;
    HWND          owner_window;
    Bool          ret;
    DWORD         error;
    int           len;
    char          fn_drive[_MAX_DRIVE];
    char          fn_dir[_MAX_DIR];
    char          fn_name[_MAX_FNAME];
    char          fn_ext[_MAX_EXT + 1];
    HINSTANCE     app_inst;

    if( gf == NULL ) {
        return( NULL );
    }

    owner_window = WREGetMainWindowHandle();
    app_inst = WREGetAppInstance();

    if( app_inst == NULL || owner_window == NULL ) {
        return( NULL );
    }

    if( gf->title != NULL ) {
        len = strlen( gf->title );
        if( len < _MAX_PATH ) {
            memcpy( wrefntitle, gf->title, len + 1 );
        } else {
            memcpy( wrefntitle, gf->title, _MAX_PATH );
            wrefntitle[_MAX_PATH - 1] = 0;
        }
    } else {
        wrefntitle[0] = 0;
    }

    if( gf->file_name != NULL && *gf->file_name != '\0' ) {
        _splitpath( gf->file_name, fn_drive, fn_dir, fn_name, fn_ext );
        if( *fn_drive != '\0' || *fn_dir != '\0' ) {
            _makepath( wre_initial_dir, fn_drive, fn_dir, NULL, NULL );
        }
        _makepath( wre_file_name, NULL, NULL, fn_name, fn_ext );
    } else {
        wre_file_name[0] = 0;
    }

    /* set the initial directory */
    if( *wre_initial_dir == '\0' ) {
        getcwd( wre_initial_dir, _MAX_PATH );
    }

#if !defined ( __NT__ )
    // CTL3D no longer requires this
    flags |= OFN_ENABLEHOOK;
#endif

    /* initialize the OPENFILENAME struct */
    memset( &wreofn, 0, sizeof( OPENFILENAME ) );

    /* fill in non-variant fields of OPENFILENAME struct */
    wreofn.lStructSize = sizeof( OPENFILENAME );
    wreofn.hwndOwner = owner_window;
    wreofn.hInstance = app_inst;
    wreofn.lpstrFilter = gf->filter;
    wreofn.lpstrCustomFilter = NULL;
    wreofn.nMaxCustFilter = 0;
    wreofn.nFilterIndex = WREFindFileFilterIndex( gf->filter );
    wreofn.lpstrFile = wre_file_name;
    wreofn.nMaxFile = _MAX_PATH;
    wreofn.lpstrFileTitle = wrefntitle;
    wreofn.nMaxFileTitle = _MAX_PATH;
    wreofn.lpstrInitialDir = wre_initial_dir;
    wreofn.lpstrTitle = wrefntitle;
    wreofn.Flags = flags;
    wreofn.lpfnHook = (LPVOID)MakeProcInstance( (LPVOID)WREOpenHookProc, app_inst );

#if 0
    wreofn.nFileOffset = 0L;
    wreofn.nFileExtension = 0L;
    wreofn.lpstrDefExt = NULL;
    wreofn.lCustData = NULL;
    wreofn.lpTemplateName = NULL;
#endif

    if( action == OPENFILE ) {
        ret = GetOpenFileName( (LPOPENFILENAME)&wreofn );
    } else if( action == SAVEFILE ) {
        ret = GetSaveFileName( (LPOPENFILENAME)&wreofn );
    } else {
        return( NULL );
    }

#ifndef __NT__
    if( wreofn.lpfnHook != NULL ) {
        FreeProcInstance( (FARPROC)wreofn.lpfnHook );
    }
#endif

    if( !ret ) {
        error = CommDlgExtendedError();
        if( error ) {
            WREDisplayErrorMsg( WRE_ERRORSELECTINGFILE );
        }
        return( NULL );
    } else {
        memcpy( wre_initial_dir, wre_file_name, wreofn.nFileOffset );
        if( wre_initial_dir[wreofn.nFileOffset - 1] == '\\' &&
            wre_initial_dir[wreofn.nFileOffset - 2] != ':' ) {
            wre_initial_dir[wreofn.nFileOffset - 1] = '\0';
        } else {
            wre_initial_dir[wreofn.nFileOffset] = '\0';
        }
        if( gf->save_ext ) {
            _splitpath( wre_file_name, NULL, NULL, NULL, fn_ext + 1 );
            if( fn_ext[1] != '\0' ) {
                fn_ext[0] = '*';
                WRESetFileFilter( fn_ext );
            } else {
                char *out_ext;
                out_ext = WREFindFileFilterFromIndex( gf->filter, wreofn.nFilterIndex );
                if( out_ext[2] != '*' ) {
                    strcat( wre_file_name, &out_ext[1] );
                }
            }
        }
    }

    UpdateWindow( WREGetMainWindowHandle() );

    return( WREStrDup( wre_file_name ) );
}
예제 #10
0
void WRESetFileFilter( char *filter )
{
    WREFreeFileFilter();
    LastFileFilter = WREStrDup( filter );
}
예제 #11
0
Bool WRESaveResource( WREResInfo *res_info, Bool get_name )
{
    char                *fn;
    WREGetFileStruct    gf;
    int                 fn_offset;
    Bool                got_name;
    Bool                ok;

    fn_offset = 0;
    got_name = FALSE;

    ok = (res_info != NULL && res_info->info != NULL);

    if( ok ) {
        ok = (WRCountZeroLengthResources( res_info->info->dir ) == 0);
        if( !ok ) {
            WREDisplayErrorMsg( WRE_UPDATEBEFORESAVE );
        }
    }

    if( ok ) {
        if( res_info->info->save_name != NULL ) {
            fn = res_info->info->save_name;
        } else {
            res_info->info->save_type = res_info->info->file_type;
            fn = WREStrDup( res_info->info->file_name );
            got_name = TRUE;
        }

        if( get_name || fn == NULL || *fn == '\0' ) {
            gf.file_name = fn;
            gf.title = WREResSaveTitle;
            gf.filter = WREResFilter;
            gf.save_ext = TRUE;
            fn = WREGetSaveFileName( &gf );
            got_name = TRUE;
            res_info->info->save_type = WR_DONT_KNOW;
        }

        ok = (fn != NULL && *fn != '\0');
    }

    if( ok ) {
        if( got_name && res_info->info->save_name != NULL ) {
            WREMemFree( res_info->info->save_name );
        }
        res_info->info->save_name = fn;
        if( res_info->info->save_type == WR_DONT_KNOW ) {
            res_info->info->save_type = WRESelectFileType( fn, res_info->is32bit );
        }
        ok = (res_info->info->save_type != WR_DONT_KNOW);
    }

    if( ok ) {
        if( WRIsHashTableDirty( res_info->symbol_table ) ) {
            if( res_info->symbol_file == NULL ) {
                res_info->symbol_file = WRECreateSymName( fn );
            }
        }
    }

    if( ok ) {
        WRECreateDLGInclude( &res_info->info->dir, res_info->symbol_file );
        ok = WRESaveResourceToFile( res_info );
        if( !ok ) {
            WREDisplayErrorMsg( WRE_SAVEFAILED );
        }
    }

    if( ok ) {
        if( get_name || WRIsHashTableDirty( res_info->symbol_table ) ) {
            ok = WRESaveSymbols( res_info->symbol_table, &res_info->symbol_file, get_name );
        }
    }

    if( ok ) {
        //fn_offset = WRFindFnOffset( fn );
        SendMessage( res_info->res_win, WM_SETTEXT, 0, (LPARAM)(LPSTR)&fn[fn_offset] );
    }

    return( ok );
}