HeapLister(code)
Volume Number: 6
Issue Number: 10
Column Tag: C Forum
Related Info: Memory Manager
HeapLister (code)
By Denis Molony, Sultanate of Oman
Listing: DPMUtilities.h
#define _H_DPMUtilities
void Write (int h, int v, char *text, long val, int width);
Handle WriteHandle (Handle mPtr, int leading, int trailing);
void WriteAddress (Ptr address, int leading, int trailing);
void WriteRect (Rect *theRect, int leading, int trailing);
void WritePoint (Point thePoint, int leading, int trailing);
void WriteBoolean (Boolean value, int leading, int trailing);
void FillLine (register char *cptr,
char *display, int totBytes);
void FourBlanks (void);
void DrawHex4 (register unsigned int i);
void DrawHex6 (register unsigned long i);
void AppendString (register char *s);
void NumToHex6 (register unsigned long i, register char *s);
#define CharOf(c) ((((c)>=0x20)&&((c)<=0xCF))?(c):’.’)
Listing: DPMUtilities.c
#include
#include
FontInfo fInfo;
char *dp;
char *countPtr;
char hexChar[16] = {‘0’,’1',’2',’3',’4',’5',’6',’7',
‘8’,’9',’A’,’B’,’C’,’D’,’E’,’F’};
void Write (int h, int v, char *text, long val, int width)
{
Str255 theText;
int charWidth = CharWidth (‘0’);
CtoPstr (text);
MoveTo (h - StringWidth (text), v);
DrawString (text);
if (width != 0) {
NumToString (val, theText);
Move ((width * charWidth) -
StringWidth (theText), 0);
DrawString (theText);
}
PtoCstr (text);
}
void WriteRect (Rect *theRect, int leading, int trailing)
{
Str255 text;
if (leading > 0)
Move (leading, 0);
NumToString (theRect->top, text);
DrawString (text);
DrawChar (‘/’);
NumToString (theRect->left, text);
DrawString (text);
DrawChar (‘/’);
NumToString (theRect->bottom, text);
DrawString (text);
DrawChar (‘/’);
NumToString (theRect->right, text);
DrawString (text);
if (trailing > 0)
Move (trailing, 0);
}
void WritePoint (Point thePoint, int leading, int trailing)
{
Str255 text;
if (leading > 0)
Move (leading, 0);
NumToString (thePoint.v, text);
DrawString (text);
DrawChar (‘/’);
NumToString (thePoint.h, text);
DrawString (text);
if (trailing > 0)
Move (trailing, 0);
}
Handle WriteHandle (Handle mPtr, int leading, int trailing)
{
char display[10];
long trueHandle;
if (leading > 0)
Move (leading, 0);
if (mPtr == 0L)
DrawString (“\pNULL”);
else {
NumToHex6 ((long)mPtr, display);
DrawString (display);
DrawText (“ ->”, 0, 3);
trueHandle = (long)StripAddress (*mPtr);
NumToHex6 (trueHandle, display);
Move (4, 0);
DrawString (display);
}
if (trailing > 0)
Move (trailing, 0);
return ((Handle)trueHandle);
}
void WriteAddress (Ptr address, int leading, int trailing)
{
char display[10];
long trueHandle;
if (leading > 0)
Move (leading, 0);
if (address == 0L)
DrawString (“\pNULL”);
else {
NumToHex6 ((long)address, display);
DrawString (display);
}
if (trailing > 0)
Move (trailing, 0);
}
void WriteBoolean (Boolean value, int leading, int trailing)
{
Str255 text;
if (leading > 0)
Move (leading, 0);
if (value)
DrawString (“\pTrue”);
else
DrawString (“\pFalse”);
if (trailing > 0)
Move (trailing, 0);
}
void AppendString (register char *s)
{
register char i, len;
*countPtr += (len = *s++);
for (i = 0; i < len; i++)
*dp++ = *s++;
}
void DrawHex6 (register unsigned long i)
{
register int mod = 20;
register int j;
register unsigned long mask = 0x000FFFFF;
for (j = 6;j > 0; --j) {
(*countPtr)++;
*dp++ = (hexChar[i>>mod]);
mod -= 4;
i &= mask;
mask >>= 4;
}
}
void DrawHex4 (register unsigned int i)
{
register int mod = 12;
register int j;
register unsigned int mask = 0x0FFF;
for (j = 4;j > 0; --j) {
(*countPtr)++;
*dp++ = hexChar[i>>mod];
mod -= 4;
i &= mask;
mask >>= 4;
}
}
void FourBlanks ()
{
(*countPtr) += 4;
*dp++ = ‘ ‘;
*dp++ = ‘ ‘;
*dp++ = ‘ ‘;
*dp++ = ‘ ‘;
}
void FillLine (register char *cptr, char *display, int totBytes)
{
register int k;
register int *ptr;
register char c;
register long n;
long i;
int count = 0;
ptr = (int*) cptr;
i = (long) cptr;
dp = countPtr = display;
*dp++ = 0;
n = i;
DrawHex6 (i);
AppendString (“\p: “);
for (k = 0 ;k < 4; k++) {
if (count >= totBytes)
FourBlanks();
else
DrawHex4(*ptr++);
n += 2;
count += 2;
(*countPtr)++;
*dp++ = ‘ ‘;
}
(*countPtr)++;
*dp++ = ‘ ‘;
for (k = 0; k < 4; k++) {
if (count >= totBytes)
FourBlanks ();
else
DrawHex4(*ptr++);
n += 2;
count += 2;
(*countPtr)++;
*dp++ = ‘ ‘;
}
AppendString (“\p “);
count = 0;
for (k = 0; k < 16; k++) {
c = *cptr++;
if (++count > totBytes)
return;
(*countPtr)++;
*dp++ = CharOf(c);
}
}
void NumToHex6 (register unsigned long i, register char *s)
{
register int mod = 20;
register int j;
register unsigned long mask = 0x000FFFFF;
*s++ = 6;
for (j = 6;j > 0; --j) {
*s++ = (hexChar[i>>mod]);
mod -= 4;
i &= mask;
mask >>= 4;
}
}
Listing: HeapConstants.h
#define LOCKtext 8
#define UNLOCKtext 9
#define HPURGEtext 10
#define HNOPURGEtext 11
#define LINEHEIGHT 11
#define LINESINMAINPANE 12