📄 wrestr.c
字号:
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
* DESCRIBE IT HERE!
*
****************************************************************************/
#include <windows.h>
#include <string.h>
#include <stdlib.h>
#include "wrdll.h"
#include "wstring.h"
#include "wreglbl.h"
#include "wremem.h"
#include "wregcres.h"
#include "wrerenam.h"
#include "wrenames.h"
#include "wrestrdp.h"
#include "wrelist.h"
#include "wrenew.h"
#include "wredel.h"
#include "wrestat.h"
#include "wremsg.h"
#include "wremsgs.gh"
#include "wreres.h"
#include "wreftype.h"
#include "wretoolb.h"
#include "wremain.h"
#include "wre_wres.h"
#include "wre_rc.h"
#include "wrestr.h"
/****************************************************************************/
/* macro definitions */
/****************************************************************************/
#define MAX_RETRIES 99
/****************************************************************************/
/* external function prototypes */
/****************************************************************************/
/****************************************************************************/
/* type definitions */
/****************************************************************************/
typedef struct WREStringSession {
WStringHandle hndl;
WStringInfo *info;
WResTypeNode *tnode;
WREResInfo *rinfo;
} WREStringSession;
/****************************************************************************/
/* static function prototypes */
/****************************************************************************/
static WREStringSession *WREFindStringSession ( WStringHandle );
static WREStringSession *WREAllocStringSession ( void );
static WREStringSession *WREStartStringSession ( WRECurrentResInfo *, WStringNode *node );
static Bool WREAddStringToDir ( WRECurrentResInfo * );
static WStringNode *WREMakeNode ( WRECurrentResInfo * );
static WStringNode *WRECreateStringNodes ( WRECurrentResInfo * );
static void WREFreeStringNode ( WStringNode *node );
static Bool WREGetStringSessionData ( WREStringSession *, Bool );
static void WRERemoveStringEditSession( WREStringSession * );
static WREStringSession *WREFindResStringSession ( WREResInfo *rinfo );
static WResTypeNode *WREUseStringNodes ( WResDir dir, WStringNode *node );
/****************************************************************************/
/* static variables */
/****************************************************************************/
static LIST *WREStringSessions = NULL;
extern Bool WRENoInterface;
void WRERemoveStringEditSession( WREStringSession *session )
{
if( session ) {
ListRemoveElt( &WREStringSessions, session );
if( session->info ) {
WStrFreeStringInfo( session->info );
}
WREMemFree( session );
}
}
Bool WREAddStringToDir ( WRECurrentResInfo *curr )
{
WResLangType lang;
int dup, num_retries;
WResID *rname, *tname;
Bool ok, tname_alloc;
ok = TRUE;
tname_alloc = FALSE;
WREGetCurrentResource ( curr );
if( !curr->info ) {
curr->info = WRECreateNewResource( NULL );
ok = ( curr->info != NULL );
}
// check for an existing string tables
if( ok ) {
if( WREFindTypeNode( curr->info->info->dir, (uint_16)RT_STRING, NULL ) ) {
WREDisplayErrorMsg( WRE_STRINGTABLEEXISTS );
return( FALSE );
}
}
if( ok ) {
if( curr->info->current_type == (uint_16)RT_STRING ) {
tname = &curr->type->Info.TypeName;
} else {
tname = WResIDFromNum ( (uint_16)RT_STRING );
tname_alloc = TRUE;
}
lang.lang = DEF_LANG;
lang.sublang = DEF_SUBLANG;
}
if ( ok ) {
dup = TRUE;
num_retries = 0;
rname = NULL;
while ( ok && dup && ( num_retries <= MAX_RETRIES ) ) {
rname = WResIDFromNum( 0 );
ok = ( rname != NULL );
if ( ok ) {
ok = WRENewResource( curr, tname, rname, DEF_MEMFLAGS, 0, 0,
&lang, &dup, (uint_16)RT_STRING,
tname_alloc );
if( !ok && dup ) {
ok = TRUE;
}
num_retries++;
}
if( rname ) {
WREMemFree( rname );
}
}
if( dup ) {
WREDisplayErrorMsg( WRE_CANTFINDUNUSEDNAME );
}
}
if( ok ) {
curr->info->modified = TRUE;
}
if( tname_alloc ) {
WREMemFree( tname );
}
return ( ok );
}
Bool WRENewStringResource ( void )
{
WRECurrentResInfo curr;
Bool ok;
ok = WREAddStringToDir ( &curr );
if ( ok ) {
ok = ( WREStartStringSession ( &curr, NULL ) != NULL );
}
return ( ok );
}
Bool WREEditStringResource ( WRECurrentResInfo *curr )
{
WStringNode *nodes;
Bool ok;
WREStringSession *session;
nodes = NULL;
ok = ( curr && curr->info && curr->type );
if( ok ) {
session = WREFindResStringSession( curr->info );
if( session ) {
WStringBringToFront( session->hndl );
return( TRUE );
}
}
if ( ok ) {
nodes = WRECreateStringNodes( curr );
ok = ( nodes != NULL );
}
if ( ok ) {
ok = ( WREStartStringSession ( curr, nodes ) != NULL );
}
return ( ok );
}
Bool WREEndEditStringResource ( WStringHandle hndl )
{
WREStringSession *session;
WRECurrentResInfo curr;
Bool ret;
ret = FALSE;
session = WREFindStringSession ( hndl );
if( session ) {
ret = TRUE;
if( !session->tnode || !session->tnode->Head->Head->Info.Length ) {
curr.info = session->rinfo;
curr.type = session->tnode;
curr.res = NULL;
curr.lang = NULL;
ret = WREDeleteStringResources( &curr, TRUE );
WRESetStatusByID( -1, WRE_EMPTYREMOVED );
}
WRERemoveStringEditSession( session );
}
return( ret );
}
Bool WRESaveEditStringResource( WStringHandle hndl )
{
WREStringSession *session;
session = WREFindStringSession( hndl );
if( !session ) {
return( FALSE );
}
return( WREGetStringSessionData( session, FALSE ) );
}
WREStringSession *WREStartStringSession ( WRECurrentResInfo *curr,
WStringNode *nodes )
{
WREStringSession *session;
if ( !curr ) {
return ( NULL );
}
session = WREAllocStringSession ();
if ( !session ) {
return ( NULL );
}
session->info = WStrAllocStringInfo ();
if ( !session->info ) {
return ( NULL );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -