📄 addressdb.c
字号:
*
* if !sortByCompany:
* nameKey, firstNameKey, companyKey (if no name or first name), uniq ID
*
*
*************************************************************/
//static void AddrFindKey(AddrPackedDBRecord *r, char **key, UInt16 *whichKey,
// Int16 sortByCompany)
//{
// AddrDBRecordFlags fieldFlags;
//
// fieldFlags.allBits = r->flags.allBits;
//
// ErrFatalDisplayIf(*whichKey == 0 || *whichKey == 5, "Bad addr key");
//
// if (sortByCompany)
// {
// if (*whichKey == 1 && fieldFlags.bits.company)
// {
// *whichKey = 2;
// goto returnCompanyKey;
// }
//
// if (*whichKey <= 2 && fieldFlags.bits.name)
// {
// *whichKey = 3;
// goto returnNameKey;
// }
//
// if (*whichKey <= 3 && fieldFlags.bits.firstName)
// {
// *whichKey = 4;
// goto returnFirstNameKey;
// }
// }
// else
// {
// if (*whichKey == 1 && fieldFlags.bits.name)
// {
// *whichKey = 2;
// goto returnNameKey;
// }
//
// if (*whichKey <= 2 && fieldFlags.bits.firstName)
// {
// *whichKey = 3;
// goto returnFirstNameKey;
// }
//
// // For now don't consider company name when sorting by person name
// // unless there isn't a name or firstName
// if (*whichKey <= 3 && fieldFlags.bits.company &&
// !(fieldFlags.bits.name || fieldFlags.bits.firstName))
// {
// *whichKey = 4;
// goto returnCompanyKey;
// }
//
// }
//
// // All possible fields have been tried so return NULL so that
// // the uniq ID is compared.
// *whichKey = 5;
// *key = NULL;
// return;
//
//
//
//returnCompanyKey:
// *key = (char *) &r->companyFieldOffset + r->companyFieldOffset;
// return;
//
//
//returnNameKey:
// *key = &r->firstField;
// return;
//
//
//returnFirstNameKey:
// *key = &r->firstField;
// if (r->flags.bits.name)
// {
// *key += StrLen(*key) + 1;
// }
// return;
//
//}
/************************************************************
*
* FUNCTION: AddrComparePackedRecords
*
* DESCRIPTION: Compare two packed records.
*
* PARAMETERS: address record 1
* address record 2
*
* RETURNS: -1 if record one is less
* 1 if record two is less
*
* CREATED: 1/14/95
*
* BY: Roger Flores
*
* COMMENTS: Compare the two records key by key until
* there is a difference. Return -1 if r1 is less or 1 if r2
* is less. A zero may be returned if two records
* seem identical.
* NULL fields are considered less than others.
*
*************************************************************/
//static Int16 AddrComparePackedRecords(AddrPackedDBRecord *r1, AddrPackedDBRecord *r2,
// Int16 sortByCompany, SortRecordInfoPtr /*info1*/, SortRecordInfoPtr /*info2*/,
// MemHandle /*appInfoH*/)
//{
// UInt16 whichKey1, whichKey2;
// char *key1, *key2;
// Int16 result;
//
// whichKey1 = 1;
// whichKey2 = 1;
//
// do {
// AddrFindKey(r1, &key1, &whichKey1, sortByCompany);
// AddrFindKey(r2, &key2, &whichKey2, sortByCompany);
//
// // A key with NULL loses the StrCompare.
// if (key1 == NULL)
// {
// // If both are NULL then return them as equal
// if (key2 == NULL)
// {
// result = 0;
// return result;
// }
// else
// result = -1;
// }
// else
// if (key2 == NULL)
// result = 1;
// else
// {
// result = StrCaselessCompare(key1, key2);
// if (result == 0)
// result = StrCompare(key1, key2);
// }
//
// } while (!result);
//
//
// return result;
//}
/************************************************************
*
* FUNCTION: AddrUnpackedSize
*
* DESCRIPTION: Return the size of an AddrDBRecordType
*
* PARAMETERS: address record
*
* RETURNS: the size in bytes
*
* CREATED: 1/10/95
*
* BY: Roger Flores
*
*************************************************************/
//static Int16 AddrUnpackedSize(AddrDBRecordPtr r)
//{
// Int16 size;
// Int16 index;
//
// size = sizeof (AddrPackedDBRecord) - sizeof (char); // correct
// for (index = firstAddressField; index < addressFieldsCount; index++)
// {
// if (r->fields[index] != NULL)
// size += StrLen(r->fields[index]) + 1;
// }
// return size;
//}
/************************************************************
*
* FUNCTION: AddrPack
*
* DESCRIPTION: Pack an AddrDBRecordType. Doesn't pack empty strings.
*
* PARAMETERS: address record to pack
* address record to pack into
*
* RETURNS: the AddrPackedDBRecord is packed
*
* CREATED: 1/10/95
*
* BY: Roger Flores
*
*************************************************************/
//static void AddrPack(AddrDBRecordPtr s, void * recordP)
//{
// Int32 offset;
// AddrDBRecordFlags flags;
// Int16 index;
// AddrPackedDBRecord* d=0;
// Int16 len;
// void * srcP;
// UInt8 companyFieldOffset;
//
// flags.allBits = 0;
//
// DmWrite(recordP, (Int32)&d->options, &s->options, sizeof(s->options));
// offset = (Int32)&d->firstField;
//
// for (index = firstAddressField; index < addressFieldsCount; index++) {
// if (s->fields[index] != NULL)
///* if (s->fields[index][0] == '\0')
// {
// // so set the companyFieldOffset or clear it code doesn't fail
// s->fields[index] = NULL;
// }
// else
//*/
// {
// ErrFatalDisplayIf(s->fields[index][0] == '\0' && index != note,
// "Empty field being added");
// srcP = s->fields[index];
// len = StrLen(srcP) + 1;
// DmWrite(recordP, offset, srcP, len);
// offset += len;
// SetBitMacro(flags.allBits, index);
// }
// }
//
// // Set the flags indicating which fields are used
// DmWrite(recordP, (Int32)&d->flags.allBits, &flags.allBits, sizeof(flags.allBits));
//
// // Set the companyFieldOffset or clear it
// if (s->fields[company] == NULL)
// companyFieldOffset = 0;
// else {
// index = 1;
// if (s->fields[name] != NULL)
// index += StrLen(s->fields[name]) + 1;
// if (s->fields[firstName] != NULL)
// index += StrLen(s->fields[firstName]) + 1;
// companyFieldOffset = (UInt8) index;
// }
// DmWrite(recordP, (Int32)(&d->companyFieldOffset), &companyFieldOffset, sizeof(companyFieldOffset));
//}
/************************************************************
*
* FUNCTION: AddrUnpack
*
* DESCRIPTION: Fills in the AddrDBRecord structure
*
* PARAMETERS: address record to unpack
* the address record to unpack into
*
* RETURNS: the record unpacked
*
* CREATED: 1/14/95
*
* BY: Roger Flores
*
*************************************************************/
static void AddrUnpack(AddrPackedDBRecord *src, AddrDBRecordPtr dest)
{
Int16 index;
UInt32 flags;
char *p;
dest->options = src->options;
flags = src->flags.allBits;
p = &src->firstField;
for (index = firstAddressField; index < addressFieldsCount; index++)
{
// If the flag is set point to the string else NULL
if (GetBitMacro(flags, index) != 0)
{
dest->fields[index] = p;
p += StrLen(p) + 1;
}
else
dest->fields[index] = NULL;
}
}
/************************************************************
*
* FUNCTION: AddrFindSortPosition
*
* DESCRIPTION: Return where a record is or should be
* Useful to find or find where to insert a record.
*
* PARAMETERS: address record
*
* RETURNS: the size in bytes
*
* CREATED: 1/11/95
*
* BY: Roger Flores
*
*************************************************************/
//static UInt16 AddrFindSortPosition(DmOpenRef dbP, AddrPackedDBRecord *newRecord)
//{
// Int16 sortByCompany;
// AddrAppInfoPtr appInfoPtr;
//
//
// appInfoPtr = (AddrAppInfoPtr) AddrAppInfoGetPtr(dbP);
// sortByCompany = appInfoPtr->misc.sortByCompany;
// MemPtrUnlock(appInfoPtr);
//
// return DmFindSortPosition(dbP, (void *) newRecord, NULL, (DmComparF *)
// AddrComparePackedRecords, (Int16) sortByCompany);
//}
/************************************************************
*
* FUNCTION: StrCmpMatches
*
* DESCRIPTION: Compares two strings and reports the number
* of matching bytes from the start of <s1>.
*
* PARAMETERS: 2 string pointers
*
* RETURNS: number of matching bytes from <s1>.
*
* CREATED: 6/15/95
*
* BY: Roger Flores
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* Roger 06/15/95 Initial Revision
* kwk 05/16/99 Use TxtCaselessCompare routine.
*
*************************************************************/
//static UInt16 StrCmpMatches(const Char* s1, const Char* s2)
//{
// UInt16 matches;
//
// ErrFatalDisplayIf ( s1 == NULL, "Error NULL string parameter");
// ErrFatalDisplayIf ( s2 == NULL, "Error NULL string parameter");
//
// TxtCaselessCompare(s1, StrLen(s1), &matches, s2, StrLen(s2), NULL);
// return (matches);
//}
/************************************************************
*
* FUNCTION: AddrNewRecord
*
* DESCRIPTION: Create a new packed record in sorted position
*
* PARAMETERS: database pointer - open db pointer
* address record - pointer to a record to copy into the DB
* record index - to be set to the new record's index
*
* RETURNS: ##0 if successful, errorcode if not
* index set if a new record is created.
*
* CREATED: 1/10/95
*
* BY: Roger Flores
*
*************************************************************/
//Err AddrNewRecord(DmOpenRef dbP, AddrDBRecordPtr r, UInt16 *index)
//{
// MemHandle recordH;
// Err err;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -