home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Frostbyte's 1980s DOS Shareware Collection
/
floppyshareware.zip
/
floppyshareware
/
DOOG
/
CBASE09.ZIP
/
CBASE.ZIP
/
CBCMP.C
< prev
next >
Wrap
Text File
|
1989-08-31
|
10KB
|
538 lines
/* Copyright (c) 1989 Citadel */
/* All Rights Reserved */
/* #ident "cbcmp.c 1.1 - 89/08/31" */
#include <blkio.h>
#include <errno.h>
/* #include <string.h> */
#include "cbase_.h"
/*man---------------------------------------------------------------------------
NAME
SYNOPSIS
DESCRIPTION
SEE ALSO
DIAGNOSTICS
------------------------------------------------------------------------------*/
static int charcmp(s1, s2, n)
void * s1;
void * s2;
size_t n;
{
int rt = 0;
/*signed*/char n1 = 0;
/*signed*/char n2 = 0;
cbrpos_t b1 = 0;
cbrpos_t b2 = 0;
memcpy((void *)&n1, s1, sizeof(n1));
memcpy((void *)&n2, s2, sizeof(n2));
if (n1 < n2) {
rt = -1;
} else if (n1 > n2) {
rt = 1;
} else {
rt = 0;
}
if (rt != 0) {
return rt;
}
memcpy((void *)&b1, (void *)((char *)s1 + n - sizeof(cbrpos_t)), sizeof(b1));
memcpy((void *)&b2, (void *)((char *)s2 + n - sizeof(cbrpos_t)), sizeof(b2));
if (b1 < b2) {
rt = -1;
} else if (b1 > b2) {
rt = 1;
} else {
rt = 0;
}
return rt;
}
static int ucharcmp(s1, s2, n)
void * s1;
void * s2;
size_t n;
{
int rt = 0;
unsigned char n1 = 0;
unsigned char n2 = 0;
cbrpos_t b1 = 0;
cbrpos_t b2 = 0;
memcpy((void *)&n1, s1, sizeof(n1));
memcpy((void *)&n2, s2, sizeof(n2));
if (n1 < n2) {
rt = -1;
} else if (n1 > n2) {
rt = 1;
} else {
rt = 0;
}
if (rt != 0) {
return rt;
}
memcpy((void *)&b1, (void *)((char *)s1 + n - sizeof(cbrpos_t)), sizeof(b1));
memcpy((void *)&b2, (void *)((char *)s2 + n - sizeof(cbrpos_t)), sizeof(b2));
if (b1 < b2) {
rt = -1;
} else if (b1 > b2) {
rt = 1;
} else {
rt = 0;
}
return rt;
}
static int shortcmp(s1, s2, n)
void * s1;
void * s2;
size_t n;
{
int rt = 0;
/*signed*/short n1 = 0;
/*signed*/short n2 = 0;
cbrpos_t b1 = 0;
cbrpos_t b2 = 0;
memcpy((void *)&n1, s1, sizeof(n1));
memcpy((void *)&n2, s2, sizeof(n2));
if (n1 < n2) {
rt = -1;
} else if (n1 > n2) {
rt = 1;
} else {
rt = 0;
}
if (rt != 0) {
return rt;
}
memcpy((void *)&b1, (void *)((char *)s1 + n - sizeof(cbrpos_t)), sizeof(b1));
memcpy((void *)&b2, (void *)((char *)s2 + n - sizeof(cbrpos_t)), sizeof(b2));
if (b1 < b2) {
rt = -1;
} else if (b1 > b2) {
rt = 1;
} else {
rt = 0;
}
return rt;
}
static int ushortcmp(s1, s2, n)
void * s1;
void * s2;
size_t n;
{
int rt = 0;
unsigned short n1 = 0;
unsigned short n2 = 0;
cbrpos_t b1 = 0;
cbrpos_t b2 = 0;
memcpy((void *)&n1, s1, sizeof(n1));
memcpy((void *)&n2, s2, sizeof(n2));
if (n1 < n2) {
rt = -1;
} else if (n1 > n2) {
rt = 1;
} else {
rt = 0;
}
if (rt != 0) {
return rt;
}
memcpy((void *)&b1, (void *)((char *)s1 + n - sizeof(cbrpos_t)), sizeof(b1));
memcpy((void *)&b2, (void *)((char *)s2 + n - sizeof(cbrpos_t)), sizeof(b2));
if (b1 < b2) {
rt = -1;
} else if (b1 > b2) {
rt = 1;
} else {
rt = 0;
}
return rt;
}
static int intcmp(s1, s2, n)
void * s1;
void * s2;
size_t n;
{
int rt = 0;
/*signed*/int n1 = 0;
/*signed*/int n2 = 0;
cbrpos_t b1 = 0;
cbrpos_t b2 = 0;
memcpy((void *)&n1, s1, sizeof(n1));
memcpy((void *)&n2, s2, sizeof(n2));
if (n1 < n2) {
rt = -1;
} else if (n1 > n2) {
rt = 1;
} else {
rt = 0;
}
if (rt != 0) {
return rt;
}
memcpy((void *)&b1, (void *)((char *)s1 + n - sizeof(cbrpos_t)), sizeof(b1));
memcpy((void *)&b2, (void *)((char *)s2 + n - sizeof(cbrpos_t)), sizeof(b2));
if (b1 < b2) {
rt = -1;
} else if (b1 > b2) {
rt = 1;
} else {
rt = 0;
}
return rt;
}
static int uintcmp(s1, s2, n)
void * s1;
void * s2;
size_t n;
{
int rt = 0;
unsigned int n1 = 0;
unsigned int n2 = 0;
cbrpos_t b1 = 0;
cbrpos_t b2 = 0;
memcpy((void *)&n1, s1, sizeof(n1));
memcpy((void *)&n2, s2, sizeof(n2));
if (n1 < n2) {
rt = -1;
} else if (n1 > n2) {
rt = 1;
} else {
rt = 0;
}
if (rt != 0) {
return rt;
}
memcpy((void *)&b1, (void *)((char *)s1 + n - sizeof(cbrpos_t)), sizeof(b1));
memcpy((void *)&b2, (void *)((char *)s2 + n - sizeof(cbrpos_t)), sizeof(b2));
if (b1 < b2) {
rt = -1;
} else if (b1 > b2) {
rt = 1;
} else {
rt = 0;
}
return rt;
}
static int longcmp(s1, s2, n)
void * s1;
void * s2;
size_t n;
{
int rt = 0;
/*signed*/long n1 = 0;
/*signed*/long n2 = 0;
cbrpos_t b1 = 0;
cbrpos_t b2 = 0;
memcpy((void *)&n1, s1, sizeof(n1));
memcpy((void *)&n2, s2, sizeof(n2));
if (n1 < n2) {
rt = -1;
} else if (n1 > n2) {
rt = 1;
} else {
rt = 0;
}
if (rt != 0) {
return rt;
}
memcpy((void *)&b1, (void *)((char *)s1 + n - sizeof(cbrpos_t)), sizeof(b1));
memcpy((void *)&b2, (void *)((char *)s2 + n - sizeof(cbrpos_t)), sizeof(b2));
if (b1 < b2) {
rt = -1;
} else if (b1 > b2) {
rt = 1;
} else {
rt = 0;
}
return rt;
}
static int ulongcmp(s1, s2, n)
void * s1;
void * s2;
size_t n;
{
int rt = 0;
unsigned long n1 = 0;
unsigned long n2 = 0;
cbrpos_t b1 = 0;
cbrpos_t b2 = 0;
memcpy((void *)&n1, s1, sizeof(n1));
memcpy((void *)&n2, s2, sizeof(n2));
if (n1 < n2) {
rt = -1;
} else if (n1 > n2) {
rt = 1;
} else {
rt = 0;
}
if (rt != 0) {
return rt;
}
memcpy((void *)&b1, (void *)((char *)s1 + n - sizeof(cbrpos_t)), sizeof(b1));
memcpy((void *)&b2, (void *)((char *)s2 + n - sizeof(cbrpos_t)), sizeof(b2));
if (b1 < b2) {
rt = -1;
} else if (b1 > b2) {
rt = 1;
} else {
rt = 0;
}
return rt;
}
static int floatcmp(s1, s2, n)
void * s1;
void * s2;
size_t n;
{
int rt = 0;
float n1 = 0;
float n2 = 0;
cbrpos_t b1 = 0;
cbrpos_t b2 = 0;
memcpy((void *)&n1, s1, sizeof(n1));
memcpy((void *)&n2, s2, sizeof(n2));
if (n1 < n2) {
rt = -1;
} else if (n1 > n2) {
rt = 1;
} else {
rt = 0;
}
if (rt != 0) {
return rt;
}
memcpy((void *)&b1, (void *)((char *)s1 + n - sizeof(cbrpos_t)), sizeof(b1));
memcpy((void *)&b2, (void *)((char *)s2 + n - sizeof(cbrpos_t)), sizeof(b2));
if (b1 < b2) {
rt = -1;
} else if (b1 > b2) {
rt = 1;
} else {
rt = 0;
}
return rt;
}
static int doublecmp(s1, s2, n)
void * s1;
void * s2;
size_t n;
{
int rt = 0;
double n1 = 0;
double n2 = 0;
cbrpos_t b1 = 0;
cbrpos_t b2 = 0;
memcpy((void *)&n1, s1, sizeof(n1));
memcpy((void *)&n2, s2, sizeof(n2));
if (n1 < n2) {
rt = -1;
} else if (n1 > n2) {
rt = 1;
} else {
rt = 0;
}
if (rt != 0) {
return rt;
}
memcpy((void *)&b1, (void *)((char *)s1 + n - sizeof(cbrpos_t)), sizeof(b1));
memcpy((void *)&b2, (void *)((char *)s2 + n - sizeof(cbrpos_t)), sizeof(b2));
if (b1 < b2) {
rt = -1;
} else if (b1 > b2) {
rt = 1;
} else {
rt = 0;
}
return rt;
}
static int ldoublecmp(s1, s2, n)
void * s1;
void * s2;
size_t n;
{
int rt = 0;
/*long*/double n1 = 0;
/*long*/double n2 = 0;
cbrpos_t b1 = 0;
cbrpos_t b2 = 0;
memcpy((void *)&n1, s1, sizeof(n1));
memcpy((void *)&n2, s2, sizeof(n2));
if (n1 < n2) {
rt = -1;
} else if (n1 > n2) {
rt = 1;
} else {
rt = 0;
}
if (rt != 0) {
return rt;
}
memcpy((void *)&b1, (void *)((char *)s1 + n - sizeof(cbrpos_t)), sizeof(b1));
memcpy((void *)&b2, (void *)((char *)s2 + n - sizeof(cbrpos_t)), sizeof(b2));
if (b1 < b2) {
rt = -1;
} else if (b1 > b2) {
rt = 1;
} else {
rt = 0;
}
return rt;
}
static int pointercmp(s1, s2, n)
void * s1;
void * s2;
size_t n;
{
int rt = 0;
void * n1 = 0;
void * n2 = 0;
cbrpos_t b1 = 0;
cbrpos_t b2 = 0;
memcpy((void *)&n1, s1, sizeof(n1));
memcpy((void *)&n2, s2, sizeof(n2));
if (n1 < n2) {
rt = -1;
} else if (n1 > n2) {
rt = 1;
} else {
rt = 0;
}
if (rt != 0) {
return rt;
}
memcpy((void *)&b1, (void *)((char *)s1 + n - sizeof(cbrpos_t)), sizeof(b1));
memcpy((void *)&b2, (void *)((char *)s2 + n - sizeof(cbrpos_t)), sizeof(b2));
if (b1 < b2) {
rt = -1;
} else if (b1 > b2) {
rt = 1;
} else {
rt = 0;
}
return rt;
}
static int stringcmp(s1, s2, n)
void * s1;
void * s2;
size_t n;
{
int rt = 0;
cbrpos_t b1 = 0;
cbrpos_t b2 = 0;
rt = strncmp((char *)s1, (char *)s2, n - sizeof(cbrpos_t));
if (rt != 0) {
return rt;
}
memcpy((void *)&b1, (void *)((char *)s1 + n - sizeof(cbrpos_t)), sizeof(b1));
memcpy((void *)&b2, (void *)((char *)s2 + n - sizeof(cbrpos_t)), sizeof(b2));
if (b1 < b2) {
rt = -1;
} else if (b1 > b2) {
rt = 1;
} else {
rt = 0;
}
return rt;
}
static int binarycmp(s1, s2, n)
void * s1;
void * s2;
size_t n;
{
int rt = 0;
cbrpos_t b1 = 0;
cbrpos_t b2 = 0;
rt = memcmp((char *)s1, (char *)s2, n - sizeof(cbrpos_t));
if (rt != 0) {
return rt;
}
memcpy((void *)&b1, (void *)((char *)s1 + n - sizeof(cbrpos_t)), sizeof(b1));
memcpy((void *)&b2, (void *)((char *)s2 + n - sizeof(cbrpos_t)), sizeof(b2));
if (b1 < b2) {
rt = -1;
} else if (b1 > b2) {
rt = 1;
} else {
rt = 0;
}
return rt;
}
/* cbase comparison function array definition */
pfcbcmp_t cbcmp_p[] = {
charcmp, /* t_char = 1 */
ucharcmp, /* t_uchar = 2 */
shortcmp, /* t_short = 3 */
ushortcmp, /* t_ushort = 4 */
intcmp, /* t_int = 5 */
uintcmp, /* t_uint = 6 */
longcmp, /* t_long = 7 */
ulongcmp, /* t_ulong = 8 */
floatcmp, /* t_float = 9 */
doublecmp, /* t_double = 10 */
ldoublecmp, /* t_ldouble = 11 */
pointercmp, /* t_pointer = 12 */
stringcmp, /* t_string = 13 */
binarycmp /* t_binary = 14 */
};