home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
BURKS 2
/
BURKS_AUG97.ISO
/
BURKS
/
SOFTWARE
/
LIBS
/
EMSIF24A.ZIP
/
TESTUTIL.C
(
.txt
)
< prev
next >
Wrap
C/C++ Source or Header
|
1991-11-15
|
36KB
|
769 lines
/***************************************************************************
* TESTUTIL.C *
* MODULE: TESTUTIL *
* OS: DOS *
* VERSION: 1.0 *
* DATE: 11/15/91 *
* *
* Copyright (c) 1991 James W. Birdsall. All Rights Reserved. *
* *
* Requires testutil.h to compile. *
* Compiles under Borland C++ 2.0, TC 2.0, or MSC 6.00A. *
* *
* This file contains various utility functions used to fill and check *
* blocks of memory and perform other basic services. Many are coded in *
* in-line assembly language to improve speed. The in-line assembly is *
* compatible with both Turbo/Borland C[++] and MSC 6.00A. If your *
* compiler does not support in-line assembly, or your compiler requires *
* an external assembler which you do not have, or you simply do not wish *
* to use the in-line assembly code, the functions also contain C code *
* versions. The C code versions are the default; in order to use the *
* in-line assembly, you must define the symbol INLINE_ASM when *
* compiling. *
* *
***************************************************************************/
/*
** system includes <>
*/
#include <string.h>
#include <dos.h>
/*
** custom includes ""
*/
#include "testutil.h"
/*
** local #defines
*/
/*
** misc: copyright strings, version macros, etc.
*/
/*
** typedefs
*/
/*
** global variables
*/
/*
** static globals
*/
/*
** function prototypes
*/
/*
** functions
*/
/***************************************************************************
* FUNCTION: FARMEMCHECK *
* *
* DESCRIPTION: *
* *
* This function scans a block of memory looking for bytes which do *
* not match checkchar. *
* *
* ENTRY: *
* *
* buffer - pointer to block of memory to scan *
* len - length of block *
* checkchar - value which should be matched *
* *
* EXIT: *
* *
* Returns 0 if all bytes match, nonzero if mismatch found. *
* *
* CONSTRAINTS/SIDE EFFECTS: *
* *
***************************************************************************/
int farmemcheck(unsigned char far *buffer, unsigned int len,
unsigned char checkchar)
{
int retval = 0;
unsigned char huge *temp;
/* normalize far pointer and turn into huge pointer */
temp = normptr(buffer);
#ifdef INLINE_ASM
ASM push bx /* preserve registers */
ASM push cx
ASM push si
ASM push ds
ASM lds si, [temp] /* load pointer into DS:SI */
ASM mov cx, [len] /* load length into CX */
ASM mov bl, [checkchar] /* load match value into BX */
looptop:
ASM lodsb /* load next byte into AL */
ASM cmp al, bl /* test against BL */
ASM jne nomatch /* if not equal, exit loop */
ASM loop looptop /* otherwise loop */
ASM jmp match
nomatch:
ASM mov WORD PTR [retval], 1 /* return nonzero on mismatch */
match:
ASM pop ds /* restore register values */
ASM pop si
ASM pop cx
ASM pop bx
#else
for (; len; len--, temp++) /* do the same thing in C */
{
if (*temp != checkchar)
{
retval = 1;
break;
}
}
#endif
return retval;
} /* end of farmemcheck() */
/***************************************************************************
* FUNCTION: LFARMEMCHECK *
* *
* DESCRIPTION: *
* *
* This function scans a block of memory longer than 64K looking for *
* bytes which do not match checkchar. *
* *
* ENTRY: *
* *
* buffer - pointer to block of memory to scan *
* len - length of block *
* checkchar - value which should be matched *
* *
* EXIT: *
* *
* Returns 0 if all bytes match, nonzero if mismatch found. *
* *
* CONSTRAINTS/SIDE EFFECTS: *
* *
***************************************************************************/
int lfarmemcheck(unsigned char far *buffer, unsigned long len,
unsigned char checkchar)
{
int retval;
unsigned int copylen;
unsigned char huge *temp;
/* normalize far pointer and turn into huge pointer */
temp = normptr(buffer);
while (len > 0L)
{
copylen = ((len > 65000L) ? 65000U : (unsigned int) len);
if ((retval = farmemcheck((void far *) temp, copylen, checkchar)) != 0)
{
return retval;
}
temp = normptr((unsigned char far *)(temp + copylen));
len -= copylen;
}
return retval;
} /* end of lfarmemcheck() */
/***************************************************************************
* FUNCTION: LFMEMCMP *
* *
* DESCRIPTION: *
* *
* Compares two regions of memory longer than 64K.