⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 addressdb.c

📁 个人日程管理系统
💻 C
📖 第 1 页 / 共 5 页
字号:
//   AddrPackedDBRecord*   recordP;
//   UInt16                   newIndex;
//   
//
//   // 1) and 2) (make a new chunk with the correct size)
//   recordH = DmNewHandle(dbP, (Int32) AddrUnpackedSize(r));
//   if (recordH == NULL)
//      return dmErrMemError;
//
//      
//   // 3) Copy the data from the unpacked record to the packed one.
//   recordP = MemHandleLock(recordH);
//   AddrPack(r, recordP);
//
//   // Get the index
//   newIndex = AddrFindSortPosition(dbP, recordP);
//   MemPtrUnlock(recordP);
//
//
//   // 4) attach in place
//   err = DmAttachRecord(dbP, &newIndex, recordH, 0);
//   if (err) 
//      MemHandleFree(recordH);
//   else
//      *index = newIndex;
//      
//   return err;
//}


/************************************************************
 *
 *  FUNCTION: AddrChangeRecord
 *
 *  DESCRIPTION: Change a record in the Address Database
 *
 *  PARAMETERS: dbP - open database pointer
 *            database index
 *            address record
 *            changed fields
 *
 *  RETURNS: ##0 if successful, errorcode if not
 *
 *  CREATED: 1/14/95 
 *
 *  BY: Roger Flores
 *
 *   COMMENTS:   Records are not stored with extra padding - they
 *   are always resized to their exact storage space.  This avoids
 *   a database compression issue.  The code works as follows:
 *   
 *   1)   get the size of the new record
 *   2)   make the new record
 *   3)   pack the packed record plus the changes into the new record
 *   4)   if the sort position is changes move to the new position
 *   5)   attach in position
 *
 * The MemHandle to the record passed doesn't need to be unlocked 
 * since that chunk is freed by this routine.  It should be discarded.
 *
 *************************************************************/
//Err AddrChangeRecord(DmOpenRef dbP, UInt16 *index, AddrDBRecordPtr r, 
//   AddrDBRecordFlags changedFields)
//{
//   AddrDBRecordType    src;
//   MemHandle             srcH;
//   Err                result;
//   MemHandle             recordH=0;
//   MemHandle             oldH;
//   Int16                i;
//   UInt32             changes = changedFields.allBits;
//   Int16                sortByCompany;
//   AddrAppInfoPtr    appInfoPtr;
//   Boolean            dontMove;
//   UInt16                attributes;      // to contain the deleted flag
//   
//   AddrPackedDBRecord*   cmpP;
//   AddrPackedDBRecord*   recordP;
//
//   
//   // We do not assume that r is completely valid so we get a valid
//   // AddrDBRecordPtr...
//   if ((result = AddrGetRecord(dbP, *index, &src, &srcH)) != 0)
//      return result;
//   
//   // and we apply the changes to it.
//   src.options = r->options;         // copy the phone info
//   for (i = firstAddressField; i < addressFieldsCount; i++) 
//      {
//      // If the flag is set point to the string else NULL
//      if (GetBitMacro(changes, i) != 0)
//         {
//         src.fields[i] = r->fields[i];
//         RemoveBitMacro(changes, i);
//         }
//      if (changes == 0)
//         break;      // no more changes
//      }
//
//
//   // 1) and 2) (make a new chunk with the correct size)
//   recordH = DmNewHandle(dbP, AddrUnpackedSize(&src));
//   if (recordH == NULL)
//      {
//      MemHandleUnlock(srcH);      // undo lock from AddrGetRecord above
//      return dmErrMemError;
//      }
//   recordP = MemHandleLock(recordH);
//
//      
//   // 3) Copy the data from the unpacked record to the packed one.
//   AddrPack(&src, recordP);
//
//   // The original record is copied and no longer needed.
//   MemHandleUnlock(srcH);
//   
//
//   // 4) if the sort position changes...
//   // Check if any of the key fields have changed
//   if ((changedFields.allBits & sortKeyFieldBits) == 0) 
//      goto attachRecord;
//   
//   
//   // Make sure *index-1 < *index < *index+1, if so it's in sorted 
//   // order.  Leave it there.   
//   appInfoPtr = (AddrAppInfoPtr) AddrAppInfoGetPtr(dbP);
//   sortByCompany = appInfoPtr->misc.sortByCompany;
//   MemPtrUnlock(appInfoPtr);
//
//   if (*index > 0)
//      {
//      // This record wasn't deleted and deleted records are at the end of the
//      // database so the prior record may not be deleted!
//      cmpP = MemHandleLock(DmQueryRecord(dbP, *index-1));
//      dontMove = (AddrComparePackedRecords (cmpP,  recordP, sortByCompany,
//                     NULL, NULL, 0) == -1);
//      MemPtrUnlock(cmpP);
//      }
//   else 
//      dontMove = true;
//
//
//   if (*index+1 < DmNumRecords (dbP))
//      {
//      DmRecordInfo(dbP, *index+1, &attributes, NULL, NULL);
//      if (attributes & dmRecAttrDelete)
//         ;      // don't move it after the deleted record!
//      else {
//         cmpP = MemHandleLock(DmQueryRecord(dbP, *index+1));
//         dontMove = dontMove && (AddrComparePackedRecords (recordP, cmpP, 
//                     sortByCompany, NULL, NULL, 0) == -1);
//         MemPtrUnlock(cmpP);
//         }
//      }
//
//      
//   if (dontMove) 
//      goto attachRecord;
//
//   
//   
//   // The record isn't in the right position.  Move it.
//   i = AddrFindSortPosition(dbP, recordP);
//   DmMoveRecord(dbP, *index, i);
//   if (i > *index) i--;
//   *index = i;                  // return new position
//
//
//   // Attach the new record to the old index,  the preserves the 
//   // category and record id.
//attachRecord:
//
//   result = DmAttachRecord(dbP, index, recordH, &oldH);
//   MemPtrUnlock(recordP);
//   if (result) return result;
//
//   MemHandleFree(oldH);
//   return 0;
//}



/************************************************************
 *
 *  FUNCTION: AddrGetRecord
 *
 *  DESCRIPTION: Get a record from the Address Database
 *
 *  PARAMETERS: database pointer - open db pointer
 *            database index - index of record to lock
 *            address record pointer - pointer address structure
 *            address record - MemHandle to unlock when done
 *
 *  RETURNS: ##0 if successful, errorcode if not
 *    The record's MemHandle is locked so that the pointer to 
 *  strings within the record remain pointing to valid chunk
 *  versus the record randomly moving.  Unlock the MemHandle when
 *  AddrDBRecord is destroyed.
 *
 *  CREATED: 1/14/95 
 *
 *  BY: Roger Flores
 *
 *************************************************************/
Err AddrGetRecord(DmOpenRef dbP, UInt16 index, AddrDBRecordPtr recordP, 
   MemHandle *recordH)
{
   AddrPackedDBRecord *src;

   *recordH = DmQueryRecord(dbP, index);
   src = (AddrPackedDBRecord *) MemHandleLock(*recordH);
   if (src == NULL)
      return dmErrIndexOutOfRange;
   
   AddrUnpack(src, recordP);
   
   return 0;
}


/***********************************************************************
 *
 * FUNCTION:    RecordContainsData
 *
 * DESCRIPTION: Checks the record returns true if it contains any data.
 *
 * PARAMETERS:  recordP  - a pointer to an address record
 *
 * RETURNED:    true if one of the fields has data
 *
 * REVISION HISTORY:
 *         Name   Date      Description
 *         ----   ----      -----------
 *         rsf   12/3/97   Initial Revision
 *
 ***********************************************************************/
Boolean RecordContainsData (AddrDBRecordPtr recordP)
{
   UInt16 i;
   
   
	// Look for a field which isn't empty
	for (i = firstAddressField; i < addressFieldsCount; i++)
		{
		if (recordP->fields[i] != NULL)
		   return true;
		}
	
	return false;
}


/***********************************************************************
 *
 * FUNCTION:    RecordContainsField
 *
 * DESCRIPTION: Check if a packed record contains a desired field.           
 *
 * PARAMETERS:  recordP  - pointer to the record to search
 *              field - type of field to find.
 *
 * RETURNED:    true if the record contains the field.
 *
 * REVISION HISTORY:
 *         Name   Date      Description
 *         ----   ----      -----------
 *         Roger   7/9/96   Initial Revision
 *
 ***********************************************************************/
//static Boolean RecordContainsField(AddrPackedDBRecord *packedRecordP, 
//   AddressLookupFields field, Int16 * phoneP, Int16 direction,
//   AddressFields lookupFieldMap[])
//{
//   int index;
//   int stopIndex;
//   int phoneType;
//   
//   
//   switch (field)
//   	{
//      case addrLookupSortField:
//         return packedRecordP->flags.allBits & sortKeyFieldBits;
//      
//      case addrLookupListPhone:
//         return GetBitMacro(packedRecordP->flags.allBits, firstPhoneField + 
//            packedRecordP->options.phones.displayPhoneForList);
//      
//      case addrLookupNoField:
//         return true;
//      
//      default:
//			if (!IsPhoneLookupField(field))
//				return GetBitMacro(packedRecordP->flags.allBits, lookupFieldMap[field]) != 0;
//         
//			phoneType = field - addrLookupWork;
//			index = firstPhoneField + *phoneP;
//			if (direction == dmSeekForward)
//				stopIndex = lastPhoneField + direction;
//			else
//				stopIndex = firstPhoneField + direction;
//			
//         while (index != stopIndex)
//         	{
//            // If the phone field is the type requested and it's not empty 
//            // return it.
//            if (GetPhoneLabel(packedRecordP, index) == phoneType &&
//            	GetBitMacro(packedRecordP->flags.allBits, index))
//            	{
//               *phoneP = index - firstPhoneField;
//               return true;
//             	}
//          	index += direction;
//         	}
//          
//         // The phone type wasn't used.
//         if (direction == dmSeekForward)
//         	*phoneP = 0; 						     // Reset for the next record
//         else
//            *phoneP = numPhoneFields - 1;      // Reset for the next record
//          
//         return false;
//		}
//}


/************************************************************
 *
 *  FUNCTION: AddrChangeSortOrder
 *
 *  DESCRIPTION: Change the Address Database's sort order
 *
 *  PARAMETERS: dbP - open database pointer
 *            TRUE if sort by company
 *
 *  RETURNS: nothing
 *
 *  CREATED: 1/17/95 
 *
 *  BY: Roger Flores
 *
 *************************************************************/
//Err AddrChangeSortOrder(DmOpenRef dbP, Boolean sortByCompany)
//{
//   AddrAppInfoPtr appInfoPtr;
//   AddrAppInfoPtr   nilP=0;
//   AddrDBMisc      misc;
//
//   
//   appInfoPtr = (AddrAppInfoPtr) AddrAppInfoGetPtr(dbP);
//   misc = appInfoPtr->misc;
//   misc.sortByCompany = sortByCompany;
//   DmWrite(appInfoPtr, (Int32) &nilP->misc, &misc, sizeof(misc));
//   MemPtrUnlock(appInfoPtr);
//   
//   DmQuickSort(dbP, (DmComparF *) AddrComparePackedRecords, (Int16) sortByCompany);
//   return 0;
//}


/***********************************************************************
 *
 * FUNCTION:    AddrLookupSeekRecord
 *
 * DESCRIPTION: Given the index of a record, scan 
 *              forewards or backwards for displayable records.           
 *
 * PARAMETERS:  indexP  - pointer to the index of a record to start from;
 *                        the index of the record sought is returned in
 *                        this parameter.
 *
 *              offset  - number of records to skip:   
 *                           0 - mean seek from the current record to the
 *                             next display record, if the current record is
 *                             a display record, its index is retuned.
 *                         1 - mean seek foreward, skipping one displayable 
 *                             record
 *                        -1 - means seek backwards, skipping one 
 *                             displayable record
 *                             
 *
 * RETURNED:    true if a displayable record was found.
 *
 * REVISION HISTORY:
 *         Name   Date      Description
 *         ----   ----      -----------
 *         Roger   7/9/96   Initial Revision
 *

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -