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

📄 hwlist.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 <string.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <dos.h>
#include "heapwalk.h"

typedef struct glb_state{
    heap_list           sel;
    heap_list           top;
    BOOL                sel_valid;
}GlobStateStruct;

static char             *gbl_types[ 11 ];
static char             *res_types[ 15 ];
static char             Buffer[100];

void InitListStrTables( void ) {
    gbl_types[ 0 ] = GetRCString( STR_MC_UNKNOWN );
    gbl_types[ 1 ] = GetRCString( STR_DGROUP );
    gbl_types[ 2 ] = GetRCString( STR_DATA );
    gbl_types[ 3 ] = GetRCString( STR_CODE );
    gbl_types[ 4 ] = GetRCString( STR_TASK );
    gbl_types[ 5 ] = GetRCString( STR_RESOURCE );
    gbl_types[ 6 ] = GetRCString( STR_MC_MODULE );
    gbl_types[ 7 ] = GetRCString( STR_MC_FREE );
    gbl_types[ 8 ] = GetRCString( STR_INTERNAL );
    gbl_types[ 9 ] = GetRCString( STR_SENTINEL );
    gbl_types[ 10 ] = GetRCString( STR_BURGERMASTER );
    res_types[ 0 ] = GetRCString( STR_USERDEFINED );
    res_types[ 1 ] = GetRCString( STR_CURSOR_COMP );
    res_types[ 2 ] = GetRCString( STR_MC_BITMAP );
    res_types[ 3 ] = GetRCString( STR_ICON_COMP );
    res_types[ 4 ] = GetRCString( STR_MC_MENU );
    res_types[ 5 ] = GetRCString( STR_DIALOG );
    res_types[ 6 ] = GetRCString( STR_STRING );
    res_types[ 7 ] = GetRCString( STR_FONTDIR );
    res_types[ 8 ] = GetRCString( STR_MC_FONT );
    res_types[ 9 ] = GetRCString( STR_ACCELERATORS );
    res_types[ 10 ] = GetRCString( STR_RCDATA );
    res_types[ 11 ] = GetRCString( STR_ERRTABLE );
    res_types[ 12 ] = GetRCString( STR_MC_CURSOR );
    res_types[ 13 ] = GetRCString( STR_MC_ICON );
    res_types[ 14 ] = GetRCString( STR_NAMETABLE );
}

/*
 * CALL BACK functions that returned formated text lines for the list box
 */

char *GetGlobalTextItem( unsigned i ) {

    FormatHeapListItem( Buffer, i );
    return( Buffer );
}

char *GetLocalTextItem( unsigned i ) {

    FormatLocalHeapListItem( Buffer, i );
    return( Buffer );
}

/*
 * SortByGlobType
 */

int SortByGlobType( heap_list **p1, heap_list **p2 )
{
    WORD        t1;
    WORD        t2;
    WORD        tmp;
    int         ret;

    if( !ListingDPMI ) {
        t1 = (*p1)->info.ge.wType;
        t2 = (*p2)->info.ge.wType;
        ret = strcmp( gbl_types[t1], gbl_types[t2] );
        if( ret == 0 ) {
            tmp = t1;
            t1 = (*p1)->info.ge.wData;
            t2 = (*p2)->info.ge.wData;
            if( tmp == GT_CODE ) {
                /* compare the module names */
                ret = strcmp( (*p1)->szModule, (*p2)->szModule );
                if( ret == 0 ) {
                    ret = t1 - t2;
                }
            } else if( tmp == GT_RESOURCE ) {
                if( t1 >= (sizeof( res_types ) /sizeof( char *) ) ) {
                    ret = strcmp( GetRCString( STR_LOWER_UNKNOWN ),
                                  res_types[t2] );
                } else if( t2 >= (sizeof( res_types ) /sizeof( char *) ) ) {
                    ret = strcmp(  res_types[t1],
                                   GetRCString( STR_LOWER_UNKNOWN ) );
                } else ret = strcmp( res_types[t1], res_types[t2] );
            }
        }
        return( ret );
    } else {
        t1 = (*p1)->info.mem.desc.type;
        t2 = (*p2)->info.mem.desc.type;
        if( t1 == t2 ) return( 0 );
        if( t1 == 2 ) return( 1 );
        return( -1 );
    }
} /* SortByType */

/*
 * GetDGroupItem - fills hl with information about the DGROUP owned by
 *                 owner
 */

BOOL GetDGroupItem( char *owner, heap_list *hl ) {

    MODULEENTRY me;

    MyGlobalFirst( &( hl->info.ge ), GLOBAL_ALL );
    do {
        if( hl->info.ge.wType == GT_DGROUP ) {
            if( hl->info.ge.hOwner != NULL ) {
                if( MyModuleFindHandle( &me, hl->info.ge.hOwner ) ) {
                    if( !strcmp( me.szModule, owner ) ){
                        strcpy( hl->szModule , owner );
                        hl->szModule[MAX_MODULE_NAME]=0;
                        return( TRUE );
                    }
                }
            }
        }
    } while( MyGlobalNext( &hl->info.ge, GLOBAL_ALL ) );
    return( FALSE );
}

/*
 * AddToBuff - add a string to the current formatted selector
 */
static char *_buff;
void AddToBuff( char *str, ... )
{
    va_list     al;
    char        tmp[256];

    va_start( al, str );
    vsprintf( tmp, str, al );
    va_end( al );
    strcat( _buff, tmp );

} /* AddToBuff */

/*
 * FormatSel - format selector info
 */
static void FormatSel( char *which, WORD sel, char *buff )
{
    descriptor  desc;
    DWORD       base;
    DWORD       limit;

    buff[ 0 ] = 0;
    _buff = buff;
    GetADescriptor( sel, &desc );
    if( which != NULL ) {
        AddToBuff( "      %s = %04x  ", which, sel );
        if( sel == 0L ) {
            AddToBuff( "********  ********  ****  ****  *   ***    *\n" );
            return;
        }
    } else {
        AddToBuff( " %04x  ", sel );
    }

    base = GET_DESC_BASE( desc );
    limit = GET_DESC_LIMIT( desc );
    AddToBuff( "%08lx  %08lx  ", base, limit );
    if( desc.granularity ) {
        AddToBuff( "page  " );
    } else {
        AddToBuff( "byte  " );
    }
    if( desc.type == 2 ) {
        AddToBuff( "data  " );
    } else {
        AddToBuff( "code  " );
    }
    AddToBuff( "%1d   ", (WORD) desc.dpl );
    if( desc.type == 2 )  {
        AddToBuff( "R" );
        if( desc.writeable_or_readable ) AddToBuff( "/W" );
        else AddToBuff( "  " );
        AddToBuff( "    " );
    } else {
        AddToBuff( "Ex" );
        if( desc.writeable_or_readable ) AddToBuff( "/R" );
        else AddToBuff( "  " );
        AddToBuff( "   " );
    }
    if( desc.big_or_default ) {
        AddToBuff( "Y" );
    } else {
        AddToBuff( " " );
    }

} /* FormatSel */

/*
 * FormatHeapListItem - format a single line of the heaplist
 */

BOOL FormatHeapListItem( char *line, unsigned index )
{
    char        type[30];
    char        handle[5];
    char        lock[15];
    heap_list   *hl;

    if( index >= HeapListSize ) return( FALSE );
    hl = HeapList[index];
    if( hl->is_dpmi ) {
        FormatSel( NULL, hl->info.mem.sel, line );
    } else {
        if( hl->info.ge.hBlock != 0 ) {
            sprintf( handle,"%04x", hl->info.ge.hBlock );
        } else {
            handle[0] = 0;
        }
        lock[0] = 0;
        if( hl->info.ge.wcLock ) {
            strcat( lock, "L1" );
            if( hl->info.ge.wcPageLock ) strcat( lock,"," );

⌨️ 快捷键说明

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