Пример #1
0
void sortScript()
{
	//this saves dynamic space
	UInt16 i, k, size;
	Err err;
	ScriptType temp[map.numCmds];
	
	//get rid of all map cmds
	for(i = 0; i < map.numCmds; i++)
	{
		if(!cmdIsAI(script[i].type))
		{
			//copy next cmd into this one if there is			
			for(k = i; k < map.numCmds;k++)
			{
				//if there is a cmd left
				if(k != (map.numCmds - 1))
				{
					//if it still isn't ai then continue
					if(!cmdIsAI(script[k + 1].type))
					{
						continue;
					}
					else
					{
						//copy it into new, discard old
						MemMove(&temp[i], &script[k + 1], sizeof(ScriptType));						
						size++;
						//get out of loop
						break;
					}	
				}
			}
		}	
		//leave it if it is an ai	
	}	
	
	//resize script to value of size
	err = MemHandleResize(scriptH, sizeof(ScriptType) * size);
	if(err == memErrChunkLocked)
	{
		//unlock
		MemHandleUnlock(scriptH);
		if(err = MemHandleResize(scriptH, sizeof(ScriptType) * size))
		{
			ErrFatalDisplay("In sortscript, couldn't resize script");
		}
		script = (ScriptType *)MemHandleLock(scriptH);		 
	}		
	else if(err != 0)
	{
		//some other error
		ErrFatalDisplay("In sortscript, couldn't resize script");	
	}	
	
	//move all script into new one
	MemMove(script, &temp, sizeof(ScriptType) * size);
}
Пример #2
0
/* remove an item from the list and move te rest one position up */
static Int16 RemoveFileRec(FileRef fr)
{
    Int16 i;
    Err ret;
    file_rec_t* axxFileList;
    axxPacFD FileDesc;

    axxFileList = MemHandleLock(axxFileListHandle);
    i = GetFilePos((Int16)fr);
    if (i == -1)
        return -1;
    
    FileDesc=axxFileList[i].fd;
    for (; i < axxFLSize - 1; i++) {
        MemMove (&axxFileList[i], &axxFileList[i + 1],sizeof(axxFileList));
    }    
    axxFLSize--;
    ret = MemHandleResize(axxFileListHandle, sizeof(file_rec_t) * axxFLSize);
    ret = MemHandleUnlock(axxFileListHandle);
    /* Check if the current file is the one removed from the list */
    if ((currFileDesc != -1) && ( FileDesc== currFileDesc)) {
        /* the cache of offsets is no longer valid if this file
           was closed */
        currFileDesc = -1;
        MemHandleFree(moff);
    }
    return 0;
}
Пример #3
0
/***********************************************************************
 *
 * FUNCTION:    SubstituteStr
 *
 * DESCRIPTION: This routine substitutes the occurrence a token, within
 *              a string, with another string.
 *
 * PARAMETERS:  str    - string containing token string
 *              token  - the string to be replaced
 *              sub    - the string to substitute for the token
 *              subLen - length of the substitute string.
 *
 * RETURNED:    pointer to the string
 *
 ***********************************************************************/
static Char* SubstituteStr(Char* str, const Char* token, const Char* sub, UInt16 subLen) {
  const UInt16 tokenLen = StrLen(token);
  const UInt16 charsToMove = subLen - tokenLen;
  const UInt16 strLen = StrLen(str);
  MemHandle strH = MemPtrRecoverHandle(str);
  const UInt16 blockSize = MemHandleSize(strH);
  Char* ptr = StrStr(str, token);

  ASSERT(str);
  ASSERT(token);
  ASSERT(sub);

  /* Find the start of the token string, if it doesn't exist, exit. */
  if (ptr == NULL)
    return str;

  /* Resize the string if necessary. */
  if (strLen + charsToMove + 1 >= blockSize) {
    MemHandleUnlock(strH);
    MemHandleResize(strH, strLen + charsToMove + 1);
    str = MemHandleLock(strH);
    ASSERT(str);
    ptr = StrStr(str, token);
    ASSERT(ptr);
  }

  /* Make room for the substitute string. */
  if (charsToMove)
    MemMove(ptr + subLen, ptr + tokenLen, StrLen (ptr + tokenLen)+1);
  
  /* Replace the token with the substitute string. */
  MemMove(ptr, sub, subLen);
  
  return str;
}
Пример #4
0
void wxControl::SetFieldLabel(const wxString& label)
{
    FieldType* field = (FieldType*)GetObjectPtr();
    if(field==NULL)
        return;

    uint16_t newSize = label.Length() + 1;
    MemHandle strHandle = FldGetTextHandle(field);
    FldSetTextHandle(field, NULL );
    if (strHandle)
    {
        if(MemHandleResize(strHandle, newSize)!=errNone)
            strHandle = 0;
    }
    else
    {
        strHandle = MemHandleNew( newSize );
    }
    if(!strHandle)
        return;

    char* str = (char*) MemHandleLock( strHandle );
    if(str==NULL)
        return;

    strcpy(str, label.c_str());
    MemHandleUnlock(strHandle);
    FldSetTextHandle(field, strHandle);
    FldRecalculateField(field, true);
}
Пример #5
0
void removeAI(UInt8 aiNum)
{
	PlayerStruct playerTemp[game.numPlayersOnScreen - 1];	 	
	UInt16 i;
	Err err;
	
	if(game.numPlayersOnScreen < 1)
	{
		ErrDisplay("In removeAI(), there are no players to remove");
	}		
	
	//move all player data to temp var:
	for(i = 0; i < aiNum; i++)
	{
		//move each player until one to delete appears
		playerTemp[i] = player[i];
	}
	for(i = aiNum + 1; i < game.numPlayersOnScreen; i++)
	{
		//move each player until end
		playerTemp[i - 1] = player[i];		
	}	
	
	//players are in place and top player is useless, can now resize
	game.numPlayersOnScreen--;	
	//resize to the number of players
	err = MemHandleResize(playerH, sizeof(PlayerStruct) * (game.numPlayersOnScreen));
	if(err == memErrChunkLocked)
	{
		//unlock
		MemHandleUnlock(playerH);
		if(err = MemHandleResize(playerH, sizeof(PlayerStruct) * game.numPlayersOnScreen))
		{	
			ErrFatalDisplay("In removeAI, couldn't resize player stack");
		}
		player = (PlayerStruct *)MemHandleLock(playerH);		 
	}		
	else if(err != errNone)
	{
		//some other error
		ErrFatalDisplay("In removeAI, couldn't resize player stack");	
	} 
	//copy orginal back to stack
	MemMove(player, (PlayerStruct *)&playerTemp, sizeof(PlayerStruct) * game.numPlayersOnScreen);	
}
Пример #6
0
/********************************************************************
 * Function: addRecord
 * Description:  function responsible for writing a packed System record
 * to the database. 
 * ******************************************************************/ 
void writeRecord (MemPtr record, MemHandle recordDBrec) {
	UInt16 length = 0, offset = 0;
	Char *ch;
	
	/* get length of the system buffer */
	length = MemPtrSize (record);
	
	/* re-size and write. */
	if (MemHandleResize (recordDBrec, length) == 0) {
		ch = MemHandleLock (recordDBrec);
		DmWrite (ch, offset, record, length);
		MemHandleUnlock (recordDBrec);
	}
}
Пример #7
0
/**************************************************************************
 * Function: getSystemFromIndex
 * Description: based upon a system database index, this will locate the
 * system for that index, unpack and decrypt it and initialize s
 * ************************************************************************/ 
void getSystemFromIndex (DmOpenRef SystemDB, md_hash * SysPass, UInt16 index, MemHandle tmp, System * s) {
	MemHandle rec = DmQueryRecord (SystemDB, index);
	if (rec) {
		MemPtr scratch, buff = MemHandleLock (rec);
		
			/*	resize the buffer */
		if (MemHandleResize (tmp, MemPtrSize (buff)) == 0) {
			scratch = MemHandleLock (tmp);
			
			/*	unpack and decrypt the account */
			UnpackSystem (s, buff, scratch, SysPass, MemHandleSize (rec), true); 
		}
		MemHandleUnlock (rec);
	}
}
Пример #8
0
/**************************************************************************
 * Function: getAccountFromIndex
 * Description: based upon an account index, this will locate the
 * account for that index, unpack and decrypt it and initialize acc
 * ************************************************************************/ 
void getAccountFromIndex (DmOpenRef AccountDB, md_hash * SysPass, UInt16 index, MemHandle tmp, Account * acc) {
	/*	query the record from the database */
	MemHandle rec = DmQueryRecord (AccountDB, index);
	
	if (rec){
		MemPtr scratch, buff = MemHandleLock (rec);
		
		/*	resize buffer */
		if (MemHandleResize (tmp, MemPtrSize (buff)) == 0) {
			scratch = MemHandleLock (tmp);
			
			/*	unpack the account */
			UnpackAccount (acc, buff, scratch, SysPass, MemHandleSize (rec), true, true);
		}
		MemHandleUnlock (rec);
	}
}
Пример #9
0
/**
 * FUNCTION: smSetSize
 *
 * Set size of memory block memH to newSize.
 *
 * PRE-Condition:   memH is a valid handle; newSize > 0; 
 *                  memory block is unlocked
 *
 * POST-Condition:  memory block size = newSize
 *
 * IN:      memH
 *          Handle to memory block
 * IN:      newSize
 *          New size of memory block
 * 
 * RETURN:  SML_ERR_OK, if O.K.
 *          SML_ERR_WRONG_PARAM, if memH is unknown
 *          SML_ERR_WRONG_USAGE, if memH is locked
 *          SML_ERR_INVALID_SIZE, if newSize <= 0
 *          SML_ERR_NOT_ENOUGH_SPACE, if available memory < newSize
 *
 * @see  smGetSize
 */
Ret_t smSetSize (MemHandle_t memH, MemSize_t newSize) {
  Err ret;

  if ( memH != smMemH ) {
    return SML_ERR_WRONG_PARAM;
  }
  if ( smLocked ) {
    return SML_ERR_WRONG_USAGE;
  }
  if ( newSize <= 0 ) {
    return SML_ERR_INVALID_SIZE;
  }

  if ( (ret=MemHandleResize((VoidHand)smPalmH, newSize)) != 0 ) {
    return SML_ERR_NOT_ENOUGH_SPACE;
  }
  
  return SML_ERR_OK;
}
Пример #10
0
int AppendField( FieldPtr fld, CharPtr str, UInt len )
{
	Err err=0;
	CharPtr  s;
	VoidHand h;
	UInt prevlen;

	h=(VoidHand)FldGetTextHandle(fld);

	if(h==NULL) {
		h=MemHandleNew(len+1);
		if(h==NULL) return(-1);
		s=MemHandleLock(h);
		StrNCopy(s, str, len);
		s[len]=0;
		MemHandleUnlock(h);
	} else {
		prevlen=FldGetTextLength(fld);

		FldSetTextHandle(fld, NULL);

		if( MemHandleSize(h)<=(prevlen+len)) {
			err=MemHandleResize( h, prevlen+len+1 );
		}
		if( err!=0 ) return(-1);

		s=MemHandleLock(h);
		StrNCopy(s+prevlen, str, len);
		s[len+prevlen]=0;
		MemHandleUnlock(h);
	}

	FldSetTextHandle(fld, (Handle)h);
	/* FldDrawField(fld); */

	return( 0 );
}
Пример #11
0
/***********************************************************************
 *
 * FUNCTION:    ApptGetAppointments
 *
 * DESCRIPTION: This routine returns a list of appointments that are on 
 *              the date specified
 *
 * PARAMETERS:  dbP    - pointer to the database
 *              date   - date to search for
 *              countP - number of appointments on the specified 
 *                       day (returned value)
 *
 * RETURNED:    handle of the appointment list (ApptInfoType)
 *
 * REVISION HISTORY:
 *          Name    Date        Description
 *          ----    ----        -----------
 *          art     6/15/95     Initial Revision
 *
 ***********************************************************************/
MemHandle ApptGetAppointments (DmOpenRef dbP, DateType date, UInt16 * countP) {
    Err error;
    Int16 result;
    Int16 count = 0;
    UInt16    recordNum;
    Boolean repeats;
    MemHandle recordH;
    MemHandle apptListH;
    ApptInfoPtr apptList;
    ApptDBRecordType apptRec;
    ApptPackedDBRecordPtr r;

    // Allocated a block to hold the appointment list.
    apptListH = MemHandleNew (sizeof (ApptInfoType) * apptMaxPerDay);
    ErrFatalDisplayIf(!apptListH, "Out of memory");
    if (! apptListH) return (0);

    apptList = MemHandleLock (apptListH);

    // Find the first non-repeating appointment of the day.
    if (ApptFindFirst (dbP, date, &recordNum)) {
        while (count < apptMaxPerDay) {
            // Check if the appointment is on the date passed, if it is
            // add it to the appointment list.
            recordH = DmQueryRecord (dbP, recordNum);
            r = MemHandleLock (recordH);
            result = DateCompare (r->when.date, date);

            if (result == 0) {
                // Add the record to the appoitment list.
                apptList[count].startTime = r->when.startTime;
                apptList[count].endTime = r->when.endTime;
                apptList[count].recordNum = recordNum;
                count++;
            }
            MemHandleUnlock (recordH);
            if (result != 0) break;

            // Get the next record.
            error = DmSeekRecordInCategory (dbP, &recordNum, 1,
                                            dmSeekForward,
                                            dmAllCategories);
            if (error == dmErrSeekFailed) break;
        }
    }

    // Add the repeating appointments to the list.  Repeating appointments
    // are stored at the beginning of the database.
    recordNum = 0;
    while (count < apptMaxPerDay) {
        recordH = DmQueryNextInCategory (dbP, &recordNum, dmAllCategories);
        if (! recordH) break;
        
        r = (ApptPackedDBRecordPtr) MemHandleLock (recordH);
        
        repeats = (r->flags.repeat != 0);
        if (repeats) {
            ApptUnpack (r, &apptRec);
            if (ApptRepeatsOnDate (&apptRec, date)) {
                // Add the record to the appoitment list.
                apptList[count].startTime = r->when.startTime;              
                apptList[count].endTime = r->when.endTime;              
                apptList[count].recordNum = recordNum;  
                count++;
            }
        }
        MemHandleUnlock (recordH);

        // If the record has no repeating info we've reached the end of the 
        // repeating appointments.
        if (! repeats) break;
        
        recordNum++;
    }

    // Sort the list by start time.
    // SysInsertionSort (apptList, count, sizeof (ApptInfoType),
    //          ApptListCompare, 0L);

    // If there are no appointments on the specified day, free the appointment
    // list.
    if (count == 0) {
        MemPtrFree (apptList);
        apptListH = 0;
    }
    // Resize the appointment list block to release any unused space.
    else {
        MemHandleUnlock (apptListH);
        MemHandleResize (apptListH, count * sizeof (ApptInfoType));
    }

    *countP = count;
    return (apptListH);
}
Пример #12
0
Err vfsFileOpen(UInt16 volRefNum, const Char *pathNameP, UInt16 openMode,
        FileRef *fileRefP)
{
    axxPacFD FileDesc = 0;                       
    Int16 fileRef;
    axxPacMode mode = 0;
    Char* strErr;
    Err ret;
    axxPacStatType stat;
    file_rec_t* axxFileList;

    ret = axxPacStat( volRefNum, (Char*)pathNameP, &stat );
    if ( ret != 0 ) {
      return vfsErrFileNotFound;
    }
    if ( ! ( stat.attrib & FA_SUBDIR ) ) {
        /* only files can be opened in the AxxPac */
        if ( openMode & vfsModeWrite )
            mode = O_RdWr;
        else if ( openMode & vfsModeRead )
            mode = O_RdOnly;
        else if ( openMode & vfsModeCreate )
            mode = O_Creat;
        else
            return vfsErrFilePermissionDenied;

        FileDesc = axxPacOpen( volRefNum, (Char*) pathNameP, mode );
        if ( FileDesc < 0 ) {
            strErr= axxPacStrError( volRefNum );
            /* errors need to be mapped to VFS errors */
            if ( strErr[3]=='s' ) 
                return vfsErrFileNotFound;
            return expErrNotOpen;
        }
        /* create the File Ref that will be identify the file even if  */
        /* the axxPac closes the file by going to sleep mode */
        fileRef = CreateFileRef();
    }
    else {
      /* folders will just have a virtual file descriptor */
        FileDesc = CreateFileRef();
        fileRef  = FileDesc;
    }

    if ( axxFLSize == 0 ) {
        axxFileListHandle = MemHandleNew( sizeof( file_rec_t ) );
    }
    else {
        ret = MemHandleResize( axxFileListHandle, sizeof( file_rec_t ) *
                                                 ( axxFLSize + 1 ) );
        if ( ret != 0 )
            goto ERROR_FO;
    }
    axxFileList = MemHandleLock(axxFileListHandle);
    /* some Axxpac functions require the path, others require the FileDesc,
       store the FileDesc, attrib and path in a table */
    StrCopy (axxFileList[axxFLSize].name, pathNameP);
    axxFileList[axxFLSize].fd = FileDesc;
    axxFileList[axxFLSize].attrib = stat.attrib;
    axxFileList[axxFLSize].size = stat.size;
    axxFileList[axxFLSize].position=0;
    axxFileList[axxFLSize].mode=mode;
    axxFileList[axxFLSize].fileRef=fileRef;
    axxFLSize++; 
    ret = MemHandleUnlock(axxFileListHandle);
    *fileRefP = (FileRef)fileRef;  

    return errNone ;

ERROR_FO:
  axxPacClose(volRefNum, FileDesc);
  return vfsErrFilePermissionDenied;
}
Пример #13
0
void addAI(PlayerType type, PointType firstPos)
{
	/* adds a member to be controlled by computer.
	 * needs revision*/ 
	PlayerStruct stack[game.numPlayersOnScreen]; 
	PlayerStruct temp;
	
	//set type for info
	temp.type = type;
	//set position
	temp.health = aInfo[type].orgHealth;
	temp.oldpos = firstPos;
	temp.nextpos = firstPos;
	temp.dirSpeed[left]= 0;
	temp.dirSpeed[right]= 0;	
	temp.dirSpeed[down]= 0;	
	temp.dirSpeed[up]= 0;	
	temp.dirSpeed[select]= 0;		
	
	//if there is at least one ai
	if(playerH)
	{
		//resize player variable to +1 sizeof(player structure)	
		Err err = true;	
		
		//move data from stack to temp
		MemMove(&stack, player, sizeof(PlayerStruct) * game.numPlayersOnScreen);
			
		err = MemHandleResize(playerH, sizeof(PlayerStruct) * (game.numPlayersOnScreen + 1));
		if(err == memErrChunkLocked)
		{
			//needs to be unlocked first
			MemHandleUnlock(playerH);
			err = MemHandleResize(playerH, sizeof(PlayerStruct) * (game.numPlayersOnScreen + 1));
			ErrFatalDisplayIf(err, "In addAI(), error resizing player stack");
			player = (PlayerStruct *)MemHandleLock(playerH);			
		}
		else
		{
			//resizing didnt work
			ErrDisplay("In addAI(), Couldn't resize player stack");			
		}
		
		//didn't need to unlock		
		MemMove(player, &stack, sizeof(PlayerStruct) * game.numPlayersOnScreen);
		game.numPlayersOnScreen++;
		//set that player data to temp
		player[game.numPlayersOnScreen-1] = temp;		
	}
	else
	{
		//there is no players at all
		//make new memhandle to a player which is size of one player
		playerH = MemHandleNew(sizeof(PlayerStruct));
		ErrFatalDisplayIf(!playerH, "In addAI(), Couldn't make new handle to PlayerStruct");
		player = (PlayerStruct *)MemHandleLock(playerH); 
		game.numPlayersOnScreen = 1;
		//set that player data to temp
		player[0] = temp;
	}	
}
Пример #14
0
void addObjective(ObjectiveType type, PointType pos)
{
	/* adds a member to be controlled by computer.
	 * needs revision*/ 
	ObjStruct stack[game.numObjsOnScreen]; 
	ObjStruct temp;
	
	temp.type = type;
	temp.pos = pos;
	
	switch(type)
	{
		case munitionsObj:
			temp.bmp = munitionsBmp;
			temp.health = OBJ_HEALTH_MAJOR;
			break;
		case coalplantObj:
			temp.bmp = coalplantBmp;
			temp.health = OBJ_HEALTH_MAJOR;
			break;
		case v2Obj:
			temp.bmp = v2Bmp;
			temp.health = OBJ_HEALTH_MAJOR;
			break;
		case aagunObj:
			temp.bmp = aagunBmp;
			temp.health = OBJ_HEALTH_MINOR;
			break;
		case art88mmObj:
			temp.bmp = art88mmBmp;
			temp.health = OBJ_HEALTH_MEDIUM;
			break;
		case howitzersObj:
			temp.bmp = howitzersBmp;
			temp.health = OBJ_HEALTH_MINOR;
			break;
		case radarstationObj:
			temp.bmp = radarstationBmp;
			temp.health = OBJ_HEALTH_MEDIUM;
			break;
		case panzersObj:
			temp.bmp = panzersBmp;
			temp.health = OBJ_HEALTH_MINOR;
			break;
		case kingtigersObj:
			temp.bmp = kingtigersBmp;
			temp.health = OBJ_HEALTH_MEDIUM;
			break;
		case bunkerObj:
			temp.bmp = bunkerBmp;
			temp.health = OBJ_HEALTH_MINOR;
			break;
	}
	
	
	//if there is at least one ai
	if(objH)
	{
		//resize player variable to +1 sizeof(player structure)	
		Err err = true;	
		
		//move data from stack to temp
		MemMove(&stack, obj, sizeof(ObjStruct) * game.numObjsOnScreen);
			
		err = MemHandleResize(objH, sizeof(ObjStruct) * (game.numObjsOnScreen + 1));
		if(err == memErrChunkLocked)
		{
			//needs to be unlocked first
			MemHandleUnlock(objH);
			err = MemHandleResize(objH, sizeof(ObjStruct) * (game.numObjsOnScreen + 1));
			ErrFatalDisplayIf(err, "In addAI(), error resizing player stack");
			obj = (ObjStruct *)MemHandleLock(objH);			
		}
		else
		{
			//resizing didnt work
			ErrDisplay("In addAI(), Couldn't resize player stack");			
		}
		
		//didn't need to unlock		
		MemMove(obj, &stack, sizeof(ObjStruct) * game.numObjsOnScreen);
		game.numObjsOnScreen++;
		//set that player data to temp
		obj[game.numObjsOnScreen-1] = temp;		
	}
	else
	{
		//there is no players at all
		//make new memhandle to a player which is size of one player
		objH = MemHandleNew(sizeof(ObjStruct));
		ErrFatalDisplayIf(!objH, "In addAI(), Couldn't make new handle to PlayerStruct");
		obj = (ObjStruct *)MemHandleLock(objH); 
		game.numObjsOnScreen = 1;
		//set that player data to temp
		obj[0] = temp;
	}	
}