KpGenericPtr_t FAR reallocBufferPtrPrv(KpGenericPtr_t fp, KpInt32_t numBytes) { KpHandle_t h; /* initialize it in case of error */ KpGenericPtr_t p = (KpGenericPtr_t) NULL; KpInt32_t oldNumBytes; if (fp != NULL) { /* get size of old buffer */ oldNumBytes = getPtrSize(fp); if (numBytes >= 0) { /* get memory */ h = allocBufferHandle (numBytes); if (h != NULL) { /* lock it down */ p = lockBuffer (h); if (p == NULL) { freeBuffer (h); } else { /* make sure sizes make sense */ if (oldNumBytes <= numBytes) { /* copy old contents */ memmove(p, fp, oldNumBytes); } /* free old buffer */ freeBufferPtr(fp); } } } } return p; }
/*-------------------------------------------------------------------- * DESCRIPTION (Public) * Set the name of the file to associate with the profile. * If the Name is NULL no file will be associated with the profile. * * AUTHOR * lsh & mlb * * DATE Copied * November 15, 1995 *------------------------------------------------------------------*/ SpStatus_t KSPAPI SpProfileSetName ( SpProfile_t Profile, KpChar_t *FileName, SpFileProps_t *Props) { char FAR *fileName; SpProfileData_t FAR *ProfileData; SpStatus_t status; /* convert profile handle to data pointer */ ProfileData = SpProfileLock (Profile); if (NULL == ProfileData) return SpStatBadProfile; /* Free current FileName if one is there */ if (ProfileData->FileName != NULL) { if (ProfileData->TagArray == NULL) status = SpProfilePopTagArray(ProfileData); freeBuffer(ProfileData->FileName); } /* create the FileName handle */ ProfileData->FileName = allocBufferHandle (strlen (FileName) + 1); if (ProfileData->FileName == NULL) return SpStatMemory; /* lock FileName handle and return ptr */ fileName = (char *) lockBuffer (ProfileData->FileName); if (fileName == NULL) return SpStatMemory; /* copy text data into the newly allocated space */ strcpy (fileName, FileName); /* Copy props information into internal profile data structure */ #if defined (KPMAC) SpProfSetSpFileProps (Props, &(ProfileData->Props)); #endif /* unlock handles */ unlockBuffer (ProfileData->FileName); SpProfileUnlock (Profile); return SpStatSuccess; }
/* PTMemTest checks whether there is a reasonable amount of memory still available */ KpInt32_t PTMemTest(void) { KpHandle_t theBuffer; #if defined (KPMAC) theBuffer = NewHandle (MINPTMEMSIZE); /* do not want temp mem in this case */ MemLogAlloc (theBuffer, MINPTMEMSIZE); #else theBuffer = allocBufferHandle (MINPTMEMSIZE); #endif if (theBuffer == NULL) { return (0); } else { freeBuffer (theBuffer); return (1); } }
/*-------------------------------------------------------------------- * DESCRIPTION (Private -- phase out 5/4/95) * Set the name of the file to associate with the profile. * If the Name is NULL no file will be associated with the profile. * * AUTHOR * lsh * * DATE CREATED * Octorber 22, 1993 *------------------------------------------------------------------*/ SpStatus_t KSPAPI SpProfileSetFileName ( SpProfile_t Profile, char FAR *FileName) { char FAR *fileName; SpProfileData_t FAR *ProfileData; /* convert profile handle to data pointer */ ProfileData = SpProfileLock (Profile); if (NULL == ProfileData) return SpStatBadProfile; /* Free current FileName if one is there */ if (ProfileData->FileName != NULL) freeBuffer(ProfileData->FileName); /* create the FileName handle */ ProfileData->FileName = allocBufferHandle (strlen (FileName) + 1); if (ProfileData->FileName == NULL) return (SpStatMemory); /* lock FileName handle and return ptr */ fileName = (char *) lockBuffer (ProfileData->FileName); if (fileName == NULL) return (SpStatMemory); /* copy text data into the newly allocated space */ strcpy (fileName, FileName); #if defined (KPMAC) SpProfileClearProps(&(ProfileData->Props)); #endif /* unlock handles */ unlockBuffer (ProfileData->FileName); SpProfileUnlock (Profile); return SpStatSuccess; }
KpGenericPtr_t allocSysBufferPtr (KpInt32_t numBytes) { return (allocBufferHandle (numBytes)); }
KpHandle_t allocSysLargeBufferHandle (KpInt32_t numBytes) { return (allocBufferHandle (numBytes)); }
/*-------------------------------------------------------------------- * DESCRIPTION * Order the list of profiles by newest creation date * * AUTHOR * doro * * DATE CREATED * December 15, 1995 *------------------------------------------------------------------*/ SpStatus_t KSPAPI SpProfileOrderList( SpProfile_t *profileList, KpInt32_t foundCount) { KpInt32_t Date, *DateList; KpInt32_t Time, *TimeList; SpHeader_t PfHeader; KpHandle_t DateHandle, TimeHandle; int i, j, z; SpStatus_t Status; SpProfile_t profileToMove; if (foundCount < 2) return SpStatSuccess; if ((DateHandle = allocBufferHandle(foundCount*sizeof(KpInt32_t))) == (KpHandle_t)NULL) return SpStatMemory; if ((DateList = (KpInt32_t *)lockBuffer(DateHandle)) == (KpInt32_t *)NULL) { freeBuffer(DateHandle); return SpStatBadBuffer; } if ((TimeHandle = allocBufferHandle(foundCount*sizeof(KpInt32_t))) == (KpHandle_t)NULL) { freeBuffer(DateHandle); return SpStatMemory; } if ((TimeList = (KpInt32_t *)lockBuffer(TimeHandle)) == (KpInt32_t *)NULL) { freeBuffer(DateHandle); freeBuffer(TimeHandle); return SpStatBadBuffer; } Status = SpProfileGetHeader (profileList[0], &PfHeader); Date = 366*PfHeader.DateTime.Year + 31*PfHeader.DateTime.Month + PfHeader.DateTime.Day; Time = 3600*PfHeader.DateTime.Hour + 60*PfHeader.DateTime.Minute + PfHeader.DateTime.Second; /* Save First Profile's date */ DateList[0] = Date; TimeList[0] = Time; for (i = 1; i < foundCount; i++) { /* Get testable version of Time and Date */ Status = SpProfileGetHeader (profileList[i], &PfHeader); Date = 366*PfHeader.DateTime.Year + 31*PfHeader.DateTime.Month + PfHeader.DateTime.Day; Time = 3600*PfHeader.DateTime.Hour + 60*PfHeader.DateTime.Minute + PfHeader.DateTime.Second; /* Save in case no move required */ DateList[i] = Date; TimeList[i] = Time; /* Loop thru those before */ for (j = 0; j < i; j++) { /* Test for created before a previous entry */ if ((Date > DateList[j]) || ((Date == DateList[j]) && (Time > TimeList[j]))) { /* Save the profile o finterest */ profileToMove = profileList[i]; /* Move the older profiles back */ for (z = i; z > j; z--) { DateList[z] = DateList[z-1]; TimeList[z] = TimeList[z-1]; profileList[z] = profileList[z-1]; } /* Put the Profile of interest into its spot */ DateList[j] = Date; TimeList[j] = Time; profileList[j] = profileToMove; /* Check the next one on the complete list (i) */ break; } } } freeBuffer(DateHandle); freeBuffer(TimeHandle); return SpStatSuccess; }
static SpStatus_t SpSearchEngine(SpCallerId_t CallerId, SpDataBase_p DataBase, SpSearch_t *SearchCriterion, KpBool_t SubSearch, SpProfile_t *profileList, KpInt32_t listSize, KpInt32_t *foundCount, KpInt32_t searchMode, KpfileCallBack_t CBFunc) { SpStatus_t status = SpStatSuccess; KpBool_t Fstatus; KpHandle_t Handle; Limits_t *Limits; KpInt32_t ProfileCount = listSize; KpInt32_t i, critSize; KpfileDirEntry_t fileSearch; KpInt32_t FindAll = (searchMode & SPSEARCHFORALL); SpSearchCriterion_t *criterion; /* Allocate space to point to the search criteria, * point to the SpProfile array, give the max profiles * to find, and give the total found so far */ if ((Handle = allocBufferHandle(sizeof(Limits_t))) != (KpHandle_t)NULL) { if ((Limits = (Limits_t *)lockBuffer(Handle)) != NULL) { Limits->CallerId = CallerId; Limits->SearchCriterion = SearchCriterion; Limits->profileList = profileList; Limits->listSize = listSize; /* for Maximum Profiles */ Limits->CurrentIndex = *foundCount; /* for Current number found */ Limits->RetStatus = SpStatSuccess; /* Init Good Status */ Limits->GetALL = FindAll; /* Find count of all that match */ /* Loop thru DB entries */ for (i = 0; i < DataBase->numEntries && ((Limits->CurrentIndex < Limits->listSize) || (FindAll > 0)) && Limits->RetStatus == SpStatSuccess; ++i) { fileSearch.structSize = sizeof(KpfileDirEntry_t); if (searchMode & SEARCH_NOT_RECURSIVE) { fileSearch.nwAttr = ATTR_DIRECTORY; /* No directories */ fileSearch.wAttr = 0; } else { fileSearch.nwAttr = 0; fileSearch.wAttr = 0; /* Take anything found */ } if (searchMode & SEARCH_NOT_RESOLVE_ALIAS) fileSearch.nwAttr |= ATTR_LINK; /* turn off resolving of alias/shortcut/links */ strcpy(fileSearch.fileName, DataBase->Entries[i].dirName); fileSearch.subDirSearch = SubSearch; #if defined (KPMAC) fileSearch.osfPrivate.vRefNum = DataBase->Entries[i].fileProps.vRefNum; fileSearch.osfPrivate.fileType = 0; fileSearch.osfPrivate.fileCreator = 0; fileSearch.osfPrivate.dirID = DataBase->Entries[i].fileProps.dirID; #elif defined (KPWIN32) fileSearch.osfPrivate.filter[0] = '\0'; #endif /* The Call Back routine tests the individual * files reported for the test criteria and if * more profiles are found than there is space * for, it returns to stop the FileFind routine * and this search loop. */ Fstatus = KpFileFind(&fileSearch, Limits, CBFunc); } if (Limits->RetStatus != SpStatSuccess) { status = Limits->RetStatus; *foundCount = 0; } else { *foundCount = Limits->CurrentIndex; if (*foundCount < listSize) ProfileCount = *foundCount; if ((ProfileCount > 0) && (SearchCriterion != (SpSearch_t *)NULL)) { critSize = SearchCriterion->critSize; criterion = SearchCriterion->criterion; for (i = 0; i < SearchCriterion->critCount; i++) { if (criterion->SearchElement == SPSEARCH_TIMEORDER) { status = SpProfileOrderList(profileList, ProfileCount); break; } } criterion = (SpSearchCriterion_t *)(critSize + (KpUInt8_p)criterion); } } } else status = SpStatMemory; freeBuffer(Handle); } else status = SpStatMemory; return status; }
static KpBool_t TestFile(KpfileDirEntry_t FAR *fileSearch, SpCallerId_t CallerId, SpStatus_t *ReturnStatus, SpSearch_t *SearchCriterion, SpProfile_t *profileList, KpInt32_t listSize, KpInt32_t TotalAvailable, KpInt32_t *CurrentIndex) { SpProfile_t *profPtr; SpHeader_t Header; SpStatus_t Status; SpFileProps_t FileProp; SpProfileData_t FAR *ProfData; KpBool_t returnBool = KPTRUE; /* assume we will continue */ char *filename; KpInt32_t searchMode = SEARCH_RECURSIVE | SPSEARCHFORALL; SpDataBase_t DataBase; char Dir1[MAX_PATH]; SpDataBaseEntry_t List[1]; #if defined (KPMAC) KpUInt16_t vRefNumSave; KpUInt32_t dirIDSave; int i; #endif if ((fileSearch->opStatus == IOFILE_FINISHED) || (fileSearch->opStatus == IOFILE_STARTED) || (fileSearch->opStatus == IOFILE_ERROR)) { return returnBool; } #if defined (KPMAC) FileProp.vRefNum = fileSearch->osfPrivate.parm.dirInfo.ioVRefNum; FileProp.dirID = fileSearch->osfPrivate.parm.dirInfo.ioDrParID; #endif /* Search into sub-directories */ if (IsDirectory(fileSearch)) { DataBase.numEntries = 1; if (fileSearch->nwAttr & ATTR_DIRECTORY) searchMode |= SEARCH_NOT_RECURSIVE; if (fileSearch->nwAttr & ATTR_LINK) searchMode |= SEARCH_NOT_RESOLVE_ALIAS; #if defined (KPMAC) // Setup vRefNum/DirID of subdirectory. Save original and restore vefore returning List[0].fileProps.vRefNum = fileSearch->osfPrivate.parm.dirInfo.ioVRefNum; List[0].fileProps.dirID = fileSearch->osfPrivate.parm.dirInfo.ioDrParID; vRefNumSave = fileSearch->osfPrivate.vRefNum; dirIDSave = fileSearch->osfPrivate.dirID; // Only search one level of subdirectory on Mac searchMode |= SEARCH_NOT_RECURSIVE; #endif #if defined (KPUNIX) strcpy(Dir1, fileSearch->osfPrivate.base_Dir); strcat(Dir1, "/"); strcat(Dir1, fileSearch->fileName); #else strcpy(Dir1, fileSearch->fileName); #endif List[0].dirName = (char *)Dir1; DataBase.Entries = List; Status = SpSearchEngine(CallerId, &DataBase, SearchCriterion, KPFALSE, profileList, listSize, CurrentIndex, searchMode, (KpfileCallBack_t)TestFileCB); #if defined (KPMAC) fileSearch->osfPrivate.vRefNum = vRefNumSave; fileSearch->osfPrivate.dirID = dirIDSave; #endif if (Status == SpStatSuccess) return KPTRUE; else return KPFALSE; } Status = SpProfileLoadHeader(fileSearch->fileName, &FileProp, &Header); if (Status == SpStatSuccess) { Status = SpProfileCheck(SearchCriterion, &Header); if (Status == SpStatSuccess) { if (*CurrentIndex < listSize) { profPtr = &profileList[*CurrentIndex]; Status = SpProfileAlloc(CallerId, profPtr, &ProfData); if (Status == SpStatSuccess) { if ((Status = SpProfileSetHeader(*profPtr, &Header)) == SpStatSuccess) { ProfData->FileName = allocBufferHandle( strlen(fileSearch->fileName) + 1); if (ProfData->FileName == 0) { SpProfileFree(profPtr); return KPFALSE; } filename = (char *)lockBuffer(ProfData->FileName); if (filename == 0) { freeBuffer(ProfData->FileName); SpProfileFree(profPtr); return KPFALSE; } strcpy(filename, fileSearch->fileName); unlockBuffer (ProfData->FileName); ProfData->TotalCount = 0; freeBuffer(ProfData->TagArray); ProfData->TagArray = NULL; #if defined (KPMAC) ProfData->Props.vRefNum = fileSearch->osfPrivate.vRefNum; ProfData->Props.dirID = fileSearch->osfPrivate.dirID; for (i= 0; i < 5; i++) { ProfData->Props.fileType[i] = NULL; ProfData->Props.creatorType[i] = NULL; } #endif (*CurrentIndex)++; if ((*CurrentIndex >= listSize) && (TotalAvailable == 0)) returnBool = KPFALSE; } else { *ReturnStatus = Status; returnBool = KPFALSE; } /* if SpProfileSetHeader */ SpProfileUnlock(*profPtr); } else { *ReturnStatus = (KpInt32_t)Status; returnBool = KPFALSE; } /* if SpProfileAlloc */ } else (*CurrentIndex)++; } /* if SpProfileCheck */ } /* if SpProfileLoadHeader */ return returnBool; }