home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ User's Journal & Wi…eveloper's Journal Tools
/
C-C__Users_Journal_and_Windows_Developers_Journal_Tools_1997.iso
/
windbase
/
windbase.exe
/
MEMSLC.3
/
SET.C
< prev
next >
Wrap
C/C++ Source or Header
|
1996-07-30
|
7KB
|
208 lines
/*****************************************************************************\
** **
** WW WW IIIIIIII NNN NN DDDDDDD BBBBBBB AA SSSSSS EEEEEEEE **
** WW W WW II NNNN NN DD DD BB BB AA AA SS EE **
** WW W WW II NN NN NN DD DD BBBBBBB AAAAAAAA SSSSSS EEEEEE **
** WW W WW II NN NNNN DD DD BB BB AA AA SS EE **
** WWWWW IIIIIIII NN NNN DDDDDDD BBBBBBB AA AA SSSSSS EEEEEEEE **
** **
** SSSSSS OOOOOO FFFFFFFF TTTTTTTT WW WW AA RRRRRRR EEEEEEEE **
** SS OO OO FF TT WW W WW AA AA RR RR EE **
** SSSSS OO OO FFFFF TT WW W WW AAAAAAAA RRRRRRR EEEEEE **
** SS OO OO FF TT WW W WW AA AA RR RR EE **
** SSSSSS OOOOOO FF TT WWWWW AA AA RR RR EEEEEEEE **
** **
*********** NOTICE ************************************************************
** This file contains valuable trade secrets and proprietary **
** assets of Windbase Software Inc. Embodying substantial **
** creative efforts and confidential information. Unauthorized **
** use, copying, decompiling, translating, disclosure or **
** transfer, of any kind, is strictly prohibited. **
** **
** COPYRIGHT (C) 1992, 1993, 1994. Windbase Software Inc. **
** ALL RIGHTS RESERVED. **
\*****************************************************************************/
#include <stdio.h>
#include <string.h>
#include <malloc.h>
#include "../memsl.h"
#ifdef WBSTDC
int Compare(void *nullitem, char *item1, char *item2)
#else
int Compare(nullitem, item1, item2)
void *nullitem;
char *item1,
*item2;
#endif
{
WBTrcEntry(0,"Compare",("%p, %s, %s",nullitem,item1?item1:"NULL",item2?item2:"NULL"));
nullitem = nullitem;
WBTrcReturn(0,strcmp(item1,item2),("%d",strcmp(item1,item2)));
}
#ifdef WBSTDC
void *Copy(void *nullitem, char *item)
#else
void *Copy(nullitem, item)
void *nullitem;
char *item;
#endif
{
char *newstr;
WBTrcEntry(0,"Copy",("%p, %s",nullitem,item?item:"NULL"));
nullitem = nullitem;
if ((newstr = malloc(strlen(item)+1)) != NULL)
strcpy(newstr,item);
WBTrcReturn(0,newstr,("%p",newstr));
}
#ifdef WBSTDC
void Print(void *nullitem, char *item)
#else
void Print(nullitem, item)
void *nullitem;
char *item;
#endif
{
WBTrcEntry(0,"Print",("%p, %s",nullitem,item?item:"NULL"));
nullitem = nullitem;
printf("%s\n",item);
WBTrcVReturn(0,(""));
}
#ifdef WBSTDC
void Delete(void *nullitem, char *item)
#else
void Delete(nullitem, item)
void *nullitem;
char *item;
#endif
{
WBTrcEntry(0,"Delete",("%p, %s",nullitem,item?item:"NULL"));
nullitem = nullitem;
free(item);
WBTrcVReturn(0,(""));
}
#if defined(WBTRC_LEVEL1) || defined(WBTRC_LEVEL2)
#ifdef WBSTDC
int main(int argc, char **argv)
#else
int main(argc, argv)
int argc;
char **argv;
#endif
#else
#ifdef WBSTDC
int main(void)
#else
int main()
#endif
#endif
{
FILE *file;
WBSET *newset, *set1, *set2;
char str[41], *strptr;
WBTrcMainEntry();
if ((set1 = WBSetOpen(NULL)) != NULL)
if ((set2 = WBSetOpen(NULL)) != NULL)
if ((newset = WBSetOpen(NULL)) != NULL)
{
#ifdef FUNCTCAST
WBSetCompareF(set1,NULL,(int (*)(void *, void *, void *))Compare);
WBSetExecuteF(set1,NULL,(void (*)(void *, void *))Print);
WBSetDeleteF(set1,NULL,(void (*)(void *, void *))Delete);
WBSetCompareF(set2,NULL,(int (*)(void *, void *, void *))Compare);
WBSetExecuteF(set2,NULL,(void (*)(void *, void *))Print);
WBSetDeleteF(set2,NULL,(void (*)(void *, void *))Delete);
WBSetCompareF(newset,NULL,(int (*)(void *, void *, void *))Compare);
WBSetExecuteF(newset,NULL,(void (*)(void *, void *))Print);
WBSetDeleteF(newset,NULL,(void (*)(void *, void *))Delete);
WBSetCopyF(newset,NULL,(void *(*)(void *, void *))Copy);
#else
WBSetCompareF(set1,NULL,(int (*)())Compare);
WBSetExecuteF(set1,NULL,(void (*)())Print);
WBSetDeleteF(set1,NULL,(void (*)())Delete);
WBSetCompareF(set2,NULL,(int (*)())Compare);
WBSetExecuteF(set2,NULL,(void (*)())Print);
WBSetDeleteF(set2,NULL,(void (*)())Delete);
WBSetCompareF(newset,NULL,(int (*)())Compare);
WBSetExecuteF(newset,NULL,(void (*)())Print);
WBSetDeleteF(newset,NULL,(void (*)())Delete);
WBSetCopyF(newset,NULL,(void *(*)())Copy);
#endif
if ((file = fopen("data.dat","rt")) != NULL)
{
while (fgets(str,40,file))
{
if (*str && *(str+strlen(str)-1) == '\n')
*(str+strlen(str)-1) = '\0';
if ((strptr = malloc(strlen(str)+1)) != NULL)
{
strcpy(strptr,str);
if (WBSetAdd(set1,strptr) == -1)
free(strptr);
}
}
fclose(file);
}
if ((file = fopen("data2.dat","rt")) != NULL)
{
while (fgets(str,40,file))
{
if (*str && *(str+strlen(str)-1) == '\n')
*(str+strlen(str)-1) = '\0';
if ((strptr = malloc(strlen(str)+1)) != NULL)
{
strcpy(strptr,str);
if (WBSetAdd(set2,strptr) == -1)
free(strptr);
}
}
fclose(file);
}
printf(" Executing set1\n");
WBSetExecute(set1);
printf(" Executing set2\n");
WBSetExecute(set2);
if (WBSetIsSubset(set1,set2))
printf("set2 is a subset of set1, set1 is a superset of set2\n");
else
printf("set2 is NOT a subset of set1\n");
if (WBSetIsSubset(set2,set1))
printf("set1 is a subset of set2, set2 is a superset of set1\n");
else
printf("set1 is NOT a subset of set2\n");
if (WBSetIsEqual(set1,set2))
printf("Set1 and Set2 are Equal\n");
else
printf("Set1 and Set2 are NOT Equal\n");
WBSetClose(set1);
WBSetClose(set2);
WBSetClose(newset);
}
WBTrcReturn(0,0,("0"));
}