Esempio n. 1
0
/*--------------------------------------------------------------------
 * DESCRIPTION
 *	Create profile that uses supplied buffer as the profile data.
 *
 * AUTHOR
 * 	lsh
 *
 * DATE CREATED
 *	October 20, 1993
 *------------------------------------------------------------------*/
SpStatus_t KSPAPI SpProfileLoadFromBuffer (
				SpCallerId_t	CallerId,
				void			FAR *Buffer,
				SpProfile_t		FAR *Profile)
{
	SpStatus_t		Status;
	SpProfileData_t	FAR *ProfileData;
	
	Status = SpProfileAlloc (CallerId, Profile, &ProfileData);
	if (SpStatSuccess != Status)
		return Status;

/* get profile header into internal format */
	Status = SpProfileLoadFromBufferImp (ProfileData,  Buffer);

	SpProfileUnlock (*Profile);

/* free profile if an error occurred */
	if (SpStatSuccess != Status)
		SpProfileFree (Profile);

	return Status;
}
Esempio n. 2
0
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;
}