⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wstr.c

📁 开放源码的编译器open watcom 1.6.0版的源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/****************************************************************************
*
*                            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 "wglbl.h"
#include "wmem.h"
#include "wstring.h"
#include "winfo.h"
#include "wribbon.h"
#include "wstrdup.h"
#include "wstr.h"
#include "wcopystr.h"
#include "widn2str.h"
#include "wnewitem.h"
#include "sys_rc.h"

/****************************************************************************/
/* external function prototypes                                             */
/****************************************************************************/

/****************************************************************************/
/* macro definitions                                                        */
/****************************************************************************/

/****************************************************************************/
/* type definitions                                                         */
/****************************************************************************/

/****************************************************************************/
/* static function prototypes                                               */
/****************************************************************************/
static  void            WMakeDataFromStringBlock( WStringBlock *block, void **data, int *size );
static  int             WInitDataFromStringBlock( WStringBlock *block, void *data, int size );
static  int             WInitStringTable        ( WStringInfo *info, WStringTable *tbl );
static  int             WMakeStringBlockFromData( void *data, int size, WStringBlock *block );
static  int             WCalcStringBlockSize    ( WStringBlock *block );
static  WStringBlock    *WFindStringTableBlock  ( WStringTable *tbl, uint_16 blocknum );
static  WStringBlock    *WAllocStringBlock      ( void );
static  WStringTable    *WAllocStringTable      ( int is32bit );
static  void            WFreeStringTable        ( WStringTable *tbl );
static  void            WFreeStringTableBlock   ( WStringBlock *block );
static  WStringNode     *WMakeStringNodeFromStringBlock( WStringBlock * );

/****************************************************************************/
/* static variables                                                         */
/****************************************************************************/

WStringEditInfo *WAllocStringEInfo ( void )
{
    WStringEditInfo *einfo;

    einfo = (WStringEditInfo *) WMemAlloc ( sizeof(WStringEditInfo) );

    if ( einfo ) {
        memset ( einfo, 0, sizeof(WStringEditInfo) );
        einfo->current_pos = -1;
    }

    return ( einfo );
}

void WFreeStringEInfo ( WStringEditInfo *einfo )
{
    if ( einfo ) {
        if ( einfo->tbl ) {
            WFreeStringTable ( einfo->tbl );
            einfo->tbl = NULL;
        }
        if ( einfo->wsb ) {
            WDestroyStatusLine ( einfo->wsb );
            einfo->wsb = NULL;
        }
        if ( einfo->ribbon ) {
            WDestroyRibbon ( einfo );
        }
        if ( ( einfo->edit_dlg != (HWND)NULL ) &&
             IsWindow ( einfo->edit_dlg ) ) {
            DestroyWindow ( einfo->edit_dlg );
            einfo->edit_dlg = (HWND)NULL;
        }
        if ( ( einfo->win != (HWND)NULL ) && IsWindow ( einfo->win ) ) {
            SetWindowLong( einfo->win, 0, (LONG)0 );
            DestroyWindow ( einfo->win );
            einfo->win = (HWND)NULL;
        }
        if ( einfo->file_name ) {
            WMemFree ( einfo->file_name );
        }
        WMemFree ( einfo );
    }
}

Bool WIsBlockEmpty( WStringBlock *block )
{
    return( WRIsBlockEmpty( &block->block ) );
}

WStringBlock *WFindStringBlock( WStringTable *tbl, uint_16 blocknum )
{
    WStringBlock *block;

    if( tbl ) {
        block = tbl->first_block;
        while( block ) {
            if( ( block->blocknum & 0xfff0 ) == ( blocknum & 0xfff0 ) ) {
                return( block );
            }
            block = block->next;
        }
    }

    return( NULL );
}

int WFindStringPos( WStringTable *tbl, uint_16 string_id )
{
    WStringBlock        *block;
    int                 pos;
    int                 i;

    pos = 0;

    if( tbl ) {
        block = tbl->first_block;
        while( block ) {
            for( i=0; i<STRTABLE_STRS_PER_BLOCK; i++ ) {
                if( block->block.String[i] != NULL ) {
                    if( ( ( block->blocknum & 0xfff0 ) + i ) == string_id ) {
                        return( pos );
                    }
                    pos++;
                }
            }
            block = block->next;
        }
    }

    return( -1 );
}

WStringBlock *WFindStringTableBlock( WStringTable *tbl, uint_16 blocknum )
{
    WStringBlock *block;
    WStringBlock *last;

    last = NULL;
    if( tbl ) {
        block = tbl->first_block;
        while( block ) {
            if( block->blocknum > blocknum ) {
                break;
            } else if( block->blocknum == blocknum ) {
                return( block );
            }
            last = block;
            block = block->next;
        }
    }

    return( last );
}

void WMakeDataFromStringBlock ( WStringBlock *block, void **data, int *size )
{
    if( block ) {
        WRMakeDataFromStringBlock(&block->block, data, size, block->is32bit);
    }
}

int WMakeStringBlockFromData( void *data, int size, WStringBlock *block )
{
    int ret;

    if( !data || !size || !block ) {
        return( FALSE );
    }

    ret = WRMakeStringBlockFromData( &block->block, data, size,
                                     block->is32bit );

    return( ret );
}

WStringBlock *WGetOrMakeStringBlock( WStringTable *tbl, uint_16 blocknum )
{
    WStringBlock        *block;
    WStringBlock        *after;

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

    after = WFindStringTableBlock( tbl, blocknum );

    if( after ) {
        if( ( after->blocknum & 0xfff0 ) == ( blocknum & 0xfff0 ) ) {
            return( after );
        }
    }

    block = WAllocStringBlock();
    if( block == NULL ) {
        return( NULL );
    }
    block->is32bit  = tbl->is32bit;
    block->blocknum = blocknum & 0xfff0;

    if( after ) {
        if( after->next ) {
            after->next->prev = block;
        }
        block->next = after->next;
        block->prev = after;
        after->next = block;
    } else {
        block->next = tbl->first_block;
        block->prev = NULL;
        tbl->first_block = block;
    }

    return( block );
}

Bool WRemoveStringBlock( WStringTable *tbl, WStringBlock *block )
{
    Bool ok;

    ok = ( tbl && block );

    if( ok ) {
        if( block->next ) {
            block->next->prev = block->prev;
        }
        if( block->prev ) {
            block->prev->next = block->next;
        }
        if( tbl->first_block == block ) {
            tbl->first_block = block->next;
        }
        WFreeStringTableBlock( block );
    }

    return ( ok );
}

WStringBlock *WAllocStringBlock( void )
{
    WStringBlock *block;

    block = (WStringBlock *) WMemAlloc(sizeof(WStringBlock));
    if( block ) {
        memset( block, 0, sizeof(WStringBlock) );
    }

    return( block );
}

void WFreeStringTable ( WStringTable *tbl )
{
    if( tbl ) {
        WFreeStringTableBlocks( tbl->first_block );
        WMemFree( tbl );
    }
}

void WFreeStringTableBlocks( WStringBlock *block )
{
    WStringBlock *b;

    while( block ) {
        b = block;
        block = block->next;
        WFreeStringTableBlock( b );
    }
}

void WFreeStringTableBlock( WStringBlock *block )
{
    int i;

    if( block ) {
        for( i=0; i<STRTABLE_STRS_PER_BLOCK; i++ ) {
            if( block->symbol[i] != NULL ) {
                WMemFree( block->symbol[i] );
            }
        }
        ResFreeStringTableBlock( &block->block );
        WMemFree( block );
    }
}

void WFreeStringNodes( WStringInfo *info )
{
    WFreeStringNode( info->tables );
    info->tables = NULL;
}

void WFreeStringNode( WStringNode *node )
{
    WStringNode *n;

    while( node ) {
        n = node;
        node = node->next;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -