📄 wstr.c
字号:
if( n->block_name ) {
WMemFree( n->block_name );
}
if( n->data ) {
WMemFree( n->data );
}
WMemFree( n );
}
}
WStringNode *WMakeStringNodeFromStringBlock( WStringBlock *block )
{
WStringNode *node;
if( block == NULL ) {
return( NULL );
}
node = (WStringNode *)WMemAlloc( sizeof(WStringNode) );
if( node == NULL ) {
return( NULL );
}
memset( node, 0, sizeof(WStringNode) );
node->block_name = WResIDFromNum( block->blocknum / 16 + 1 );
node->MemFlags = block->MemFlags;
WMakeDataFromStringBlock( block, &node->data, &node->data_size );
if( node->data == NULL ) {
WFreeStringNode( node );
return( NULL );
}
return( node );
}
WStringNode *WMakeStringNodes( WStringTable *tbl )
{
WStringNode *node;
WStringNode *new;
WStringBlock *block;
node = NULL;
block = tbl->first_block;
while( block ) {
new = WMakeStringNodeFromStringBlock( block );
if( new == NULL ) {
WFreeStringNode( node );
return( NULL );
}
if( node ) {
new->next = node;
node = new;
} else {
node = new;
}
block = block->next;
}
return( node );
}
WStringTable *WAllocStringTable( int is32bit )
{
WStringTable *tbl;
tbl = (WStringTable *) WMemAlloc( sizeof(WStringTable) );
if( !tbl ) {
return ( NULL );
}
tbl->is32bit = is32bit;
tbl->first_block = NULL;
return( tbl );
}
int WInitStringTable ( WStringInfo *info, WStringTable *tbl )
{
WStringBlock *block;
WStringNode *node;
uint_16 blocknum;
if( !info || !tbl ) {
return( FALSE );
}
node = info->tables;
while( node ) {
blocknum = (uint_16) WResIDToNum( node->block_name );
blocknum = ( blocknum - 1 ) * 16;
if( WFindStringBlock( tbl, blocknum ) ) {
return( FALSE );
}
block = WGetOrMakeStringBlock( tbl, blocknum );
if( block == NULL ) {
return( FALSE );
}
if( !WMakeStringBlockFromData(node->data, node->data_size, block) ) {
return( FALSE );
}
node = node->next;
}
return( TRUE );
}
WStringTable *WMakeStringTableFromInfo( WStringInfo *info )
{
WStringTable *tbl;
int ok;
tbl = NULL;
ok = ( info != NULL );
if( ok ) {
tbl = WAllocStringTable ( info->is32bit );
ok = ( tbl != NULL );
}
if ( ok ) {
ok = WInitStringTable ( info, tbl );
}
if ( ok ) {
//WFreeStringNodes( info );
} else {
if ( tbl ) {
WFreeStringTable ( tbl );
tbl = NULL;
}
}
return ( tbl );
}
Bool WGetFirstStringInBlock ( WStringBlock *block, uint_16 *first )
{
int i;
if ( block && first ) {
for( i=0; i<STRTABLE_STRS_PER_BLOCK; i++ ) {
if( block->block.String[i] != NULL ) {
*first = ( ( block->blocknum & 0xfff0 ) + i );
return ( TRUE );
}
}
}
return ( FALSE );
}
static WStringBlock *WFindLargestBlock( WStringTable *tbl )
{
WStringBlock *block;
WStringBlock *largest;
largest = NULL;
if( tbl ) {
block = tbl->first_block;
while( block ) {
if( ( largest == NULL ) ||
( block->blocknum > largest->blocknum ) ) {
largest = block;
}
block = block->next;
}
}
return( largest );
}
uint_16 WFindLargestStringID( WStringTable *tbl )
{
WStringBlock *largest;
int i;
largest = WFindLargestBlock( tbl );
if( largest ) {
for( i=STRTABLE_STRS_PER_BLOCK-1; i>=0; i-- ) {
if( largest->block.String[i] != NULL ) {
return( ( largest->blocknum & 0xfff0 ) + i );
}
}
return( largest->blocknum & 0xfff0 );
}
return( 0 );
}
Bool WResolveStringTable( WStringEditInfo *einfo )
{
WStringBlock *block;
if( !einfo || !einfo->tbl ) {
return( FALSE );
}
block = einfo->tbl->first_block;
while( block ) {
WResolveStringTableBlock( block, einfo->info->symbol_table );
block = block->next;
}
return( TRUE );
}
Bool WResolveStringTableBlock( WStringBlock *block, WRHashTable *symbol_table )
{
WRHashValueList *vlist;
int i;
if( !block || !symbol_table ) {
return( FALSE );
}
for( i=0; i<STRTABLE_STRS_PER_BLOCK; i++ ) {
if( block->block.String[i] == NULL ) {
continue;
}
vlist = WRLookupValue( symbol_table, (block->blocknum & 0xfff0) + i );
if( vlist == NULL ) {
continue;
}
if( vlist->next == NULL ) {
if( block->symbol[i] != NULL ) {
WMemFree( block->symbol[i] );
}
block->symbol[i] = WStrDup( vlist->entry->name );
}
WRValueListFree( vlist );
}
return( TRUE );
}
static Bool WResolveStringTableBlockSymIDs( WStringEditInfo *einfo,
WStringBlock *block,
WRHashTable *symbol_table )
{
WRHashValue hv;
int i;
Bool replace;
char *text;
if( !symbol_table ) {
return( FALSE );
}
for( i=0; i<STRTABLE_STRS_PER_BLOCK; i++ ) {
if( block->block.String[i] == NULL ) {
continue;
}
text = WResIDNameToStr( block->block.String[ i ] );
if( text == NULL ) {
continue;
}
if( WRLookupName( symbol_table, block->symbol[i], &hv ) ) {
WInsertStringData( einfo, (uint_16)hv, text, block->symbol[i],
&replace );
} else {
WInsertStringData( einfo, (uint_16)((block->blocknum & 0xfff0)+i),
text, block->symbol[i], &replace );
}
WMemFree( text );
}
return( TRUE );
}
Bool WResolveStringTableSymIDs( WStringEditInfo *einfo )
{
WStringTable *new_tbl;
WStringTable *old_tbl;
WStringBlock *block;
LRESULT pos;
HWND lbox;
if( !einfo || !einfo->tbl ) {
return( FALSE );
}
new_tbl = WAllocStringTable( einfo->tbl->is32bit );
if( new_tbl == NULL ) {
return( FALSE );
}
old_tbl = einfo->tbl;
einfo->tbl = new_tbl;
block = old_tbl->first_block;
while( block ) {
WResolveStringTableBlockSymIDs( einfo, block, einfo->info->symbol_table );
block = block->next;
}
if( new_tbl->first_block == NULL ) {
WFreeStringTable( new_tbl );
einfo->tbl = old_tbl;
return( FALSE );
}
WFreeStringTable( old_tbl );
lbox = GetDlgItem( einfo->edit_dlg, IDM_STREDLIST );
pos = SendMessage( lbox, LB_GETCURSEL, 0, 0 );
if( pos == LB_ERR ) {
pos = 0;
}
SendMessage( lbox, LB_RESETCONTENT, 0, 0 );
SendMessage( lbox, WM_SETREDRAW, FALSE, 0 );
block = einfo->tbl->first_block;
while( block ) {
WAddEditWinLBoxBlock( einfo, block, -1 );
block = block->next;
}
SendMessage( lbox, WM_SETREDRAW, TRUE, 0 );
einfo->current_block = NULL;
einfo->current_string = 0;
einfo->current_pos = -1;
SendMessage( lbox, LB_SETCURSEL, (WPARAM) pos, 0 );
return( TRUE );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -