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

📄 hwlocal.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 <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "heapwalk.h"

typedef struct {
    LOCALENTRY          top;
    LOCALENTRY          sel;
    BOOL                valid_sel;
} LocalStateStruct;

static HGLOBAL          LocalHeapHandle;
static char             Owner[MAX_MODULE_NAME +1];
static HWND             LocalHeapHwnd;

LOCALENTRY      **LocalHeapList;
unsigned        LocalHeapCount;

extern msglist Sort_types[];
extern msglist LocalNormMsg[];
extern msglist LocalUSERMsg[];
extern msglist LocalGDIMsg[];
extern msglist FlagMsg[];


/*
 * PutOutLocalHeader
 */
static void PutOutLocalHeader( FILE *fptr ) {

    time_t      tm;
    LclInfo     info;
    char        *sorttype;

    tm = time( NULL );
    LclHeapInfo( &info );

    RCfprintf( fptr, STR_SNAP_LCL_CREATED, asctime( localtime( &tm ) ) );
    RCfprintf( fptr, STR_LCL_HEAP_OF, Owner );
    sorttype = SrchMsg( LSortType, Sort_types, "" );
    RCfprintf( fptr, STR_LCL_SORTED_BY, sorttype );
    RCfprintf( fptr, STR_LCL_SUMMARY_HEADING );
    RCfprintf( fptr, STR_LCL_FREE_OBJECTS, info.free_count, info.free_size );
    RCfprintf( fptr, STR_LCL_MOVEABLE_OBJECTS,
               info.movable_count, info.movable_size );
    RCfprintf( fptr, STR_LCL_FIXED_OBJECTS, info.fixed_count, info.fixed_size );
    RCfprintf( fptr, STR_LCL_TOTAL_LINE );
    RCfprintf( fptr, STR_LCL_TOTAL_OBJECTS, info.tot_count, info.tot_size );
    fprintf( fptr, "\n%s\n\n", HeapLocalTitles );
} /* PutOutLocalHeader */

/*
 * SortByLocalType
 * NB this routine assumes that p1 and p2 have the same wHeapType
 */

int SortByLocalType(  LOCALENTRY **p1, LOCALENTRY **p2 )
{

    char        *type1;
    char        *type2;

    switch( (*p1)->wHeapType ) {
    case NORMAL_HEAP:
        type1 = SrchMsg( (*p1)->wType, LocalNormMsg, "" );
        type2 = SrchMsg( (*p2)->wType, LocalNormMsg, "" );
        break;
    case USER_HEAP:
        type1 = SrchMsg( (*p1)->wType, LocalUSERMsg, "" );
        type2 = SrchMsg( (*p2)->wType, LocalUSERMsg, "" );
        break;
    case GDI_HEAP:
        type1 = SrchMsg( (*p1)->wType, LocalGDIMsg, "" );
        type2 = SrchMsg( (*p2)->wType, LocalGDIMsg, "" );
        break;
    }
    return( strcmp( type1, type2 ) );
}


/*
 * FreeLocalList - frees the local heap list
 */

static void FreeLocalList( void ) {

    unsigned    i;

    if( LocalHeapList == NULL ) return;
    for( i=0; i < LocalHeapCount; i++ ) {
        MemFree( LocalHeapList[i] );
    }
    MemFree( LocalHeapList );
    LocalHeapList = NULL;
}

/*
 * LclHeapInfo - return statistics about the local heap
 */

void LclHeapInfo( LclInfo *info ) {

    unsigned    index;

    memset( info, 0, sizeof( LclInfo ) );
    for( index=0; index < LocalHeapCount; index++ ) {
        switch( LocalHeapList[index]->wFlags ) {
        case LF_FREE:
            info->free_count ++;
            info->free_size += LocalHeapList[index]->wSize;
            break;
        case LF_MOVEABLE:
            info->movable_count ++;
            info->movable_size += LocalHeapList[index]->wSize;
            break;
        case LF_FIXED:
            info->fixed_count ++;
            info->fixed_size += LocalHeapList[index]->wSize;
            break;
        }
    }
    info->tot_count = info->free_count + info->movable_count + info->fixed_count;
    info->tot_size = info->free_size + info->movable_size + info->fixed_size;
}

/*
 * FormatLocalHeapListItem - format a single line of the local heap list
 */

BOOL FormatLocalHeapListItem( char *line, unsigned index ) {

    LOCALENTRY  *item;
    char        *flags;
    char        *type;

    if( index == LocalHeapCount ) return( FALSE );
    item = LocalHeapList[index];
    flags = SrchMsg( item->wFlags, FlagMsg, "" );
    switch( item->wHeapType ) {
    case NORMAL_HEAP:
        type = SrchMsg( item->wType, LocalNormMsg, "" );
        break;
    case USER_HEAP:
        type = SrchMsg( item->wType, LocalUSERMsg, "" );
        break;
    case GDI_HEAP:
        type = SrchMsg( item->wType, LocalGDIMsg, "" );
        break;
    }
    sprintf( line, "%04X    %04X  %6d %-9s %4d  %-20s",
             item->wAddress,
             (UINT)item->hHandle,
             item->wSize,
             flags,
             item->wcLock,
             type
          );
    return( TRUE );
}

/*
 * EnableLocalMenu - grey or enable the local menu in the main window
 */

static void EnableLocalMenu( BOOL enable )
{
    WORD                action;
    HMENU               mh;

    if( enable ) {
        action = MF_ENABLED;
    } else {
        action = MF_GRAYED;
    }
    mh = GetMenu( HeapWalkMainWindow );
    if( HeapType != HEAPMENU_DISPLAY_DPMI ) {
        EnableMenuItem( mh, HEAPMENU_LOCAL_LOCALWALK,  action);
        EnableMenuItem( mh, HEAPMENU_COMPACT_AND_LOCALWALK, action);
    }
    EnableMenuItem( mh, HEAPMENU_GDI_LOCALWALK,  action);
    EnableMenuItem( mh, HEAPMENU_USER_LOCALWALK, action);
} /* EnableLocalMenu */

/*
 * AddToLocalHeapList - add an entry the the local heap list
 */

static BOOL AddToLocalHeapList( LOCALENTRY *item, unsigned i ) {

    LocalHeapList[i] = MemAlloc( sizeof( LOCALENTRY ) );
    if( LocalHeapList[i] == NULL ) return( FALSE );
    *LocalHeapList[i] = *item;
    return( TRUE );
} /* AddToLocalHeapList */

/*
 * SaveLocalListState - save the top item and selected item in the
 *              list box so we can restore them later
 */
BOOL SaveLocalListState( HWND boxhwnd, LocalStateStruct *info ) {

    LRESULT     top, sel;

    top = SendMessage( boxhwnd, LB_GETTOPINDEX, 0, 0L );
    sel = SendMessage( boxhwnd, LB_GETCURSEL, 0, 0L );
    if( sel != LB_ERR && sel < LocalHeapCount ) {
        info->sel = *LocalHeapList[sel];

⌨️ 快捷键说明

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